Back to index

python-biopython  1.60
Public Member Functions | Public Attributes | Private Member Functions
Bio.PDB.NeighborSearch.NeighborSearch Class Reference

List of all members.

Public Member Functions

def __init__
def search
def search_all

Public Attributes

 atom_list
 coords
 kdt

Private Member Functions

def _get_unique_parent_pairs

Detailed Description

This class can be used for two related purposes:

1. To find all atoms/residues/chains/models/structures within radius 
of a given query position. 

2. To find all atoms/residues/chains/models/structures that are within 
a fixed radius of each other.

NeighborSearch makes use of the Bio.KDTree C++ module, so it's fast.

Definition at line 16 of file NeighborSearch.py.


Constructor & Destructor Documentation

def Bio.PDB.NeighborSearch.NeighborSearch.__init__ (   self,
  atom_list,
  bucket_size = 10 
)
o atom_list - list of atoms. This list is used in the queries.
It can contain atoms from different structures.
o bucket_size - bucket size of KD tree. You can play around 
with this to optimize speed if you feel like it.

Definition at line 28 of file NeighborSearch.py.

00028 
00029     def __init__(self, atom_list, bucket_size=10):
00030         """
00031         o atom_list - list of atoms. This list is used in the queries.
00032         It can contain atoms from different structures.
00033         o bucket_size - bucket size of KD tree. You can play around 
00034         with this to optimize speed if you feel like it.
00035         """
00036         self.atom_list=atom_list
00037         # get the coordinates
00038         coord_list = [a.get_coord() for a in atom_list]
00039         # to Nx3 array of type float
00040         self.coords=numpy.array(coord_list).astype("f")
00041         assert(bucket_size>1)
00042         assert(self.coords.shape[1]==3)
00043         self.kdt=KDTree(3, bucket_size)
00044         self.kdt.set_coords(self.coords)


Member Function Documentation

def Bio.PDB.NeighborSearch.NeighborSearch._get_unique_parent_pairs (   self,
  pair_list 
) [private]

Definition at line 47 of file NeighborSearch.py.

00047 
00048     def _get_unique_parent_pairs(self, pair_list):
00049         # translate a list of (entity, entity) tuples to 
00050         # a list of (parent entity, parent entity) tuples,
00051         # thereby removing duplicate (parent entity, parent entity)
00052         # pairs.
00053         # o pair_list - a list of (entity, entity) tuples
00054         parent_pair_list=[]
00055         for (e1, e2) in pair_list:
00056             p1=e1.get_parent()
00057             p2=e2.get_parent()
00058             if p1==p2:
00059                 continue
00060             elif p1<p2:
00061                 parent_pair_list.append((p1, p2))
00062             else:
00063                 parent_pair_list.append((p2, p1))
00064         return uniqueify(parent_pair_list)

Here is the call graph for this function:

Here is the caller graph for this function:

def Bio.PDB.NeighborSearch.NeighborSearch.search (   self,
  center,
  radius,
  level = "A" 
)
Neighbor search.

Return all atoms/residues/chains/models/structures
that have at least one atom within radius of center.
What entitity level is returned (e.g. atoms or residues)
is determined by level (A=atoms, R=residues, C=chains,
M=models, S=structures).

o center - Numeric array 
o radius - float
o level - char (A, R, C, M, S)

Definition at line 67 of file NeighborSearch.py.

00067 
00068     def search(self, center, radius, level="A"):
00069         """Neighbor search.
00070 
00071         Return all atoms/residues/chains/models/structures
00072         that have at least one atom within radius of center.
00073         What entitity level is returned (e.g. atoms or residues)
00074         is determined by level (A=atoms, R=residues, C=chains,
00075         M=models, S=structures).
00076 
00077         o center - Numeric array 
00078         o radius - float
00079         o level - char (A, R, C, M, S)
00080         """
00081         if not level in entity_levels:
00082             raise PDBException("%s: Unknown level" % level)
00083         self.kdt.search(center, radius)
00084         indices=self.kdt.get_indices()
00085         n_atom_list=[]
00086         atom_list=self.atom_list
00087         for i in indices:
00088             a=atom_list[i]
00089             n_atom_list.append(a)
00090         if level=="A":
00091             return n_atom_list
00092         else:
00093             return unfold_entities(n_atom_list, level)
            

Here is the call graph for this function:

Here is the caller graph for this function:

def Bio.PDB.NeighborSearch.NeighborSearch.search_all (   self,
  radius,
  level = "A" 
)
All neighbor search.

Search all entities that have atoms pairs within
radius. 

o radius - float
o level - char (A, R, C, M, S)

Definition at line 94 of file NeighborSearch.py.

00094 
00095     def search_all(self, radius, level="A"):
00096         """All neighbor search.
00097 
00098         Search all entities that have atoms pairs within
00099         radius. 
00100 
00101         o radius - float
00102         o level - char (A, R, C, M, S)
00103         """
00104         if not level in entity_levels:
00105             raise PDBException("%s: Unknown level" % level)
00106         self.kdt.all_search(radius)
00107         indices=self.kdt.all_get_indices()
00108         atom_list=self.atom_list
00109         atom_pair_list=[]
00110         for i1, i2 in indices:
00111             a1=atom_list[i1]
00112             a2=atom_list[i2]
00113             atom_pair_list.append((a1, a2))
00114         if level=="A":
00115             # return atoms
00116             return atom_pair_list
00117         next_level_pair_list=atom_pair_list
00118         for l in ["R", "C", "M", "S"]:
00119             next_level_pair_list=self._get_unique_parent_pairs(next_level_pair_list)
00120             if level==l:
00121                 return next_level_pair_list 

Here is the call graph for this function:


Member Data Documentation

Definition at line 35 of file NeighborSearch.py.

Definition at line 39 of file NeighborSearch.py.

Definition at line 42 of file NeighborSearch.py.


The documentation for this class was generated from the following file: