Iterator Factory

The IteratorFactory class provides implementations of java.util.Iterator to ease the handling of atoms and bonds used in Molecule objects and its descendants. The IteratorFactory object always belongs to one particular Molecule object (or descendant). The following iterators are included in this class:

The above mentioned iterators are constructed by the appropriate IteratorFactory.createXXX() methods. For example an atom iterator can be constructed with the createAtomIterator() method of the iterator factory. The behavior of the iterator is determined by the parameters given in the constructor of the iterator factory. The behavior can be bond or atom related: the factory constructs consistent iterators for the specified molecule with the specified behavior.

Usage examples

Example for simple usage of an atom iterator:

 
//initialize a Molecule; Molecule molecule = ...; //create an iterator factory where the iterators skip the pseudo atom and coordinate bonds. IteratorFactory ifc = new IteratorFactory(molecule, IteratorFactory.SKIP_PSEUDO_ATOM | IteratorFactory.SKIP_EXPLICIT_H, IteratorFactory.SKIP_COORDINATE_BONDS); AtomIterator atomIterator = ifc.createAtomIterator(); //iteration on the atoms of a component except the pseudo atoms. while (atomIterator.hasNext()){ MolAtom atom = atomIterator.nextAtom(); //process the atom ... }

Example for complex usage of iterators:

     //initialize an RgMolecule; 
     RgMolecule mol = ... ;
     //create the iterator factory with the specified molecule and parameters related to atoms and bonds.
     IteratorFactory factory = new IteratorFactory(mol, IteratorFactory.INCLUDE_ALL_ATOMS, IteratorFactory.INCLUDE_ALL_BONDS);
     RgComponentIterator rgIterator = factory.createRgComponentIterator();
     //iteration on the components of the RgMolecule.
     while (rgIterator.hasNext()) {
         Molecule component = rgIterator.nextComponent();
         IteratorFactory ifc = new IteratorFactory(component, IteratorFactory.SKIP_PSEUDO_ATOM | IteratorFactory.SKIP_EXPLICIT_H,
                 IteratorFactory.SKIP_COORDINATE_BONDS);
         AtomIterator atomIterator = ifc.createAtomIterator();
         //iteration on the atoms of a component
         while (atomIterator.hasNext()){
             MolAtom atom = atomIterator.nextAtom();
             //process the atom
             ...
         }
         //iteration on the bonds of a component
         BondIterator bondIterator = ifc.createBondIterator();
         while (bondIterator.hasNext()){
             MolBond bond = bondIterator.nextBond();
             //process the bond
             ...
         }
     }       

 

 

Relative configuration of tetrahedral stereo centers
Previous chapter

Table of contents
 

Atom and bond-set handling
Next chapter