Search in sources :

Example 1 with SignatureFingerprinter

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

the class SignatureFingerprintTanimotoTest method testCountMethod1and2.

@Test
public void testCountMethod1and2() throws CDKException {
    ICountFingerprint fp1 = new IntArrayCountFingerprint(new HashMap<String, Integer>() {

        {
            put("A", 3);
        }
    });
    ICountFingerprint fp2 = new IntArrayCountFingerprint(new HashMap<String, Integer>() {

        {
            put("A", 4);
        }
    });
    Assert.assertEquals(0.923, Tanimoto.method1(fp1, fp2), 0.001);
    Assert.assertEquals(0.75, Tanimoto.method2(fp1, fp2), 0.001);
    IAtomContainer mol1 = TestMoleculeFactory.makeIndole();
    IAtomContainer mol2 = TestMoleculeFactory.makeIndole();
    SignatureFingerprinter fingerprinter = new SignatureFingerprinter();
    fp1 = fingerprinter.getCountFingerprint(mol1);
    fp2 = fingerprinter.getCountFingerprint(mol2);
    Assert.assertEquals(1.0, Tanimoto.method1(fp1, fp2), 0.001);
    Assert.assertEquals(1.0, Tanimoto.method2(fp1, fp2), 0.001);
}
Also used : ICountFingerprint(org.openscience.cdk.fingerprint.ICountFingerprint) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) SignatureFingerprinter(org.openscience.cdk.fingerprint.SignatureFingerprinter) IntArrayCountFingerprint(org.openscience.cdk.fingerprint.IntArrayCountFingerprint) Test(org.junit.Test)

Example 2 with SignatureFingerprinter

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

the class SignatureFingerprintTanimotoTest method testComparingBitFingerprintAndCountBehavingAsBit.

@Test
public void testComparingBitFingerprintAndCountBehavingAsBit() throws Exception {
    IAtomContainer mol1 = TestMoleculeFactory.make123Triazole();
    IAtomContainer mol2 = TestMoleculeFactory.makeImidazole();
    SignatureFingerprinter fingerprinter = new SignatureFingerprinter(1);
    ICountFingerprint countFp1 = fingerprinter.getCountFingerprint(mol1);
    ICountFingerprint countFp2 = fingerprinter.getCountFingerprint(mol2);
    countFp1.setBehaveAsBitFingerprint(true);
    countFp2.setBehaveAsBitFingerprint(true);
    IBitFingerprint bitFp1 = fingerprinter.getBitFingerprint(mol1);
    IBitFingerprint bitFp2 = fingerprinter.getBitFingerprint(mol2);
    double bitTanimoto = Tanimoto.calculate(bitFp1, bitFp2);
    double countTanimoto1 = Tanimoto.method1(countFp1, countFp2);
    double countTanimoto2 = Tanimoto.method2(countFp1, countFp2);
    Assert.assertEquals(countTanimoto1, countTanimoto2, 0.001);
    Assert.assertEquals(bitTanimoto, countTanimoto1, 0.001);
}
Also used : ICountFingerprint(org.openscience.cdk.fingerprint.ICountFingerprint) IBitFingerprint(org.openscience.cdk.fingerprint.IBitFingerprint) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) SignatureFingerprinter(org.openscience.cdk.fingerprint.SignatureFingerprinter) Test(org.junit.Test)

Example 3 with SignatureFingerprinter

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

the class SignatureFingerprintTanimotoTest method testRawTanimotoBetween0and1.

/**
 * @throws Exception
 * @cdk.bug 3310138
 */
@Test
public void testRawTanimotoBetween0and1() throws Exception {
    SmilesParser smilesParser = new SmilesParser(SilentChemObjectBuilder.getInstance());
    IAtomContainer mol1 = smilesParser.parseSmiles("Cc1nc(C(=O)NC23CC4CC(CC(C4)C2)C3)c(C)n1C5CCCCC5");
    IAtomContainer mol2 = smilesParser.parseSmiles("CS(=O)(=O)Nc1ccc(Cc2onc(n2)c3ccc(cc3)S(=O)(=O)Nc4ccc(CCNC[C@H](O)c5cccnc5)cc4)cc1");
    SignatureFingerprinter fingerprinter = new SignatureFingerprinter(0);
    Map<String, Integer> fp1 = fingerprinter.getRawFingerprint(mol1);
    Map<String, Integer> fp2 = fingerprinter.getRawFingerprint(mol2);
    float tanimoto = Tanimoto.calculate(fp1, fp2);
    Assert.assertTrue("Tanimoto expected to be between 0 and 1, was:" + tanimoto, tanimoto > 0 && tanimoto < 1);
}
Also used : SmilesParser(org.openscience.cdk.smiles.SmilesParser) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) SignatureFingerprinter(org.openscience.cdk.fingerprint.SignatureFingerprinter) Test(org.junit.Test)

Example 4 with SignatureFingerprinter

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

the class SignatureFingerprintTanimotoTest method testICountFingerprintComparison.

@Test
public void testICountFingerprintComparison() throws Exception {
    IAtomContainer mol1 = TestMoleculeFactory.makeIndole();
    IAtomContainer mol2 = TestMoleculeFactory.makeIndole();
    SignatureFingerprinter fingerprinter = new SignatureFingerprinter();
    ICountFingerprint fp1 = fingerprinter.getCountFingerprint(mol1);
    ICountFingerprint fp2 = fingerprinter.getCountFingerprint(mol2);
    double tanimoto = Tanimoto.calculate(fp1, fp2);
    Assert.assertEquals(1.0, tanimoto, 0.001);
}
Also used : ICountFingerprint(org.openscience.cdk.fingerprint.ICountFingerprint) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) SignatureFingerprinter(org.openscience.cdk.fingerprint.SignatureFingerprinter) Test(org.junit.Test)

Example 5 with SignatureFingerprinter

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

the class SignatureFingerprintTanimotoTest method compareCountFingerprintAndRawFingerprintTanimoto.

@Test
public void compareCountFingerprintAndRawFingerprintTanimoto() throws CDKException {
    IAtomContainer mol1 = TestMoleculeFactory.make123Triazole();
    IAtomContainer mol2 = TestMoleculeFactory.makeImidazole();
    SignatureFingerprinter fingerprinter = new SignatureFingerprinter(1);
    ICountFingerprint countFp1 = fingerprinter.getCountFingerprint(mol1);
    ICountFingerprint countFp2 = fingerprinter.getCountFingerprint(mol2);
    Map<String, Integer> feat1 = fingerprinter.getRawFingerprint(mol1);
    Map<String, Integer> feat2 = fingerprinter.getRawFingerprint(mol2);
    float rawTanimoto = Tanimoto.calculate(feat1, feat2);
    double countTanimoto = Tanimoto.method1(countFp1, countFp2);
    Assert.assertEquals(rawTanimoto, countTanimoto, 0.001);
}
Also used : ICountFingerprint(org.openscience.cdk.fingerprint.ICountFingerprint) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) SignatureFingerprinter(org.openscience.cdk.fingerprint.SignatureFingerprinter) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)5 SignatureFingerprinter (org.openscience.cdk.fingerprint.SignatureFingerprinter)5 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)5 ICountFingerprint (org.openscience.cdk.fingerprint.ICountFingerprint)4 IBitFingerprint (org.openscience.cdk.fingerprint.IBitFingerprint)1 IntArrayCountFingerprint (org.openscience.cdk.fingerprint.IntArrayCountFingerprint)1 SmilesParser (org.openscience.cdk.smiles.SmilesParser)1