Example #1
0
        public void TestToString()
        {
            PharmacophoreQueryAtom qatom = new PharmacophoreQueryAtom("aromatic", "c1ccccc1");
            string repr = qatom.ToString();

            Assert.AreEqual("aromatic [c1ccccc1]", repr);
        }
        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");
            }
        }
Example #3
0
 /// <summary>
 /// Create a query angle constraint between three query groups.
 /// </summary>
 /// <remarks>
 /// Note that the angle is only considered upto 2 decimal places.
 /// </remarks>
 /// <param name="atom1">The first pharmacophore group</param>
 /// <param name="atom2">The second pharmacophore group</param>
 /// <param name="atom3">The third pharmacophore group</param>
 /// <param name="lower">The lower bound of the angle between the three groups</param>
 /// <param name="upper">The upper bound of the angle between the three groups</param>
 public PharmacophoreQueryAngleBond(PharmacophoreQueryAtom atom1, PharmacophoreQueryAtom atom2,
                                    PharmacophoreQueryAtom atom3, double lower, double upper)
     : base(new IAtom[] { atom1, atom2, atom3 })
 {
     this.upper = Round(upper, 2);
     this.lower = Round(lower, 2);
 }
Example #4
0
 /// <summary>
 /// Create a query angle constraint between three query groups.
 /// <para>
 /// This constructor allows you to define a query angle constraint
 /// such that the angle between the three query groups is exact
 /// (i.e., not a range).
 /// </para>
 /// </summary>
 /// <remarks>
 /// Note that the angle is only considered upto 2 decimal places.
 /// </remarks>
 /// <param name="atom1">The first pharmacophore group</param>
 /// <param name="atom2">The second pharmacophore group</param>
 /// <param name="atom3">The third pharmacophore group</param>
 /// <param name="angle">The exact angle between the two groups</param>
 public PharmacophoreQueryAngleBond(PharmacophoreQueryAtom atom1, PharmacophoreQueryAtom atom2,
                                    PharmacophoreQueryAtom atom3, double angle)
     : base(new PharmacophoreQueryAtom[] { atom1, atom2, atom3 })
 {
     this.upper = Round(angle, 2);
     this.lower = Round(angle, 2);
 }
        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);
        }
        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);
        }
