Search in sources :

Example 1 with CircularFingerprinter

use of org.openscience.cdk.fingerprint.CircularFingerprinter in project ambit-mirror by ideaconsult.

the class FingerprinterTest method test_fp.

@Test
public void test_fp() throws Exception {
    String[] smiles = new String[] { "O(CC(NCC1=C(C=C(C=C1)C)C)C)C", "O(CC(NCC=1C(=CC(=CC1)C)C)C)C" };
    SmilesParser p = new SmilesParser(SilentChemObjectBuilder.getInstance());
    SmilesGenerator absolute_aromatic = SmilesGenerator.absolute().aromatic();
    SmilesGenerator isomeric_aromatic = SmilesGenerator.isomeric().aromatic();
    CircularFingerprinter fp = new CircularFingerprinter();
    BitSet[] bs = new BitSet[] { null, null };
    for (int i = 0; i < smiles.length; i++) {
        IAtomContainer mol = p.parseSmiles(smiles[i]);
        // AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol);
        // CDKHueckelAromaticityDetector.detectAromaticity(mol);
        IBitFingerprint cf = fp.getBitFingerprint(mol);
        bs[i] = cf.asBitSet();
        String newsmiles = absolute_aromatic.create(mol);
        Assert.assertEquals(1.0f, Tanimoto.calculate(bs[i], fp.getBitFingerprint(p.parseSmiles(newsmiles)).asBitSet()));
        String newsmiles_i = isomeric_aromatic.create(mol);
        Assert.assertEquals(1.0f, Tanimoto.calculate(bs[i], fp.getBitFingerprint(p.parseSmiles(newsmiles_i)).asBitSet()));
    }
    Assert.assertEquals(1.0f, Tanimoto.calculate(bs[0], bs[1]));
}
Also used : SmilesParser(org.openscience.cdk.smiles.SmilesParser) IBitFingerprint(org.openscience.cdk.fingerprint.IBitFingerprint) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) BitSet(java.util.BitSet) CircularFingerprinter(org.openscience.cdk.fingerprint.CircularFingerprinter) SmilesGenerator(org.openscience.cdk.smiles.SmilesGenerator) IBitFingerprint(org.openscience.cdk.fingerprint.IBitFingerprint) Test(org.junit.Test)

Example 2 with CircularFingerprinter

use of org.openscience.cdk.fingerprint.CircularFingerprinter in project ambit-mirror by ideaconsult.

the class Context method parseFingerprinterParams.

protected List<IFingerprinter> parseFingerprinterParams() {
    final List<IFingerprinter> fps = new ArrayList<IFingerprinter>();
    int fplen = 1024;
    int fptype = CircularFingerprinter.CLASS_ECFP6;
    try {
        Object o = options.getParam(":fplen");
        try {
            if (o != null)
                fplen = Integer.parseInt(o.toString());
        } catch (Exception x) {
        }
        o = options.getParam(":fptype");
        try {
            if (o != null)
                fptype = _fptype.valueOf(o.toString()).getCode();
        } catch (Exception x) {
        }
        o = options.getParam(":fpclass");
        if (o != null) {
            String[] fpclass = o.toString().split(",");
            Class clazz = null;
            for (String fp : fpclass) try {
                if (fp.indexOf(".") < 0)
                    fp = "org.openscience.cdk.fingerprint." + fp.trim();
                else
                    fp = fp.trim();
                clazz = Class.forName(fp);
                Object fingerprinter = null;
                if (clazz.equals(CircularFingerprinter.class)) {
                    fingerprinter = new CircularFingerprinter(fptype, fplen);
                } else {
                    fingerprinter = clazz.newInstance();
                }
                if (fingerprinter instanceof IFingerprinter)
                    fps.add((IFingerprinter) fingerprinter);
            } catch (Exception x) {
                if (clazz != null)
                    try {
                        Object fingerprinter = clazz.getDeclaredConstructor(IChemObjectBuilder.class).newInstance(SilentChemObjectBuilder.getInstance());
                        if (fingerprinter instanceof IFingerprinter)
                            fps.add((IFingerprinter) fingerprinter);
                    } catch (Exception xx) {
                        logger_cli.log(Level.SEVERE, "MSG_ERR_CLASS", new Object[] { fp, x.toString() });
                    }
            }
        }
    } catch (Exception x) {
    }
    if (fps.size() == 0) {
        fps.add(new org.openscience.cdk.fingerprint.CircularFingerprinter(fptype, fplen));
    // fps.add(new AtomEnvironentMatrix());
    }
    StringBuilder b = new StringBuilder();
    for (IFingerprinter fp : fps) {
        b.append("\n");
        b.append(fp.getClass().getName());
    }
    logger_cli.log(Level.INFO, "MSG_FP", new Object[] { b.toString() });
    return fps;
}
Also used : ArrayList(java.util.ArrayList) IFingerprinter(org.openscience.cdk.fingerprint.IFingerprinter) CircularFingerprinter(org.openscience.cdk.fingerprint.CircularFingerprinter) ICountFingerprint(org.openscience.cdk.fingerprint.ICountFingerprint) IBitFingerprint(org.openscience.cdk.fingerprint.IBitFingerprint) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) SQLException(java.sql.SQLException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) OperationNotSupportedException(javax.naming.OperationNotSupportedException) FileNotFoundException(java.io.FileNotFoundException) CircularFingerprinter(org.openscience.cdk.fingerprint.CircularFingerprinter)

