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 
) [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));"

Note that the path generated by the search will not contain the root atom, but will contain the target atom

Parameters:
moleculeThe AtomContainer to be searched
rootThe root atom to start the search at
targetThe target
pathAn AtomContainer to be filled with the path
Returns:
true if the target atom was found during this function call

Definition at line 163 of file PathTools.java.

References org::openscience::cdk::interfaces::IChemObject::getFlag(), org::openscience::cdk::interfaces::IChemObject::setFlag(), and org::openscience::cdk::CDKConstants::VISITED.

Referenced by org::openscience::cdk::tools::GenerateFragments::generateMurckoFragments().

                                                                                                                         {
        java.util.List<IBond> bonds = molecule.getConnectedBondsList(root);
        IAtom nextAtom;
        root.setFlag(CDKConstants.VISITED, true);
        for (IBond bond : bonds) {
            nextAtom = bond.getConnectedAtom(root);            
            if (!nextAtom.getFlag(CDKConstants.VISITED)) {
                path.addAtom(nextAtom);
                path.addBond(bond);
                if (nextAtom == target) {
                    return true;
                } else {
                    if (!depthFirstTargetSearch(molecule, nextAtom, target, path)) {
                        // we did not find the target
                        path.removeAtom(nextAtom);
                        path.removeBond(bond);
                    } else {
                        return true;
                    }
                }
            }
        }
        return false;
    }

Here is the call graph for this function:

Here is the caller graph for this function:


Generated by  Doxygen 1.6.0   Back to index