Esempio n. 1
0
 def computeSimilarityFP(self, c_chem, typeFP, typeMetric):
     
     try:
         if typeMetric == 'Tanimoto':
             return DataStructs.TanimotoSimilarity(self.d_FP[typeFP], c_chem.d_FP[typeFP])
         elif typeMetric == "Dice":
             return DataStructs.DiceSimilarity(self.d_FP[typeFP], c_chem.d_FP[typeFP])
         elif typeMetric == "Cosine":
             return DataStructs.CosineSimilarity(self.d_FP[typeFP], c_chem.d_FP[typeFP])
         elif typeMetric == "Sokal":
             return DataStructs.SokalSimilarity(self.d_FP[typeFP], c_chem.d_FP[typeFP])
         elif typeMetric == "Russel":
             return DataStructs.RusselSimilarity(self.d_FP[typeFP], c_chem.d_FP[typeFP])
         elif typeMetric == "RogotGoldberg":
             return DataStructs.RogotGoldbergSimilarity(self.d_FP[typeFP], c_chem.d_FP[typeFP])
         elif typeMetric == "AllBit":
             return DataStructs.AllBitSimilarity(self.d_FP[typeFP], c_chem.d_FP[typeFP])
         elif typeMetric == "Kulczynski":
             return DataStructs.KulczynskiSimilarity(self.d_FP[typeFP], c_chem.d_FP[typeFP])
         elif typeMetric == "McConnaughey":
             return DataStructs.McConnaugheySimilarity(self.d_FP[typeFP], c_chem.d_FP[typeFP])
         elif typeMetric == "Asymmetric":
             return DataStructs.AsymmetricSimilarity(self.d_FP[typeFP], c_chem.d_FP[typeFP])
         elif typeMetric == "BraunBlanquet":
             return DataStructs.BraunBlanquetSimilarity(self.d_FP[typeFP], c_chem.d_FP[typeFP])
     except:
         print("Combination %s and %s not supported"%(typeFP, typeMetric))
         self.log = "%sCombination %s and %s not supported\n"%(self.log, typeFP, typeMetric)
         return "NA"
def get_similarity_all(fp1, fp2):
    """
    Get similarity score for fingerprints that are supplied always as SparseBitVect
    RDKit has the following similarity measures:
        Tanimoto, Dice, Cosine, Sokal, Russel, Kulczynski, McConnaughey, and Tversky.
    """
    similarity_scores = [
        DataStructs.TanimotoSimilarity(fp1, fp2),
        DataStructs.DiceSimilarity(fp1, fp2),
        DataStructs.CosineSimilarity(fp1, fp2),
        #        DataStructs.SokalSimilarity(fp1,fp2),
        DataStructs.RusselSimilarity(fp1, fp2),
        DataStructs.KulczynskiSimilarity(fp1, fp2),
        DataStructs.McConnaugheySimilarity(fp1, fp2)
    ]

    return similarity_scores
Esempio n. 3
0
def GetSimilarity(rdkmol1, rdkmol2, metric='tanimoto'):
    '''
    mol1 and mol2 are RDKit fingerprint objects for molecule
    '''
    valid_metric = ('tanimoto', 'dice', 'cosine', 'sokal', 'russel', 'kulczynski', 'mcconnaughey')
    if metric.lower() == 'tanimoto':
        return DataStructs.TanimotoSimilarity(rdkmol1, rdkmol2)
    elif metric.lower() == 'dice':
        return DataStructs.DiceSimilarity(rdkmol1, rdkmol2)
    elif metric.lower() == 'cosine':
        return DataStructs.CosineSimilarity(rdkmol1, rdkmol2)
    elif metric.lower() == 'sokal':
        return DataStructs.SokalSimilarity(rdkmol1, rdkmol2)
    elif metric.lower() == 'russel':
        return DataStructs.RusselSimilarity(rdkmol1, rdkmol2)
    elif metric.lower() == 'kulczynski':
        return DataStructs.KulczynskiSimilarity(rdkmol1, rdkmol2)
    elif metric.lower() == 'mcconnaughey':
        return DataStructs.McConnaugheySimilarity(rdkmol1, rdkmol2)
    #elif metric.lower() == 'tversky': #Was returning error
    #    return DataStructs.TverskySimilarity(rdkmol1, rdkmol2)
    else:
        sys.exit('***ERROR: Unrecognized similarity metric: %s***.\n Use one of %s' % (metric,', '.join(valid_metric)))