Search in sources :

Example 1 with MDLV2000Reader

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

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

the class MoleculeTools method readMolfile.

public static IAtomContainer readMolfile(String molfile) throws Exception {
    MDLV2000Reader r = null;
    try {
        StringReader reader = new StringReader(molfile);
        r = new MDLV2000Reader(reader);
        r.addSetting(new BooleanIOSetting("AddStereoElements", IOSetting.Importance.HIGH, "Assign stereo configurations to stereocenters utilising 2D/3D coordinates.", "false"));
        /*
			 * Properties customSettings = new Properties();
			 * customSettings.setProperty("AddStereoElements", "false");
			 * PropertiesListener listener = new
			 * PropertiesListener(customSettings);
			 * r.addChemObjectIOListener(listener);
			 */
        IAtomContainer mol = r.read(new AtomContainer());
        reader.close();
        return mol;
    } finally {
        try {
            r.close();
        } catch (Exception x) {
        }
    }
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) AtomContainer(org.openscience.cdk.silent.AtomContainer) BooleanIOSetting(org.openscience.cdk.io.setting.BooleanIOSetting) StringReader(java.io.StringReader) MDLV2000Reader(org.openscience.cdk.io.MDLV2000Reader) InvalidSmilesException(org.openscience.cdk.exception.InvalidSmilesException) CDKException(org.openscience.cdk.exception.CDKException) IOException(java.io.IOException)

Example 3 with MDLV2000Reader

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

the class MDLV2000ReaderExtendedTest method readSGroup.

protected IChemObject readSGroup(String dir, String file) throws Exception {
    MDLV2000Reader reader = new MDLV2000Reader(MDLV2000Reader.class.getClassLoader().getResourceAsStream(dir + file), IChemObjectReader.Mode.RELAXED);
    IAtomContainer mol = MoleculeTools.newMolecule(SilentChemObjectBuilder.getInstance());
    IChemObject newMol = reader.read(mol);
    reader.close();
    return newMol;
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IChemObject(org.openscience.cdk.interfaces.IChemObject) MDLV2000Reader(org.openscience.cdk.io.MDLV2000Reader)

Example 4 with MDLV2000Reader

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

the class MDLV2000ReaderExtendedTest method testRGP.

@Test
public void testRGP() throws Exception {
    File[] files = new File("src/test/resources/ambit2/core/data/M__RGP").listFiles();
    if (files == null)
        throw new Exception("Files not found");
    for (File file : files) try {
        MDLV2000Reader reader = new MDLV2000Reader(new FileInputStream(file));
        IAtomContainer mol = MoleculeTools.newMolecule(SilentChemObjectBuilder.getInstance());
        reader.read(mol);
        reader.close();
    } catch (Exception x) {
        System.err.println(file.getName());
        x.printStackTrace();
    // throw new Exception(file.getName(),x);
    }
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) File(java.io.File) MDLV2000Reader(org.openscience.cdk.io.MDLV2000Reader) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 5 with MDLV2000Reader

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

Aggregations

MDLV2000Reader (org.openscience.cdk.io.MDLV2000Reader)162 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)156 Test (org.junit.Test)140 InputStream (java.io.InputStream)138 ChemFile (org.openscience.cdk.ChemFile)52 AtomContainer (org.openscience.cdk.AtomContainer)44 ChemObject (org.openscience.cdk.ChemObject)34 ISimpleChemObjectReader (org.openscience.cdk.io.ISimpleChemObjectReader)24 SlowTest (org.openscience.cdk.test.SlowTest)21 IChemObjectBuilder (org.openscience.cdk.interfaces.IChemObjectBuilder)17 IChemFile (org.openscience.cdk.interfaces.IChemFile)15 IChemModel (org.openscience.cdk.interfaces.IChemModel)14 AtomContainer (org.openscience.cdk.silent.AtomContainer)14 IChemSequence (org.openscience.cdk.interfaces.IChemSequence)13 List (java.util.List)12 IRingSet (org.openscience.cdk.interfaces.IRingSet)12 ByteArrayInputStream (java.io.ByteArrayInputStream)11 DescriptorValue (org.openscience.cdk.qsar.DescriptorValue)11 DoubleArrayResult (org.openscience.cdk.qsar.result.DoubleArrayResult)11 IAtom (org.openscience.cdk.interfaces.IAtom)10