Search in sources :

Example 1 with MoleculeReader

use of ambit2.core.processors.structure.MoleculeReader in project ambit-mirror by ideaconsult.

the class CompoundJSONReporter method getSDFContent.

protected String getSDFContent(IStructureRecord item) throws AmbitException {
    // most common case
    if (MOL_TYPE.SDF.toString().equals(item.getFormat()))
        return item.getContent();
    // otherwise
    if (reader == null)
        reader = new MoleculeReader();
    try {
        StringWriter w = new StringWriter();
        SDFWriter sdfwriter = new SDFWriter(w);
        IAtomContainer ac = reader.process(item);
        MoleculeTools.clearProperties(ac);
        sdfwriter.write(ac);
        sdfwriter.close();
        return w.toString();
    } catch (Exception x) {
        throw new AmbitException(x);
    }
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) MoleculeReader(ambit2.core.processors.structure.MoleculeReader) StringWriter(java.io.StringWriter) SDFWriter(org.openscience.cdk.io.SDFWriter) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) IOException(java.io.IOException) AmbitException(net.idea.modbcum.i.exceptions.AmbitException)

Example 2 with MoleculeReader

use of ambit2.core.processors.structure.MoleculeReader in project ambit-mirror by ideaconsult.

the class CallableFingerprintsModelCreator method createProcessors.

protected ProcessorsChain<IStructureRecord, IBatchStatistics, IProcessor> createProcessors() throws Exception {
    ProcessorsChain<IStructureRecord, IBatchStatistics, IProcessor> p1 = new ProcessorsChain<IStructureRecord, IBatchStatistics, IProcessor>();
    p1.add(new ProcessorStructureRetrieval());
    p1.add(new MoleculeReader());
    p1.add(new FingerprintGenerator(new Fingerprinter()));
    p1.add(new DefaultAmbitProcessor<BitSet, BitSet>() {

        /**
         */
        private static final long serialVersionUID = -2978697147490545478L;

        public BitSet process(BitSet target) throws AmbitException {
            builder.getTrainingData().add(target);
            return target;
        }
    });
    p1.setAbortOnError(true);
    return p1;
}
Also used : IBatchStatistics(net.idea.modbcum.i.batch.IBatchStatistics) BitSet(java.util.BitSet) IProcessor(net.idea.modbcum.i.processors.IProcessor) FingerprintGenerator(ambit2.core.processors.structure.FingerprintGenerator) IStructureRecord(ambit2.base.interfaces.IStructureRecord) MoleculeReader(ambit2.core.processors.structure.MoleculeReader) Fingerprinter(org.openscience.cdk.fingerprint.Fingerprinter) ProcessorsChain(net.idea.modbcum.i.processors.ProcessorsChain) ProcessorStructureRetrieval(ambit2.db.processors.ProcessorStructureRetrieval) AmbitException(net.idea.modbcum.i.exceptions.AmbitException)

Example 3 with MoleculeReader

use of ambit2.core.processors.structure.MoleculeReader in project ambit-mirror by ideaconsult.

the class FingerPrintGeneratorTest method test.

@Test
public void test() throws Exception {
    BigInteger[] expected = /*{
				new BigInteger("1126174803623952"), 
				new BigInteger("1152961362175993860"), 
				new BigInteger("2305843011903291728"),
				new BigInteger("25769820160"), 
				new BigInteger("1099511627776"),
				new BigInteger("33554496"), 
				new BigInteger("8864814662912"),
				new BigInteger("4803285265416200"), 
				new BigInteger("9223372050830336000"),
				new BigInteger("2454675102173515776"),
				new BigInteger("1152921504611041536"),
				new BigInteger("155684661740175875"), 
				new BigInteger("6917529131798265856"), 
				new BigInteger("310748377023266816"),
				new BigInteger("67110400"), 
				new BigInteger("2305843009213710336")};
				*/
    { new BigInteger("576462128137896992"), new BigInteger("10376293541473171584"), new BigInteger("2305843009214747777"), new BigInteger("72127962782121984"), new BigInteger("52776558133248"), new BigInteger("0"), new BigInteger("338649581355264"), new BigInteger("4366794756"), new BigInteger("17730770043904"), new BigInteger("2314887591865356288"), new BigInteger("2305844109263241488"), new BigInteger("2400709834665132544"), new BigInteger("13835058125075449856"), new BigInteger("10741891072"), new BigInteger("9007208196998144"), new BigInteger("18014398511644672") };
    MoleculeReader molreader = new MoleculeReader();
    FingerprintGenerator gen = new FingerprintGenerator(new Fingerprinter());
    InputStream in = FingerPrintGeneratorTest.class.getClassLoader().getResourceAsStream("ambit2/core/data/fp/fptest.mol");
    RawIteratingSDFReader reader = new RawIteratingSDFReader(new InputStreamReader(in));
    while (reader.hasNext()) {
        IStructureRecord record = reader.nextRecord();
        BitSet bs1 = gen.process(molreader.process(record));
        BigInteger[] h16 = new BigInteger[16];
        MoleculeTools.bitset2bigint16(bs1, 64, h16);
        new Random(10000);
        BitSet bs2 = gen.process(molreader.process(record));
        Assert.assertEquals(bs1, bs2);
        MoleculeTools.bitset2bigint16(bs2, 64, h16);
        for (int i = 0; i < 16; i++) {
            Assert.assertEquals(expected[i], h16[i]);
        }
    }
/*
		IStructureRecord record = new StructureRecord();
		record.setContent();
		MoleculeReader reader = new MoleculeReader();
		reader.process(target)
		*/
}
Also used : RawIteratingSDFReader(ambit2.core.io.RawIteratingSDFReader) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) BitSet(java.util.BitSet) FingerprintGenerator(ambit2.core.processors.structure.FingerprintGenerator) IStructureRecord(ambit2.base.interfaces.IStructureRecord) MoleculeReader(ambit2.core.processors.structure.MoleculeReader) MACCSFingerprinter(org.openscience.cdk.fingerprint.MACCSFingerprinter) ExtendedFingerprinter(org.openscience.cdk.fingerprint.ExtendedFingerprinter) SubstructureFingerprinter(org.openscience.cdk.fingerprint.SubstructureFingerprinter) PubchemFingerprinter(org.openscience.cdk.fingerprint.PubchemFingerprinter) Fingerprinter(org.openscience.cdk.fingerprint.Fingerprinter) HybridizationFingerprinter(org.openscience.cdk.fingerprint.HybridizationFingerprinter) EStateFingerprinter(org.openscience.cdk.fingerprint.EStateFingerprinter) Random(java.util.Random) BigInteger(java.math.BigInteger) Test(org.junit.Test)

