code: public static boolean depthFirstTargetSearch(IAtomContainer molecule, IAtom root, IAtom target, IAtomContainer path) {
          List<IBond> bonds = molecule.getConnectedBondsList(root);
          IAtom nextAtom;
          root.setFlag(CDKConstants.VISITED, true);
          boolean first = path.isEmpty();
          if (first)
              path.addAtom(root);
          for (IBond bond : bonds) {
              nextAtom = bond.getOther(root);
              if (!nextAtom.getFlag(CDKConstants.VISITED)) {
                  path.addAtom(nextAtom);
                  path.addBond(bond);
                  if (nextAtom.equals(target)) {
                      if (first)
                          path.removeAtomOnly(root);
                      return true;
                  } else {
                      if (!depthFirstTargetSearch(molecule, nextAtom, target, path)) {
                          // we did not find the target
                          path.removeAtomOnly(nextAtom);
                          path.removeBond(bond);
                      } else {
                          if (first)
                              path.removeAtomOnly(root);
                          return true;
                      }
                  }
              }
          }
          if (first)
              path.removeAtomOnly(root);
          return false;
      }
docs: Recursively performs 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.
  <p>
  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));"
  <p>
  Note that the path generated by the search will not contain the root atom,
  but will contain the target atom
  
  @param molecule The AtomContainer to be searched
  @param root     The root atom to start the search at
  @param target   The target
  @param path     An AtomContainer to be filled with the path
  @return true if the target atom was found during this function call