Recovers a RingSet corresponding to a AtomContainer that has been
stored by storeRingSystem().

@param mol      The IAtomContainer for which to recover the IRingSet.
999
private IRingSet recoverRingSystem(IAtomContainer mol) {
        IRingSet ringSet = mol.getBuilder().newInstance(IRingSet.class);
        for (Integer[] bondNumbers : listOfRings) {
            IRing ring = mol.getBuilder().newInstance(IRing.class, bondNumbers.length);
            for (int bondNumber : bondNumbers) {
                IBond bond = mol.getBond(bondNumber);
                ring.addBond(bond);
                if (!ring.contains(bond.getBegin())) ring.addAtom(bond.getBegin());
                if (!ring.contains(bond.getEnd())) ring.addAtom(bond.getEnd());
            }
            ringSet.addAtomContainer(ring);
        }
        return ringSet;
    }
277554
private IAtomContainer getMoleculeFromID(IAtomContainerSet molSet, String id) {
        for (IAtomContainer mol : molSet.atomContainers()) {
            if (mol.getID().equals(id)) return mol;
        }
        return null;
    }
309625
private List<Integer> getAttachedInOrder(IRing macrocycle, IAtomContainer shared) {
        List<Integer> ringAttach = new ArrayList<>();
        Set<IAtom> visit = new HashSet<>();
        IAtom atom = shared.getAtom(0);
        while (atom != null) {
            visit.add(atom);
            ringAttach.add(macrocycle.indexOf(atom));
            List<IAtom> connected = shared.getConnectedAtomsList(atom);
            atom = null;
            for (IAtom neighbor : connected) {
                if (!visit.contains(neighbor)) {
                    atom = neighbor;
                    break;
                }
            }
        }
        return ringAttach;
    }
274766
public static List<IChemObject> getAllChemObjects(IAtomContainerSet set) {
        ArrayList<IChemObject> list = new ArrayList<IChemObject>();
        list.add(set);
        for (IAtomContainer atomContainer : set.atomContainers()) {
            list.add(atomContainer);
        }
        return list;
    }
895169
private IQueryAtom matchExact(final IAtomContainer mol, final IAtom atom) {
        final IChemObjectBuilder bldr = atom.getBuilder();

        int elem = atom.getAtomicNumber();

        // attach atom skipped
        if (elem == 0)
            return null;

        int hcnt = atom.getImplicitHydrogenCount();
        int val = hcnt;
        int con = hcnt;

        for (IBond bond : mol.getConnectedBondsList(atom)) {
            val += bond.getOrder().numeric();
            con++;
            if (bond.getOther(atom).getAtomicNumber() == 1)
                hcnt++;
        }

        Expr expr = new Expr(Expr.Type.ELEMENT, elem)
                .and(new Expr(Expr.Type.TOTAL_DEGREE, con))
                .and(new Expr(Expr.Type.TOTAL_H_COUNT, hcnt))
                .and(new Expr(Expr.Type.VALENCE, val));
        return new QueryAtom(expr);
    }
418964
public static MarkedElement markupMol(IRenderingElement elem, IAtomContainer mol) {
        assert elem != null;
        MarkedElement tagElem = markupChemObj(elem, mol);
        tagElem.aggClass("mol");
        return tagElem;
    }
1188323
public static void removeElectronContainer(IChemModel chemModel, IElectronContainer electrons) {
        ICrystal crystal = chemModel.getCrystal();
        if (crystal != null) {
            if (crystal.contains(electrons)) {
                crystal.removeElectronContainer(electrons);
            }
            return;
        }
        IAtomContainerSet moleculeSet = chemModel.getMoleculeSet();
        if (moleculeSet != null) {
            MoleculeSetManipulator.removeElectronContainer(moleculeSet, electrons);
        }
        IReactionSet reactionSet = chemModel.getReactionSet();
        if (reactionSet != null) {
            ReactionSetManipulator.removeElectronContainer(reactionSet, electrons);
        }
    }
891797
public IAtomContainer getUnsetAtomsInAtomContainer(IAtom atom, IAtomContainer ac) {
        List atoms = ac.getConnectedAtomsList(atom);
        IAtomContainer connectedAtoms = atom.getBuilder().newInstance(IAtomContainer.class);
        for (int i = 0; i < atoms.size(); i++) {
            IAtom curAtom = (IAtom) atoms.get(i);
            if (!curAtom.getFlag(CDKConstants.ISPLACED)) {//&& atoms[i].getPoint3d() == null) {
                connectedAtoms.addAtom(curAtom);
            }
        }
        return connectedAtoms;
    }
