// minimum details


        /// <summary>  Partitions a RingSet into RingSets of connected rings. Rings which share
        /// an Atom, a Bond or three or more atoms with at least on other ring in
        /// the RingSet are considered connected.
        ///
        /// </summary>
        /// <param name="ringSet"> The RingSet to be partitioned
        /// </param>
        /// <returns>          A Vector of connected RingSets
        /// </returns>
        public static System.Collections.ArrayList partitionRings(IRingSet ringSet)
        {
            System.Collections.ArrayList ringSets = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
            if (ringSet.AtomContainerCount == 0)
            {
                return(ringSets);
            }
            IRingSet tempRingSet = null;
            IRing    ring        = (IRing)ringSet.getAtomContainer(0);

            if (ring == null)
            {
                return(ringSets);
            }
            IRingSet rs = ring.Builder.newRingSet();

            for (int f = 0; f < ringSet.AtomContainerCount; f++)
            {
                rs.addAtomContainer(ringSet.getAtomContainer(f));
            }
            do
            {
                ring = (IRing)rs.getAtomContainer(0);
                IRingSet newRs = ring.Builder.newRingSet();
                newRs.addAtomContainer(ring);
                tempRingSet = walkRingSystem(rs, ring, newRs);
                if (debug)
                {
                    System.Console.Out.WriteLine("found ringset with ringcount: " + tempRingSet.AtomContainerCount);
                }
                ringSets.Add(walkRingSystem(rs, ring, newRs));
            }while (rs.AtomContainerCount > 0);

            return(ringSets);
        }
        /// <summary>  Converts a RingSet to an AtomContainer.
        ///
        /// </summary>
        /// <param name="ringSet"> The RingSet to be converted.
        /// </param>
        /// <returns>          The AtomContainer containing the bonds and atoms of the ringSet.
        /// </returns>
        public static IAtomContainer convertToAtomContainer(IRingSet ringSet)
        {
            IRing ring = (IRing)ringSet.getAtomContainer(0);

            if (ring == null)
            {
                return(null);
            }
            IAtomContainer ac = ring.Builder.newAtomContainer();

            for (int i = 0; i < ringSet.AtomContainerCount; i++)
            {
                ring = (IRing)ringSet.getAtomContainer(i);
                for (int r = 0; r < ring.getBondCount(); r++)
                {
                    IBond bond = ring.getBondAt(r);
                    if (!ac.contains(bond))
                    {
                        for (int j = 0; j < bond.AtomCount; j++)
                        {
                            ac.addAtom(bond.getAtomAt(j));
                        }
                        ac.addBond(bond);
                    }
                }
            }
            return(ac);
        }
        // minimum details


        /// <summary>  Partitions a RingSet into RingSets of connected rings. Rings which share
        /// an Atom, a Bond or three or more atoms with at least on other ring in
        /// the RingSet are considered connected.
        /// 
        /// </summary>
        /// <param name="ringSet"> The RingSet to be partitioned
        /// </param>
        /// <returns>          A Vector of connected RingSets
        /// </returns>
        public static System.Collections.ArrayList partitionRings(IRingSet ringSet)
        {
            System.Collections.ArrayList ringSets = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
            if (ringSet.AtomContainerCount == 0)
                return ringSets;
            IRingSet tempRingSet = null;
            IRing ring = (IRing)ringSet.getAtomContainer(0);
            if (ring == null)
                return ringSets;
            IRingSet rs = ring.Builder.newRingSet();
            for (int f = 0; f < ringSet.AtomContainerCount; f++)
            {
                rs.addAtomContainer(ringSet.getAtomContainer(f));
            }
            do
            {
                ring = (IRing)rs.getAtomContainer(0);
                IRingSet newRs = ring.Builder.newRingSet();
                newRs.addAtomContainer(ring);
                tempRingSet = walkRingSystem(rs, ring, newRs);
                if (debug)
                {
                    System.Console.Out.WriteLine("found ringset with ringcount: " + tempRingSet.AtomContainerCount);
                }
                ringSets.Add(walkRingSystem(rs, ring, newRs));
            }
            while (rs.AtomContainerCount > 0);

            return ringSets;
        }
        /// <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);
        }
