/// <summary> Partitions the atoms in an AtomContainer into covalently connected components.
        ///
        /// </summary>
        /// <param name="atomContainer"> The AtomContainer to be partitioned into connected components, i.e. molecules
        /// </param>
        /// <returns>                 A SetOfMolecules.
        ///
        /// </returns>
        /// <cdk.dictref>    blue-obelisk:graphPartitioning </cdk.dictref>
        public static ISetOfMolecules partitionIntoMolecules(IAtomContainer atomContainer)
        {
            IAtomContainer     ac         = atomContainer.Builder.newAtomContainer();
            IAtom              atom       = null;
            IElectronContainer eContainer = null;
            IMolecule          molecule   = null;
            ISetOfMolecules    molecules  = atomContainer.Builder.newSetOfMolecules();

            System.Collections.ArrayList sphere = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
            for (int f = 0; f < atomContainer.AtomCount; f++)
            {
                atom = atomContainer.getAtomAt(f);
                atom.setFlag(CDKConstants.VISITED, false);
                ac.addAtom(atom);
            }
            IElectronContainer[] eContainers = atomContainer.ElectronContainers;
            for (int f = 0; f < eContainers.Length; f++)
            {
                eContainer = eContainers[f];
                eContainer.setFlag(CDKConstants.VISITED, false);
                ac.addElectronContainer(eContainer);
            }
            while (ac.AtomCount > 0)
            {
                atom     = ac.getAtomAt(0);
                molecule = atomContainer.Builder.newMolecule();
                sphere.Clear();
                sphere.Add(atom);
                atom.setFlag(CDKConstants.VISITED, true);
                PathTools.breadthFirstSearch(ac, sphere, molecule);
                molecules.addMolecule(molecule);
                ac.remove(molecule);
            }
            return(molecules);
        }
        /// <summary>  Uses precomputed set of ALL rings and performs an aromaticity detection
        /// based on Hueckels 4n + 2 rule.
        ///
        /// </summary>
        /// <param name="ringSet">                set of ALL rings
        /// </param>
        /// <param name="removeAromaticityFlags"> Leaves ChemObjects that are already marked as
        /// aromatic as they are
        /// </param>
        /// <param name="atomContainer">          AtomContainer to be searched for rings
        /// </param>
        /// <returns>                         True, if molecules contains an
        /// aromatic feature
        /// </returns>
        public static bool detectAromaticity(IAtomContainer atomContainer, IRingSet ringSet, bool removeAromaticityFlags)
        {
            bool foundSomething = false;

            if (removeAromaticityFlags)
            {
                for (int f = 0; f < atomContainer.AtomCount; f++)
                {
                    atomContainer.getAtomAt(f).setFlag(CDKConstants.ISAROMATIC, false);
                }
                for (int f = 0; f < atomContainer.ElectronContainerCount; f++)
                {
                    IElectronContainer electronContainer = atomContainer.getElectronContainerAt(f);
                    if (electronContainer is IBond)
                    {
                        electronContainer.setFlag(CDKConstants.ISAROMATIC, false);
                    }
                }
                for (int f = 0; f < ringSet.AtomContainerCount; f++)
                {
                    ((IRing)ringSet.getAtomContainer(f)).setFlag(CDKConstants.ISAROMATIC, false);
                }
            }

            IRing ring = null;

            RingSetManipulator.sort(ringSet);
            for (int f = 0; f < ringSet.AtomContainerCount; f++)
            {
                ring = (IRing)ringSet.getAtomContainer(f);
                //logger.debug("Testing for aromaticity in ring no ", f);
                if (AromaticityCalculator.isAromatic(ring, atomContainer))
                {
                    ring.setFlag(CDKConstants.ISAROMATIC, true);

                    for (int g = 0; g < ring.AtomCount; g++)
                    {
                        ring.getAtomAt(g).setFlag(CDKConstants.ISAROMATIC, true);
                    }

                    for (int g = 0; g < ring.ElectronContainerCount; g++)
                    {
                        IElectronContainer electronContainer = ring.getElectronContainerAt(g);
                        if (electronContainer is IBond)
                        {
                            electronContainer.setFlag(CDKConstants.ISAROMATIC, true);
                        }
                    }

                    foundSomething = true;
                    //logger.debug("This ring is aromatic: ", f);
                }
                else
                {
                    //logger.debug("This ring is *not* aromatic: ", f);
                }
            }
            return(foundSomething);
        }