本文整理汇总了Python中rdkit.DataStructs.FingerprintSimilarity方法的典型用法代码示例。如果您正苦于以下问题:Python DataStructs.FingerprintSimilarity方法的具体用法?Python DataStructs.FingerprintSimilarity怎么用?Python DataStructs.FingerprintSimilarity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rdkit.DataStructs
的用法示例。
在下文中一共展示了DataStructs.FingerprintSimilarity方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_highest_similarity_for_mol
# 需要导入模块: from rdkit import DataStructs [as 别名]
# 或者: from rdkit.DataStructs import FingerprintSimilarity [as 别名]
def get_highest_similarity_for_mol(fp, fp_list_to_compare):
max_sim = 0
for fp_comp in fp_list_to_compare:
sim = DataStructs.FingerprintSimilarity(fp, fp_comp)
if sim == 1.0:
return sim
if sim > max_sim:
max_sim = sim
return max_sim
示例2: get_highest_similarity
# 需要导入模块: from rdkit import DataStructs [as 别名]
# 或者: from rdkit.DataStructs import FingerprintSimilarity [as 别名]
def get_highest_similarity(input_file, output_file, comparison_file='../full_toxcast/restructured.csv',
top_compounds_only=True, num_compounds=1500):
df_avg = pd.read_csv(input_file, header=0, index_col=False)
if top_compounds_only:
df_avg = df_avg.head(num_compounds)
smiles_list = df_avg['smiles']
avg_scores = df_avg['avg_score']
# default_mol = Chem.MolFromSmiles('CCCC')
# default_fp = rdMolDescriptors.GetMorganFingerprintAsBitVect(default_mol, 2, nBits=1024)
# mol2 = Chem.MolFromSmiles('CCCC')
# fp2 = rdMolDescriptors.GetMorganFingerprintAsBitVect(mol2, 2, nBits=1024)
# sim = DataStructs.FingerprintSimilarity(default_fp, fp2)
df_comparison = pd.read_csv(comparison_file, header=0, index_col=False)
#df_comparison = df_comparison.head(100)
comparison_smiles_list = df_comparison['smiles']
comparison_fp_list = []
similarity_list = []
for c_smiles in comparison_smiles_list:
comp_mol = Chem.MolFromSmiles(c_smiles)
#comp_fp = rdMolDescriptors.GetMorganFingerprintAsBitVect(comp_mol, 2, nBits=1024)
comp_fp = FingerprintMols.FingerprintMol(comp_mol)
comparison_fp_list.append(comp_fp)
for i, smiles in enumerate(smiles_list):
mol_to_test = Chem.MolFromSmiles(smiles)
#fp_to_test = rdMolDescriptors.GetMorganFingerprintAsBitVect(mol_to_test, 2, nBits=1024)
fp_to_test = FingerprintMols.FingerprintMol(mol_to_test)
similarity_list.append(get_highest_similarity_for_mol(fp_to_test, comparison_fp_list))
if i%500 == 0:
print(i)
with open(output_file, 'w', newline='') as csvfile:
fieldnames = ['smiles', 'avg_score', 'max_similarity']
writer = csv.DictWriter(csvfile, fieldnames = fieldnames)
writer.writeheader()
for i, smiles in enumerate(smiles_list):
out_line = {'smiles': smiles, 'avg_score': avg_scores[i],
'max_similarity': similarity_list[i]}
writer.writerow(out_line)