Returns Ring set based on Hanser Ring Finding method
@param molecule
@return report collected the rings
@see org.openscience.cdk.smsd.ring.RingFinder#getRingSet(org.openscience.cdk.interfaces.IAtomContainer)
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;
    }
526239
private IRing prepareRing(List vec, IAtomContainer mol) {
        // add the atoms in vec to the new ring
        int atomCount = vec.size();
        IRing ring = mol.getBuilder().newInstance(IRing.class, atomCount);
        IAtom[] atoms = new IAtom[atomCount];
        vec.toArray(atoms);
        ring.setAtoms(atoms);
        // add the bonds in mol to the new ring
        try {
            IBond b;
            for (int i = 0; i < atomCount - 1; i++) {
                b = mol.getBond(atoms[i], atoms[i + 1]);
                if (b != null) {
                    ring.addBond(b);
                } else {
                    logger.error("This should not happen.");
                }
            }
            b = mol.getBond(atoms[0], atoms[atomCount - 1]);
            if (b != null) {
                ring.addBond(b);
            } else {
                logger.error("This should not happen either.");
            }
        } catch (Exception exc) {
            logger.debug(exc);
        }
        logger.debug("found Ring  ", ring);
        return ring;
    }
453059
public IAtom getPlacedHeavyAtom(IAtomContainer molecule, IAtom atom) {
        List<IBond> bonds = molecule.getConnectedBondsList(atom);
        for (IBond bond : bonds) {
            IAtom connectedAtom = bond.getOther(atom);
            if (isPlacedHeavyAtom(connectedAtom)) {
                return connectedAtom;
            }
        }
        return null;
    }
1087558
public static void markAromaticRings(IRing ring) {
        // return as soon as the conditions are not met:
        // 1. all atoms are labeled aromatic
        for (IAtom atom : ring.atoms())
            if (!atom.getFlag(CDKConstants.ISAROMATIC)) return;

        // 2. all bonds are labeled aromatic
        for (IBond bond : ring.bonds())
            if (!bond.getFlag(CDKConstants.ISAROMATIC)) return;

        // OK, all conditions are met, so ring is aromatic
        ring.setFlag(CDKConstants.ISAROMATIC, true);
    }
437959
public IAtomContainer placeRingSubstituents(IRingSet rs, double bondLength) {
        logger.debug("RingPlacer.placeRingSubstituents() start");
        IRing ring = null;
        IAtom atom = null;
        IRingSet rings = null;
        IAtomContainer unplacedPartners = rs.getBuilder().newInstance(IAtomContainer.class);
        IAtomContainer sharedAtoms = rs.getBuilder().newInstance(IAtomContainer.class);
        IAtomContainer primaryAtoms = rs.getBuilder().newInstance(IAtomContainer.class);
        IAtomContainer treatedAtoms = rs.getBuilder().newInstance(IAtomContainer.class);
        Point2d centerOfRingGravity = null;
        for (int j = 0; j < rs.getAtomContainerCount(); j++) {
            ring = (IRing) rs.getAtomContainer(j); /*
                                                    * Get the j-th Ring in
                                                    * RingSet rs
                                                    */
            for (int k = 0; k < ring.getAtomCount(); k++) {
                unplacedPartners.removeAllElements();
                sharedAtoms.removeAllElements();
                primaryAtoms.removeAllElements();
                atom = ring.getAtom(k);
                rings = rs.getRings(atom);
                centerOfRingGravity = GeometryUtil.get2DCenter(rings);
                atomPlacer.partitionPartners(atom, unplacedPartners, sharedAtoms);
                atomPlacer.markNotPlaced(unplacedPartners);
                try {
                    for (int f = 0; f < unplacedPartners.getAtomCount(); f++) {
                        logger.debug("placeRingSubstituents->unplacedPartners: "
                                + (molecule.indexOf(unplacedPartners.getAtom(f)) + 1));
                    }
                } catch (Exception exc) {
                }

                treatedAtoms.add(unplacedPartners);
                if (unplacedPartners.getAtomCount() > 0) {
                    atomPlacer.distributePartners(atom, sharedAtoms, centerOfRingGravity, unplacedPartners, bondLength);
                }
            }
        }
        logger.debug("RingPlacer.placeRingSubstituents() end");
        return treatedAtoms;
    }
