arXiv:2610.02186cs.LGOct 2026

Manuscript Offprint

arXiv:2610.02186

Higher-Order Molecular Grammars for Generative and Foundation Models in Chemistry

Yiming Huang, Yujie Zeng, Vijay Prakash Dwivedi, Simone Foti, Jianmin Wang, Jure Leskovec, Tolga Birdal

ABSTRACT

Molecular learning models are strongly shaped by their underlying representations. Yet standard sequential and graph formalisms struggle to explicitly encode higher-order topology, such as ring systems and recurring motifs. Existing higher-order representations can capture these structures directly, but they are often computationally demanding and difficult to decode into valid molecules. Here, we introduce Higher-order Grammar Representation (HGR), a principled, topology-aware framework that lifts molecules to combinatorial complexes and parses each complex into a compact sequence of production rules under a context-free higher-order grammar. By serialising higher-order topology into rule sequences, HGR makes these structures directly compatible with standard sequence models, avoiding the computational overhead of explicit higher-order encodings while preserving topological expressiveness. To reduce benchmark bias towards simple ring systems, we construct RingDiv, a ring-enriched benchmark containing 1.18 million molecules, including the curated RingDiv300k subset, and introduce the ring diversity index (RDI) to quantify ring-system coverage. In molecular generation, HGR-based models uniquely combine 100% validity by construction with leading distributional alignment, ranking first in FCD on all five generation benchmarks. In representation learning, HGR-FM achieves the highest mean AUC across seven MoleculeNet benchmarks under both transfer protocols, improving on the strongest baseline by 8.3 and 3.3 AUC points under probing and full fine-tuning, respectively. Collectively, these results establish HGR as an efficient higher-order representation for molecular generation and transferable representation learning.

Main

Molecular representation is a cornerstone of computational chemistry and drug design, bridging the gap between chemical structures and their biological, chemical, or physical properties 1^{1}. Effective representations enable efficient and precise navigation of chemical space and thus are essential for drug discovery tasks, including virtual screening, activity prediction, and scaffold hopping 2^{2}. However, current molecular representations struggle to encode higher-order structural information, that is, relations involving more than two atoms or molecular substructures, for generation and other tasks 3,4^{3,4}. This limitation matters because many chemically important structures, including rings and functional groups, are intrinsically higher-order 5^{5}. Ring systems constrain molecular shape and position substituents 6^{6}, whereas functional groups establish interaction sites through polarity, hydrogen bonding and acidity. Together, these higher-order units connect atom-level connectivity to meso-scale chemical organisation and, ultimately, molecule-level behaviour, including reactivity, metabolic stability and interactions with biological targets 7,8^{7,8}. Our statistical analysis further shows that ring-system usage is highly concentrated, with a small set recurring across many drug-like molecules. This concentration makes ring-system diversity tractable to model. Beyond chemistry, higher-order relations are increasingly studied across diverse contexts, including the neural population activity underlying spatial navigation 9^{9}, group hunting behaviours in ecological competitive networks 10^{10}, and recommendations from multiple friends in social networks 11^{11}. Nevertheless, higher-order topology has often been encoded only implicitly, reduced to pairwise graphs, or treated as isolated motifs 5^{5}.

Formally, molecular representation refers to the process of encoding molecules into mathematical or computational formats that algorithms can process to model, analyse, and predict molecular behaviour. Broadly, representations fall into three categories: early atom-level linear representations, graph-based representations, and the emerging higher-order topological representations (Fig. 1b). In addition, there exist various non-invertible mappings, such as molecular fingerprints 12^{12}, which transform molecules into computationally convenient forms (e.g., vectors in feature space) but generally lack strict reversibility.

