Exemplo n.º 1
0
  def testSimilarityMap(self):
    # Morgan2 BV
    refWeights = [0.5, 0.5, 0.5, -0.5, 0.5, 0.5]
    weights = sm.GetAtomicWeightsForFingerprint(self.mol1, self.mol2, lambda m, i: sm.GetMorganFingerprint(m, i, radius=2, fpType='bv'))
    for w,r in zip(weights, refWeights): self.assertEqual(w, r)

    fig, maxWeight = sm.GetSimilarityMapForFingerprint(self.mol1, self.mol2, lambda m, i: sm.GetMorganFingerprint(m, i, radius=2, fpType='bv'))
    self.assertEqual(maxWeight, 0.5)
    
    weights, maxWeight = sm.GetStandardizedWeights(weights)
    self.assertEqual(maxWeight, 0.5)
    refWeights = [1.0, 1.0, 1.0, -1.0, 1.0, 1.0]
    for w,r in zip(weights, refWeights): self.assertEqual(w, r)

    weights = sm.GetAtomicWeightsForFingerprint(self.mol1, self.mol2, lambda m, i: sm.GetMorganFingerprint(m, i, fpType='count'))
    self.assertTrue(weights[3] < 0)
    weights = sm.GetAtomicWeightsForFingerprint(self.mol1, self.mol2, lambda m, i: sm.GetMorganFingerprint(m, i, fpType='bv', useFeatures=True))
    self.assertTrue(weights[3] < 0)

    # hashed AP BV
    refWeights = [0.09523, 0.17366, 0.17366, -0.23809, 0.17366, 0.17366]
    weights = sm.GetAtomicWeightsForFingerprint(self.mol1, self.mol2, lambda m, i: sm.GetAPFingerprint(m, i, fpType='bv', nBits=1024))
    for w,r in zip(weights, refWeights): self.assertAlmostEqual(w, r, 4)

    weights = sm.GetAtomicWeightsForFingerprint(self.mol1, self.mol2, lambda m, i: sm.GetAPFingerprint(m, i, fpType='normal'))
    self.assertTrue(weights[3] < 0)
    weights = sm.GetAtomicWeightsForFingerprint(self.mol1, self.mol2, lambda m, i: sm.GetAPFingerprint(m, i, fpType='hashed'))
    self.assertTrue(weights[3] < 0)
    
    # hashed TT BV
    refWeights = [0.5, 0.5, -0.16666, -0.5, -0.16666, 0.5]
    weights = sm.GetAtomicWeightsForFingerprint(self.mol1, self.mol2, lambda m, i: sm.GetTTFingerprint(m, i, fpType='bv', nBits=1024, nBitsPerEntry=1))
    for w,r in zip(weights, refWeights): self.assertAlmostEqual(w, r, 4)

    weights = sm.GetAtomicWeightsForFingerprint(self.mol1, self.mol2, lambda m, i: sm.GetTTFingerprint(m, i, fpType='normal'))
    self.assertTrue(weights[3] < 0)
    weights = sm.GetAtomicWeightsForFingerprint(self.mol1, self.mol2, lambda m, i: sm.GetTTFingerprint(m, i, fpType='hashed'))
    self.assertTrue(weights[3] < 0)

    # RDK fingerprint BV
    refWeights = [0.42105, 0.42105, 0.42105, -0.32895, 0.42105, 0.42105]
    weights = sm.GetAtomicWeightsForFingerprint(self.mol1, self.mol2, lambda m, i: sm.GetRDKFingerprint(m, i, nBits=1024, nBitsPerHash=1))
    for w,r in zip(weights, refWeights): self.assertAlmostEqual(w, r, 4)
Exemplo n.º 2
0
def fp_maps(results, query, fingerprint, fpradius, nbits, features, metric,
            out_file, multfile):
    if fingerprint == "ecfp" or fingerprint == "fcfp":
        fp_func = lambda m, idx: SimilarityMaps.GetMorganFingerprint(
            m,
            atomId=idx,
            radius=fpradius,
            fpType='bv',
            nBits=nbits,
            useFeatures=features)
    elif fingerprint == "rdkit":
        fp_func = lambda m, idx: SimilarityMaps.GetRDKFingerprint(
            m, atomId=idx, fpType="bv", nBits=nbits)
    elif fingerprint == "ap":
        fp_func = lambda m, idx: SimilarityMaps.GetAPFingerprint(
            m, atomId=idx, fpType="bv", nBits=nbits)
    else:
        fp_func = lambda m, idx: SimilarityMaps.GetTTFingerprint(
            m, atomId=idx, fpType="bv", nBits=nbits)
    if multfile:
        sim_map_mf(results, query, fp_func, metric, out_file)
    else:
        sim_map(results, query, fp_func, metric, out_file)