MoleCode unlocks structural intelligence in large language models

Zhiyuan Yan, Chen Liu, Boxuan Zhao, Kaiqing Lin, Jixiang Zhao, Yimi Wang, Liuzhenghao Lv, Hao Li, Shanzhuo Zhang, Li Yuan, Fanyang MoarXiv 2026

TL;DR

MoleCode is a training-free, graph-explicit molecular language designed to let Large Language Models (LLMs) reason directly over molecular topology rather than decoding it from linear strings. By representing atoms and bonds as typed entities with persistent identifiers, it shifts the computational burden away from syntax reconstruction toward productive chemical reasoning. This representational shift dramatically improves LLM performance on complex, unfamiliar molecules and large structures like polymers while reducing overall inference costs.

What Problem Does This Paper Address?

When we ask LLMs to solve chemistry problems, we typically feed them molecules formatted as SMILES strings—one-dimensional text representations that flatten a 2D or 3D molecular graph. While compact, SMILES hides the molecule's actual topology behind strict sequential syntax, where branches are marked by parentheses and ring closures by matching numbers.

Consequently, before an LLM can execute a chemical operation (like predicting a reaction or optimizing a property), it must first spend significant internal computational effort reconstructing the implicit graph structure from the text. This syntactic bottleneck causes LLMs to struggle heavily when dealing with large, complex, or structurally unfamiliar molecules.

MoleCode makes molecular structure explicit, editable, and operable for LLMs compared to implicit string methods like SMILES.

Methods

The authors introduce MoleCode, an LLM-native molecular language that makes topology completely explicit within the prompt context without modifying the model's weights. MoleCode relies on a simple grammar composed of three primitives:

  • Subgraph: Defines structural scopes (e.g., a whole molecule, a functional group, or a polymer repeat unit).
  • Node: Represents typed entities (atoms or higher-level chemical labels) using persistent, unique identifiers (e.g., Mol_C_4).
  • Edge: Declares explicit relations between nodes using human- and machine-readable operators (e.g., --- for single bonds, === for double bonds).

Conversion between standard formats (like SMILES or RDKit MOL files) and MoleCode is entirely deterministic and bidirectional. Furthermore, MoleCode allows inline comments (%%), enabling models to attach reasoning chains directly to specific graph components.

Datasets

The framework was evaluated across several diverse benchmarks:

  • Unified Small-Molecule Benchmark: Spanning 4 task families (molecular editing, generation, understanding, and analysis) compiled from existing benchmarks like TOMG, ChEBI-20, ChemIQ, and ChemCoTBench.
  • PubChem Memorization Benchmark: A newly constructed dataset stratifying 150 molecules into three exposure tiers (popular, classical, and novel) based on PubChem occurrence frequency to test structural generalization.
  • ChemLLM-Polymer Benchmark: A new benchmark introduced in this paper to evaluate structure scaling (carbon counting), polymer editing, and de novo polymer generation.
  • Higher-Order Benchmarks: Utilizing the Markush subset of the MolParser-7M benchmark and reaction data from MechFinder.

Key Insights and Ideas

  • Reallocating Inference Tokens: With SMILES, the chain-of-thought (CoT) token cost scales superlinearly ($C^{1.65}$) with carbon count because the model wastes tokens deciphering the syntax. MoleCode flips this dynamic: though the initial prompt is longer, the CoT reasoning scales sublinearly ($C^{0.52}$), resulting in a lower total token cost per query for complex tasks.
  • Generalization Over Memorization: SMILES relies heavily on pattern matching from pretraining data. When tested on completely novel molecules, SMILES performance collapses. MoleCode maintains stable accuracy across popular and novel molecules alike because the topology is laid bare in the context window.
  • Chemically Grounded Optimization: Because atoms and bonds are exposed as addressable objects, LLMs can perform localized graph edits (e.g., swapping an ether group for a methylene). This allows the model to successfully optimize properties like lipophilicity ($\text{LogP}$) and solubility while maintaining high structural similarity to the starting compound.
MoleCode reallocates inference from structural reconstruction to productive reasoning, scaling sublinearly with carbon count.

Key Results

Evaluating frontier models like Gemini-3-Pro, Gemini-2.5-Flash, and DeepSeek-R1 revealed massive performance leaps:

  • Property & Reaction Prediction: For Gemini-3-Pro, reaction prediction accuracy shot up from 58.8% (SMILES) to 95.0% (MoleCode), and molecular formula prediction increased from 58.0% to 90.0%.
  • Familiarity Robustness: On complex, novel molecules, Gemini-2.5-Flash's accuracy dropped to 16% using SMILES but remained at 72% using MoleCode.
  • Polymer Scaling: In polymer carbon-counting tasks, full-chain SMILES accuracy collapsed to 0% as chain lengths grew. MoleCode maintained near-perfect accuracy even for polymers exceeding 250 repeat units by representing the repetition symbolically (e.g., $\times n$).
Performance comparison across task families and structural complexity tiers showing consistent improvements over SMILES.

Limitations and Future Work

Despite its success, MoleCode has a few limitations:

  • Verbosity: Because it explicitly defines every node and edge, MoleCode inputs consume significantly more prompt tokens than compact SMILES strings.
  • No Inherent Knowledge Creation: MoleCode cannot grant an LLM chemical knowledge it doesn't already possess; smaller or less capable models may still output chemically invalid graphs.
  • Domain Extensions Needed: The current grammar lacks primitives required for specialized domains like organometallic chemistry, inorganic crystalline solids, or complex biological macromolecules, which require explicit handling of coordination geometry and periodicity.

The authors suggest that the logical next step is integrating graph-explicit languages like MoleCode directly into the pretraining phase of scientific LLMs, allowing models to natively perceive topology from day one.

Summary updated

BibTeX
@misc{yan2026molecode,
  author = {Zhiyuan Yan and Chen Liu and Boxuan Zhao and Kaiqing Lin and Jixiang Zhao and Yimi Wang and Liuzhenghao Lv and Hao Li and Shanzhuo Zhang and Li Yuan and Fanyang Mo},
  title = {{MoleCode unlocks structural intelligence in large language models}},
  year = {2026},
  eprint = {2605.16480},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2605.16480},
}
Figure