Search in sources :

Example 1 with ChemFile

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

the class CIFReaderTest method cod1100784.

/**
 * Ensure a CIF file from the crystallography open database can be read.
 * Example input <a href="http://www.crystallography.net/1100784.cif">1100784</a>.
 */
@Test
public void cod1100784() throws IOException, CDKException {
    InputStream in = getClass().getResourceAsStream("1100784.cif");
    CIFReader cifReader = new CIFReader(in);
    // try {
    IChemFile chemFile = cifReader.read(new ChemFile());
    org.hamcrest.MatcherAssert.assertThat(chemFile.getChemSequenceCount(), is(1));
    org.hamcrest.MatcherAssert.assertThat(chemFile.getChemSequence(0).getChemModelCount(), is(1));
    Assert.assertNotNull(chemFile.getChemSequence(0).getChemModel(0).getCrystal());
    // } finally {
    cifReader.close();
// }
}
Also used : InputStream(java.io.InputStream) IChemFile(org.openscience.cdk.interfaces.IChemFile) ChemFile(org.openscience.cdk.silent.ChemFile) IChemFile(org.openscience.cdk.interfaces.IChemFile) Test(org.junit.Test) ChemObjectIOTest(org.openscience.cdk.test.io.ChemObjectIOTest)

Example 2 with ChemFile

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

the class CIFReaderTest method cod1100784AtomCount.

@Test
public void cod1100784AtomCount() throws IOException, CDKException {
    InputStream in = getClass().getResourceAsStream("1100784.cif");
    CIFReader cifReader = new CIFReader(in);
    IChemFile chemFile = cifReader.read(new ChemFile());
    ICrystal crystal = chemFile.getChemSequence(0).getChemModel(0).getCrystal();
    Assert.assertEquals(72, crystal.getAtomCount());
    cifReader.close();
}
Also used : ICrystal(org.openscience.cdk.interfaces.ICrystal) InputStream(java.io.InputStream) IChemFile(org.openscience.cdk.interfaces.IChemFile) ChemFile(org.openscience.cdk.silent.ChemFile) IChemFile(org.openscience.cdk.interfaces.IChemFile) Test(org.junit.Test) ChemObjectIOTest(org.openscience.cdk.test.io.ChemObjectIOTest)

Example 3 with ChemFile

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

the class CIFReaderTest method cod1100784CellLengths.

@Test()
public void cod1100784CellLengths() throws IOException, CDKException {
    InputStream in = getClass().getResourceAsStream("1100784.cif");
    CIFReader cifReader = new CIFReader(in);
    IChemFile chemFile = cifReader.read(new ChemFile());
    ICrystal crystal = chemFile.getChemSequence(0).getChemModel(0).getCrystal();
    Assert.assertTrue(java.lang.Math.abs(crystal.getA().length() - 10.9754) < 1E-5);
    Assert.assertTrue(java.lang.Math.abs(crystal.getB().length() - 11.4045) < 1E-5);
    Assert.assertTrue(java.lang.Math.abs(crystal.getC().length() - 12.9314) < 1E-5);
    cifReader.close();
}
Also used : ICrystal(org.openscience.cdk.interfaces.ICrystal) InputStream(java.io.InputStream) IChemFile(org.openscience.cdk.interfaces.IChemFile) ChemFile(org.openscience.cdk.silent.ChemFile) IChemFile(org.openscience.cdk.interfaces.IChemFile) Test(org.junit.Test) ChemObjectIOTest(org.openscience.cdk.test.io.ChemObjectIOTest)

Example 4 with ChemFile

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

the class CDKAtomTypeMatcherFilesTest method testSmilesFiles.

