Exemplo n.º 1
0
        public void TestCNSPcore()
        {
            var filename = "NCDK.Data.MDL.cnssmarts.sdf";
            var ins      = ResourceLoader.GetAsStream(filename);
            var reader   = new EnumerableSDFReader(ins, CDK.Builder);

            var query = new PharmacophoreQuery();
            var arom  = new PharmacophoreQueryAtom("A", "c1ccccc1");
            var n1    = new PharmacophoreQueryAtom("BasicAmine", "[NX3;h2,h1,H1,H2;!$(NC=O)]");
            var b1    = new PharmacophoreQueryBond(arom, n1, 5.0, 7.0);

            query.Atoms.Add(arom);
            query.Atoms.Add(n1);
            query.Bonds.Add(b1);

            var mol = reader.First();

            reader.Close();

            var matcher = new PharmacophoreMatcher(query);
            var status  = matcher.Matches(mol);

            Assert.IsTrue(status);

            var pmatches = matcher.GetMatchingPharmacophoreAtoms();

            Assert.AreEqual(1, pmatches.Count);

            var upmatches = matcher.GetUniqueMatchingPharmacophoreAtoms();

            Assert.AreEqual(1, upmatches.Count);
        }
Exemplo n.º 2
0
        public void TestAngleMatch2()
        {
            var filename = "NCDK.Data.MDL.cnssmarts.sdf";
            var ins      = ResourceLoader.GetAsStream(filename);
            var reader   = new EnumerableSDFReader(ins, CDK.Builder);

            var query = new PharmacophoreQuery();
            var n1    = new PharmacophoreQueryAtom("BasicAmine", "[NX3;h2,h1,H1,H2;!$(NC=O)]");
            var n2    = new PharmacophoreQueryAtom("BasicAmine", "[NX3;h2,h1,H1,H2;!$(NC=O)]");
            var n3    = new PharmacophoreQueryAtom("BasicAmine", "[NX3;h2,h1,H1,H2;!$(NC=O)]");
            var b1    = new PharmacophoreQueryAngleBond(n1, n2, n3, 89.14);

            query.Atoms.Add(n1);
            query.Atoms.Add(n2);
            query.Atoms.Add(n3);
            query.Bonds.Add(b1);

            var mol = reader.First();

            reader.Close();

            var matcher = new PharmacophoreMatcher(query);
            var status  = matcher.Matches(mol);

            Assert.IsTrue(status);
        }
Exemplo n.º 3
0
        public void TestMatcherQuery1()
        {
            Assert.IsNotNull(conformers);

            // make a query
            var query = new PharmacophoreQuery();

            var o  = new PharmacophoreQueryAtom("D", "[OX1]");
            var n1 = new PharmacophoreQueryAtom("A", "[N]");
            var n2 = new PharmacophoreQueryAtom("A", "[N]");

            query.Atoms.Add(o);
            query.Atoms.Add(n1);
            query.Atoms.Add(n2);

            var b1 = new PharmacophoreQueryBond(o, n1, 4.0, 4.5);
            var b2 = new PharmacophoreQueryBond(o, n2, 4.0, 5.0);
            var b3 = new PharmacophoreQueryBond(n1, n2, 5.4, 5.8);

            query.Bonds.Add(b1);
            query.Bonds.Add(b2);
            query.Bonds.Add(b3);

            var matcher = new PharmacophoreMatcher(query);

            bool firstTime = true;
            int  i         = 0;
            var  statuses  = new bool[100];

            foreach (var conf in conformers)
            {
                if (firstTime)
                {
                    statuses[i] = matcher.Matches(conf, true);
                    firstTime   = false;
                }
                else
                {
                    statuses[i] = matcher.Matches(conf, false);
                }
                i++;
            }

            var hits = new int[18];
            int idx  = 0;

            for (i = 0; i < statuses.Length; i++)
            {
                if (statuses[i])
                {
                    hits[idx++] = i;
                }
            }

            int[] expected = { 0, 1, 2, 5, 6, 7, 8, 9, 10, 20, 23, 48, 62, 64, 66, 70, 76, 87 };
            for (i = 0; i < expected.Length; i++)
            {
                Assert.AreEqual(expected[i], hits[i], $"Hit {i} didn't match");
            }
        }
