chem-highlighter
Highlighting API for chemical molecules. Given a molecule and a set of atoms/bonds/rings to
color, produces highlighted SVG/PNG/console output, or plain format conversion (SDF, Mol, RXN,
CDX, CDXML, SMILES, InChI, InChIKey, SVG, EPS, PNG). Backend-agnostic: RDKitMolecule (built in,
uses RDKit for everything) implements the HighlightBackendMolecule ABC; other backends can
implement the same ABC against a different underlying engine, so code written against
HighlightBackendMolecule is not tied to RDKit specifically.
Document (also in chem_highlighter/hml.py) wraps a list of molecule-backend instances
parsed from a single input, for formats that can legitimately hold more than one structure: SDF
(every record, not just the first), RXN (reactants/agents/products), CDXML (any number of
fragments), and dot-separated SMILES. HighlightBackendMolecule.from_bytes keeps its existing
single-molecule restrictions unchanged (e.g. still rejects multi-fragment CDXML); Document
is the opt-in multi-molecule path built on top of it.
Prerequisites
Python >= 3.10, < 3.15. RDKit, matplotlib, numpy, polars, scipy, msgspec are pulled in as dependencies.
Installation
pip install chem-highlighter
For a local development install:
pip install -e .
# or: uv sync
Usage
import msgspec
from chem_highlighter import RDKitMolecule, HML
doc = RDKitMolecule.from_string("c1ccccc1O", "SMILES")
doc.cleanup()
hml = HML(highlighted_atoms={6: 0}, palette=["#ff0000"])
doc.highlight_from_json(msgspec.json.encode(hml).decode())
svg = doc.to_svg()
png = doc.to_png()
HighlightBackendMolecule (chem_highlighter/hml.py) is the actual interface: construction
(from_bytes/from_string/from_mol/from_molblock), export (export/export_string/
to_molblock/to_svg/to_png/to_console), and editing (cleanup, kekulize,
align_to_reference, hide_hydrogens, highlight_from_json) — each editing method is one-shot
per document (calling it twice, or in the wrong order relative to another, raises ValueError);
see the class docstrings for the exact rules.
Modules
hml— theHighlightBackendMoleculeABC, the multi-moleculeDocumentclass, andHML/HMolhighlight-payload types.backend/rdkit.py—RDKitMolecule, the RDKit-backed implementation.align— align one molecule to another via bond flips + rotation (used byalign_to_reference).decomposer— R-group decomposition, core/residue splitting, and plotting decomposed sets.diff— highlight the difference between two SMILES strings.modify— rotate/mirror/flip-bond primitives on RDKit molecules.state— save and restore RDKit atom state (used internally bymodify/align).table— render a Polars DataFrame as an AG Grid HTML table.utils— shared helpers: conformer comparison, high-precision V3000 export, PNG render options, color/console formatting.
Environment variables
PNG rendering (RDKitMolecule.export/to_png, utils.get_png_render_options) reads:
CHEM_HIGHLIGHTER_PNG_WIDTH,CHEM_HIGHLIGHTER_PNG_HEIGHT— bounding box in pixels; the molecule is scaled to fit and centered. If only one is set, the other mirrors it. Unset: keeps the default RDKit canvas sizing (unbounded).CHEM_HIGHLIGHTER_PNG_TRANSPARENT—truefor a transparent background instead of white.
Named to match the PNG env vars of other backend implementations, so a caller using more than one backend configures PNG output once.
Testing
pytest
mypy .
ruff check .
Coverage is configured for 100% (the [tool.coverage.report] section of pyproject.toml,
fail_under = 100). vulture is configured to flag dead code ([tool.vulture]).
Some tests (the image/PNG-size tests in tests/test_rdkit.py, the shared assertions in
tests/backend_test.py) rely on native RDKit rendering; no native/OS-specific setup needed
beyond the pip install above.
License
MIT, see LICENSE.
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 chem_highlighter-0.3.2.tar.gz.
File metadata
- Download URL: chem_highlighter-0.3.2.tar.gz
- Upload date:
- Size: 70.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cd1f588030d573811ea82cbc307157122a43b2100ec375424e87ba5071bffbd8
|
|
| MD5 |
53e9897a50e9acdd4878809cb54837b5
|
|
| BLAKE2b-256 |
f4e72c714c5d3157c9b6d235e0163cb25f31be7249c4c25d20aae98912a319cf
|
Provenance
The following attestation bundles were made for chem_highlighter-0.3.2.tar.gz:
Publisher:
release.yml on audivir/chem-highlighter
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
chem_highlighter-0.3.2.tar.gz -
Subject digest:
cd1f588030d573811ea82cbc307157122a43b2100ec375424e87ba5071bffbd8 - Sigstore transparency entry: 2604308603
- Sigstore integration time:
-
Permalink:
audivir/chem-highlighter@dcf5a51a0948574d5c509425af0ce0a99c080093 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/audivir
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@dcf5a51a0948574d5c509425af0ce0a99c080093 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file chem_highlighter-0.3.2-py3-none-any.whl.
File metadata
- Download URL: chem_highlighter-0.3.2-py3-none-any.whl
- Upload date:
- Size: 42.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4dd6904f520a5dc9b0f82593e700f0962d0bab2a96a4920fa3b9e3244381d95d
|
|
| MD5 |
05e5a82df7f0559179e0b33e780762a2
|
|
| BLAKE2b-256 |
01221d6b8d3d66a8c165da095b1ecff4b6765bcbfcb7dfe7febe97602efcd4c1
|
Provenance
The following attestation bundles were made for chem_highlighter-0.3.2-py3-none-any.whl:
Publisher:
release.yml on audivir/chem-highlighter
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
chem_highlighter-0.3.2-py3-none-any.whl -
Subject digest:
4dd6904f520a5dc9b0f82593e700f0962d0bab2a96a4920fa3b9e3244381d95d - Sigstore transparency entry: 2604308610
- Sigstore integration time:
-
Permalink:
audivir/chem-highlighter@dcf5a51a0948574d5c509425af0ce0a99c080093 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/audivir
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@dcf5a51a0948574d5c509425af0ce0a99c080093 -
Trigger Event:
workflow_dispatch
-
Statement type: