public void TestICountFingerprintComparison() { var mol1 = TestMoleculeFactory.MakeIndole(); var mol2 = TestMoleculeFactory.MakeIndole(); var fingerprinter = new SignatureFingerprinter(); var fp1 = fingerprinter.GetCountFingerprint(mol1); var fp2 = fingerprinter.GetCountFingerprint(mol2); var tanimoto = Tanimoto.Calculate(fp1, fp2); Assert.AreEqual(1.0, tanimoto, 0.001); }
public void TestRawTanimotoBetween0and1() { var smilesParser = CDK.SmilesParser; var mol1 = smilesParser.ParseSmiles("Cc1nc(C(=O)NC23CC4CC(CC(C4)C2)C3)c(C)n1C5CCCCC5"); var mol2 = smilesParser.ParseSmiles("CS(=O)(=O)Nc1ccc(Cc2onc(n2)c3ccc(cc3)S(=O)(=O)Nc4ccc(CCNC[C@H](O)c5cccnc5)cc4)cc1"); var fingerprinter = new SignatureFingerprinter(0); var fp1 = fingerprinter.GetRawFingerprint(mol1); var fp2 = fingerprinter.GetRawFingerprint(mol2); var tanimoto = Tanimoto.Calculate(fp1, fp2); Assert.IsTrue(tanimoto > 0 && tanimoto < 1, $"Tanimoto expected to be between 0 and 1, was:{tanimoto}"); }
public void CompareCountFingerprintAndRawFingerprintTanimoto() { var mol1 = TestMoleculeFactory.Make123Triazole(); var mol2 = TestMoleculeFactory.MakeImidazole(); var fingerprinter = new SignatureFingerprinter(1); var countFp1 = fingerprinter.GetCountFingerprint(mol1); var countFp2 = fingerprinter.GetCountFingerprint(mol2); var feat1 = fingerprinter.GetRawFingerprint(mol1); var feat2 = fingerprinter.GetRawFingerprint(mol2); var rawTanimoto = Tanimoto.Calculate(feat1, feat2); var countTanimoto = Tanimoto.Method1(countFp1, countFp2); Assert.AreEqual(rawTanimoto, countTanimoto, 0.001); }
public void TestCompaRingBitFingerprintAndCountBehavingAsBit() { var mol1 = TestMoleculeFactory.Make123Triazole(); var mol2 = TestMoleculeFactory.MakeImidazole(); var fingerprinter = new SignatureFingerprinter(1); ICountFingerprint countFp1 = fingerprinter.GetCountFingerprint(mol1); ICountFingerprint countFp2 = fingerprinter.GetCountFingerprint(mol2); countFp1.SetBehaveAsBitFingerprint(true); countFp2.SetBehaveAsBitFingerprint(true); var bitFp1 = fingerprinter.GetBitFingerprint(mol1); var bitFp2 = fingerprinter.GetBitFingerprint(mol2); var bitTanimoto = Tanimoto.Calculate(bitFp1, bitFp2); var countTanimoto1 = Tanimoto.Method1(countFp1, countFp2); var countTanimoto2 = Tanimoto.Method2(countFp1, countFp2); Assert.AreEqual(countTanimoto1, countTanimoto2, 0.001); Assert.AreEqual(bitTanimoto, countTanimoto1, 0.001); }
public void TestCountMethod1and2() { ICountFingerprint fp1 = new IntArrayCountFingerprint(new Dictionary <string, int>() { { "A", 3 } }); ICountFingerprint fp2 = new IntArrayCountFingerprint(new Dictionary <string, int>() { { "A", 4 } }); Assert.AreEqual(0.923, Tanimoto.Method1(fp1, fp2), 0.001); Assert.AreEqual(0.75, Tanimoto.Method2(fp1, fp2), 0.001); var mol1 = TestMoleculeFactory.MakeIndole(); var mol2 = TestMoleculeFactory.MakeIndole(); var fingerprinter = new SignatureFingerprinter(); fp1 = fingerprinter.GetCountFingerprint(mol1); fp2 = fingerprinter.GetCountFingerprint(mol2); Assert.AreEqual(1.0, Tanimoto.Method1(fp1, fp2), 0.001); Assert.AreEqual(1.0, Tanimoto.Method2(fp1, fp2), 0.001); }
/// <summary> /// Build fingerprint /// </summary> /// <param name="mol"></param> public static BitSetFingerprint BuildBitSetFingerprint( IAtomContainer mol, FingerprintType fpType, int fpSubtype = -1, int fpLen = -1) { // Data for Tanimoto similarity using various fingerprint types for CorpId 123456 query. // Cart - Standard MDL Oracle Cartridge scores // // Similarity Score // ------------------------------------------------ // Size -> 192 896 1024 1024 128 1024 320 // CorpId Cart MACCS PbChm ECFP4 EXT EState Basic Sbstr // ------ ---- ---- ---- ---- ---- ---- ---- ---- // 123456 0.99 1.00 1.00 1.00 1.00 1.00 1.00 1.00 // 123456 0.99 0.98 0.96 0.77 0.95 1.00 0.95 1.00 // 123456 0.99 0.98 0.96 0.77 0.95 1.00 0.94 1.00 // 123456 0.99 1.00 1.00 1.00 1.00 1.00 1.00 1.00 // 123456 0.99 1.00 1.00 1.00 1.00 1.00 1.00 1.00 // 123456 0.99 0.91 1.00 0.81 1.00 1.00 1.00 1.00 // 123456 0.98 0.95 1.00 0.74 0.92 1.00 0.93 0.94 // 123456 0.98 1.00 1.00 1.00 1.00 1.00 1.00 1.00 // 123456 0.98 1.00 1.00 1.00 1.00 1.00 1.00 1.00 // 123456 0.98 1.00 0.83 0.76 0.77 0.90 0.76 0.94 // LSH Bin Count - The number of LSH bins (of 25) that match the query bin values //-------------- // CorpId MAC PbC ECFP EX // ------ --- --- --- --- // 123456 25 25 25 25 // 123456 25 20 7 16 // 123456 25 20 9 19 // 123456 25 25 25 25 // 123456 25 25 25 25 // 123456 20 25 9 25 // 123456 21 25 11 17 // 123456 25 25 25 25 // 123456 25 25 25 25 // 123456 25 9 6 11 // Data for Tanimoto similarity using various Circular fingerprint types. // Using 2 molecules where the 2nd just has an added methyl group. // // Measure Score // -------- ----- // ECFP0 1.00 // ECFP2 .88 // ECFP4 .75 // ECFP6 .64 // FCFP0 1.00 // FCFP2 .92 // FCFP4 .84 // FCFP6 .74 IFingerprinter ifptr = null; IBitFingerprint ibfp = null; BitSetFingerprint bfp = null; IAtomContainer mol2; string s = ""; DateTime t0 = DateTime.Now; double getFptrTime = 0, buildFpTime = 0; if (fpType == FingerprintType.Basic) // size = 1024 { ifptr = new Fingerprinter(); } else if (fpType == FingerprintType.Circular) // size variable { CircularFingerprinterClass cfpClass = (CircularFingerprinterClass)fpSubtype; if (cfpClass < CircularFingerprinterClass.ECFP0 || cfpClass > CircularFingerprinterClass.ECFP6) { cfpClass = (CircularFingerprinterClass)CircularFingerprintType.DefaultCircularClass; // default class } if (fpLen < 0) { fpLen = CircularFingerprintType.DefaultCircularLength; // default length } ifptr = new CircularFingerprinter(cfpClass, fpLen); //CircularFingerprinter cfp = (CircularFingerprinter)ifptr; //ICountFingerprint cntFp = cfp.getCountFingerprint(mol); // debug //s = CircularFpToString(cfp); // debug } else if (fpType == FingerprintType.Extended) // size = 1024 { ifptr = new ExtendedFingerprinter(); // use DEFAULT_SIZE and DEFAULT_SEARCH_DEPTH } else if (fpType == FingerprintType.EState) // size = 128 { ifptr = new EStateFingerprinter(); // use DEFAULT_SIZE and DEFAULT_SEARCH_DEPTH } else if (fpType == FingerprintType.MACCS) // size = 192 { if (MACCSFp == null) { MACCSFp = new MACCSFingerprinter(); } ifptr = MACCSFp; } else if (fpType == FingerprintType.PubChem) // size = 896 { //IChemObjectBuilder builder = DefaultChemObjectBuilder.getInstance(); ifptr = new PubchemFingerprinter(); } else if (fpType == FingerprintType.ShortestPath) // size = { ifptr = new ShortestPathFingerprinter(); // fails with atom type issue for many structures (e.g. 123456) } else if (fpType == FingerprintType.Signature) // size = { ifptr = new SignatureFingerprinter(); // can't convert array fingerprint to bitsetfingerprint } else if (fpType == FingerprintType.Substructure) // size = 320 { ifptr = new SubstructureFingerprinter(); } else { throw new Exception("Invalid CdkFingerprintType: " + fpType); } getFptrTime = TimeOfDay.Delta(ref t0); ibfp = ifptr.GetBitFingerprint(mol); bfp = (BitSetFingerprint)ibfp; buildFpTime = TimeOfDay.Delta(ref t0); //long size = bfp.size(); //int card = bfp.Cardinality; return(bfp); }