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
def compare_structure(smiles1, smiles2, fp_type="Morgan", sim_type="Dice"): """ Task: Compare structual similarity of two compound based on fingerprints. Parameters: smiles1: str, smiles of the compound 1 smiles2: str, smiles of the compound 2 fp_type: str, type of fingerprints sim_type: str, method for calculating similarity """ if fp_type == "Morgan": getfp = lambda smi: AllChem.GetMorganFingerprint( Chem.MolFromSmiles(smi), 2, useFeatures=False) elif fp_type == "MorganWithFeature": getfp = lambda smi: AllChem.GetMorganFingerprint( Chem.MolFromSmiles(smi), 2, useFeatures=True) elif fp_type == "MACCS": getfp = lambda smi: Chem.MACCSkeys.GenMACCSKeys(Chem.MolFromSmiles(smi) ) elif fp_type == "Topological": getfp = lambda smi: FingerprintMols.FingerprintMol( Chem.MolFromSmiles(smi)) elif fp_type == "AtomPairs": getfp = lambda smi: Pairs.GetAtomPairFingerprint( Chem.MolFromSmiles(smi)) try: fp1 = getfp(smiles1) fp2 = getfp(smiles2) if sim_type == "Dice": sim_fp = DataStructs.DiceSimilarity(fp1, fp2) elif sim_type == "Tanimoto": sim_fp = DataStructs.TanimotoSimilarity(fp1, fp2) elif sim_type == "Cosine": sim_fp = DataStructs.CosineSimilarity(fp1, fp2) elif sim_type == "Sokal": sim_fp = DataStructs.SokalSimilarity(fp1, fp2) elif sim_type == "Russel": sim_fp = DataStructs.RusselSimilarity(fp1, fp2) except Exception as e: sim_fp = -1 return sim_fp
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)))