code: public static int breadthFirstTargetSearch(IAtomContainer atomContainer, List<IAtom> sphere, IAtom target,
              int pathLength, int cutOff) {
          if (pathLength == 0) resetFlags(atomContainer);
          pathLength++;
          if (pathLength > cutOff) {
              return -1;
          }
  
          IAtom nextAtom;
          List<IAtom> newSphere = new ArrayList<IAtom>();
          for (IAtom atom : sphere) {
              List<IBond> bonds = atomContainer.getConnectedBondsList(atom);
              for (IBond bond : bonds) {
                  if (!bond.getFlag(CDKConstants.VISITED)) {
                      bond.setFlag(CDKConstants.VISITED, true);
                  }
                  nextAtom = bond.getOther(atom);
                  if (!nextAtom.getFlag(CDKConstants.VISITED)) {
                      if (nextAtom.equals(target)) {
                          return pathLength;
                      }
                      newSphere.add(nextAtom);
                      nextAtom.setFlag(CDKConstants.VISITED, true);
                  }
              }
          }
          if (newSphere.size() > 0) {
              return breadthFirstTargetSearch(atomContainer, newSphere, target, pathLength, cutOff);
          }
          return -1;
      }
docs: Performs a breadthFirstTargetSearch in an AtomContainer starting with a
  particular sphere, which usually consists of one start atom. While
  searching the graph, the method marks each visited atom. It then puts all
  the atoms connected to the atoms in the given sphere into a new vector
  which forms the sphere to search for the next recursive method call.
  The method keeps track of the sphere count and returns it as soon
  as the target atom is encountered.
  
  @param atomContainer The AtomContainer in which the path search is to be performed.
  @param sphere        The sphere of atoms to start with. Usually just the starting atom
  @param target        The target atom to be searched
  @param pathLength    The current path length, incremented and passed in recursive calls. Call this method with "zero".
  @param cutOff        Stop the path search when this cutOff sphere count has been reatomContainerhed
  @return The shortest path between the starting sphere and the target atom