TopoCompile: Molecular Generation with Exact Global Count Constraints
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.
Figures & tables
| A. Exact-valid yield (%) | ||||||||
|---|---|---|---|---|---|---|---|---|
| Method | MOSES | ZINC250K | GuacaMol | NPGen | ||||
| Common | Rare | Common | Rare | Common | Rare | Common | Rare | |
| Graph DiT | 56.64 | 5.57 | 43.36 | 8.40 | 0.49 | 4.30 | OOM | |
| STGG+ | 80.86 | 29.00 | 79.59 | 37.50 | 34.86 | 13.87 | 16.89 | 3.71 |
| FragFM+Guidance | 22.07 | 0.20 | 11.04 | 0.00 | 4.98 | 0.00 | 1.56 | 0.00 |
| GenMol+Filter | 1.86 | 0.00 | 1.46 | 0.00 | 1.66 | 0.00 | 0.00 | 0.00 |
| Method | GuacaMol | MOSES | NPGen | ZINC250K | ||||
|---|---|---|---|---|---|---|---|---|
| V.U.N. | FCD score | V.U.N. | FCD | V.U.N. | FCD | Validity | FCD | |
| DiGress ( Vignac et al., 2023 ) | 85.1 | 68.0 | 81.4 | 1.19 | 85.1 | 2.05 | 94.98 | 3.482 |
| DeFoG ( Qin et al., 2025 ) | 97.9 | 73.8 | 85.4 | 1.95 | 83.8 | 4.46 | 99.22 | 1.425 |
| GraphAF ( Shi et al., 2020 ; Lee et al., 2026 ) | – | 85.2 | 0.523 | 48.1 | 25.11 | 67.92 | 16.128 | |
| Tree-Invent ( Xu & Chen, 2023 ) | 86.2 | 58.1 | OOM | 75.3 | 8.20 | 95.43 | 5.999 | |
| FragFM ( Lee et al., 2026 ) | 95.0 | 85.8 | 86.9 | 0.58 | 92.6 | 1.34 | 99.81 | 0.630 |
Appendix figures & tables15 assets
Supplementary material from the paper’s appendix.
Appendix
| Dataset | |||||||
|---|---|---|---|---|---|---|---|
| MOSES | 6/6 | 5/4 | 6/6 | 26/26 | 32/32 | 18/18 | 32/32 |
| ZINC250K | 9/9 | 5/4 | 6/5 | 32/32 | 32/32 | 21/22 | 32/32 |
| GuacaMol | 21/21 | 5/5 | 8/8 | 32/32 | 32/32 | 32/32 | 32/32 |
| NPGen | 25/25 | 7/7 | 13/13 | 32/32 | 32/32 | 32/32 | 32/32 |
| Method | MOSES | ZINC250K | GuacaMol | NPGen | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Common | Rare | Common | Rare | Common | Rare | Common | Rare | |||||||||
| Valid | E.V | Valid | E.V | Valid | E.V | Valid | E.V | Valid | E.V | Valid | E.V | Valid | E.V | Valid | E.V | |
| Graph DiT | 67.19 | 67.19 | 31.77 | 31.77 | 61.81 | 61.81 | 46.18 | 46.18 | 12.80 | 12.80 | 8.48 | 8.48 | 44.63 | 44.63 | 35.88 | 35.88 |
| STGG+ | 100.00 | 93.06 | 100.00 | 21.01 | 100.00 | 92.71 | 100.00 | 30.90 | 100.00 | 77.98 | 100.00 | 7.14 | 100.00 | 61.63 | 99.88 | 10.88 |
| FragFM+Guidance | 97.92 | 26.82 | 40.89 | 4.43 | 100.00 | 15.97 | 97.22 | 1.74 | 93.30 | 5.51 | 91.67 | 0.15 | 98.25 | 5.13 | 92.50 | 0.13 |
| GenMol+Filter | 100.00 | 16.67 | 100.00 | 0.00 | 100.00 | 11.11 | 100.00 | 0.00 | 100.00 | 5.80 | 100.00 | 0.00 | 100.00 | 3.88 | 100.00 | 0.00 |
| Method | MOSES | ZINC250K | GuacaMol | NPGen | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Common | Rare | Common | Rare | Common | Rare | Common | Rare | |||||||||
| Valid | E.V | Valid | E.V | Valid | E.V | Valid | E.V | Valid | E.V | Valid | E.V | Valid | E.V | Valid | E.V | |
| Graph DiT | 54.17 | 41.25 | 40.62 | 5.21 | 45.00 | 29.58 | 35.42 | 10.68 | 23.12 | 5.63 | 69.38 | 1.25 | 41.52 | 9.38 | 15.62 | 0.00 |
| STGG+ | 100.00 | 94.38 | 100.00 | 32.55 | 100.00 | 95.00 | 100.00 | 65.63 | 100.00 | 98.75 | 100.00 | 4.38 | 100.00 | 95.54 | – | – |
| FragFM+Guidance | 98.75 | 88.44 | 65.23 | 15.23 | 100.00 | 86.25 | 94.53 | 26.56 | 90.00 | 49.38 | 71.25 | 2.50 | 96.88 | 53.57 | 41.07 | 0.45 |
| GenMol+Filter | 100.00 | 18.75 | 100.00 | 0.00 | 100.00 | 16.88 | 100.00 | 0.00 | 100.00 | 20.00 | 100.00 | 0.00 | 100.00 | 14.29 | 100.00 | 0.00 |
| Method | MOSES | ZINC250K | GuacaMol | NPGen | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Common | Rare | Common | Rare | Common | Rare | Common | Rare | |||||||||
| Valid | E.V | Valid | E.V | Valid | E.V | Valid | E.V | Valid | E.V | Valid | E.V | Valid | E.V | Valid | E.V | |
| Graph DiT | 57.52 | 36.69 | 53.24 | 1.27 | 53.32 | 24.31 | 61.93 | 3.22 | 21.00 | 1.37 | 35.35 | 0.00 | 35.16 | 2.25 | 35.84 | 0.00 |
| STGG+ | 100.00 | 97.51 | 100.00 | 9.14 | 100.00 | 96.43 | 100.00 | 14.77 | 100.00 | 96.09 | 100.00 | 0.68 | 100.00 | 89.55 | 92.09 | 1.17 |
| FragFM+Guidance | 99.74 | 66.15 | 75.78 | 5.90 | 100.00 | 55.80 | 91.48 | 5.68 | 91.11 | 26.27 | 70.51 | 0.10 | 98.14 | 14.45 | 66.11 | 0.00 |
| GenMol+Filter | 100.00 | 5.03 | 100.00 | 0.00 | 100.00 | 5.36 | 100.00 | 0.00 | 100.00 | 3.13 | 100.00 | 0.00 | 100.00 | 1.37 | 100.00 | 0.00 |
| Method | MOSES | ZINC250K | GuacaMol | NPGen | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Common | Rare | Common | Rare | Common | Rare | Common | Rare | |||||||||
| Valid | E.V | Valid | E.V | Valid | E.V | Valid | E.V | Valid | E.V | Valid | E.V | Valid | E.V | Valid | E.V | |
| Graph DiT | 69.34 | 56.64 | 41.60 | 5.57 | 66.02 | 43.36 | 51.07 | 8.40 | 3.61 | 0.49 | 49.51 | 4.30 | oom | |||
| STGG+ | 100.00 | 80.86 | 100.00 | 29.00 | 100.00 | 79.59 | 100.00 | 37.50 | 100.00 | 34.86 | 100.00 | 13.87 | 100.00 | 16.89 | 100.00 | 3.71 |
| FragFM+Guidance | 97.85 | 22.07 | 69.34 | 0.20 | 99.12 | 11.04 | 97.46 | 0.00 | 93.16 | 4.98 | 90.53 | 0.00 | 98.34 | 1.56 | 97.46 | 0.00 |
| GenMol+Filter | 100.00 | 1.86 | 100.00 | 0.00 | 100.00 | 1.46 | 100.00 | 0.00 | 100.00 | 1.66 | 99.90 | 0.00 | 100.00 | 0.00 | 100.00 | 0.00 |
| Dataset | Schema | Local | Factorized | Joint |
|---|---|---|---|---|
| Exact / NUE (%) | ||||
| MOSES | 41.35 / 39.90 | 72.66 / 70.43 | 100.00 / 95.79 | |
| 30.42 / 29.93 | 83.84 / 83.01 | 100.00 / 99.12 | ||
| 56.16 / 55.56 | 83.25 / 82.20 | 100.00 / 98.78 | ||
| 34.08 / 33.64 | 83.06 / 82.18 | 100.00 / 98.83 | ||
| 15.04 / 14.84 | 71.68 / 69.82 | 100.00 / 97.66 | ||
| Dataset | Schema | Metric | Uniform | Frequency | Learned |
|---|---|---|---|---|---|
| MOSES | Filters (%) | 66.39 | 73.97 | 97.51 | |
| Filters (%) | 66.91 | 76.27 | 95.66 | ||
| Filters (%) | 65.00 | 77.84 | 94.74 | ||
| Filters (%) | 64.66 | 75.19 | 96.16 | ||
| Filters (%) | 69.61 | 74.77 | 96.38 | ||
| ZINC250K | NSPDK | 0.0739 | 0.0373 | 0.0239 |
| Dataset / variant | Time (s) | States | Transitions | Peak (GiB) | Complete / total |
|---|---|---|---|---|---|
| moses/full | 0.044 | 1.35e+03 | 2.18e+04 | 4.04 | 4314/4314 |
| moses/without grouping | 0.611 | 1.35e+03 | 3.84e+05 | 4.04 | 4314/4314 |
| moses/without optional bounds | 0.0473 | 1.35e+03 | 2.18e+04 | 4.04 | 4314/4314 |
| moses/without count sum | 1.51 | 3.88e+03 | 1.06e+06 | 4.04 | 4314/4314 |
| moses/without structural pruning | 9.4 | 3.32e+04 | 5.56e+06 | 4.04 | 3722/4314 |
| zinc250k/full | 0.0488 | 1.5e+03 | 2.22e+04 | 1.36 | 5448/5448 |
| Dataset | Vocabulary size | Mol. cov. | Component cov. | Whole | Mean | Core occ./unique |
|---|---|---|---|---|---|---|
| MOSES | 14,798 | 99.29 | 99.93 | 0.0023 | 0.454 | 99.88/82.56 |
| ZINC250K | 10,651 | 97.76 | 99.79 | 0.0200 | 0.476 | 99.67/94.52 |
| GuacaMol | 57,662 | 97.33 | 99.79 | 0.0582 | 0.453 | 99.65/81.58 |
| NPGen | 70,591 | 93.25 | 99.64 | 0.1397 | 0.518 | 98.80/83.21 |
| Dataset | Ring systems | Ring size | Topology | Core | Core pair | Top core (%) | Distinct cov. (%) | Valid/attempts | |
|---|---|---|---|---|---|---|---|---|---|
| MOSES | 0.9634 | 0.9354 | 0.9992 | 0.9976 | 0.9778 | 0.8912 | 33.85 | 19.77 | 25000/25000 |
| ZINC250K | 0.9945 | 0.9946 | 0.9998 | 0.9990 | 0.9689 | 0.8351 | 36.04 | 35.62 | 25000/25000 |
| GuacaMol | 0.9970 | 0.9973 | 0.9988 | 0.9973 | 0.9262 | 0.8157 | 43.67 | 8.29 | 10000/10000 |
| Method | Specification | Enforcement point | Relation to TopoCompile |
|---|---|---|---|
| PRODIGY / ConStruct ( Sharma et al., 2024 ; Madeira et al., 2024 ) | Supported hard graph properties | Projection during diffusion | Exactness depends on a suitable property-specific projector or closure condition, rather than suffix feasibility for an additive count vector |
| Saikali & Pesant ( Saikali & Pesant, 2026 ) | SMILES grammar with physicochemical and structural constraints | CP construction and search, guided by belief propagation | General symbolic search rather than a compact component-tree completion state |
| GeAI-BLAnC ( Manibod et al., 2025 ) | Fixed-length sequence constraints, including SMILES grammar and molecular-weight ranges | CP/BP modifies the next-token distribution | Non-backtracking generation may fail to complete; full completion can use backtracking |
| Geng et al. ( Geng et al., 2026 ) | Chemical, structural, and user logical constraints | SMT assembly from neural proposals | The solver guarantees assembled outputs rather than every neural construction prefix |
| TopoCompile | Multiple component-additive count equalities | Exact DP on before every action | Every retained prefix is completable relative to the vocabulary and grammar, without trajectory backtracking or completed-sample rejection/repair |
Molecular Generation
Molecular generation develops computational methods to create chemical structures and conformations for discovery, optimization, and structure elucidation.
See all 233 papers