code: public static IAtomContainer extractSubstructure(IAtomContainer atomContainer, int... atomIndices)
              throws CloneNotSupportedException {
          IAtomContainer substructure = (IAtomContainer) atomContainer.clone();
          int numberOfAtoms = substructure.getAtomCount();
          IAtom[] atoms = new IAtom[numberOfAtoms];
          for (int atomIndex = 0; atomIndex < numberOfAtoms; atomIndex++) {
              atoms[atomIndex] = substructure.getAtom(atomIndex);
          }
  
          Arrays.sort(atomIndices);
          for (int index = 0; index < numberOfAtoms; index++) {
              if (Arrays.binarySearch(atomIndices, index) < 0) {
                  IAtom atom = atoms[index];
                  substructure.removeAtom(atom);
              }
          }
  
          return substructure;
      }
docs: Extract a substructure from an atom container, in the form of a new
  cloned atom container with only the atoms with indices in atomIndices and
  bonds that connect these atoms.
  
  Note that this may result in a disconnected atom container.
  
  @param atomContainer the source container to extract from
  @param atomIndices the indices of the substructure
  @return a cloned atom container with a substructure of the source
  @throws CloneNotSupportedException if the source container cannot be cloned