Exemplo n.º 4
0
        /* process a single pcore definition */
        private static PharmacophoreQuery ProcessPharmacophoreElement(XElement e, Dictionary <string, string> global)
        {
            PharmacophoreQuery ret = new PharmacophoreQuery();

            ret.SetProperty("description", e.Attribute("description")?.Value);
            ret.Title = e.Attribute("name")?.Value;

            // first get any local group definitions
            Dictionary <string, string> local = GetGroupDefinitions(e);

            // now lets look at the constraints
            var children = e.Elements();

            foreach (var child in children)
            {
                if (string.Equals(child.Name.LocalName, "distanceConstraint", StringComparison.Ordinal))
                {
                    ProcessDistanceConstraint(child, local, global, ret);
                }
                else if (string.Equals(child.Name.LocalName, "angleConstraint", StringComparison.Ordinal))
                {
                    ProcessAngleConstraint(child, local, global, ret);
                }
            }
            return(ret);
        }
Exemplo n.º 5
0
        public void TestAngleMatch3()
        {
            Assert.IsNotNull(conformers);

            // make a query
            var query = new PharmacophoreQuery();

            var o  = new PharmacophoreQueryAtom("D", "[OX1]");
            var n1 = new PharmacophoreQueryAtom("A", "[N]");
            var n2 = new PharmacophoreQueryAtom("A", "[N]");

            query.Atoms.Add(o);
            query.Atoms.Add(n1);
            query.Atoms.Add(n2);
            var b1 = new PharmacophoreQueryAngleBond(o, n1, n2, 43, 47);

            query.Bonds.Add(b1);

            var matcher = new PharmacophoreMatcher(query);

            bool firstTime = true;
            int  i         = 0;
            var  statuses  = new bool[100];

            foreach (var conf in conformers)
            {
                if (firstTime)
                {
                    statuses[i] = matcher.Matches(conf, true);
                    firstTime   = false;
                }
                else
                {
                    statuses[i] = matcher.Matches(conf, false);
                }
                i++;
            }
            Assert.AreEqual(100, statuses.Length);

            var hits = new int[9];
            int idx  = 0;

            for (i = 0; i < statuses.Length; i++)
            {
                if (statuses[i])
                {
                    hits[idx++] = i;
                }
            }

            int[] expected = { 0, 6, 32, 33, 48, 54, 60, 62, 69 };
            for (i = 0; i < expected.Length; i++)
            {
                Assert.AreEqual(expected[i], hits[i], $"Hit {i} didn't match");
            }
        }
