-
Notifications
You must be signed in to change notification settings - Fork 36
IterateOverAllAtomPairsInAnAtomContainer
dstoeckel edited this page Mar 16, 2015
·
2 revisions
Iterating over all atom pairs of an AtomContainer using the BALL_FOREACH_ATOM_PAIR-macro:
#include <BALL/KERNEL/forEach.h>
using namespace BALL;
...
AtomContainer ac;
AtomIterator ait1, ait2;
BALL_FOREACH_ATOM_PAIR(ac, ait1, ait2)
{
// Compute the distance of the current atom pair
float dist = ait1->getPosition().getDistance(ait2->getPosition());
// Print the distance
std::cout << dist << " " << ait1->getFullName() << " " << ait2->getFullName() << std::endl;
}Note: Using a simple nested AtomIterator-BondIterator-construction will consider each atom-pair twice!
Note: Never try to add or remove atoms from the AtomContainer while running over it! Your programm will crash!
Note: the BALL_FOREACH_ATOM_PAIR-macro gets an AtomContainer. BALL-objects, that can be runtime-cast to an AtomContainer are for example a Chain, a Residue, a Molecule, a Protein, or a System.