Search in sources :

Example 1 with ISimpleChemObjectReader

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;
    }
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) CDKException(org.openscience.cdk.exception.CDKException) IChemFile(org.openscience.cdk.interfaces.IChemFile) ReaderFactory(org.openscience.cdk.io.ReaderFactory) IChemModel(org.openscience.cdk.interfaces.IChemModel) IOException(java.io.IOException) AtomTypeFactory(org.openscience.cdk.config.AtomTypeFactory) CDKException(org.openscience.cdk.exception.CDKException) IOException(java.io.IOException) ISimpleChemObjectReader(org.openscience.cdk.io.ISimpleChemObjectReader) IChemSequence(org.openscience.cdk.interfaces.IChemSequence) IAtom(org.openscience.cdk.interfaces.IAtom)

Example 2 with ISimpleChemObjectReader

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;
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) StringReader(java.io.StringReader) ISimpleChemObjectReader(org.openscience.cdk.io.ISimpleChemObjectReader) MDLV2000Reader(org.openscience.cdk.io.MDLV2000Reader)

Example 3 with ISimpleChemObjectReader

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);
}
Also used : SmilesParser(org.openscience.cdk.smiles.SmilesParser) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) ChemObject(org.openscience.cdk.ChemObject) InputStream(java.io.InputStream) ChemFile(org.openscience.cdk.ChemFile) ISimpleChemObjectReader(org.openscience.cdk.io.ISimpleChemObjectReader) List(java.util.List) DoubleResult(org.openscience.cdk.qsar.result.DoubleResult) MDLV2000Reader(org.openscience.cdk.io.MDLV2000Reader) Test(org.junit.Test)

Example 4 with ISimpleChemObjectReader

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);
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) HINReader(org.openscience.cdk.io.HINReader) ChemObject(org.openscience.cdk.ChemObject) InputStream(java.io.InputStream) ChemFile(org.openscience.cdk.ChemFile) ISimpleChemObjectReader(org.openscience.cdk.io.ISimpleChemObjectReader) List(java.util.List) DoubleArrayResult(org.openscience.cdk.qsar.result.DoubleArrayResult) Test(org.junit.Test)

Example 5 with ISimpleChemObjectReader

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);
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) ChemObject(org.openscience.cdk.ChemObject) InputStream(java.io.InputStream) ChemFile(org.openscience.cdk.ChemFile) ISimpleChemObjectReader(org.openscience.cdk.io.ISimpleChemObjectReader) List(java.util.List) DoubleArrayResult(org.openscience.cdk.qsar.result.DoubleArrayResult) MDLV2000Reader(org.openscience.cdk.io.MDLV2000Reader) DescriptorValue(org.openscience.cdk.qsar.DescriptorValue) Test(org.junit.Test)

Aggregations

ISimpleChemObjectReader (org.openscience.cdk.io.ISimpleChemObjectReader)43 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)37 Test (org.junit.Test)34 InputStream (java.io.InputStream)33 ChemFile (org.openscience.cdk.ChemFile)25 MDLV2000Reader (org.openscience.cdk.io.MDLV2000Reader)24 List (java.util.List)19 DoubleArrayResult (org.openscience.cdk.qsar.result.DoubleArrayResult)15 ChemObject (org.openscience.cdk.ChemObject)12 HINReader (org.openscience.cdk.io.HINReader)9 CDKException (org.openscience.cdk.exception.CDKException)4 IAtom (org.openscience.cdk.interfaces.IAtom)4 IChemFile (org.openscience.cdk.interfaces.IChemFile)4 PDBReader (org.openscience.cdk.io.PDBReader)4 IOException (java.io.IOException)3 IAtomContainerSet (org.openscience.cdk.interfaces.IAtomContainerSet)3 IChemModel (org.openscience.cdk.interfaces.IChemModel)3 IChemSequence (org.openscience.cdk.interfaces.IChemSequence)3 MDLReader (org.openscience.cdk.io.MDLReader)3 StringReader (java.io.StringReader)2