3693
@Override
    public IRingSet getRingSet(IAtomContainer molecule) throws CDKException {

        Collection<List<IAtom>> cycles = findRings(molecule);

        IRingSet ringSet = molecule.getBuilder().newInstance(IRingSet.class);

        for (List<IAtom> ringAtoms : cycles) {
            IRing ring = molecule.getBuilder().newInstance(IRing.class);
            for (IAtom atom : ringAtoms) {
                atom.setFlag(CDKConstants.ISINRING, true);
                ring.addAtom(atom);
                for (IAtom atomNext : ringAtoms) {
                    if (!atom.equals(atomNext)) {
                        IBond bond = molecule.getBond(atom, atomNext);
                        if (bond != null) {
                            bond.setFlag(CDKConstants.ISINRING, true);
                            ring.addElectronContainer(bond);
                        }
                    }
                }
            }
            ringSet.addAtomContainer(ring);
        }
        return ringSet;
    }
1245836
public IAtomContainer getPlacedHeavyAtoms(IAtomContainer molecule, IAtom atom) {

        List<IBond> bonds = molecule.getConnectedBondsList(atom);
        IAtomContainer connectedAtoms = molecule.getBuilder().newInstance(IAtomContainer.class);
        IAtom connectedAtom = null;
        for (IBond bond : bonds) {
            connectedAtom = bond.getOther(atom);
            if (isPlacedHeavyAtom(connectedAtom)) {
                connectedAtoms.addAtom(connectedAtom);
            }
        }
        return connectedAtoms;
    }
332864
public IRingSet getLargestRingSet(List<IRingSet> ringSystems) {
        IRingSet       largestRingSet = null;
        int            atomNumber     = 0;
        IAtomContainer container      = null;
        for (int i = 0; i < ringSystems.size(); i++) {
            container = getAllInOneContainer(ringSystems.get(i));
            if (atomNumber < container.getAtomCount()) {
                atomNumber = container.getAtomCount();
                largestRingSet = ringSystems.get(i);
            }
        }
        return largestRingSet;
    }
1144541
private void prepareCoords(Iterable<IAtomContainer> mols) throws CDKException {
        for (IAtomContainer mol : mols) {
            if (!ensure2dLayout(mol) && mol.getBondCount() > 0) {
                final double factor = GeometryUtil.getScaleFactor(mol, 1.5);
                GeometryUtil.scaleMolecule(mol, factor);
            }
        }
    }
424627
public static int getAtomCount(IRingSet set) {
        int count = 0;
        for (IAtomContainer atomContainer : set.atomContainers()) {
            count += atomContainer.getAtomCount();
        }
        return count;
    }
1017830
public static void sort(IRingSet ringSet) {
        List<IRing> ringList = new ArrayList<IRing>();
        for (IAtomContainer atomContainer : ringSet.atomContainers()) {
            ringList.add((IRing) atomContainer);
        }
        Collections.sort(ringList, new RingSizeComparator(RingSizeComparator.SMALL_FIRST));
        ringSet.removeAllAtomContainers();
        for (IAtomContainer aRingList : ringList)
            ringSet.addAtomContainer(aRingList);

    }
126867
public IAtom getPlacedHeavyAtomInAtomContainer(IAtom atomA, IAtom atomB, IAtomContainer ac) {
        List atoms = ac.getConnectedAtomsList(atomA);
        IAtom atom = null;
        for (int i = 0; i < atoms.size(); i++) {
            IAtom curAtom = (IAtom) atoms.get(i);
            if (curAtom.getFlag(CDKConstants.ISPLACED) && !curAtom.getSymbol().equals("H") && !Objects.equals(curAtom, atomB)) {
                return curAtom;
            }
        }
        return atom;
    }
511338
private List<IAtomContainer> toList(IAtomContainerSet frags) {
        return new ArrayList<>(FluentIterable.from(frags.atomContainers()).toList());
    }
1157570
private IRingSet getRingSetOfAtom(List ringSystems, IAtom atom) {
        IRingSet ringSetOfAtom = null;
        for (int i = 0; i < ringSystems.size(); i++) {
            if (((IRingSet) ringSystems.get(i)).contains(atom)) {
                return (IRingSet) ringSystems.get(i);
            }
        }
        return ringSetOfAtom;
    }