这个代码可以用于自动把所有分子的分子图保存为png格式。
import sys
sys.path.append('/home/li/.conda/envs/li/lib/python3.7/site-packages')
from rdkit import Chem
from rdkit.Chem import Draw
smis=[]
for i in open ("/home/li/draw_molecule_picture/moses2_smiles.txt"):
smis.append(i)
mols = []
for smi in smis:
mol = Chem.MolFromSmiles(smi)
mols.append(mol)
for j in range(38726):
print(j)
mols[j] = mols[j*50:(j+1)*50]
# output picture
try:
img = Draw.MolsToGridImage(mols[j], molsPerRow=5, subImgSize=(300, 300))
img.save('/home/li/draw_molecule_picture/'+str(j)+'.png')
except:
print("第"+str(j)+"张图片显示不出来")
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)