public void TestGetAngle5() { 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); Assert.AreEqual(54.7356, pbond.BondLength, 0.0001); }
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)); }
/// <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); }