- (a) iterate over the neighbouring atoms, and then request the bond joining the two atoms?
for nbr in ob.OBAtomAtomIter(atom): bond = atom.GetBond(nbr)
for bond in ob.OBAtomBondIter(atom): nbr = bond.GetNbrAtom(atom)
Obviously, either way you get your atom and bond. But which is more efficient? Clearly, the answer to this depends on the internals of the toolkit. But if you assume that each atom knows its attached atoms and bonds, then it's only the second step that determines the relative efficiency. That is:
- (a) given two atoms find the bond that joins them, versus
- (b) given an atom and a bond find the atom at the other end
Since the implementation of (a) will probably involve the same test that (b) is doing plus additional work, it follows that (b) must be more efficient. I never really thought about this before until I was writing the kekulization code for Open Babel. It's the sort of thing that's useful to work out once and then apply in future without thinking. Sure, the speed difference may be minimal but given that you have to choose, you might as well write it the more efficient way.