Search in sources :

Example 11 with RawIteratingSDFReader

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

the class SMARTSPropertiesGeneratorTest method testAromatic.

@Test
public void testAromatic() throws Exception {
    MoleculeReader mr = new MoleculeReader();
    AtomConfigurator config = new AtomConfigurator();
    SMARTSPropertiesGenerator gen = new SMARTSPropertiesGenerator();
    RawIteratingSDFReader reader = new RawIteratingSDFReader(new InputStreamReader(getClass().getClassLoader().getResourceAsStream("benzene.sdf")));
    while (reader.hasNext()) {
        IStructureRecord record = reader.nextRecord();
        IAtomContainer c = config.process(mr.process(record));
        CDKHueckelAromaticityDetector.detectAromaticity(c);
        if (c.getAtomCount() <= 2)
            continue;
        // no SMARTSProp assigned, will be generated on the fly
        Assert.assertNull(c.getProperty(gen.getProperty()));
        testMatchAromatic(c);
        // get the record anew, and set the property
        c = mr.process(record);
        record = gen.process(record);
        Assert.assertNotNull(record.getRecordProperty(gen.getProperty()));
        c.setProperty(gen.getProperty(), record.getRecordProperty(gen.getProperty()));
        Assert.assertNotNull(c.getProperty(gen.getProperty()));
        testMatchAromatic(c);
    }
    reader.close();
}
Also used : IStructureRecord(ambit2.base.interfaces.IStructureRecord) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) MoleculeReader(ambit2.core.processors.structure.MoleculeReader) RawIteratingSDFReader(ambit2.core.io.RawIteratingSDFReader) InputStreamReader(java.io.InputStreamReader) AtomConfigurator(ambit2.core.processors.structure.AtomConfigurator) Test(org.junit.Test)

Example 12 with RawIteratingSDFReader

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

the class SMARTSPropertiesGeneratorTest method test.

@Test
public void test() throws Exception {
    MoleculeReader mr = new MoleculeReader();
    SMARTSPropertiesGenerator gen = new SMARTSPropertiesGenerator();
    RawIteratingSDFReader reader = new RawIteratingSDFReader(new InputStreamReader(getClass().getClassLoader().getResourceAsStream("test.sdf")));
    while (reader.hasNext()) {
        IStructureRecord record = reader.nextRecord();
        IAtomContainer c = mr.process(record);
        if (c.getAtomCount() <= 2)
            continue;
        // no SMARTSProp assigned, will be generated on the fly
        Assert.assertNull(c.getProperty(gen.getProperty()));
        testMatch(c);
        String[] properties = new String[] { "0110,03310503,02210503,033206050203,033206060102,02210601,02210601,043206060001,03210600,04310600,0210,03210600,03210600,044206060001,0110,044206060102,0110,03310602,0110,02210602,044206050203,0110,04410503,0110,0430,0210,0220,0110,", "0110,03310502,02210502,033206050102,033206060001,02210600,02210600,043206060003,03210603,04310603,0210,03210603,03210603,044206060003,0110,044206060001,0110,03310601,0110,02210601,044206050102,0110,04410502,0110,0430,0210,0220,0110,", "0110,03310500,02210500,033205060002,033206060102,02210601,02210601,043206060103,03210603,04310603,0210,03210603,03210603,044206060103,0110,044206060102,0110,03310602,0110,02210602,044205060002,0110,04410500,0110,0430,0210,0220,0110," };
        for (String prop : properties) {
            // get the record anew
            c = mr.process(record);
            c.removeProperty(gen.getProperty());
            c.setProperty(gen.getProperty(), prop);
            Assert.assertNotNull(c.getProperty(gen.getProperty()));
            testMatch(c);
        }
        // get the record anew
        c = mr.process(record);
        record = gen.process(record);
        Assert.assertNotNull(record.getRecordProperty(gen.getProperty()));
        c.setProperty(gen.getProperty(), record.getRecordProperty(gen.getProperty()));
        Assert.assertNotNull(c.getProperty(gen.getProperty()));
        testMatch(c);
    }
    reader.close();
}
Also used : IStructureRecord(ambit2.base.interfaces.IStructureRecord) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) MoleculeReader(ambit2.core.processors.structure.MoleculeReader) RawIteratingSDFReader(ambit2.core.io.RawIteratingSDFReader) InputStreamReader(java.io.InputStreamReader) Test(org.junit.Test)

Example 13 with RawIteratingSDFReader

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

the class StructureKeysBitSetGeneratorTest method testTriazoleKeys.

/**
 * aromatic :<{113, 852}> 113: c(c)n 852: c(cn)n sdf 8: N, 12 CC, 22 NC, 27
 * C(C)N, 71 C, 444 C(CN)N, 911 NN
 *
 * @param cleanKekuleBonds
 * @throws Exception
 */
