Search in sources :

Example 1 with ChemObject

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

the class ConjugatedPiSystemsDetectorTest method testPiSystemWithCumulativeDB.

/**
 *  A unit test for JUnit
 *
 *@return    Description of the Return Value
 */
@Test
public void testPiSystemWithCumulativeDB() throws Exception {
    logger.info("Entering testPiSystemWithCumulativeDB.");
    IAtomContainer mol;
    String filename = "piSystemCumulative.mol";
    InputStream ins = this.getClass().getResourceAsStream(filename);
    MDLReader reader = new MDLReader(ins);
    IChemFile chemFile = (IChemFile) reader.read((ChemObject) new ChemFile());
    mol = chemFile.getChemSequence(0).getChemModel(0).getMoleculeSet().getAtomContainer(0);
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol);
    Aromaticity.cdkLegacy().apply(mol);
    IAtomContainerSet acSet = ConjugatedPiSystemsDetector.detect(mol);
    Assert.assertEquals(2, acSet.getAtomContainerCount());
    IAtomContainer ac1 = acSet.getAtomContainer(0);
    Assert.assertEquals(4, ac1.getAtomCount());
    Assert.assertEquals(3, ac1.getBondCount());
    for (int i = 0; i < ac1.getAtomCount(); i++) {
        Assert.assertTrue(mol.contains(ac1.getAtom(i)));
    }
    for (int i = 0; i < ac1.getBondCount(); i++) {
        Assert.assertTrue(mol.contains(ac1.getBond(i)));
    }
    IAtomContainer ac2 = acSet.getAtomContainer(0);
    Assert.assertEquals(4, ac2.getAtomCount());
    Assert.assertEquals(3, ac2.getBondCount());
    for (int i = 0; i < ac2.getAtomCount(); i++) {
        Assert.assertTrue(mol.contains(ac1.getAtom(i)));
    }
    for (int i = 0; i < ac2.getBondCount(); i++) {
        Assert.assertTrue(mol.contains(ac1.getBond(i)));
    }
}
Also used : MDLReader(org.openscience.cdk.io.MDLReader) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) ChemObject(org.openscience.cdk.ChemObject) InputStream(java.io.InputStream) IChemFile(org.openscience.cdk.interfaces.IChemFile) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) ChemFile(org.openscience.cdk.ChemFile) IChemFile(org.openscience.cdk.interfaces.IChemFile) Test(org.junit.Test)

Example 2 with ChemObject

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

the class ChemFileManipulatorTest method testGetAllAtomContainers_IChemFile.

@Test
public void testGetAllAtomContainers_IChemFile() throws Exception {
    String filename = "prev2000.sd";
    logger.info("Testing: " + filename);
    InputStream ins = this.getClass().getResourceAsStream(filename);
    MDLReader reader = new MDLReader(ins, Mode.STRICT);
    ChemFile chemFile = (ChemFile) reader.read((ChemObject) new ChemFile());
    Assert.assertNotNull(chemFile);
    List<IAtomContainer> containersList = ChemFileManipulator.getAllAtomContainers(chemFile);
    Assert.assertEquals(2, containersList.size());
}
Also used : MDLReader(org.openscience.cdk.io.MDLReader) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) ChemObject(org.openscience.cdk.ChemObject) IChemObject(org.openscience.cdk.interfaces.IChemObject) InputStream(java.io.InputStream) ChemFile(org.openscience.cdk.ChemFile) IChemFile(org.openscience.cdk.interfaces.IChemFile) Test(org.junit.Test)

Example 3 with ChemObject

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

the class ChemModelManipulatorTest method testGetAllAtomContainers_IChemModel.

@Test
public void testGetAllAtomContainers_IChemModel() throws Exception {
    String filename = "a-pinene.mol";
    logger.info("Testing: " + filename);
    InputStream ins = this.getClass().getResourceAsStream(filename);
    MDLV2000Reader reader = new MDLV2000Reader(ins);
    ChemModel chemFile = (ChemModel) reader.read((ChemObject) new ChemModel());
    Assert.assertNotNull(chemFile);
    List<IAtomContainer> containersList = ChemModelManipulator.getAllAtomContainers(chemFile);
    Assert.assertEquals(1, containersList.size());
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) ChemModel(org.openscience.cdk.ChemModel) IChemModel(org.openscience.cdk.interfaces.IChemModel) ChemObject(org.openscience.cdk.ChemObject) IChemObject(org.openscience.cdk.interfaces.IChemObject) InputStream(java.io.InputStream) MDLV2000Reader(org.openscience.cdk.io.MDLV2000Reader) Test(org.junit.Test)

Example 4 with ChemObject

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

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

Aggregations

ChemObject (org.openscience.cdk.ChemObject)108 Test (org.junit.Test)104 InputStream (java.io.InputStream)69 ChemFile (org.openscience.cdk.ChemFile)68 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)64 MDLV2000Reader (org.openscience.cdk.io.MDLV2000Reader)34 IAtomContainerSet (org.openscience.cdk.interfaces.IAtomContainerSet)22 SimpleChemObjectReaderTest (org.openscience.cdk.test.io.SimpleChemObjectReaderTest)21 IChemFile (org.openscience.cdk.interfaces.IChemFile)14 IAtomType (org.openscience.cdk.interfaces.IAtomType)12 IChemModel (org.openscience.cdk.interfaces.IChemModel)12 ISimpleChemObjectReader (org.openscience.cdk.io.ISimpleChemObjectReader)12 List (java.util.List)11 StringReader (java.io.StringReader)10 IChemSequence (org.openscience.cdk.interfaces.IChemSequence)9 IIsotope (org.openscience.cdk.interfaces.IIsotope)9 DoubleArrayResult (org.openscience.cdk.qsar.result.DoubleArrayResult)9 IChemObject (org.openscience.cdk.interfaces.IChemObject)8 HINReader (org.openscience.cdk.io.HINReader)8 DescriptorValue (org.openscience.cdk.qsar.DescriptorValue)8