/** * @cdk.bug 1750968 */ public IAtomContainer makeBug1750968() throws Exception { String filename = "data/mdl/bug_1750968.mol"; // set up molecule reader InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); ISimpleChemObjectReader molReader = new MDLReader(ins, Mode.STRICT); // read molecule return molReader.read(DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainer.class)); }
@BeforeClass public static void setup() { setSimpleChemObjectReader(new MDLReader(), "data/mdl/Strychnine_nichtOK.mol"); }
@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()); }
@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); }
@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); } }
@Test public void testGetAllAtomContainers_IChemFile() 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()); Assert.assertNotNull(chemFile); List<IAtomContainer> containersList = ChemFileManipulator.getAllAtomContainers(chemFile); Assert.assertEquals(2, containersList.size()); }
@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()); } }
/** * @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(); }
/** * @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); }
/** * Loads a molecule with two adamantanes and one cubane * substructure and tests whether all are found. */ public void getMappedSubstructures_IAtomContainer() throws Exception { // Set up molecule reader String filename = "data/mdl/diadamantane-cubane.mol"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); ISimpleChemObjectReader molReader = new MDLReader(ins, Mode.STRICT); // Read molecule IAtomContainer molecule = (IAtomContainer) molReader.read(DefaultChemObjectBuilder.getInstance().newInstance( IAtomContainer.class)); // Map templates TemplateHandler th = new TemplateHandler(DefaultChemObjectBuilder.getInstance()); IAtomContainerSet mappedStructures = th.getMappedSubstructures(molecule); // Do the Assert.assertion Assert.assertEquals("3 mapped templates", 3, mappedStructures.getAtomContainerCount()); }
/** * 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()); }
/** * @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()); }
@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()); }
/** * @cdk.bug 1014344 */ @Test public void testSFBug1014344_1() throws Exception { String filename_cml = "data/cml/bug1014344-1.cml"; String filename_mol = "data/mdl/bug1014344-1.mol"; InputStream ins1 = this.getClass().getClassLoader().getResourceAsStream(filename_cml); InputStream ins2 = this.getClass().getClassLoader().getResourceAsStream(filename_mol); CMLReader reader1 = new CMLReader(ins1); IChemFile chemFile = (IChemFile) reader1.read(new ChemFile()); IChemSequence seq = chemFile.getChemSequence(0); IChemModel model = seq.getChemModel(0); IAtomContainer mol1 = model.getMoleculeSet().getAtomContainer(0); MDLReader reader2 = new MDLReader(ins2); IAtomContainer mol2 = reader2.read(new AtomContainer()); addImplicitHydrogens(mol1); addImplicitHydrogens(mol2); SmilesGenerator sg = new SmilesGenerator(); String moleculeSmile1 = sg.create(mol1); // logger.debug(filename_cml + " -> " + moleculeSmile1); String moleculeSmile2 = sg.create(mol2); // logger.debug(filename_mol + " -> " + moleculeSmile2); Assert.assertEquals(moleculeSmile1, moleculeSmile2); }
/** * @cdk.bug 1014344 */ @Category(SlowTest.class) // MDL -> CML (slow) -> SMILES round tripping @Test public void testSFBug1014344() throws Exception { String filename = "data/mdl/bug1014344-1.mol"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MDLReader reader = new MDLReader(ins, Mode.STRICT); IAtomContainer mol1 = reader.read(new AtomContainer()); addImplicitHydrogens(mol1); SmilesGenerator sg = new SmilesGenerator(); String molSmiles = sg.create(mol1); StringWriter output = new StringWriter(); CMLWriter cmlWriter = new CMLWriter(output); cmlWriter.write(mol1); CMLReader cmlreader = new CMLReader(new ByteArrayInputStream(output.toString().getBytes())); IAtomContainer mol2 = ((IChemFile) cmlreader.read(new ChemFile())).getChemSequence(0).getChemModel(0) .getMoleculeSet().getAtomContainer(0); addImplicitHydrogens(mol2); String cmlSmiles = sg.create(new AtomContainer(mol2)); Assert.assertEquals(molSmiles, cmlSmiles); }
public void visualFullMolecule2DEvaluation() throws Exception { HydrogenPlacer hydrogenPlacer = new HydrogenPlacer(); String filename = "data/mdl/reserpine.mol"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MDLReader reader = new MDLReader(ins, Mode.STRICT); ChemFile chemFile = (ChemFile) reader.read((ChemObject) new ChemFile()); org.openscience.cdk.interfaces.IChemSequence seq = chemFile.getChemSequence(0); org.openscience.cdk.interfaces.IChemModel model = seq.getChemModel(0); IAtomContainer mol = model.getMoleculeSet().getAtomContainer(0); double bondLength = GeometryUtil.getBondLengthAverage(mol); logger.debug("Read Reserpine"); logger.debug("Starting addition of H's"); addExplicitHydrogens(mol); logger.debug("ended addition of H's"); hydrogenPlacer.placeHydrogens2D(mol, bondLength); }
@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()); }
@Test public void testAccepts() { MDLReader reader = new MDLReader(); reader.setReaderMode(Mode.STRICT); Assert.assertTrue(reader.accepts(ChemFile.class)); Assert.assertTrue(reader.accepts(ChemModel.class)); Assert.assertTrue(reader.accepts(AtomContainer.class)); }
+ " 1 3 1 6 0 0\n" + " 1 4 1 0 0 0\n" + " 1 5 1 1 0 0\n" + " 2 3 1 0 0 0\n" + " 2 6 1 0 0 0\n" + " 2 7 1 6 0 0\n" + " 3 8 1 6 0 0\n" + " 3 9 1 0 0 0\n"; MDLReader reader = new MDLReader(new StringReader(mdl), Mode.STRICT); ChemFile chemFile = (ChemFile) reader.read(new ChemFile()); reader.close();