2022-01-18 使用RDKit计算分子相似性,并将相似性结果写入excel文件,做分布图

import xlwt

import rdkit

from rdkitimport Chem

from rdkit.Chemimport Draw

from rdkit.Chemimport AllChem

from rdkit.Chemimport Draw

from rdkitimport DataStructs

from rdkit.Chemimport Descriptors

suppl = Chem.SDMolSupplier('C:/Users/zhangguhua/Desktop/pycharm_job_path/Fragment_Library_4063.sdf')

mols = [molfor molin supplif molis not None]

fo =open('C:/Users/zhangguhua/Desktop/pycharm_job_path/Sulcotrione.smi').read()

ref_mol = Chem.MolFromSmiles(fo)

fo_fp = AllChem.GetMorganFingerprint(ref_mol,2)

mols_fps = [(mol,AllChem.GetMorganFingerprint(mol,2))for molin mols]

fo_mols = [(m,DataStructs.TanimotoSimilarity(fo_fp,mols_fp))for m,mols_fpin mols_fps]

sorted_fo_mols =sorted(fo_mols,reverse=True,key=lambda x: x[1])

print(len(sorted_fo_mols))

book = xlwt.Workbook(encoding='utf-8',style_compression=0)

sheet = book.add_sheet('RDKit',cell_overwrite_ok=True)

col = ('num','mole-similarity')

a = []

for iin range(0,2):

sheet.write(0,i,col[i])

for iin range(len(sorted_fo_mols)):

for m,sin sorted_fo_mols:

a.append(s)

sheet.write(i+1,1,a[i])

savepath ='C:/Users/zhangguhua/Desktop/pycharm_job_path/data.xls'

book.save(savepath)

result = sorted_fo_mols[:200]

test_200 =open('C:/Users/zhangguhua/Desktop/pycharm_job_path/test200.sdf','w')

writer = Chem.SDWriter(test_200)

for x,yin result:

writer.write(x)

writer.close

print('b')

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容