英文:
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()
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论