Beispiel #1
0
        public void TestGetBondLength()
        {
            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);

            Assert.AreEqual(1.732051, pbond.BondLength, 0.00001);
        }
Beispiel #2
0
        public void TestMatchedBonds()
        {
            Assert.IsNotNull(conformers);

            // make a query
            PharmacophoreQuery 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);

            IAtomContainer       conf1   = conformers[0];
            PharmacophoreMatcher 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);

            PharmacophoreBond pbond  = (PharmacophoreBond)BondRef.Deref(bMatches[0][0]);
            PharmacophoreAtom patom1 = (PharmacophoreAtom)AtomRef.Deref(pbond.Begin);
            PharmacophoreAtom 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
            IBond value = mapping[bMatches[0][0]];

            Assert.AreEqual(b1, value);
        }
        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));
        }
Beispiel #4
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);
        }
        /// <summary>
        /// Convert the input into a pcore molecule.
        /// </summary>
        /// <param name="input">the compound being converted from</param>
        /// <returns>pcore molecule </returns>
        /// <exception cref="CDKException">match failed</exception>
        private IAtomContainer GetPharmacophoreMolecule(IAtomContainer input)
        {
            // XXX: prepare query, to be moved
            PrepareInput(input);

            var pharmacophoreMolecule = input.Builder.NewAtomContainer();

            var matched     = new HashSet <string>();
            var uniqueAtoms = new LinkedHashSet <PharmacophoreAtom>();

            Debug.WriteLine($"Converting [{input.Title}] to a pcore molecule");

            // lets loop over each pcore query atom
            foreach (var atom in pharmacophoreQuery.Atoms)
            {
                var qatom  = (PharmacophoreQueryAtom)atom;
                var smarts = qatom.Smarts;

                // a pcore query might have multiple instances of a given pcore atom (say
                // 2 hydrophobic groups separated by X unit). In such a case we want to find
                // the atoms matching the pgroup SMARTS just once, rather than redoing the
                // matching for each instance of the pcore query atom.
                if (!matched.Add(qatom.Symbol))
                {
                    continue;
                }

                // see if the smarts for this pcore query atom gets any matches
                // in our query molecule. If so, then collect each set of
                // matching atoms and for each set make a new pcore atom and
                // add it to the pcore atom container object
                int count = 0;
                foreach (var query in qatom.CompiledSmarts)
                {
                    // create the lazy mappings iterator
                    var mappings = query.MatchAll(input).GetUniqueAtoms();

                    foreach (var mapping in mappings)
                    {
                        uniqueAtoms.Add(NewPCoreAtom(input, qatom, smarts, mapping));
                        count++;
                    }
                }
                Debug.WriteLine($"\tFound {count} unique matches for {smarts}");
            }

            pharmacophoreMolecule.SetAtoms(uniqueAtoms.ToArray());

            // now that we have added all the pcore atoms to the container
            // we need to join all atoms with pcore bonds   (i.e. distance constraints)
            if (HasDistanceConstraints(pharmacophoreQuery))
            {
                var npatom = pharmacophoreMolecule.Atoms.Count;
                for (int i = 0; i < npatom - 1; i++)
                {
                    for (int j = i + 1; j < npatom; j++)
                    {
                        var atom1 = PharmacophoreAtom.Get(pharmacophoreMolecule.Atoms[i]);
                        var atom2 = PharmacophoreAtom.Get(pharmacophoreMolecule.Atoms[j]);
                        var bond  = new PharmacophoreBond(atom1, atom2);
                        pharmacophoreMolecule.Bonds.Add(bond);
                    }
                }
            }

            // if we have angle constraints, generate only the valid
            // possible angle relationships, rather than all possible
            if (HasAngleConstraints(pharmacophoreQuery))
            {
                int nangleDefs = 0;

                foreach (var bond in pharmacophoreQuery.Bonds)
                {
                    if (!(bond is PharmacophoreQueryAngleBond))
                    {
                        continue;
                    }

                    var startQAtom  = bond.Atoms[0];
                    var middleQAtom = bond.Atoms[1];
                    var endQAtom    = bond.Atoms[2];

                    // make a list of the patoms in the target that match
                    // each type of angle atom
                    var startl  = new List <IAtom>();
                    var middlel = new List <IAtom>();
                    var endl    = new List <IAtom>();

                    foreach (var tatom in pharmacophoreMolecule.Atoms)
                    {
                        if (tatom.Symbol.Equals(startQAtom.Symbol, StringComparison.Ordinal))
                        {
                            startl.Add(tatom);
                        }
                        if (tatom.Symbol.Equals(middleQAtom.Symbol, StringComparison.Ordinal))
                        {
                            middlel.Add(tatom);
                        }
                        if (tatom.Symbol.Equals(endQAtom.Symbol, StringComparison.Ordinal))
                        {
                            endl.Add(tatom);
                        }
                    }

                    // now we form the relevant angles, but we will
                    // have reversed repeats
                    var tmpl = new List <IAtom[]>();
                    foreach (var middle in middlel)
                    {
                        foreach (var start in startl)
                        {
                            if (middle.Equals(start))
                            {
                                continue;
                            }
                            foreach (var end in endl)
                            {
                                if (start.Equals(end) || middle.Equals(end))
                                {
                                    continue;
                                }
                                tmpl.Add(new IAtom[] { start, middle, end });
                            }
                        }
                    }

                    // now clean up reversed repeats
                    var unique = new List <IAtom[]>();
                    for (int i = 0; i < tmpl.Count; i++)
                    {
                        var  seq1     = tmpl[i];
                        bool isRepeat = false;
                        for (int j = 0; j < unique.Count; j++)
                        {
                            if (i == j)
                            {
                                continue;
                            }
                            var seq2 = unique[j];
                            if (Compares.AreDeepEqual(seq1[1], seq2[1]) && Compares.AreDeepEqual(seq1[0], seq2[2]) && Compares.AreDeepEqual(seq1[2], seq2[0]))
                            {
                                isRepeat = true;
                            }
                        }
                        if (!isRepeat)
                        {
                            unique.Add(seq1);
                        }
                    }

                    // finally we can add the unique angle to the target
                    foreach (var seq in unique)
                    {
                        var pbond = new PharmacophoreAngleBond(PharmacophoreAtom.Get(seq[0]), PharmacophoreAtom.Get(seq[1]), PharmacophoreAtom.Get(seq[2]));
                        pharmacophoreMolecule.Bonds.Add(pbond);
                        nangleDefs++;
                    }
                }
                Debug.WriteLine($"Added {nangleDefs} defs to the target pcore molecule");
            }
            return(pharmacophoreMolecule);
        }