The exact same idiom is used for iterating over the bonds attached to an atom. The OEAtomBase method GetBonds returns an OEBondBaseIter over the bonds connected to the atom. The example below shows how to use this method to determine the explicit degree of an atom, i.e. the number of bonds to it, other than implicit hydrogen atoms.
1 /**************************************************************
2 * Copyright 2005, OpenEye Scientific Software, Inc.
3 *************************************************************/
4
5 import openeye.oechem.*;
6
7 public class BondsOfAnAtom {
8 private static int MyGetExplicitDegree(OEAtomBase atom) {
9 int result=0;
10 for (OEBondBaseIter iter = atom.GetBonds(); iter.hasNext(); iter.next())
11 result++;
12 return result;
13 }
14
15 public static void main(String argv[]) {
16 OEGraphMol mol = new OEGraphMol();
17 oechem.OEParseSmiles(mol, "c1cocc1Br");
18 oechem.OEAssignAromaticFlags(mol);
19
20 for (OEAtomBaseIter aiter = mol.GetAtoms();aiter.hasNext();) {
21 OEAtomBase atom = aiter.next();
22 System.out.println(atom.GetIdx()+": "+MyGetExplicitDegree(atom));
23 }
24 }
25 }