Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Modify to make UniversalIsomorphismTester usable in a threaded enviro…

…nment. 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.
  • Loading branch information...
commit c241461d89bacfec0ad599e4980d2314549f0fd0 1 parent 510a753
Yap Chun Wei authored May 04, 2012 egonw committed July 27, 2012
47  src/main/org/openscience/cdk/isomorphism/UniversalIsomorphismTester.java
@@ -111,8 +111,13 @@
111 111
 
112 112
   final static int ID1 = 0;
113 113
   final static int ID2 = 1;
114  
-  private static long start;
115  
-  private static long timeout=-1;
  114
+  private long start;
  115
+  private long timeout=-1;
  116
+
  117
+  public UniversalIsomorphismTester()
  118
+  {
  119
+      
  120
+  }
116 121
 
117 122
   ///////////////////////////////////////////////////////////////////////////
118 123
   //                            Query Methods
@@ -134,7 +139,7 @@
134 139
    * @return     true if the 2 molecule are isomorph
135 140
    * @throws     CDKException if the first molecule is an instance of IQueryAtomContainer
136 141
    */
137  
-  public static boolean isIsomorph(IAtomContainer g1, IAtomContainer g2)  throws CDKException{
  142
+  public boolean isIsomorph(IAtomContainer g1, IAtomContainer g2)  throws CDKException{
138 143
 	  if (g1 instanceof IQueryAtomContainer)
139 144
 		  throw new CDKException(
140 145
 		      "The first IAtomContainer must not be an IQueryAtomContainer"
@@ -167,7 +172,7 @@ public static boolean isIsomorph(IAtomContainer g1, IAtomContainer g2)  throws C
167 172
    * @param  g2  second molecule. May be an {@link IQueryAtomContainer}.
168 173
    * @return     the first isomorph mapping found projected of g1. This is a List of RMap objects containing Ids of matching bonds.
169 174
    */
170  
-  public static List<RMap> getIsomorphMap(IAtomContainer g1, IAtomContainer g2)  throws CDKException{
  175
+  public List<RMap> getIsomorphMap(IAtomContainer g1, IAtomContainer g2)  throws CDKException{
171 176
 	  if (g1 instanceof IQueryAtomContainer)
172 177
 		  throw new CDKException(
173 178
 		      "The first IAtomContainer must not be an IQueryAtomContainer"
@@ -194,7 +199,7 @@ public static boolean isIsomorph(IAtomContainer g1, IAtomContainer g2)  throws C
194 199
    * This is a List of RMap objects containing Ids of matching atoms.
195 200
    * @throws CDKException if the first molecules is not an instance of {@link IQueryAtomContainer}
196 201
    */
197  
-  public static List<RMap> getIsomorphAtomsMap(IAtomContainer g1, IAtomContainer g2)  throws CDKException {
  202
+  public List<RMap> getIsomorphAtomsMap(IAtomContainer g1, IAtomContainer g2)  throws CDKException {
198 203
 	  if (g1 instanceof IQueryAtomContainer)
199 204
 		  throw new CDKException(
200 205
 		      "The first IAtomContainer must not be an IQueryAtomContainer"
@@ -202,7 +207,7 @@ public static boolean isIsomorph(IAtomContainer g1, IAtomContainer g2)  throws C
202 207
 	  
203 208
       List<RMap> list = checkSingleAtomCases(g1, g2);
204 209
       if (list == null) {
205  
-          return makeAtomsMapOfBondsMap(UniversalIsomorphismTester.getIsomorphMap(g1, g2), g1, g2);
  210
+          return makeAtomsMapOfBondsMap(getIsomorphMap(g1, g2), g1, g2);
206 211
       } else if (list.isEmpty()) {
207 212
           return null;
208 213
       } else {
@@ -219,7 +224,7 @@ public static boolean isIsomorph(IAtomContainer g1, IAtomContainer g2)  throws C
219 224
    * @param  g2  second molecule. May be an {@link IQueryAtomContainer}.
220 225
    * @return     the list of all the 'mappings'
221 226
    */
222  
-  public static List<List<RMap>> getIsomorphMaps(IAtomContainer g1, IAtomContainer g2)  throws CDKException{
  227
+  public List<List<RMap>> getIsomorphMaps(IAtomContainer g1, IAtomContainer g2)  throws CDKException{
223 228
     return search(g1, g2, getBitSet(g1), getBitSet(g2), true, true);
224 229
   }
225 230
 
@@ -246,7 +251,7 @@ public static boolean isIsomorph(IAtomContainer g1, IAtomContainer g2)  throws C
246 251
    *
247 252
    * @see #makeAtomsMapsOfBondsMaps(List, IAtomContainer, IAtomContainer)
248 253
    */
249  
-  public static List<List<RMap>> getSubgraphMaps(IAtomContainer g1, IAtomContainer g2)  throws CDKException{
  254
+  public List<List<RMap>> getSubgraphMaps(IAtomContainer g1, IAtomContainer g2)  throws CDKException{
250 255
     return search(g1, g2, new BitSet(), getBitSet(g2), true, true);
251 256
   }
252 257
 
@@ -259,7 +264,7 @@ public static boolean isIsomorph(IAtomContainer g1, IAtomContainer g2)  throws C
259 264
    * @return     the first subgraph bond mapping found projected on g1. This is a {@link List} of
260 265
    *             {@link RMap} objects containing Ids of matching bonds.
261 266
    */
262  
-  public static List<RMap> getSubgraphMap(IAtomContainer g1, IAtomContainer g2)  throws CDKException{
  267
+  public List<RMap> getSubgraphMap(IAtomContainer g1, IAtomContainer g2)  throws CDKException{
263 268
     List<RMap> result = null;
264 269
     List<List<RMap>> rMapsList = search(g1, g2, new BitSet(), getBitSet(g2), false, false);
265 270
 
@@ -281,13 +286,13 @@ public static boolean isIsomorph(IAtomContainer g1, IAtomContainer g2)  throws C
281 286
    * @return     all subgraph atom mappings found projected on g1. This is a
282 287
    *             {@link List} of {@link RMap} objects containing Ids of matching atoms.
283 288
    */
284  
-  public static List<List<RMap>> getSubgraphAtomsMaps(IAtomContainer g1,
  289
+  public List<List<RMap>> getSubgraphAtomsMaps(IAtomContainer g1,
285 290
 		                                              IAtomContainer g2)
286 291
     throws CDKException {
287 292
       List<RMap> list = checkSingleAtomCases(g1, g2);
288 293
       if (list == null) {
289 294
           return makeAtomsMapsOfBondsMaps(
290  
-              UniversalIsomorphismTester.getSubgraphMaps(g1, g2), g1, g2
  295
+              getSubgraphMaps(g1, g2), g1, g2
291 296
           );
292 297
       } else {
293 298
           List<List<RMap>> atomsMap = new ArrayList<List<RMap>>();
@@ -305,12 +310,12 @@ public static boolean isIsomorph(IAtomContainer g1, IAtomContainer g2)  throws C
305 310
    * @return    the first subgraph atom mapping found projected on g1.
306 311
    *            This is a {@link List} of {@link RMap} objects containing Ids of matching atoms.
307 312
    */
308  
-  public static List<RMap> getSubgraphAtomsMap(IAtomContainer g1,
  313
+  public List<RMap> getSubgraphAtomsMap(IAtomContainer g1,
309 314
                                                IAtomContainer g2)
310 315
       throws CDKException {
311 316
       List<RMap> list = checkSingleAtomCases(g1, g2);
312 317
       if (list == null) {
313  
-          return makeAtomsMapOfBondsMap(UniversalIsomorphismTester.getSubgraphMap(g1, g2), g1, g2);
  318
+          return makeAtomsMapOfBondsMap(getSubgraphMap(g1, g2), g1, g2);
314 319
       } else if (list.isEmpty()) {
315 320
           return null;
316 321
       } else {
@@ -325,7 +330,7 @@ public static boolean isIsomorph(IAtomContainer g1, IAtomContainer g2)  throws C
325 330
    * @param  g2  second molecule. May be an {@link IQueryAtomContainer}.
326 331
    * @return     true if g2 a subgraph on g1
327 332
    */
328  
-  public static boolean isSubgraph(IAtomContainer g1, IAtomContainer g2)  throws CDKException{
  333
+  public boolean isSubgraph(IAtomContainer g1, IAtomContainer g2)  throws CDKException{
329 334
 	  if (g1 instanceof IQueryAtomContainer)
330 335
 		  throw new CDKException(
331 336
 		      "The first IAtomContainer must not be an IQueryAtomContainer"
@@ -365,7 +370,7 @@ public static boolean isSubgraph(IAtomContainer g1, IAtomContainer g2)  throws C
365 370
    * @return     the list of all the maximal common substructure
366 371
    *             found projected of g1 (list of AtomContainer )
367 372
    */
368  
-  public static List<IAtomContainer> getOverlaps(IAtomContainer g1, IAtomContainer g2) throws CDKException{
  373
+  public List<IAtomContainer> getOverlaps(IAtomContainer g1, IAtomContainer g2) throws CDKException{
369 374
       start=System.currentTimeMillis();
370 375
       List<List<RMap>> rMapsList = search(g1, g2, new BitSet(), new BitSet(), true, false);
371 376
 
@@ -438,7 +443,7 @@ public static RGraph buildRGraph(IAtomContainer g1, IAtomContainer g2)  throws C
438 443
    *                           structure
439 444
    * @return                   a List of Lists of {@link RMap} objects that represent the search solutions
440 445
    */
441  
-  public static List<List<RMap>> search(IAtomContainer g1, IAtomContainer g2, BitSet c1,
  446
+  public List<List<RMap>> search(IAtomContainer g1, IAtomContainer g2, BitSet c1,
442 447
 		  BitSet c2, boolean findAllStructure, boolean findAllMap)  throws CDKException{
443 448
 	  // remember start time
444 449
 	  start = System.currentTimeMillis();
@@ -476,8 +481,8 @@ public static RGraph buildRGraph(IAtomContainer g1, IAtomContainer g2)  throws C
476 481
 	  // build the RGraph corresponding to this problem
477 482
 	  RGraph rGraph = buildRGraph(g1, g2); 
478 483
 	  // Set time data
479  
-	  rGraph.setTimeout(UniversalIsomorphismTester.timeout);
480  
-	  rGraph.setStart(UniversalIsomorphismTester.start);
  484
+	  rGraph.setTimeout(timeout);
  485
+	  rGraph.setStart(start);
481 486
 	  // parse the RGraph with the given constrains and options
482 487
 	  rGraph.parse(c1, c2, findAllStructure, findAllMap);
483 488
 	  List<BitSet> solutionList = rGraph.getSolutions();
@@ -579,7 +584,7 @@ public static IAtomContainer project(List<RMap> rMapList, IAtomContainer g, int
579 584
    * @return            the list cleaned
580 585
    * @throws CDKException if there is a problem in obtaining subgraphs
581 586
    */
582  
-  private static List<IAtomContainer> getMaximum(List<IAtomContainer> graphList) throws CDKException {
  587
+  private List<IAtomContainer> getMaximum(List<IAtomContainer> graphList) throws CDKException {
583 588
     List<IAtomContainer> reducedGraphList = new ArrayList<IAtomContainer>();
584 589
     reducedGraphList.addAll(graphList);
585 590
 
@@ -1087,8 +1092,8 @@ private static boolean testSubgraphHeuristics(IAtomContainer ac1, IAtomContainer
1087 1092
    * @param timeout
1088 1093
    * Time in milliseconds. -1 to ignore the timeout.
1089 1094
    */
1090  
-  public static void setTimeout(long timeout) {
1091  
-	  UniversalIsomorphismTester.timeout = timeout;
  1095
+  public void setTimeout(long timeout) {
  1096
+	  this.timeout = timeout;
1092 1097
   }
1093 1098
   
1094 1099
 }

0 notes on commit c241461

Please sign in to comment.
Something went wrong with that request. Please try again.