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); }
/** * 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 sgroupExpandedAbbreviationRoundTrip() throws Exception { StringWriter sw = new StringWriter(); try (MDLV2000Reader mdlr = new MDLV2000Reader(getClass().getResourceAsStream("/data/mdl/triphenyl-phosphate-expanded.mol")); MDLV2000Writer mdlw = new MDLV2000Writer(sw)) { mdlw.write(mdlr.read(new AtomContainer())); String output = sw.toString(); assertThat(output, containsString("M STY 3 1 SUP 2 SUP 3 SUP\n")); assertThat(output, containsString("M SDS EXP 1 1")); } }
/** * @cdk.bug 2936440 */ @Test public void testHas2DCoordinates_With000() throws CDKException { String filenameMol = "data/mdl/with000coordinate.mol"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filenameMol); IAtomContainer molOne = null; MDLV2000Reader reader = new MDLV2000Reader(ins, Mode.STRICT); molOne = (IAtomContainer) reader.read(new AtomContainer()); Assert.assertTrue(GeometryUtil.has2DCoordinates(molOne)); }
@Test public void testGetAllAtomContainers_IChemModel() throws Exception { String filename = "data/mdl/a-pinene.mol"; logger.info("Testing: " + filename); InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MDLV2000Reader reader = new MDLV2000Reader(ins); ChemModel chemFile = (ChemModel) reader.read((ChemObject) new ChemModel()); Assert.assertNotNull(chemFile); List<IAtomContainer> containersList = ChemModelManipulator.getAllAtomContainers(chemFile); Assert.assertEquals(1, containersList.size()); }
@Test public void e_butene_0D() throws Exception { InputStream in = getClass().getResourceAsStream("/data/mdl/e_butene_0d.mol"); MDLV2000Reader reader = new MDLV2000Reader(in); IAtomContainer molecule = DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainer.class); molecule = reader.read(molecule); reader.close(); assertNotNull(molecule); assertFalse(molecule.stereoElements().iterator().hasNext()); }
@Test public void testUndefinedStereo2() throws Exception { String filename = "data/mdl/a-pinene-with-undefined-stereo.mol"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MDLV2000Reader reader = new MDLV2000Reader(ins, Mode.STRICT); IAtomContainer mol = reader.read(new AtomContainer()); reader.close(); Assert.assertEquals(IBond.Stereo.UP_OR_DOWN, mol.getBond(1).getStereo()); }
@Test public void radicalsReflectedInHydrogenCount() throws Exception { MDLV2000Reader r = new MDLV2000Reader(getClass().getResourceAsStream("structure-with-radical.mol")); IAtomContainer m = r.read(new AtomContainer()); r.close(); assertThat(m.getAtom(0).getAtomicNumber(), is(8)); assertThat(m.getAtom(0).getImplicitHydrogenCount(), is(0)); }
/** * @cdk.bug 1343 */ @Test public void nonNegativeHydrogenCountOnHydrogenRadical() throws Exception { InputStream in = getClass().getResourceAsStream("/data/mdl/ChEBI_29293.mol"); MDLV2000Reader reader = new MDLV2000Reader(in); IAtomContainer container = reader.read(new AtomContainer()); reader.close(); assertThat(container.getAtom(0).getImplicitHydrogenCount(), is(0)); assertThat(container.getAtom(1).getImplicitHydrogenCount(), is(0)); }
@Test public void testAliasPropertyGroup() throws Exception { String filename = "data/mdl/AliasPropertyRGroup.sdf"; logger.info("Testing: " + filename); InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MDLV2000Reader reader = new MDLV2000Reader(ins); IAtomContainer mol = reader.read(new AtomContainer()); reader.close(); IAtom atom = mol.getAtom(0); assertTrue(atom instanceof IPseudoAtom); Assert.assertEquals("R\\1", ((IPseudoAtom) atom).getLabel()); }
@Test public void testSingleDoubletRadical() throws Exception { InputStream in = ClassLoader.getSystemResourceAsStream("data/mdl/singleDoubletRadical.mol"); MDLV2000Reader reader = new MDLV2000Reader(in); IAtomContainer molecule = DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainer.class); molecule = reader.read(molecule); reader.close(); assertThat(molecule.getConnectedSingleElectronsCount(molecule.getAtom(1)), is(1)); }
@Test public void testSingleTripletRadical() throws Exception { InputStream in = ClassLoader.getSystemResourceAsStream("data/mdl/singleTripletRadical.mol"); MDLV2000Reader reader = new MDLV2000Reader(in); IAtomContainer molecule = DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainer.class); molecule = reader.read(molecule); reader.close(); assertThat(molecule.getConnectedSingleElectronsCount(molecule.getAtom(1)), is(2)); }
@Test public void testTritiumProperties() throws Exception { String filename = "data/mdl/chemblMolregno7039.mol"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MDLV2000Reader reader = new MDLV2000Reader(ins); IAtomContainer molecule = new AtomContainer(); molecule = reader.read(molecule); reader.close(); IAtom tritium = molecule.getAtom(molecule.getAtomCount() - 1); assertTrue(1 == tritium.getAtomicNumber()); assertTrue(3 == tritium.getMassNumber()); }
@Test public void testMakeUpDownBonds_IAtomContainer() throws Exception { String filename = "data/mdl/tetrahedral_2_lazy.mol"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MDLV2000Reader reader = new MDLV2000Reader(ins); ChemFile chemFile = (ChemFile) reader.read((ChemObject) new ChemFile()); IAtomContainer mol = chemFile.getChemSequence(0).getChemModel(0).getMoleculeSet().getAtomContainer(0); BondTools.makeUpDownBonds(mol); Assert.assertEquals(IBond.Stereo.DOWN, mol.getBond(3).getStereo()); }
@Test public void testGiveAngle_IAtom_IAtom_IAtom() throws Exception { String filename = "data/mdl/testdoublebondconfig.mol"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MDLV2000Reader reader = new MDLV2000Reader(ins); ChemFile chemFile = (ChemFile) reader.read((ChemObject) new ChemFile()); IAtomContainer mol = chemFile.getChemSequence(0).getChemModel(0).getMoleculeSet().getAtomContainer(0); Assert.assertEquals(2.0943946986086157, BondTools.giveAngle(mol.getAtom(0), mol.getAtom(2), mol.getAtom(3)), 0.2); }
@Test public void testGiveAngleFromMiddle_IAtom_IAtom_IAtom() throws Exception { String filename = "data/mdl/testdoublebondconfig.mol"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MDLV2000Reader reader = new MDLV2000Reader(ins); ChemFile chemFile = (ChemFile) reader.read((ChemObject) new ChemFile()); IAtomContainer mol = chemFile.getChemSequence(0).getChemModel(0).getMoleculeSet().getAtomContainer(0); Assert.assertEquals(2.0943946986086157, BondTools.giveAngleFromMiddle(mol.getAtom(0), mol.getAtom(2), mol.getAtom(3)), 0.2); }
/** * Test that R-groups at higher atom numbers (>9) are read correctly */ @Test public void testRGroupHighAtomNumber() throws Exception { InputStream in = ClassLoader.getSystemResourceAsStream("data/mdl/brenda_molfile_rgroup.mol"); MDLV2000Reader reader = new MDLV2000Reader(in); IAtomContainer molecule = DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainer.class); reader.read(molecule); reader.close(); Assert.assertEquals("R", molecule.getAtom(55).getSymbol()); }
@Test public void testIsSquarePlanar_IAtomContainer_IAtom() throws Exception { String filename = "data/mdl/squareplanar.mol"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MDLV2000Reader reader = new MDLV2000Reader(ins); ChemFile chemFile = (ChemFile) reader.read((ChemObject) new ChemFile()); IAtomContainer mol = chemFile.getChemSequence(0).getChemModel(0).getMoleculeSet().getAtomContainer(0); Assert.assertTrue(BondTools.isSquarePlanar(mol, mol.getAtom(0))); Assert.assertFalse(BondTools.isSquarePlanar(mol, mol.getAtom(1))); }
@Test public void testPseudoAtomLabels() throws Exception { InputStream in = ClassLoader.getSystemResourceAsStream("data/mdl/pseudoatoms.sdf"); MDLV2000Reader reader = new MDLV2000Reader(in); IAtomContainer molecule = DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainer.class); molecule = reader.read(molecule); reader.close(); assertTrue(molecule.getAtom(4) instanceof IPseudoAtom); Assert.assertEquals("R", molecule.getAtom(4).getSymbol()); IPseudoAtom pa = (IPseudoAtom) molecule.getAtom(4); Assert.assertEquals("Gln", pa.getLabel()); }
@Test public void testGiveAngleBothMethods_Point2d_Point2d_Point2d_boolean() throws Exception { String filename = "data/mdl/testdoublebondconfig.mol"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MDLV2000Reader reader = new MDLV2000Reader(ins); ChemFile chemFile = (ChemFile) reader.read((ChemObject) new ChemFile()); IAtomContainer mol = chemFile.getChemSequence(0).getChemModel(0).getMoleculeSet().getAtomContainer(0); Assert.assertEquals(2.0943946986086157, BondTools.giveAngleBothMethods(mol.getAtom(0).getPoint2d(), mol .getAtom(2).getPoint2d(), mol.getAtom(3).getPoint2d(), true), 0.2); Assert.assertEquals(2.0943946986086157, BondTools.giveAngleBothMethods(mol.getAtom(0).getPoint2d(), mol .getAtom(2).getPoint2d(), mol.getAtom(3).getPoint2d(), false), 0.2); }