Example #7
0
        private static PharmacophoreAtom NewPCoreAtom(IAtomContainer input, PharmacophoreQueryAtom qatom, string smarts, int[] mapping)
        {
            var coords = GetEffectiveCoordinates(input, mapping);
            var patom  = new PharmacophoreAtom(smarts, qatom.Symbol, coords);

            // n.b. mapping[] copy is mad by pcore atom
            patom.SetMatchingAtoms(mapping);
            return(patom);
        }
        public void TestToString()
        {
            PharmacophoreQueryAtom qatom1 = new PharmacophoreQueryAtom("Amine", "[CX2]N");
            PharmacophoreQueryAtom qatom2 = new PharmacophoreQueryAtom("aromatic", "c1ccccc1");
            PharmacophoreQueryBond qbond1 = new PharmacophoreQueryBond(qatom1, qatom2, 1.0, 2.0);
            string repr = qbond1.ToString();

            Assert.AreEqual("DC::Amine [[CX2]N]::aromatic [c1ccccc1]::[1.0 - 2.0] ", repr);
        }
        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");
            }
        }
        public void TestLower()
        {
            PharmacophoreQueryAtom qatom1 = new PharmacophoreQueryAtom("Amine", "[CX2]N");
            PharmacophoreQueryAtom qatom2 = new PharmacophoreQueryAtom("aromatic", "c1ccccc1");
            PharmacophoreQueryBond qbond1 = new PharmacophoreQueryBond(qatom1, qatom2, 1.0, 2.0);
            PharmacophoreQueryBond qbond2 = new PharmacophoreQueryBond(qatom1, qatom2, 1.732);

            Assert.AreEqual(1.0, qbond1.GetLower(), 0.01);
            Assert.AreEqual(1.732, qbond2.GetLower(), 0.01);
        }
        public void TestToString()
        {
            PharmacophoreQueryAtom      qatom1 = new PharmacophoreQueryAtom("Amine", "[CX2]N");
            PharmacophoreQueryAtom      qatom2 = new PharmacophoreQueryAtom("aromatic", "c1ccccc1");
            PharmacophoreQueryAtom      qatom3 = new PharmacophoreQueryAtom("blah", "C");
            PharmacophoreQueryAngleBond qbond1 = new PharmacophoreQueryAngleBond(qatom1, qatom2, qatom3, 54.735);
            string repr = qbond1.ToString();

            Assert.AreEqual(repr, "AC::Amine [[CX2]N]::aromatic [c1ccccc1]::blah [C]::[54.74 - 54.74] ");
        }
        public void TestLower()
        {
            PharmacophoreQueryAtom      qatom1 = new PharmacophoreQueryAtom("Amine", "[CX2]N");
            PharmacophoreQueryAtom      qatom2 = new PharmacophoreQueryAtom("aromatic", "c1ccccc1");
            PharmacophoreQueryAtom      qatom3 = new PharmacophoreQueryAtom("blah", "C");
            PharmacophoreQueryAngleBond qbond1 = new PharmacophoreQueryAngleBond(qatom1, qatom2, qatom3, 54.735);
            PharmacophoreQueryAngleBond qbond2 = new PharmacophoreQueryAngleBond(qatom1, qatom2, qatom3, 50, 60);

            Assert.AreEqual(54.74, qbond1.GetLower(), 0.01);
            Assert.AreEqual(50.00, qbond2.GetLower(), 0.01);
        }
        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);
        }
        static void Main()
        {
            var matcher = new PharmacophoreMatcher();

            #region
            QueryAtomContainer query = new QueryAtomContainer(ChemObjectBuilder.Instance);

            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);

            string filename = "/Users/rguha/pcore1.sdf";
            using (var srm = new FileStream(filename, FileMode.Open))
            {
                foreach (var conformers in new IEnumerableMDLConformerReader(srm, ChemObjectBuilder.Instance))
                {
                    bool firstTime = true;
                    foreach (var conf in conformers)
                    {
                        bool status;
                        if (firstTime)
                        {
                            status    = matcher.Matches(conf, true);
                            firstTime = false;
                        }
                        else
                        {
                            status = matcher.Matches(conf, false);
                        }
                        if (status)
                        {
                            // OK, matched. Do something
                        }
                    }
                    #endregion
                }
            }
        }
Example #15
0
        public void TestMatches()
        {
            PharmacophoreQueryAtom qatom = new PharmacophoreQueryAtom("aromatic", "c1ccccc1");

            PharmacophoreAtom patom1 = new PharmacophoreAtom("c1ccccc1", "aromatic", Vector3.Zero);
            PharmacophoreAtom patom2 = new PharmacophoreAtom("c1ccccc1", "hydrophobic", Vector3.Zero);
            PharmacophoreAtom patom3 = new PharmacophoreAtom("Cc1ccccc1", "aromatic", Vector3.Zero);
            PharmacophoreAtom patom4 = new PharmacophoreAtom("[CX2]N", "amine", Vector3.Zero);

            Assert.IsTrue(qatom.Matches(patom1));
            Assert.IsFalse(qatom.Matches(patom2));

            Assert.IsTrue(qatom.Matches(patom3));
            Assert.IsFalse(qatom.Matches(patom4));
        }
        public void TestMatches()
        {
            PharmacophoreAtom patom1 = new PharmacophoreAtom("[CX2]N", "Amine", Vector3.Zero);
            PharmacophoreAtom patom2 = new PharmacophoreAtom("c1ccccc1", "Aromatic", new Vector3(1, 1, 1));
            PharmacophoreBond pbond  = new PharmacophoreBond(patom1, patom2);

            PharmacophoreQueryAtom qatom1 = new PharmacophoreQueryAtom("Amine", "[CX2]N");
            PharmacophoreQueryAtom qatom2 = new PharmacophoreQueryAtom("aromatic", "c1ccccc1");
            PharmacophoreQueryBond qbond1 = new PharmacophoreQueryBond(qatom1, qatom2, 1.0, 2.0);
            PharmacophoreQueryBond qbond2 = new PharmacophoreQueryBond(qatom1, qatom2, 1.732);
            PharmacophoreQueryBond qbond3 = new PharmacophoreQueryBond(qatom1, qatom2, 0.1, 1.0);

            Assert.IsTrue(qbond1.Matches(pbond));
            Assert.IsTrue(qbond2.Matches(pbond));
            Assert.IsFalse(qbond3.Matches(pbond));
        }
        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);
        }
