扭曲的rdkit MolsToGridImage png文件,因为每行10个分子。我怎么修理它?

2024-09-20 06:29:07 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我的剧本:

   dopts = Draw.rdMolDraw2D.MolDrawOptions()
    dopts.prepareMolsBeforeDrawing = True

    k = 10
    results = Draw.MolsToGridImage(
        self.hits[:k + 1], molsPerRow=5, subImgSize=(250,250),
        drawOptions=dopts,
        legends=[x.GetProp("chembl_id")
                 for x in self.hits[:k]],        )
    results.save(f'{self.out_dir}/output.png')

但是整个图像输出文件中的分子放错了位置output is something like this.

我已将此作为一个问题发布,尚未解决https://github.com/rdkit/rdkit/issues/4097


Tags: selftrueoutputresultsdraw剧本hitsrdkit
1条回答
网友
1楼 · 发布于 2024-09-20 06:29:07

查看有关分子制备的documentation sectionprepareMolsBeforeDrawing),似乎表明如果2D构象已经存在,它将不会生成新构象

Does some cleanup operations on the molecule to prepare it to draw nicely. The operations include: kekulization, addition of chiral Hs (so that we can draw wedges to them), wedging of bonds at chiral centers, and generation of a 2D conformation if the molecule does not already have a conformation

如果你的分子来自某种类似SDF的东西,那么也许移除已经存在的构象可以解决这个问题,尽管我不能完全确定,因为我没有SDF要测试。在绘制图像之前,请尝试添加以下内容,假设您对已经存在的构象没有任何用处,否则,请事先制作一份副本

# Assuming molecules are in a list named mols
for mol in mols:
    mol.RemoveAllConformers()  # edited in-place

编辑:

在一些具有3D构象的化合物上进行测试,移除构象确实迫使rdkit生成新的2D坐标用于描述

或者,您也可以自己添加二维坐标,覆盖现有构象,然后如果您愿意,可以删除preparation参数,前提是您对它执行的其他清理步骤不感兴趣:

for mol in mols:
    AllChem.Compute2dCoords(mol, clearConfs=True)

相关问题 更多 >