Simplified Molecular-Input Line-Entry System (SMILES) 13^{13} remains one of the most widely used molecular representations, using parentheses and numbers to denote branching points and ring closures. Although compact and interpretable, SMILES is prone to generating invalid molecules due to inherent syntactic and semantic flaws. To mitigate these challenges, Self-Referencing Embedded Strings (SELFIES) 14^{14} improve robustness and validity in deep generative models, albeit at the cost of simplicity, interpretability and compactness. With the rapid rise of large language models, sequence-based representations have regained attention in molecular modelling and drug discovery 15,16^{15,16}. However, such string-based representations still do not explicitly encode hierarchical or meso-scale molecular structure. Molecular graphs provide a direct representation of atoms and bonds, and graph neural networks (GNNs) have been widely used for molecular learning and generation 17,18^{17,18}. Despite these advances, GNNs face several limitations. Standard message-passing GNNs are bounded by the Weisfeiler–Lehman (WL) test 19^{19}; deeper architectures can suffer from over-smoothing 20^{20} and over-squashing 21^{21}, which hinder long-range dependency modelling; and simple non-learnable readout functions can constrain graph-level representations. More fundamentally, both sequence- and graph-based representations leave hierarchical higher-order topology implicit, limiting their ability to transfer across structure-sensitive tasks 22^{22}.

Recently, higher-order structures have gained increasing attention in molecular modelling because they expose multi-way molecular organisation in forms useful for interpretability, efficient modelling and synthetic-accessibility analysis 5,23^{5,23}. A natural entry point to higher-order molecular topology is the ring system. Rings provide basic molecular shape, tune rigidity and substituent geometry, and strongly influence global physicochemical and electronic properties. Improved synthetic methods and building-block availability further broaden accessible ring chemical space, often leveraging conformational constraints to enhance potency and selectivity 7,24^{7,24}. Indeed, only a small fraction of bioactive molecules lack rings, and the vast majority of FDA-approved small-molecule drugs contain at least one ring 8^{8}. Moreover, molecules are inherently hierarchical 3^{3}. The atom level encodes fine-grained local connectivity and semantic similarity. The meso-scale captures chemically meaningful substructures, such as rings, functional groups, linkers and pharmacophores, that act as property-determining “semantic units”. These units govern polarity, hydrogen bonding, acidity, reactivity and conformational rigidity, linking local chemistry to global topology. The molecule level then summarises the overall structural patterns. If a model relies only on single-level reconstruction or contrastive supervision, it can either overemphasize local validity while producing globally incoherent assemblies (e.g., implausible motif fusion/attachment) or preserve coarse global structure at the expense of chemically faithful local details, making it difficult to maintain local consistency and global stability simultaneously.

Motif-based representations provide one pragmatic route to capture such higher-order topology. They can be interpreted within a hypergraph framework, where each fragment is treated as a hyperedge connecting multiple atoms 25^{25}. This shift from atom- to fragment-level units parallels the transition from character- to word-level representations in natural language processing, and can yield more compact and expressive molecular encodings. These approaches broadly fall into fragment-string and fragment-graph representations. Fragment-string methods represent molecules as sequences of substructure units, including SMILES Pair Encoding (SPE) 26^{26}, t-SMILES 1^{1}, Group SELFIES 27^{27}, and fragSMILES 28^{28}. These methods preserve the convenience of string-based modelling by serialising substructures into a one-dimensional order, but relations among fragments remain implicit in the string syntax. Graph-based fragment methods instead operate on fragment graphs, including motif-assembly generators and graph grammars. For example, JT-VAE 29^{29} first generates a tree and then expands selected nodes by attaching substructures from a learned vocabulary. HierVAE 30^{30} follows the same vocabulary-based principle but uses a multiresolution representation to improve combinatorial attachment and generate larger molecules. Graph grammars 31−34^{31-34} represent graphs through derivations over reusable subgraph rules, making them the closest existing family to HGR among fragment-based methods. However, graph grammars often face a trade-off between rule

2/43 expressiveness and reuse. Context-specific fragments yield sparse, long-tailed rule vocabularies, whereas generic fragments weaken chemically meaningful motif semantics. Taken together, these fragment-based representations capture multi-atom interactions by treating fragments as higher-order units, but they do not explicitly encode the hierarchical part-whole organisation linking atoms, motifs, ring systems and larger molecular structures.