Example #18
0
        /// <summary>
        /// string representation of this query.
        /// </summary>
        /// <returns>string representation of this query</returns>
        public override string ToString()
        {
            var stringBuilder = new StringBuilder();

            stringBuilder.Append("PharmacophoreQuery(").Append(this.GetHashCode()).Append(", ");
            stringBuilder.Append("#A:").Append(Atoms.Count).Append(", ");
            stringBuilder.Append("#EC:").Append(GetElectronContainers().Count()).Append(", ");
            foreach (var atom in Atoms)
            {
                PharmacophoreQueryAtom qatom = (PharmacophoreQueryAtom)atom;
                stringBuilder.Append(qatom.Symbol).Append(", ");
            }
            foreach (var bond in Bonds)
            {
                stringBuilder.Append(bond.ToString()).Append(", ");
            }
            stringBuilder.Append(')');
            return(stringBuilder.ToString());
        }
Example #19
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);
        }
        public void TestMatches()
        {
            PharmacophoreAtom      patom1 = new PharmacophoreAtom("[CX2]N", "Amine", new Vector3(1, 1, 1));
            PharmacophoreAtom      patom2 = new PharmacophoreAtom("c1ccccc1", "Aromatic", Vector3.Zero);
            PharmacophoreAtom      patom3 = new PharmacophoreAtom("C", "Blah", new Vector3(1, 0, 0));
            PharmacophoreAngleBond pbond  = new PharmacophoreAngleBond(patom1, patom2, patom3);

            PharmacophoreQueryAtom      qatom1 = new PharmacophoreQueryAtom("Amine", "[CX2]N");
            PharmacophoreQueryAtom      qatom2 = new PharmacophoreQueryAtom("aromatic", "c1ccccc1");
            PharmacophoreQueryAtom      qatom3 = new PharmacophoreQueryAtom("blah", "C");
            PharmacophoreQueryAngleBond qbond1 = new PharmacophoreQueryAngleBond(qatom1, qatom2, qatom3, 54.735);
            PharmacophoreQueryAngleBond qbond2 = new PharmacophoreQueryAngleBond(qatom1, qatom2, qatom3, 50, 60);
            PharmacophoreQueryAngleBond qbond3 = new PharmacophoreQueryAngleBond(qatom1, qatom2, qatom3, 60, 80);
            PharmacophoreQueryBond      qbond4 = new PharmacophoreQueryBond(qatom1, qatom2, 1, 2);

            Assert.IsTrue(qbond1.Matches(pbond));
            Assert.IsTrue(qbond2.Matches(pbond));
            Assert.IsFalse(qbond3.Matches(pbond));
            Assert.IsFalse(qbond4.Matches(pbond));
        }
Example #21
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);
        }
        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));
        }
        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]);
        }
        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);
        }
Example #25
0
        public void TestGetSmarts()
        {
            PharmacophoreQueryAtom qatom = new PharmacophoreQueryAtom("aromatic", "c1ccccc1");

            Assert.AreEqual("c1ccccc1", qatom.Smarts);
        }
