An LLM-native, graph-explicit molecular language (Mermaid-based) for molecules, polymers, and Markush structures.
Project description
🧬 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
Project details
Release history Release notifications | RSS feed
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 molecode-0.1.0.tar.gz.
File metadata
- Download URL: molecode-0.1.0.tar.gz
- Upload date:
- Size: 56.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b67855f1c83135c12398cecb239be0b57d1bc07a7dde6b0d5ed6feaf6989316d
|
|
| MD5 |
98fd68d22b3b068a7937de80e6eba96f
|
|
| BLAKE2b-256 |
919dcf601e30329946b174d1c8fff1181f441e98f3502a330812f8d66e16930a
|
File details
Details for the file molecode-0.1.0-py3-none-any.whl.
File metadata
- Download URL: molecode-0.1.0-py3-none-any.whl
- Upload date:
- Size: 58.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
712783aa3e7cca02a5d012e872efb35c6704091861dba44175eae7cb9af060ee
|
|
| MD5 |
e8df69a413584fdaecacdea87d8c89ab
|
|
| BLAKE2b-256 |
827aaf555e6e7dbc1dda5ea046c0864f61fa265cbb6bbe0a58916a4bb8f41ef8
|