12.2 Number of Ring Bonds to an Atom

To provide an example of how one might use the above functions, the code below returns the number of ring bonds attached to an atom. This is useful for identifying ring fusion atoms (ring bond count = 3) and potential spiro-atoms (ring bond count $\ge$ 4).

unsigned int MyAtomRingBondCount(const OEAtomBase *atm)
{
  unsigned int count = 0;
  OEIter<OEBondBase> bond;
  for (bond=atm->GetBonds(); bond; ++bond)
    if (bond->IsInRing())
      count++;
  return count;
}

Once again, the example function above requires that the function OEFindRingAtomsAndBonds has previously been called on this molecule, typically by the high-level readers.