Search in sources :

Example 1 with ChemFile

use of org.openscience.cdk.ChemFile in project MetFragRelaunched by ipb-halle.

the class OnlineChemSpiderDatabase method getAtomContainerFromString.

/**
 * @param sdfString
 * @return
 * @throws CDKException
 */
protected ArrayList<IAtomContainer> getAtomContainerFromString(String sdfString) {
    MDLV2000Reader reader = new MDLV2000Reader(new StringReader(sdfString));
    java.util.List<IAtomContainer> containersList;
    java.util.ArrayList<IAtomContainer> ret = new ArrayList<IAtomContainer>();
    ChemFile chemFile = null;
    try {
        chemFile = (ChemFile) reader.read((ChemObject) new ChemFile());
    } catch (CDKException e) {
        try {
            reader.close();
        } catch (IOException e1) {
        }
        this.logger.error("Error: Could not perform database query. This could be caused by a temporal database timeout. Try again later.");
        return new ArrayList<IAtomContainer>();
    }
    containersList = ChemFileManipulator.getAllAtomContainers(chemFile);
    for (IAtomContainer container : containersList) {
        ret.add(container);
    }
    try {
        reader.close();
    } catch (IOException e) {
        this.logger.error("Error: Could not perform database query. This could be caused by a temporal database timeout. Try again later.");
        return new ArrayList<IAtomContainer>();
    }
    return ret;
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) CDKException(org.openscience.cdk.exception.CDKException) StringReader(java.io.StringReader) ArrayList(java.util.ArrayList) ChemFile(org.openscience.cdk.ChemFile) IOException(java.io.IOException) MDLV2000Reader(org.openscience.cdk.io.MDLV2000Reader)

Example 2 with ChemFile

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

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

the class ConjugatedPiSystemsDetectorTest method readCMLMolecule.

/**
 *  A unit test for JUnit
 *
 *  @cdk.inchi
 *
 *@return    Description of the Return Value
 */
private IAtomContainer readCMLMolecule(String filename) throws Exception {
    IAtomContainer mol;
    logger.debug("Filename: " + filename);
    InputStream ins = this.getClass().getResourceAsStream(filename);
    CMLReader reader = new CMLReader(ins);
    IChemFile file = reader.read(new ChemFile());
    Assert.assertNotNull(file);
    Assert.assertEquals(1, file.getChemSequenceCount());
    IChemSequence sequence = file.getChemSequence(0);
    Assert.assertNotNull(sequence);
    Assert.assertEquals(1, sequence.getChemModelCount());
    IChemModel chemModel = sequence.getChemModel(0);
    Assert.assertNotNull(chemModel);
    IAtomContainerSet moleculeSet = chemModel.getMoleculeSet();
    Assert.assertNotNull(moleculeSet);
    Assert.assertEquals(1, moleculeSet.getAtomContainerCount());
    mol = moleculeSet.getAtomContainer(0);
    Assert.assertNotNull(mol);
    return 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) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) ChemFile(org.openscience.cdk.ChemFile) IChemFile(org.openscience.cdk.interfaces.IChemFile) IChemModel(org.openscience.cdk.interfaces.IChemModel) IChemSequence(org.openscience.cdk.interfaces.IChemSequence)

Example 4 with ChemFile

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

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

the class FingerprinterTest method testbug2917084.

@Test(expected = CDKException.class)
@Category(SlowTest.class)
public void testbug2917084() throws Exception {
    String filename1 = "boronBuckyBall.mol";
    logger.info("Testing: " + filename1);
    InputStream ins1 = this.getClass().getResourceAsStream(filename1);
    MDLV2000Reader reader = new MDLV2000Reader(ins1, Mode.STRICT);
    IChemFile chemFile = reader.read(new ChemFile());
    Assert.assertNotNull(chemFile);
    IAtomContainer mol = ChemFileManipulator.getAllAtomContainers(chemFile).get(0);
    Fingerprinter fingerprinter = new Fingerprinter(1024, 8);
    Assert.assertNotNull(fingerprinter.getBitFingerprint(mol));
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) InputStream(java.io.InputStream) IChemFile(org.openscience.cdk.interfaces.IChemFile) ChemFile(org.openscience.cdk.ChemFile) IChemFile(org.openscience.cdk.interfaces.IChemFile) MDLV2000Reader(org.openscience.cdk.io.MDLV2000Reader) Category(org.junit.experimental.categories.Category) SlowTest(org.openscience.cdk.test.SlowTest) 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