Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

updated SMSD code Signed-off-by: Syed Asad Rahman <s9asad@gmail.com>

Signed-off-by: Rajarshi  Guha <rajarshi.guha@gmail.com>
  • Loading branch information...
commit 370a9267a3731057ac559724ab7b5c3582209018 1 parent 935b5f6
@asad asad authored rajarshi committed
Showing with 206 additions and 411 deletions.
  1. +1 −1  src/main/org/openscience/cdk/smsd/algorithm/cdk/CDKMCSHandler.java
  2. +1 −3 src/main/org/openscience/cdk/smsd/algorithm/mcsplus/ExactMapping.java
  3. +0 −2  src/main/org/openscience/cdk/smsd/algorithm/mcsplus/GenerateCompatibilityGraph.java
  4. +16 −26 src/main/org/openscience/cdk/smsd/algorithm/mcsplus/MCSPlusHandler.java
  5. +0 −2  src/main/org/openscience/cdk/smsd/algorithm/single/SingleMapping.java
  6. +3 −6 src/main/org/openscience/cdk/smsd/algorithm/single/SingleMappingHandler.java
  7. +1 −1  src/main/org/openscience/cdk/smsd/algorithm/vflib/VFlibHandler.java
  8. +1 −1  src/main/org/openscience/cdk/smsd/algorithm/vflib/VFlibMCSHandler.java
  9. +1 −1  src/main/org/openscience/cdk/smsd/algorithm/vflib/VFlibTurboHandler.java
  10. +2 −2 src/main/org/openscience/cdk/smsd/algorithm/vflib/map/VFMCSMapper.java
  11. +1 −1  src/main/org/openscience/cdk/smsd/factory/FragmentMatcher.java
  12. +22 −20 src/main/org/openscience/cdk/smsd/factory/SubStructureSearchAlgorithms.java
  13. +37 −41 src/main/org/openscience/cdk/smsd/filters/ChemicalFilters.java
  14. +1 −1  src/main/org/openscience/cdk/smsd/helper/FinalMappings.java
  15. +1 −1  src/main/org/openscience/cdk/smsd/interfaces/IMCSBase.java
  16. +72 −40 src/main/org/openscience/cdk/smsd/tools/ExtAtomContainerManipulator.java
  17. +0 −213 src/main/org/openscience/cdk/smsd/tools/MDLFileReader.java
  18. +45 −49 src/main/org/openscience/cdk/smsd/{helper → tools}/MolHandler.java
  19. +1 −0  src/main/org/openscience/cdk/smsd/tools/MoleculeSanityCheck.java
View
2  src/main/org/openscience/cdk/smsd/algorithm/cdk/CDKMCSHandler.java
@@ -30,7 +30,7 @@
import java.util.TreeMap;
import org.openscience.cdk.interfaces.IMolecule;
import org.openscience.cdk.smsd.helper.FinalMappings;
-import org.openscience.cdk.smsd.helper.MolHandler;
+import org.openscience.cdk.smsd.tools.MolHandler;
import org.openscience.cdk.annotations.TestClass;
import org.openscience.cdk.annotations.TestMethod;
import org.openscience.cdk.exception.CDKException;
View
4 src/main/org/openscience/cdk/smsd/algorithm/mcsplus/ExactMapping.java
@@ -52,7 +52,7 @@
List<Integer> clique_List = new ArrayList<Integer>(clique_List_org);
int clique_siz = clique_List.size();
int vec_size = comp_graph_nodes.size();
- //System.out.println("VEC SIZE " + vec_size);
+// System.out.println("VEC SIZE " + vec_size);
@egonw Owner
egonw added a note

Consider using the ILoggingTool functionality:

logger.debug"(VEC SIZE ", vec_size);

@asad
asad added a note