Example #26
0
 /// <summary>
 /// Create a query distance constraint between two query groups.
 /// <para>
 /// This constructor allows you to define a query distance constraint
 /// such that the distance between the two query groups is exact
 /// (i.e., not a range).
 /// </para>
 /// </summary>
 /// <remarks>
 /// Note that the distance is only considered upto 2 decimal places.
 /// </remarks>
 /// <param name="atom1">The first pharmacophore group</param>
 /// <param name="atom2">The second pharmacophore group</param>
 /// <param name="distance">The exact distance between the two groups</param>
 /// <seealso cref="PharmacophoreQueryBond(PharmacophoreQueryAtom, PharmacophoreQueryAtom, double, double)"/>
 public PharmacophoreQueryBond(PharmacophoreQueryAtom atom1, PharmacophoreQueryAtom atom2, double distance)
     : base(atom1, atom2)
 {
     this.upper = Round(distance, 2);
     this.lower = Round(distance, 2);
 }
Example #27
0
 /// <summary>
 /// Create a query distance constraint between two query groups.
 /// </summary>
 /// <remarks>
 /// Note that the distance is only considered upto 2 decimal places.
 /// </remarks>
 /// <param name="atom1">The first pharmacophore group</param>
 /// <param name="atom2">The second pharmacophore group</param>
 /// <param name="lower">The lower bound of the distance between the two groups</param>
 /// <param name="upper">The upper bound of the distance between the two groups</param>
 /// <seealso cref="PharmacophoreQueryBond(PharmacophoreQueryAtom,PharmacophoreQueryAtom,double)"/>
 public PharmacophoreQueryBond(PharmacophoreQueryAtom atom1, PharmacophoreQueryAtom atom2, double lower, double upper)
     : base(atom1, atom2)
 {
     this.upper = Round(upper, 2);
     this.lower = Round(lower, 2);
 }
Example #28
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));
        }
Example #29
0
        /// <summary>
        /// Write out one or more pharmacophore queries in the CDK XML format.
        /// </summary>
        /// <param name="queries">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[] queries, Stream output)
        {
            var root = new XElement("pharmacophoreContainer");

            root.SetAttributeValue("version", "1.0");
            foreach (var query in queries)
            {
                var pcore = new XElement("pharmacophore");

                var description = query.GetProperty <string>("description");
                if (description != null)
                {
                    pcore.SetAttributeValue("description", description);
                }

                var name = query.Title;
                if (name != null)
                {
                    pcore.SetAttributeValue("name", name);
                }

                // we add the pcore groups for this query as local to the group
                foreach (var atom in query.Atoms)
                {
                    var group = new XElement("group");
                    group.SetAttributeValue("id", atom.Symbol);
                    group.Value = ((PharmacophoreQueryAtom)atom).Smarts;
                    pcore.Add(group);
                }

                // now add the constraints
                foreach (var bond in query.Bonds)
                {
                    XElement elem = null;
                    switch (bond)
                    {
                    case PharmacophoreQueryBond dbond:
                    {
                        elem = new XElement("distanceConstraint");
                        elem.SetAttributeValue("lower", dbond.GetLower().ToString(NumberFormatInfo.InvariantInfo));
                        elem.SetAttributeValue("upper", dbond.GetUpper().ToString(NumberFormatInfo.InvariantInfo));
                        elem.SetAttributeValue("units", "A");
                    }
                    break;

                    case PharmacophoreQueryAngleBond dbond:
                    {
                        elem = new XElement("angleConstraint");
                        elem.SetAttributeValue("lower", dbond.GetLower().ToString(NumberFormatInfo.InvariantInfo));
                        elem.SetAttributeValue("upper", dbond.GetUpper().ToString(NumberFormatInfo.InvariantInfo));
                        elem.SetAttributeValue("units", "degrees");
                    }
                    break;
                    }

                    // now add the group associated with this constraint
                    foreach (var iAtom in bond.Atoms)
                    {
                        PharmacophoreQueryAtom atom = (PharmacophoreQueryAtom)iAtom;
                        var gelem = new XElement("groupRef");
                        gelem.SetAttributeValue("id", atom.Symbol);
                        if (elem != null)
                        {
                            elem.Add(gelem);
                        }
                    }
                    pcore.Add(elem);
                }
                root.Add(pcore);
            }
            var doc = new XDocument(root);

            doc.Save(output);
        }