491175
public static Rectangle2D calculateBounds(IAtomContainerSet moleculeSet) {
        Rectangle2D totalBounds = new Rectangle2D.Double();
        for (int i = 0; i < moleculeSet.getAtomContainerCount(); i++) {
            IAtomContainer container = moleculeSet.getAtomContainer(i);
            Rectangle2D acBounds = calculateBounds(container);
            if (totalBounds.isEmpty()) {
                totalBounds = acBounds;
            } else {
                Rectangle2D.union(totalBounds, acBounds, totalBounds);
            }
        }
        return totalBounds;
    }
1327580
private List<Integer> getBondNosForRingGroup(IAtomContainer molecule, List<Integer> ringGroup, IRingSet ringSet) {
        List<Integer> btc = new ArrayList<Integer>();
        for (Integer i : ringGroup) {
            for (IBond bond : ringSet.getAtomContainer(i).bonds()) {
                if (btc.size() > 0) {
                    if (!btc.contains(molecule.indexOf(bond))) {
                        btc.add(molecule.indexOf(bond));
                    }
                } else {
                    btc.add(molecule.indexOf(bond));
                }
            }
        }
        return btc;
    }
1344423
public IRingSet getBasicRings() throws NoSuchAtomException {
        IRingSet ringset = molecule.getBuilder().newInstance(IRingSet.class);
        IAtomContainer spt = getSpanningTree();
        for (int i = 0; i < totalEdgeCount; i++)
            if (!bondsInTree[i]) ringset.addAtomContainer(getRing(spt, molecule.getBond(i)));
        return ringset;
    }
