# Algorithm for counting neighbors

I need an algorithm to process protein chains. The volume size would probably not exceed 30x30x30 angstrom^3.

Say, I have a point cloud of 50,000 points in a 3D space.

I want to count the number of neighbors each point {(x1,y1,z1), (x2,y2,z2), (x3,y3,z3), ... ...,(xN,yN,zN)} has at radii {r1, r2, r3, ..., rM}.

Which algorithm should I use?

1. Do you need to do this count online/sequentially or all at once?
All once.

2. What restrictions might there be on the radii?
The radii will be 4.0, 4.5, 5.0, 5.5, 6.0, 6.5, 7.0 angstrom.

3. Do you need to do this just once in this particular case or do you need a general algorithm?
I will use this to process protein sequences. Not DNA/RNA, though.

4. For a general algorithm, what's the likely range of the number of points?
The range would be 50,000 at max (although, the maximum length of available protein is 38,000 residues).

5. Are you expecting there to be relatively few or relatively many neighbors?
I am expecting relatively few neighbors, in the range of 0-50.

NOTE: I prefer a hash-based algorithm as it doesn't require additional data structures like KD tree, or octree.