From: <mig...@us...> - 2009-02-02 15:33:25
|
Revision: 14045 http://cdk.svn.sourceforge.net/cdk/?rev=14045&view=rev Author: miguelrojasch Date: 2009-02-02 15:33:22 +0000 (Mon, 02 Feb 2009) Log Message: ----------- When a cml contains references it should not add id Modified Paths: -------------- cdk/branches/cdk-1.2.x/src/main/org/openscience/cdk/io/cml/CMLReactionModule.java Modified: cdk/branches/cdk-1.2.x/src/main/org/openscience/cdk/io/cml/CMLReactionModule.java =================================================================== --- cdk/branches/cdk-1.2.x/src/main/org/openscience/cdk/io/cml/CMLReactionModule.java 2009-02-02 15:28:14 UTC (rev 14044) +++ cdk/branches/cdk-1.2.x/src/main/org/openscience/cdk/io/cml/CMLReactionModule.java 2009-02-02 15:33:22 UTC (rev 14045) @@ -25,8 +25,10 @@ */ package org.openscience.cdk.io.cml; +import org.openscience.cdk.interfaces.IAtomContainer; import org.openscience.cdk.interfaces.IChemFile; import org.openscience.cdk.interfaces.IMolecule; +import org.openscience.cdk.interfaces.IMoleculeSet; import org.xml.sax.Attributes; /** @@ -74,6 +76,10 @@ objectType = "Reactant"; String id = atts.getValue("id"); if(id != null) currentMolecule.setID(id); + else{ + String ref = atts.getValue("ref"); + if(ref != null)currentMolecule.setID(ref); + } // cdo.setObjectProperty("Reactant", "id", id); } else if ("product".equals(local)) { // cdo.startObject("Product"); @@ -86,6 +92,10 @@ objectType = "Product"; String id = atts.getValue("id"); if(id != null) currentMolecule.setID(id); + else{ + String ref = atts.getValue("ref"); + if(ref != null) currentMolecule.setID(ref); + } // cdo.setObjectProperty("Product", "id", id); } else if ("substance".equals(local)) { // cdo.startObject("Agent"); @@ -98,6 +108,10 @@ objectType = "Agent"; String id = atts.getValue("id"); if(id != null) currentMolecule.setID(id); + else{ + String ref = atts.getValue("ref"); + if(ref != null) currentMolecule.setID(ref); + } // cdo.setObjectProperty("Agent", "id", id); } else if ("molecule".equals(local)) { // do nothing for now @@ -106,6 +120,13 @@ if(id != null) { // cdo.setObjectProperty(objectType, "id", id); currentMolecule.setID(id); + }else{ + String ref = atts.getValue("ref"); + if(ref != null){ + IAtomContainer atomC = getMoleculeFromID(currentMoleculeSet, ref); + super.currentMolecule = atomC; +// currentMolecule.setID(ref); + } } } else { super.startElement(xpath, uri, local, raw, atts); @@ -132,11 +153,27 @@ currentReaction.addAgent((IMolecule)currentMolecule); } else if ("molecule".equals(local)) { logger.debug("Storing Molecule"); - super.storeData(); + //if the current molecule exists in the currentMoleculeSet means that is a reference in these. + if(currentMoleculeSet.getMultiplier(currentMolecule) == -1) + super.storeData(); // do nothing else but store atom/bond information } else { super.endElement(xpath, uri, local, raw); } } - + + /** + * Get the IMolecule contained in a IMoleculeSet object with a ID. + * + * @param molSet The IMoleculeSet + * @param id The ID the look + * @return The IMolecule with the ID + */ + private IAtomContainer getMoleculeFromID(IMoleculeSet molSet, String id){ + for (IAtomContainer mol : molSet.molecules()) { + if (mol.getID().equals(id)) + return mol; + } + return null; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |