예제 #1
0
        // compute the invariants for the first atom in a SMILES string
        static SMARTSAtomInvariants InvariantOfFirstAtom(string smiles)
        {
            var container = sp.ParseSmiles(smiles);

            SMARTSAtomInvariants.ConfigureDaylightWithRingInfo(container);
            return(container.Atoms[0].GetProperty <SMARTSAtomInvariants>(SMARTSAtomInvariants.Key));
        }
예제 #2
0
        public void RingNumber_cyclophane()
        {
            var container = sp.ParseSmiles("C1CC23CCC11CCC4(CC1)CCC(CC2)(CC3)CC4");

            SMARTSAtomInvariants.ConfigureDaylightWithRingInfo(container);
            int R1 = 0, R2 = 0, R3 = 0;

            foreach (var atom in container.Atoms)
            {
                SMARTSAtomInvariants inv = atom.GetProperty <SMARTSAtomInvariants>(SMARTSAtomInvariants.Key);
                switch (inv.RingNumber)
                {
                case 1:
                    R1++;
                    break;

                case 2:
                    R2++;
                    break;

                case 3:
                    R3++;
                    break;
                }
            }
            Assert.AreEqual(8, R1);
            Assert.AreEqual(8, R2);
            Assert.AreEqual(4, R3);
        }
예제 #3
0
        public void TargetTest()
        {
            var container = sp.ParseSmiles("CCC");

            SMARTSAtomInvariants.ConfigureDaylightWithRingInfo(container);
            foreach (var atom in container.Atoms)
            {
                Assert.AreEqual(container, (atom.GetProperty <SMARTSAtomInvariants>(SMARTSAtomInvariants.Key)).Target);
            }
        }
예제 #4
0
 /// <summary>
 /// Do not use - temporary method until the SMARTS packages are cleaned up.
 /// </summary>
 /// <remarks>
 /// Prepares a target molecule for matching with SMARTS.
 /// </remarks>
 /// <param name="container">the container to initialise</param>
 /// <param name="ringQuery">whether the smarts will check ring size queries</param>
 public static void Prepare(IAtomContainer container, bool ringQuery)
 {
     if (ringQuery)
     {
         SMARTSAtomInvariants.ConfigureDaylightWithRingInfo(container);
     }
     else
     {
         SMARTSAtomInvariants.ConfigureDaylightWithoutRingInfo(container);
     }
 }
예제 #5
0
        public void NoRingInfo()
        {
            var container = sp.ParseSmiles("C1CC23CCC11CCC4(CC1)CCC(CC2)(CC3)CC4");

            SMARTSAtomInvariants.ConfigureDaylightWithoutRingInfo(container);
            foreach (var atom in container.Atoms)
            {
                SMARTSAtomInvariants inv = atom.GetProperty <SMARTSAtomInvariants>(SMARTSAtomInvariants.Key);
                Assert.IsTrue(inv.RingSize.Count == 0);
                Assert.AreEqual(0, inv.RingNumber);
            }
        }
예제 #6
0
        public void RingSize_cyclophane()
        {
            var container = sp.ParseSmiles("C1CC23CCC11CCC4(CC1)CCC(CC2)(CC3)CC4");

            SMARTSAtomInvariants.ConfigureDaylightWithRingInfo(container);
            foreach (var atom in container.Atoms)
            {
                SMARTSAtomInvariants inv = atom.GetProperty <SMARTSAtomInvariants>(SMARTSAtomInvariants.Key);
                Assert.IsTrue(inv.RingSize.Contains(6));
                Assert.IsFalse(inv.RingSize.Contains(12));
            }
        }
예제 #7
0
        public void RingSize_imidazole()
        {
            var container = sp.ParseSmiles("N1C=NC2=CC=CC=C12");

            SMARTSAtomInvariants.ConfigureDaylightWithRingInfo(container);
            int ringSize5 = 0, ringSize6 = 0;

            foreach (var atom in container.Atoms)
            {
                SMARTSAtomInvariants inv = atom.GetProperty <SMARTSAtomInvariants>(SMARTSAtomInvariants.Key);
                if (inv.RingSize.Contains(5))
                {
                    ringSize5++;
                }
                if (inv.RingSize.Contains(6))
                {
                    ringSize6++;
                }
            }

            Assert.AreEqual(5, ringSize5);
            Assert.AreEqual(4, ringSize6);
        }
예제 #8
0
        /// <summary>
        /// Computes invariants - see <see cref="ConfigureDaylightWithRingInfo(IAtomContainer)"/>
        /// and <see cref="ConfigureDaylightWithoutRingInfo(IAtomContainer)"/>.
        /// </summary>
        /// <param name="container">the container to configure</param>
        /// <param name="graph">the graph for quick traversal</param>
        /// <param name="bondMap">the bond map for quick bond lookup</param>
        /// <param name="ringInfo">logical condition as whether ring info should be included</param>
        private static void ConfigureDaylight(IAtomContainer container, int[][] graph, EdgeToBondMap bondMap, bool ringInfo)
        {
            var nAtoms = container.Atoms.Count;

            var ringNumber = new int[nAtoms];
            var ringSize   = new int[nAtoms];

            Arrays.Fill(ringSize, nAtoms + 1);

            if (ringInfo)
            {
                // non-unique but used by daylight
                foreach (var cycle in Cycles.FindSSSR(container).GetPaths())
                {
                    var size = cycle.Length - 1;
                    for (int i = 1; i < cycle.Length; i++)
                    {
                        var v = cycle[i];
                        if (size < ringSize[v])
                        {
                            ringSize[v] = size;
                        }
                        ringNumber[v]++;
                        bondMap[cycle[i], cycle[i - 1]].IsInRing = true;
                    }
                }
            }
            else
            {
                // ring membership is super cheap
                foreach (var bond in new RingSearch(container, graph).RingFragments().Bonds)
                {
                    bond.IsInRing = true;
                }
            }

            for (int v = 0; v < nAtoms; v++)
            {
                var atom = container.Atoms[v];

                int implHCount = CheckNotNull(atom.ImplicitHydrogenCount, "Implicit hydrogen count was not set.");

                int totalHCount     = implHCount;
                int valence         = implHCount;
                int degree          = 0;
                int ringConnections = 0;

                // traverse bonds
                foreach (var w in graph[v])
                {
                    var bond  = bondMap[v, w];
                    var order = bond.Order;

                    if (order.IsUnset())
                    {
                        throw new NullReferenceException("Bond order was not set.");
                    }

                    valence += order.Numeric();

                    degree++;

                    if (bond.IsInRing)
                    {
                        ringConnections++;
                    }

                    if (container.Atoms[w].AtomicNumber == 1)
                    {
                        totalHCount++;
                    }
                }

                var inv = new SMARTSAtomInvariants(container, valence, ringNumber[v],
                                                   ringSize[v] <= nAtoms ? new int[] { ringSize[v] } : Array.Empty <int>(),
                                                   ringConnections, degree, degree + implHCount, totalHCount);

                // if there was no properties a default size LinkedHashMap is created
                // automatically
                atom.SetProperty(SMARTSAtomInvariants.Key, inv);
            }
        }