@Override public void endElement(CMLStack xpath, String uri, String local, String raw) { if ("reaction".equals(local)) { // cdo.endObject("Reaction"); currentReactionSet.addReaction(currentReaction); currentChemModel.setReactionSet(currentReactionSet); } else if ("reactionList".equals(local)) { // cdo.endObject("ReactionSet"); currentChemModel.setReactionSet(currentReactionSet); /* FIXME: this should be when document is closed! */ } else if ("reactant".equals(local)) { // cdo.endObject("Reactant"); currentReaction.addReactant(currentMolecule); } else if ("product".equals(local)) { // cdo.endObject("Product"); currentReaction.addProduct(currentMolecule); } else if ("substance".equals(local)) { // cdo.endObject("Agent"); 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. if (currentMoleculeSet.getMultiplier(currentMolecule) == -1) super.storeData(); // do nothing else but store atom/bond information } else { super.endElement(xpath, uri, local, raw); } }
@Override public void endElement(CMLStack xpath, String uri, String local, String raw) { if ("reaction".equals(local)) { // cdo.endObject("Reaction"); currentReactionSet.addReaction(currentReaction); currentChemModel.setReactionSet(currentReactionSet); } else if ("reactionList".equals(local)) { // cdo.endObject("ReactionSet"); currentChemModel.setReactionSet(currentReactionSet); /* FIXME: this should be when document is closed! */ } else if ("reactant".equals(local)) { // cdo.endObject("Reactant"); currentReaction.addReactant(currentMolecule); } else if ("product".equals(local)) { // cdo.endObject("Product"); currentReaction.addProduct(currentMolecule); } else if ("substance".equals(local)) { // cdo.endObject("Agent"); 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. if (currentMoleculeSet.getMultiplier(currentMolecule) == -1) super.storeData(); // do nothing else but store atom/bond information } else { super.endElement(xpath, uri, local, raw); } }
IAtomContainerSet agentSet = ConnectivityChecker.partitionIntoMolecules(agentContainer); for (int i = 0; i < agentSet.getAtomContainerCount(); i++) { reaction.addAgent(agentSet.getAtomContainer(i));
reaction.addAgent(product);
reaction.addAgent(agent);
break; case Agent: rxn.addAgent(comp); break;
@Test public void testAddAgent_IAtomContainer() { IReaction reaction = (IReaction) newChemObject(); IAtomContainer proton = reaction.getBuilder().newInstance(IAtomContainer.class); reaction.addAgent(proton); Assert.assertEquals(1, reaction.getAgents().getAtomContainerCount()); }
@Test public void testGetAgents() { IReaction reaction = (IReaction) newChemObject(); IAtomContainer water = reaction.getBuilder().newInstance(IAtomContainer.class); reaction.addAgent(water); Assert.assertEquals(1, reaction.getAgents().getAtomContainerCount()); }
@Test public void testReactionCustomization() throws Exception { StringWriter writer = new StringWriter(); IReaction reaction = new Reaction(); reaction.setID("reaction1"); IAtomContainer reactant = reaction.getBuilder().newInstance(IAtomContainer.class); reactant.setID("react"); IAtomContainer product = reaction.getBuilder().newInstance(IAtomContainer.class); product.setID("product"); IAtomContainer agent = reaction.getBuilder().newInstance(IAtomContainer.class); agent.setID("agent"); reaction.addReactant(reactant); reaction.addProduct(product); reaction.addAgent(agent); CMLWriter cmlWriter = new CMLWriter(writer); cmlWriter.write(reaction); cmlWriter.close(); String cmlContent = writer.toString(); logger.debug("****************************** testReactionCustomization()"); logger.debug(cmlContent); logger.debug("******************************"); Assert.assertTrue(cmlContent.indexOf("<reaction id=\"reaction1") != -1); Assert.assertTrue(cmlContent.indexOf("<molecule id=\"react") != -1); Assert.assertTrue(cmlContent.indexOf("<molecule id=\"product") != -1); Assert.assertTrue(cmlContent.indexOf("<molecule id=\"agent") != -1); }
protected static String cansmi(IReaction rxn) throws CDKException { IReaction copy = rxn.getBuilder().newInstance(IReaction.class); for (IAtomContainer mol : rxn.getReactants().atomContainers()) copy.addReactant(AtomContainerManipulator.copyAndSuppressedHydrogens(mol)); for (IAtomContainer mol : rxn.getProducts().atomContainers()) copy.addProduct(AtomContainerManipulator.copyAndSuppressedHydrogens(mol)); for (IAtomContainer mol : rxn.getAgents().atomContainers()) copy.addAgent(AtomContainerManipulator.copyAndSuppressedHydrogens(mol)); return smigen.create(copy); }
atom = reaction.getBuilder().newInstance(IAtom.class, "H"); agent.addAtom(atom); reaction.addAgent(agent);