private IChemFile parseCMLString(String cmlString) throws Exception { IChemFile chemFile = null; CMLReader reader = new CMLReader(new ByteArrayInputStream(cmlString.getBytes())); chemFile = (IChemFile) reader.read(new ChemFile()); reader.close(); return chemFile; }
private IChemFile parseCMLString(String cmlString) throws Exception { IChemFile chemFile = null; CMLReader reader = new CMLReader(new ByteArrayInputStream(cmlString.getBytes())); chemFile = (IChemFile) reader.read(new org.openscience.cdk.ChemFile()); reader.close(); return chemFile; }
private IChemFile parseCMLString(String cmlString) throws Exception { IChemFile chemFile = null; CMLReader reader = new CMLReader(new ByteArrayInputStream(cmlString.getBytes())); chemFile = (IChemFile) reader.read(new org.openscience.cdk.ChemFile()); reader.close(); return chemFile; }
@Test public void testOla28() throws Exception { String filename = "data/cml/mol28.cml"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); CMLReader reader = new CMLReader(ins); IChemFile file = reader.read(new ChemFile()); reader.close(); IAtomContainer mol = ChemFileManipulator.getAllAtomContainers(file).get(0); for (IAtom atom : mol.atoms()) { List<IAtom> neighbors = mol.getConnectedAtomsList(atom); if (neighbors.size() == 4) { Stereo stereo = StereoTool.getStereo(neighbors.get(0), neighbors.get(1), neighbors.get(2), neighbors.get(3)); ITetrahedralChirality stereoCenter = new TetrahedralChirality(mol.getAtom(0), neighbors.toArray(new IAtom[]{}), stereo); CIP_CHIRALITY chirality = CIPTool.getCIPChirality(mol, stereoCenter); } } }
/** * @cdk.bug 2114987 */ @Test public void testCMLTestCase() throws Exception { String filename = "data/cml/olaCmlAtomType.cml"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); CMLReader reader = new CMLReader(ins); IChemFile chemFile = new ChemFile(); chemFile = (IChemFile) reader.read(chemFile); reader.close(); IAtomContainer container = ChemFileManipulator.getAllAtomContainers(chemFile).get(0); for (IAtom atom : container.atoms()) { Assert.assertEquals(CDKConstants.UNSET, atom.getImplicitHydrogenCount()); } }
/** * @cdk.bug 1930029 */ @Test public void testAtomProperties() throws Exception { String filename = "data/cml/custompropertiestest.cml"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); CMLReader reader = new CMLReader(ins); ChemFile chemFile = (ChemFile) reader.read((ChemFile) new ChemFile()); reader.close(); Assert.assertNotNull(chemFile); IAtomContainer container = ChemFileManipulator.getAllAtomContainers(chemFile).get(0); for (int i = 0; i < container.getAtomCount(); i++) { Assert.assertEquals(2, container.getAtom(i).getProperties().size()); } }
/** */ @Test public void testReactionProperties() throws Exception { String filename = "data/cml/reaction.2.cml"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); CMLReader reader = new CMLReader(ins); IChemFile chemFile = new ChemFile(); chemFile = (IChemFile) reader.read(chemFile); reader.close(); IReaction reaction = chemFile.getChemSequence(0).getChemModel(0).getReactionSet().getReaction(0); Assert.assertEquals("3", (String) reaction.getProperty("Ka")); } }
@Test public void testMixedNamespaces() throws Exception { InputStream in = getClass().getResourceAsStream("US06358966-20020319-C00001-enr.cml"); CMLReader reader = new CMLReader(in); try { IChemFile cfile = reader.read(DefaultChemObjectBuilder.getInstance().newInstance(IChemFile.class)); Assert.assertEquals(34, ChemFileManipulator.getAtomCount(cfile)); Assert.assertEquals(39, ChemFileManipulator.getBondCount(cfile)); } finally { reader.close(); } } }
@Test public void testFile3() throws Exception { String filename = "data/cml/3.cml"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); CMLReader reader = new CMLReader(ins); IChemFile chemFile = (IChemFile) reader.read(new ChemFile()); reader.close(); // test the resulting ChemFile content Assert.assertNotNull(chemFile); IAtomContainer mol = ChemFileManipulator.getAllAtomContainers(chemFile).get(0); for (int i = 0; i <= 3; i++) { Assert.assertFalse("Bond " + (i + 1) + " is not aromatic in the file", mol.getBond(i).getFlag(CDKConstants.ISAROMATIC)); } for (int i = 4; i <= 9; i++) { Assert.assertTrue("Bond " + (i + 1) + " is aromatic in the file", mol.getBond(i).getFlag(CDKConstants.ISAROMATIC)); } }
/** * Ensure stereoBond content is read if the usual "dictRef" attribute is not * supplied * * @cdk.bug 1248 */ @Test public void testBug1248() throws IOException, CDKException { InputStream in = getClass().getResourceAsStream("/data/cml/(1R)-1-aminoethan-1-ol.cml"); CMLReader reader = new CMLReader(in); try { IChemFile cfile = reader.read(DefaultChemObjectBuilder.getInstance().newInstance(IChemFile.class)); Assert.assertNotNull("ChemFile was Null", cfile); List<IAtomContainer> containers = ChemFileManipulator.getAllAtomContainers(cfile); Assert.assertEquals("Expected a single atom container", 1, containers.size()); IAtomContainer container = containers.get(0); Assert.assertNotNull("Null atom container read", container); IBond bond = container.getBond(2); Assert.assertNotNull("Null bond", bond); Assert.assertEquals("Expected Wedge (Up) Bond", IBond.Stereo.UP, bond.getStereo()); } finally { reader.close(); } }
/** * @cdk.bug 2697568 */ @Test public void testReadReactionWithPointersToMoleculeSet() throws Exception { String filename = "data/cml/AlanineTree.cml"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); CMLReader reader = new CMLReader(ins); IChemFile chemFile = new ChemFile(); chemFile = (IChemFile) reader.read(chemFile); reader.close(); Assert.assertSame(chemFile.getChemSequence(0).getChemModel(0).getMoleculeSet().getAtomContainer(0), chemFile .getChemSequence(0).getChemModel(0).getReactionSet().getReaction(0).getReactants().getAtomContainer(0)); }
/** * @cdk.bug 2697568 */ @Test public void testBug2697568() throws Exception { String filename = "data/cml/AlanineTreeReverse.cml"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); CMLReader reader = new CMLReader(ins); IChemFile chemFile = new ChemFile(); chemFile = (IChemFile) reader.read(chemFile); reader.close(); Assert.assertSame(chemFile.getChemSequence(0).getChemModel(0).getMoleculeSet().getAtomContainer(0), chemFile .getChemSequence(0).getChemModel(0).getReactionSet().getReaction(0).getReactants().getAtomContainer(0)); }
public static IChemModel roundTripChemModel(Convertor convertor, IChemModel model) throws Exception { String cmlString = "<!-- failed -->"; Element cmlDOM = convertor.cdkChemModelToCMLList(model); cmlString = cmlDOM.toXML(); logger.debug("CML string: ", cmlString); CMLReader reader = new CMLReader(new ByteArrayInputStream(cmlString.getBytes())); reader.close(); IChemFile file = (IChemFile) reader.read(model.getBuilder().newInstance(IChemFile.class)); Assert.assertNotNull(file); Assert.assertEquals(1, file.getChemSequenceCount()); IChemSequence sequence = file.getChemSequence(0); Assert.assertNotNull(sequence); Assert.assertEquals(1, sequence.getChemModelCount()); IChemModel chemModel = sequence.getChemModel(0); Assert.assertNotNull(chemModel); return chemModel; }
/** * Ensures that {@code <bondStereo dictRef="cml:"/>} doesn't cause an exception * * @cdk.bug 1275 */ @Test public void testBug1275() throws CDKException, IOException { InputStream in = getClass().getResourceAsStream("/data/cml/(1R)-1-aminoethan-1-ol-malformedDictRef.cml"); CMLReader reader = new CMLReader(in); try { IChemFile cfile = reader.read(DefaultChemObjectBuilder.getInstance().newInstance(IChemFile.class)); Assert.assertNotNull("ChemFile was null", cfile); List<IAtomContainer> containers = ChemFileManipulator.getAllAtomContainers(cfile); Assert.assertEquals("expected a single atom container", 1, containers.size()); IAtomContainer container = containers.get(0); Assert.assertNotNull("null atom container read", container); // we check here that the malformed dictRef doesn't throw an exception Assert.assertEquals("expected non-stereo bond", IBond.Stereo.NONE, container.getBond(0).getStereo()); Assert.assertEquals("expected Wedge (Up) Bond", IBond.Stereo.UP, container.getBond(1).getStereo()); Assert.assertEquals("expected non-stereo bond", IBond.Stereo.NONE, container.getBond(2).getStereo()); } finally { reader.close(); } }
public static IReaction roundTripReaction(Convertor convertor, IReaction reaction) throws Exception { String cmlString = "<!-- failed -->"; Element cmlDOM = convertor.cdkReactionToCMLReaction(reaction); cmlString = cmlDOM.toXML(); IReaction roundTrippedReaction = null; logger.debug("CML string: ", cmlString); CMLReader reader = new CMLReader(new ByteArrayInputStream(cmlString.getBytes())); IChemFile file = (IChemFile) reader.read(new org.openscience.cdk.ChemFile()); reader.close(); Assert.assertNotNull(file); Assert.assertEquals(1, file.getChemSequenceCount()); IChemSequence sequence = file.getChemSequence(0); Assert.assertNotNull(sequence); Assert.assertEquals(1, sequence.getChemModelCount()); IChemModel chemModel = sequence.getChemModel(0); Assert.assertNotNull(chemModel); IReactionSet reactionSet = chemModel.getReactionSet(); Assert.assertNotNull(reactionSet); Assert.assertEquals(1, reactionSet.getReactionCount()); roundTrippedReaction = reactionSet.getReaction(0); Assert.assertNotNull(roundTrippedReaction); return roundTrippedReaction; }
@Test public void testCMLOK1() throws Exception { String filename = "data/cml/cs2a.cml"; logger.info("Testing: " + filename); InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); CMLReader reader = new CMLReader(ins); IChemFile chemFile = (IChemFile) reader.read(new org.openscience.cdk.ChemFile()); reader.close(); // test the resulting ChemFile content Assert.assertNotNull(chemFile); Assert.assertEquals(chemFile.getChemSequenceCount(), 1); org.openscience.cdk.interfaces.IChemSequence seq = chemFile.getChemSequence(0); Assert.assertNotNull(seq); Assert.assertEquals(seq.getChemModelCount(), 1); org.openscience.cdk.interfaces.IChemModel model = seq.getChemModel(0); Assert.assertNotNull(model); Assert.assertEquals(model.getMoleculeSet().getAtomContainerCount(), 1); // test the molecule IAtomContainer mol = model.getMoleculeSet().getAtomContainer(0); Assert.assertNotNull(mol); Assert.assertEquals(38, mol.getAtomCount()); Assert.assertEquals(48, mol.getBondCount()); Assert.assertTrue(GeometryUtil.has3DCoordinates(mol)); Assert.assertFalse(GeometryUtil.has2DCoordinates(mol)); }
@Test public void testCMLOK2() throws Exception { String filename = "data/cml/cs2a.mol.cml"; logger.info("Testing: " + filename); InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); CMLReader reader = new CMLReader(ins); IChemFile chemFile = (IChemFile) reader.read(new org.openscience.cdk.ChemFile()); reader.close(); // test the resulting ChemFile content Assert.assertNotNull(chemFile); Assert.assertEquals(chemFile.getChemSequenceCount(), 1); org.openscience.cdk.interfaces.IChemSequence seq = chemFile.getChemSequence(0); Assert.assertNotNull(seq); Assert.assertEquals(seq.getChemModelCount(), 1); org.openscience.cdk.interfaces.IChemModel model = seq.getChemModel(0); Assert.assertNotNull(model); Assert.assertEquals(model.getMoleculeSet().getAtomContainerCount(), 1); // test the molecule IAtomContainer mol = model.getMoleculeSet().getAtomContainer(0); Assert.assertNotNull(mol); Assert.assertEquals(38, mol.getAtomCount()); Assert.assertEquals(29, mol.getBondCount()); Assert.assertTrue(GeometryUtil.has3DCoordinates(mol)); Assert.assertFalse(GeometryUtil.has2DCoordinates(mol)); }
@Test public void testCMLOK6() throws Exception { String filename = "data/cml/nsc2dmol.a2.cml"; logger.info("Testing: " + filename); InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); CMLReader reader = new CMLReader(ins); IChemFile chemFile = (IChemFile) reader.read(new org.openscience.cdk.ChemFile()); reader.close(); // test the resulting ChemFile content Assert.assertNotNull(chemFile); Assert.assertEquals(chemFile.getChemSequenceCount(), 1); org.openscience.cdk.interfaces.IChemSequence seq = chemFile.getChemSequence(0); Assert.assertNotNull(seq); Assert.assertEquals(seq.getChemModelCount(), 1); org.openscience.cdk.interfaces.IChemModel model = seq.getChemModel(0); Assert.assertNotNull(model); Assert.assertEquals(model.getMoleculeSet().getAtomContainerCount(), 1); // test the molecule IAtomContainer mol = model.getMoleculeSet().getAtomContainer(0); Assert.assertNotNull(mol); Assert.assertEquals(13, mol.getAtomCount()); Assert.assertEquals(12, mol.getBondCount()); Assert.assertFalse(GeometryUtil.has3DCoordinates(mol)); Assert.assertTrue(GeometryUtil.has2DCoordinates(mol)); }
@Test public void testCMLOK9() throws Exception { String filename = "data/cml/nsc3dmol.1.cml"; logger.info("Testing: " + filename); InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); CMLReader reader = new CMLReader(ins); IChemFile chemFile = (IChemFile) reader.read(new org.openscience.cdk.ChemFile()); reader.close(); // test the resulting ChemFile content Assert.assertNotNull(chemFile); Assert.assertEquals(chemFile.getChemSequenceCount(), 1); org.openscience.cdk.interfaces.IChemSequence seq = chemFile.getChemSequence(0); Assert.assertNotNull(seq); Assert.assertEquals(seq.getChemModelCount(), 1); org.openscience.cdk.interfaces.IChemModel model = seq.getChemModel(0); Assert.assertNotNull(model); Assert.assertEquals(model.getMoleculeSet().getAtomContainerCount(), 1); // test the molecule IAtomContainer mol = model.getMoleculeSet().getAtomContainer(0); Assert.assertNotNull(mol); Assert.assertEquals(15, mol.getAtomCount()); Assert.assertEquals(15, mol.getBondCount()); Assert.assertTrue(GeometryUtil.has3DCoordinates(mol)); Assert.assertFalse(GeometryUtil.has2DCoordinates(mol)); }
@Test public void testCMLOK10() throws Exception { String filename = "data/cml/nsc3dmol.2.cml"; logger.info("Testing: " + filename); InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); CMLReader reader = new CMLReader(ins); IChemFile chemFile = (IChemFile) reader.read(new org.openscience.cdk.ChemFile()); reader.close(); // test the resulting ChemFile content Assert.assertNotNull(chemFile); Assert.assertEquals(chemFile.getChemSequenceCount(), 1); org.openscience.cdk.interfaces.IChemSequence seq = chemFile.getChemSequence(0); Assert.assertNotNull(seq); Assert.assertEquals(seq.getChemModelCount(), 1); org.openscience.cdk.interfaces.IChemModel model = seq.getChemModel(0); Assert.assertNotNull(model); Assert.assertEquals(model.getMoleculeSet().getAtomContainerCount(), 1); // test the molecule IAtomContainer mol = model.getMoleculeSet().getAtomContainer(0); Assert.assertNotNull(mol); Assert.assertEquals(15, mol.getAtomCount()); Assert.assertEquals(15, mol.getBondCount()); Assert.assertTrue(GeometryUtil.has3DCoordinates(mol)); Assert.assertFalse(GeometryUtil.has2DCoordinates(mol)); }