RDKit molecule drawing with Depth of Field (DOF) effects.
Project description
rdkit-dof
rdkit-dof is a lightweight Python package for rendering RDKit molecules with a depth-of-field (DOF) or fog effect. It uses 3D conformer depth to fade distant atoms and bonds, producing clearer visual depth in 2D molecular depictions.
Highlights
- Single-molecule, grid, GIF, and animated SVG rendering with RDKit-compatible APIs.
- SVG, PNG, GIF, and animated SVG output, including direct file saving.
- Atom and bond highlighting with saturated colors while the rest keeps DOF fading.
- Preset styles:
default,nature,jacs, anddark. - Local or global configuration through standard-library dataclasses.
- Optional Jupyter/IPython integration for RDKit
Moldisplay.
Comparison
Single Molecule
| Default RDKit | rdkit-dof Effect |
|---|---|
Grid Mode
| Default RDKit | rdkit-dof Effect |
|---|---|
Highlighting
| Single Highlighting | Grid Highlighting |
|---|---|
Animation
| GIF Animation | SVG Animation |
|---|---|
Installation
pip install rdkit-dof
Quick Start
from rdkit import Chem
from rdkit.Chem.rdDistGeom import EmbedMolecule
from rdkit.Chem.rdForceFieldHelpers import MMFFOptimizeMolecule
from rdkit_dof import MolToDofImage, MolsToDofGif, MolsToDofSvgAnimation, dofconfig
mol = Chem.MolFromSmiles("CCO")
mol = Chem.AddHs(mol)
EmbedMolecule(mol, randomSeed=42)
MMFFOptimizeMolecule(mol)
dofconfig.use_style("nature")
MolToDofImage(
mol,
size=(600, 500),
legend="Ethanol",
filename="ethanol.svg",
)
MolsToDofGif([mol, mol], size=(600, 500), duration=250, filename="mols.gif")
MolsToDofSvgAnimation([mol, mol], size=(600, 500), duration=250, filename="mols.svg")
Unicode/non-ASCII legend text is not supported. rdkit-dof emits a warning and
passes the text through to RDKit unchanged. Use ASCII legends for portable
output.
Examples
Open the executed notebook for concrete examples with rendered output:
- Quickstart Notebook: single molecule, style presets, highlighting, grid rendering, configuration, notebook integration, and raw SVG/PNG output.
- 中文 Notebook: Chinese version with the same runnable examples.
Molecules with 3D conformers get true depth-based fading. Molecules without conformers are still supported; 2D coordinates are computed automatically and the depth effect is flat.
Documentation
- Usage Guide: workflow notes for single molecules, grids, animations, highlighting, notebook integration, and custom RDKit drawing.
- API Reference: signatures and parameter behavior for
MolToDofImage,MolsToGridDofImage,MolsToDofGif,MolsToDofSvgAnimation, andDofDrawSettings. - Configuration: global config, local settings,
.env, environment variables, and style presets.
Compatibility
- Python 3.8+
- RDKit 2023.09+
- Linux, macOS, and Windows
Python 3.8 installs are constrained to the last compatible RDKit line (<2024.3.6).
Development
uv sync --group dev
uv run pytest
uv run ruff check .
uv run mypy src
uv run pyright
To open the notebook examples:
uv sync --group dev --group notebook
uv run notebook examples/rdkit_dof_quickstart.en.ipynb
To regenerate README showcase images:
python scripts/_generate_comparison_images.py
License
This project is distributed under the MIT License. See LICENSE for details.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rdkit_dof-0.2.1.tar.gz.
File metadata
- Download URL: rdkit_dof-0.2.1.tar.gz
- Upload date:
- Size: 1.0 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
40b95169c884fa45e84944850ff05d9fd7185e8c66f4cad2c88b0503d57cfcee
|
|
| MD5 |
392defbbd1aa1bba8b375a6fe5ee8339
|
|
| BLAKE2b-256 |
213b7518ceb0eb85f11d98f2aef9c2a78a3ee035bb6e229403817a01a476076a
|
File details
Details for the file rdkit_dof-0.2.1-py3-none-any.whl.
File metadata
- Download URL: rdkit_dof-0.2.1-py3-none-any.whl
- Upload date:
- Size: 14.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.23 {"installer":{"name":"uv","version":"0.11.23","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4ea2d4de899b5288e9d7413c52ff2d5452395066b19c1877ca4f2ba3e23da092
|
|
| MD5 |
018debff12c8ceb5636489b8c654c91b
|
|
| BLAKE2b-256 |
775e15db60cede0bdfc62dc7b1282f710a1ced5bbab1db3dc17021da95f74e7b
|