Skip to content

Commit

Permalink
Replaced IMolecule* with IAtomContainer*
Browse files Browse the repository at this point in the history
Signed-off-by: Rajarshi  Guha <rajarshi.guha@gmail.com>
  • Loading branch information
egonw authored and rajarshi committed Dec 3, 2011
1 parent 3d3037f commit 7f6617d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 29 deletions.
25 changes: 12 additions & 13 deletions src/main/org/openscience/cdk/io/cml/CMLCoreModule.java
Expand Up @@ -42,13 +42,12 @@
import org.openscience.cdk.geometry.CrystalGeometryTools;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.interfaces.IAtomContainerSet;
import org.openscience.cdk.interfaces.IBond;
import org.openscience.cdk.interfaces.IChemFile;
import org.openscience.cdk.interfaces.IChemModel;
import org.openscience.cdk.interfaces.IChemSequence;
import org.openscience.cdk.interfaces.ICrystal;
import org.openscience.cdk.interfaces.IMolecule;
import org.openscience.cdk.interfaces.IMoleculeSet;
import org.openscience.cdk.interfaces.IMonomer;
import org.openscience.cdk.interfaces.IPseudoAtom;
import org.openscience.cdk.interfaces.IReaction;
Expand Down Expand Up @@ -82,7 +81,7 @@ public class CMLCoreModule implements ICMLModule {
protected IChemFile currentChemFile;

protected IAtomContainer currentMolecule;
protected IMoleculeSet currentMoleculeSet;
protected IAtomContainerSet currentMoleculeSet;
protected IChemModel currentChemModel;
protected IChemSequence currentChemSequence;
protected IReactionSet currentReactionSet;
Expand Down Expand Up @@ -312,8 +311,8 @@ public void startDocument() {
// cdo.startDocument();
currentChemSequence = currentChemFile.getBuilder().newInstance(IChemSequence.class);
currentChemModel = currentChemFile.getBuilder().newInstance(IChemModel.class);
currentMoleculeSet = currentChemFile.getBuilder().newInstance(IMoleculeSet.class);
currentMolecule = currentChemFile.getBuilder().newInstance(IMolecule.class);
currentMoleculeSet = currentChemFile.getBuilder().newInstance(IAtomContainerSet.class);
currentMolecule = currentChemFile.getBuilder().newInstance(IAtomContainer.class);
atomEnumeration = new HashMap<String, IAtom>();
moleculeCustomProperty = new ArrayList<String>();

Expand Down Expand Up @@ -568,8 +567,8 @@ else if (att.equals("occupancy")) {
BUILTIN = "";
// cdo.startObject("Molecule");
if (currentChemModel == null) currentChemModel = currentChemFile.getBuilder().newInstance(IChemModel.class);
if (currentMoleculeSet == null) currentMoleculeSet = currentChemFile.getBuilder().newInstance(IMoleculeSet.class);
currentMolecule = currentChemFile.getBuilder().newInstance(IMolecule.class);
if (currentMoleculeSet == null) currentMoleculeSet = currentChemFile.getBuilder().newInstance(IAtomContainerSet.class);
currentMolecule = currentChemFile.getBuilder().newInstance(IAtomContainer.class);
for (int i = 0; i < atts.getLength(); i++) {
if (atts.getQName(i).equals("id")) {
// cdo.setObjectProperty("Molecule", "id", atts.getValue(i));
Expand Down Expand Up @@ -625,26 +624,26 @@ else if (att.equals("occupancy")) {
}
}
} else if (DICTREF.equals("cdk:moleculeSet")) {
currentMoleculeSet = currentChemFile.getBuilder().newInstance(IMoleculeSet.class);
currentMoleculeSet = currentChemFile.getBuilder().newInstance(IAtomContainerSet.class);
// see if there is an ID attribute
for (int i = 0; i < atts.getLength(); i++) {
String att = atts.getQName(i);
if (att.equals("id")) {
currentMoleculeSet.setID(atts.getValue(i));
}
}
currentMolecule = currentChemFile.getBuilder().newInstance(IMolecule.class);
currentMolecule = currentChemFile.getBuilder().newInstance(IAtomContainer.class);
} else {
// the old default
currentMoleculeSet = currentChemFile.getBuilder().newInstance(IMoleculeSet.class);
currentMoleculeSet = currentChemFile.getBuilder().newInstance(IAtomContainerSet.class);
// see if there is an ID attribute
for (int i = 0; i < atts.getLength(); i++) {
String att = atts.getQName(i);
if (att.equals("id")) {
currentMoleculeSet.setID(atts.getValue(i));
}
}
currentMolecule = currentChemFile.getBuilder().newInstance(IMolecule.class);
currentMolecule = currentChemFile.getBuilder().newInstance(IAtomContainer.class);
}
}else if ("formula".equals(name)){
formulaCounter++;
Expand Down Expand Up @@ -725,9 +724,9 @@ public void endElement(CMLStack xpath, String uri, String name, String raw) {
} else if ("molecule".equals(name)) {
storeData();
// cdo.endObject("Molecule");
if (currentMolecule instanceof IMolecule) {
if (currentMolecule instanceof IAtomContainer) {
logger.debug("Adding molecule to set");
currentMoleculeSet.addAtomContainer((IMolecule)currentMolecule);
currentMoleculeSet.addAtomContainer(currentMolecule);
logger.debug("#mols in set: " + currentMoleculeSet.getAtomContainerCount());
} else if (currentMolecule instanceof ICrystal) {
logger.debug("Adding crystal to chemModel");
Expand Down
25 changes: 12 additions & 13 deletions src/main/org/openscience/cdk/io/cml/CMLReactionModule.java
Expand Up @@ -26,9 +26,8 @@
package org.openscience.cdk.io.cml;

import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.interfaces.IAtomContainerSet;
import org.openscience.cdk.interfaces.IChemFile;
import org.openscience.cdk.interfaces.IMolecule;
import org.openscience.cdk.interfaces.IMoleculeSet;
import org.openscience.cdk.interfaces.IReaction;
import org.openscience.cdk.interfaces.IReactionSet;
import org.xml.sax.Attributes;
Expand Down Expand Up @@ -74,7 +73,7 @@ public void startElement(CMLStack xpath, String uri, String local, String raw, A
currentReactionSet = currentChemFile.getBuilder().newInstance(IReactionSet.class);
currentReaction = currentChemFile.getBuilder().newInstance(IReaction.class);
}
currentMolecule = currentChemFile.getBuilder().newInstance(IMolecule.class);
currentMolecule = currentChemFile.getBuilder().newInstance(IAtomContainer.class);
objectType = "Reactant";
String id = atts.getValue("id");
if(id != null) currentMolecule.setID(id);
Expand All @@ -90,7 +89,7 @@ public void startElement(CMLStack xpath, String uri, String local, String raw, A
currentReactionSet = currentChemFile.getBuilder().newInstance(IReactionSet.class);
currentReaction = currentChemFile.getBuilder().newInstance(IReaction.class);
}
currentMolecule = currentChemFile.getBuilder().newInstance(IMolecule.class);
currentMolecule = currentChemFile.getBuilder().newInstance(IAtomContainer.class);
objectType = "Product";
String id = atts.getValue("id");
if(id != null) currentMolecule.setID(id);
Expand All @@ -106,7 +105,7 @@ public void startElement(CMLStack xpath, String uri, String local, String raw, A
currentReactionSet = currentChemFile.getBuilder().newInstance(IReactionSet.class);
currentReaction = currentChemFile.getBuilder().newInstance(IReaction.class);
}
currentMolecule = currentChemFile.getBuilder().newInstance(IMolecule.class);
currentMolecule = currentChemFile.getBuilder().newInstance(IAtomContainer.class);
objectType = "Agent";
String id = atts.getValue("id");
if(id != null) currentMolecule.setID(id);
Expand Down Expand Up @@ -146,13 +145,13 @@ public void endElement(CMLStack xpath, String uri, String local, String raw) {
/* FIXME: this should be when document is closed! */
} else if ("reactant".equals(local)) {
// cdo.endObject("Reactant");
currentReaction.addReactant((IMolecule)currentMolecule);
currentReaction.addReactant(currentMolecule);
} else if ("product".equals(local)) {
// cdo.endObject("Product");
currentReaction.addProduct((IMolecule)currentMolecule);
currentReaction.addProduct(currentMolecule);
} else if ("substance".equals(local)) {
// cdo.endObject("Agent");
currentReaction.addAgent((IMolecule)currentMolecule);
currentReaction.addAgent(currentMolecule);
} else if ("molecule".equals(local)) {
logger.debug("Storing Molecule");
//if the current molecule exists in the currentMoleculeSet means that is a reference in these.
Expand All @@ -165,14 +164,14 @@ public void endElement(CMLStack xpath, String uri, String local, String raw) {
}

/**
* Get the IMolecule contained in a IMoleculeSet object with a ID.
* Get the IAtomContainer contained in a IAtomContainerSet object with a ID.
*
* @param molSet The IMoleculeSet
* @param molSet The IAtomContainerSet
* @param id The ID the look
* @return The IMolecule with the ID
* @return The IAtomContainer with the ID
*/
private IAtomContainer getMoleculeFromID(IMoleculeSet molSet, String id){
for (IAtomContainer mol : molSet.molecules()) {
private IAtomContainer getMoleculeFromID(IAtomContainerSet molSet, String id){
for (IAtomContainer mol : molSet.atomContainers()) {
if (mol.getID().equals(id))
return mol;
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/org/openscience/cdk/io/cml/PDBConvention.java
Expand Up @@ -34,10 +34,10 @@

import org.openscience.cdk.CDKConstants;
import org.openscience.cdk.config.IsotopeFactory;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.interfaces.IBond;
import org.openscience.cdk.interfaces.IChemFile;
import org.openscience.cdk.interfaces.ICrystal;
import org.openscience.cdk.interfaces.IMolecule;
import org.openscience.cdk.interfaces.IPDBAtom;
import org.openscience.cdk.interfaces.IPDBMonomer;
import org.openscience.cdk.interfaces.IPDBPolymer;
Expand Down Expand Up @@ -216,9 +216,9 @@ public void endElement(CMLStack xpath, String uri, String local, String raw) {
storeData();
if(xpath.sp == 1){
// cdo.endObject("Molecule");
if (currentMolecule instanceof IMolecule) {
if (currentMolecule instanceof IAtomContainer) {
logger.debug("Adding molecule to set");
currentMoleculeSet.addAtomContainer((IMolecule)currentMolecule);
currentMoleculeSet.addAtomContainer(currentMolecule);
logger.debug("#mols in set: " + currentMoleculeSet.getAtomContainerCount());
} else if (currentMolecule instanceof ICrystal) {
logger.debug("Adding crystal to chemModel");
Expand Down

0 comments on commit 7f6617d

Please sign in to comment.