From c241461d89bacfec0ad599e4980d2314549f0fd0 Mon Sep 17 00:00:00 2001 From: yapchunwei Date: Fri, 4 May 2012 12:38:54 +0800 Subject: [PATCH] Modify to make UniversalIsomorphismTester usable in a threaded environment. Remove keyword static from variables start and timeout. Remove keyword static from methods isIsomorph, getIsomorphMap, getIsomorphAtomsMap, getIsomorphMaps, getSubgraphMaps, getSubgraphMap, getSubgraphAtomsMaps, getSubgraphAtomsMap, isSubgraph, getOverlaps, search, getMaximum, setTimeout. Added constructor. --- .../UniversalIsomorphismTester.java | 47 ++++++++++--------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/src/main/org/openscience/cdk/isomorphism/UniversalIsomorphismTester.java b/src/main/org/openscience/cdk/isomorphism/UniversalIsomorphismTester.java index 2981237662c..3be8859d514 100644 --- a/src/main/org/openscience/cdk/isomorphism/UniversalIsomorphismTester.java +++ b/src/main/org/openscience/cdk/isomorphism/UniversalIsomorphismTester.java @@ -111,8 +111,13 @@ public class UniversalIsomorphismTester { final static int ID1 = 0; final static int ID2 = 1; - private static long start; - private static long timeout=-1; + private long start; + private long timeout=-1; + + public UniversalIsomorphismTester() + { + + } /////////////////////////////////////////////////////////////////////////// // Query Methods @@ -134,7 +139,7 @@ public class UniversalIsomorphismTester { * @return true if the 2 molecule are isomorph * @throws CDKException if the first molecule is an instance of IQueryAtomContainer */ - public static boolean isIsomorph(IAtomContainer g1, IAtomContainer g2) throws CDKException{ + public boolean isIsomorph(IAtomContainer g1, IAtomContainer g2) throws CDKException{ if (g1 instanceof IQueryAtomContainer) throw new CDKException( "The first IAtomContainer must not be an IQueryAtomContainer" @@ -167,7 +172,7 @@ public static boolean isIsomorph(IAtomContainer g1, IAtomContainer g2) throws C * @param g2 second molecule. May be an {@link IQueryAtomContainer}. * @return the first isomorph mapping found projected of g1. This is a List of RMap objects containing Ids of matching bonds. */ - public static List getIsomorphMap(IAtomContainer g1, IAtomContainer g2) throws CDKException{ + public List getIsomorphMap(IAtomContainer g1, IAtomContainer g2) throws CDKException{ if (g1 instanceof IQueryAtomContainer) throw new CDKException( "The first IAtomContainer must not be an IQueryAtomContainer" @@ -194,7 +199,7 @@ public static List getIsomorphMap(IAtomContainer g1, IAtomContainer g2) t * This is a List of RMap objects containing Ids of matching atoms. * @throws CDKException if the first molecules is not an instance of {@link IQueryAtomContainer} */ - public static List getIsomorphAtomsMap(IAtomContainer g1, IAtomContainer g2) throws CDKException { + public List getIsomorphAtomsMap(IAtomContainer g1, IAtomContainer g2) throws CDKException { if (g1 instanceof IQueryAtomContainer) throw new CDKException( "The first IAtomContainer must not be an IQueryAtomContainer" @@ -202,7 +207,7 @@ public static List getIsomorphAtomsMap(IAtomContainer g1, IAtomContainer g List list = checkSingleAtomCases(g1, g2); if (list == null) { - return makeAtomsMapOfBondsMap(UniversalIsomorphismTester.getIsomorphMap(g1, g2), g1, g2); + return makeAtomsMapOfBondsMap(getIsomorphMap(g1, g2), g1, g2); } else if (list.isEmpty()) { return null; } else { @@ -219,7 +224,7 @@ public static List getIsomorphAtomsMap(IAtomContainer g1, IAtomContainer g * @param g2 second molecule. May be an {@link IQueryAtomContainer}. * @return the list of all the 'mappings' */ - public static List> getIsomorphMaps(IAtomContainer g1, IAtomContainer g2) throws CDKException{ + public List> getIsomorphMaps(IAtomContainer g1, IAtomContainer g2) throws CDKException{ return search(g1, g2, getBitSet(g1), getBitSet(g2), true, true); } @@ -246,7 +251,7 @@ public static List> getIsomorphMaps(IAtomContainer g1, IAtomContainer * * @see #makeAtomsMapsOfBondsMaps(List, IAtomContainer, IAtomContainer) */ - public static List> getSubgraphMaps(IAtomContainer g1, IAtomContainer g2) throws CDKException{ + public List> getSubgraphMaps(IAtomContainer g1, IAtomContainer g2) throws CDKException{ return search(g1, g2, new BitSet(), getBitSet(g2), true, true); } @@ -259,7 +264,7 @@ public static List> getSubgraphMaps(IAtomContainer g1, IAtomContainer * @return the first subgraph bond mapping found projected on g1. This is a {@link List} of * {@link RMap} objects containing Ids of matching bonds. */ - public static List getSubgraphMap(IAtomContainer g1, IAtomContainer g2) throws CDKException{ + public List getSubgraphMap(IAtomContainer g1, IAtomContainer g2) throws CDKException{ List result = null; List> rMapsList = search(g1, g2, new BitSet(), getBitSet(g2), false, false); @@ -281,13 +286,13 @@ public static List getSubgraphMap(IAtomContainer g1, IAtomContainer g2) t * @return all subgraph atom mappings found projected on g1. This is a * {@link List} of {@link RMap} objects containing Ids of matching atoms. */ - public static List> getSubgraphAtomsMaps(IAtomContainer g1, + public List> getSubgraphAtomsMaps(IAtomContainer g1, IAtomContainer g2) throws CDKException { List list = checkSingleAtomCases(g1, g2); if (list == null) { return makeAtomsMapsOfBondsMaps( - UniversalIsomorphismTester.getSubgraphMaps(g1, g2), g1, g2 + getSubgraphMaps(g1, g2), g1, g2 ); } else { List> atomsMap = new ArrayList>(); @@ -305,12 +310,12 @@ public static List> getSubgraphAtomsMaps(IAtomContainer g1, * @return the first subgraph atom mapping found projected on g1. * This is a {@link List} of {@link RMap} objects containing Ids of matching atoms. */ - public static List getSubgraphAtomsMap(IAtomContainer g1, + public List getSubgraphAtomsMap(IAtomContainer g1, IAtomContainer g2) throws CDKException { List list = checkSingleAtomCases(g1, g2); if (list == null) { - return makeAtomsMapOfBondsMap(UniversalIsomorphismTester.getSubgraphMap(g1, g2), g1, g2); + return makeAtomsMapOfBondsMap(getSubgraphMap(g1, g2), g1, g2); } else if (list.isEmpty()) { return null; } else { @@ -325,7 +330,7 @@ public static List getSubgraphAtomsMap(IAtomContainer g1, * @param g2 second molecule. May be an {@link IQueryAtomContainer}. * @return true if g2 a subgraph on g1 */ - public static boolean isSubgraph(IAtomContainer g1, IAtomContainer g2) throws CDKException{ + public boolean isSubgraph(IAtomContainer g1, IAtomContainer g2) throws CDKException{ if (g1 instanceof IQueryAtomContainer) throw new CDKException( "The first IAtomContainer must not be an IQueryAtomContainer" @@ -365,7 +370,7 @@ public static boolean isSubgraph(IAtomContainer g1, IAtomContainer g2) throws C * @return the list of all the maximal common substructure * found projected of g1 (list of AtomContainer ) */ - public static List getOverlaps(IAtomContainer g1, IAtomContainer g2) throws CDKException{ + public List getOverlaps(IAtomContainer g1, IAtomContainer g2) throws CDKException{ start=System.currentTimeMillis(); List> rMapsList = search(g1, g2, new BitSet(), new BitSet(), true, false); @@ -438,7 +443,7 @@ public static RGraph buildRGraph(IAtomContainer g1, IAtomContainer g2) throws C * structure * @return a List of Lists of {@link RMap} objects that represent the search solutions */ - public static List> search(IAtomContainer g1, IAtomContainer g2, BitSet c1, + public List> search(IAtomContainer g1, IAtomContainer g2, BitSet c1, BitSet c2, boolean findAllStructure, boolean findAllMap) throws CDKException{ // remember start time start = System.currentTimeMillis(); @@ -476,8 +481,8 @@ public static List> search(IAtomContainer g1, IAtomContainer g2, BitS // build the RGraph corresponding to this problem RGraph rGraph = buildRGraph(g1, g2); // Set time data - rGraph.setTimeout(UniversalIsomorphismTester.timeout); - rGraph.setStart(UniversalIsomorphismTester.start); + rGraph.setTimeout(timeout); + rGraph.setStart(start); // parse the RGraph with the given constrains and options rGraph.parse(c1, c2, findAllStructure, findAllMap); List solutionList = rGraph.getSolutions(); @@ -579,7 +584,7 @@ public static List projectList(List> rMapsList, IAtom * @return the list cleaned * @throws CDKException if there is a problem in obtaining subgraphs */ - private static List getMaximum(List graphList) throws CDKException { + private List getMaximum(List graphList) throws CDKException { List reducedGraphList = new ArrayList(); reducedGraphList.addAll(graphList); @@ -1087,8 +1092,8 @@ private static boolean testSubgraphHeuristics(IAtomContainer ac1, IAtomContainer * @param timeout * Time in milliseconds. -1 to ignore the timeout. */ - public static void setTimeout(long timeout) { - UniversalIsomorphismTester.timeout = timeout; + public void setTimeout(long timeout) { + this.timeout = timeout; } }