public void testTriazoleKeys(boolean cleanKekuleBonds) throws Exception {
    MoleculeReader mr = new MoleculeReader();
    AtomConfigurator config = new AtomConfigurator();
    RawIteratingSDFReader reader = new RawIteratingSDFReader(new InputStreamReader(getClass().getClassLoader().getResourceAsStream("triazole.sdf")));
    BitSet bitsetKekule = null;
    StructureKeysBitSetGenerator bitsetGenerator = new StructureKeysBitSetGenerator();
    bitsetGenerator.setCleanKekuleBonds(cleanKekuleBonds);
    while (reader.hasNext()) {
        IStructureRecord record = reader.nextRecord();
        IAtomContainer c = config.process(mr.process(record));
        // CDKHueckelAromaticityDetector.detectAromaticity(c);
        bitsetKekule = bitsetGenerator.process(c);
        logger.fine(bitsetKekule.toString());
    }
    reader.close();
    SmilesParser parser = new SmilesParser(SilentChemObjectBuilder.getInstance());
    IAtomContainer mol = parser.parseSmiles("c1cnn[nH]1");
    for (IBond b : mol.bonds()) logger.fine(Boolean.toString(b.getFlag(CDKConstants.ISAROMATIC)));
    mol = config.process(mol);
    // CDKHueckelAromaticityDetector.detectAromaticity(mol);
    for (IBond b : mol.bonds()) logger.fine(Boolean.toString(b.getFlag(CDKConstants.ISAROMATIC)));
    BitSet bitsetAromatic = bitsetGenerator.process(mol);
    logger.fine(bitsetAromatic.toString());
    Assert.assertEquals(bitsetKekule, bitsetAromatic);
    parser = new SmilesParser(SilentChemObjectBuilder.getInstance());
    mol = parser.parseSmiles("C1=CN=NN1");
    for (IBond b : mol.bonds()) logger.fine(Boolean.toString(b.getFlag(CDKConstants.ISAROMATIC)));
    mol = config.process(mol);
    // CDKHueckelAromaticityDetector.detectAromaticity(mol);
    for (IBond b : mol.bonds()) logger.fine(Boolean.toString(b.getFlag(CDKConstants.ISAROMATIC)));
    BitSet bitsetKekuleSMILES = bitsetGenerator.process(mol);
    logger.fine(bitsetKekuleSMILES.toString());
    Assert.assertEquals(bitsetKekule, bitsetKekuleSMILES);
}
Also used : SmilesParser(org.openscience.cdk.smiles.SmilesParser) IStructureRecord(ambit2.base.interfaces.IStructureRecord) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) MoleculeReader(ambit2.core.processors.structure.MoleculeReader) RawIteratingSDFReader(ambit2.core.io.RawIteratingSDFReader) InputStreamReader(java.io.InputStreamReader) BitSet(java.util.BitSet) IBond(org.openscience.cdk.interfaces.IBond) AtomConfigurator(ambit2.core.processors.structure.AtomConfigurator)

Example 14 with RawIteratingSDFReader

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

the class StructureKeysBitSetGeneratorTest method testBiphenylKeys.

public void testBiphenylKeys(boolean cleanKekuleBonds) throws Exception {
    MoleculeReader mr = new MoleculeReader();
    AtomConfigurator config = new AtomConfigurator();
    RawIteratingSDFReader reader = new RawIteratingSDFReader(new InputStreamReader(getClass().getClassLoader().getResourceAsStream("biphenyl.sdf")));
    BitSet bitsetKekule = null;
    StructureKeysBitSetGenerator bitsetGenerator = new StructureKeysBitSetGenerator();
    bitsetGenerator.setCleanKekuleBonds(cleanKekuleBonds);
    while (reader.hasNext()) {
        IStructureRecord record = reader.nextRecord();
        IAtomContainer c = config.process(mr.process(record));
        bitsetKekule = bitsetGenerator.process(c);
    }
    reader.close();
    SmilesParser parser = new SmilesParser(SilentChemObjectBuilder.getInstance());
    IAtomContainer mol = parser.parseSmiles("c1ccccc1c2ccccc2");
    BitSet bitsetAromatic = bitsetGenerator.process(mol);
    Assert.assertEquals(bitsetKekule, bitsetAromatic);
}
Also used : SmilesParser(org.openscience.cdk.smiles.SmilesParser) IStructureRecord(ambit2.base.interfaces.IStructureRecord) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) MoleculeReader(ambit2.core.processors.structure.MoleculeReader) RawIteratingSDFReader(ambit2.core.io.RawIteratingSDFReader) InputStreamReader(java.io.InputStreamReader) BitSet(java.util.BitSet) AtomConfigurator(ambit2.core.processors.structure.AtomConfigurator)

