private IAtomContainer fullerene() throws Exception { String path = "/data/mdl/boronBuckyBall.mol"; MDLV2000Reader mdl = new MDLV2000Reader(getClass().getResourceAsStream(path)); try { return mdl.read(new AtomContainer()); } finally { mdl.close(); } }
@Test public void testAccepts() { MDLV2000Reader reader = new MDLV2000Reader(); Assert.assertTrue(reader.accepts(ChemFile.class)); Assert.assertTrue(reader.accepts(ChemModel.class)); Assert.assertTrue(reader.accepts(AtomContainer.class)); }
@Test(expected = CDKException.class) public void readOldJmolCoordsFailOnStrictRead() throws Exception { MDLV2000Reader reader = new MDLV2000Reader(); reader.setReaderMode(IChemObjectReader.Mode.STRICT); reader.readMDLCoordinate(" -2.00120 7.8089", 0); }
@Test(expected = CDKException.class) public void testSgroupInvalidConnectInStrictMode() throws Exception { try (MDLV2000Reader mdlr = new MDLV2000Reader(getClass().getResourceAsStream("/data/mdl/sgroup-sru-bad-scn.mol"))) { mdlr.setReaderMode(Mode.STRICT); IAtomContainer container = mdlr.read(new AtomContainer()); } }
/** * When atomic mass is defined as a delta some atoms don't have a reasonable * default. Most tools will output an 'M ISO' property, so can be specified * @throws Exception expected format error */ @Test(expected = CDKException.class) public void seaborgiumMassDelta() throws Exception { try (InputStream in = getClass().getResourceAsStream("seaborgium.mol"); MDLV2000Reader mdlr = new MDLV2000Reader(in, Mode.STRICT)) { IAtomContainer mol = mdlr.read(new AtomContainer()); } }
@Test public void e_butene_3D() throws Exception { InputStream in = getClass().getResourceAsStream("/data/mdl/e_butene_3d.mol"); MDLV2000Reader reader = new MDLV2000Reader(in); Properties prop = new Properties(); prop.setProperty("ForceReadAs3DCoordinates", "true"); PropertiesListener listener = new PropertiesListener(prop); reader.addChemObjectIOListener(listener); reader.customizeJob(); IAtomContainer molecule = DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainer.class); molecule = reader.read(molecule); reader.close(); assertNotNull(molecule); assertTrue(molecule.stereoElements().iterator().hasNext()); }
private static IAtomContainer createMolecule(String molecule) throws IOException, CDKException { IAtomContainer structure = null; if (molecule != null) { ISimpleChemObjectReader reader = new MDLV2000Reader(new StringReader(molecule)); Assert.assertNotNull("Could not create reader", reader); if (reader.accepts(AtomContainer.class)) { structure = reader.read(DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainer.class)); } } return structure; }
@Override public void close() { try { molReader.close(); } catch (IOException e) { e.printStackTrace(); } }
@SuppressWarnings("unchecked") @Override public boolean accepts(Class<? extends IChemObject> classObject) { Class<?>[] interfaces = classObject.getInterfaces(); for (Class<?> anInterface : interfaces) { if (IChemFile.class.equals(anInterface)) return true; if (IChemModel.class.equals(anInterface)) return true; if (IAtomContainer.class.equals(anInterface)) return true; } if (IAtomContainer.class.equals(classObject)) return true; if (IChemFile.class.equals(classObject)) return true; if (IChemModel.class.equals(classObject)) return true; Class superClass = classObject.getSuperclass(); return superClass != null && this.accepts(superClass); }
/** * The non-standard ACDLabs atom label property should throw a CDKException in STRICT mode. * @throws Exception */ @Test(expected=CDKException.class) public void testAcdChemSketchLabel_Strict() throws Exception { String filename = "data/mdl/chemsketch-all-labelled.mol"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MDLV2000Reader reader = new MDLV2000Reader(ins, Mode.STRICT); reader.read(new AtomContainer()); }
@Test public void e_butene_2D_optOff() throws Exception { InputStream in = getClass().getResourceAsStream("/data/mdl/e_butene_2d.mol"); MDLV2000Reader reader = new MDLV2000Reader(in); Properties prop = new Properties(); prop.setProperty("AddStereoElements", "false"); PropertiesListener listener = new PropertiesListener(prop); reader.addChemObjectIOListener(listener); reader.customizeJob(); IAtomContainer molecule = DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainer.class); molecule = reader.read(molecule); reader.close(); assertNotNull(molecule); assertFalse(molecule.stereoElements().iterator().hasNext()); }
@Test(expected = CDKException.class) public void testSgroupDefOrderInStrictMode() throws Exception { try (MDLV2000Reader mdlr = new MDLV2000Reader(getClass().getResourceAsStream("/data/mdl/sgroup-sru-bad-def.mol"))) { mdlr.setReaderMode(Mode.STRICT); IAtomContainer container = mdlr.read(new AtomContainer()); } }
@Test public void readMDLCoordinates_wrong_decimal_position_relaxed() throws Exception { MDLV2000Reader reader = new MDLV2000Reader(); reader.setReaderMode(IChemObjectReader.Mode.RELAXED); assertThat(reader.readMDLCoordinate(" -2.0012 7.8089 ", 10), is(closeTo(7.8089, 0.1))); }
private IAtomContainer loadMolecule(String path) throws Exception { InputStream ins = this.getClass().getClassLoader().getResourceAsStream(path); MDLV2000Reader reader = new MDLV2000Reader(ins, Mode.STRICT); ChemFile chemFile = (ChemFile) reader.read((ChemObject) new ChemFile()); reader.close(); List<IAtomContainer> containersList = ChemFileManipulator.getAllAtomContainers(chemFile); return (IAtomContainer) containersList.get(0); }
public void ignoreCalculate_IAtomContainer() throws Exception { String filename = "data/mdl/clorobenzene.mol"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MDLV2000Reader reader = new MDLV2000Reader(ins); IAtomContainer container = reader.read(new AtomContainer()); DescriptorValue count = descriptor.calculate(container); System.out.println(count.getValue()); Assert.fail("Not validated yet"); }
@Test public void readOldJmolCoords() throws Exception { MDLV2000Reader reader = new MDLV2000Reader(); reader.setReaderMode(IChemObjectReader.Mode.RELAXED); assertThat(reader.readMDLCoordinate(" -2.00120 7.8089", 0), is(closeTo(-2.00120, 0.1))); }
@Test public void testAccepts() { MDLV2000Reader reader = new MDLV2000Reader(); assertTrue(reader.accepts(ChemFile.class)); assertTrue(reader.accepts(ChemModel.class)); assertTrue(reader.accepts(AtomContainer.class)); }
@Test public void testEmptyString() throws Exception { String emptyString = ""; MDLV2000Reader reader = new MDLV2000Reader(new StringReader(emptyString)); IAtomContainer mol = reader.read(new AtomContainer()); reader.close(); Assert.assertNull(mol); }
@Test public void roundTripExpandedAbbrv() throws IOException, CDKException { try (MDLV2000Reader mdlr = new MDLV2000Reader(getClass().getResourceAsStream("/data/mdl/triphenyl-phosphate-expanded.mol"))) { IAtomContainer mol = mdlr.read(new AtomContainer(0, 0, 0, 0)); String res = writeToStr(mol); assertThat(res, CoreMatchers.containsString("M V30 1 SUP 0 ATOMS=(6 6 19 20 21 22 23) XBONDS=(1 5) ESTATE=E LABEL=Ph\n" + "M V30 2 SUP 0 ATOMS=(6 8 14 15 16 17 18) XBONDS=(1 7) ESTATE=E LABEL=Ph\n" + "M V30 3 SUP 0 ATOMS=(6 7 9 10 11 12 13) XBONDS=(1 6) ESTATE=E LABEL=Ph\n")); } }
@Test(expected = CDKException.class) public void readMDLCoordinates_wrong_decimal_position_strict() throws Exception { MDLV2000Reader reader = new MDLV2000Reader(); reader.setReaderMode(IChemObjectReader.Mode.STRICT); assertThat(reader.readMDLCoordinate(" -2.0012 7.8089 ", 10), is(closeTo(7.8089, 0.1))); }