Exemplo n.º 6
0
 private static bool ContainsPatom(PharmacophoreQuery q, string id)
 {
     foreach (var queryAtom in q.Atoms)
     {
         if (queryAtom.Symbol.Equals(id, StringComparison.Ordinal))
         {
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 7
0
        public void TestMatchedBonds()
        {
            Assert.IsNotNull(conformers);

            // make a query
            var query = new PharmacophoreQuery();

            var o  = new PharmacophoreQueryAtom("D", "[OX1]");
            var n1 = new PharmacophoreQueryAtom("A", "[N]");
            var n2 = new PharmacophoreQueryAtom("A", "[N]");

            query.Atoms.Add(o);
            query.Atoms.Add(n1);
            query.Atoms.Add(n2);

            var b1 = new PharmacophoreQueryBond(o, n1, 4.0, 4.5);
            var b2 = new PharmacophoreQueryBond(o, n2, 4.0, 5.0);
            var b3 = new PharmacophoreQueryBond(n1, n2, 5.4, 5.8);

            query.Bonds.Add(b1);
            query.Bonds.Add(b2);
            query.Bonds.Add(b3);

            var  conf1   = conformers[0];
            var  matcher = new PharmacophoreMatcher(query);
            bool status  = matcher.Matches(conf1);

            Assert.IsTrue(status);

            var bMatches = matcher.GetMatchingPharmacophoreBonds();

            Assert.AreEqual(2, bMatches.Count); // 2 since we haven't gotten a unique set
            Assert.AreEqual(3, bMatches[0].Count);

            var pbond  = (PharmacophoreBond)BondRef.Deref(bMatches[0][0]);
            var patom1 = (PharmacophoreAtom)AtomRef.Deref(pbond.Begin);
            var patom2 = (PharmacophoreAtom)AtomRef.Deref(pbond.End);

            Assert.AreEqual("D", patom1.Symbol);
            Assert.AreEqual("A", patom2.Symbol);

            var bondMap = matcher.GetTargetQueryBondMappings();

            Assert.AreEqual(2, bondMap.Count);
            var mapping = bondMap[0];

            // get the 'BondRef' for lookup
            var value = mapping[bMatches[0][0]];

            Assert.AreEqual(b1, value);
        }
Exemplo n.º 8
0
        public void TestGetterSetter()
        {
            var query = new PharmacophoreQuery();
            var arom  = new PharmacophoreQueryAtom("A", "c1ccccc1");
            var n1    = new PharmacophoreQueryAtom("BasicAmine", "[NX3;h2,h1,H1,H2;!$(NC=O)]");
            var b1    = new PharmacophoreQueryBond(arom, n1, 5.0, 7.0);

            query.Atoms.Add(arom);
            query.Atoms.Add(n1);
            query.Bonds.Add(b1);

            var matcher = new PharmacophoreMatcher();

            matcher.SetPharmacophoreQuery(query);
            var retQuery = matcher.GetPharmacophoreQuery();

            Assert.AreEqual(2, retQuery.Atoms.Count);
            Assert.AreEqual(1, retQuery.Bonds.Count);
        }
Exemplo n.º 9
0
        public void TestMatchingBonds()
        {
            var filename = "NCDK.Data.MDL.cnssmarts.sdf";
            var ins      = ResourceLoader.GetAsStream(filename);
            EnumerableSDFReader reader = new EnumerableSDFReader(ins, CDK.Builder);

            PharmacophoreQuery     query = new PharmacophoreQuery();
            PharmacophoreQueryAtom arom  = new PharmacophoreQueryAtom("A", "c1ccccc1");
            PharmacophoreQueryAtom n1    = new PharmacophoreQueryAtom("BasicAmine", "[NX3;h2,h1,H1,H2;!$(NC=O)]");
            PharmacophoreQueryBond b1    = new PharmacophoreQueryBond(arom, n1, 5.0, 7.0);

            query.Atoms.Add(arom);
            query.Atoms.Add(n1);
            query.Bonds.Add(b1);

            IAtomContainer mol = (IAtomContainer)reader.First();

            reader.Close();

            PharmacophoreMatcher matcher = new PharmacophoreMatcher(query);
            bool status = matcher.Matches(mol);

            Assert.IsTrue(status);

            var pmatches = matcher.GetMatchingPharmacophoreAtoms();

            Assert.AreEqual(1, pmatches.Count);

            var upmatches = matcher.GetUniqueMatchingPharmacophoreAtoms();

            Assert.AreEqual(1, upmatches.Count);

            var bmatches = matcher.GetMatchingPharmacophoreBonds();

            Assert.AreEqual(1, bmatches.Count);
            var bmatch = bmatches[0];

            Assert.AreEqual(1, bmatch.Count);
            PharmacophoreBond pbond = (PharmacophoreBond)BondRef.Deref(bmatch[0]);

            Assert.AreEqual(5.63, pbond.BondLength, 0.01);
        }
Exemplo n.º 10
0
        public PharmacophoreQueryTest()
        {
            query = new PharmacophoreQuery();

            PharmacophoreQueryAtom o  = new PharmacophoreQueryAtom("D", "[OX1]");
            PharmacophoreQueryAtom n1 = new PharmacophoreQueryAtom("A", "[N]");
            PharmacophoreQueryAtom n2 = new PharmacophoreQueryAtom("A", "[N]");

            query.Atoms.Add(o);
            query.Atoms.Add(n1);
            query.Atoms.Add(n2);

            PharmacophoreQueryBond b1 = new PharmacophoreQueryBond(o, n1, 4.0, 4.5);
            PharmacophoreQueryBond b2 = new PharmacophoreQueryBond(o, n2, 4.0, 5.0);
            PharmacophoreQueryBond b3 = new PharmacophoreQueryBond(n1, n2, 5.4, 5.8);

            query.Bonds.Add(b1);
            query.Bonds.Add(b2);
            query.Bonds.Add(b3);
        }
Exemplo n.º 11
0
        public void MultiSmartsQuery()
        {
            var query = new PharmacophoreQuery();
            var rings = new PharmacophoreQueryAtom("A", "c1ccccc1|C1CCCC1");
            var o1    = new PharmacophoreQueryAtom("Hd", "[OX1]");
            var b1    = new PharmacophoreQueryBond(rings, o1, 3.5, 5.8);

            query.Atoms.Add(rings);
            query.Atoms.Add(o1);
            query.Bonds.Add(b1);

            var matcher = new PharmacophoreMatcher();

            matcher.SetPharmacophoreQuery(query);

            var filename   = "NCDK.Data.PCore.multismartpcore.sdf";
            var ins        = ResourceLoader.GetAsStream(filename);
            var reader     = new EnumerableSDFReader(ins, CDK.Builder);
            var enumerator = reader.GetEnumerator();

            enumerator.MoveNext();
            var mol = enumerator.Current;

            Assert.IsTrue(matcher.Matches(mol));
            Assert.AreEqual(1, matcher.GetUniqueMatchingPharmacophoreAtoms().Count);
            Assert.AreEqual(2, matcher.GetUniqueMatchingPharmacophoreAtoms()[0].Count);

            enumerator.MoveNext();
            mol = enumerator.Current;
            Assert.IsTrue(matcher.Matches(mol));
            Assert.AreEqual(2, matcher.GetUniqueMatchingPharmacophoreAtoms().Count);
            Assert.AreEqual(2, matcher.GetUniqueMatchingPharmacophoreAtoms()[0].Count);
            Assert.AreEqual(2, matcher.GetUniqueMatchingPharmacophoreAtoms()[1].Count);

            enumerator.MoveNext();
            mol = enumerator.Current;
            reader.Close();
            Assert.IsFalse(matcher.Matches(mol));
        }
Exemplo n.º 12
0
        public void TestInvalidQuery()
        {
            var query = new PharmacophoreQuery();
            var o     = new PharmacophoreQueryAtom("D", "[OX1]");
            var n1    = new PharmacophoreQueryAtom("A", "[N]");
            var n2    = new PharmacophoreQueryAtom("A", "[NX3]");

            query.Atoms.Add(o);
            query.Atoms.Add(n1);
            query.Atoms.Add(n2);

            var b1 = new PharmacophoreQueryBond(o, n1, 4.0, 4.5);
            var b2 = new PharmacophoreQueryBond(o, n2, 4.0, 5.0);
            var b3 = new PharmacophoreQueryBond(n1, n2, 5.4, 5.8);

            query.Bonds.Add(b1);
            query.Bonds.Add(b2);
            query.Bonds.Add(b3);

            var matcher = new PharmacophoreMatcher(query);

            matcher.Matches(conformers[0]);
        }
Exemplo n.º 13
0
        public void TestMatchedAtoms()
        {
            Assert.IsNotNull(conformers);

            // make a query
            var query = new PharmacophoreQuery();

            var o  = new PharmacophoreQueryAtom("D", "[OX1]");
            var n1 = new PharmacophoreQueryAtom("A", "[N]");
            var n2 = new PharmacophoreQueryAtom("A", "[N]");

            query.Atoms.Add(o);
            query.Atoms.Add(n1);
            query.Atoms.Add(n2);

            var b1 = new PharmacophoreQueryBond(o, n1, 4.0, 4.5);
            var b2 = new PharmacophoreQueryBond(o, n2, 4.0, 5.0);
            var b3 = new PharmacophoreQueryBond(n1, n2, 5.4, 5.8);

            query.Bonds.Add(b1);
            query.Bonds.Add(b2);
            query.Bonds.Add(b3);

            var  conf1   = conformers[0];
            var  matcher = new PharmacophoreMatcher(query);
            bool status  = matcher.Matches(conf1);

            Assert.IsTrue(status);

            var pmatches = matcher.GetMatchingPharmacophoreAtoms();

            Assert.AreEqual(2, pmatches.Count);

            var upmatches = matcher.GetUniqueMatchingPharmacophoreAtoms();

            Assert.AreEqual(1, upmatches.Count);
        }
Exemplo n.º 14
0
 /// <summary>
 /// Set a pharmacophore query.
 /// </summary>
 /// <param name="query">The query</param>
 public void SetPharmacophoreQuery(PharmacophoreQuery query)
 {
     pharmacophoreQuery = query;
 }
Exemplo n.º 15
0
 /// <summary>
 /// Initialize the matcher with a query.
 /// </summary>
 /// <param name="pharmacophoreQuery">The query pharmacophore</param>
 /// <seealso cref="PharmacophoreQueryAtom"/>
 /// <seealso cref="PharmacophoreQueryBond"/>
 public PharmacophoreMatcher(PharmacophoreQuery pharmacophoreQuery)
 {
     this.pharmacophoreQuery = pharmacophoreQuery;
 }
Exemplo n.º 16
0
        private static void ProcessAngleConstraint(XElement child, Dictionary <string, string> local,
                                                   Dictionary <string, string> global, PharmacophoreQuery ret)
        {
            double     lower;
            XAttribute tmp;

            tmp = child.Attribute("lower");
            if (tmp == null)
            {
                throw new CDKException("Must have a 'lower' attribute");
            }
            else
            {
                lower = double.Parse(tmp.Value, NumberFormatInfo.InvariantInfo);
            }

            // we may not have an upper bound specified
            double upper;

            tmp = child.Attribute("upper");
            if (tmp != null)
            {
                upper = double.Parse(tmp.Value, NumberFormatInfo.InvariantInfo);
            }
            else
            {
                upper = lower;
            }

            // now get the three groups for this distance
            var grouprefs = child.Elements().ToReadOnlyList();

            if (grouprefs.Count != 3)
            {
                throw new CDKException("An angle constraint can only refer to 3 groups.");
            }
            string id1 = grouprefs[0].Attribute("id")?.Value;
            string id2 = grouprefs[1].Attribute("id")?.Value;
            string id3 = grouprefs[2].Attribute("id")?.Value;

            // see if it's a local def, else get it from the global list
            string smarts1, smarts2, smarts3;

            if (local.ContainsKey(id1))
            {
                smarts1 = local[id1];
            }
            else if (global.ContainsKey(id1))
            {
                smarts1 = global[id1];
            }
            else
            {
                throw new CDKException("Referring to a non-existant group definition");
            }

            if (local.ContainsKey(id2))
            {
                smarts2 = local[id2];
            }
            else if (global.ContainsKey(id2))
            {
                smarts2 = global[id2];
            }
            else
            {
                throw new CDKException("Referring to a non-existant group definition");
            }

            if (local.ContainsKey(id3))
            {
                smarts3 = local[id3];
            }
            else if (global.ContainsKey(id3))
            {
                smarts3 = global[id3];
            }
            else
            {
                throw new CDKException("Referring to a non-existant group definition");
            }

            // now see if we already have a correpsondiong pcore atom
            // else create a new atom
            if (!ContainsPatom(ret, id1))
            {
                PharmacophoreQueryAtom pqa = new PharmacophoreQueryAtom(id1, smarts1);
                ret.Atoms.Add(pqa);
            }
            if (!ContainsPatom(ret, id2))
            {
                PharmacophoreQueryAtom pqa = new PharmacophoreQueryAtom(id2, smarts2);
                ret.Atoms.Add(pqa);
            }
            if (!ContainsPatom(ret, id3))
            {
                PharmacophoreQueryAtom pqa = new PharmacophoreQueryAtom(id3, smarts3);
                ret.Atoms.Add(pqa);
            }

            // now add the constraint as a bond
            IAtom a1 = null, a2 = null;
            IAtom a3 = null;

            foreach (var queryAtom in ret.Atoms)
            {
                if (queryAtom.Symbol.Equals(id1, StringComparison.Ordinal))
                {
                    a1 = queryAtom;
                }
                if (queryAtom.Symbol.Equals(id2, StringComparison.Ordinal))
                {
                    a2 = queryAtom;
                }
                if (queryAtom.Symbol.Equals(id3, StringComparison.Ordinal))
                {
                    a3 = queryAtom;
                }
            }
            ret.Bonds.Add(new PharmacophoreQueryAngleBond((PharmacophoreQueryAtom)a1, (PharmacophoreQueryAtom)a2,
                                                          (PharmacophoreQueryAtom)a3, lower, upper));
        }
Exemplo n.º 17
0
 /// <summary>
 /// Write out one or more pharmacophore queries in the CDK XML format.
 /// </summary>
 /// <param name="query">The pharmacophore queries</param>
 /// <param name="output">The Stream to write to</param>
 /// <exception cref="IOException">if there is a problem writing the XML document</exception>
 public static void WritePharmacophoreDefinition(PharmacophoreQuery query, Stream output)
 {
     WritePharmacophoreDefinition(new PharmacophoreQuery[] { query }, output);
 }