Example 15 with RawIteratingSDFReader

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

the class FingerPrintGeneratorTest method testPolyAromatics.

@Test
public void testPolyAromatics() throws Exception {
    MoleculeReader molreader = new MoleculeReader();
    FingerprintGenerator gen = new FingerprintGenerator(new Fingerprinter());
    InputStream in = FingerPrintGeneratorTest.class.getClassLoader().getResourceAsStream("ambit2/core/data/fp/polyaromatics.sdf");
    RawIteratingSDFReader reader = new RawIteratingSDFReader(new InputStreamReader(in));
    while (reader.hasNext()) {
        IStructureRecord record = reader.nextRecord();
        IAtomContainer mol = molreader.process(record);
        AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol);
        CDKHydrogenAdder.getInstance(SilentChemObjectBuilder.getInstance()).addImplicitHydrogens(mol);
        CDKHueckelAromaticityDetector.detectAromaticity(mol);
        gen.setHydrogens(false);
        mol = AtomContainerManipulator.removeHydrogensPreserveMultiplyBonded(mol);
        BitSet bs1 = gen.process(mol);
        System.out.println(bs1);
        ExtendedFingerprinter efp = new ExtendedFingerprinter();
        System.out.println(efp.getClass().getName());
        System.out.println(efp.getBitFingerprint(mol).asBitSet());
        PubchemFingerprinter pfp = new PubchemFingerprinter(SilentChemObjectBuilder.getInstance());
        System.out.println(pfp.getClass().getName());
        System.out.println(pfp.getBitFingerprint(mol).asBitSet());
        EStateFingerprinter esfp = new EStateFingerprinter();
        System.out.println(esfp.getClass().getName());
        System.out.println(esfp.getBitFingerprint(mol).asBitSet());
        MACCSFingerprinter mfp = new MACCSFingerprinter();
        System.out.println(mfp.getClass().getName());
        System.out.println(mfp.getBitFingerprint(mol).asBitSet());
        SubstructureFingerprinter sfp = new SubstructureFingerprinter();
        System.out.println(sfp.getClass().getName());
        System.out.println(sfp.getBitFingerprint(mol).asBitSet());
        HybridizationFingerprinter hfp = new HybridizationFingerprinter();
        System.out.println(hfp.getClass().getName());
        System.out.println(hfp.getBitFingerprint(mol).asBitSet());
    /*
			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)
		*/
    reader.close();
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) RawIteratingSDFReader(ambit2.core.io.RawIteratingSDFReader) InputStreamReader(java.io.InputStreamReader) PubchemFingerprinter(org.openscience.cdk.fingerprint.PubchemFingerprinter) InputStream(java.io.InputStream) BitSet(java.util.BitSet) SubstructureFingerprinter(org.openscience.cdk.fingerprint.SubstructureFingerprinter) FingerprintGenerator(ambit2.core.processors.structure.FingerprintGenerator) EStateFingerprinter(org.openscience.cdk.fingerprint.EStateFingerprinter) IStructureRecord(ambit2.base.interfaces.IStructureRecord) HybridizationFingerprinter(org.openscience.cdk.fingerprint.HybridizationFingerprinter) ExtendedFingerprinter(org.openscience.cdk.fingerprint.ExtendedFingerprinter) 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) MACCSFingerprinter(org.openscience.cdk.fingerprint.MACCSFingerprinter) Test(org.junit.Test)

Aggregations

RawIteratingSDFReader (ambit2.core.io.RawIteratingSDFReader)30 InputStreamReader (java.io.InputStreamReader)26 Test (org.junit.Test)21 IStructureRecord (ambit2.base.interfaces.IStructureRecord)19 InputStream (java.io.InputStream)18 IDatabaseConnection (org.dbunit.database.IDatabaseConnection)13 ITable (org.dbunit.dataset.ITable)12 MoleculeReader (ambit2.core.processors.structure.MoleculeReader)7 FileReader (java.io.FileReader)6 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)6 File (java.io.File)5 IIteratingChemObjectReader (org.openscience.cdk.io.iterator.IIteratingChemObjectReader)5 IOException (java.io.IOException)4 AmbitException (net.idea.modbcum.i.exceptions.AmbitException)4 AtomConfigurator (ambit2.core.processors.structure.AtomConfigurator)3 BitSet (java.util.BitSet)3 GZIPInputStream (java.util.zip.GZIPInputStream)3 Property (ambit2.base.data.Property)2 StructureRecord (ambit2.base.data.StructureRecord)2 IteratingDelimitedFileReader (ambit2.core.io.IteratingDelimitedFileReader)2