Search in sources :

Example 6 with ChemFile

use of org.openscience.cdk.ChemFile 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 7 with ChemFile

use of org.openscience.cdk.ChemFile in project cdk by cdk.

the class AtomPlacer3DTest method testFindHeavyAtomsInChain_IAtomContainer_IAtomContainer.

@Test
public void testFindHeavyAtomsInChain_IAtomContainer_IAtomContainer() throws Exception {
    String filename = "allmol232.mol";
    InputStream ins = this.getClass().getResourceAsStream(filename);
    // TODO: shk3-cleanuptests: best to use the STRICT IO mode here
    MDLV2000Reader reader = new MDLV2000Reader(ins);
    ChemFile chemFile = (ChemFile) reader.read((ChemObject) new ChemFile());
    reader.close();
    List<IAtomContainer> containersList = ChemFileManipulator.getAllAtomContainers(chemFile);
    IAtomContainer ac = new AtomContainer(containersList.get(0));
    addExplicitHydrogens(ac);
    IAtomContainer chain = ac.getBuilder().newInstance(IAtomContainer.class);
    for (int i = 16; i < 25; i++) {
        chain.addAtom(ac.getAtom(i));
    }
    chain.addAtom(ac.getAtom(29));
    chain.addAtom(ac.getAtom(30));
    int[] result = new AtomPlacer3D().findHeavyAtomsInChain(ac, chain);
    Assert.assertEquals(16, result[0]);
    Assert.assertEquals(11, result[1]);
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) ChemObject(org.openscience.cdk.ChemObject) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) AtomContainer(org.openscience.cdk.silent.AtomContainer) InputStream(java.io.InputStream) ChemFile(org.openscience.cdk.ChemFile) MDLV2000Reader(org.openscience.cdk.io.MDLV2000Reader) Test(org.junit.Test)

Example 8 with ChemFile

use of org.openscience.cdk.ChemFile in project cdk by cdk.

the class ModelBuilder3DTest method testModelBuilder3D_bug_1241421.

/*
     * @cdk.bug 1241421
     */
@Test
@Category(SlowTest.class)
public void testModelBuilder3D_bug_1241421() throws Exception {
    ModelBuilder3D mb3d = ModelBuilder3D.getInstance(DefaultChemObjectBuilder.getInstance());
    String filename = "bug1241421.mol";
    InputStream ins = this.getClass().getResourceAsStream(filename);
    MDLV2000Reader reader = new MDLV2000Reader(ins);
    ChemFile chemFile = (ChemFile) reader.read((ChemObject) new ChemFile());
    reader.close();
    List<IAtomContainer> containersList = ChemFileManipulator.getAllAtomContainers(chemFile);
    IAtomContainer ac = new AtomContainer(containersList.get(0));
    ac = mb3d.generate3DCoordinates(ac, false);
    checkAverageBondLength(ac);
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) ChemObject(org.openscience.cdk.ChemObject) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) AtomContainer(org.openscience.cdk.silent.AtomContainer) InputStream(java.io.InputStream) ChemFile(org.openscience.cdk.ChemFile) MDLV2000Reader(org.openscience.cdk.io.MDLV2000Reader) Category(org.junit.experimental.categories.Category) SlowTest(org.openscience.cdk.test.SlowTest) Test(org.junit.Test)

Example 9 with ChemFile

use of org.openscience.cdk.ChemFile in project cdk by cdk.

the class MolecularFormulaManipulatorTest method testFromMol.

/**
 * @cdk.bug 3071473
 */
@Test
public void testFromMol() throws Exception {
    String filename = "formulatest.mol";
    InputStream ins = this.getClass().getResourceAsStream(filename);
    MDLV2000Reader reader = new MDLV2000Reader(ins);
    ChemFile chemFile = reader.read(new ChemFile());
    reader.close();
    Assert.assertNotNull(chemFile);
    List<IAtomContainer> mols = ChemFileManipulator.getAllAtomContainers(chemFile);
    IAtomContainer mol = mols.get(0);
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol);
    CDKHydrogenAdder ha = CDKHydrogenAdder.getInstance(DefaultChemObjectBuilder.getInstance());
    ha.addImplicitHydrogens(mol);
    AtomContainerManipulator.convertImplicitToExplicitHydrogens(mol);
    IMolecularFormula molecularFormula = MolecularFormulaManipulator.getMolecularFormula(mol);
    String formula2 = MolecularFormulaManipulator.getString(molecularFormula);
    Assert.assertTrue(formula2.equals("C35H64N3O21P3S"));
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) InputStream(java.io.InputStream) ChemFile(org.openscience.cdk.ChemFile) CDKHydrogenAdder(org.openscience.cdk.tools.CDKHydrogenAdder) IMolecularFormula(org.openscience.cdk.interfaces.IMolecularFormula) MDLV2000Reader(org.openscience.cdk.io.MDLV2000Reader) Test(org.junit.Test)

Example 10 with ChemFile

use of org.openscience.cdk.ChemFile 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)

Aggregations

ChemFile (org.openscience.cdk.ChemFile)188 InputStream (java.io.InputStream)171 Test (org.junit.Test)171 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)154 IChemFile (org.openscience.cdk.interfaces.IChemFile)112 ChemObject (org.openscience.cdk.ChemObject)68 SimpleChemObjectReaderTest (org.openscience.cdk.test.io.SimpleChemObjectReaderTest)66 IChemSequence (org.openscience.cdk.interfaces.IChemSequence)57 IChemModel (org.openscience.cdk.interfaces.IChemModel)55 MDLV2000Reader (org.openscience.cdk.io.MDLV2000Reader)52 CMLReader (org.openscience.cdk.io.CMLReader)41 IAtomContainerSet (org.openscience.cdk.interfaces.IAtomContainerSet)33 ByteArrayInputStream (java.io.ByteArrayInputStream)30 ISimpleChemObjectReader (org.openscience.cdk.io.ISimpleChemObjectReader)25 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)23 List (java.util.List)21 IAtom (org.openscience.cdk.interfaces.IAtom)19 SlowTest (org.openscience.cdk.test.SlowTest)18 DoubleArrayResult (org.openscience.cdk.qsar.result.DoubleArrayResult)15 IReaction (org.openscience.cdk.interfaces.IReaction)11