def draw_mol(self, mol, size=(160, 120), **kwargs): """Draw a molecule Parameters ---------- mol : rdkit.Chem.rdchem.Mol The molecule to draw size : tuple The size of the drawing canvas **kwargs : object Attributes of the rdkit.Chem.Draw.rdMolDraw2D.MolDrawOptions class like `fixedBondLength=35, bondLineWidth=2` Notes ----- The list of supported MolDrawOptions attributes are available in https://www.rdkit.org/docs/source/rdkit.Chem.Draw.rdMolDraw2D.html#rdkit.Chem.Draw.rdMolDraw2D.MolDrawOptions """ if self.useSVG: d2d = Draw.MolDraw2DSVG(*size) else: d2d = Draw.MolDraw2DCairo(*size) opts = Draw.MolDrawOptions() for key, value in kwargs.items(): setattr(opts, key, value) d2d.SetDrawOptions(opts) d2d.DrawMolecule(mol) d2d.FinishDrawing() return d2d.GetDrawingText()
def draw_mol(self, mol, size=(160, 120), use_coords=True, MolDrawOptions=None, **kwargs): """Draw a molecule Parameters ---------- mol : rdkit.Chem.rdchem.Mol The molecule to draw size : tuple The size of the drawing canvas use_coords : bool Use the 2D or 3D coordinates of the molecule MolDrawOptions : rdkit.Chem.Draw.MolDrawOptions or None Directly set the drawing options. Useful for making highly customized drawings **kwargs : object Attributes of the rdkit.Chem.Draw.MolDrawOptions class like `fixedBondLength=35, bondLineWidth=2` Notes ----- The list of supported MolDrawOptions attributes are available in https://www.rdkit.org/docs/source/rdkit.Chem.Draw.rdMolDraw2D.html#rdkit.Chem.Draw.rdMolDraw2D.MolDrawOptions """ if self.useSVG: d2d = Draw.MolDraw2DSVG(*size) else: d2d = Draw.MolDraw2DCairo(*size) MolDrawOptions = MolDrawOptions or Draw.MolDrawOptions() for key, value in kwargs.items(): setattr(MolDrawOptions, key, value) d2d.SetDrawOptions(MolDrawOptions) if not use_coords: mol = deepcopy(mol) mol.RemoveAllConformers() hl_atoms = getattr(mol, "__sssAtoms", []) d2d.DrawMolecule(mol, highlightAtoms=hl_atoms) d2d.FinishDrawing() return d2d.GetDrawingText()
""" __all__ = ["plot_pathway"] from collections import Iterable import numpy as np import matplotlib.pyplot as plt import networkx as nx from rdkit import Chem from rdkit.Chem import Draw # Remove white background and highlight atoms/bonds with white circles/lines, respectively _DRAWING_OPTIONS = Draw.MolDrawOptions() _DRAWING_OPTIONS.clearBackground = False _DRAWING_OPTIONS.setHighlightColour((1, 1, 1)) _DRAWING_OPTIONS.highlightBondWidthMultiplier = 20 def _get_image(inchi, size): # Returns a PIL image from an InChI string mol = Chem.MolFromInchi(inchi) return Draw.MolToImage( mol, size=size, options=_DRAWING_OPTIONS, highlightAtoms=[atom.GetIdx() for atom in mol.GetAtoms()], highlightBonds=[bond.GetIdx() for bond in mol.GetBonds()], )