@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)); }
private void initIOSettings() { forceReadAs3DCoords = addSetting(new BooleanIOSetting("ForceReadAs3DCoordinates", IOSetting.Importance.LOW, "Should coordinates always be read as 3D?", "false")); }
@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); } }
reader = new MDLV3000Reader(); else if (format instanceof MDLFormat) reader = new MDLReader(); else throw new IllegalArgumentException("Unexpected format: " + format);
@Override public boolean accepts(Class<? extends IChemObject> classObject) { if (IChemFile.class.equals(classObject)) return true; if (IChemModel.class.equals(classObject)) return true; if (IAtomContainer.class.equals(classObject)) return true; Class<?>[] interfaces = classObject.getInterfaces(); for (int i = 0; i < interfaces.length; i++) { if (IChemFile.class.equals(interfaces[i])) return true; if (IChemModel.class.equals(interfaces[i])) return true; if (IAtomContainer.class.equals(interfaces[i])) return true; } Class superClass = classObject.getSuperclass(); if (superClass != null) return this.accepts(superClass); return false; }
@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()); }
/** * @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)); }
@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 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()); } }
@BeforeClass public static void setup() { setSimpleChemObjectReader(new MDLReader(), "data/mdl/Strychnine_nichtOK.mol"); }
/** * @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()); }
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); }
/** * 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()); }
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; }
/** * @cdk.bug 1014344 */ @Test public void testStabilityAfterRoundtrip() 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); 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); labeler.canonLabel(mol1); labeler.canonLabel(mol2); Iterator<IAtom> atoms1 = mol1.atoms().iterator(); Iterator<IAtom> atoms2 = mol2.atoms().iterator(); while (atoms1.hasNext()) { IAtom atom1 = atoms1.next(); IAtom atom2 = atoms2.next(); Assert.assertEquals(atom1.getProperty(InvPair.CANONICAL_LABEL), atom2.getProperty(InvPair.CANONICAL_LABEL)); } }
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());
/** * @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 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 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); }