-
Notifications
You must be signed in to change notification settings - Fork 32
LocateAtomsInSpatialProximity
dstoeckel edited this page Mar 16, 2015
·
2 revisions
Identifying atoms in a certain spatial proximity can be done with the help of BALL's HashGridBox3.
#include <BALL/DATATYPE/hashGrid.h>
#include <BALL/STRUCTURE/geometricProperties.h>
#include <BALL/MATHS/vector3.h>
#include <BALL/KERNEL/system.h>
#include <BALL/KERNEL/atom.h>
using namespace BALL;
// create and fill a grid with spacing 1.5 Angstroem containing the protein
// create a bounding box including the proteins in the System S
BoundingBoxProcessor bp;
S.apply(bp);
Vector3 upper = bp.getUpper();
Vector3 lower = bp.getLower();
// create a grid with spacing 1.5\AA storing atom pointers limited to the bounding box
HashGrid3<Atom*> grid(lower, upper - lower, 1.5);
...
// insert all atom pointers into the grid according to the atom positions
grid.insert(atomN->getPosition(), atomN);
...
// now get all neighbouring atoms within a distance of 1.5\AA of atom B
// get the box containing atom B
HashGridBox3<Atom*>* box = grid.getBox(atomB->getPosition());
// and iterate over all neighbouring boxes
for(HashGridBox3<Atom*>::BoxIterator bit = box->beginBox(); +bit; ++bit)
{
HashGridBox3<Atom*>::DataIterator data_it;
for (data_it = bit->beginData(); +data_it; ++data_it)
{
if((*data_it)->getDistance(*atomB) <= 1.5)
{
// now do something interesting
std::cout << (*data_it)->getPosition() << std::endl;
}
}
}
Please note that this interface is available in version 1.4!
from BALL import *
# define the HashGrid spacing
threshold = 5.
threshold_sq = threshold*threshold
# get a system
S = getSystems()[0]
# create a bounding box including the proteins in the System S
bbp = BoundingBoxProcessor()
S.apply(bbp)
# create a grid with spacing 1.5\AA storing atom pointers limited to the bounding box
grid = AtomHashGrid3(bbp.getLower()-Vector3(threshold), bbp.getUpper()-bbp.getLower()+Vector3(threshold), threshold)
# insert all aminoacid atoms into the grid according to the atom positions
for a in atoms(S):
if ((not a.getResidue().isAminoAcid())):
continue
grid.insert(a.getPosition(), a)
# consider a special atom a
a = ...
# get the box containing atom a
box = grid.getBox(a.getPosition())
# and iterate over all neighbouring boxes
for neighbor_box in box.iterboxes():
for a2 in neighbor_box.iterdata():
# now do something interesting
print a2.getPosition()
If you want to run the script without BALLView replace
S = getSystems()[0]
with
path = Path()
pdbfile = PDBFile(path.find("structures/bpti.pdb"))
S = System()
pdbfile.read(S)