use of org.openscience.cdk.io.ISimpleChemObjectReader in project ambit-mirror by ideaconsult.
the class CdkJmolAdapter method openBufferedReader.
/* **************************************************************
* the file related methods
* **************************************************************/
public Object openBufferedReader(String name, BufferedReader bufferedReader) {
IChemFile chemFile = null;
try {
ISimpleChemObjectReader chemObjectReader = null;
try {
chemObjectReader = new ReaderFactory().createReader(bufferedReader);
} catch (IOException ex) {
return "Jmol: Error determining input format: " + ex;
}
if (chemObjectReader == null) {
return "Jmol: unrecognized input format";
}
chemFile = (IChemFile) chemObjectReader.read(new org.openscience.cdk.ChemFile());
} catch (CDKException ex) {
return "Error reading input:" + ex;
}
if (chemFile == null)
return "unknown error reading file";
try {
AtomTypeFactory factory = AtomTypeFactory.getInstance("pdb_atomtypes.txt", chemFile.getBuilder());
// IAtomContainer atomContainer = (IAtomContainer)ChemFileManipulator.getAllInOneContainer(chemFile);
Iterator<IChemSequence> seq = chemFile.chemSequences().iterator();
while (seq.hasNext()) {
Iterator<IChemModel> model = seq.next().chemModels().iterator();
while (model.hasNext()) {
Iterator<IAtomContainer> c = model.next().getMoleculeSet().atomContainers().iterator();
while (c.hasNext()) {
Iterator<IAtom> it = c.next().atoms().iterator();
while (it.hasNext()) {
IAtom atom = it.next();
try {
factory.configure(atom);
} catch (CDKException exception) {
bcLogger.severe("Could not configure atom: " + atom);
bcLogger.log(Level.SEVERE, " because: " + exception.getMessage(), exception);
}
}
}
}
}
return chemFile;
} catch (Exception x) {
return "Error configuring atoms input:" + x;
}
}
use of org.openscience.cdk.io.ISimpleChemObjectReader in project cdk by cdk.
the class GraphOnlyFingerprinterTest method createMolecule.
private static IAtomContainer createMolecule(String molecule) throws IOException, CDKException {
IAtomContainer structure = null;
if (molecule != null) {
ISimpleChemObjectReader reader = new MDLV2000Reader(new StringReader(molecule));
Assert.assertNotNull("Could not create reader", reader);
if (reader.accepts(AtomContainer.class)) {
structure = reader.read(DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainer.class));
}
}
return structure;
}
use of org.openscience.cdk.io.ISimpleChemObjectReader in project cdk by cdk.
the class ZagrebIndexDescriptorTest method test2Dvs3D.
@Test
public void test2Dvs3D() throws Exception {
SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance());
IAtomContainer mol = sp.parseSmiles("O1C2C34C(C(C1O)CCCc1cc(cc(c1)C(F)(F)F)C(F)(F)F)CCC(C3CCC(O2)(OO4)C)C");
addExplicitHydrogens(mol);
AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol);
Aromaticity.cdkLegacy().apply(mol);
double value2D = ((DoubleResult) descriptor.calculate(mol).getValue()).doubleValue();
String filename = "cpsa-uncharged.sdf";
InputStream ins = this.getClass().getResourceAsStream(filename);
ISimpleChemObjectReader reader = new MDLV2000Reader(ins);
ChemFile content = (ChemFile) reader.read((ChemObject) new ChemFile());
List cList = ChemFileManipulator.getAllAtomContainers(content);
mol = (IAtomContainer) cList.get(0);
AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol);
Aromaticity.cdkLegacy().apply(mol);
double value3D = ((DoubleResult) descriptor.calculate(mol).getValue()).doubleValue();
Assert.assertEquals(value2D, value3D, 0.001);
}
use of org.openscience.cdk.io.ISimpleChemObjectReader in project cdk by cdk.
the class MomentOfInertiaDescriptorTest method testMomentOfInertia2.
@Test
public void testMomentOfInertia2() throws java.lang.Exception {
String filename = "momi2.hin";
InputStream ins = this.getClass().getResourceAsStream(filename);
ISimpleChemObjectReader reader = new HINReader(ins);
ChemFile content = (ChemFile) reader.read((ChemObject) new ChemFile());
List cList = ChemFileManipulator.getAllAtomContainers(content);
IAtomContainer ac = (IAtomContainer) cList.get(0);
DoubleArrayResult retval = (DoubleArrayResult) descriptor.calculate(ac).getValue();
Assert.assertEquals(10068.419360, retval.get(0), 0.00001);
Assert.assertEquals(9731.078356, retval.get(1), 0.00001);
Assert.assertEquals(773.612799, retval.get(2), 0.00001);
Assert.assertEquals(1.034666, retval.get(3), 0.00001);
Assert.assertEquals(13.014804, retval.get(4), 0.00001);
Assert.assertEquals(12.578745, retval.get(5), 0.00001);
Assert.assertEquals(8.2966226, retval.get(6), 0.00001);
}
use of org.openscience.cdk.io.ISimpleChemObjectReader in project cdk by cdk.
the class PetitjeanShapeIndexDescriptorTest method testPetitjeanShapeIndexDescriptor.
@Test
public void testPetitjeanShapeIndexDescriptor() throws Exception {
// first molecule is nbutane, second is naphthalene
String filename = "petitejean.sdf";
InputStream ins = this.getClass().getResourceAsStream(filename);
ISimpleChemObjectReader reader = new MDLV2000Reader(ins);
ChemFile content = (ChemFile) reader.read((ChemObject) new ChemFile());
List cList = ChemFileManipulator.getAllAtomContainers(content);
IAtomContainer ac = (IAtomContainer) cList.get(0);
DescriptorValue result = descriptor.calculate(ac);
DoubleArrayResult dar = (DoubleArrayResult) result.getValue();
Assert.assertEquals(0.5, dar.get(0), 0.00001);
Assert.assertEquals(0.606477, dar.get(1), 0.000001);
ac = (IAtomContainer) cList.get(1);
result = descriptor.calculate(ac);
dar = (DoubleArrayResult) result.getValue();
Assert.assertEquals(0.666666, dar.get(0), 0.000001);
Assert.assertEquals(0.845452, dar.get(1), 0.000001);
}
Aggregations