Beispiel #1
0
        /// <summary>  Checks the pathes if a ring has been found
        ///
        /// </summary>
        /// <param name="pathes">  The pathes to check for rings
        /// </param>
        /// <param name="ringSet"> The ringset to add the detected rings to
        /// </param>
        /// <param name="ac">      The AtomContainer with the original structure
        /// </param>
        private void detectRings(System.Collections.ArrayList pathes, IRingSet ringSet, IAtomContainer ac)
        {
            Path  path = null;
            IRing ring = null;
            IBond bond = null;

            for (int f = 0; f < pathes.Count; f++)
            {
                path = (Path)pathes[f];
                if (path.Count > 3 && path[path.Count - 1] == path[0])
                {
                    if (debug)
                    {
                        System.Console.Out.WriteLine("Removing path " + path.toString(originalAc) + " which is a ring.");
                    }
                    path.RemoveAt(0);
                    ring = ac.Builder.newRing();
                    for (int g = 0; g < path.Count; g++)
                    {
                        ring.addAtom((IAtom)path[g]);
                    }
                    IBond[] bonds = ac.Bonds;
                    for (int g = 0; g < bonds.Length; g++)
                    {
                        bond = bonds[g];
                        if (ring.contains(bond.getAtomAt(0)) && ring.contains(bond.getAtomAt(1)))
                        {
                            ring.addBond(bond);
                        }
                    }
                    ringSet.addAtomContainer(ring);
                }
            }
        }
 /// <summary> Checks if <code>atom1</code> and <code>atom2</code> share membership in the same ring or ring system.
 /// Membership in the same ring is checked if the RingSet contains the SSSR of a molecule; membership in
 /// the same ring or same ring system is checked if the RingSet contains all rings of a molecule.<BR><BR>
 ///
 /// <p><B>Important:</B> This method only returns meaningful results if <code>atom1</code> and
 /// <code>atom2</code> are members of the same molecule for which the RingSet was calculated!
 ///
 /// </summary>
 /// <param name="atom1">  The first atom
 /// </param>
 /// <param name="atom2">  The second atom
 /// </param>
 /// <returns> boolean true if <code>atom1</code> and <code>atom2</code> share membership of at least one ring or ring system, false otherwise
 /// </returns>
 public static bool isSameRing(IRingSet ringSet, IAtom atom1, IAtom atom2)
 {
     IAtomContainer[] rings = ringSet.AtomContainers;
     for (int i = 0; i < rings.Length; i++)
     {
         IRing ring = (IRing)rings[i];
         if (ring.contains(atom1))
         {
             if (ring.contains(atom2))
             {
                 return(true);
             }
         }
     }
     return(false);
 }
        /// <summary>  Tests the <code>ring</code> in the <code>molecule</code> for aromaticity. Uses the
        /// H&uuml;ckle rule (4n + 2) pie electrons. sp<sup>2</sup> hybridized C contibute 1 electron non
        /// sp<sup>2</sup> hybridized heteroatoms contribute 2 electrons (N and O should never be sp in
        /// or anything else in a ring and d electron elements get to complicated)
        /// sp<sup>2</sup> hybridized heteroatoms contribute 1 electron hybridization is worked out by
        /// counting the number of bonds with order 2. Therefore sp<sup>2</sup> hybridization is assumed
        /// if there is one bond of order 2. Otherwise sp<sup>3</sup> hybridization is assumed.
        ///
        /// </summary>
        /// <param name="ring">     the ring to test
        /// </param>
        /// <param name="atomContainer"> the AtomContainer the ring is in
        /// </param>
        /// <returns>           true if the ring is aromatic false otherwise.
        /// </returns>
        protected internal static bool isAromatic(IRing ring, IAtomContainer atomContainer)
        {
            IAtom[] ringAtoms = ring.Atoms;
            int     eCount    = 0;

            IBond[] conectedBonds;
            int     numDoubleBond = 0;
            bool    allConnectedBondsSingle;

            for (int i = 0; i < ringAtoms.Length; i++)
            {
                IAtom atom = ringAtoms[i];
                numDoubleBond           = 0;
                allConnectedBondsSingle = true;
                conectedBonds           = atomContainer.getConnectedBonds(atom);
                for (int j = 0; j < conectedBonds.Length; j++)
                {
                    IBond bond = conectedBonds[j];
                    if (bond.Order == 2 && ring.contains(bond))
                    {
                        numDoubleBond++;
                    }
                    // Count the Electron if bond order = 1.5
                    else if (bond.Order == 1.5 && ring.contains(bond))
                    {
                        numDoubleBond = 1;
                    }

                    if (bond.Order != 1)
                    {
                        allConnectedBondsSingle = false;
                    }
                }
                if (numDoubleBond == 1)
                {
                    //C or heteroatoms both contibute 1 electron in sp2 hybridized form
                    eCount++;
                }
                else if (!atom.Symbol.Equals("C"))
                {
                    //Heteroatom probably in sp3 hybrid therefore 2 electrons contributed.
                    eCount = eCount + 2;
                }
                else if (atom.getFlag(CDKConstants.ISAROMATIC))
                {
                    eCount++;
                }
                else if (allConnectedBondsSingle && atom.Symbol.Equals("C") && atom.getFormalCharge() == 1.0)
                {
                    // This is for tropylium and kinds.
                    // Dependence on hybridisation would be better:
                    // empty p-orbital is needed
                    continue;
                }
                else
                {
                    return(false);
                }
            }
            if (eCount - 2 != 0 && (eCount - 2) % 4 == 0)
            {
                return(true);
            }
            return(false);
        }
        /// <summary>  Tests the <code>ring</code> in the <code>molecule</code> for aromaticity. Uses the 
        /// H&uuml;ckle rule (4n + 2) pie electrons. sp<sup>2</sup> hybridized C contibute 1 electron non 
        /// sp<sup>2</sup> hybridized heteroatoms contribute 2 electrons (N and O should never be sp in 
        /// or anything else in a ring and d electron elements get to complicated) 
        /// sp<sup>2</sup> hybridized heteroatoms contribute 1 electron hybridization is worked out by
        /// counting the number of bonds with order 2. Therefore sp<sup>2</sup> hybridization is assumed 
        /// if there is one bond of order 2. Otherwise sp<sup>3</sup> hybridization is assumed.
        /// 
        /// </summary>
        /// <param name="ring">     the ring to test
        /// </param>
        /// <param name="atomContainer"> the AtomContainer the ring is in
        /// </param>
        /// <returns>           true if the ring is aromatic false otherwise.
        /// </returns>
        protected internal static bool isAromatic(IRing ring, IAtomContainer atomContainer)
        {

            IAtom[] ringAtoms = ring.Atoms;
            int eCount = 0;
            IBond[] conectedBonds;
            int numDoubleBond = 0;
            bool allConnectedBondsSingle;

            for (int i = 0; i < ringAtoms.Length; i++)
            {
                IAtom atom = ringAtoms[i];
                numDoubleBond = 0;
                allConnectedBondsSingle = true;
                conectedBonds = atomContainer.getConnectedBonds(atom);
                for (int j = 0; j < conectedBonds.Length; j++)
                {
                    IBond bond = conectedBonds[j];
                    if (bond.Order == 2 && ring.contains(bond))
                    {
                        numDoubleBond++;
                    }
                    // Count the Electron if bond order = 1.5
                    else if (bond.Order == 1.5 && ring.contains(bond))
                    {
                        numDoubleBond = 1;
                    }

                    if (bond.Order != 1)
                    {
                        allConnectedBondsSingle = false;
                    }
                }
                if (numDoubleBond == 1)
                {
                    //C or heteroatoms both contibute 1 electron in sp2 hybridized form
                    eCount++;
                }
                else if (!atom.Symbol.Equals("C"))
                {
                    //Heteroatom probably in sp3 hybrid therefore 2 electrons contributed.
                    eCount = eCount + 2;
                }
                else if (atom.getFlag(CDKConstants.ISAROMATIC))
                {
                    eCount++;
                }
                else if (allConnectedBondsSingle && atom.Symbol.Equals("C") && atom.getFormalCharge() == 1.0)
                {
                    // This is for tropylium and kinds. 
                    // Dependence on hybridisation would be better:
                    // empty p-orbital is needed
                    continue;
                }
                else
                {
                    return false;
                }
            }
            if (eCount - 2 != 0 && (eCount - 2) % 4 == 0)
            {
                return true;
            }
            return false;
        }