rdkit.Chem.Draw package

Submodules

Module contents

rdkit.Chem.Draw.DebugDraw(mol, size=(350, 350), drawer=None, asSVG=True, useBW=True, includeHLabels=True, addAtomIndices=True, addBondIndices=False)
rdkit.Chem.Draw.DrawMorganBit(mol, bitId, bitInfo, whichExample=0, **kwargs)
rdkit.Chem.Draw.DrawMorganBits(tpls, **kwargs)
rdkit.Chem.Draw.DrawMorganEnv(mol, atomId, radius, molSize=(150, 150), baseRad=0.3, useSVG=True, aromaticColor=(0.9, 0.9, 0.2), ringColor=(0.8, 0.8, 0.8), centerColor=(0.6, 0.6, 0.9), extraColor=(0.9, 0.9, 0.9), drawOptions=None, **kwargs)
rdkit.Chem.Draw.DrawMorganEnvs(envs, molsPerRow=3, subImgSize=(150, 150), baseRad=0.3, useSVG=True, aromaticColor=(0.9, 0.9, 0.2), ringColor=(0.8, 0.8, 0.8), centerColor=(0.6, 0.6, 0.9), extraColor=(0.9, 0.9, 0.9), legends=None, drawOptions=None, **kwargs)
rdkit.Chem.Draw.DrawRDKitBit(mol, bitId, bitInfo, whichExample=0, **kwargs)
rdkit.Chem.Draw.DrawRDKitBits(tpls, **kwargs)
rdkit.Chem.Draw.DrawRDKitEnv(mol, bondPath, molSize=(150, 150), baseRad=0.3, useSVG=True, aromaticColor=(0.9, 0.9, 0.2), extraColor=(0.9, 0.9, 0.9), nonAromaticColor=None, drawOptions=None, **kwargs)
rdkit.Chem.Draw.DrawRDKitEnvs(envs, molsPerRow=3, subImgSize=(150, 150), baseRad=0.3, useSVG=True, aromaticColor=(0.9, 0.9, 0.2), extraColor=(0.9, 0.9, 0.9), nonAromaticColor=None, legends=None, drawOptions=None, **kwargs)
class rdkit.Chem.Draw.FingerprintEnv(submol, highlightAtoms, atomColors, highlightBonds, bondColors, highlightRadii)

Bases: tuple

Create new instance of FingerprintEnv(submol, highlightAtoms, atomColors, highlightBonds, bondColors, highlightRadii)

atomColors

Alias for field number 2

bondColors

Alias for field number 4

highlightAtoms

Alias for field number 1

highlightBonds

Alias for field number 3

highlightRadii

Alias for field number 5

submol

Alias for field number 0

rdkit.Chem.Draw.MolToFile(mol, filename, size=(300, 300), kekulize=True, wedgeBonds=True, imageType=None, fitImage=False, options=None, **kwargs)

Generates a drawing of a molecule and writes it to a file

rdkit.Chem.Draw.MolToImage(mol, size=(300, 300), kekulize=True, wedgeBonds=True, fitImage=False, options=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 [])

  • 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

rdkit.Chem.Draw.MolsMatrixToGridImage(molsMatrix, subImgSize=(200, 200), legendsMatrix=None, highlightAtomListsMatrix=None, highlightBondListsMatrix=None, useSVG=False, returnPNG=False, **kwargs)

Creates a mol grid image from a nested data structure (where each data substructure represents a row), padding rows as needed so all rows are the length of the longest row

ARGUMENTS:

  • molsMatrix: A two-deep nested data structure of RDKit molecules to draw,

iterable of iterables (for example list of lists) of RDKit molecules

  • subImgSize: The size of a cell in the drawing; passed through to MolsToGridImage (default (200, 200))

  • legendsMatrix: A two-deep nested data structure of strings to label molecules with,

iterable of iterables (for example list of lists) of strings (default None)

  • highlightAtomListsMatrix: A three-deep nested data structure of integers of atoms to highlight,

iterable of iterables (for example list of lists) of integers (default None)

  • highlightBondListsMatrix: A three-deep nested data structure of integers of bonds to highlight,

iterable of iterables (for example list of lists) of integers (default None)

  • useSVG: Whether to return an SVG (if true) or PNG (if false);

passed through to MolsToGridImage (default false)

  • returnPNG: Whether to return PNG data (if true) or a PIL object for a PNG image file (if false);

has no effect if useSVG is true; passed through to MolsToGridImage (default false)

  • kwargs: Any other keyword arguments are passed to MolsToGridImage

NOTES:

