Diff of /cdk-fingerprint-paper/trunk/src/makeHitStatistics.groovy [r15019] .. [r15020] Maximize Restore

  Switch to side-by-side view

--- a/cdk-fingerprint-paper/trunk/src/makeHitStatistics.groovy
+++ b/cdk-fingerprint-paper/trunk/src/makeHitStatistics.groovy
@@ -1,6 +1,13 @@
 import org.openscience.cdk.smiles.SmilesParser;
 import org.openscience.cdk.DefaultChemObjectBuilder; 
 import org.openscience.cdk.isomorphism.UniversalIsomorphismTester;
+import org.openscience.cdk.tools.manipulator.AtomContainerManipulator;
+import org.openscience.cdk.aromaticity.CDKHueckelAromaticityDetector;
+import org.openscience.cdk.fingerprint.ExtendedFingerprinter;
+import org.openscience.cdk.fingerprint.Fingerprinter;
+import org.openscience.cdk.fingerprint.MACCSFingerprinter;
+import org.openscience.cdk.fingerprint.EStateFingerprinter;
+import org.openscience.cdk.fingerprint.SubstructureFingerprinter;
 
 def cli = new CliBuilder(usage: 'makeHitStatistics.groovy -[qd]');
 cli.with {
@@ -35,7 +42,54 @@
 def parse(SMILES) {
     SmilesParser parser = new SmilesParser( 
                                 DefaultChemObjectBuilder.getInstance() );
-    parser.parseSmiles(SMILES);
+    def mol = parser.parseSmiles(SMILES);
+    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol);
+    CDKHueckelAromaticityDetector.detectAromaticity(mol);
+    return mol;
+}
+
+def isSubgraph( testMolecule, queryMolecule ) {
+    UniversalIsomorphismTester.isSubgraph( testMolecule, 
+                                           queryMolecule );
+}
+
+def boolean bitSetMatches( testBitSet, queryBitset ) {
+    return queryBitset.equals( testBitSet.and(queryBitset) );
+}
+
+def fingerprintMatches( testMolecule, queryMolecule ) {
+    def fingerprinter = new Fingerprinter(); 
+    def t = fingerprinter.getFingerprint( testMolecule );
+    def q = fingerprinter.getFingerprint( queryMolecule );
+    return bitSetMatches( t, q );
+}
+
+def extendedFingerprintMatches( testMolecule, queryMolecule ) {
+    def extendedFingerprinter = new ExtendedFingerprinter();
+    def t = extendedFingerprinter.getFingerprint( testMolecule );
+    def q = extendedFingerprinter.getFingerprint( queryMolecule );
+    return bitSetMatches( t, q );
+}
+
+def MACCSFingerprintMatches( testMolecule, queryMolecule ) {
+    def MACCSFingerprinter = new MACCSFingerprinter();
+    def t = MACCSFingerprinter.getFingerprint( testMolecule );
+    def q = MACCSFingerprinter.getFingerprint( queryMolecule );
+    return bitSetMatches( t, q );
+}
+
+def EStateFingerprintMatches( testMolecule, queryMolecule ) {
+    def EStateFingerprinter = new EStateFingerprinter();
+    def t = EStateFingerprinter.getFingerprint( testMolecule );
+    def q = EStateFingerprinter.getFingerprint( queryMolecule );
+    return bitSetMatches( t, q );
+}
+
+def SubstructureFingerprintMatches( testMolecule, queryMolecule ) {
+    def SubstructureFingerprinter = new SubstructureFingerprinter();
+    def t = SubstructureFingerprinter.getFingerprint( testMolecule );
+    def q = SubstructureFingerprinter.getFingerprint( queryMolecule );
+    return bitSetMatches( t, q );
 }
 
 def database = [];
@@ -63,19 +117,30 @@
 def oldPercent = "";
 
 targetFile = new File("result.txt");
-targetFile.write("Query SMILES, Target SMILES, Universal Isomorphism hit\n");
+targetFile.write( "Query SMILES, "
+                  + "Target SMILES, "
+                  + "Universal Isomorphism hit, "
+                  + "Fingerprint hit, " 
+                  + "ExtendedFingerprint hit, "
+                  + "MACCSFingerprint hit, "
+                  + "EStateFingerprinter hit, "
+                  + "SubstructureFingerprinter hit\n" );
 
 for ( query in queries ) {
     for ( smiles in database ) {
         def queryMolecule = parse(query);
         def testMolecule  = parse(smiles);
 
-        def isSubgraph = UniversalIsomorphismTester
-                             .isSubgraph( testMolecule, 
-                                          queryMolecule );
-
-        targetFile.append( query + ", " + smiles + ", " + isSubgraph );
-        targetFile.append("\n");
+        targetFile.append( 
+            query + ", " 
+            + smiles + ", " 
+            + isSubgraph(                     testMolecule, queryMolecule ) + ", "
+            + fingerprintMatches(             testMolecule, queryMolecule ) + ", "
+            + extendedFingerprintMatches(     testMolecule, queryMolecule ) + ", "
+            + MACCSFingerprintMatches(        testMolecule, queryMolecule ) + ", "
+            + EStateFingerprintMatches(       testMolecule, queryMolecule ) + ", "
+            + SubstructureFingerprintMatches( testMolecule, queryMolecule ) 
+            + "\n" );
 
         def percent = sprintf( "%5.1f", (double)((100 * i++) / total) );
         if ( !oldPercent.equals(percent) ) {