Example 3 with CircularFingerprinter

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

the class Bayesian method addMolecule.

/**
 * Appends a new row to the model source data, which consists of a molecule and whether or not it
 * is considered active.
 *
 * @param mol molecular structure, which must be non-blank
 * @param active whether active or not
 */
public void addMolecule(IAtomContainer mol, boolean active) throws CDKException {
    if (mol == null || mol.getAtomCount() == 0)
        throw new CDKException("Molecule cannot be blank or null.");
    CircularFingerprinter circ = new CircularFingerprinter(classType);
    circ.setPerceiveStereo(optPerceiveStereo);
    circ.calculate(mol);
    // gather all of the (folded) fingerprints into a sorted set
    // e.g. 1024/0x400 -> 1023/0x3FF: chop off higher order bits
    final int AND_BITS = folding - 1;
    Set<Integer> hashset = new TreeSet<>();
    for (int n = circ.getFPCount() - 1; n >= 0; n--) {
        int code = circ.getFP(n).hashCode;
        if (folding > 0)
            code &= AND_BITS;
        hashset.add(code);
    }
    // convert the set into a sorted primitive array
    int[] hashes = new int[hashset.size()];
    int p = 0;
    for (Integer h : hashset) hashes[p++] = h;
    // record the processed information for model building purposes
    if (active)
        numActive++;
    training.add(hashes);
    activity.add(active);
    for (int h : hashes) {
        int[] stash = inHash.get(h);
        if (stash == null)
            stash = new int[] { 0, 0 };
        if (active)
            stash[0]++;
        stash[1]++;
        inHash.put(h, stash);
    }
}
Also used : CDKException(org.openscience.cdk.exception.CDKException) TreeSet(java.util.TreeSet) CircularFingerprinter(org.openscience.cdk.fingerprint.CircularFingerprinter)

Example 4 with CircularFingerprinter

use of org.openscience.cdk.fingerprint.CircularFingerprinter in project ambit-mirror by ideaconsult.

the class InchiProcessorTest method testInChI_pubchem.

