One can use KD-Trees to speed up searches. MDAnalysis uses Thomas Hamelryck’s C++ implementation from Biopython. The following are fairly technical descriptions of the available classes.
If you know that you are using a specific selection repeatedly then may be faster to explicitly build the selection using the AtomNeighborSearch class instead of using MDAnalysis selections.
Example:
import MDAnalysis.lib.KDTree.NeighborSearch as NS
u = Universe(psf,dcd)
water = u.select_atoms('name OH2')
protein = u.select_atoms('protein')
# when analyzing a trajectory, carry out the next two steps
# for every frame
ns_w = NS.AtomNeighborSearch(water)
solvation_shell = ns_w.search_list(protein,4.0) # water oxygens within 4A of protein
This class can be used for two related purposes:
1. To find all atoms/residues/segments within radius of a given query position.
2. To find all atoms/residues/segments that are within a fixed radius of each other.
AtomNeighborSearch makes use of the KDTree C++ module, so it’s fast.
Arguments : |
---|
Neighbor search.
Return all atoms/residues/segments that have at least one atom within radius of center.
Arguments : |
|
---|
In order to obtain the coordinates for the center argument from a AtomGroup one can simply provide the output of the centroid or centerOfMass functions.
All neighbor search.
Search all entities that have atoms pairs within radius.
Arguments : |
|
---|
Search neighbours near all atoms in atoms.
Returns all atoms/residues/segments that contain atoms that are within radius of any other atom listed in other, i.e. “find all A within R of B” where A are the atoms used for setting up the AtomNeighborSearch and B are the other atoms.
Arguments : |
---|
This class can be used for two related purposes:
1. To find all indices of a coordinate list within radius of a given query position.
2. To find all indices of a coordinate list that are within a fixed radius of each other.
CoordinateNeighborSearch makes use of the KDTree C++ module, so it’s fast.
Arguments : |
|
---|
Neighbor search.
Return all indices in the coordinates list that have at least one atom within radius of center.
Arguments : |
|
---|
All neighbor search.
Return all index pairs corresponding to coordinates within the radius.
Arguments : |
|
---|
Search neighbours near all centers.
Returns all indices that are within radius of any center listed in centers, i.e. “find all A within R of B” where A are the coordinates used for setting up the CoordinateNeighborSearch and B are the centers.
Arguments : |
|
---|