Topological deep learning (TDL) offers a general route beyond sequence-, graph- and fragment-based representations by modelling multi-way relations with hypergraphs, simplicial complexes, cell complexes and combinatorial complexes 22,35^{22,35}. Such structures are typically encoded using families of incidence (boundary) matrices. Although this makes higher-order structure explicit, generating over such structures is difficult because the incidence relations across topological dimensions must remain mutually consistent. For example, a face generated in an edge–face incidence matrix is structurally inconsistent if its boundary edges are absent from the node–edge incidence matrix. Molecular generation with incidence-based representations must navigate both the vast chemical space and a space of possible higher-order incidence relations that grows combinatorially with molecular size. Together with the limitations of sequence-, graph- and fragment-based representations discussed above, these challenges reveal a common trade-off between explicit higher-order structure and computational tractability. Sequence and graph encodings leave higher-order topology implicit, fragment-based methods do not explicitly encode its hierarchy, and incidence-based encodings make scalable generation difficult. Resolving this trade-off calls for an expressive and lossless representation that remains computationally tractable for both molecular generation and property prediction.

In this work, we propose Higher-order Grammar Representation (HGR), a principled and lossless representation that converts hierarchical higher-order molecular topology into a compact sequence of production rules. The central idea of HGR is to (i) lift a molecular graph into a combinatorial complex whose cells correspond to hierarchical and higher-order (multi-atom) relations, then (ii) parse each molecular complex into a sequence of production rules via a bottom-up contraction procedure, thereby inducing a higher-order grammar that supports exact decoding. Intuitively, HGR treats molecules as assemblies of reusable higher-order structural “words”, while retaining the attachment information needed for exact reconstruction. Each lifted cell contributes one production-rule token, and the resulting ordered sequence preserves the complex’s hierarchy across atom, motif and molecule scales. This sequence formulation makes HGR compatible with mature sequence architectures while avoiding the combinatorial cost of generation over higher-order incidence matrices. To address rule explosion, we introduce two lifting schemes, Motif-Induced Grammar (MIG) and Ring Scaffold Grammar (RSG), which respectively simplify complex anchor interfaces and stabilise lifting around ring systems. Evaluating higher-order molecular representations also requires benchmarks that adequately cover complex ring systems, which are underrepresented in commonly used molecular generation datasets. We therefore construct RingDiv, a ring-enriched benchmark of 1.18 million molecules, together with its topology-balanced RingDiv300k subset, to evaluate molecular generation in ring-diverse chemical space.

In summary, we make five contributions: (i) Lifting. We introduce two data-driven lifting strategies that convert a molecular graph into a combinatorial complex while controlling boundary complexity and rule explosion. (ii) Higher-order grammar. We propose HGR, a grammar-induction framework that serialises a molecule's hierarchical higher-order topology into a compact HGR string and enables exact reconstruction through deterministic reverse derivation. (iii) Structure-aware rule encoding. We initialise production-rule tokens with permutation-invariant structural descriptors, yielding rule embeddings that reflect topological similarity and generalise to unseen rules. (iv) Generative and transfer applications. We instantiate HGR in two complementary regimes: grammar-constrained molecular generation through VAE-prior sampling (HGR-VAE) or latent diffusion sampling (HGR-LDF), and foundation modelling (HGR-FM) for transferable representation learning. Both regimes operate on the same HGR representation, enabling reuse across generative and predictive tasks. (v) RingDiv benchmark. We construct RingDiv, a ring-enriched benchmark that mitigates the ring-system bias of existing datasets. Our evaluation yields three key insights: (i) the grammar-based generators are valid by construction and achieve strong chemical and graph-structural distributional alignment; (ii) the same representation is broadly transferable, letting a single pretrained model support multiple downstream tasks and improve property prediction; and (iii) ablations attribute these gains to the explicit encoding of hierarchical higher-order topology rather than to sequence modelling alone, identifying it as a useful inductive bias. Relative to our preliminary report 36^{36}, the present study substantially extends the generative framework by refining HGR-VAE and introducing latent diffusion sampling, together with a fuller methodological

3/43 specification and broader evaluation across five molecular-generation benchmarks. We further provide a more detailed characterisation of RingDiv, expanded ablation studies, and analyses of chemical and topological generation fidelity.

References (44)