如何使用Rdkit使键线变粗。

huangapple go评论67阅读模式
英文:

How to make bond lines thicker with Rdkit

问题

I am using RDKit to draw a molecule in 2D. I am trying to use DrawingOptions.bondLineWidth to control the bond thickness but it doesn't seem to be working (the bond lines remain the same thickness regardless of the value I set it to). Any idea?

from rdkit.Chem import Draw
from rdkit.Chem.Draw import DrawingOptions
import matplotlib.pyplot as plt

DrawingOptions.atomLabelFontSize = 55
DrawingOptions.dotsPerAngstrom = 100
DrawingOptions.bondLineWidth = 10.0

mol = Chem.MolFromSmiles('CC(C)(C)c1cc(O)ccc1O')
img = Draw.MolToImage(mol, size=(1000, 1000), fitImage=True, kekulize=False, fitWidth=True)
fig, ax = plt.subplots()
ax.imshow(img)
ax.grid(False)
ax.axis('off')
plt.show()

(Note: I've provided the code you provided without translation, as requested.)

英文:

I am using RDkit to draw a molecule in 2D. I am trying to use DrawingOptions.bondLineWidth to control the bond thickness but it doesn't seem to be working (the bond lines remain the same thickness regardless of the value I set it to). Any idea?

from rdkit.Chem import Draw
from rdkit.Chem.Draw import DrawingOptions
import matplotlib.pyplot as plt

DrawingOptions.atomLabelFontSize = 55
DrawingOptions.dotsPerAngstrom = 100
DrawingOptions.bondLineWidth = 10.0

mol = Chem.MolFromSmiles('CC(C)(C)c1cc(O)ccc1O')
img = Draw.MolToImage(mol, size=(1000, 1000), fitImage=True, kekulize=False, fitWidth=True)
fig, ax = plt.subplots()
ax.imshow(img)
ax.grid(False)
ax.axis('off')
plt.show()

答案1

得分: 2

我在这里发现DrawingOptions已被弃用,并且在MolToImage中被MolDrawOptions所忽略。我更新了代码,这个可以在rdkit==2022.9.4下工作。

from rdkit import Chem
from rdkit.Chem import Draw
import matplotlib.pyplot as plt

opts = Draw.MolDrawOptions()
opts.bondLineWidth = 5.

mol = Chem.MolFromSmiles('CC(C)(C)c1cc(O)ccc1O')
img = Draw.MolToImage(mol, size=(500, 500), options=opts)
fig, ax = plt.subplots()
ax.imshow(img)
ax.grid(False)
ax.axis('off')
plt.show()
英文:

I found out here that DrawingOptions is deprecated and ignored by MolToImage in favour of MolDrawOptions. I updated the code, this is working with rdkit==2022.9.4

from rdkit import Chem
from rdkit.Chem import Draw
import matplotlib.pyplot as plt

opts = Draw.MolDrawOptions()
opts.bondLineWidth = 5.

mol = Chem.MolFromSmiles('CC(C)(C)c1cc(O)ccc1O')
img = Draw.MolToImage(mol, size=(500, 500), options=opts)
fig, ax = plt.subplots()
ax.imshow(img)
ax.grid(False)
ax.axis('off')
plt.show()

huangapple
  • 本文由 发表于 2023年5月11日 01:45:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/76221272.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定