Search in sources :

Example 1 with MDLReader

use of org.openscience.cdk.io.MDLReader in project ambit-mirror by ideaconsult.

the class SizeDescriptorTest method getTestMolecule.

public IAtomContainer getTestMolecule() throws Exception {
    IAtomContainer mol = new AtomContainer();
    MDLReader reader = new MDLReader(getClass().getClassLoader().getResourceAsStream("ambit2/descriptors/size/224824.sdf"));
    mol = (IAtomContainer) reader.read(mol);
    reader.close();
    return mol;
}
Also used : MDLReader(org.openscience.cdk.io.MDLReader) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) AtomContainer(org.openscience.cdk.silent.AtomContainer)

Example 2 with MDLReader

use of org.openscience.cdk.io.MDLReader 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 3 with MDLReader

use of org.openscience.cdk.io.MDLReader 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 4 with MDLReader

use of org.openscience.cdk.io.MDLReader in project cdk by cdk.

the class MoleculeFactory method loadMolecule.

public static IAtomContainer loadMolecule(String inFile) {
    ChemFile chemFile;
    IChemSequence chemSequence;
    IChemModel chemModel;
    IAtomContainerSet setOfMolecules;
    IAtomContainer molecule = null;
    try (FileInputStream fis = new FileInputStream(inFile);
        MDLReader mr = new MDLReader(fis)) {
        chemFile = (ChemFile) mr.read((ChemObject) new ChemFile());
        mr.close();
        chemSequence = chemFile.getChemSequence(0);
        chemModel = chemSequence.getChemModel(0);
        setOfMolecules = chemModel.getMoleculeSet();
        molecule = setOfMolecules.getAtomContainer(0);
        for (int i = 0; i < molecule.getAtomCount(); i++) {
            molecule.getAtom(i).setPoint2d(null);
        }
    } catch (CDKException | IOException exc) {
        // we just return null if something went wrong
        logger.error("An exception occurred while loading a molecule: " + inFile);
        logger.debug(exc);
    }
    return molecule;
}
Also used : MDLReader(org.openscience.cdk.io.MDLReader) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) CDKException(org.openscience.cdk.exception.CDKException) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) ChemFile(org.openscience.cdk.ChemFile) IChemModel(org.openscience.cdk.interfaces.IChemModel) IOException(java.io.IOException) IChemSequence(org.openscience.cdk.interfaces.IChemSequence) FileInputStream(java.io.FileInputStream)

Example 5 with MDLReader

use of org.openscience.cdk.io.MDLReader in project cdk by cdk.

the class SmilesGeneratorTest method testSFBug1014344.

/**
 * @cdk.bug 1014344
 */
@Category(SlowTest.class)
// MDL -> CML (slow) -> SMILES round tripping
@Test
public void testSFBug1014344() throws Exception {
    String filename = "bug1014344-1.mol";
    InputStream ins = this.getClass().getResourceAsStream(filename);
    MDLReader reader = new MDLReader(ins, Mode.STRICT);
    IAtomContainer mol1 = reader.read(new AtomContainer());
    addImplicitHydrogens(mol1);
    SmilesGenerator sg = new SmilesGenerator();
    String molSmiles = sg.create(mol1);
    StringWriter output = new StringWriter();
    CMLWriter cmlWriter = new CMLWriter(output);
    cmlWriter.write(mol1);
    CMLReader cmlreader = new CMLReader(new ByteArrayInputStream(output.toString().getBytes()));
    IAtomContainer mol2 = ((IChemFile) cmlreader.read(new ChemFile())).getChemSequence(0).getChemModel(0).getMoleculeSet().getAtomContainer(0);
    addImplicitHydrogens(mol2);
    String cmlSmiles = sg.create(new AtomContainer(mol2));
    Assert.assertEquals(molSmiles, cmlSmiles);
}
Also used : MDLReader(org.openscience.cdk.io.MDLReader) CMLReader(org.openscience.cdk.io.CMLReader) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) StringWriter(java.io.StringWriter) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) AtomContainer(org.openscience.cdk.AtomContainer) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ChemFile(org.openscience.cdk.ChemFile) IChemFile(org.openscience.cdk.interfaces.IChemFile) CMLWriter(org.openscience.cdk.io.CMLWriter) Category(org.junit.experimental.categories.Category) SlowTest(org.openscience.cdk.test.SlowTest) Test(org.junit.Test)

Aggregations

MDLReader (org.openscience.cdk.io.MDLReader)13 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)12 InputStream (java.io.InputStream)10 ChemFile (org.openscience.cdk.ChemFile)9 Test (org.junit.Test)7 IChemFile (org.openscience.cdk.interfaces.IChemFile)7 ChemObject (org.openscience.cdk.ChemObject)5 IAtomContainerSet (org.openscience.cdk.interfaces.IAtomContainerSet)5 ByteArrayInputStream (java.io.ByteArrayInputStream)3 AtomContainer (org.openscience.cdk.AtomContainer)3 CMLReader (org.openscience.cdk.io.CMLReader)3 ISimpleChemObjectReader (org.openscience.cdk.io.ISimpleChemObjectReader)3 SlowTest (org.openscience.cdk.test.SlowTest)3 StringWriter (java.io.StringWriter)2 IChemModel (org.openscience.cdk.interfaces.IChemModel)2 IChemSequence (org.openscience.cdk.interfaces.IChemSequence)2 CMLWriter (org.openscience.cdk.io.CMLWriter)2 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 Category (org.junit.experimental.categories.Category)1