Organizations: Institute for AI Industry Research, Tsinghua University · Department of Computer Science and Technology, Tsinghua University · School of Pharmaceutical Sciences, Peking University · University of Electronic Science and Technology of China
Molecular design is a central task in drug discovery that requires precise structural reasoning and domain knowledge. While large language models (LLMs) have shown promise in generating high-level editing intentions in natural language, they often struggle to faithfully execute these modifications, particularly when operating on non-intuitive representations like SMILES. We introduce MECo, a framework that bridges reasoning and execution by translating editing actions into executable code. MECo reformulates molecular modification for LLMs as a cascaded framework: generating human-interpretable editing intentions from a molecule and design objective, followed by translating those intentions into executable structural edits via code generation. Our approach achieves over 98% accuracy in reproducing held-out realistic edits derived from chemical reactions and target-specific compound pairs. On downstream benchmarks spanning physicochemical properties and target activities, MECo substantially improves consistency by 38-86 percentage points to 90%+ and achieves higher success rates over SMILES-based baselines while preserving structural similarity. By aligning intention with execution, MECo enables consistent, controllable and interpretable molecular design, laying the foundation for high-fidelity feedback loops and collaborative human-AI workflows in drug discovery.
Figures & tables
Figure 1: Motivation for MECo: bridging reasoning and execution in molecular optimization through code generation. Left: Human chemists reason over molecular graphs to design targeted edits, such as modifying a functional group to adjust polarity or introducing new interactions, and annotate them directly on the structure. Top right: Reasoning LLMs can generate similar high-level rationales and editing actions, but often struggle to execute them faithfully due to the limitations of sequential molecular representations like SMILES. Bottom right: MECo addresses this gap by introducing a coder LLM that translates editing actions into executable code, enabling precise, interpretable, and reproducible structural edits on the molecular graph.
Figure 2: Overview of the MECo framework. (A) Synthetic data construction for model training. (B) Realistic data for testing on unseen molecular modifications derived from both reaction and activity data, reflecting chemical transformations observed in practice and in human reasoning. Modifications are categorized into terminal or core replacements. (C) End-to-end workflow and evaluation of the framework. The coder LLM is evaluated both independently and within the integrated pipeline. A reasoning LLM first generates rationales and editing actions, which are then executed by the coder model to produce optimized molecules. Outputs are subsequently reviewed by human experts to assess the alignment between generated structures and intended editing actions.
Action
Model
Terminal replacement
Core replacement
Reaction-derived
Target-specific
Target-specific
Direct
Qwen2.5-7B-Instruct
0.5
1.3
0.0
Qwen2.5-7B-Instruct-FT
38.7
7.4
2.7
CodeGen
Qwen2.5-7B-Instruct
35.4
3.7
4.1
Qwen2.5-Coder-7B-Instruct
50.3
9.9
12.2
Qwen2.5-Coder-7B-Instruct-FT (ours)
99.9
98.3
98.3
Table 1: Execution accuracy (%) across realistic edit benchmarks. Rows are shaded to distinguish model variants: Qwen2.5 , Qwen2.5-Coder , and finetuned versions (darker, denoted by -FT).
Property optimization tasks
Model
Penalized logP
Solubility
QED
VR%
SR%
Sim
CR%
VR%
SR%
Sim
CR%
VR%
SR%
Sim
CR%
W/o thinking
GPT-4o
22
8
0.11
–
41
35
0.21
–
31
17
0.11
–
Gemini-2.0-flash
66
44
0.27
–
32
28
0.13
–
64
54
0.26
–
DeepSeek-V3
53
21
0.20
–
52
44
0.21
–
48
33
0.18
–
Table 2: Performance on molecular optimization tasks. Each task reports validity rate (VR%), success rate (SR%), mean similarity to the source molecule (Sim), and consistency rate (CR%). Bold numbers highlight the best value in each column. Note: GPT-5 refused to answer a small number of samples.
Figure 3: Incremental bar plots comparing direct generation (light bars) and MECo (dark stacked bars) across tasks and metrics under two different reasoning LLMs. Numbers above the bars indicate the absolute improvements of MECo over direct.
Figure 4: Representative case study of molecular modification. (A) Direct generation produces uncontrolled changes and low similarity, often leading to unrealistic score inflation or failed optimization; MECo achieves improved scores and higher similarity through interpretable, chemistry-preserving edits. (B) MECo demonstrates coherent consistency across the reasoning–execution–analysis pipeline.
Appendix figures & tables10 assets
Supplementary material from the paper’s appendix.
Appendix
Category
Name
SMILES
Halogens
Fluoro
[*:1]F
Chloro
[*:1]Cl
Bromo
[*:1]Br
Iodo
[*:1]I
Alkyl
Methyl
[*:1]C
Ethyl
[*:1]CC
Appendix
Table 3: Common substituents for synthetic data.
Category
Name
SMILES
Aromatic linkers
Meta-phenylene
[:1]c1cc([:2])ccc1
Para-phenylene
[:1]c1ccc([:2])cc1
Ortho-phenylene
[:1]c1c([:2])cccc1
Carbonyl-based linkers
Amide
[:1]C;!R[N;!R][:2]
Reverse amide
[:1][N;!R]C;!R[:2]
Ester
[:1]C;!R[O;!R][:2]
Appendix
Table 4: Common molecular linkers for synthetic data.
Figure 5: Multiple possible permutations in symmetry-to-asymmetry core replacement.
Figure 6: t-SNE for fragments in synthetic training data construction and realistic edit test set.
Action/Model
Molecule Number Style
Attachment Point
Whole SMILES
Fragment Attachment Style
CodeGen / Coder
Numbered
[C:1]N
0%
0%
Rooted
-CN
20%
1%
Asterisked
*CN
6%
6%
Direct / General
Numbered
[C:1]N
0%
3%
Rooted
-CN
12%
6%
Appendix
Table 5: Accuracy across different SMILES attachment styles and numbering strategies.
Table 6: Final prompt for code-based molecular editing
Figure 7: Execution accuracy of the finetuned code LLM (Qwen2.5-Coder-7B-Instruct-FT) across bins of structural similarity (ECFP–Tanimoto) and string similarity (SequenceMatcher), evaluated on data from different sources and for both terminal and core replacements. The size of the semi-transparent halo around each point reflects the number of test samples in that bin.
Table 7: Prompt wrapper in the molecular modification task.
Figure 8: Visualization of manual check criteria.
Figure 9: Bar plots of molecular optimization performance across six tasks, showing property improvement (top row) and structural similarity (bottom row) for Direct generation and MECo for DeepSeek-R1 and Gemini-2.5-Pro.
The Hong Kong University of Science and Technology (Guangzhou) · Nanjing University of Aeronautics and Astronautics · The 63rd Research Institute, National University of Defense Technology, Nanjing