本文整理汇总了Python中rdkit.Chem.Draw.MolDrawing.DrawingOptions.selectColor方法的典型用法代码示例。如果您正苦于以下问题:Python DrawingOptions.selectColor方法的具体用法?Python DrawingOptions.selectColor怎么用?Python DrawingOptions.selectColor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rdkit.Chem.Draw.MolDrawing.DrawingOptions
的用法示例。
在下文中一共展示了DrawingOptions.selectColor方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MolToImage
# 需要导入模块: from rdkit.Chem.Draw.MolDrawing import DrawingOptions [as 别名]
# 或者: from rdkit.Chem.Draw.MolDrawing.DrawingOptions import selectColor [as 别名]
def MolToImage(mol, size=(300,300), kekulize=True, wedgeBonds=True,
fitImage=False, options=None, canvas=None, **kwargs):
"""Returns a PIL image containing a drawing of the molecule
ARGUMENTS:
- kekulize: run kekulization routine on input `mol` (default True)
- size: final image size, in pixel (default (300,300))
- wedgeBonds: draw wedge (stereo) bonds (default True)
- highlightAtoms: list of atoms to highlight (default [])
- highlightMap: dictionary of (atom, color) pairs (default None)
- highlightBonds: list of bonds to highlight (default [])
- highlightColor: RGB color as tuple (default [1, 0, 0])
NOTE:
use 'matplotlib.colors.to_rgb()' to convert string and
HTML color codes into the RGB tuple representation, eg.
from matplotlib.colors import ColorConverter
img = Draw.MolToImage(m, highlightAtoms=[1,2], highlightColor=ColorConverter().to_rgb('aqua'))
img.save("molecule.png")
RETURNS:
a PIL Image object
"""
if not mol:
raise ValueError('Null molecule provided')
if canvas is None:
img,canvas=_createCanvas(size)
else:
img=None
if options is None:
options = DrawingOptions()
if fitImage:
options.dotsPerAngstrom = int(min(size) / 10)
options.wedgeDashedBonds = wedgeBonds
if 'highlightColor' in kwargs:
color = kwargs.pop('highlightColor', (1, 0, 0))
options.selectColor = color
drawer = MolDrawing(canvas=canvas,drawingOptions=options)
if kekulize:
from rdkit import Chem
mol = Chem.Mol(mol.ToBinary())
Chem.Kekulize(mol)
if not mol.GetNumConformers():
from rdkit.Chem import AllChem
AllChem.Compute2DCoords(mol)
if 'legend' in kwargs:
legend = kwargs['legend']
del kwargs['legend']
else:
legend=''
drawer.AddMol(mol,**kwargs)
if legend:
from rdkit.Chem.Draw.MolDrawing import Font
bbox = drawer.boundingBoxes[mol]
pos = size[0]/2,int(.94*size[1]),0 # the 0.94 is extremely empirical
# canvas.addCanvasPolygon(((bbox[0],bbox[1]),(bbox[2],bbox[1]),(bbox[2],bbox[3]),(bbox[0],bbox[3])),
# color=(1,0,0),fill=False,stroke=True)
# canvas.addCanvasPolygon(((0,0),(0,size[1]),(size[0],size[1]),(size[0],0) ),
# color=(0,0,1),fill=False,stroke=True)
font=Font(face='sans',size=12)
canvas.addCanvasText(legend,pos,font)
if kwargs.get('returnCanvas',False):
return img,canvas,drawer
else:
canvas.flush()
return img