Cheminformatics Tutorials - Herong's Tutorial Examples - v2.01, by Herong Yang
MolToImage/MolToFile - Molecule PNG Image
This section provides a tutorial example on how to use rdkit.Chem.Draw.MolToImage(m) and rdkit.Chem.Draw.MolToFile(m, f) methods to generate molecule images in PNG format and store them in PIL objects or files.
There are two main methods that generate molecule images as PIL objects or image files.
1. rdkit.Chem.Draw.MolToImage(m) - Returns a PIL image object containing a drawing of the molecule. By default, the returning PIL object represents the molecule images in PNG format.
2. rdkit.Chem.Draw.MolToFile(m, f) - Generates a drawing of a molecule and writes it to a file. By default, the generated image file uses PNG format.
Here is an example session of using these two methods:
>>> from rdkit import Chem >>> m = Chem.MolFromSmiles('Cc1ccccc1') >>> from rdkit.Chem import Draw >>> p = Draw.MolToImage(m) >>> p <class 'PIL.PngImagePlugin.PngImageFile'> >>> Draw.MolToFile(m, "molecule.png")
If you open the generated image file, molecule.png, you will see the following molecule image with 300x300 pixels:
If you are running Python in a Jupyter Notebook environment, the "p" statement will actually display its PNG image in the Notebook as shown below:
Table of Contents
SMILES (Simplified Molecular-Input Line-Entry System)
Open Babel: The Open Source Chemistry Toolbox
Using Open Babel Command: "obabel"
Generating SVG Pictures with Open Babel
Substructure Search with Open Babel
Similarity Search with Open Babel
Fingerprint Index for Fastsearch with Open Babel
Stereochemistry with Open Babel
Command Line Tools Provided by Open Babel
RDKit: Open-Source Cheminformatics Software
rdkit.Chem.rdchem - The Core Module
rdkit.Chem.rdmolfiles - Molecular File Module
rdkit.Chem.rdDepictor - Compute 2D Coordinates
►rdkit.Chem.Draw - Handle Molecule Images
What Is rdkit.Chem.Draw Module
►MolToImage/MolToFile - Molecule PNG Image
rdkit.Chem.Draw.MolDrawing.DrawingOptions Class
rdkirdkit.Chem.Draw.rdMolDraw2D.MolDraw2DCairo - 2D Molecule Drawing
rdkit.Chem.Draw.rdMolDraw2D.MolDraw2DCairo - Molecule PNG Image
rdkit.Chem.Draw.rdMolDraw2D.MolDraw2DSVG - Molecule SVG Image
rdkit.Chem.Draw.rdMolDraw2D.MolDrawOptions - Drawing Options
Drawing Diagrams with MolDraw2DCairo and MolDraw2DSVG
Molecule Substructure Search with RDKit
rdkit.Chem.rdmolops - Molecule Operations
Daylight Fingerprint Generator in RDKit
Morgan Fingerprint Generator in RDKit
RDKit Performance on Substructure Search
Introduction to Molecular Fingerprints
OCSR (Optical Chemical Structure Recognition)
AlphaFold - Protein Structure Prediction