@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(); file = writer.toString();
MDLRXNWriter mdlWriter = new MDLRXNWriter(writer); mdlWriter.write(reactionSet); mdlWriter.close(); file = writer.toString();