sure will keep note that for the next update!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
for (int a = 0; a < clique_siz; a++) {
for (int b = 0; b < vec_size; b += 3) {
if (clique_List.get(a) == comp_graph_nodes.get(b + 2)) {
@@ -77,10 +77,8 @@
List<Integer> clique_List_org) {
try {
-
List<Integer> clique_List = extractCliqueMapping(comp_graph_nodes, clique_List_org);
_mappings.add(clique_List);
-
} catch (Exception e) {
System.err.println("Error in FinalMapping List: " + e.getCause());
e.printStackTrace();
View
2  src/main/org/openscience/cdk/smsd/algorithm/mcsplus/GenerateCompatibilityGraph.java
@@ -329,8 +329,6 @@ protected int compatibilityGraphCEdgeZero() throws IOException {
//Size of C and D edges of the compatibility graph
cEdgesSize = cEdges.size();
dEdgesSize = dEdges.size();
-
-
return 0;
}
View
42 src/main/org/openscience/cdk/smsd/algorithm/mcsplus/MCSPlusHandler.java
@@ -37,7 +37,7 @@
import org.openscience.cdk.interfaces.IMolecule;
import org.openscience.cdk.smsd.filters.PostFilter;
import org.openscience.cdk.smsd.helper.FinalMappings;
-import org.openscience.cdk.smsd.helper.MolHandler;
+import org.openscience.cdk.smsd.tools.MolHandler;
import org.openscience.cdk.smsd.interfaces.AbstractMCSAlgorithm;
import org.openscience.cdk.smsd.interfaces.IMCSBase;
@@ -94,6 +94,7 @@ public void set(IAtomContainer source, IAtomContainer target) {
* @param target
*/
@TestMethod("testSet_IMolecule_IMolecule")
+ @Override
@egonw Owner
egonw added a note

This could have been in a separate commit too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
public void set(IMolecule source, IMolecule target) throws CDKException {
IMolecule mol1 = source;
@@ -120,8 +121,6 @@ public void set(String sourceMolFileName, String targetMolFileName) {
MolHandler Reactant = new MolHandler(mol1, false);
MolHandler Product = new MolHandler(mol2, false);
set(Reactant, Product);
-
-
}
/** {@inheritDoc}
@@ -150,9 +149,7 @@ public void searchMCS() {
} else {
flagExchange = true;
mappings = new MCSPlus().getOverlaps(target, source);
-
}
-
PostFilter.filter(mappings);
setAllMapping();
setAllAtomMapping();
@@ -170,8 +167,7 @@ private final void setAllMapping() {
int counter = 0;
for (Map<Integer, Integer> solution : final_solution) {
// System.out.println("Number of MCS solution: " + solution);
- TreeMap<Integer, Integer> validSolution = new TreeMap<Integer, Integer>();
-
+ Map<Integer, Integer> validSolution = new TreeMap<Integer, Integer>();
if (!flagExchange) {
for (Map.Entry<Integer, Integer> map : solution.entrySet()) {
validSolution.put(map.getKey(), map.getValue());
@@ -193,34 +189,29 @@ private final void setAllMapping() {
private final synchronized void setAllAtomMapping() {
try {
- List<Map<Integer, Integer>> final_solution = FinalMappings.getInstance().getFinalMapping();
int counter = 0;
- for (Map<Integer, Integer> solution : final_solution) {
-
-
+ for (Map<Integer, Integer> solution : allMCS) {
Map<IAtom, IAtom> atomMappings = new HashMap<IAtom, IAtom>();
-
for (Map.Entry<Integer, Integer> map : solution.entrySet()) {
int IIndex = map.getKey();
int JIndex = map.getValue();
-
IAtom sourceAtom = null;
IAtom targetAtom = null;
-
- if (!flagExchange) {
- sourceAtom = source.getAtom(IIndex);
- targetAtom = target.getAtom(JIndex);
- } else {
- sourceAtom = source.getAtom(JIndex);
- targetAtom = target.getAtom(IIndex);
- }
-
+//
+// if (!flagExchange) {
+// sourceAtom = source.getAtom(IIndex);
+// targetAtom = target.getAtom(JIndex);
+// } else {
+// sourceAtom = source.getAtom(JIndex);
+// targetAtom = target.getAtom(IIndex);
+// }
+ sourceAtom = source.getAtom(IIndex);
+ targetAtom = target.getAtom(JIndex);
atomMappings.put(sourceAtom, targetAtom);
}
-
allAtomMCS.add(counter++, atomMappings);
}
} catch (Exception I) {
@@ -231,15 +222,14 @@ private final synchronized void setAllAtomMapping() {
private synchronized void setFirstMapping() {
if (!allMCS.isEmpty()) {
- firstMCS = new TreeMap<Integer, Integer>(allMCS.get(0));
+ firstMCS = new TreeMap<Integer, Integer>(allMCS.iterator().next());
}
}
private synchronized void setFirstAtomMapping() {
if (!allAtomMCS.isEmpty()) {
- atomsMCS = new HashMap<IAtom, IAtom>(allAtomMCS.get(0));
+ atomsMCS = new HashMap<IAtom, IAtom>(allAtomMCS.iterator().next());
}
-
}
/** {@inheritDoc}
View
2  src/main/org/openscience/cdk/smsd/algorithm/single/SingleMapping.java
@@ -138,10 +138,8 @@ private void postFilter() {
List<TreeMap<Integer, Integer>> SortedMap = new ArrayList<TreeMap<Integer, Integer>>();
connectedBondOrder = sortByValue(connectedBondOrder);
for (Map.Entry<Integer, Integer> map : connectedBondOrder.entrySet()) {
-
TreeMap<Integer, Integer> mapToBeMoved = mappings.get(map.getKey());
SortedMap.add(mapToBeMoved);
-
}
mappings = SortedMap;
FinalMappings final_MAPPINGS = FinalMappings.getInstance();
View
9 src/main/org/openscience/cdk/smsd/algorithm/single/SingleMappingHandler.java
@@ -31,7 +31,7 @@
import org.openscience.cdk.annotations.TestClass;
import org.openscience.cdk.annotations.TestMethod;
import org.openscience.cdk.smsd.helper.FinalMappings;
-import org.openscience.cdk.smsd.helper.MolHandler;
+import org.openscience.cdk.smsd.tools.MolHandler;
import org.openscience.cdk.smsd.interfaces.AbstractMCSAlgorithm;
import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.interfaces.IAtom;
@@ -193,11 +193,8 @@ private final synchronized void setAllAtomMapping() {
sourceAtom = source.getAtom(IIndex);
targetAtom = target.getAtom(JIndex);
-
atomMappings.put(sourceAtom, targetAtom);
-
}
-
allAtomMCS.add(counter++, atomMappings);
}
} catch (Exception I) {
@@ -208,14 +205,14 @@ private final synchronized void setAllAtomMapping() {
private synchronized void setFirstMapping() {
if (allMCS.size() > 0) {
- firstMCS = new TreeMap<Integer, Integer>(allMCS.get(0));
+ firstMCS = new TreeMap<Integer, Integer>(allMCS.iterator().next());
}
}
private synchronized void setFirstAtomMapping() {
if (allAtomMCS.size() > 0) {
- atomsMCS = new HashMap<IAtom, IAtom>(allAtomMCS.get(0));
+ atomsMCS = new HashMap<IAtom, IAtom>(allAtomMCS.iterator().next());
}
}
View
2  src/main/org/openscience/cdk/smsd/algorithm/vflib/VFlibHandler.java
@@ -36,7 +36,7 @@
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.tools.MolHandler;
import org.openscience.cdk.smsd.interfaces.AbstractSubGraph;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IAtomContainer;
View
2  src/main/org/openscience/cdk/smsd/algorithm/vflib/VFlibMCSHandler.java
@@ -40,7 +40,7 @@
import org.openscience.cdk.smsd.algorithm.vflib.interfaces.IQuery;
import org.openscience.cdk.smsd.algorithm.vflib.map.VFMCSMapper;
import org.openscience.cdk.smsd.algorithm.vflib.query.TemplateCompiler;
-import org.openscience.cdk.smsd.helper.MolHandler;
+import org.openscience.cdk.smsd.tools.MolHandler;
import org.openscience.cdk.smsd.interfaces.AbstractMCSAlgorithm;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IAtomContainer;
View
2  src/main/org/openscience/cdk/smsd/algorithm/vflib/VFlibTurboHandler.java
@@ -35,7 +35,7 @@
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.query.TemplateCompiler;
-import org.openscience.cdk.smsd.helper.MolHandler;
+import org.openscience.cdk.smsd.tools.MolHandler;
import org.openscience.cdk.smsd.interfaces.AbstractSubGraph;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IAtomContainer;
View
4 src/main/org/openscience/cdk/smsd/algorithm/vflib/map/VFMCSMapper.java
@@ -26,14 +26,14 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import org.openscience.cdk.interfaces.IAtom;
+import org.openscience.cdk.interfaces.IAtomContainer;
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.interfaces.IState;
import org.openscience.cdk.smsd.algorithm.vflib.query.TemplateCompiler;
import org.openscience.cdk.smsd.algorithm.vflib.validator.VFMatch;
-import org.openscience.cdk.interfaces.IAtom;
-import org.openscience.cdk.interfaces.IAtomContainer;
/**
* This class finds MCS between query and target molecules
View
2  src/main/org/openscience/cdk/smsd/factory/FragmentMatcher.java
@@ -33,7 +33,7 @@
import org.openscience.cdk.smsd.algorithm.mcsplus.MCSPlusHandler;
import org.openscience.cdk.smsd.algorithm.single.SingleMappingHandler;
import org.openscience.cdk.smsd.algorithm.vflib.VFlibMCSHandler;
-import org.openscience.cdk.smsd.helper.MolHandler;
+import org.openscience.cdk.smsd.tools.MolHandler;
import org.openscience.cdk.DefaultChemObjectBuilder;
import org.openscience.cdk.annotations.TestClass;
import org.openscience.cdk.annotations.TestMethod;
View
42 src/main/org/openscience/cdk/smsd/factory/SubStructureSearchAlgorithms.java
@@ -48,7 +48,7 @@
import org.openscience.cdk.smsd.filters.ChemicalFilters;
import org.openscience.cdk.smsd.global.BondType;
import org.openscience.cdk.smsd.global.TimeOut;
-import org.openscience.cdk.smsd.helper.MolHandler;
+import org.openscience.cdk.smsd.tools.MolHandler;
import org.openscience.cdk.smsd.interfaces.Algorithm;
import org.openscience.cdk.smsd.interfaces.AbstractMCS;
import org.openscience.cdk.tools.ILoggingTool;
@@ -186,8 +186,6 @@ private synchronized void cdkMCSAlgorithm() {
firstAtomMCS.putAll(mcs.getFirstAtomMapping());
allAtomMCS.addAll(mcs.getAllAtomMapping());
-
-
}
private synchronized void mcsPlusAlgorithm() {
@@ -289,11 +287,7 @@ private boolean isBondMatch(IAtomContainer Reactant, IAtomContainer Product) {
}
private void defaultAlgorithm() {
- if (BondType.getInstance().isBondSensitive()) {
- cdkMCSAlgorithm();
- } else {
- mcsPlusAlgorithm();
- }
+ cdkMCSAlgorithm();
@egonw Owner
egonw added a note

This is an example of a big functional change. I should really do with:

  1. a good commit message
  2. a unit test, to test the new behavior
@asad
asad added a note

This is change after I have tested many molecules (12000 from KEGG). The MCSPlus is presently suffering from an indexing bug (was introduced at some point while optimising the code) which I will solve it soon (will refer my old svn log at EBI).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
if (isTimeOut() || getFirstAtomMapping() == null) {
vfLibMCS();
}
@@ -514,6 +508,7 @@ public double getTanimotoSimilarity() throws IOException {
int decimalPlaces = 4;
int rAtomCount = 0;
int pAtomCount = 0;
+ double tanimoto = 0.0;
if (!removeHydrogen) {
rAtomCount = rMol.getMolecule().getAtomCount();
pAtomCount = pMol.getMolecule().getAtomCount();
@@ -521,13 +516,13 @@ public double getTanimotoSimilarity() throws IOException {
rAtomCount = rMol.getMolecule().getAtomCount() - getHCount(rMol.getMolecule());
pAtomCount = pMol.getMolecule().getAtomCount() - getHCount(pMol.getMolecule());
}
- double matchCount = getFirstMapping().size();
- double tanimoto = (matchCount) / (rAtomCount + pAtomCount - matchCount);
-
- BigDecimal tan = new BigDecimal(tanimoto);
-
- tan = tan.setScale(decimalPlaces, BigDecimal.ROUND_HALF_UP);
- tanimoto = tan.doubleValue();
+ if (getFirstMapping() != null || !getFirstMapping().isEmpty()) {
+ double matchCount = getFirstMapping().size();
+ tanimoto = (matchCount) / (rAtomCount + pAtomCount - matchCount);
+ BigDecimal tan = new BigDecimal(tanimoto);
+ tan = tan.setScale(decimalPlaces, BigDecimal.ROUND_HALF_UP);
+ tanimoto = tan.doubleValue();
+ }
return tanimoto;
}
@@ -610,6 +605,7 @@ public double getEuclideanDistance() throws IOException {
int decimalPlaces = 4;
double source = 0;
double target = 0;
+ double euclidean = -1;
if (!removeHydrogen) {
source = rMol.getMolecule().getAtomCount();
target = pMol.getMolecule().getAtomCount();
@@ -617,12 +613,14 @@ public double getEuclideanDistance() throws IOException {
source = rMol.getMolecule().getAtomCount() - getHCount(rMol.getMolecule());
target = pMol.getMolecule().getAtomCount() - getHCount(pMol.getMolecule());
}
- double common = getFirstMapping().size();
- double euclidean = Math.sqrt(source + target - 2 * common);
- BigDecimal dist = new BigDecimal(euclidean);
- dist = dist.setScale(decimalPlaces, BigDecimal.ROUND_HALF_UP);
- euclidean = dist.doubleValue();
+ if (getFirstMapping() != null || !getFirstMapping().isEmpty()) {
+ double common = getFirstMapping().size();
+ euclidean = Math.sqrt(source + target - 2 * common);
+ BigDecimal dist = new BigDecimal(euclidean);
+ dist = dist.setScale(decimalPlaces, BigDecimal.ROUND_HALF_UP);
+ euclidean = dist.doubleValue();
+ }
return euclidean;
}
@@ -630,6 +628,7 @@ public double getEuclideanDistance() throws IOException {
* {@inheritDoc}
* @return the bondSensitiveTimeOut
*/
+ @Override
public double getBondSensitiveTimeOut() {
return bondSensitiveTimeOut;
}
@@ -638,6 +637,7 @@ public double getBondSensitiveTimeOut() {
* {@inheritDoc}
* @param bondSensitiveTimeOut the bond Sensitive Timeout in mins (default 0.15 min)
*/
+ @Override
public void setBondSensitiveTimeOut(double bondSensitiveTimeOut) {
this.bondSensitiveTimeOut = bondSensitiveTimeOut;
}
@@ -646,6 +646,7 @@ public void setBondSensitiveTimeOut(double bondSensitiveTimeOut) {
* {@inheritDoc}
* @return the bondInSensitiveTimeOut
*/
+ @Override
public double getBondInSensitiveTimeOut() {
return bondInSensitiveTimeOut;
}
@@ -654,6 +655,7 @@ public double getBondInSensitiveTimeOut() {
* {@inheritDoc}
* @param bondInSensitiveTimeOut the bond insensitive Timeout in mins (default 0.15 min)
*/
+ @Override
public void setBondInSensitiveTimeOut(double bondInSensitiveTimeOut) {
this.bondInSensitiveTimeOut = bondInSensitiveTimeOut;
}
View
78 src/main/org/openscience/cdk/smsd/filters/ChemicalFilters.java
@@ -35,7 +35,7 @@
import java.util.Map;
import java.util.TreeMap;
import org.openscience.cdk.smsd.tools.BondEnergies;
-import org.openscience.cdk.smsd.helper.MolHandler;
+import org.openscience.cdk.smsd.tools.MolHandler;
import org.openscience.cdk.CDKConstants;
import org.openscience.cdk.DefaultChemObjectBuilder;
import org.openscience.cdk.annotations.TestClass;
@@ -226,23 +226,31 @@ public synchronized void sortResultsByStereoAndBondMatch() throws CDKException {
boolean flag = false;
if (stereoMatchFlag) {
+ //Higher Score is mapped preferred over lower
stereoScoreMap = sortMapByValueInDecendingOrder(stereoScoreMap);
-
-
- double higestStereoScore = 0.0;
+ double higestStereoScore = stereoScoreMap.isEmpty() ? 0 : stereoScoreMap.values().iterator().next();
+ double secondhigestStereoScore = higestStereoScore;
for (Integer key : stereoScoreMap.keySet()) {
- higestStereoScore = stereoScoreMap.get(key).doubleValue();
+ if (secondhigestStereoScore < higestStereoScore
+ && stereoScoreMap.get(key) > secondhigestStereoScore) {
+ secondhigestStereoScore = stereoScoreMap.get(key);
+ } else if (secondhigestStereoScore == higestStereoScore
+ && stereoScoreMap.get(key) < secondhigestStereoScore) {
+ secondhigestStereoScore = stereoScoreMap.get(key);
+ }
+ }
+
+ if (!stereoScoreMap.isEmpty()) {
flag = true;
clear();
- break;
}
/*Put back the sorted solutions*/
int counter = 0;
for (Integer I : stereoScoreMap.keySet()) {
- if (higestStereoScore == stereoScoreMap.get(I).doubleValue()) {
-
+ if (higestStereoScore == stereoScoreMap.get(I).doubleValue()
+ || secondhigestStereoScore == stereoScoreMap.get(I).doubleValue()) {
addSolution(counter, I,
allStereoAtomMCS,
allStereoMCS,
@@ -251,9 +259,8 @@ public synchronized void sortResultsByStereoAndBondMatch() throws CDKException {
fragmentScoreMap);
counter++;
}
-// System.out.println("Sorted Map Key " + key + " Sorted Value: " + sortedStereoScoreMap.get(key));
+// System.out.println("Sorted Map Key " + I + " Sorted Value: " + stereoScoreMap.get(I));
// System.out.println("sortedAllMCS Key " + key + " Sorted Value: " + sortedAllMCS.get(key));
-
}
if (flag) {
firstSolution.putAll(allMCS.get(0));
@@ -301,8 +308,6 @@ public synchronized void sortResultsByFragments() {
flag = true;
clear();
}
-
-
int counter = 0;
for (Map.Entry<Integer, Integer> map : fragmentScoreMap.entrySet()) {
if (_minFragmentScore == map.getValue().intValue()) {
@@ -421,14 +426,11 @@ public synchronized void sortResultsByEnergies() throws CDKException {
if (ac1Bond != null && ac2Bond != null) {
maps.put(ac1Bond, ac2Bond);
}
-
}
-
}
}
}
}
-
// System.out.println("Mol Map size:" + maps.size());
return maps;
@@ -560,7 +562,6 @@ public int compare(Map.Entry<Integer, Double> entry, Map.Entry<Integer, Double>
*/
@TestMethod("testGetStereoMatches")
public List<Double> getStereoMatches() {
-
return Collections.unmodifiableList(stereoScore);
}
@@ -580,7 +581,6 @@ private IAtomContainer getMappedFragment(IAtomContainer molecule, Map<IAtom, IAt
}
}
} else {
-
System.out.println("1: Reactant, 2: Product " + key + "is invalid option");
}
@@ -639,26 +639,29 @@ private double getBondScore(double score, Map<IBond, IBond> bondMaps) {
}
private double getBondFormalChargeMatches(IBond RBond, IBond PBond) {
@egonw Owner
egonw added a note

Variables names start with a lower case character, per Java convention.

@asad
asad added a note

Agree, will change it in the future updates

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
-
double score = 0.0;
- if (RBond.getAtom(0).getFormalCharge() == PBond.getAtom(0).getFormalCharge()) {
- score += Math.abs(RBond.getAtom(0).getFormalCharge() - PBond.getAtom(0).getFormalCharge());
-
- } else {
- score -= Math.abs(RBond.getAtom(0).getFormalCharge() - PBond.getAtom(0).getFormalCharge());
-
- }
-
-
- if (RBond.getAtom(1).getFormalCharge() == PBond.getAtom(1).getFormalCharge()) {
- score += Math.abs(RBond.getAtom(1).getFormalCharge() - PBond.getAtom(1).getFormalCharge());
-
- } else {
- score -= Math.abs(RBond.getAtom(1).getFormalCharge() - PBond.getAtom(1).getFormalCharge());
+ if (RBond.getAtom(0).getID().equals(PBond.getAtom(0).getID())
+ && RBond.getAtom(1).getID().equals(PBond.getAtom(1).getID())) {
+ if (!RBond.getOrder().equals(PBond.getOrder())
+ && RBond.getAtom(0).getFormalCharge() != PBond.getAtom(0).getFormalCharge()) {
+ score += Math.abs(RBond.getAtom(0).getFormalCharge() - PBond.getAtom(0).getFormalCharge());
+ }
+ if (!RBond.getOrder().equals(PBond.getOrder())
+ && RBond.getAtom(1).getFormalCharge() != PBond.getAtom(1).getFormalCharge()) {
+ score += Math.abs(RBond.getAtom(1).getFormalCharge() - PBond.getAtom(1).getFormalCharge());
+ }
+ } else if (RBond.getAtom(1).getID().equals(PBond.getAtom(0).getID())
+ && RBond.getAtom(0).getID().equals(PBond.getAtom(1).getID())) {
+ if (!RBond.getOrder().equals(PBond.getOrder())
+ && RBond.getAtom(1).getFormalCharge() != PBond.getAtom(0).getFormalCharge()) {
+ score += Math.abs(RBond.getAtom(1).getFormalCharge() - PBond.getAtom(0).getFormalCharge());
+ }
+ if (!RBond.getOrder().equals(PBond.getOrder())
+ && RBond.getAtom(0).getFormalCharge() != PBond.getAtom(1).getFormalCharge()) {
+ score += Math.abs(RBond.getAtom(0).getFormalCharge() - PBond.getAtom(1).getFormalCharge());
+ }
}
-
return score;
-
}
private double getRingMatchScore(double score, IAtomContainer subgraphRContainer, IAtomContainer subgraphPContainer) {
@@ -683,7 +686,6 @@ private double getRingMatchScore(double score, IAtomContainer subgraphRContainer
if (rLength > pLength) {
score += (rLength - pLength) * 2;
}
-
}
return score;
}
@@ -804,12 +806,10 @@ private double getBondTypeMatches(IBond queryBond, IBond targetBond) {
int ReactantBondType = queryBond.getOrder().ordinal();
int ProductBondType = targetBond.getOrder().ordinal();
-
if ((queryBond.getFlag(CDKConstants.ISAROMATIC) == targetBond.getFlag(CDKConstants.ISAROMATIC))
&& (ReactantBondType == ProductBondType)) {
score += 2;
}
-
if (queryBond.getFlag(CDKConstants.ISAROMATIC) && targetBond.getFlag(CDKConstants.ISAROMATIC)) {
score += 4;
}
@@ -824,15 +824,12 @@ private double getBondTypeMatches(IBond queryBond, IBond targetBond) {
score += Math.abs(ReactantBondType - ProductBondType);
}
}
-
return score;
}
private int getFragmentCount(IAtomContainer molecule) {
boolean fragmentFlag = true;
-
IAtomContainerSet fragmentMolSet = DefaultChemObjectBuilder.getInstance().newInstance(IMoleculeSet.class);
-
int countFrag = 0;
if (molecule.getAtomCount() > 0) {
fragmentFlag = ConnectivityChecker.isConnected(molecule);
@@ -843,7 +840,6 @@ private int getFragmentCount(IAtomContainer molecule) {
}
countFrag = fragmentMolSet.getAtomContainerCount();
}
-
return countFrag;
}
}
View
2  src/main/org/openscience/cdk/smsd/helper/FinalMappings.java
@@ -41,7 +41,7 @@
@TestClass("org.openscience.cdk.smsd.helper.FinalMappingsTest")
public class FinalMappings implements IFinalMapping {
- private List<Map<Integer, Integer>> mappings = null;
+ private static List<Map<Integer, Integer>> mappings = null;
private static FinalMappings instance = null;
protected FinalMappings() {
View
2  src/main/org/openscience/cdk/smsd/interfaces/IMCSBase.java
@@ -29,7 +29,7 @@
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.interfaces.IMolecule;
-import org.openscience.cdk.smsd.helper.MolHandler;
+import org.openscience.cdk.smsd.tools.MolHandler;
/**
* Interface that holds basic core interface for all MCS algorithm.
View
112 src/main/org/openscience/cdk/smsd/tools/ExtAtomContainerManipulator.java
@@ -24,6 +24,7 @@
*/
package org.openscience.cdk.smsd.tools;
+import org.openscience.reactionblast.tools.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -32,15 +33,11 @@
import javax.vecmath.Point2d;
import javax.vecmath.Point3d;
-import org.openscience.cdk.Atom;
import org.openscience.cdk.Bond;
-import org.openscience.cdk.PseudoAtom;
import org.openscience.cdk.interfaces.IAtomParity;
import org.openscience.cdk.interfaces.IBond.Order;
import org.openscience.cdk.interfaces.ILonePair;
-import org.openscience.cdk.interfaces.ISingleElectron;
import org.openscience.cdk.CDKConstants;
-import org.openscience.cdk.DefaultChemObjectBuilder;
import org.openscience.cdk.annotations.TestClass;
import org.openscience.cdk.annotations.TestMethod;
import org.openscience.cdk.aromaticity.CDKHueckelAromaticityDetector;
@@ -71,25 +68,31 @@
@TestClass("org.openscience.cdk.smsd.tools.ExtAtomContainerManipulatorTest")
public class ExtAtomContainerManipulator extends AtomContainerManipulator {
+ private static void printAtoms(IAtomContainer mol) {
+ System.out.print("Atom: ");
+ for (IAtom a : mol.atoms()) {
+
+ System.out.print(a.getSymbol());
+ System.out.print("[" + a.getFormalCharge() + "]");
+ if (a.getID() != null) {
+ System.out.print("[" + a.getID() + "]");
+ }
+
+ }
+ System.out.println();
+ System.out.println();
+ }
+
/**
* Retrurns deep copy of the molecule
* @param container
* @return deep copy of the mol
*/
@TestMethod("testMakeDeepCopy")
- public static IMolecule makeDeepCopy(IAtomContainer container) {
-
- IMolecule newAtomContainer = DefaultChemObjectBuilder.getInstance().newInstance(IMolecule.class);
+ public static IAtomContainer makeDeepCopy(IAtomContainer container) {
-
- int lonePairCount = container.getLonePairCount();
- int singleElectronCount = container.getSingleElectronCount();
-
-
- ILonePair[] lonePairs = new ILonePair[lonePairCount];
- ISingleElectron[] singleElectrons = new ISingleElectron[singleElectronCount];
-
+ IAtomContainer newAtomContainer = container.getBuilder().newInstance(IAtomContainer.class);
// Deep copy of the Atoms
IAtom[] atoms = copyAtoms(container, newAtomContainer);
@@ -98,26 +101,58 @@ public static IMolecule makeDeepCopy(IAtomContainer container) {
// Deep copy of the LonePairs
for (int index = 0; index < container.getLonePairCount(); index++) {
-
- if (container.getAtom(index).getSymbol().equalsIgnoreCase("R")) {
- lonePairs[index] = DefaultChemObjectBuilder.getInstance().newInstance(ILonePair.class, container.getAtom(index));
+ if (container.getAtom(index).getSymbol().equalsIgnoreCase("R") || container.getAtom(index).getSymbol().equalsIgnoreCase("A")) {
+ newAtomContainer.addLonePair(container.getBuilder().newInstance(ILonePair.class, container.getAtom(index)));
+ } else {
+ newAtomContainer.addLonePair(index);
}
- newAtomContainer.addLonePair(lonePairs[index]);
}
for (int index = 0; index < container.getSingleElectronCount(); index++) {
- singleElectrons[index] = DefaultChemObjectBuilder.getInstance().newInstance(ISingleElectron.class, container.getAtom(index));
- newAtomContainer.addSingleElectron(singleElectrons[index]);
-
+ newAtomContainer.addSingleElectron(index);
}
newAtomContainer.setProperties(container.getProperties());
newAtomContainer.setFlags(container.getFlags());
-
newAtomContainer.setID(container.getID());
-
newAtomContainer.notifyChanged();
+
return newAtomContainer;
+ }
+
+ /**
+ * Retrurns deep copy of the molecule
+ * @param container
+ * @return deep copy of the mol
+ */
+ @TestMethod("testMakeDeepCopy")
+ public static IMolecule makeDeepCopy(IMolecule container) {
+ IMolecule newMolecule = container.getBuilder().newInstance(IMolecule.class);
+// Deep copy of the Atoms
+ IAtom[] atoms = copyAtoms(container, newMolecule);
+
+// Deep copy of the bonds
+ copyBonds(atoms, container, newMolecule);
+
+// Deep copy of the LonePairs
+ for (int index = 0; index < container.getLonePairCount(); index++) {
+ if (container.getAtom(index).getSymbol().equalsIgnoreCase("R") || container.getAtom(index).getSymbol().equalsIgnoreCase("A")) {
+ newMolecule.addLonePair(container.getBuilder().newInstance(ILonePair.class, container.getAtom(index)));
+ } else {
+ newMolecule.addLonePair(index);
+ }
+ }
+
+ for (int index = 0; index < container.getSingleElectronCount(); index++) {
+ newMolecule.addSingleElectron(index);
+ }
+
+ newMolecule.setProperties(container.getProperties());
+ newMolecule.setFlags(container.getFlags());
+ newMolecule.setID(container.getID());
+ newMolecule.notifyChanged();
+
+ return newMolecule;
}
/**
@@ -205,12 +240,11 @@ public static int getExplicitHydrogenCount(IAtomContainer atomContainer, IAtom a
/**
* Returns The number of Implicit Hydrogen Count for a given IAtom.
- * @param atomContainer
* @param atom
* @return Implicit Hydrogen Count
*/
@TestMethod("testGetImplicitHydrogenCount")
- public static int getImplicitHydrogenCount(IAtomContainer atomContainer, IAtom atom) {
+ public static int getImplicitHydrogenCount(IAtom atom) {
return atom.getHydrogenCount() == CDKConstants.UNSET ? 0 : atom.getHydrogenCount();
}
@@ -222,7 +256,7 @@ public static int getImplicitHydrogenCount(IAtomContainer atomContainer, IAtom a
*/
@TestMethod("testGetHydrogenCount")
public static int getHydrogenCount(IAtomContainer atomContainer, IAtom atom) {
- return getExplicitHydrogenCount(atomContainer, atom) + getImplicitHydrogenCount(atomContainer, atom);
+ return getExplicitHydrogenCount(atomContainer, atom) + getImplicitHydrogenCount(atom);
}
/**
@@ -233,7 +267,7 @@ public static int getHydrogenCount(IAtomContainer atomContainer, IAtom atom) {
* is atom Hydrogen then its not removed.
*/
@TestMethod("testRemoveHydrogensAndPreserveAtomID")
- public static IAtomContainer removeHydrogensAndPreserveAtomID(IAtomContainer atomContainer) {
+ public static IMolecule removeHydrogensExceptSingleAndPreserveAtomID(IAtomContainer atomContainer) {
Map<IAtom, IAtom> map = new HashMap<IAtom, IAtom>(); // maps original atoms to clones.
List<IAtom> remove = new ArrayList<IAtom>(); // lists removed Hs.
IMolecule mol = null;
@@ -274,15 +308,14 @@ public static IAtomContainer removeHydrogensAndPreserveAtomID(IAtomContainer ato
} else {
mol = atomContainer.getBuilder().newInstance(IMolecule.class, atomContainer);
- mol.setProperties(atomContainer.getProperties());
- mol.setFlags(atomContainer.getFlags());
- if (atomContainer.getID() != null) {
- mol.setID(atomContainer.getID());
- }
if (atomContainer.getAtom(0).getSymbol().equalsIgnoreCase("H")) {
System.err.println("WARNING: single hydrogen atom removal not supported!");
}
-
+ mol.setFlags(atomContainer.getFlags());
+ }
+ mol.setProperties(atomContainer.getProperties());
+ if (atomContainer.getID() != null) {
+ mol.setID(atomContainer.getID());
}
return mol;
@@ -297,7 +330,7 @@ public static IAtomContainer removeHydrogensAndPreserveAtomID(IAtomContainer ato
*/
@TestMethod("testConvertExplicitToImplicitHydrogens")
public static IAtomContainer convertExplicitToImplicitHydrogens(IAtomContainer atomContainer) {
- IAtomContainer mol = atomContainer.getBuilder().newInstance(IAtomContainer.class, atomContainer);
+ IAtomContainer mol = atomContainer.getBuilder().newInstance(IMolecule.class, atomContainer);
convertImplicitToExplicitHydrogens(mol);
if (mol.getAtomCount() > 1) {
mol = removeHydrogens(mol);
@@ -336,15 +369,15 @@ public static void percieveAtomTypesAndConfigureAtoms(IAtomContainer container)
}
}
- private static IAtom[] copyAtoms(IAtomContainer container, IMolecule newAtomContainer) {
+ private static IAtom[] copyAtoms(IAtomContainer container, IAtomContainer newAtomContainer) {
int atomCount = container.getAtomCount();
IAtom[] atoms = new IAtom[atomCount];
for (int index = 0; index < container.getAtomCount(); index++) {
if (container.getAtom(index) instanceof IPseudoAtom) {
- atoms[index] = new PseudoAtom(container.getAtom(index));
+ atoms[index] = container.getBuilder().newInstance(IPseudoAtom.class, container.getAtom(index));
} else {
- atoms[index] = new Atom(container.getAtom(index));
+ atoms[index] = container.getBuilder().newInstance(IAtom.class, container.getAtom(index));
}
set2D(container, index, atoms);
@@ -356,13 +389,12 @@ public static void percieveAtomTypesAndConfigureAtoms(IAtomContainer container)
setStereoParity(container, index, atoms);
newAtomContainer.addAtom(atoms[index]);
setAtomParity(container, index, newAtomContainer);
-
}
return atoms;
}
- private static void copyBonds(IAtom[] atoms, IAtomContainer container, IMolecule newAtomContainer) {
+ private static void copyBonds(IAtom[] atoms, IAtomContainer container, IAtomContainer newAtomContainer) {
int bondCount = container.getBondCount();
IBond[] bonds = new IBond[bondCount];
for (int index = 0; index < container.getBondCount(); index++) {
View
213 src/main/org/openscience/cdk/smsd/tools/MDLFileReader.java
@@ -1,213 +0,0 @@
-/* Copyright (C) 2006-2010 Syed Asad Rahman {asad@ebi.ac.uk}
- *
- * Contact: cdk-devel@lists.sourceforge.net
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License
- * as published by the Free Software Foundation; either version 2.1
- * of the License, or (at your option) any later version.
- * All we ask is that proper credit is given for our work, which includes
- * - but is not limited to - adding the above copyright notice to the beginning
- * of your source code files, and to any copyright notice that you may distribute
- * with programs based on this work.
- *
- * This program is distributed inputStream the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-package org.openscience.cdk.smsd.tools;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.Reader;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import org.openscience.cdk.ChemModel;
-import org.openscience.cdk.Molecule;
-import org.openscience.cdk.annotations.TestClass;
-import org.openscience.cdk.annotations.TestMethod;
-import org.openscience.cdk.exception.CDKException;
-import org.openscience.cdk.geometry.GeometryTools;
-import org.openscience.cdk.graph.ConnectivityChecker;
-import org.openscience.cdk.interfaces.IAtomContainer;
-import org.openscience.cdk.interfaces.IChemModel;
-import org.openscience.cdk.interfaces.IMolecule;
-import org.openscience.cdk.io.IChemObjectReader.Mode;
-import org.openscience.cdk.io.MDLReader;
-import org.openscience.cdk.io.MDLV2000Reader;
-import org.openscience.cdk.io.MDLV3000Reader;
-import org.openscience.cdk.layout.StructureDiagramGenerator;
-import org.openscience.cdk.tools.manipulator.MoleculeSetManipulator;
-
-/**
- * Class that reads MDL files (various versions).
- * @cdk.module smsd
- * @cdk.githash
- * @author Syed Asad Rahman <asad@ebi.ac.uk>
- */
-@TestClass("org.openscience.cdk.smsd.tools.MDLFileReaderTest")
-public class MDLFileReader {
-
- private static IMolecule molecule = null;
-
- /**
- * Constructor for MDL file reader
- * @param inputStream
- * @param mode
- * @throws IOException
- */
- @TestMethod("MDLFileReaderTest")
- public MDLFileReader(InputStream inputStream, Mode mode) throws IOException {
-
- try {
- MDLV2000Reader reader2 = new MDLV2000Reader(inputStream, mode);
- molecule = (IMolecule) reader2.read(new Molecule());
- reader2.close();
- } catch (CDKException e) {
- String string = e.toString();
- if (string.contains("This file must be read with the MDLV3000Reader.")) {
- MDLV3000Reader reader2 = new MDLV3000Reader(inputStream, mode);
- try {
- molecule = (IMolecule) reader2.read(new Molecule());
- } catch (CDKException ex) {
- Logger.getLogger(MDLFileReader.class.getName()).log(Level.SEVERE, null, ex);
- }
- reader2.close();
-
- } else if (string.contains("This file must be read with the MDLReader.")) {
- try {
- MDLReader reader2 = new MDLReader(inputStream, mode);
- molecule = (IMolecule) reader2.read(new Molecule());
- reader2.close();
- } catch (CDKException ex) {
- Logger.getLogger(MDLFileReader.class.getName()).log(Level.SEVERE, null, ex);
- }
-
-
- }
-
-
- }
-
- }
-
- /**
- * Constructor for MDL file reader
- * @param inputStream
- * @throws IOException
- * @throws CDKException
- */
- @TestMethod("MDLFileReaderTest")
- public MDLFileReader(InputStream inputStream) throws IOException, CDKException {
- this(inputStream, Mode.RELAXED);
- }
-
- /**
- * Constructor for MDL file reader
- * @param reader
- * @throws IOException
- * @throws CDKException
- */
- @TestMethod("MDLFileReaderTest")
- public MDLFileReader(Reader reader) throws IOException, CDKException {
- this(reader, Mode.RELAXED);
- }
-
- /**
- * Constructor for MDL file reader
- * @param reader
- * @param mode
- * @throws IOException
- */
- @TestMethod("MDLFileReaderTest")
- public MDLFileReader(Reader reader, Mode mode) throws IOException {
-
- try {
- MDLV2000Reader reader2 = new MDLV2000Reader(reader, mode);
- molecule = (IMolecule) reader2.read(new Molecule());
- reader2.close();
- } catch (CDKException e) {
- String string = e.toString();
- if (string.contains("This file must be read with the MDLV3000Reader.")) {
- MDLV3000Reader reader2 = new MDLV3000Reader(reader, mode);
- try {
- molecule = (IMolecule) reader2.read(new Molecule());
- } catch (CDKException ex) {
- Logger.getLogger(MDLFileReader.class.getName()).log(Level.SEVERE, null, ex);
- }
- reader2.close();
-
- } else if (string.contains("This file must be read with the MDLReader.")) {
- try {
- MDLReader reader2 = new MDLReader(reader, mode);
- molecule = (IMolecule) reader2.read(new Molecule());
- reader2.close();
- } catch (CDKException ex) {
- Logger.getLogger(MDLFileReader.class.getName()).log(Level.SEVERE, null, ex);
- }
-
-
- }
-
-
- }
-
- }
-
- /**
- * Returns read molecule
- * @return read molecule
- */
- @TestMethod("testGetMolecule")
- public IMolecule getMolecule() {
- return molecule;
- }
-
- /**
- * Returns moecule with cleaned Layout
- * @return cleaned Layout molecule
- */
- @TestMethod("testGetMoleculeWithLayoutCheck")
- public IMolecule getMoleculeWithLayoutCheck() {
- if (GeometryTools.has2DCoordinatesNew(molecule) != 2) {
- try {
- StructureDiagramGenerator sdg = new StructureDiagramGenerator(molecule);
- sdg.generateCoordinates();
- molecule = sdg.getMolecule();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- return molecule;
- }
-
- /**
- * Returns molecule with new layout
- * @return cleaned model
- */
- @TestMethod("testGetChemModelWithMoleculeWithLayoutCheck")
- public IChemModel getChemModelWithMoleculeWithLayoutCheck() {
- IChemModel chemModel = new ChemModel();
- chemModel.setMoleculeSet(ConnectivityChecker.partitionIntoMolecules(molecule));
- for (IAtomContainer mol : MoleculeSetManipulator.getAllAtomContainers(chemModel.getMoleculeSet())) {
- if (GeometryTools.has2DCoordinatesNew(mol) != 2) {
- try {
- StructureDiagramGenerator sdg = new StructureDiagramGenerator((IMolecule) mol);
- sdg.generateCoordinates();
- sdg.getMolecule();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- return chemModel;
- }
-}
-
-
View
94 ...n/org/openscience/cdk/smsd/helper/MolHandler.java → ...in/org/openscience/cdk/smsd/tools/MolHandler.java
@@ -22,7 +22,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-package org.openscience.cdk.smsd.helper;
+package org.openscience.cdk.smsd.tools;
//~--- JDK imports ------------------------------------------------------------
import java.io.FileInputStream;
@@ -30,8 +30,7 @@
import java.io.InputStreamReader;
import java.util.logging.Level;
//~--- non-JDK imports --------------------------------------------------------
-import org.openscience.cdk.smsd.tools.ExtAtomContainerManipulator;
-import org.openscience.cdk.smsd.tools.MoleculeSanityCheck;
+import org.openscience.reactionblast.tools.ExtAtomContainerManipulator;
import org.openscience.cdk.DefaultChemObjectBuilder;
import org.openscience.cdk.Molecule;
import org.openscience.cdk.annotations.TestClass;
@@ -42,7 +41,6 @@
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.interfaces.IAtomContainerSet;
import org.openscience.cdk.interfaces.IMolecule;
-import org.openscience.cdk.interfaces.IMoleculeSet;
import org.openscience.cdk.io.MDLReader;
import org.openscience.cdk.tools.ILoggingTool;
import org.openscience.cdk.tools.LoggingToolFactory;
@@ -56,7 +54,7 @@
@TestClass("org.openscience.cdk.smsd.helper.MolHandlerTest")
public class MolHandler {
- private IAtomContainer mol = null;
+ private IAtomContainer atomContainer = null;
private IAtomContainerSet fragmentMolSet = null;
private boolean removeHydrogen = false;
private boolean connectedFlag = false;
@@ -65,24 +63,24 @@
private void checkFragmentation() {
- if (mol.getAtomCount() > 0) {
- connectedFlag = ConnectivityChecker.isConnected(mol);
+ if (atomContainer.getAtomCount() > 0) {
+ connectedFlag = ConnectivityChecker.isConnected(atomContainer);
}
- fragmentMolSet = DefaultChemObjectBuilder.getInstance().newInstance(IMoleculeSet.class);
+ fragmentMolSet = DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainerSet.class);
if (!connectedFlag) {
- fragmentMolSet.add(ConnectivityChecker.partitionIntoMolecules(mol));
- fragmentMolSet.setID(mol.getID());
+ fragmentMolSet.add(ConnectivityChecker.partitionIntoMolecules(atomContainer));
+ fragmentMolSet.setID(atomContainer.getID());
} else {
- fragmentMolSet.addAtomContainer(mol);
- fragmentMolSet.setID(mol.getID());
+ fragmentMolSet.addAtomContainer(atomContainer);
+ fragmentMolSet.setID(atomContainer.getID());
}
}
/**
* Creates a new instance of MolHandler
- * @param MolFile mol file name
+ * @param MolFile atomContainer file name
* @param cleanMolecule
* @param removeHydrogen
*
@@ -97,14 +95,14 @@ public MolHandler(String MolFile, boolean cleanMolecule, boolean removeHydrogen)
readMolecule = new FileInputStream(MolFile);
molRead = new MDLReader(new InputStreamReader(readMolecule));
- this.mol = (IMolecule) molRead.read(new Molecule());
+ this.atomContainer = (IMolecule) molRead.read(new Molecule());
if (cleanMolecule) {
- MoleculeSanityCheck.fixAromaticity((IMolecule) mol);
+ MoleculeSanityCheck.fixAromaticity((IMolecule) atomContainer);
}
- BondTools.makeUpDownBonds(mol);
+ BondTools.makeUpDownBonds(atomContainer);
/*Remove Hydrogen by Asad*/
if (removeHydrogen) {
- mol = ExtAtomContainerManipulator.removeHydrogens(mol);
+ atomContainer = ExtAtomContainerManipulator.removeHydrogens(atomContainer);
}
checkFragmentation();
} catch (IOException ex) {
@@ -131,15 +129,14 @@ public MolHandler(String MolFile, boolean cleanMolecule) {
ReadMolecule = new FileInputStream(MolFile);
molRead = new MDLReader(new InputStreamReader(ReadMolecule));
- this.mol = (IMolecule) molRead.read(new Molecule());
+ this.atomContainer = (IMolecule) molRead.read(new Molecule());
if (cleanMolecule) {
- MoleculeSanityCheck.fixAromaticity((IMolecule) mol);
+ MoleculeSanityCheck.fixAromaticity(atomContainer);
}
- BondTools.makeUpDownBonds(mol);
+ BondTools.makeUpDownBonds(atomContainer);
/*Remove Hydrogen by Asad*/
if (removeHydrogen) {
- mol = ExtAtomContainerManipulator.removeHydrogens(mol);
-
+ atomContainer = ExtAtomContainerManipulator.removeHydrogens(atomContainer);
}
checkFragmentation();
@@ -153,72 +150,71 @@ public MolHandler(String MolFile, boolean cleanMolecule) {
/**
* Creates a new instance of MolHandler
- * @param molecule Molecule AtomContainer
+ * @param container Molecule AtomContainer
* @param cleanMolecule
* @param removeHydrogen
*/
@TestMethod("MolHandlerTest")
- public MolHandler(IAtomContainer molecule, boolean cleanMolecule, boolean removeHydrogen) {
+ public MolHandler(IAtomContainer container, boolean cleanMolecule, boolean removeHydrogen) {
- String molID = molecule.getID();
+ String molID = container.getID();
this.removeHydrogen = removeHydrogen;
- this.mol = molecule;
+ this.atomContainer = container;
if (cleanMolecule) {
- MoleculeSanityCheck.fixAromaticity((IMolecule) mol);
- } /*Hydrogen are always removed for this molecule before mapping*/
+ MoleculeSanityCheck.fixAromaticity(atomContainer);
+ } /*Hydrogen are always removed for this container before mapping*/
if (removeHydrogen) {
try {
- this.mol = (IMolecule) ExtAtomContainerManipulator.removeHydrogensAndPreserveAtomID(mol);
- mol.setID(molID);
+ this.atomContainer = ExtAtomContainerManipulator.removeHydrogensExceptSingleAndPreserveAtomID(atomContainer);
+ atomContainer.setID(molID);
} catch (Exception ex) {
Logger.error(Level.SEVERE, null, ex);
}
} else {
- this.mol = DefaultChemObjectBuilder.getInstance().newInstance(IMolecule.class, mol);
- mol.setID(molID);
-
+ this.atomContainer = container.getBuilder().newInstance(IAtomContainer.class, atomContainer);
+ atomContainer.setID(molID);
}
checkFragmentation();
}
/**
* Creates a new instance of MolHandler
- * @param molecule
+ * @param container
* @param cleanMolecule
*/
@TestMethod("MolHandlerTest")
- public MolHandler(IAtomContainer molecule, boolean cleanMolecule) {
+ public MolHandler(IAtomContainer container, boolean cleanMolecule) {
- String molID = molecule.getID();
+ String molID = container.getID();
this.removeHydrogen = false;
- this.mol = molecule;
+ this.atomContainer = container;
if (cleanMolecule) {
- MoleculeSanityCheck.fixAromaticity((IMolecule) mol);
- } /*Hydrogen are always removed for this molecule before mapping*/
+ MoleculeSanityCheck.fixAromaticity(atomContainer);
+ } /*Hydrogen are always removed for this container before mapping*/
if (removeHydrogen) {
try {
- this.mol = (IMolecule) ExtAtomContainerManipulator.removeHydrogensAndPreserveAtomID(mol);
- mol.setID(molID);
+ this.atomContainer = ExtAtomContainerManipulator.removeHydrogensExceptSingleAndPreserveAtomID(atomContainer);
+ atomContainer.setID(molID);
} catch (Exception ex) {
Logger.error(Level.SEVERE, null, ex);
}
} else {
- this.mol = DefaultChemObjectBuilder.getInstance().newInstance(IMolecule.class, mol);
- mol.setID(molID);
+ this.atomContainer = container.getBuilder().newInstance(IAtomContainer.class, atomContainer);
+ atomContainer.setID(molID);
}
checkFragmentation();
}
/**
- * Returns the modified molecule
- * @return get processed / modified molecule
+ * Returns the modified container
+ * @return get processed / modified container
*/
@TestMethod("testGetMolecule")
public IAtomContainer getMolecule() {
- return mol;
+ return atomContainer;
}
/**
@@ -231,7 +227,7 @@ public boolean getRemoveHydrogenFlag() {
}
/**
- * Returns Fragmented molecule if getConnectedFlag was false
+ * Returns Fragmented container if getConnectedFlag was false
* @return AtomContainer Set
*/
@TestMethod("testGetFragmentedMolecule")
@@ -240,8 +236,8 @@ public IAtomContainerSet getFragmentedMolecule() {
}
/**
- * Returns true is molecule is not fragmented else false
- * @return true is mol is connected else false
+ * Returns true is container is not fragmented else false
+ * @return true is atomContainer is connected else false
*/
@TestMethod("testGetConnectedFlag")
public boolean getConnectedFlag() {
View
1  src/main/org/openscience/cdk/smsd/tools/MoleculeSanityCheck.java
@@ -24,6 +24,7 @@
*/
package org.openscience.cdk.smsd.tools;
+import org.openscience.reactionblast.tools.ExtAtomContainerManipulator;
import org.openscience.cdk.CDKConstants;
import org.openscience.cdk.annotations.TestClass;
import org.openscience.cdk.annotations.TestMethod;

4 comments on commit 370a926

@egonw

Consider using the ILoggingTool functionality:

logger.debug"(VEC SIZE ", vec_size);

@egonw

This could have been in a separate commit too.

@egonw

This is an example of a big functional change. I should really do with:

  1. a good commit message
  2. a unit test, to test the new behavior
@egonw

Variables names start with a lower case character, per Java convention.

@asad

This is change after I have tested many molecules (12000 from KEGG). The MCSPlus is presently suffering from an indexing bug (was introduced at some point while optimising the code) which I will solve it soon (will refer my old svn log at EBI).

@asad

sure will keep note that for the next update!

@asad

Agree, will change it in the future updates

@egonw
Owner

Asad, it is of utmost importance that you file bug report, that you cannot fix the same day. Or, if it has such an impact as the index bug seems to have, file it always. People need to know that they need to upgrade to the next version, if they use your SMSD code (and I know some are).

For these bugs, you must also add unit tests that shows at least one situation when the bug happens. And please annotate that unit test with "@cdk.bug XXXXX" then. It is really important to disclose these things.

@asad

Your point is valid but I was waiting for the commits. I will file the bug report right away!
Thanks for -> ... "@cdk.bug XXXXX"

@asad

Just filed the bug report. cdk.bug 3021679
Could you please add this to the MCSPlus module and then I will pull the changes.

@egonw
Owner

Sorry, I do not have time for that now.

The @cdk.bug annotation goes on the test... check the existing source code; there is plenty of use of it.

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