Permalink
Browse files

added substructure search benchmark

  • Loading branch information...
1 parent 61ce8c7 commit 4d1217887ce7a44814504134739a6da5f176e1c8 @metamolecular metamolecular committed with Jan 22, 2009
View
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<testSuite name="CheminfoBench" xmlns="http://www.sun.com/japex/testSuite">
+ <param name="basedir" value="."/>
+ <param name="japex.classPath" value="build/classes"/>
+ <param name="japex.resultUnit" value="ms"/>
+ <param name="japex.warmupIterations" value="10"/>
+ <param name="japex.runIterations" value="10"/>
+ <param name="japex.reportsDirectory" value="build/reports"/>
+ <driverGroup name="Ring Benchmark" xmlns="http://www.sun.com/japex/testSuite">
+ <driver name="CDK-1.2.x">
+ <param name="japex.driverClass" value="net.openmolecules.benchmark.driver.CDKSubstructureBench"/>
+ <param name="japex.classPath" value="${basedir}/lib/cdk-1.2.x-20090116.jar"/>
+ <param name="description" value="Finds all substructures in a set of hydrogen-suppressed structures."/>
+ </driver>
+ <driver name="mx-0.108.1">
+ <param name="japex.driverClass" value="net.openmolecules.benchmark.driver.MXSubstructureBench"/>
+ <param name="japex.classPath" value="${basedir}/lib/mx-0.108.1.jar"/>
+ <param name="description" value="Finds all substructures in a set of hydrogen-suppressed structures."/>
+ </driver>
+ </driverGroup>
+ <testCase name="Read 416-Record PubChem SD File and Find All Substructure Matches to Benzene in Each Hydrogen-Suppressed Structure">
+ <param name="japex.inputFile" value="data/pubchem_416_benzenes.sdf" />
+ </testCase>
+</testSuite>
@@ -0,0 +1,94 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package net.openmolecules.benchmark.driver;
+
+import com.sun.japex.JapexDriverBase;
+import com.sun.japex.TestCase;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.List;
+import org.openscience.cdk.DefaultChemObjectBuilder;
+import org.openscience.cdk.exception.CDKException;
+import org.openscience.cdk.interfaces.IAtomContainer;
+import org.openscience.cdk.interfaces.IMolecule;
+import org.openscience.cdk.io.iterator.IteratingMDLReader;
+import org.openscience.cdk.isomorphism.UniversalIsomorphismTester;
+import org.openscience.cdk.templates.MoleculeFactory;
+import org.openscience.cdk.tools.manipulator.AtomContainerManipulator;
+
+/**
+ *
+ * @author rich
+ */
+public class CDKSubstructureBench extends JapexDriverBase
+{
+
+ private List<IAtomContainer> molecules;
+
+ @Override
+ public void prepare(TestCase testCase)
+ {
+ molecules = new ArrayList();
+ IteratingMDLReader reader = getReader(testCase.getParam("japex.inputFile"));
+
+ while (reader.hasNext())
+ {
+ IAtomContainer molecule = (IMolecule) reader.next();
+
+ molecule = AtomContainerManipulator.removeHydrogens(molecule);
+ molecules.add(molecule);
+ }
+
+ try
+ {
+ reader.close();
+ } catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public void run(TestCase testCase)
+ {
+ IMolecule query = MoleculeFactory.makeBenzene();
+ int count = 0;
+
+ try
+ {
+ for (IAtomContainer target : molecules)
+ {
+ if (UniversalIsomorphismTester.isSubgraph(target, query))
+ {
+ count++;
+ }
+ }
+ } catch (CDKException e)
+ {
+ throw new RuntimeException(e);
+ }
+
+ System.out.println("count=" + count);
+ }
+
+ private IteratingMDLReader getReader(String filename)
+ {
+ IteratingMDLReader result = null;
+
+ try
+ {
+ Reader raw = new FileReader(filename);
+
+ result = new IteratingMDLReader(raw, DefaultChemObjectBuilder.getInstance());
+ } catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+
+ return result;
+ }
+}
@@ -0,0 +1,77 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package net.openmolecules.benchmark.driver;
+
+import com.metamolecular.mx.io.Molecules;
+import com.metamolecular.mx.io.mdl.SDFileReader;
+import com.metamolecular.mx.map.DefaultMapper;
+import com.metamolecular.mx.map.Mapper;
+import com.metamolecular.mx.model.Molecule;
+import com.sun.japex.JapexDriverBase;
+import com.sun.japex.TestCase;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ *
+ * @author rich
+ */
+public class MXSubstructureBench extends JapexDriverBase
+{
+
+ private List<Molecule> molecules;
+
+ @Override
+ public void prepare(TestCase testCase)
+ {
+ molecules = new ArrayList();
+ SDFileReader reader = createReader(testCase.getParam("japex.inputFile"));
+
+ while (reader.hasNextRecord())
+ {
+ reader.nextRecord();
+
+ Molecule molecule = reader.getMolecule(true);
+
+ molecules.add(molecule);
+ }
+
+ reader.close();
+ }
+
+ @Override
+ public void run(TestCase testCase)
+ {
+ Molecule query = Molecules.createBenzene();
+ Mapper mapper = new DefaultMapper(query);
+ int count = 0;
+
+ for (Molecule target : molecules)
+ {
+ if (mapper.hasMap(target))
+ {
+ count++;
+ }
+ }
+
+ System.out.println(count);
+ }
+
+ private SDFileReader createReader(String filename)
+ {
+ SDFileReader result = null;
+
+ try
+ {
+ result = new SDFileReader(filename);
+ } catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+
+ return result;
+ }
+}

0 comments on commit 4d12178

Please sign in to comment.