/** @cdk.bug 1535055 */ @Test public void testBug1535055() throws Exception { SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance()); IAtomContainer mol = sp.parseSmiles("COC(=O)c1ccc2c(c1)c1ccccc1[nH]2"); CDKHueckelAromaticityDetector.detectAromaticity(mol); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol); SmilesGenerator sg = new SmilesGenerator(); sg.setUseAromaticityFlag(true); String s1 = sg.createSMILES(mol); String filename = "data/cml/bug1535055.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 mol2 = ChemFileManipulator.getAllAtomContainers(chemFile).get(0); CDKHueckelAromaticityDetector.detectAromaticity(mol2); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol2); String s2 = sg.createSMILES(mol2); Assert.assertTrue(s1.contains("[nH]")); Assert.assertTrue(s2.contains("[nH]")); }
/** * Sets the given cml. Does not update other fields like for example smiles * * @param cml */ public void setCML(String cml) { InputStream inputStream = new ByteArrayInputStream(cml.getBytes()); CMLReader cmlReader = new CMLReader(inputStream); try { IChemFile readFile = (IChemFile) cmlReader.read(new ChemFile()); setAtomContainer((AtomContainer) ChemFileManipulator.getAllAtomContainers(readFile).get(0)); } catch (CDKException e) { throw new RuntimeException("failed to read atomContainer", e); } }
public IAtomContainer getAtomContainer() { if (atomContainer == null) { InputStream in = FileStoreKeeper.FILE_STORE.retrieve(fileStoreKey); CMLReader cmlReader = new CMLReader(in); try { IChemFile readFile = (IChemFile) cmlReader.read(new ChemFile()); setAtomContainer((AtomContainer) ChemFileManipulator.getAllAtomContainers(readFile).get(0)); } catch (CDKException e) { throw new RuntimeException("failed to read atomContainer", e); } } return atomContainer; }
/** * 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"); }
/** * 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 testMDMoleculeCustomizationRoundtripping() throws Exception { StringWriter writer = new StringWriter(); CMLWriter cmlWriter = new CMLWriter(writer); cmlWriter.registerCustomizer(new MDMoleculeCustomizer()); MDMolecule molecule = makeMDBenzene(); cmlWriter.write(molecule); String serializedMol = writer.toString(); logger.debug("****************************** testMDMoleculeCustomizationRoundtripping()"); logger.debug(serializedMol); logger.debug("******************************"); logger.debug("****************************** testMDMoleculeCustomization Write first"); logger.debug(serializedMol); logger.debug("******************************"); CMLReader reader = new CMLReader(new ByteArrayInputStream(serializedMol.getBytes())); reader.registerConvention("md:mdMolecule", new MDMoleculeConvention(new ChemFile())); IChemFile file = (IChemFile) reader.read(new ChemFile()); List containers = ChemFileManipulator.getAllAtomContainers(file); Assert.assertEquals(1, containers.size()); Object molecule2 = containers.get(0); Assert.assertTrue(molecule2 instanceof MDMolecule); MDMolecule mdMol = (MDMolecule) molecule2; Assert.assertEquals(6, mdMol.getAtomCount()); Assert.assertEquals(6, mdMol.getBondCount()); List residues = mdMol.getResidues(); Assert.assertEquals(2, residues.size()); Assert.assertEquals(3, ((Residue) residues.get(0)).getAtomCount()); Assert.assertEquals(3, ((Residue) residues.get(1)).getAtomCount()); Assert.assertEquals("myResidue1", ((Residue) residues.get(0)).getName()); Assert.assertEquals("myResidue2", ((Residue) residues.get(1)).getName()); Assert.assertEquals(0, ((Residue) residues.get(0)).getNumber()); Assert.assertEquals(1, ((Residue) residues.get(1)).getNumber()); List chargeGroup = mdMol.getChargeGroups(); Assert.assertEquals(2, chargeGroup.size()); Assert.assertEquals(2, ((ChargeGroup) chargeGroup.get(0)).getAtomCount()); Assert.assertEquals(4, ((ChargeGroup) chargeGroup.get(1)).getAtomCount()); Assert.assertNotNull(((ChargeGroup) chargeGroup.get(0)).getSwitchingAtom()); Assert.assertEquals("a2", ((ChargeGroup) chargeGroup.get(0)).getSwitchingAtom().getID()); Assert.assertNotNull(((ChargeGroup) chargeGroup.get(1)).getSwitchingAtom()); Assert.assertEquals("a5", ((ChargeGroup) chargeGroup.get(1)).getSwitchingAtom().getID()); Assert.assertEquals(2, ((ChargeGroup) chargeGroup.get(0)).getNumber()); Assert.assertEquals(3, ((ChargeGroup) chargeGroup.get(1)).getNumber()); writer = new StringWriter(); cmlWriter = new CMLWriter(writer); cmlWriter.registerCustomizer(new MDMoleculeCustomizer()); cmlWriter.write(mdMol); String serializedMDMol = writer.toString(); logger.debug("****************************** testMDMoleculeCustomizationRoundtripping()"); logger.debug(serializedMol); logger.debug("******************************"); logger.debug("****************************** testMDMoleculeCustomization Write second"); logger.debug(serializedMDMol); logger.debug("******************************"); Assert.assertEquals(serializedMol, serializedMDMol); }
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; }