/// <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);
        }
Exemplo n.º 2
0
        private IRing combineRings(IRingSet ringset, int i, int j)
        {
            int c = 0;

            for (int b = 0; b < cb[i].Length; b++)
            {
                c = cb[i][b] + cb[j][b];
                if (c > 1)
                {
                    break; //at least one common bond
                }
            }
            if (c < 2)
            {
                return(null);
            }
            IRing ring  = molecule.Builder.newRing();
            IRing ring1 = (IRing)ringset.getAtomContainer(i);
            IRing ring2 = (IRing)ringset.getAtomContainer(j);

            for (int b = 0; b < cb[i].Length; b++)
            {
                c = cb[i][b] + cb[j][b];
                if ((c == 1) && (cb[i][b] == 1))
                {
                    ring.addBond(molecule.getBondAt(b));
                }
                else if ((c == 1) && (cb[j][b] == 1))
                {
                    ring.addBond(molecule.getBondAt(b));
                }
            }
            for (int a = 0; a < ring1.AtomCount; a++)
            {
                ring.addAtom(ring1.getAtomAt(a));
            }
            for (int a = 0; a < ring2.AtomCount; a++)
            {
                ring.addAtom(ring2.getAtomAt(a));
            }

            return(ring);
        }
Exemplo n.º 3
0
        /// <summary> Returns all the rings in the RingSet that share
        /// one or more atoms with a given ring.
        ///
        /// </summary>
        /// <param name="ring"> A ring with which all return rings must share one or more atoms
        /// </param>
        /// <returns>  All the rings that share one or more atoms with a given ring.
        /// </returns>

        public virtual System.Collections.IList getConnectedRings(IRing ring)
        {
            System.Collections.IList connectedRings = new System.Collections.ArrayList();
            IRing tempRing;
            IAtom atom;

            for (int i = 0; i < ring.AtomCount; i++)
            {
                atom = ring.getAtomAt(i);
                for (int j = 0; j < AtomContainerCount; j++)
                {
                    tempRing = (IRing)getAtomContainer(j);
                    if (tempRing != ring && tempRing.contains(atom))
                    {
                        connectedRings.Add(tempRing);
                    }
                }
            }
            return(connectedRings);
        }