Hi Hong Man,
Can you provide some additional information about the implementation of cKDTree that you use?
Apart from that, scipy.spatial.cKDTree is *not* suited for systems with periodic boundary conditions!
If you use MDAnalysis 18.0, I'd recommend something along these lines:
Finding the N closest oxygens around each lithium:
N = 10
1. compute a distance array:
distances = MDAnalysis.lib.distances.distance_array(Li.positions, O.positions, box=u.dimensions)
2. get the indices of the N nearest oxygen atoms:
indices = numpy.argpartition(distances, N, axis=1)[:, :N]
3. create empty AtomGroup:
O_around_Li = MDAnalysis.AtomGroup([], u)
4. Add oxygens to group using the indices we found:
for idx in indices:
O_around_Li += O[idx]
Beware: If you have multiple Li atoms, the obtained group might contain duplicate atoms (oxygen atoms that solvate two or more Li atoms)
Hope this helps!
Cheers,
Johannes