Search in sources :

Example 1 with InteractiveIteratingMDLReader

use of ambit2.core.io.InteractiveIteratingMDLReader in project ambit-mirror by ideaconsult.

the class DataSet method getReader.

public static IIteratingChemObjectReader<IAtomContainer> getReader(InputStream in, String extension) throws CDKException, AmbitIOException {
    FileInputState instate = new FileInputState();
    IIteratingChemObjectReader<IAtomContainer> reader;
    if (extension.endsWith(FileInputState._FILE_TYPE.SDF_INDEX.getExtension())) {
        reader = new InteractiveIteratingMDLReader(in, SilentChemObjectBuilder.getInstance());
        ((InteractiveIteratingMDLReader) reader).setSkip(true);
    } else
        reader = instate.getReader(in, extension);
    reader.setReaderMode(Mode.RELAXED);
    reader.setErrorHandler(new IChemObjectReaderErrorHandler() {

        @Override
        public void handleError(String message, int row, int colStart, int colEnd, Exception exception) {
            exception.printStackTrace();
        }

        @Override
        public void handleError(String message, int row, int colStart, int colEnd) {
            System.out.println(message);
        }

        @Override
        public void handleError(String message, Exception exception) {
            exception.printStackTrace();
        }

        @Override
        public void handleError(String message) {
            System.out.println(message);
        }
    });
    return reader;
}
Also used : IChemObjectReaderErrorHandler(org.openscience.cdk.io.IChemObjectReaderErrorHandler) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) InteractiveIteratingMDLReader(ambit2.core.io.InteractiveIteratingMDLReader) FileInputState(ambit2.core.io.FileInputState) AmbitIOException(ambit2.base.exceptions.AmbitIOException) CDKException(org.openscience.cdk.exception.CDKException) FileNotFoundException(java.io.FileNotFoundException)

Example 2 with InteractiveIteratingMDLReader

use of ambit2.core.io.InteractiveIteratingMDLReader in project ambit-mirror by ideaconsult.

the class SLNCli method getReader.

public IIteratingChemObjectReader<IAtomContainer> getReader(InputStream in, String extension) throws CDKException, AmbitIOException {
    FileInputState instate = new FileInputState();
    IIteratingChemObjectReader<IAtomContainer> reader;
    if (extension.endsWith(FileInputState._FILE_TYPE.SDF_INDEX.getExtension())) {
        reader = new InteractiveIteratingMDLReader(in, SilentChemObjectBuilder.getInstance());
        ((InteractiveIteratingMDLReader) reader).setSkip(true);
    } else
        reader = instate.getReader(in, extension);
    reader.setReaderMode(Mode.RELAXED);
    reader.setErrorHandler(new IChemObjectReaderErrorHandler() {

        @Override
        public void handleError(String message, int row, int colStart, int colEnd, Exception exception) {
            exception.printStackTrace();
        }

        @Override
        public void handleError(String message, int row, int colStart, int colEnd) {
            System.out.println(message);
        }

        @Override
        public void handleError(String message, Exception exception) {
            exception.printStackTrace();
        }

        @Override
        public void handleError(String message) {
            System.out.println(message);
        }
    });
    return reader;
}
Also used : IChemObjectReaderErrorHandler(org.openscience.cdk.io.IChemObjectReaderErrorHandler) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) InteractiveIteratingMDLReader(ambit2.core.io.InteractiveIteratingMDLReader) FileInputState(ambit2.core.io.FileInputState) AmbitIOException(ambit2.base.exceptions.AmbitIOException) CDKException(org.openscience.cdk.exception.CDKException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 3 with InteractiveIteratingMDLReader

use of ambit2.core.io.InteractiveIteratingMDLReader in project ambit-mirror by ideaconsult.

the class ListenerTest method testListenerSDF.

@Test
public void testListenerSDF() throws Exception {
    IIteratingChemObjectReader reader = new InteractiveIteratingMDLReader(getClass().getClassLoader().getResourceAsStream("test_properties.sdf"), DefaultChemObjectBuilder.getInstance(), true);
    String[] labels = { "ID", "SMILES", "WEIGHT", "FORMULA", "NAME", "Drug" };
    readFile(reader, labels);
    reader.close();
}
Also used : IIteratingChemObjectReader(org.openscience.cdk.io.iterator.IIteratingChemObjectReader) InteractiveIteratingMDLReader(ambit2.core.io.InteractiveIteratingMDLReader) Test(org.junit.Test)

Example 4 with InteractiveIteratingMDLReader

use of ambit2.core.io.InteractiveIteratingMDLReader in project ambit-mirror by ideaconsult.

the class ParserTest method testStereo.

public void testStereo(SmilesGenerator g) throws Exception {
    SmilesParser p = new SmilesParser(SilentChemObjectBuilder.getInstance());
    InChIGeneratorFactory factory = InChIGeneratorFactory.getInstance();
    IIteratingChemObjectReader<IAtomContainer> reader = null;
    int error = 0;
    try {
        InputStream in = ParserTest.class.getClassLoader().getResourceAsStream("ambit2/dbcli/test/stereo.sdf");
        Assert.assertNotNull(in);
        reader = new InteractiveIteratingMDLReader(in, SilentChemObjectBuilder.getInstance());
        Assert.assertNotNull(reader);
        StructureStandardizer standardizer = new StructureStandardizer();
        standardizer.setGenerateSMILES(true);
        standardizer.setGenerateSMILES_Canonical(false);
        standardizer.setNeutralise(true);
        standardizer.setSplitFragments(true);
        standardizer.setGenerateTautomers(false);
        standardizer.setImplicitHydrogens(true);
        standardizer.setClearIsotopes(true);
        while (reader.hasNext()) {
            IAtomContainer m1 = reader.next();
            AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(m1);
            try {
                String smi = g.create(m1);
                IAtomContainer m2 = p.parseSmiles(smi);
                AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(m2);
                String newsmiles = g.create(m2);
                Assert.assertEquals(smi, newsmiles);
                InChIGenerator gen1 = factory.getInChIGenerator(m1);
                InChIGenerator gen2 = factory.getInChIGenerator(m2);
                Assert.assertEquals(gen1.getInchi(), gen2.getInchi());
                Assert.assertEquals(gen1.getInchiKey(), gen2.getInchiKey());
                Assert.assertEquals(g.create(m1), g.create(m2));
                System.out.println(smi);
                printstereo(m1);
                System.out.println(newsmiles);
                printstereo(m2);
                IAtomContainer m1_transformed = standardizer.process(m1);
                AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(m1_transformed);
                IAtomContainer m2_transformed = standardizer.process(m2);
                AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(m2_transformed);
                System.out.println(g.create(m1_transformed));
                printstereo(m1_transformed);
                System.out.println(g.create(m2_transformed));
                printstereo(m2_transformed);
                gen1 = factory.getInChIGenerator(m1_transformed);
                gen2 = factory.getInChIGenerator(m2_transformed);
                Assert.assertEquals(gen1.getInchi(), gen2.getInchi());
                Assert.assertEquals(gen1.getInchiKey(), gen2.getInchiKey());
            } catch (Exception x) {
                error++;
                System.out.println(x.getMessage());
            }
        }
    } finally {
        if (reader != null)
            reader.close();
    }
    Assert.assertEquals(0, error);
}
Also used : SmilesParser(org.openscience.cdk.smiles.SmilesParser) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) InChIGenerator(org.openscience.cdk.inchi.InChIGenerator) InputStream(java.io.InputStream) InteractiveIteratingMDLReader(ambit2.core.io.InteractiveIteratingMDLReader) InChIGeneratorFactory(org.openscience.cdk.inchi.InChIGeneratorFactory) StructureStandardizer(ambit2.tautomers.processor.StructureStandardizer)

