protected IReaction parseCML(String input) throws FileNotFoundException, CDKException { File f = new File(input); if (!f.isFile()) { LOGGER.warn(WARNING, format("CML file not found! " + f.getName())); exit(1); } String[] split = f.getName().split(".cml"); CMLReader cmlReader = new CMLReader(new FileInputStream(input)); AtomContainer ac = cmlReader.read(new AtomContainer()); IReaction r = new Reaction(); r.addReactant(ac, 1.0); r.addProduct(ac, 1.0); r.setID(split[0]); return r; }
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()); 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 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 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()); // test the resulting ChemFile content Assert.assertNotNull(chemFile); IAtomContainer mol = ChemFileManipulator.getAllAtomContainers(chemFile).get(0); String[] expectedTypes = {"C.sp2", "N.sp2", "C.sp2", "N.sp3", "C.sp2", "N.sp2", "O.sp3", "C.sp2", "C.sp2", "C.sp2"}; assertAtomTypes(testedAtomTypes, expectedTypes, mol); }
@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 chemFile = (IChemFile) reader.read(new ChemFile()); // test the resulting ChemFile content Assert.assertNotNull(chemFile); IAtomContainer mol = ChemFileManipulator.getAllAtomContainers(chemFile).get(0); String[] expectedTypes = {"C.sp2", "C.sp2", "C.sp2", "C.sp2", "F", "C.sp2", "C.sp2", "C.sp2", "O.sp2", "C.sp3", "C.sp3", "C.sp3", "N.plus", "C.sp3", "C.sp3", "C.sp3", "C.sp3", "C.sp3", "C.sp2", "O.sp3", "C.sp2", "C.sp2", "C.sp2", "C.sp2", "C.sp2", "Cl"}; assertAtomTypes(testedAtomTypes, expectedTypes, mol); }
public void visualBugPMR() throws Exception { String filename = "data/cml/SL0016a.cml"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); CMLReader reader = new CMLReader(ins); ChemFile chemFile = (ChemFile) reader.read((ChemObject) new ChemFile()); IChemSequence seq = chemFile.getChemSequence(0); IChemModel model = seq.getChemModel(0); IAtomContainer mol = model.getMoleculeSet().getAtomContainer(0); //MoleculeViewer2D.display(mol, true, false, JFrame.DO_NOTHING_ON_CLOSE,""); }
@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); } } }
/** * A unit test for JUnit * *@exception Exception Description of the Exception */ @Test public void testResolveOverlap2() throws Exception { logger.debug("Test case with neither bond nor atom overlap"); String filename = "data/cml/overlaptest2.cml"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); CMLReader reader = new CMLReader(ins); IChemFile chemFile = (IChemFile) reader.read(new ChemFile()); IAtomContainer atomContainer = (IAtomContainer) ChemFileManipulator.getAllAtomContainers(chemFile).get(0); //MoleculeViewer2D.display(new AtomContainer(atomContainer), false); double score = new OverlapResolver().getOverlapScore(atomContainer, new Vector(), new Vector()); Assert.assertEquals(0.0, score, 0.0001); logger.debug("End of test case with neither bond nor atom overlap"); }
/** * @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()); } }
/** * A unit test for JUnit * *@exception Exception Description of the Exception */ @Test public void testResolveOverlap3() throws Exception { logger.debug("Test case with bond overlap"); String filename = "data/cml/overlaptest3.cml"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); CMLReader reader = new CMLReader(ins); IChemFile chemFile = (IChemFile) reader.read(new ChemFile()); IAtomContainer atomContainer = (IAtomContainer) ChemFileManipulator.getAllAtomContainers(chemFile).get(0); //MoleculeViewer2D.display(new AtomContainer(atomContainer), false); double score = new OverlapResolver().getBondOverlapScore(atomContainer, new Vector()); Assert.assertTrue(score > 0); logger.debug("End of test case with bond overlap"); }
/** * @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()); } }
/** * A unit test for JUnit * *@exception Exception Description of the Exception */ @Test public void testResolveOverlap4() throws Exception { double overlapScore = 0; logger.debug("Test case with atom clash"); String filename = "data/cml/overlaptest.cml"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); CMLReader reader = new CMLReader(ins); IChemFile chemFile = (IChemFile) reader.read(new ChemFile()); IAtomContainer atomContainer = (IAtomContainer) ChemFileManipulator.getAllAtomContainers(chemFile).get(0); //MoleculeViewer2D.display(new AtomContainer(atomContainer), false); OverlapResolver or = new OverlapResolver(); overlapScore = or.resolveOverlap(atomContainer, null); //MoleculeViewer2D.display(new AtomContainer(atomContainer), false); Assert.assertEquals(0.0, overlapScore, 0.0001); logger.debug("End of test case with atom clash"); }
/** */ @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)); } }
/** * @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; }