@Test public void testEmptyString() throws Exception { String emptyString = ""; MDLReader reader = new MDLReader(new StringReader(emptyString), Mode.STRICT); IAtomContainer mol = (IAtomContainer) reader.read(new AtomContainer()); reader.close(); Assert.assertNull(mol); }
molRead = new MDLReader(new InputStreamReader(readMolecule)); this.atomContainer = (IAtomContainer) molRead.read(new AtomContainer()); molRead.close(); readMolecule.close(); if (molRead != null) { try { molRead.close(); } catch (IOException ioe) { logger.warn("Couldn't close molReader: ", ioe.getMessage());
@Test(expected = AssertionError.class) public void testHas2DCoordinates_With000() throws Exception { String filenameMol = "data/mdl/with000coordinate.mol"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filenameMol); IAtomContainer molOne = null; MDLReader reader = new MDLReader(ins, Mode.RELAXED); molOne = reader.read(new AtomContainer()); reader.close(); assertNotNull(molOne.getAtom(0).getPoint2d()); }
/** * @cdk.bug 1542467 */ @Test public void testBug1542467() throws Exception { String filename = "data/mdl/Strychnine_nichtOK.mol"; logger.info("Testing: " + filename); InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MDLReader reader = new MDLReader(ins, Mode.STRICT); ChemFile chemFile = (ChemFile) reader.read((ChemObject) new ChemFile()); reader.close(); assertNotNull(chemFile); List<IAtomContainer> containersList = ChemFileManipulator.getAllAtomContainers(chemFile); Assert.assertEquals(1, containersList.size()); Assert.assertTrue((containersList.get(0)).getAtomCount() > 0); Assert.assertTrue((containersList.get(0)).getBondCount() > 0); }
/** * @cdk.bug 1356 */ @Test public void properties() throws Exception { InputStream in = ClassLoader.getSystemResourceAsStream("data/mdl/bug1356.sdf"); MDLReader reader = new MDLReader(in); IChemFile chemfile = DefaultChemObjectBuilder.getInstance().newInstance(IChemFile.class); chemfile = reader.read(chemfile); IAtomContainer container = ChemFileManipulator.getAllAtomContainers(chemfile).iterator().next(); assertNotNull(container.getProperty("first")); assertNotNull(container.getProperty("second")); reader.close(); }
/** * Tests that the '0' read from the bond block for bond stereo * is read is 'no stereochemistry involved'. */ @Test public void testStereoReadZeroDefault() throws Exception { String filename = "data/mdl/prev2000.sd"; logger.info("Testing: " + filename); InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MDLReader reader = new MDLReader(ins, Mode.STRICT); ChemFile chemFile = (ChemFile) reader.read((ChemObject) new ChemFile()); reader.close(); assertNotNull(chemFile); List<IAtomContainer> containersList = ChemFileManipulator.getAllAtomContainers(chemFile); Assert.assertEquals(2, containersList.size()); IAtomContainer container = containersList.get(0); Assert.assertEquals(IBond.Stereo.NONE, container.getBond(0).getStereo()); }
MDLReader reader = new MDLReader(ins); IAtomContainer mol = reader.read(new AtomContainer()); reader.close();
/** * @cdk.bug 3485634 */ @Test public void testMissingAtomProperties() throws Exception { InputStream in = ClassLoader.getSystemResourceAsStream("data/mdl/bug3485634.mol"); MDLReader reader = new MDLReader(in); IAtomContainer molecule = DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainer.class); molecule = reader.read(molecule); reader.close(); Assert.assertEquals(9, molecule.getAtomCount()); }
/** * The corrupt file is really ok; it is just not V2000 material. */ @Test public void testSDF() throws Exception { String filename = "data/mdl/prev2000.sd"; logger.info("Testing: " + filename); InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MDLReader reader = new MDLReader(ins, Mode.STRICT); ChemFile chemFile = (ChemFile) reader.read((ChemObject) new ChemFile()); reader.close(); assertNotNull(chemFile); List<IAtomContainer> containersList = ChemFileManipulator.getAllAtomContainers(chemFile); Assert.assertEquals(2, containersList.size()); Assert.assertEquals(39, (containersList.get(0)).getAtomCount()); Assert.assertEquals(41, (containersList.get(0)).getBondCount()); Assert.assertEquals(29, (containersList.get(1)).getAtomCount()); Assert.assertEquals(28, (containersList.get(1)).getBondCount()); }
public static IAtomContainer loadMolecule(String inFile) { MDLReader mr = null; ChemFile chemFile = null; IChemSequence chemSequence = null; IChemModel chemModel = null; IAtomContainerSet setOfMolecules = null; IAtomContainer molecule = null; try { FileInputStream fis = new FileInputStream(inFile); mr = new MDLReader(fis); chemFile = (ChemFile) mr.read((ChemObject) new ChemFile()); mr.close(); chemSequence = chemFile.getChemSequence(0); chemModel = chemSequence.getChemModel(0); setOfMolecules = chemModel.getMoleculeSet(); molecule = setOfMolecules.getAtomContainer(0); for (int i = 0; i < molecule.getAtomCount(); i++) { molecule.getAtom(i).setPoint2d(null); } } catch (CDKException | IOException exc) { // we just return null if something went wrong logger.error("An exception occurred while loading a molecule: " + inFile); logger.debug(exc); } return molecule; }
@Test public void testReadProton() throws Exception { String mdl = "proton.mol\n" + "\n" + "\n" + " 1 0 0 0 0 1\n" + " -0.0073 -0.5272 0.9655 H 0 3 0 0 0\n"; MDLReader reader = new MDLReader(new StringReader(mdl), Mode.STRICT); IAtomContainer mol = reader.read(new AtomContainer()); reader.close(); assertNotNull(mol); Assert.assertEquals(1, mol.getAtomCount()); Assert.assertEquals(0, mol.getBondCount()); IAtom atom = mol.getAtom(0); Assert.assertEquals(1, atom.getFormalCharge().intValue()); }
@Test public void testUndefinedStereo() throws Exception { String filename = "data/mdl/ChEBI_26120.mol"; logger.info("Testing: " + filename); InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MDLReader reader = new MDLReader(ins, Mode.RELAXED); IAtomContainer mol = (IAtomContainer) reader.read(new AtomContainer()); reader.close(); Assert.assertEquals(IBond.Stereo.E_OR_Z, mol.getBond(1).getStereo()); Assert.assertEquals(IBond.Stereo.E_OR_Z, mol.getBond(6).getStereo()); Assert.assertEquals(IBond.Stereo.E_OR_Z, mol.getBond(7).getStereo()); Assert.assertEquals(IBond.Stereo.E_OR_Z, mol.getBond(11).getStereo()); }
MDLReader reader = new MDLReader(new StringReader(mdl), Mode.STRICT); ChemFile chemFile = (ChemFile) reader.read(new ChemFile()); reader.close(); assertNotNull(chemFile); Assert.assertEquals(1, chemFile.getChemSequenceCount());