Search in sources :

Example 21 with ChemFile

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

the class XYZReaderTest method testViagra.

@Test
public void testViagra() throws Exception {
    String filename = "viagra.xyz";
    logger.info("Testing: ", filename);
    InputStream ins = this.getClass().getResourceAsStream(filename);
    XYZReader reader = new XYZReader(ins);
    ChemFile chemFile = (ChemFile) reader.read((ChemObject) new ChemFile());
    reader.close();
    Assert.assertNotNull(chemFile);
    Assert.assertEquals(1, chemFile.getChemSequenceCount());
    org.openscience.cdk.interfaces.IChemSequence seq = chemFile.getChemSequence(0);
    Assert.assertNotNull(seq);
    Assert.assertEquals(1, seq.getChemModelCount());
    org.openscience.cdk.interfaces.IChemModel model = seq.getChemModel(0);
    Assert.assertNotNull(model);
    IAtomContainerSet som = model.getMoleculeSet();
    Assert.assertNotNull(som);
    Assert.assertEquals(1, som.getAtomContainerCount());
    IAtomContainer m = som.getAtomContainer(0);
    Assert.assertNotNull(m);
    Assert.assertEquals(63, m.getAtomCount());
    Assert.assertEquals(0, m.getBondCount());
    Assert.assertEquals("N", m.getAtom(0).getSymbol());
    Assert.assertNotNull(m.getAtom(0).getPoint3d());
    Assert.assertEquals(-3.4932, m.getAtom(0).getPoint3d().x, 0.0001);
    Assert.assertEquals(-1.8950, m.getAtom(0).getPoint3d().y, 0.0001);
    Assert.assertEquals(0.1795, m.getAtom(0).getPoint3d().z, 0.0001);
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) ChemObject(org.openscience.cdk.ChemObject) InputStream(java.io.InputStream) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) ChemFile(org.openscience.cdk.ChemFile) SimpleChemObjectReaderTest(org.openscience.cdk.test.io.SimpleChemObjectReaderTest) Test(org.junit.Test)

Example 22 with ChemFile

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

the class XYZReaderTest method testComment.

@Test
public void testComment() throws Exception {
    String filename = "viagra_withComment.xyz";
    logger.info("Testing: ", filename);
    InputStream ins = this.getClass().getResourceAsStream(filename);
    XYZReader reader = new XYZReader(ins);
    ChemFile chemFile = (ChemFile) reader.read((ChemObject) new ChemFile());
    reader.close();
    Assert.assertNotNull(chemFile);
    Assert.assertEquals(1, chemFile.getChemSequenceCount());
    org.openscience.cdk.interfaces.IChemSequence seq = chemFile.getChemSequence(0);
    Assert.assertNotNull(seq);
    Assert.assertEquals(1, seq.getChemModelCount());
    org.openscience.cdk.interfaces.IChemModel model = seq.getChemModel(0);
    Assert.assertNotNull(model);
    IAtomContainerSet som = model.getMoleculeSet();
    Assert.assertNotNull(som);
    Assert.assertEquals(1, som.getAtomContainerCount());
    IAtomContainer m = som.getAtomContainer(0);
    Assert.assertNotNull(m);
    Assert.assertEquals(63, m.getAtomCount());
    Assert.assertEquals(0, m.getBondCount());
    // atom 63: H    3.1625    3.1270   -0.9362
    Assert.assertEquals("H", m.getAtom(62).getSymbol());
    Assert.assertNotNull(m.getAtom(62).getPoint3d());
    Assert.assertEquals(3.1625, m.getAtom(62).getPoint3d().x, 0.0001);
    Assert.assertEquals(3.1270, m.getAtom(62).getPoint3d().y, 0.0001);
    Assert.assertEquals(-0.9362, m.getAtom(62).getPoint3d().z, 0.0001);
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) ChemObject(org.openscience.cdk.ChemObject) InputStream(java.io.InputStream) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) ChemFile(org.openscience.cdk.ChemFile) SimpleChemObjectReaderTest(org.openscience.cdk.test.io.SimpleChemObjectReaderTest) Test(org.junit.Test)

Example 23 with ChemFile

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

the class Gaussian98ReaderTest method testNMRReading.

