use of org.openscience.cdk.interfaces.IChemFile in project ambit-mirror by ideaconsult.
the class MoleculeTools method readCMLMolecule.
public static IAtomContainer readCMLMolecule(InputStream in) throws Exception {
IAtomContainer mol = null;
CMLReader reader = new CMLReader(in);
IChemFile obj = null;
obj = (IChemFile) reader.read(newChemFile(SilentChemObjectBuilder.getInstance()));
int n = obj.getChemSequenceCount();
if (n > 1)
logger.finest("> 1 sequence in a record");
for (int j = 0; j < n; j++) {
IChemSequence seq = obj.getChemSequence(j);
int m = seq.getChemModelCount();
if (m > 1)
logger.finest("> 1 model in a record");
for (int k = 0; k < m; k++) {
IChemModel mod = seq.getChemModel(k);
IAtomContainerSet som = mod.getMoleculeSet();
if (som.getAtomContainerCount() > 1)
logger.finest("> 1 molecule in a record");
for (int l = 0; l < som.getAtomContainerCount(); l++) {
mol = som.getAtomContainer(l);
return mol;
}
}
}
reader = null;
return mol;
}
use of org.openscience.cdk.interfaces.IChemFile in project ambit-mirror by ideaconsult.
the class TestCML method parseCMLString.
public static 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;
}
use of org.openscience.cdk.interfaces.IChemFile in project ambit-mirror by ideaconsult.
the class TestCML method testCML_singlePropertyForAllAtoms.
@Test
public void testCML_singlePropertyForAllAtoms() throws Exception {
String smiles = "CCCC";
IAtomContainer mol = parser.parseSmiles(smiles);
for (int i = 0; i < mol.getAtomCount(); i++) {
String id = Integer.toString(i + 1);
mol.getAtom(i).setProperty("Prop" + id, id);
mol.getAtom(i).setID(id);
}
printAtomProperties(mol);
for (int i = 0; i < mol.getAtomCount(); i++) {
String id = Integer.toString(i + 1);
Assert.assertEquals(id, mol.getAtom(i).getProperty("Prop" + id));
Assert.assertEquals(1, mol.getAtom(i).getProperties().size());
}
String cmlcode = writeCML(mol);
logger.info(cmlcode);
IChemFile chemFile = parseCMLString(cmlcode);
IAtomContainer mol2 = chemFile.getChemSequence(0).getChemModel(0).getMoleculeSet().getAtomContainer(0);
printAtomProperties(mol2);
for (int i = 0; i < mol2.getAtomCount(); i++) {
String id = mol2.getAtom(i).getID();
Assert.assertEquals(id, mol2.getAtom(i).getProperty("Prop" + id));
Assert.assertEquals(1, mol2.getAtom(i).getProperties().size());
}
logger.info(writeCML(mol2));
}
use of org.openscience.cdk.interfaces.IChemFile 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.interfaces.IChemFile 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());
}
}
Aggregations