Exemple #5
0
 /// <summary> Adds all rings of another RingSet if they are not allready part of this ring set.
 ///
 /// </summary>
 /// <param name="ringSet"> the ring set to be united with this one.
 /// </param>
 public virtual void add(IRingSet ringSet)
 {
     for (int f = 0; f < ringSet.AtomContainerCount; f++)
     {
         if (!contains((IRing)ringSet.getAtomContainer(f)))
         {
             addAtomContainer(ringSet.getAtomContainer(f));
         }
     }
 }
        /// <summary> Returns the ring with the highest numbers of other rings attached to it.
        ///
        /// </summary>
        /// <returns> the ring with the highest numbers of other rings attached to it.
        /// </returns>
        public static IRing getMostComplexRing(IRingSet ringSet)
        {
            int[] neighbors = new int[ringSet.AtomContainerCount];
            IRing ring1, ring2;
            IAtom atom1, atom2;
            int   mostComplex = 0, mostComplexPosition = 0;

            /* for all rings in this RingSet */
            for (int i = 0; i < ringSet.AtomContainerCount; i++)
            {
                /* Take each ring */
                ring1 = (IRing)ringSet.getAtomContainer(i);
                /* look at each Atom in this ring whether it is part of any other ring */
                for (int j = 0; j < ring1.AtomCount; j++)
                {
                    atom1 = ring1.getAtomAt(j);
                    /* Look at each of the other rings in the ringset */
                    for (int k = i + 1; k < ringSet.AtomContainerCount; k++)
                    {
                        ring2 = (IRing)ringSet.getAtomContainer(k);
                        if (ring1 != ring2)
                        {
                            for (int l = 0; l < ring2.AtomCount; l++)
                            {
                                atom2 = ring2.getAtomAt(l);
                                if (atom1 == atom2)
                                {
                                    neighbors[i]++;
                                    neighbors[k]++;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            for (int i = 0; i < neighbors.Length; i++)
            {
                if (neighbors[i] > mostComplex)
                {
                    mostComplex         = neighbors[i];
                    mostComplexPosition = i;
                }
            }
            return((IRing)ringSet.getAtomContainer(mostComplexPosition));
        }
Exemple #7
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);
        }
 /// <summary> Returns all the atoms and bonds from all the rings in the RingSet 
 /// in one AtomContainer.
 /// 
 /// </summary>
 /// <returns> an AtomContainer with all atoms and bonds from the RingSet
 /// 
 /// </returns>
 /// <deprecated> This method has a serious performace impact. Try to use
 /// other methods.
 /// </deprecated>
 public static IAtomContainer getAllInOneContainer(IRingSet ringSet)
 {
     // FIXME: make RingSet a subclass of IChemObject (see bug #) and clean up
     // the code in the next line
     IAtomContainer container = ringSet.Builder.newAtomContainer();
     for (int i = 0; i < ringSet.AtomContainerCount; i++)
     {
         container.add((IRing)ringSet.getAtomContainer(i));
     }
     return container;
 }
        /// <summary> Returns all the atoms and bonds from all the rings in the RingSet
        /// in one AtomContainer.
        ///
        /// </summary>
        /// <returns> an AtomContainer with all atoms and bonds from the RingSet
        ///
        /// </returns>
        /// <deprecated> This method has a serious performace impact. Try to use
        /// other methods.
        /// </deprecated>
        public static IAtomContainer getAllInOneContainer(IRingSet ringSet)
        {
            // FIXME: make RingSet a subclass of IChemObject (see bug #) and clean up
            // the code in the next line
            IAtomContainer container = ringSet.Builder.newAtomContainer();

            for (int i = 0; i < ringSet.AtomContainerCount; i++)
            {
                container.add((IRing)ringSet.getAtomContainer(i));
            }
            return(container);
        }
 /// <summary>  Returns the geometric center of all the rings in this ringset.
 /// See comment for center(IAtomContainer atomCon, Dimension areaDim, HashMap renderingCoordinates) for details on coordinate sets
 /// 
 /// </summary>
 /// <param name="ringSet"> Description of the Parameter
 /// </param>
 /// <returns>          the geometric center of the rings in this ringset
 /// </returns>
 public static Point2d get2DCenter(IRingSet ringSet)
 {
     double centerX = 0;
     double centerY = 0;
     for (int i = 0; i < ringSet.AtomContainerCount; i++)
     {
         Point2d centerPoint = GeometryTools.get2DCenter((IRing)ringSet.getAtomContainer(i));
         centerX += centerPoint.x;
         centerY += centerPoint.y;
     }
     Point2d point = new Point2d(centerX / ((double)ringSet.AtomContainerCount), centerY / ((double)ringSet.AtomContainerCount));
     return point;
 }
        /// <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;
        }
        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;
        }
 /// <summary>  Converts a RingSet to an AtomContainer.
 /// 
 /// </summary>
 /// <param name="ringSet"> The RingSet to be converted.
 /// </param>
 /// <returns>          The AtomContainer containing the bonds and atoms of the ringSet.
 /// </returns>
 public static IAtomContainer convertToAtomContainer(IRingSet ringSet)
 {
     IRing ring = (IRing)ringSet.getAtomContainer(0);
     if (ring == null)
         return null;
     IAtomContainer ac = ring.Builder.newAtomContainer();
     for (int i = 0; i < ringSet.AtomContainerCount; i++)
     {
         ring = (IRing)ringSet.getAtomContainer(i);
         for (int r = 0; r < ring.getBondCount(); r++)
         {
             IBond bond = ring.getBondAt(r);
             if (!ac.contains(bond))
             {
                 for (int j = 0; j < bond.AtomCount; j++)
                 {
                     ac.addAtom(bond.getAtomAt(j));
                 }
                 ac.addBond(bond);
             }
         }
     }
     return ac;
 }
 /// <summary> Returns the ring with the highest numbers of other rings attached to it.
 /// 
 /// </summary>
 /// <returns> the ring with the highest numbers of other rings attached to it.    
 /// </returns>
 public static IRing getMostComplexRing(IRingSet ringSet)
 {
     int[] neighbors = new int[ringSet.AtomContainerCount];
     IRing ring1, ring2;
     IAtom atom1, atom2;
     int mostComplex = 0, mostComplexPosition = 0;
     /* for all rings in this RingSet */
     for (int i = 0; i < ringSet.AtomContainerCount; i++)
     {
         /* Take each ring */
         ring1 = (IRing)ringSet.getAtomContainer(i);
         /* look at each Atom in this ring whether it is part of any other ring */
         for (int j = 0; j < ring1.AtomCount; j++)
         {
             atom1 = ring1.getAtomAt(j);
             /* Look at each of the other rings in the ringset */
             for (int k = i + 1; k < ringSet.AtomContainerCount; k++)
             {
                 ring2 = (IRing)ringSet.getAtomContainer(k);
                 if (ring1 != ring2)
                 {
                     for (int l = 0; l < ring2.AtomCount; l++)
                     {
                         atom2 = ring2.getAtomAt(l);
                         if (atom1 == atom2)
                         {
                             neighbors[i]++;
                             neighbors[k]++;
                             break;
                         }
                     }
                 }
             }
         }
     }
     for (int i = 0; i < neighbors.Length; i++)
     {
         if (neighbors[i] > mostComplex)
         {
             mostComplex = neighbors[i];
             mostComplexPosition = i;
         }
     }
     return (IRing)ringSet.getAtomContainer(mostComplexPosition);
 }