🧬 MoleCode
An LLM-native, graph-explicit molecular language
MoleCode presents molecules as code so LLMs can read, write, edit, and reason on chemistry directly — instead of reconstructing structure from cryptic strings.
Paper (arXiv:2605.16480) · GitHub · AtomFlow
What is MoleCode?
A molecule is a graph: atoms are nodes, bonds are edges. Yet LLMs are usually fed molecules as linear strings (SMILES) where the graph is implicit — so the model must rebuild the structure from syntax before it can reason.
MoleCode makes the structure the language. Every atom and bond is a typed declaration with a persistent identifier, serialized as a Mermaid graph, and deterministically, losslessly inter-convertible with SMILES / MOL via RDKit (no learned model). One grammar spans small molecules, polymers, and Markush structures.
Install
pip install molecode
Quick start
from rdkit import Chem
from molecode import mol_to_mermaid, mermaid_to_mol, mol_to_smiles
# SMILES -> MoleCode graph
graph = mol_to_mermaid(Chem.MolFromSmiles("CC(=O)Oc1ccccc1C(=O)O"), name="Aspirin")
print(graph)
# MoleCode graph -> SMILES (lossless round-trip)
assert mol_to_smiles(mermaid_to_mol(graph)) == Chem.CanonSmiles("CC(=O)Oc1ccccc1C(=O)O")
Three domains, one grammar:
from molecode.polymer import polymer_to_mermaid, mermaid_to_psmiles # polymers (×n repeat unit)
from molecode.markush import MoleCodeGraph, molecode_isomorphic # Markush ({R1}/{Boc} nodes)
from molecode.prompts import MOLECULE_SYSTEM_PROMPT, MARKUSH_SYSTEM_PROMPT # LLM system prompts
from molecode import LLMClient # optional OpenAI-compatible client
Why it matters
- Generalization, not memorization. On novel molecules SMILES accuracy falls to ~20% while MoleCode holds ~76–80% (same model, same knowledge).
- Cheaper reasoning. Sub-linear chain-of-thought growth — ~5× lower total token cost per query than SMILES.
- Scales to big, repetitive objects. Full-chain SMILES collapses toward 0% as polymer chains grow; MoleCode stays flat.
For coding agents
MoleCode also ships as an Agent Skill (Claude Code auto-discovers it; Codex
reads AGENTS.md) with a CLI for SMILES/PSMILES/Markush ↔ MoleCode conversion,
validation, isomorphism comparison, and OCSR (molecule image → MoleCode). See the
repository.
Citation
@article{yan2026molecode,
title={MoleCode unlocks structural intelligence in large language models},
author={Yan, Zhiyuan and Liu, Chen and Zhao, Boxuan and Lin, Kaiqing and Zhao, Jixiang and Wang, Yimi and Lv, Liuzhenghao and Li, Hao and Zhang, Shanzhuo and Yuan, Li and others},
journal={arXiv preprint arXiv:2605.16480},
year={2026}
}
License
MIT © 2026 AtomFlow-AI
Metadata
Release files for molecode 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| molecode-0.1.0.tar.gz | 56.3 kB | Without provenance | Details for molecode-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| molecode-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for molecode-0.1.0-py3-none-any.whl |
Total release size: 114.8 kB
Release files / molecode-0.1.0.tar.gz
| Download URL | molecode-0.1.0.tar.gz |
|---|---|
| Size | 56.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b67855f1c83135c12398cecb239be0b57d1bc07a7dde6b0d5ed6feaf6989316d
|
|
BLAKE2b-256 checksum How to use checksums |
919dcf601e30329946b174d1c8fff1181f441e98f3502a330812f8d66e16930a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.15
|
Release files / molecode-0.1.0-py3-none-any.whl
| Download URL | molecode-0.1.0-py3-none-any.whl |
|---|---|
| Size | 58.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
712783aa3e7cca02a5d012e872efb35c6704091861dba44175eae7cb9af060ee
|
|
BLAKE2b-256 checksum How to use checksums |
827aaf555e6e7dbc1dda5ea046c0864f61fa265cbb6bbe0a58916a4bb8f41ef8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.15
|
Security for molecode 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.