@Test
public void testNMRReading() throws Exception {
    IAtomContainer atomContainer;
    // boolean foundOneShieldingEntry = false;
    // Double shielding = null;
    Object object;
    int shieldingCounter;
    String filename = "g98ReaderNMRTest.log";
    InputStream ins = this.getClass().getResourceAsStream(filename);
    BufferedReader inputReader = new BufferedReader(new InputStreamReader(ins));
    Gaussian98Reader g98Reader = new Gaussian98Reader(inputReader);
    ChemFile chemFile = g98Reader.read(new ChemFile());
    g98Reader.close();
    List<IAtomContainer> atomContainersList = ChemFileManipulator.getAllAtomContainers(chemFile);
    Assert.assertNotNull(atomContainersList);
    Assert.assertTrue(atomContainersList.size() == 54);
    // logger.debug("Found " + atomContainers.length + " atomContainers");
    Iterator<IAtomContainer> iterator = atomContainersList.iterator();
    int counter = 0;
    while (iterator.hasNext()) {
        IAtomContainer ac = iterator.next();
        shieldingCounter = 0;
        atomContainer = ac;
        for (int g = 0; g < atomContainer.getAtomCount(); g++) {
            object = atomContainer.getAtom(g).getProperty(CDKConstants.ISOTROPIC_SHIELDING);
            if (object != null) {
                // shielding = (Double)object;
                shieldingCounter++;
            }
        }
        if (counter < 53)
            Assert.assertTrue(shieldingCounter == 0);
        else
            Assert.assertTrue(shieldingCounter == ac.getAtomCount());
        // logger.debug("AtomContainer " + (f + 1) + " has " + atomContainers[f].getAtomCount() + " atoms and " + shieldingCounter + " shielding entries");
        counter++;
    }
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) ChemFile(org.openscience.cdk.ChemFile) SimpleChemObjectReaderTest(org.openscience.cdk.test.io.SimpleChemObjectReaderTest) Test(org.junit.Test)

Example 24 with ChemFile

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

the class GhemicalReaderTest method testEthene.

@Test
public void testEthene() throws Exception {
    String filename = "ethene.mm1gp";
    InputStream ins = this.getClass().getResourceAsStream(filename);
    GhemicalMMReader reader = new GhemicalMMReader(ins);
    ChemFile chemFile = (ChemFile) reader.read((ChemObject) new ChemFile());
    reader.close();
    Assert.assertNotNull(chemFile);
    Assert.assertEquals(1, chemFile.getChemSequenceCount());
    org.openscience.cdk.interfaces.IChemSequence seq = chemFile.getChemSequence(0);
    Assert.assertNotNull(seq);
    Assert.assertEquals(1, seq.getChemModelCount());
    org.openscience.cdk.interfaces.IChemModel model = seq.getChemModel(0);
    Assert.assertNotNull(model);
    IAtomContainerSet som = model.getMoleculeSet();
    Assert.assertNotNull(som);
    Assert.assertEquals(1, som.getAtomContainerCount());
    IAtomContainer m = som.getAtomContainer(0);
    Assert.assertNotNull(m);
    Assert.assertEquals(6, m.getAtomCount());
    Assert.assertEquals(5, m.getBondCount());
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) ChemObject(org.openscience.cdk.ChemObject) InputStream(java.io.InputStream) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) ChemFile(org.openscience.cdk.ChemFile) SimpleChemObjectReaderTest(org.openscience.cdk.test.io.SimpleChemObjectReaderTest) Test(org.junit.Test)

Example 25 with ChemFile

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

the class HINReaderTest method testAromaticRingsLine.

/**
 * @cdk.bug 2984581
 * @throws Exception
 */
@Test
public void testAromaticRingsLine() throws Exception {
    String filename = "bug2984581.hin";
    InputStream ins = this.getClass().getResourceAsStream(filename);
    ISimpleChemObjectReader reader = new HINReader(ins);
    IChemFile content = reader.read(new ChemFile());
    reader.close();
    List<IAtomContainer> cList = ChemFileManipulator.getAllAtomContainers(content);
    Assert.assertEquals(1, cList.size());
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) InputStream(java.io.InputStream) IChemFile(org.openscience.cdk.interfaces.IChemFile) IChemFile(org.openscience.cdk.interfaces.IChemFile) ChemFile(org.openscience.cdk.ChemFile) SimpleChemObjectReaderTest(org.openscience.cdk.test.io.SimpleChemObjectReaderTest) 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