298238
void placeConnectedRings(IRingSet rs, IRing ring, int handleType, double bondLength) {
        final IRingSet connectedRings = rs.getConnectedRings(ring);

        //		logger.debug(rs.reportRingList(molecule));
        for (IAtomContainer container : connectedRings.atomContainers()) {
            final IRing connectedRing = (IRing) container;
            if (!connectedRing.getFlag(CDKConstants.ISPLACED)) {
                //				logger.debug(ring.toString(molecule));
                //				logger.debug(connectedRing.toString(molecule));
                final IAtomContainer sharedAtoms = AtomContainerManipulator.getIntersection(ring, connectedRing);
                final int numSharedAtoms = sharedAtoms.getAtomCount();
                logger.debug("placeConnectedRings-> connectedRing: " + (ring.toString()));
                if ((numSharedAtoms == 2 && handleType == FUSED) ||
                    (numSharedAtoms == 1 && handleType == SPIRO) ||
                    (numSharedAtoms > 2  && handleType == BRIDGED)) {

                    final Point2d sharedAtomsCenter = GeometryUtil.get2DCenter(sharedAtoms);
                    final Point2d oldRingCenter = GeometryUtil.get2DCenter(ring);
                    final Vector2d tempVector = (new Vector2d(sharedAtomsCenter));
                    final Vector2d newRingCenterVector = new Vector2d(tempVector);
                    newRingCenterVector.sub(new Vector2d(oldRingCenter));

                    // zero (or v. small ring center)
                    if (Math.abs(newRingCenterVector.x) < 0.001 && Math.abs(newRingCenterVector.y) < 0.001) {

                        // first see if we can use terminal bonds
                        IAtomContainer terminalOnly = molecule.getBuilder().newInstance(IAtomContainer.class);

                        for (IAtom atom : ring.atoms()) {
                            if (ring.getConnectedBondsCount(atom) == 1)
                                terminalOnly.addAtom(atom);
                        }

                        if (terminalOnly.getAtomCount() == 2) {
                            newRingCenterVector.set(GeometryUtil.get2DCenter(terminalOnly));
                            newRingCenterVector.sub(oldRingCenter);
                            connectedRing.setProperty(RingPlacer.SNAP_HINT, true);
                        }
                        else {
                            // project coordinates on 12 axis (30 degree snaps) and choose one with most spread
                            Vector2d vec = new Vector2d(0, 1);
                            double   bestLen = -Double.MAX_VALUE;

                            for (int i = 0; i < 12; i++) {
                                Vector2d orth = new Vector2d(-vec.y, vec.x);
                                orth.normalize();
                                double min = Double.MAX_VALUE, max = -Double.MAX_VALUE;
                                for (IAtom atom : sharedAtoms.atoms()) {
                                    // s: scalar projection
                                    double s = orth.dot(new Vector2d(atom.getPoint2d()));
                                    if (s < min)
                                        min = s;
                                    if (s > max)
                                        max = s;
                                }
                                double len = max - min;
                                if (len > bestLen) {
                                    bestLen = len;
                                    newRingCenterVector.set(vec);
                                }
                                rotate(vec, RAD_30);
                            }
                        }

                    }

                    final Vector2d oldRingCenterVector = new Vector2d(newRingCenterVector);
                    logger.debug("placeConnectedRing -> tempVector: " + tempVector + ", tempVector.length: "
                            + tempVector.length());
                    logger.debug("placeConnectedRing -> bondCenter: " + sharedAtomsCenter);
                    logger.debug("placeConnectedRing -> oldRingCenterVector.length(): " + oldRingCenterVector.length());
                    logger.debug("placeConnectedRing -> newRingCenterVector.length(): " + newRingCenterVector.length());
                    final Point2d tempPoint = new Point2d(sharedAtomsCenter);
                    tempPoint.add(newRingCenterVector);
                    placeRing(connectedRing, sharedAtoms, sharedAtomsCenter, newRingCenterVector, bondLength);
                    connectedRing.setFlag(CDKConstants.ISPLACED, true);
                    placeConnectedRings(rs, connectedRing, handleType, bondLength);
                }
            }
        }
    }
649179
public AtomContactSet getAtomContacts() {

		AtomContactSet contacts = new AtomContactSet(cutoff);

		List<Contact> list = getIndicesContacts();

		if (jAtomObjects == null) {
			for (Contact cont : list) {
				contacts.add(new AtomContact(new Pair<Atom>(iAtomObjects[cont.getI()],iAtomObjects[cont.getJ()]),cont.getDistance()));
			}

		} else {
			for (Contact cont : list) {
				contacts.add(new AtomContact(new Pair<Atom>(iAtomObjects[cont.getI()],jAtomObjects[cont.getJ()]),cont.getDistance()));
			}
		}

		return contacts;
	}
424627
public static int getAtomCount(IRingSet set) {
        int count = 0;
        for (IAtomContainer atomContainer : set.atomContainers()) {
            count += atomContainer.getAtomCount();
        }
        return count;
    }
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;
    }
1173809
private IRingSet removeExtraRings(IAtomContainer m) throws Exception {

        IRingSet rs = Cycles.sssr(m).toRingSet();

        //remove rings which dont have all aromatic atoms (according to hybridization set by lower case symbols in smiles):
        Iterator<IAtomContainer> i = rs.atomContainers().iterator();
        while (i.hasNext()) {
            IRing r = (IRing) i.next();
            if (r.getAtomCount() > 8) {
                i.remove();
            } else {
                for (IAtom a : r.atoms()) {
                    Hybridization h = a.getHybridization();
                    if (h == CDKConstants.UNSET || !(h == Hybridization.SP2 || h == Hybridization.PLANAR3)) {
                        i.remove();
                        break;
                    }
                }
            }
        }
        return rs;
    }
