From f5ccf1bdc83cb821bf7b764912f2c6fa2d0ae08a Mon Sep 17 00:00:00 2001 From: Syed Asad Rahman Date: Mon, 17 May 2010 15:48:34 +0100 Subject: [PATCH] Updated the SMSD code for turbo mode substructure search Refactored the SMSD class itself Signed-off-by: Syed Asad Rahman Signed-off-by: Rajarshi Guha --- src/main/org/openscience/cdk/smsd/SMSD.java | 271 ------------------ .../algorithm/vflib/VFlibTurboHandler.java | 69 ++--- .../factory/SubStructureSearchAlgorithms.java | 7 +- 3 files changed, 33 insertions(+), 314 deletions(-) diff --git a/src/main/org/openscience/cdk/smsd/SMSD.java b/src/main/org/openscience/cdk/smsd/SMSD.java index 9fb1e6711d9..2cc1281ac82 100644 --- a/src/main/org/openscience/cdk/smsd/SMSD.java +++ b/src/main/org/openscience/cdk/smsd/SMSD.java @@ -22,16 +22,7 @@ */ package org.openscience.cdk.smsd; -import java.io.IOException; -import java.util.List; -import java.util.Map; -import java.util.logging.Level; import org.openscience.cdk.annotations.TestClass; -import org.openscience.cdk.annotations.TestMethod; -import org.openscience.cdk.exception.CDKException; -import org.openscience.cdk.interfaces.IAtom; -import org.openscience.cdk.interfaces.IAtomContainer; -import org.openscience.cdk.interfaces.IMolecule; import org.openscience.cdk.smsd.factory.SubStructureSearchAlgorithms; import org.openscience.cdk.smsd.interfaces.AbstractMCS; import org.openscience.cdk.smsd.interfaces.Algorithm; @@ -142,10 +133,6 @@ @TestClass("org.openscience.cdk.smsd.SMSDTest") public class SMSD extends SubStructureSearchAlgorithms { - private final static ILoggingTool logger = - LoggingToolFactory.createLoggingTool(SMSD.class); - private AbstractMCS comparison = null; - /** * Algorithm {@link org.openscience.cdk.smsd.interfaces.Algorithm} * choice for find MCS or performing substructure searches @@ -168,263 +155,5 @@ public class SMSD extends SubStructureSearchAlgorithms { */ public SMSD(Algorithm algorithmType, boolean bondSensitiveFlag) { super(algorithmType, bondSensitiveFlag); - comparison = new SubStructureSearchAlgorithms(algorithmType, bondSensitiveFlag); - } - - /** {@inheritDoc} - * - * initialize query and target molecules - * @param Query query molecule - * @param Target target molecule - */ - @Override - @TestMethod("testInit_3args_1") - public synchronized void init(IMolecule Query, IMolecule Target, boolean removeHydrogen) { - - if (Query.getAtomCount() > 0 && Target.getAtomCount() > 0) { - try { - getComparison().init(Query, Target, removeHydrogen); - } catch (CDKException ex) { - logger.error(Level.SEVERE, null, ex); - } - } else { - try { - throw new CDKException("Each molecule should have atleast one atom to compare"); - } catch (CDKException ex) { - logger.error(Level.SEVERE, null, ex); - } - } - } - - /** {@inheritDoc} - * - * initialize query and target molecules - * @param Query Atomcontainer - * @param Target Atomcontainer - */ - @Override - @TestMethod("testInit_3args_2") - public synchronized void init(IAtomContainer Query, IAtomContainer Target, boolean removeHydrogen) { - - if (Query.getAtomCount() > 0 && Target.getAtomCount() > 0) { - try { - getComparison().init(Query, Target, removeHydrogen); - } catch (CDKException ex) { - logger.error(Level.SEVERE, null, ex); - } - } else { - try { - throw new CDKException("Each molecule should have atleast one atom to compare"); - } catch (CDKException ex) { - logger.error(Level.SEVERE, null, ex); - } - } - } - - /** {@inheritDoc} - * - * These are important set of paraments which will refine and rank the - * mcs solutions. The precedence of stereoFilter > fragmentFilter > energyFilter - * @param stereoFilter true if stereo match is considered else false - * @param fragmentFilter true if fragement filter is switched on else false - * @param energyFilter true if bond energy filter is switched on else false - */ - @Override - @TestMethod("testSetChemFilters") - public void setChemFilters(boolean stereoFilter, boolean fragmentFilter, boolean energyFilter) { - getComparison().setChemFilters(stereoFilter, fragmentFilter, energyFilter); - } - - /** {@inheritDoc} - * - * Returns all plausible mappings between query and target molecules - * Each map in the list has atom-atom equivalence of the mappings - * between query and target molecule i.e. map.getKey() for the query - * and map.getValue() for the target molecule - * @return A List of all possible mapped MCS atoms. - * - */ - @Override - @TestMethod("testGetAllAtomMapping") - public List> getAllAtomMapping() { - return getComparison().getAllAtomMapping(); - } - - /** {@inheritDoc} - (* - * Returns all plausible mappings between query and target molecules - * Each map in the list has atom-atom equivalence index of the mappings - * between query and target molecule i.e. map.getKey() for the query - * and map.getValue() for the target molecule - * @return A List of all possible mapped MCS atom index. - * - */ - @Override - @TestMethod("testGetAllMapping") - public List> getAllMapping() { - return getComparison().getAllMapping(); - } - - /** {@inheritDoc} - * - * Returns one of the best matches with atoms mapped - * @return One of the best MCS solution(s) atoms - * - */ - @Override - @TestMethod("testGetFirstAtomMapping") - public Map getFirstAtomMapping() { - return getComparison().getFirstAtomMapping(); - } - - /** {@inheritDoc} - * - * Returns one of the best matches with atom indexes mapped - * @return One of the best MCS solution(s) index - */ - @Override - @TestMethod("testGetFirstMapping") - public Map getFirstMapping() { - return getComparison().getFirstMapping(); - } - - /** {@inheritDoc} - * - * Returns a number which denotes the quality of the mcs. - * A solution with highest stereo score is preferred over other - * scores - * @param Key position - * @return Stereo matching score for the mapped part - * - */ - @Override - @TestMethod("testGetStereoScore") - public Integer getStereoScore(int Key) { - return getComparison().getStereoScore(Key); - } - - /** {@inheritDoc} - * - * Returns number of fragment generated in the solution space, - * if the MCS is removed from the target and query graph. - * Amongst the solutions, a solution with lowest fragment size - * is preferred - * - * @param Key position - * @return Fragment count(s) generated after removing the mapped parts - * - */ - @Override - @TestMethod("testGetFragmentSize") - public Integer getFragmentSize(int Key) { - return getComparison().getFragmentSize(Key); - } - - /** {@inheritDoc} - * - * Returns summation energy score of the disorder if the MCS is removed - * from the target and query graph. Amongst the solutions, a solution - * with lowest energy score is preferred - * - * @param Key position - * @return Total bond breaking energy required to remove the mapped part - * - */ - @Override - @TestMethod("testGetEnergyScore") - public Double getEnergyScore(int Key) { - return getComparison().getEnergyScore(Key); - } - - /** {@inheritDoc} - * - * Returns modified query molecule on which mapping was - * performed - * @return Query Molecule AtomContainer - */ - @Override - @TestMethod("testGetReactantMolecule") - public IAtomContainer getReactantMolecule() { - return getComparison().getReactantMolecule(); - } - - /** {@inheritDoc} - * - * Returns modified target molecule on which mapping was - * performed - * @return Target Molecule AtomContainer - */ - @Override - @TestMethod("testGetProductMolecule") - public IAtomContainer getProductMolecule() { - return getComparison().getProductMolecule(); - } - - /** {@inheritDoc} - * - * Returns Tanimoto similarity between query and target molecules - * (Score is between 0-min and 1-max) - * @return Tanimoto similarity between query and target molecules - * @throws java.io.IOException - */ - @Override - @TestMethod("testGetTanimotoSimilarity") - public double getTanimotoSimilarity() throws IOException { - return getComparison().getTanimotoSimilarity(); - } - - /** {@inheritDoc} - * - * - * @return true if no stereo mismatch occurs - * else false if stereo mismatch occurs - */ - @Override - @TestMethod("testIsStereoMisMatch") - public boolean isStereoMisMatch() { - return getComparison().isStereoMisMatch(); - } - - /** {@inheritDoc} - * - * Checks if query is a subgraph of the target - * @return true if query is a subgraph of the target - * else false - */ - @Override - @TestMethod("testIsSubgraph") - public boolean isSubgraph() { - return getComparison().isSubgraph(); - - } - - /** {@inheritDoc} - * - * Returns Euclidean Distance between query and target molecule - * @return Euclidean Distance between query and target molecule - * @throws IOException - */ - @Override - @TestMethod("testGetEuclideanDistance") - public double getEuclideanDistance() throws IOException { - return getComparison().getEuclideanDistance(); - } - - /** - * Returns algorithm class instance in process - * @return the comparison - */ - @TestMethod("testGetComparison") - public AbstractMCS getComparison() { - return comparison; - } - - /** - * Sets algorithm class initiated for search process - * @param comparison the comparison to set - */ - @TestMethod("testSetComparison") - public void setComparison(AbstractMCS comparison) { - this.comparison = comparison; } } diff --git a/src/main/org/openscience/cdk/smsd/algorithm/vflib/VFlibTurboHandler.java b/src/main/org/openscience/cdk/smsd/algorithm/vflib/VFlibTurboHandler.java index de2b7acb195..ce4e3ba98ac 100644 --- a/src/main/org/openscience/cdk/smsd/algorithm/vflib/VFlibTurboHandler.java +++ b/src/main/org/openscience/cdk/smsd/algorithm/vflib/VFlibTurboHandler.java @@ -34,13 +34,13 @@ import org.openscience.cdk.smsd.algorithm.vflib.interfaces.IMapper; import org.openscience.cdk.smsd.algorithm.vflib.interfaces.INode; import org.openscience.cdk.smsd.algorithm.vflib.interfaces.IQuery; -import org.openscience.cdk.smsd.algorithm.vflib.map.VFMapper; import org.openscience.cdk.smsd.algorithm.vflib.query.TemplateCompiler; import org.openscience.cdk.smsd.helper.MolHandler; import org.openscience.cdk.smsd.interfaces.AbstractSubGraph; import org.openscience.cdk.interfaces.IAtom; import org.openscience.cdk.interfaces.IAtomContainer; import org.openscience.cdk.interfaces.IMolecule; +import org.openscience.cdk.smsd.algorithm.vflib.map.VFMCSMapper; import org.openscience.cdk.smsd.interfaces.IMCSBase; /** @@ -90,13 +90,9 @@ public VFlibTurboHandler() { public boolean isSubgraph() { IQuery query = TemplateCompiler.compile(source); - - IMapper mapper = new VFMapper(query); - + IMapper mapper = new VFMCSMapper(query); Map vfLibSolution = mapper.getFirstMap(target); - -// System.out.println("Size of the Mapping: " + vfLibSolution.size()); - + Map atomatomMapping = new HashMap(); TreeMap indexindexMapping = new TreeMap(); @@ -120,61 +116,56 @@ public boolean isSubgraph() { atomsMCS.putAll(allAtomMCS.get(0)); firstMCS.putAll(allMCS.get(0)); } - - return (!firstMCS.isEmpty() && firstMCS.size() == source.getAtomCount()) ? true : false; + return !vfLibSolution.isEmpty() ? true : false; } /** {@inheritDoc} * - * @param source - * @param target + * @param reactant + * @param product */ @Override @TestMethod("testSet_IAtomContainer_IAtomContainer") - public void set(IAtomContainer source, IAtomContainer target) { + public void set(IAtomContainer reactant, IAtomContainer product) { - IAtomContainer mol1 = source; - IAtomContainer mol2 = target; + IAtomContainer mol1 = reactant; + IAtomContainer mol2 = product; MolHandler Reactant = new MolHandler(mol1, false); MolHandler Product = new MolHandler(mol2, false); - - set(Reactant, Product); + this.set(Reactant, Product); } /** {@inheritDoc} * - * @param source - * @param target + * + * @param Reactant + * @param Product */ - @TestMethod("testSet_IMolecule_IMolecule") - public void set(IMolecule source, IMolecule target) throws CDKException { - - IMolecule mol1 = source; - IMolecule mol2 = target; - - MolHandler Reactant = new MolHandler(mol1, false); - MolHandler Product = new MolHandler(mol2, false); - - set(Reactant, Product); + @Override + @TestMethod("testSet_MolHandler_MolHandler") + public void set(MolHandler Reactant, MolHandler Product) { + source = Reactant.getMolecule(); + target = Product.getMolecule(); } /** {@inheritDoc} * - * @param sourceMolFileName - * @param targetMolFileName + * Creates atoms new instance of SearchCliques + * @param ReactantMolFileName + * @param ProductMolFileName */ @Override @TestMethod("testSet_String_String") - public void set(String sourceMolFileName, String targetMolFileName) { + public void set(String ReactantMolFileName, String ProductMolFileName) { - String mol1 = sourceMolFileName; - String mol2 = targetMolFileName; + String mol1 = ReactantMolFileName; + String mol2 = ProductMolFileName; MolHandler Reactant = new MolHandler(mol1, false); MolHandler Product = new MolHandler(mol2, false); - set(Reactant, Product); + this.set(Reactant, Product); } /** {@inheritDoc} @@ -182,11 +173,11 @@ public void set(String sourceMolFileName, String targetMolFileName) { * @param source * @param target */ - @Override - @TestMethod("testSet_MolHandler_MolHandler") - public void set(MolHandler source, MolHandler target) { - this.source = source.getMolecule(); - this.target = target.getMolecule(); + @TestMethod("testSet_IMolecule_IMolecule") + public void set(IMolecule source, IMolecule target) throws CDKException { + MolHandler Reactant = new MolHandler(source, false); + MolHandler Product = new MolHandler(target, false); + this.set(Reactant, Product); } /** {@inheritDoc} diff --git a/src/main/org/openscience/cdk/smsd/factory/SubStructureSearchAlgorithms.java b/src/main/org/openscience/cdk/smsd/factory/SubStructureSearchAlgorithms.java index 18eab6cfc58..8211340d088 100644 --- a/src/main/org/openscience/cdk/smsd/factory/SubStructureSearchAlgorithms.java +++ b/src/main/org/openscience/cdk/smsd/factory/SubStructureSearchAlgorithms.java @@ -202,7 +202,6 @@ private void vfTurboHandler() { VFlibTurboHandler subGraphTurboSearch = null; subGraphTurboSearch = new VFlibTurboHandler(); subGraphTurboSearch.set(rMol, pMol); - clearMaps(); if (subGraphTurboSearch.isSubgraph()) { firstSolution.putAll(subGraphTurboSearch.getFirstMapping()); @@ -293,7 +292,7 @@ private void defaultAlgorithm() { } private void subStructureAlgorithm(int rBondCount, int pBondCount) { - if (rBondCount > 1 && pBondCount > 1) { + if (rBondCount > 0 && pBondCount > 0) { vfTurboHandler(); } else { singleMapping(); @@ -358,7 +357,7 @@ private void init(MolHandler Reactant, MolHandler Product, boolean removeHydroge */ @Override @TestMethod("testInit_3args_1") - public synchronized void init(IMolecule Reactant, IMolecule Product, boolean removeHydrogen) { + public void init(IMolecule Reactant, IMolecule Product, boolean removeHydrogen) { this.removeHydrogen = removeHydrogen; this.rMol = new MolHandler(Reactant, false, removeHydrogen); this.pMol = new MolHandler(Product, false, removeHydrogen); @@ -372,7 +371,7 @@ public synchronized void init(IMolecule Reactant, IMolecule Product, boolean rem */ @Override @TestMethod("testInit_3args_2") - public synchronized void init(IAtomContainer Reactant, IAtomContainer Product, boolean removeHydrogen) { + public void init(IAtomContainer Reactant, IAtomContainer Product, boolean removeHydrogen) { this.removeHydrogen = removeHydrogen; this.rMol = new MolHandler(Reactant, false, removeHydrogen); this.pMol = new MolHandler(Product, false, removeHydrogen);