Tanimoto { public static float calculate(BitSet bitset1, BitSet bitset2) throws CDKException { float _bitset1_cardinality = bitset1.cardinality(); float _bitset2_cardinality = bitset2.cardinality(); if (bitset1.size() != bitset2.size()) { throw new CDKException("Bitsets must have the same bit length"); } BitSet one_and_two = (BitSet) bitset1.clone(); one_and_two.and(bitset2); float _common_bit_count = one_and_two.cardinality(); return _common_bit_count / (_bitset1_cardinality + _bitset2_cardinality - _common_bit_count); } private  Tanimoto(); static float calculate(BitSet bitset1, BitSet bitset2); static double calculate(IBitFingerprint fingerprint1, IBitFingerprint fingerprint2); static float calculate(double[] features1, double[] features2); static float calculate(Map<String, Integer> features1, Map<String, Integer> features2); static double calculate(ICountFingerprint fp1, ICountFingerprint fp2); static double method1(ICountFingerprint fp1, ICountFingerprint fp2); static double method2(ICountFingerprint fp1, ICountFingerprint fp2);  }
@Test public void testTanimoto1() throws java.lang.Exception { IAtomContainer mol1 = TestMoleculeFactory.makeIndole(); IAtomContainer mol2 = TestMoleculeFactory.makePyrrole(); Fingerprinter fingerprinter = new Fingerprinter(1024, 8); BitSet bs1 = fingerprinter.getBitFingerprint(mol1).asBitSet(); BitSet bs2 = fingerprinter.getBitFingerprint(mol2).asBitSet(); float tanimoto = Tanimoto.calculate(bs1, bs2); if (standAlone) System.out.println("Tanimoto: " + tanimoto); if (!standAlone) Assert.assertEquals(0.3939, tanimoto, 0.01); }
@Test public void testTanimoto2() throws java.lang.Exception { IAtomContainer mol1 = TestMoleculeFactory.makeIndole(); IAtomContainer mol2 = TestMoleculeFactory.makeIndole(); Fingerprinter fingerprinter = new Fingerprinter(); BitSet bs1 = fingerprinter.getBitFingerprint(mol1).asBitSet(); BitSet bs2 = fingerprinter.getBitFingerprint(mol2).asBitSet(); float tanimoto = Tanimoto.calculate(bs1, bs2); if (standAlone) System.out.println("Tanimoto: " + tanimoto); if (!standAlone) Assert.assertEquals(1.0, tanimoto, 0.001); }
@Test public void testCalculate_BitFingerprint() throws java.lang.Exception { IAtomContainer mol1 = TestMoleculeFactory.makeIndole(); IAtomContainer mol2 = TestMoleculeFactory.makePyrrole(); Fingerprinter fp = new Fingerprinter(1024, 8); double similarity = Tanimoto.calculate(fp.getBitFingerprint(mol1), fp.getBitFingerprint(mol2)); Assert.assertEquals(0.3939, similarity, 0.01); }
@Test public void testExactMatch() throws Exception { IAtomContainer mol1 = TestMoleculeFactory.makeIndole(); IAtomContainer mol2 = TestMoleculeFactory.makeIndole(); addImplicitHydrogens(mol1); addImplicitHydrogens(mol2); LingoFingerprinter fingerprinter = new LingoFingerprinter(); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol1); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol2); Map<String, Integer> feat1 = fingerprinter.getRawFingerprint(mol1); Map<String, Integer> feat2 = fingerprinter.getRawFingerprint(mol2); float tanimoto = Tanimoto.calculate(feat1, feat2); Assert.assertEquals(1.0, tanimoto, 0.001); }
@Test public void testTanimoto3() throws java.lang.Exception { double[] f1 = {1, 2, 3, 4, 5, 6, 7}; double[] f2 = {1, 2, 3, 4, 5, 6, 7}; float tanimoto = Tanimoto.calculate(f1, f2); if (standAlone) System.out.println("Tanimoto: " + tanimoto); if (!standAlone) Assert.assertEquals(1.0, tanimoto, 0.001); }
@Test public void keggR00258() throws java.lang.Exception { SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance()); String smiles1 = "O=C(O)CCC(=O)C(=O)O"; String smiles2 = "O=C(O)C(N)CCC(=O)O"; String smiles3 = "O=C(O)C(N)C"; String smiles4 = "CC(=O)C(=O)O"; IAtomContainer molecule1 = sp.parseSmiles(smiles1); IAtomContainer molecule2 = sp.parseSmiles(smiles2); IAtomContainer molecule3 = sp.parseSmiles(smiles3); IAtomContainer molecule4 = sp.parseSmiles(smiles4); Fingerprinter fingerprinter = new Fingerprinter(1024, 6); BitSet bs1 = fingerprinter.getBitFingerprint(molecule1).asBitSet(); BitSet bs2 = fingerprinter.getBitFingerprint(molecule2).asBitSet(); BitSet bs3 = fingerprinter.getBitFingerprint(molecule3).asBitSet(); BitSet bs4 = fingerprinter.getBitFingerprint(molecule4).asBitSet(); assertThat((double) Tanimoto.calculate(bs1, bs2), is(closeTo(0.75, 0.1))); assertThat((double) Tanimoto.calculate(bs1, bs3), is(closeTo(0.46, 0.1))); assertThat((double) Tanimoto.calculate(bs1, bs4), is(closeTo(0.52, 0.1))); assertThat((double) Tanimoto.calculate(bs2, bs3), is(closeTo(0.53, 0.1))); assertThat((double) Tanimoto.calculate(bs2, bs4), is(closeTo(0.42, 0.1))); assertThat((double) Tanimoto.calculate(bs3, bs4), is(closeTo(0.8, 0.1))); }
@Test public void testCompareBitSetandBitFingerprintTanimoto() throws Exception { IAtomContainer mol1 = TestMoleculeFactory.make123Triazole(); IAtomContainer mol2 = TestMoleculeFactory.makeImidazole(); Fingerprinter fingerprinter = new Fingerprinter(1024, 8); BitSet bs1 = fingerprinter.getBitFingerprint(mol1).asBitSet(); BitSet bs2 = fingerprinter.getBitFingerprint(mol2).asBitSet(); float tanimoto = Tanimoto.calculate(bs1, bs2); BitSetFingerprint fp1 = new BitSetFingerprint(bs1); BitSetFingerprint fp2 = new BitSetFingerprint(bs2); double tanimoto2 = Tanimoto.calculate(fp1, fp2); Assert.assertEquals(tanimoto, tanimoto2, 0.01); IntArrayFingerprint ifp1 = new IntArrayFingerprint(fp1); IntArrayFingerprint ifp2 = new IntArrayFingerprint(fp2); tanimoto2 = Tanimoto.calculate(ifp1, ifp2); Assert.assertEquals(tanimoto, tanimoto2, 0.01); }