# 13.2.3. Neighbor Search wrapper for MDAnalysis — MDAnalysis.lib.NeighborSearch¶

This module contains classes that allow neighbor searches directly with AtomGroup objects from MDAnalysis.

class MDAnalysis.lib.NeighborSearch.AtomNeighborSearch(atom_group, box=None, bucket_size=10)[source]

This class can be used to find all atoms/residues/segments within the radius of a given query position.

For the neighbor search, this class uses the BioPython KDTree and its wrapper PeriodicKDTree for non-periodic and periodic systems, respectively.

Parameters: atom_list (AtomGroup) – list of atoms box (array-like or None, optional, default None) – Simulation cell dimensions in the form of MDAnalysis.trajectory.base.Timestep.dimensions when periodic boundary conditions should be taken into account for the calculation of contacts. bucket_size (int) – Number of entries in leafs of the KDTree. If you suffer poor performance you can play around with this number. Increasing the bucket_size will speed up the construction of the KDTree but slow down the search.
search(atoms, radius, level='A')[source]

Return all atoms/residues/segments that are within radius of the atoms in atoms.

Parameters: atoms (AtomGroup, MDAnalysis.core.groups.Atom) – list of atoms radius (float) – Radius for search in Angstrom. level (str) – char (A, R, S). Return atoms(A), residues(R) or segments(S) within radius of atoms.