Search in sources :

Example 1 with HybridizationFingerprinter

use of org.openscience.cdk.fingerprint.HybridizationFingerprinter 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)

Example 2 with HybridizationFingerprinter

use of org.openscience.cdk.fingerprint.HybridizationFingerprinter in project cdk by cdk.

the class TemplateExtractor method makeFingerprintsFromSdf.

public List<IBitFingerprint> makeFingerprintsFromSdf(boolean anyAtom, boolean anyAtomAnyBond, Map<String, Integer> timings, BufferedReader fin, int limit) throws Exception {
    HybridizationFingerprinter fingerPrinter = new HybridizationFingerprinter(HybridizationFingerprinter.DEFAULT_SIZE, HybridizationFingerprinter.DEFAULT_SEARCH_DEPTH);
    fingerPrinter.setHashPseudoAtoms(true);
    IAtomContainer m;
    IteratingSDFReader imdl = null;
    // QueryAtomContainer query=null;
    IAtomContainer query;
    List<IBitFingerprint> data = new ArrayList<>();
    ILoggingTool logger = LoggingToolFactory.createLoggingTool(getClass());
    try {
        logger.info("Read data file in ...");
        imdl = new IteratingSDFReader(fin, builder);
        // fin.close();
        logger.info("ready");
    } catch (Exception exc) {
        System.out.println("Could not read Molecules from file" + " due to: " + exc.getMessage());
    }
    int moleculeCounter = 0;
    int fingerprintCounter = 0;
    logger.info("Generated Fingerprints: " + fingerprintCounter + "    ");
    while (imdl.hasNext() && (moleculeCounter < limit || limit == -1)) {
        m = imdl.next();
        moleculeCounter++;
        if (anyAtom && !anyAtomAnyBond) {
            query = QueryAtomContainerCreator.createAnyAtomContainer(m, false);
        } else {
            query = AtomContainerManipulator.anonymise(m);
        }
        try {
            long time = -System.currentTimeMillis();
            // query fp for anyAtom is probably not useful
            data.add(fingerPrinter.getBitFingerprint(query));
            fingerprintCounter = fingerprintCounter + 1;
            time += System.currentTimeMillis();
            // store the time
            String bin = Integer.toString((int) Math.floor(time / 10.0));
            if (timings.containsKey(bin)) {
                timings.put(bin, (timings.get(bin)) + 1);
            } else {
                timings.put(bin, 1);
            }
        } catch (Exception exc1) {
            logger.info("QueryFingerprintError: from molecule:" + moleculeCounter + " due to:" + exc1.getMessage());
            // OK, just adds a fingerprint with all ones, so that any
            // structure will match this template, and leave it up
            // to substructure match to figure things out
            IBitFingerprint allOnesFingerprint = new BitSetFingerprint(fingerPrinter.getSize());
            for (int i = 0; i < fingerPrinter.getSize(); i++) {
                allOnesFingerprint.set(i, true);
            }
            data.add(allOnesFingerprint);
            fingerprintCounter = fingerprintCounter + 1;
        }
        if (fingerprintCounter % 2 == 0)
            logger.info("\b" + "/");
        else
            logger.info("\b" + "\\");
        if (fingerprintCounter % 100 == 0)
            logger.info("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b" + "Generated Fingerprints: " + fingerprintCounter + "   \n");
    }
    // while
    try {
        imdl.close();
    } catch (Exception exc2) {
        LoggingToolFactory.createLoggingTool(TemplateExtractor.class).warn("Unexpected Exception:", exc2);
    }
    logger.info("...ready with:" + moleculeCounter + " molecules\nWrite data...of data vector:" + data.size() + " fingerprintCounter:" + fingerprintCounter);
    return data;
}
Also used : HybridizationFingerprinter(org.openscience.cdk.fingerprint.HybridizationFingerprinter) IBitFingerprint(org.openscience.cdk.fingerprint.IBitFingerprint) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) ILoggingTool(org.openscience.cdk.tools.ILoggingTool) BitSetFingerprint(org.openscience.cdk.fingerprint.BitSetFingerprint) ArrayList(java.util.ArrayList) IteratingSDFReader(org.openscience.cdk.io.iterator.IteratingSDFReader) CDKException(org.openscience.cdk.exception.CDKException) IOException(java.io.IOException) BitSetFingerprint(org.openscience.cdk.fingerprint.BitSetFingerprint) IBitFingerprint(org.openscience.cdk.fingerprint.IBitFingerprint)

Aggregations

HybridizationFingerprinter (org.openscience.cdk.fingerprint.HybridizationFingerprinter)2 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)2 IStructureRecord (ambit2.base.interfaces.IStructureRecord)1 RawIteratingSDFReader (ambit2.core.io.RawIteratingSDFReader)1 FingerprintGenerator (ambit2.core.processors.structure.FingerprintGenerator)1 MoleculeReader (ambit2.core.processors.structure.MoleculeReader)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 ArrayList (java.util.ArrayList)1 BitSet (java.util.BitSet)1 Test (org.junit.Test)1 CDKException (org.openscience.cdk.exception.CDKException)1 BitSetFingerprint (org.openscience.cdk.fingerprint.BitSetFingerprint)1 EStateFingerprinter (org.openscience.cdk.fingerprint.EStateFingerprinter)1 ExtendedFingerprinter (org.openscience.cdk.fingerprint.ExtendedFingerprinter)1 Fingerprinter (org.openscience.cdk.fingerprint.Fingerprinter)1 IBitFingerprint (org.openscience.cdk.fingerprint.IBitFingerprint)1 MACCSFingerprinter (org.openscience.cdk.fingerprint.MACCSFingerprinter)1 PubchemFingerprinter (org.openscience.cdk.fingerprint.PubchemFingerprinter)1