To include a blank cell in the middle of a row, supply None for that entry in molsMatrix. You do not need to do that for empty cells at the end of a row; this function will automatically pad rows so that all rows are the same length.

This function is useful when each row has some meaning, for example the generation in a mass spectrometry fragmentation tree–refer to example at https://en.wikipedia.org/wiki/Fragmentation_(mass_spectrometry). If you want to display a set molecules where each row does not have any specific meaning, use MolsToGridImage instead.

This function nests data structures one additional level beyond the analogous function MolsToGridImage (in which the molecules and legends are non-nested lists, and the highlight parameters are two-deep nested lists)

RETURNS:

A grid of molecular images in one of these formats:

  • useSVG=False and returnPNG=False (default): A PIL object for a PNG image file

  • useSVG=False and returnPNG=True: PNG data

  • useSVG=True: An SVG string

EXAMPLES:

from rdkit import Chem from rdkit.Chem.Draw import MolsMatrixToGridImage, rdMolDraw2D FCl = Chem.MolFromSmiles(“FCl”) molsMatrix = [[FCl, FCl], [FCl, None, FCl]]

# Minimal example: Only molsMatrix is supplied, # result will be a drawing containing (where each row contains molecules): # F-Cl F-Cl # F-Cl F-Cl img = MolsMatrixToGridImage(molsMatrix) img.save(“MolsMatrixToGridImageMinimal.png”) # img is a PIL object for a PNG image file like: # <PIL.PngImagePlugin.PngImageFile image mode=RGB size=600x200 at 0x1648CC390> # Drawing will be saved as PNG file MolsMatrixToGridImageMinimal.png

# Exhaustive example: All parameters are supplied, # result will be a drawing containing (where each row of molecules is followed by a row of legends): # 1 F-Cl 0 1 F-Cl 0 # no highlighting bond highlighted # 1 F-Cl 0 1 F-Cl 0 # sodium highlighted chloride and bond highlighted legendsMatrix = [[“no highlighting”, “bond highlighted”], [“F highlighted”, “”, “Cl and bond highlighted”]] highlightAtomListsMatrix = [[[],[]], [[0], None, [1]]] highlightBondListsMatrix = [[[],[0]], [[], None, [0]]]

dopts = rdMolDraw2D.MolDrawOptions() dopts.addAtomIndices = True

img_binary = MolsMatrixToGridImage(molsMatrix=molsMatrix, subImgSize=(300, 400), legendsMatrix=legendsMatrix, highlightAtomListsMatrix=highlightAtomListsMatrix, highlightBondListsMatrix=highlightBondListsMatrix, useSVG=False, returnPNG=True, drawOptions=dopts) print(img_binary[:20]) # Prints a binary string: b’x89PNGrnx1anx00x00x00rIHDRx00x00x03x84’

rdkit.Chem.Draw.MolsToGridImage(mols, molsPerRow=3, subImgSize=(200, 200), legends=None, highlightAtomLists=None, highlightBondLists=None, useSVG=False, returnPNG=False, **kwargs)
rdkit.Chem.Draw.MolsToImage(mols, subImgSize=(200, 200), legends=None, **kwargs)
rdkit.Chem.Draw.ReactionToImage(rxn, subImgSize=(200, 200), useSVG=False, drawOptions=None, returnPNG=False, **kwargs)
rdkit.Chem.Draw.SetComicMode(opts)
rdkit.Chem.Draw.ShowMol(mol, size=(300, 300), kekulize=True, wedgeBonds=True, title='RDKit Molecule', stayInFront=True, **kwargs)

Generates a picture of a molecule and displays it in a Tkinter window

rdkit.Chem.Draw.calcAtomGaussians(mol, a=0.03, step=0.02, weights=None)

useful things to do with these: fig.axes[0].imshow(z,cmap=cm.gray,interpolation=’bilinear’,origin=’lower’,extent=(0,1,0,1)) fig.axes[0].contour(x,y,z,20,colors=’k’)

fig=Draw.MolToMPL(m); contribs=Crippen.rdMolDescriptors._CalcCrippenContribs(m) logps,mrs=zip(*contribs) x,y,z=Draw.calcAtomGaussians(m,0.03,step=0.01,weights=logps) fig.axes[0].imshow(z,cmap=cm.jet,interpolation=’bilinear’,origin=’lower’,extent=(0,1,0,1)) fig.axes[0].contour(x,y,z,20,colors=’k’,alpha=0.5) fig.savefig(‘coumlogps.colored.png’,bbox_inches=’tight’)

rdkit.Chem.Draw.shouldKekulize(mol, kekulize)