Masked graph modeling for molecule generation

Omar Mahmood, Elman Mansimov, Richard Bonneau, Kyunghyun Cho

Abstract

De novo, in-silico design of molecules is a challenging problem with applications in drug discovery and material design. We introduce a masked graph model, which learns a distribution over graphs by capturing conditional distributions over unobserved nodes (atoms) and edges (bonds) given observed ones. We train and then sample from our model by iteratively masking and replacing different parts of initialized graphs. We evaluate our approach on the QM9 and ChEMBL datasets using the GuacaMol distribution-learning benchmark. We find that validity, KL-divergence and Fréchet ChemNet Distance scores are anti-correlated with novelty, and that we can trade off between these metrics more effectively than existing models. On distributional metrics, our model outperforms previously proposed graph-based approaches and is competitive with SMILES-based approaches. Finally, we show our model generates molecules with desired values of specified properties while maintaining physiochemical similarity to the training distribution.

Introduction

The search for new molecules with specific properties is a fundamental challenge in chemistry and drug discovery. The chemical space is vast, and traditional methods of exploration are slow and costly. Deep generative models offer a promising alternative by learning the underlying distribution of known molecules to propose novel, synthesizable candidates.

However, existing models face significant hurdles. Autoregressive models, which generate molecules step-by-step, require an arbitrary ordering of atoms and bonds that can bias the learning process. Latent variable models, such as Variational Autoencoders (VAEs), are often difficult to train due to the complexity of approximating latent distributions. Furthermore, many models rely on SMILES strings—textual representations of molecules—which may fail to capture the inherent topological and 3D properties of chemical structures.

Masked Graph Modeling (MGM)

To address these limitations, we propose Masked Graph Modeling (MGM). Inspired by masked language models like BERT, MGM treats molecular generation as a "fill-in-the-blanks" task. Instead of generating a molecule in a fixed sequence, the model learns the conditional distribution of a subset of atoms and bonds given the rest of the molecular graph.

Architecture and Training

MGM utilizes a Message Passing Neural Network (MPNN). MPNNs are isomorphism-invariant, meaning they process the graph based on its connectivity rather than the order in which atoms are listed. During training, real molecules are partially masked—randomly replacing atom and bond types with a special [MASK] token. The MPNN is then tasked with predicting the original identities of these masked components. This approach allows for exact maximum likelihood training on conditional distributions, avoiding the approximations required by VAEs.

Iterative Sampling

Generating new molecules involves an iterative process similar to Gibbs sampling. Starting from an initial graph (which could be a noisy version of a training molecule or a random structure), the model repeatedly masks a fraction of the graph and predicts new values. Over several iterations, the structure "evolves" into a valid and often novel molecule.

Results and the Novelty-Similarity Trade-off

We evaluated MGM on the QM9 and ChEMBL datasets using the GuacaMol benchmark. A key finding of our work is the inherent trade-off between Novelty and Distributional Similarity (measured by Fréchet ChemNet Distance or KL-divergence). If a model produces molecules nearly identical to the training set, its similarity score is high, but its novelty is low. Conversely, highly novel molecules often deviate significantly from the known chemical distribution, potentially reducing their validity or drug-likeness.

Trade-off between distributional similarity (Fréchet ChemNet Distance) and novelty for MGM and baseline models.

As shown in the figure above, MGM provides a controllable "knob"—the masking rate and number of iterations—that allows researchers to navigate the Pareto frontier of this trade-off. MGM consistently matches or exceeds the performance of top-tier SMILES-based LSTMs and Transformers, while significantly outperforming previous graph-based generative models.

On the QM9 dataset, MGM achieved a uniqueness score of 0.978 and a validity of 0.886. Furthermore, the model excels at conditional generation; when prompted to target specific properties like molecular weight or lipophilicity (LogP), it generates molecules that closely match the target values while preserving the physiochemical characteristics of the training distribution.

Conclusion

Masked Graph Modeling represents a significant step forward in graph-based molecular generation. By bypassing the need for fixed-order generation and providing a robust framework for navigating the novelty-similarity trade-off, MGM offers a powerful tool for de novo design. Future work will focus on scaling the model to even larger, more complex molecules and incorporating 3D spatial information to further enhance the realism of generated structures.

Summary updated

BibTeX
@inproceedings{mahmood2021masked,
  author = {Omar Mahmood and Elman Mansimov and Richard Bonneau and Kyunghyun Cho},
  title = {{Masked graph modeling for molecule generation}},
  booktitle = {Nature Communications},
  year = {2021},
  doi = {10.1038/s41467-021-23415-2},
}
Figure