Skip to content

Commit

Permalink
When a reaction references a molecule which is unknown - automaticall…
Browse files Browse the repository at this point in the history
…y create one with that Id. This happens when the set of molecules is defined after the reaction. This commit resolve the test in error 'CML2Test. testBug2697568'

Signed-off-by: Egon Willighagen <egonw@users.sourceforge.net>
  • Loading branch information
johnmay authored and egonw committed Aug 5, 2013
1 parent ac5a3e7 commit a6c96d8
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/main/org/openscience/cdk/io/cml/CMLReactionModule.java
Expand Up @@ -115,18 +115,31 @@ public void startElement(CMLStack xpath, String uri, String local, String raw, A
}
// cdo.setObjectProperty("Agent", "id", id);
} else if ("molecule".equals(local)) {
// do nothing for now
// clear existing molecule data
super.newMolecule();
String id = atts.getValue("id");
if(id != null) {
// cdo.setObjectProperty(objectType, "id", id);
currentMolecule.setID(id);
}else{
if (id != null) {
// check for existing molecule of that id
IAtomContainer existing = getMoleculeFromID(currentMoleculeSet, id);
if (existing != null) {
currentMolecule = existing;
} else {
currentMolecule.setID(id);
}
} else {
String ref = atts.getValue("ref");
if(ref != null){
IAtomContainer atomC = getMoleculeFromID(currentMoleculeSet, ref);

// if there was no molecule create a new one for the reference. this
// happens when the reaction is defined before the molecule set
if (atomC == null) {
atomC = currentChemFile.getBuilder().newInstance(IAtomContainer.class);
atomC.setID(ref);
currentMoleculeSet.addAtomContainer(atomC);
}

super.currentMolecule = atomC;
// currentMolecule.setID(ref);
}
}
} else {
Expand Down

0 comments on commit a6c96d8

Please sign in to comment.