You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
dstoeckel edited this page Mar 16, 2015
·
2 revisions
How can I iterate over all bonds in an AtomContainer ?
Iterate over all bonds of an AtomContainer using the BALL_FOREACH_BOND-macro:
#include<BALL/KERNEL/forEach.h>
#include<BALL/KERNEL/bond.h>
#include<BALL/COMMON/logStream.h>
#include<BALL/KERNEL/atomContainer.h>usingnamespaceBALL;
AtomContainer ac;
...
AtomIterator ait;
Atom::BondIterator bit;
BALL_FOREACH_BOND(ac, ait, bit)
{
if (bit->getOrder() == Bond::ORDER__UNKNOWN)
{
// Get the bond lengthfloat length = bit->getLength();
// Print the bond
Log.info() << bit->getFirstAtom()->getFullName() << "" << bit->getSecondAtom()->getFullName() << "" << length << std::endl;
}
}
Note: Using a simple nested AtomIterator-BondIterator-construction will consider each bond twice!
Note: Never try to add or remove atoms/bonds from the AtomContainer while iterating over it! Your program will crash!
Note: the BALL_FOREACH_BOND-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.