use of org.openscience.cdk.io.CMLWriter in project ambit-mirror by ideaconsult.
the class TestCML method writeCML.
protected String writeCML(IAtomContainer mol) throws Exception {
StringWriter output = new StringWriter();
CMLWriter cmlwriter = new CMLWriter(output);
cmlwriter.write(mol);
cmlwriter.close();
return output.toString();
}
use of org.openscience.cdk.io.CMLWriter in project ambit-mirror by ideaconsult.
the class TestCML method testCML1.
public static void testCML1(String smiles) throws Exception {
IAtomContainer mol = SmartsHelper.getMoleculeFromSmiles(smiles);
mol.getAtom(0).setProperty("Prop1", "Test1");
mol.getAtom(0).setProperty("Prop2", "Test2");
printAtomProperties(mol.getAtom(0));
try {
System.out.println("Writing " + smiles + " to CML ");
StringWriter output = new StringWriter();
CMLWriter cmlwriter = new CMLWriter(output);
cmlwriter.write(mol);
cmlwriter.close();
String cmlcode = output.toString();
System.out.println(cmlcode);
IChemFile chemFile = parseCMLString(cmlcode);
IAtomContainer mol2 = chemFile.getChemSequence(0).getChemModel(0).getMoleculeSet().getAtomContainer(0);
printAtomProperties(mol2.getAtom(0));
} catch (Exception e) {
System.out.println(e.toString());
}
}
use of org.openscience.cdk.io.CMLWriter in project ambit-mirror by ideaconsult.
the class TestCML method testCML2.
public static void testCML2(String smiles) throws Exception {
IAtomContainer mol = SmartsHelper.getMoleculeFromSmiles(smiles);
printAromaticity(mol);
try {
System.out.println("Writing " + smiles + " to CML ");
StringWriter output = new StringWriter();
CMLWriter cmlwriter = new CMLWriter(output);
cmlwriter.write(mol);
cmlwriter.close();
String cmlcode = output.toString();
System.out.println(cmlcode);
IChemFile chemFile = parseCMLString(cmlcode);
IAtomContainer mol2 = chemFile.getChemSequence(0).getChemModel(0).getMoleculeSet().getAtomContainer(0);
printAromaticity(mol2);
} catch (Exception e) {
System.out.println(e.toString());
}
}
use of org.openscience.cdk.io.CMLWriter in project cdk by cdk.
the class SmilesGeneratorTest method testSFBug1014344.
/**
* @cdk.bug 1014344
*/
@Category(SlowTest.class)
// MDL -> CML (slow) -> SMILES round tripping
@Test
public void testSFBug1014344() throws Exception {
String filename = "bug1014344-1.mol";
InputStream ins = this.getClass().getResourceAsStream(filename);
MDLReader reader = new MDLReader(ins, Mode.STRICT);
IAtomContainer mol1 = reader.read(new AtomContainer());
addImplicitHydrogens(mol1);
SmilesGenerator sg = new SmilesGenerator();
String molSmiles = sg.create(mol1);
StringWriter output = new StringWriter();
CMLWriter cmlWriter = new CMLWriter(output);
cmlWriter.write(mol1);
CMLReader cmlreader = new CMLReader(new ByteArrayInputStream(output.toString().getBytes()));
IAtomContainer mol2 = ((IChemFile) cmlreader.read(new ChemFile())).getChemSequence(0).getChemModel(0).getMoleculeSet().getAtomContainer(0);
addImplicitHydrogens(mol2);
String cmlSmiles = sg.create(new AtomContainer(mol2));
Assert.assertEquals(molSmiles, cmlSmiles);
}
use of org.openscience.cdk.io.CMLWriter in project cdk by cdk.
the class CML2WriterTest method testHydrogenCount.
/**
* Test example with one explicit carbon, and four implicit hydrogens.
*
* @cdk.bug 1655045
*/
@Test
public void testHydrogenCount() throws Exception {
StringWriter writer = new StringWriter();
// methane
IAtomContainer molecule = new AtomContainer();
molecule.addAtom(molecule.getBuilder().newInstance(IAtom.class, Elements.CARBON));
molecule.getAtom(0).setImplicitHydrogenCount(4);
CMLWriter cmlWriter = new CMLWriter(writer);
cmlWriter.write(molecule);
cmlWriter.close();
logger.debug("****************************** testHydrogenCount()");
logger.debug(writer.toString());
logger.debug("******************************");
Assert.assertTrue(writer.toString().contains("hydrogenCount=\"4\""));
}
Aggregations