@Test
public void testSmilesFiles() throws Exception {
    CDKAtomTypeMatcher atomTypeMatcher = CDKAtomTypeMatcher.getInstance(SilentChemObjectBuilder.getInstance());
    // Read the first file
    String filename = "smiles1.cml";
    InputStream ins = this.getClass().getResourceAsStream(filename);
    CMLReader reader = new CMLReader(ins);
    IChemFile chemFile = reader.read(new ChemFile());
    Assert.assertNotNull(chemFile);
    IAtomContainer mol1 = ChemFileManipulator.getAllAtomContainers(chemFile).get(0);
    // Read the second file
    filename = "smiles2.cml";
    ins = this.getClass().getResourceAsStream(filename);
    reader = new CMLReader(ins);
    chemFile = reader.read(new ChemFile());
    Assert.assertNotNull(chemFile);
    IAtomContainer mol2 = ChemFileManipulator.getAllAtomContainers(chemFile).get(0);
    IAtomType[] types1 = atomTypeMatcher.findMatchingAtomTypes(mol1);
    IAtomType[] types2 = atomTypeMatcher.findMatchingAtomTypes(mol2);
    for (int i = 0; i < mol1.getAtomCount(); i++) {
        Assert.assertNotNull("Atom typing in mol1 failed for atom " + (i + 1), types1[i]);
        Assert.assertNotNull("Atom typing in mol2 failed for atom " + (i + 1), types2[i]);
        Assert.assertEquals("Atom type mismatch for the " + (i + 1) + " atom", types1[i].getAtomTypeName(), types2[i].getAtomTypeName());
    }
}
Also used : IAtomType(org.openscience.cdk.interfaces.IAtomType) CMLReader(org.openscience.cdk.io.CMLReader) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) InputStream(java.io.InputStream) IChemFile(org.openscience.cdk.interfaces.IChemFile) ChemFile(org.openscience.cdk.silent.ChemFile) IChemFile(org.openscience.cdk.interfaces.IChemFile) Test(org.junit.Test)

Example 5 with ChemFile

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

the class CDKAtomTypeMatcherFilesTest method testFile3.

@Test
public void testFile3() throws Exception {
    String filename = "3.cml";
    InputStream ins = this.getClass().getResourceAsStream(filename);
    CMLReader reader = new CMLReader(ins);
    IChemFile chemFile = reader.read(new ChemFile());
    // test the resulting ChemFile content
    Assert.assertNotNull(chemFile);
    IAtomContainer mol = ChemFileManipulator.getAllAtomContainers(chemFile).get(0);
    String[] expectedTypes = { "C.sp2", "N.sp2", "C.sp2", "N.sp3", "C.sp2", "N.sp2", "O.sp3", "C.sp2", "C.sp2", "C.sp2" };
    assertAtomTypes(testedAtomTypes, expectedTypes, mol);
}
Also used : CMLReader(org.openscience.cdk.io.CMLReader) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) InputStream(java.io.InputStream) IChemFile(org.openscience.cdk.interfaces.IChemFile) ChemFile(org.openscience.cdk.silent.ChemFile) IChemFile(org.openscience.cdk.interfaces.IChemFile) Test(org.junit.Test)

Aggregations

ChemFile (org.openscience.cdk.silent.ChemFile)19 InputStream (java.io.InputStream)18 Test (org.junit.Test)18 IChemFile (org.openscience.cdk.interfaces.IChemFile)18 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)14 CMLReader (org.openscience.cdk.io.CMLReader)9 MDLV2000Reader (org.openscience.cdk.io.MDLV2000Reader)5 IChemModel (org.openscience.cdk.interfaces.IChemModel)4 IChemSequence (org.openscience.cdk.interfaces.IChemSequence)4 IRingSet (org.openscience.cdk.interfaces.IRingSet)4 ChemObjectIOTest (org.openscience.cdk.test.io.ChemObjectIOTest)4 Vector (java.util.Vector)3 ICrystal (org.openscience.cdk.interfaces.ICrystal)3 IAtom (org.openscience.cdk.interfaces.IAtom)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Vector3d (javax.vecmath.Vector3d)1 CIP_CHIRALITY (org.openscience.cdk.geometry.cip.CIPTool.CIP_CHIRALITY)1 IAtomType (org.openscience.cdk.interfaces.IAtomType)1 IPDBAtom (org.openscience.cdk.interfaces.IPDBAtom)1 ITetrahedralChirality (org.openscience.cdk.interfaces.ITetrahedralChirality)1