當前位置: 首頁>>代碼示例>>Python>>正文


Python DrawingOptions.selectColor方法代碼示例

本文整理匯總了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
開發者ID:dfhahn,項目名稱:rdkit,代碼行數:87,代碼來源:__init__.py


注:本文中的rdkit.Chem.Draw.MolDrawing.DrawingOptions.selectColor方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。