protected File saveAsRXN(IChemModel model, File outFile) throws IOException, CDKException { if(model.getMoleculeSet()!=null && model.getMoleculeSet().getAtomContainerCount()>0){ String error = GT.get("Problems handling data"); String message = GT.get("{0} files cannot contain extra molecules. You painted molecules outside the reaction(s), which will not be in the file. Continue?", "RXN"); int answer = JOptionPane.showConfirmDialog(jcpPanel, message, error, JOptionPane.YES_NO_OPTION); if(answer == JOptionPane.NO_OPTION) return null; } if(model.getReactionSet()==null || model.getReactionSet().getReactionCount()==0){ String error = GT.get("Problems handling data"); String message = GT.get("RXN can only save reactions. You have no reactions painted!"); JOptionPane.showMessageDialog(jcpPanel, message, error, JOptionPane.WARNING_MESSAGE); return null; } logger.info("Saving the contents in an rxn file..."); String fileName = outFile.toString(); if (!fileName.endsWith(".rxn")) { fileName += ".rxn"; outFile = new File(fileName); } outFile=new File(fileName); cow = new MDLRXNWriter(new FileWriter(outFile)); cow.write(model.getReactionSet()); cow.close(); if(jcpPanel instanceof JChemPaintPanel) ((JChemPaintPanel)jcpPanel).setTitle(jcpPanel.getChemModel().getID()); return outFile; }
@BeforeClass public static void setup() { builder = DefaultChemObjectBuilder.getInstance(); setChemObjectIO(new MDLRXNWriter()); }
@Test public void testAccepts() throws Exception { MDLRXNWriter reader = new MDLRXNWriter(); Assert.assertTrue(reader.accepts(Reaction.class)); }
@BeforeClass public static void setup() { builder = DefaultChemObjectBuilder.getInstance(); setChemObjectIO(new MDLRXNWriter()); }
@Test public void testRoundtrip() throws Exception { IReaction reaction = builder.newInstance(IReaction.class); IAtomContainer hydroxide = builder.newInstance(IAtomContainer.class); hydroxide.addAtom(builder.newInstance(IAtom.class, "O")); reaction.addReactant(hydroxide); IAtomContainer proton = builder.newInstance(IAtomContainer.class); proton.addAtom(builder.newInstance(IAtom.class, "H")); reaction.addReactant(proton); IAtomContainer water = builder.newInstance(IAtomContainer.class); water.addAtom(builder.newInstance(IAtom.class, "O")); reaction.addProduct(water); reaction.addMapping(new Mapping(hydroxide.getAtom(0), water.getAtom(0))); // now serialize to MDL RXN StringWriter writer = new StringWriter(10000); String file = ""; MDLRXNWriter mdlWriter = new MDLRXNWriter(writer); mdlWriter.write(reaction); mdlWriter.close(); file = writer.toString(); Assert.assertTrue(file.length() > 0); // now deserialize the MDL RXN output IReaction reaction2 = builder.newInstance(IReaction.class); MDLRXNReader reader = new MDLRXNReader(new StringReader(file)); reaction2 = (IReaction) reader.read(reaction2); reader.close(); Assert.assertEquals(2, reaction2.getReactantCount()); Assert.assertEquals(1, reaction2.getProductCount()); Assert.assertEquals(1, reaction2.getMappingCount()); }
MDLRXNWriter mdlWriter = new MDLRXNWriter(writer); mdlWriter.write(reactionSet); mdlWriter.close();
MDLRXNWriter mdlWriter = new MDLRXNWriter(writer); mdlWriter.write(reactionSet); mdlWriter.close();