MDLReader extends DefaultChemObjectReader { @Override public <T extends IChemObject> T read(T object) throws CDKException { if (object instanceof IChemFile) { return (T) readChemFile((IChemFile) object); } else if (object instanceof IChemModel) { return (T) readChemModel((IChemModel) object); } else if (object instanceof IAtomContainer) { return (T) readMolecule((IAtomContainer) object); } else { throw new CDKException("Only supported are ChemFile and Molecule."); } } MDLReader();  MDLReader(InputStream in);  MDLReader(InputStream in, Mode mode);  MDLReader(Reader in);  MDLReader(Reader in, Mode mode); @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); @Override void close(); void customizeJob();  }
@Test public void testMassDiff() throws Exception { String mdl = "deuterium.mol\n" + "\n" + "\n" + " 1 0 0 0 0 1\n" + " 0.0000 0.0000 0.0000 H +1 0 0 0 0\n"; try (MDLReader reader = new MDLReader(new StringReader(mdl), Mode.STRICT)) { IAtomContainer mol = reader.read(new AtomContainer()); IAtom atom = mol.getAtom(0); Assert.assertEquals(1, atom.getAtomicNumber().intValue()); Assert.assertEquals(2, atom.getMassNumber().intValue()); } }
@Test(expected=CDKException.class) public void wrongFormat() throws CDKException { InputStream in = ClassLoader.getSystemResourceAsStream("data/mdl/bug1356.sdf"); MDLReader reader = new MDLReader(in, Mode.STRICT); IChemFile chemfile = DefaultChemObjectBuilder.getInstance().newInstance(IChemFile.class); chemfile = reader.read(chemfile); }