rdkit:如何绘制高分辨率化学结构

我正在使用 jupyter 实验室绘制化学结构。但输出图像分辨率太低。我该如何改进它?


from rdkit import Chem

from rdkit.Chem import Draw

smiles = 'C1=CC(=C(C=C1C2=C(C(=O)C3=C(C=C(C=C3O2)O)O)O)O)O'

m = Chem.MolFromSmiles(smiles)

Draw.MolToImage(m)


慕码人2483693
浏览 102回答 2
2回答

慕无忌1623718

对于那些寻找具有更高分辨率分子输出和输出的解决方案的人。该cairosvg库(也是命令行程序)具有文件类型的导出选项,包括 .svg、.pdf、.png、.eps ( https://cairosvg.org/ )。from rdkit import Chemfrom rdkit.Chem import Drawfrom rdkit.Chem.Draw import rdMolDraw2Dimport cairosvgimport iodef molecule_to_pdf(mol, file_name, width=300, height=300):    """Save substance structure as PDF"""    # Define full path name    full_path = f"./figs/2Dstruct/{file_name}.pdf"    # Render high resolution molecule    drawer = rdMolDraw2D.MolDraw2DSVG(width, height)    drawer.DrawMolecule(mol)    drawer.FinishDrawing()    # Export to pdf    cairosvg.svg2pdf(bytestring=drawer.GetDrawingText().encode(), write_to=full_path)# Examplem = Chem.MolFromSmiles('Cn1cnc2n(C)c(=O)n(C)c(=O)c12')molecule_to_pdf(m, "myfav")

慕仙森

我找到了解决方案,更多信息可以在这里找到from rdkit import Chemfrom rdkit.Chem.Draw import IPythonConsolefrom rdkit.Chem import rdDepictorfrom rdkit.Chem.Draw import rdMolDraw2Dfrom IPython.display import SVGsmiles = 'C1=CC(=C(C=C1C2=C(C(=O)C3=C(C=C(C=C3O2)O)O)O)O)O' m = Chem.MolFromSmiles(smiles)def moltosvg(mol, molSize = (300,300), kekulize = True):    mc = Chem.Mol(mol.ToBinary())    if kekulize:        try:            Chem.Kekulize(mc)        except:            mc = Chem.Mol(mol.ToBinary())    if not mc.GetNumConformers():        rdDepictor.Compute2DCoords(mc)    drawer = rdMolDraw2D.MolDraw2DSVG(molSize[0],molSize[1])    drawer.DrawMolecule(mc)    drawer.FinishDrawing()    svg = drawer.GetDrawingText()    return svg.replace('svg:','')SVG(moltosvg(m))
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python