arXiv:2610.24511cs.LGOct 2026

Manuscript Offprint

arXiv:2610.24511

TopoCompile: Molecular Generation with Exact Global Count Constraints

Xiang Wu, Rong-Hua Li, Quanqing Xu, Kangfei Zhao, Guoren Wang

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

ABSTRACT

Molecular generation designs novel molecules with desired structures and properties. Global count constraints specify molecular size, elemental composition, and ring content without prescribing detailed structure. Property-conditioned generators steer generation toward such targets but do not guarantee exact satisfaction. We introduce TOPOCOMPILE, which combines an autoregressive component-tree generator with a dynamic-programming compiler for supported component-additive integer counts. TOPOCOMPILE represents molecules as trees of intact ring systems and individual atoms, making each supported count additive over components. At each step, an autoregressive Transformer scores component and attachment actions, while the compiler masks actions with no target-satisfying completion. Within the fixed component vocabulary and typed attachment rules, constrained decoding guarantees exact equality for supported non-negative, component-additive integer counts. Applied at inference time, these checks let the same trained generator support different targets and count combinations without retraining. Across four benchmarks, TOPOCOMPILE achieves 100% Exact-valid yield for Common and Rare four-count target groups; the strongest baseline within each dataset reaches 44.9% or less on Rare targets. In unconditional generation, it achieves the highest validity or valid-unique-novel (V.U.N.) among the compared methods across all four benchmark datasets.

1 INTRODUCTION

Designing molecules with specified structural and physicochemical properties is a central problem in drug discovery and materials design. Neural molecular generators address this problem by learning distributions over molecular structures and using them to produce chemically plausible candidates beyond the training set (Gómez-Bombarelli et al., 2018; Jin et al., 2018; Zang & Wang, 2020; Shi et al., 2020; Luo et al., 2021). Recent advances in diffusion, flow, and autoregressive models have further improved molecular generation across graph and sequence representations (Vignac et al., 2023; Jolicoeur-Martineau et al., 2025; Wang et al., 2025).

In practical molecular design, chemically plausible candidates often also need to meet specific structural requirements. Global count constraints provide a direct way to express these requirements: users can specify molecular size, elemental composition, and ring content without prescribing detailed connectivity. Such constraints arise in molecular structure elucidation, where the molecular formula is known but the atom connectivity remains unresolved (Stravs et al., 2022; Bohde et al., 2025). They also support controlled comparison libraries for virtual screening and molecular-model evaluation (Imrie et al., 2021), while exact ring counts enable targeted exploration of atypical topologies such as high-cycle-rank molecules. The generator chooses detailed structures from the learned distribution while the user controls global molecular characteristics.

Existing approaches differ in how precisely they control generation and what users must specify. Property-conditioned generators steer generation toward multiple requested attributes but generally do not guarantee exact satisfaction (Liu et al., 2024; Jolicoeur-Martineau et al., 2025; Lee et al., 2026). Structure-conditioned methods can provide stronger structural control, but require a user-specified scaffold or partial structure, fixing part of the molecule in advance (Xu & Chen, 2023; Lee et al., 2025). Spectrum-conditioned methods instead require a mass spectrum and molecular formula (Bohde et al., 2025). Hard-constraint methods enforce selected rules through projection, search, or symbolic reasoning (Sharma et al., 2024; Madeira et al., 2024; Saikali & Pesant, 2026; Geng et al., 2026). Existing approaches therefore do not directly address our setting: satisfying multiple count constraints exactly while leaving the scaffold and partial structure unspecified.

To achieve this, we build molecules from scratch and check before each addition whether the requested counts remain achievable. A locally valid addition can still make these targets unreachable, yet enumerating every possible completion would require a combinatorial search over future molecular structures. We address both difficulties with a lossless component-tree representation. We cut each bridge bond, whose removal disconnects the molecular graph, and treat every intact ring system and every atom outside rings as a component. The resulting component-level graph is a tree. Each supported count is the sum of fixed, non-negative integer contributions from these components. Each component also has attachment ports that identify the local atom and bond type for a connection. Under a fixed component vocabulary and attachment rules, whether the generator can complete a partial molecule depends only on the number of components remaining, unmatched ports by bond type, and remaining target counts. A dynamic program can therefore test for an exact completion using this compact state, without enumerating complete molecular graphs.

Building on this representation, we introduce TopoCompile, which combines an autoregressive Transformer for component-tree generation with a dynamic-programming compiler. At each step, the Transformer scores component and attachment choices, while the compiler removes choices that leave no target-satisfying completion. The generator then samples from the renormalized probabilities, preserving its relative preferences among the remaining choices. Thus, the generator learns to construct plausible molecules, while the compiler ensures that the requested counts remain achievable. Because we apply constraints only during decoding, the same trained generator supports different target values and count combinations without retraining. Within the fixed component vocabulary and attachment rules, constrained decoding guarantees target counts for every molecule.

Our contributions are:

• Exact-control interface. TopoCompile provides exact control over supported global counts while leaving the scaffold, component identities, and component-tree layout unspecified. The same trained generator supports different target values and combinations of supported counts without retraining.

• Completion-checking compiler. We derive a dynamic program over the remaining component count, unmatched ports by bond type, and remaining target counts. We prove that it determines exactly whether a target-satisfying completion exists under the fixed vocabulary and attachment rules, enabling exact decoding without rejection or repair.

• Evaluation. Across four benchmarks, TopoCompile achieves 100% exact-valid yield for both frequently and infrequently observed four-count targets, whereas the strongest baseline in each dataset reaches at most 44.9% on infrequent targets. In unconditional generation, it achieves the highest validity or yield of valid, unique, novel molecules among the compared methods on all four benchmarks.

References (76)