Example 5 with InteractiveIteratingMDLReader

use of ambit2.core.io.InteractiveIteratingMDLReader in project ambit-mirror by ideaconsult.

the class StandardisationTest method test_xv5_sh.

@Test
public void test_xv5_sh() throws Exception {
    try (InputStream in = getClass().getClassLoader().getResourceAsStream("ambit2/dbcli/test/xv5.sdf")) {
        // IteratingSDFReader reader = new IteratingSDFReader(in,
        // SilentChemObjectBuilder.getInstance());
        InteractiveIteratingMDLReader reader = new InteractiveIteratingMDLReader(in, SilentChemObjectBuilder.getInstance());
        StructureStandardizer z = new StructureStandardizer();
        z.setImplicitHydrogens(true);
        z.setNeutralise(false);
        z.setGenerateTautomers(false);
        z.setGenerateSMILES(true);
        z.setGenerateSMILES_Canonical(false);
        z.setGenerateSMILES_Aromatic(false);
        z.setSplitFragments(false);
        z.setClearIsotopes(true);
        z.setGenerateInChI(true);
        CDKHydrogenAdder h = CDKHydrogenAdder.getInstance(SilentChemObjectBuilder.getInstance());
        while (reader.hasNext()) {
            IAtomContainer mol = reader.next();
            AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol);
            h.addImplicitHydrogens(mol);
            System.out.println(SmilesGenerator.generic().create(mol));
            mol = z.process(mol);
            // mol = AtomContainerManipulator.suppressHydrogens(mol);
            // System.out.println(SmilesGenerator.generic().create(mol));
            System.out.println(mol.getProperties().get(Property.getSMILESInstance()));
        }
    }
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) InputStream(java.io.InputStream) InteractiveIteratingMDLReader(ambit2.core.io.InteractiveIteratingMDLReader) CDKHydrogenAdder(org.openscience.cdk.tools.CDKHydrogenAdder) StructureStandardizer(ambit2.tautomers.processor.StructureStandardizer) Test(org.junit.Test)

Aggregations

InteractiveIteratingMDLReader (ambit2.core.io.InteractiveIteratingMDLReader)8 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)7 AmbitIOException (ambit2.base.exceptions.AmbitIOException)5 FileInputState (ambit2.core.io.FileInputState)5 FileNotFoundException (java.io.FileNotFoundException)5 CDKException (org.openscience.cdk.exception.CDKException)5 IChemObjectReaderErrorHandler (org.openscience.cdk.io.IChemObjectReaderErrorHandler)5 StructureStandardizer (ambit2.tautomers.processor.StructureStandardizer)2 InputStream (java.io.InputStream)2 Test (org.junit.Test)2 IOException (java.io.IOException)1 InChIGenerator (org.openscience.cdk.inchi.InChIGenerator)1 InChIGeneratorFactory (org.openscience.cdk.inchi.InChIGeneratorFactory)1 IIteratingChemObjectReader (org.openscience.cdk.io.iterator.IIteratingChemObjectReader)1 SmilesParser (org.openscience.cdk.smiles.SmilesParser)1 CDKHydrogenAdder (org.openscience.cdk.tools.CDKHydrogenAdder)1