code: private IAtomContainer toFragment(int[] vertices) {
  
          int n = vertices.length;
  
          Set<IAtom> atoms = new HashSet<IAtom>(n > 3 ? n + 1 + n / 3 : n);
          List<IBond> bonds = new ArrayList<IBond>();
  
          // fill the atom set
          for (int v : vertices) {
              atoms.add(container.getAtom(v));
          }
  
          // include bonds that have both atoms in the atoms set
          for (IBond bond : container.bonds()) {
              IAtom either = bond.getBegin();
              IAtom other = bond.getEnd();
              if (atoms.contains(either) && atoms.contains(other)) {
                  bonds.add(bond);
              }
          }
  
          IAtomContainer fragment = container.getBuilder().newInstance(IAtomContainer.class, 0, 0, 0, 0);
  
          fragment.setAtoms(atoms.toArray(new IAtom[n]));
          fragment.setBonds(bonds.toArray(new IBond[bonds.size()]));
  
          return fragment;
      }
docs: Utility method for creating a fragment from an array of vertices
  
  @param vertices array of vertices length=cycle weight, values 0 ...
  nAtoms
  @return atom container only containing the specified atoms (and bonds)