MDLRXNV2000Reader extends DefaultChemObjectReader { @Override public <T extends IChemObject> T read(T object) throws CDKException { if (object instanceof IReaction) { return (T) readReaction(object.getBuilder()); } else if (object instanceof IReactionSet) { IReactionSet reactionSet = object.getBuilder().newInstance(IReactionSet.class); reactionSet.addReaction(readReaction(object.getBuilder())); return (T) reactionSet; } else if (object instanceof IChemModel) { IChemModel model = object.getBuilder().newInstance(IChemModel.class); IReactionSet reactionSet = object.getBuilder().newInstance(IReactionSet.class); reactionSet.addReaction(readReaction(object.getBuilder())); model.setReactionSet(reactionSet); return (T) model; } else if (object instanceof IChemFile) { IChemFile chemFile = object.getBuilder().newInstance(IChemFile.class); IChemSequence sequence = object.getBuilder().newInstance(IChemSequence.class); sequence.addChemModel((IChemModel) read(object.getBuilder().newInstance(IChemModel.class))); chemFile.addChemSequence(sequence); return (T) chemFile; } else { throw new CDKException("Only supported are Reaction and ChemModel, and not " + object.getClass().getName() + "."); } } MDLRXNV2000Reader(Reader in);  MDLRXNV2000Reader(Reader in, Mode mode);  MDLRXNV2000Reader(InputStream input);  MDLRXNV2000Reader(InputStream input, Mode mode);  MDLRXNV2000Reader(); @Override IResourceFormat getFormat(); @Override void setReader(Reader input); @Override void setReader(InputStream input); @Override boolean accepts(Class<? extends IChemObject> classObject); @Override T read(T object); boolean accepts(IChemObject object); @Override void close();  }
@Test public void testAgentParts() throws Exception { try (InputStream in = this.getClass().getResourceAsStream("ethylesterification.mol"); MDLRXNV2000Reader rdr = new MDLRXNV2000Reader(in);) { IReaction reaction = rdr.read(new Reaction()); assertThat(reaction.getAgents().getAtomContainerCount(), is(1)); } }
@Test public void optionalSdfSeparator() throws Exception { String dummyRecord = "ethanol\n" + " Mrv1810 09251921392D \n" + "\n" + " 3 2 0 0 0 0 999 V2000\n" + " 1.9520 -1.1270 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n" + " 1.2375 -0.7145 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n" + " 2.6664 -0.7145 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0\n" + " 1 2 1 0 0 0 0\n" + " 1 3 1 0 0 0 0\n" + "M END\n" + "$$$$\n"; StringBuilder sb = new StringBuilder(); sb.append("$RXN\n"); sb.append("Test\n\n\n 2 1\n"); sb.append("$MOL\n"); sb.append(dummyRecord); sb.append("$MOL\n"); sb.append(dummyRecord); sb.append("$MOL\n"); sb.append(dummyRecord); IChemObjectBuilder bldr = SilentChemObjectBuilder.getInstance(); try (MDLRXNV2000Reader reader = new MDLRXNV2000Reader(new StringReader(sb.toString()))) { IReaction rxn = reader.read(bldr.newInstance(IReaction.class)); assertThat(rxn.getReactants().getAtomContainerCount(), is(2)); assertThat(rxn.getProducts().getAtomContainerCount(), is(1)); assertThat(rxn.getReactants().getAtomContainer(0).getAtomCount(), is(3)); assertThat(rxn.getReactants().getAtomContainer(1).getAtomCount(), is(3)); } }