Logo Search packages:      
Sourcecode: cdk version File versions  Download package

static boolean org::openscience::cdk::graph::PathTools::depthFirstTargetSearch ( IAtomContainer  molecule,
IAtom  root,
IAtom  target,
IAtomContainer  path 
) throws NoSuchAtomException [inline, static]

Recursivly perfoms a depth first search in a molecular graphs contained in the AtomContainer molecule, starting at the root atom and returning when it hits the target atom. CAUTION: This recursive method sets the VISITED flag of each atom does not reset it after finishing the search. If you want to do the operation on the same collection of atoms more than once, you have to set all the VISITED flags to false before each operation by looping of the atoms and doing a "atom.setFlag((CDKConstants.VISITED, false));"

molecule The AtomContainer to be searched
root The root atom to start the search at
target The target
path An AtomContainer to be filled with the path
true if the target atom was found during this function call

Definition at line 160 of file PathTools.java.

References org::openscience::cdk::interfaces::IBond::getConnectedAtom(), and org::openscience::cdk::interfaces::IChemObject::getFlag().

        java.util.List bonds = molecule.getConnectedBondsList(root);
        IAtom nextAtom;
        root.setFlag(CDKConstants.VISITED, true);
        for (int f = 0; f < bonds.size(); f++) {
            IBond bond = (IBond)bonds.get(f);
            nextAtom = bond.getConnectedAtom(root);
            if (!nextAtom.getFlag(CDKConstants.VISITED)) {
                if (nextAtom == target) {
                    return true;
                } else {
                    if (!depthFirstTargetSearch(molecule, nextAtom, target, path)) {
                        // we did not find the target
                    } else {
                        return true;
        return false;

Generated by  Doxygen 1.6.0   Back to index