Skip to content

Commit 78fec01

Browse files
committed
Remove 83 synchronized locks, add 6 chemistry edge-case tests, clean dead code
Performance: - Remove synchronized from 83 methods across 10 hot-path classes (Reactor, BaseGameTheory, GraphMatching, GameTheory*, ReactionMechanismTool, CallableAtomMappingTool) — these are single-threaded per reaction Chemistry tests (6 new, 46 total in default suite): - E/Z isomerization (cis→trans 2-butene, stereo fingerprint) - Friedel-Crafts acylation (aromatic C-C bond formation) - Aromatic nitration (electrophilic substitution with charged species) - Ring opening ozonolysis (cyclohexene → dialdehyde) - Quaternary ammonium formation (charged N+ / I- handling) - Identity with stereo (L-alanine → L-alanine, 0 bond changes) Cleanup: - Remove ~70 lines of dead commented-out code from GraphMatcher, GameTheoryMatrix, MappingHandler, Reactor, CDKReactionBuilder Author: Syed Asad Rahman <asad.rahman@bioinceptionlabs.com>
1 parent 2603f33 commit 78fec01

14 files changed

Lines changed: 199 additions & 153 deletions

File tree

src/main/java/com/bioinceptionlabs/reactionblast/mapping/CallableAtomMappingTool.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public class CallableAtomMappingTool implements Serializable {
7171
* @param outFileName
7272
* @throws Exception
7373
*/
74-
public static synchronized void writeMappingRXN(Reactor reactor, String outputDirectoryName, String outFileName) throws Exception {
74+
public static void writeMappingRXN(Reactor reactor, String outputDirectoryName, String outFileName) throws Exception {
7575
String reactionID = reactor.getReactionWithAtomAtomMapping().getID();
7676
IReaction mappedReaction = reactor.getReactionWithAtomAtomMapping();
7777
if (reactionID == null) {
@@ -105,7 +105,7 @@ public CallableAtomMappingTool(
105105
generateAtomAtomMapping(reaction, standardizer, removeHydrogen, checkComplex);
106106
}
107107

108-
private synchronized void generateAtomAtomMapping(
108+
private void generateAtomAtomMapping(
109109
IReaction reaction,
110110
IStandardizer standardizer,
111111
boolean removeHydrogen,

src/main/java/com/bioinceptionlabs/reactionblast/mapping/Reactor.java

Lines changed: 35 additions & 58 deletions
Large diffs are not rendered by default.

src/main/java/com/bioinceptionlabs/reactionblast/mapping/algorithm/BaseGameTheory.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public abstract class BaseGameTheory extends Debugger implements IGameTheory, Se
8585
* @param atomContainer
8686
* @return
8787
*/
88-
protected static synchronized boolean isPseudoAtoms(IAtomContainer atomContainer) {
88+
protected static boolean isPseudoAtoms(IAtomContainer atomContainer) {
8989
for (IAtom atoms : atomContainer.atoms()) {
9090
if (atoms instanceof IPseudoAtom || atoms instanceof PseudoAtom) {
9191
return true;
@@ -99,7 +99,7 @@ protected static synchronized boolean isPseudoAtoms(IAtomContainer atomContainer
9999
* @return @throws IOException
100100
*/
101101
@Override
102-
public synchronized String getSuffix() throws IOException {
102+
public String getSuffix() throws IOException {
103103
Calendar cal = new GregorianCalendar();
104104
int ms = cal.get(YEAR);
105105

@@ -126,7 +126,7 @@ public synchronized String getSuffix() throws IOException {
126126
* @throws InterruptedException
127127
*/
128128
@Override
129-
public synchronized void UpdateMatrix(Holder mh, boolean removeHydrogen) throws InterruptedException {
129+
public void UpdateMatrix(Holder mh, boolean removeHydrogen) throws InterruptedException {
130130
try {
131131
LOGGER.debug("**********Updated Matrix And Calculate Similarity**************");
132132
ReactionContainer reactionStructureInformation = mh.getReactionContainer();
@@ -199,7 +199,7 @@ public synchronized void UpdateMatrix(Holder mh, boolean removeHydrogen) throws
199199
* @throws Exception
200200
*/
201201
@Override
202-
public synchronized void UpdateMatrix(Collection<MCSSolution> mcsSolutions, Holder mh, boolean removeHydrogen) throws Exception {
202+
public void UpdateMatrix(Collection<MCSSolution> mcsSolutions, Holder mh, boolean removeHydrogen) throws Exception {
203203
try {
204204
LOGGER.debug("**********Updated Matrix And Calculate Similarity**************");
205205
ReactionContainer reactionStructureInformation = mh.getReactionContainer();
@@ -244,7 +244,7 @@ public synchronized void UpdateMatrix(Collection<MCSSolution> mcsSolutions, Hold
244244
}
245245
}
246246

247-
private synchronized void refillMatrixWithNewData(
247+
private void refillMatrixWithNewData(
248248
Holder holder,
249249
int substrateIndex,
250250
int productIndex,
@@ -332,7 +332,7 @@ private synchronized void refillMatrixWithNewData(
332332
}
333333
}
334334

335-
private synchronized MCSSolution getMappings(
335+
private MCSSolution getMappings(
336336
int queryPosition,
337337
int targetPosition,
338338
IAtomContainer educt,
@@ -528,7 +528,7 @@ private void refillMatrixWithOldData(Holder holder, int substrateIndex, int prod
528528
}
529529
}
530530

531-
synchronized String generateUniqueKey(
531+
String generateUniqueKey(
532532
IAtomContainer compound1,
533533
IAtomContainer compound2,
534534
String id1, String id2,
@@ -565,7 +565,7 @@ synchronized String generateUniqueKey(
565565
return key.toString();
566566
}
567567

568-
private synchronized int[] getCircularFP(IAtomContainer mol) throws CDKException {
568+
private int[] getCircularFP(IAtomContainer mol) throws CDKException {
569569
CircularFingerprinter circularFingerprinter = new CircularFingerprinter(6, 1024);
570570
circularFingerprinter.setPerceiveStereo(true);
571571
IBitFingerprint bitFingerprint = circularFingerprinter.getBitFingerprint(mol);
@@ -575,7 +575,7 @@ private synchronized int[] getCircularFP(IAtomContainer mol) throws CDKException
575575
/*
576576
* copy old mapping from the cache to new
577577
*/
578-
synchronized MCSSolution copyOldSolutionToNew(int queryPosition, int targetPosition,
578+
MCSSolution copyOldSolutionToNew(int queryPosition, int targetPosition,
579579
IAtomContainer compound1, IAtomContainer compound2, MCSSolution oldSolution) {
580580
AtomAtomMapping atomAtomMapping = oldSolution.getAtomAtomMapping();
581581
Map<Integer, Integer> mappingsByIndex = atomAtomMapping.getMappingsByIndex();
@@ -592,7 +592,7 @@ synchronized MCSSolution copyOldSolutionToNew(int queryPosition, int targetPosit
592592
return mcsSolution;
593593
}
594594

595-
synchronized MCSSolution addMCSSolution(int queryPosition, int targetPosition,
595+
MCSSolution addMCSSolution(int queryPosition, int targetPosition,
596596
String key, ThreadSafeCache<String, MCSSolution> mappingcache, Isomorphism isomorphism) {
597597

598598
isomorphism.setChemFilters(true, true, true);

src/main/java/com/bioinceptionlabs/reactionblast/mapping/algorithm/GameTheoryMatrix.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,6 @@ public class GameTheoryMatrix extends BaseGameTheory implements IGraphTheoryMatr
6969
private static final long serialVersionUID = 0x2c36427fd2L;
7070
//~--- constructors -------------------------------------------------------
7171
private static final ILoggingTool LOGGER = createLoggingTool(GameTheoryMatrix.class);
72-
// private void initializeMappingFLAGS(Holder mh) throws Exception {
73-
// ReactionContainer reactionStructureInformation = mh.getReactionContainer();
74-
/*Reset all the flags*/
75-
// for (int substrateIndex = 0; substrateIndex < reactionStructureInformation.getEductCount(); substrateIndex++) {
76-
// for (int productIndex = 0; productIndex < reactionStructureInformation.getProductCount(); productIndex++) {
77-
// reactionStructureInformation.setEductModified(substrateIndex, true);
78-
// reactionStructureInformation.setProductModified(productIndex, true);
79-
// }
80-
// }
81-
// }
8272
private Holder matrixHolder;
8373
private MoleculeMoleculeMapping reactionBlastMolMapping;
8474
private final List<String> eductCounter;

src/main/java/com/bioinceptionlabs/reactionblast/mapping/algorithm/GameTheoryMax.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ final class GameTheoryMax extends BaseGameTheory {
120120
GenerateMapping(false);
121121
}
122122

123-
private synchronized void GenerateMapping(boolean flag) throws Exception {
123+
private void GenerateMapping(boolean flag) throws Exception {
124124
boolean ruleMatchingFlag = flag;
125125
int iteration = 0;
126126
boolean continueMapping = true;
@@ -183,7 +183,7 @@ private synchronized void GenerateMapping(boolean flag) throws Exception {
183183
}
184184
}
185185

186-
private synchronized void UpdateMapping() throws Exception {
186+
private void UpdateMapping() throws Exception {
187187
boolean[][] FlagMatrix = winner.getFlagMatrix();
188188

189189
ReactionContainer reactionStructureInformation = mh.getReactionContainer();
@@ -246,23 +246,23 @@ private synchronized void UpdateMapping() throws Exception {
246246
* @return the reactionMolMapping
247247
*/
248248
@Override
249-
public synchronized MoleculeMoleculeMapping getReactionMolMapping() {
249+
public MoleculeMoleculeMapping getReactionMolMapping() {
250250
return reactionMolMapping;
251251
}
252252

253253
/**
254254
* @param reactionMolMapping the reactionMolMapping to set
255255
*/
256256
@Override
257-
public synchronized void setReactionMolMapping(MoleculeMoleculeMapping reactionMolMapping) {
257+
public void setReactionMolMapping(MoleculeMoleculeMapping reactionMolMapping) {
258258
this.reactionMolMapping = reactionMolMapping;
259259
}
260260

261261
/**
262262
* @return the delta
263263
*/
264264
@Override
265-
public synchronized int getDelta() {
265+
public int getDelta() {
266266
return delta;
267267
}
268268
}

src/main/java/com/bioinceptionlabs/reactionblast/mapping/algorithm/GameTheoryMin.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ final class GameTheoryMin extends BaseGameTheory {
131131
}
132132
}
133133

134-
private synchronized void GenerateIsoMorphismMapping() throws Exception {
134+
private void GenerateIsoMorphismMapping() throws Exception {
135135

136136
winner.searchWinners(educts, products, mh);
137137

@@ -146,7 +146,7 @@ private synchronized void GenerateIsoMorphismMapping() throws Exception {
146146
}
147147
}
148148

149-
private synchronized void GenerateMapping(boolean flag) throws Exception {
149+
private void GenerateMapping(boolean flag) throws Exception {
150150
boolean ruleMatchingFlag = flag;
151151
int iteration = 0;
152152
boolean continueMapping = true;
@@ -211,7 +211,7 @@ private synchronized void GenerateMapping(boolean flag) throws Exception {
211211
}
212212
}
213213

214-
private synchronized void UpdateMapping() throws Exception {
214+
private void UpdateMapping() throws Exception {
215215
boolean[][] FlagMatrix = winner.getFlagMatrix();
216216

217217
ReactionContainer reactionStructureInformationContainer = mh.getReactionContainer();
@@ -267,23 +267,23 @@ private synchronized void UpdateMapping() throws Exception {
267267
* @return the reactionMolMapping
268268
*/
269269
@Override
270-
public synchronized MoleculeMoleculeMapping getReactionMolMapping() {
270+
public MoleculeMoleculeMapping getReactionMolMapping() {
271271
return reactionMolMapping;
272272
}
273273

274274
/**
275275
* @param reactionMolMapping the reactionMolMapping to set
276276
*/
277277
@Override
278-
public synchronized void setReactionMolMapping(MoleculeMoleculeMapping reactionMolMapping) {
278+
public void setReactionMolMapping(MoleculeMoleculeMapping reactionMolMapping) {
279279
this.reactionMolMapping = reactionMolMapping;
280280
}
281281

282282
/**
283283
* @return the delta
284284
*/
285285
@Override
286-
public synchronized int getDelta() {
286+
public int getDelta() {
287287
return delta;
288288
}
289289
}

src/main/java/com/bioinceptionlabs/reactionblast/mapping/algorithm/GameTheoryMixture.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ final class GameTheoryMixture extends BaseGameTheory {
133133
}
134134
//~--- methods ------------------------------------------------------------
135135

136-
private synchronized void GenerateIsoMorphismMapping() throws Exception {
136+
private void GenerateIsoMorphismMapping() throws Exception {
137137

138138
winner.searchWinners(educts, products, mh);
139139

@@ -148,7 +148,7 @@ private synchronized void GenerateIsoMorphismMapping() throws Exception {
148148
}
149149
}
150150

151-
private synchronized void GenerateMapping(boolean flag) throws Exception {
151+
private void GenerateMapping(boolean flag) throws Exception {
152152
boolean ruleMatchingFlag = flag;
153153
int iteration = 0;
154154
boolean continueMapping = true;
@@ -191,7 +191,7 @@ private synchronized void GenerateMapping(boolean flag) throws Exception {
191191
}
192192
}
193193

194-
private synchronized void UpdateMapping() throws Exception {
194+
private void UpdateMapping() throws Exception {
195195
boolean[][] FlagMatrix = winner.getFlagMatrix();
196196

197197
ReactionContainer reactionStructureInformationContainer = mh.getReactionContainer();
@@ -247,23 +247,23 @@ private synchronized void UpdateMapping() throws Exception {
247247
* @return the reactionMolMapping
248248
*/
249249
@Override
250-
public synchronized MoleculeMoleculeMapping getReactionMolMapping() {
250+
public MoleculeMoleculeMapping getReactionMolMapping() {
251251
return reactionMolMapping;
252252
}
253253

254254
/**
255255
* @param reactionMolMapping the reactionMolMapping to set
256256
*/
257257
@Override
258-
public synchronized void setReactionMolMapping(MoleculeMoleculeMapping reactionMolMapping) {
258+
public void setReactionMolMapping(MoleculeMoleculeMapping reactionMolMapping) {
259259
this.reactionMolMapping = reactionMolMapping;
260260
}
261261

262262
/**
263263
* @return the delta
264264
*/
265265
@Override
266-
public synchronized int getDelta() {
266+
public int getDelta() {
267267
return delta;
268268
}
269269
}

src/main/java/com/bioinceptionlabs/reactionblast/mapping/algorithm/GameTheoryRings.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ final class GameTheoryRings extends BaseGameTheory {
137137
}
138138
//~--- methods ------------------------------------------------------------
139139

140-
private synchronized void GenerateIsoMorphismMapping() throws Exception {
140+
private void GenerateIsoMorphismMapping() throws Exception {
141141

142142
RuleBasedMappingHandler ph
143143
= new RuleBasedMappingHandler(mh, eductList, productList);
@@ -159,7 +159,7 @@ private synchronized void GenerateIsoMorphismMapping() throws Exception {
159159
}
160160
}
161161

162-
private synchronized void GenerateMapping() throws Exception {
162+
private void GenerateMapping() throws Exception {
163163
int iteration = 0;
164164
boolean continueMapping = true;
165165
while (continueMapping && iteration < MAX_MAPPING_ITERATIONS) {
@@ -200,7 +200,7 @@ private synchronized void GenerateMapping() throws Exception {
200200
}
201201
}
202202

203-
private synchronized void UpdateMapping() throws Exception {
203+
private void UpdateMapping() throws Exception {
204204
boolean[][] FlagMatrix = winner.getFlagMatrix();
205205

206206
ReactionContainer reactionStructureInformationContainer = mh.getReactionContainer();
@@ -256,23 +256,23 @@ private synchronized void UpdateMapping() throws Exception {
256256
* @return the reactionMolMapping
257257
*/
258258
@Override
259-
public synchronized MoleculeMoleculeMapping getReactionMolMapping() {
259+
public MoleculeMoleculeMapping getReactionMolMapping() {
260260
return reactionMolMapping;
261261
}
262262

263263
/**
264264
* @param reactionMolMapping the reactionMolMapping to set
265265
*/
266266
@Override
267-
public synchronized void setReactionMolMapping(MoleculeMoleculeMapping reactionMolMapping) {
267+
public void setReactionMolMapping(MoleculeMoleculeMapping reactionMolMapping) {
268268
this.reactionMolMapping = reactionMolMapping;
269269
}
270270

271271
/**
272272
* @return the delta
273273
*/
274274
@Override
275-
public synchronized int getDelta() {
275+
public int getDelta() {
276276
return delta;
277277
}
278278
}

src/main/java/com/bioinceptionlabs/reactionblast/mapping/container/CDKReactionBuilder.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,6 @@ public synchronized IReaction standardize(IReaction reaction) throws Exception {
137137
reaction.setID(reactionID);
138138
}
139139

140-
// System.out.println("****************************");
141-
// System.out.println("Processing: " + reactionID);
142-
// System.out.println("****************************");
143-
// System.out.println("Number of Reactant " + _imoledu.getAtomContainerCount());
144-
// System.out.println("Number of Product " + _imolpro.getAtomContainerCount());
145140
_metabolites.clear();
146141

147142
standardizedReaction.setID(reactionID);
@@ -397,10 +392,6 @@ && isAtomContainerPresent(getMoleculeID(fingerprint_Present_Mol), molecule)) {
397392
}
398393

399394
private void setReactantMolecule(IReaction IR, Collection<IAtomContainer> metabolites) {
400-
//
401-
// System.out.println("-------------------");
402-
// System.out.println("Reactants");
403-
// System.out.println("-------------------");
404395

405396
Iterator<IAtomContainer> it = metabolites.iterator();
406397
//System.out.println("Stoic Map Size: " + stoichiometryMap.size());
@@ -420,9 +411,6 @@ private void setReactantMolecule(IReaction IR, Collection<IAtomContainer> metabo
420411

421412
private void setProductMolecule(IReaction IR, Collection<IAtomContainer> metabolites) {
422413

423-
// System.out.println("-------------------");
424-
// System.out.println("Products");
425-
// System.out.println("-------------------");
426414
Iterator<IAtomContainer> it = metabolites.iterator();
427415
while (it.hasNext()) {
428416
IAtomContainer mol = it.next();

src/main/java/com/bioinceptionlabs/reactionblast/mapping/graph/GraphMatcher.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -304,15 +304,6 @@ Ring matcher is set true if both sides have rings else it set to false (IMP for
304304
MCSSolution isomorphism = callablesQueue.take().get();
305305
threadedUniqueMCSSolutions.add(isomorphism);
306306
}
307-
308-
// List<Future<MCSSolution>> invokeAll = executor.invokeAll(callablesQueue);
309-
// for (Iterator<Future<MCSSolution>> it = invokeAll.iterator(); it.hasNext();) {
310-
// Future<MCSSolution> callable = it.next();
311-
// MCSSolution isomorphism = callable.get();
312-
// if (callable.isDone()) {
313-
// mcsSolutions.add(isomorphism);
314-
// }
315-
// }
316307
// This will make the executor accept no new threads
317308
// and finish all existing threads in the queue
318309
executor.shutdown();
@@ -323,12 +314,6 @@ Ring matcher is set true if both sides have rings else it set to false (IMP for
323314
threadedUniqueMCSSolutions.stream().filter((mcs) -> !(mcs == null)).map((MCSSolution mcs) -> {
324315
int queryPosition = mcs.getQueryPosition();
325316
int targetPosition = mcs.getTargetPosition();
326-
// if (DEBUG) {
327-
// System.out.println("");
328-
// out.println("MCS " + " I " + queryPosition
329-
// + " J " + targetPosition
330-
// + " Number of Atom Mapped " + mcs.getAtomAtomMapping().getCount());
331-
// }
332317
Combination referenceKey = null;
333318
for (Combination c : jobMap.keySet()) {
334319
if (c.getRowIndex() == queryPosition && c.getColIndex() == targetPosition) {

0 commit comments

Comments
 (0)