909233
public static IAtomContainer convertToAtomContainer(IRingSet ringSet) {
        IRing ring = (IRing) ringSet.getAtomContainer(0);
        if (ring == null) return null;
        IAtomContainer ac = ring.getBuilder().newInstance(IAtomContainer.class);
        for (int i = 0; i < ringSet.getAtomContainerCount(); i++) {
            ring = (IRing) ringSet.getAtomContainer(i);
            for (int r = 0; r < ring.getBondCount(); r++) {
                IBond bond = ring.getBond(r);
                if (!ac.contains(bond)) {
                    for (int j = 0; j < bond.getAtomCount(); j++) {
                        ac.addAtom(bond.getAtom(j));
                    }
                    ac.addBond(bond);
                }
            }
        }
        return ac;
    }
725771
public static double calculate(IAtomContainer molecule) throws CDKException {
        if (atomTypeList == null) {
            atomTypeList = AtomTypeFactory.getInstance("org/openscience/cdk/dict/data/cdk-atom-types.owl",
                    molecule.getBuilder() // take whatever we got first
                    );
        }

        double sum = 0.0;
        int totalHCount = 0;
        for (IAtom atom : molecule.atoms()) {
            Double bondiiVolume = bondiiVolumes.get(atom.getSymbol());
            if (bondiiVolume == null) throw new CDKException("Unsupported element.");

            sum += bondiiVolume;

            // add volumes of implicit hydrogens?
            IAtomType type = atomTypeList.getAtomType(atom.getAtomTypeName());
            if (type == null) throw new CDKException("Unknown atom type for atom: " + atom.getSymbol());
            if (type.getFormalNeighbourCount() == null)
                throw new CDKException("Formal neighbor count not given for : " + type.getAtomTypeName());
            int hCount = type.getFormalNeighbourCount() - molecule.getConnectedBondsCount(atom);
            sum += (hCount * bondiiVolumes.get("H"));
            totalHCount += hCount;
        }
        sum -= 5.92 * (molecule.getBondCount() + totalHCount);

        boolean[] originalFlags = molecule.getFlags();
        Aromaticity.cdkLegacy().apply(molecule);
        IRingSet ringSet = Cycles.sssr(molecule).toRingSet();
        if (ringSet.getAtomContainerCount() > 0) {
            int aromRingCount = 0;
            int nonAromRingCount = 0;
            for (IAtomContainer ring : ringSet.atomContainers()) {
                if (ringIsAromatic(ring)) {
                    aromRingCount++;
                } else {
                    nonAromRingCount++;
                }
            }
            molecule.setFlags(originalFlags);
            sum -= 14.7 * aromRingCount;
            sum -= 3.8 * nonAromRingCount;
        }

        return sum;
    }
434238
private IAtomContainer getAllPlacedAtoms(IAtomContainer molecule) {
        IAtomContainer placedAtoms = new AtomContainer();
        for (int i = 0; i < molecule.getAtomCount(); i++) {
            if (molecule.getAtom(i).getFlag(CDKConstants.ISPLACED)) {
                placedAtoms.addAtom(molecule.getAtom(i));
            }
        }
        return placedAtoms;
    }
1282083
def detect_aromatic_rings_in_ligand(self):
        """"""
        self.ligrings = {}
        try:
            ring_info = self.topology_data.mol.GetRingInfo()
            self.ligand_ring_num = ring_info.NumRings()
        except Exception as e:
            m = Chem.MolFromPDBFile("lig.pdb")
            ring_info = m.GetRingInfo()
            self.ligand_ring_num = ring_info.NumRings()
        i=0
        for ring in range(self.ligand_ring_num):
            if 4 < len(ring_info.AtomRings()[ring]) <= 6 and  False not in [self.topology_data.mol.GetAtomWithIdx(x).GetIsAromatic() for x in ring_info.AtomRings()[ring]]: #narrow ring definition
                atom_ids_in_ring = []
                for atom in ring_info.AtomRings()[ring]:
                    atom_ids_in_ring.append(self.topology_data.universe.ligand.atoms[atom].name)
                self.ligrings[i]=atom_ids_in_ring
                i+=1