@Test
public void testInChI_pubchem() throws Exception {
    InChIGeneratorFactory f = InChIGeneratorFactory.getInstance();
    InChIToStructure c = f.getInChIToStructure("InChI=1/C34H34N4O4/c1-7-21-17(3)25-13-26-19(5)23(9-11-33(39)40)31(37-26)16-32-24(10-12-34(41)42)20(6)28(38-32)15-30-22(8-2)18(4)27(36-30)14-29(21)35-25/h7-8,13-16H,1-2,9-12H2,3-6H3,(H4,35,36,37,38,39,40,41,42)/p-2/fC34H32N4O4/h39,41H/q-2", SilentChemObjectBuilder.getInstance());
    System.out.println(c.getLog());
    System.out.println(c.getWarningFlags());
    IAtomContainer a = c.getAtomContainer();
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(a);
    CDKHueckelAromaticityDetector.detectAromaticity(a);
    SmilesGenerator absolute_aromatic = SmilesGenerator.absolute().aromatic();
    SmilesGenerator isomeric_aromatic = SmilesGenerator.isomeric().aromatic();
    CircularFingerprinter fp = new CircularFingerprinter();
    IBitFingerprint cf_inchi = fp.getBitFingerprint(a);
    System.out.println(cf_inchi.asBitSet());
    String[] smiles = new String[] { "C=CC1=C(C)C2=NC1=CC3=C(C)C(=C(C=C4C(=C(CCC(=O)O)C(=N4)C=C5C(=C(C)C(=C2)[N-]5)CCC(=O)O)C)[N-]3)C=C", "C=CC1=C(C)C2=NC1=CC3=NC(=CC4=C(C)C(=C(C=C5C(=C(C)C(=C2)[N-]5)CCC(=O)O)[N-]4)CCC(=O)O)C(=C3C)C=C", "C=CC1=C2C=C3C(=C(C=C)C(=N3)C=C4C(=C(CCC(=O)O)C(=CC5=NC(=CC(=C1C)[N-]2)C(=C5CCC(=O)O)C)[N-]4)C)C" };
    String aromatic_smiles_a = absolute_aromatic.create(a);
    System.out.println(aromatic_smiles_a);
    String aromatic_smiles_i = isomeric_aromatic.create(a);
    System.out.println(aromatic_smiles_i);
    System.out.println();
    SmilesParser p = new SmilesParser(SilentChemObjectBuilder.getInstance());
    for (String smi : smiles) {
        IAtomContainer mol = p.parseSmiles(smi);
        AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol);
        CDKHueckelAromaticityDetector.detectAromaticity(mol);
        IBitFingerprint cf = fp.getBitFingerprint(mol);
        System.out.println(cf.asBitSet());
        String newsmiles = absolute_aromatic.create(mol);
        System.out.println(newsmiles);
        String newsmiles_i = isomeric_aromatic.create(mol);
        System.out.println(newsmiles_i);
        System.out.print(String.format("%s\t%s\t%s\t", Tanimoto.calculate(cf.asBitSet(), cf_inchi.asBitSet()), cf.asBitSet().cardinality(), cf_inchi.asBitSet().cardinality()));
        cf.asBitSet().and(cf_inchi.asBitSet());
        System.out.println(cf.cardinality());
        System.out.println();
    }
}
Also used : SmilesParser(org.openscience.cdk.smiles.SmilesParser) IBitFingerprint(org.openscience.cdk.fingerprint.IBitFingerprint) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) InChIToStructure(org.openscience.cdk.inchi.InChIToStructure) CircularFingerprinter(org.openscience.cdk.fingerprint.CircularFingerprinter) InChIGeneratorFactory(org.openscience.cdk.inchi.InChIGeneratorFactory) SmilesGenerator(org.openscience.cdk.smiles.SmilesGenerator) Test(org.junit.Test)

Example 5 with CircularFingerprinter

use of org.openscience.cdk.fingerprint.CircularFingerprinter in project ambit-mirror by ideaconsult.

the class TestDescriptors method testCircularFingerprints.

@Test
public void testCircularFingerprints() throws Exception {
    CircularFingerprinter f = new CircularFingerprinter();
    IAtomContainer mol = MoleculeFactory.makeBenzene();
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol);
    ICountFingerprint r = f.getCountFingerprint(mol);
    System.out.println(r.numOfPopulatedbins());
    System.out.println(r.size());
    for (int i = 0; i < r.numOfPopulatedbins(); i++) {
        System.out.print(r.getHash(i));
        System.out.print("\t");
        System.out.println(r.getCount(i));
    }
}
Also used : ICountFingerprint(org.openscience.cdk.fingerprint.ICountFingerprint) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) CircularFingerprinter(org.openscience.cdk.fingerprint.CircularFingerprinter) ICountFingerprint(org.openscience.cdk.fingerprint.ICountFingerprint) Test(org.junit.Test)

Aggregations

CircularFingerprinter (org.openscience.cdk.fingerprint.CircularFingerprinter)7 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)4 Test (org.junit.Test)3 CDKException (org.openscience.cdk.exception.CDKException)3 IBitFingerprint (org.openscience.cdk.fingerprint.IBitFingerprint)3 SmilesGenerator (org.openscience.cdk.smiles.SmilesGenerator)3 BitSet (java.util.BitSet)2 ICountFingerprint (org.openscience.cdk.fingerprint.ICountFingerprint)2 SmilesParser (org.openscience.cdk.smiles.SmilesParser)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ConnectException (java.net.ConnectException)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 TreeSet (java.util.TreeSet)1 OperationNotSupportedException (javax.naming.OperationNotSupportedException)1 AmbitException (net.idea.modbcum.i.exceptions.AmbitException)1 IFingerprinter (org.openscience.cdk.fingerprint.IFingerprinter)1