Table of Contents
Fetching ...

Coder as Editor: Code-driven Interpretable Molecular Optimization

Wenyu Zhu, Chengzhu Li, Xiaohe Tian, Yifan Wang, Yinjun Jia, Jianhui Wang, Bowen Gao, Ya-Qin Zhang, Wei-Ying Ma, Yanyan Lan

TL;DR

MECo tackles molecular optimization by bridging reasoning and execution through code generation. It reformulates editing as an intention-to-code pipeline, where a reasoning LLM outputs editing actions and rationale, and a coder LLM translates these into executable RDKit-based scripts that modify the molecular graph. Trained on synthetic edits and evaluated on realistic reaction- and activity-derived edits, MECo achieves near-perfect edit fidelity (~98%) and substantially improves structure–intention consistency over direct SMILES generation across six optimization tasks. The framework enables interpretable, controllable, and reproducible design workflows, laying the groundwork for high-fidelity human–AI collaboration in real-world drug discovery.

Abstract

Molecular optimization 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 optimization for LLMs as a cascaded framework: generating human-interpretable editing intentions from a molecule and property goal, 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 optimization 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.

Coder as Editor: Code-driven Interpretable Molecular Optimization

TL;DR

MECo tackles molecular optimization by bridging reasoning and execution through code generation. It reformulates editing as an intention-to-code pipeline, where a reasoning LLM outputs editing actions and rationale, and a coder LLM translates these into executable RDKit-based scripts that modify the molecular graph. Trained on synthetic edits and evaluated on realistic reaction- and activity-derived edits, MECo achieves near-perfect edit fidelity (~98%) and substantially improves structure–intention consistency over direct SMILES generation across six optimization tasks. The framework enables interpretable, controllable, and reproducible design workflows, laying the groundwork for high-fidelity human–AI collaboration in real-world drug discovery.

Abstract

Molecular optimization 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 optimization for LLMs as a cascaded framework: generating human-interpretable editing intentions from a molecule and property goal, 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 optimization 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.
Paper Structure (39 sections, 5 equations, 6 figures, 4 tables, 1 algorithm)

This paper contains 39 sections, 5 equations, 6 figures, 4 tables, 1 algorithm.

Figures (6)

  • 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.
  • 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 relative improvements of MECo over direct.
  • Figure 4: Representative case study of molecular optimization. (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.
  • Figure 5: Visualization of manual check criteria.
  • ...and 1 more figures