Example 4 with MoleculeReader

use of ambit2.core.processors.structure.MoleculeReader in project ambit-mirror by ideaconsult.

the class RawIteratingWrapperTest method testCSVReader.

@Test
public void testCSVReader() throws Exception {
    RawIteratingCSVReader reader = new RawIteratingCSVReader(new InputStreamReader(RawIteratingWrapperTest.class.getClassLoader().getResourceAsStream("ambit2/core/data/io/test.txt")), CSVFormat.TDF);
    MoleculeReader molreader = new MoleculeReader();
    try {
        int count = 0;
        while (reader.hasNext()) {
            IStructureRecord record = reader.nextRecord();
            if (record.getSmiles() != null && record.getInchi() != null) {
                Assert.assertNotNull(record.getContent());
                Assert.assertNotNull(record.getSmiles());
                Assert.assertNotNull(record.getInchi());
                Assert.assertNotNull(record.getInchiKey());
            }
            Object o = reader.next();
            Assert.assertNotNull(o);
            Assert.assertTrue(o instanceof IStructureRecord);
            IAtomContainer mol = molreader.process((IStructureRecord) o);
            if (record.getSmiles() != null && !"".equals(record.getSmiles()))
                Assert.assertTrue(String.format("Atoms %d", mol.getAtomCount()), mol.getAtomCount() > 0);
            count++;
        }
        Assert.assertEquals(11, count);
    } finally {
        reader.close();
    }
}
Also used : RawIteratingCSVReader(ambit2.core.io.RawIteratingCSVReader) IStructureRecord(ambit2.base.interfaces.IStructureRecord) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) InputStreamReader(java.io.InputStreamReader) MoleculeReader(ambit2.core.processors.structure.MoleculeReader) Test(org.junit.Test)

Example 5 with MoleculeReader

use of ambit2.core.processors.structure.MoleculeReader in project ambit-mirror by ideaconsult.

the class SDFReporter method getSDFContent.

protected String getSDFContent(IStructureRecord item) throws AmbitException {
    // most common case
    if (MOL_TYPE.SDF.toString().equals(item.getFormat())) {
        if (isChangeLineSeparators())
            return item.getContent().replaceAll(ux, wlinesep);
        else
            return item.getContent();
    }
    // otherwise
    if (reader == null)
        reader = new MoleculeReader();
    try {
        StringWriter w = new StringWriter();
        SDFWriter sdfwriter = new SDFWriter(w);
        IAtomContainer ac = reader.process(item);
        // ac.getProperties().clear();
        MoleculeTools.clearProperties(ac);
        sdfwriter.write(ac);
        sdfwriter.close();
        if (isChangeLineSeparators())
            return w.toString().replaceAll(ux, wlinesep);
        else
            return w.toString();
    } catch (Exception x) {
        throw new AmbitException(x);
    }
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) MoleculeReader(ambit2.core.processors.structure.MoleculeReader) StringWriter(java.io.StringWriter) SDFWriter(org.openscience.cdk.io.SDFWriter) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) DbAmbitException(net.idea.modbcum.i.exceptions.DbAmbitException) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) DbAmbitException(net.idea.modbcum.i.exceptions.DbAmbitException)

Aggregations

MoleculeReader (ambit2.core.processors.structure.MoleculeReader)21 IStructureRecord (ambit2.base.interfaces.IStructureRecord)18 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)15 Test (org.junit.Test)10 InputStreamReader (java.io.InputStreamReader)9 RawIteratingSDFReader (ambit2.core.io.RawIteratingSDFReader)8 AmbitException (net.idea.modbcum.i.exceptions.AmbitException)8 AtomConfigurator (ambit2.core.processors.structure.AtomConfigurator)6 FingerprintGenerator (ambit2.core.processors.structure.FingerprintGenerator)6 ProcessorStructureRetrieval (ambit2.db.processors.ProcessorStructureRetrieval)6 BitSet (java.util.BitSet)6 Fingerprinter (org.openscience.cdk.fingerprint.Fingerprinter)6 StructureRecord (ambit2.base.data.StructureRecord)5 IBatchStatistics (net.idea.modbcum.i.batch.IBatchStatistics)5 IProcessor (net.idea.modbcum.i.processors.IProcessor)5 IDatabaseConnection (org.dbunit.database.IDatabaseConnection)5 SDFWriter (org.openscience.cdk.io.SDFWriter)5 StringWriter (java.io.StringWriter)4 ProcessorsChain (net.idea.modbcum.i.processors.ProcessorsChain)4 InputStream (java.io.InputStream)3