chematic is a pure-Rust cheminformatics library for searching, analyzing, and drawing molecular structures. Python, Rust, Node.js, and browser applications share the same Rust core.
Its aim is formally specified, independently validated kernels: results are checked against machine-checked mathematical specifications and independent reference implementations, not only against another toolkit's output. Each claim below says which of these it rests on. How correctness is established
日本語 · 中文 · Documentation · Playground
pip install chematic
cargo add chematic --features "smiles,perception,chem,threed,fp"
npm install @kent-tokyo/chematicThe Python wheels install without a C/C++ compiler. In the browser, WebAssembly processes molecules on the user's device.
The current release is v1.2.9. See release notes and artifact verification. Upcoming changes are listed under Unreleased.
- Read molecules from SMILES or SDF and calculate molecular weight, LogP, and topological polar surface area (TPSA).
- Search for a substructure with SMARTS, or find similar molecules using Morgan fingerprints and Tanimoto similarity.
- Find the maximum common substructure (MCS) of a set of molecules.
- Draw molecular structures as SVG for web pages and reports.
chematic separates three levels of assurance and names the level for each claim.
| Level | What it means | Where it applies today |
|---|---|---|
| Proved | A theorem checked by Lean 4, with no sorry and only Lean's standard axioms. |
Kekulé assignment (graph part): the checker decides exactly the specification, and the reference search is sound and complete, so it finds no assignment iff none exists. formal/kekule Graph edits (reference model): removing atoms or bonds and renumbering keep every atom, bond, bond direction and stereo mark on the same physical item, and the identity renumbering changes nothing, so metadata survives reordering. MCS certificates: the embedding checker decides the specification, and an embedding as large as G is G itself. formal/graph |
| Checked against the proof | The Rust output is judged by the proved checker on generated and real inputs. | Rust kekulize on about 2.2 million random graphs and 33,000 molecules: no invalid assignment and no wrong refusal. The run also found a SMILES parser bug (ring closure to itself, C11), since fixed. It re-runs in CI whenever the Rust kekulizer changes.Rust graph edits: about 950,000 edit steps compared field by field with the reference, 0 mismatches. Rust MCS: every returned query must embed into both inputs, reach every common subgraph Lean has verified, and keep its size when the inputs are swapped or renumbered. This found a real bug (an exhaustive MCS could be too small and depend on input order), fixed in #1371 for v1.2.9. |
| Differentially tested | Outputs compared with an independent implementation on pinned corpora, with versions and SHA-256 hashes recorded. | Published 1.2.7 wheel vs RDKit 2026.9.2: 1,000 of 1,000 rows agree for 8 descriptor and fingerprint operations, and every SMARTS, molecule-query and SubstructLibrary comparison on 6,000 ChEMBL/NCI rows agrees. v1.2.7 record On main, chirality-aware substructure search has 0 mismatches in 310,149 ordered comparisons with RDKit. |
Outside a documented domain, APIs fail closed: they return a typed error or
a diagnostic instead of an approximation (for example rdkit_compat options,
canonical_smiles_stable_key() and the CDXML parse report).
What is not guaranteed. The Rust implementation itself is not formally proved; the proof covers the specification and a Lean reference search, and Rust is checked against them on the inputs tested. The chemistry rules that choose which atoms must take a double bond follow RDKit and have no independent specification. MCS optimality is tested against verified witnesses, not proved by an independent maximum search, and the chemistry of edits (valence, implicit H) is outside the graph model. Canonicalization, 3D embedding, force fields and pKa/ADMET are tested, not proved. Agreement with RDKit shows parity, not correctness: where a mathematical answer exists, the specification decides. Details and per-release evidence: Validation.
import chematic
mol = chematic.from_smiles("CC(=O)Oc1ccccc1C(=O)O")
print(mol.mw, mol.logp, mol.tpsa)
print(mol.has_substructure("[OH]"))use chematic::smiles::parse;
let mol = parse("c1ccccc1").expect("valid SMILES");
println!("{}", mol.atom_count());import init, { parse_smiles, get_descriptors_json } from "@kent-tokyo/chematic";
await init();
const mol = parse_smiles("CCO");
console.log(JSON.parse(get_descriptors_json(mol)));The optional rdkit_compat Python namespace covers a documented subset;
unsupported options fail explicitly rather than silently approximating RDKit.
Stable selected paths include SMILES/SMARTS, descriptors, fingerprints, similarity and substructure search, common MOL/SDF I/O, and documented Rust/Python/Node/WASM bindings. 3D, pKa/ADMET, IUPAC, Markush/polymer, rich CDXML editing, and RDKit-style APIs remain experimental or bounded.
canonical_smiles() is not a universal identity key. Use the fail-closed
canonical_smiles_stable_key() only within its documented domain.
- When to choose chematic
- Getting started and cookbook
- Compatibility scope and RDKit migration
- Validation and benchmark methodology
- Formats and bindings
- MCP server
cargo test --workspace --all-targets --locked --exclude chematic-py
cargo test -p chematic-py --lib --no-default-features --locked
cargo clippy --workspace --all-targets --locked -- -D warningsLicensed under Apache-2.0 or MIT. See NOTICE for attribution.