Generative Models (DGMG & JT-VAE)
Relevant source files
The following files were used as context for generating this wiki page:
- examples/generative_models/dgmg/README.md
- examples/generative_models/jtvae/README.md
- python/dgllife/model/model_zoo/dgmg.py
- examples/generative_models/dgmg/train.py
- examples/generative_models/dgmg/eval.py
- examples/generative_models/jtvae/train.py
- examples/generative_models/jtvae/vocab.py
- tests/data/test_datasets.py
The DGL-LifeSci project implements advanced deep generative models to learn the distribution of molecular structures and generate new molecules with similar properties. The primary focus is on two architectures: Deep Generative Models of Graphs (DGMG) and Junction Tree Variational Autoencoders (JT-VAE, also referred to as JTNN). These models address the challenge of molecular graph generation by either progressively building the graph atom-by-atom (DGMG) or by utilizing a hierarchical approach that first generates a tree structure representing chemical clusters before assembling the final graph (JT-VAE).
These generative capabilities enable downstream tasks such as de novo drug design, molecule optimization, and molecular property exploration. DGMG is an auto-regressive model that adds nodes and edges sequentially, while JT-VAE is an auto-encoder that maps molecular graphs to a latent space composed of both tree-structured and graph-structured representations.
Sources: examples/generative_models/dgmg/README.md, examples/generative_models/jtvae/README.md, python/dgllife/model/model_zoo/dgmg.py:461-480
Deep Generative Models of Graphs (DGMG)
DGMG generates molecular graphs by executing a sequence of decisions to add nodes (atoms) and edges (bonds). It uses a state-machine-like approach where at each step, the model decides whether to add a new node, which type it should be, whether to add an edge to the new node, and which destination node the edge should connect to.
Architecture and Components
The DGMG implementation consists of several specialized neural network modules that handle different stages of the generation process:
| Component | Description |
|---|---|
GraphEmbed | Computes a global representation of the current molecular graph using node gating and linear transformations. |
GraphProp | Performs message passing rounds to update atom representations based on their neighbors and bond types. |
AddNode | An agent that predicts whether to terminate generation or add a specific type of atom. |
AddEdge | An agent that decides whether to add a bond from the newly added atom. |
ChooseDestAndUpdate | An agent that selects a destination node for a new bond and triggers graph propagation to update states. |
Sources: python/dgllife/model/model_zoo/dgmg.py:168-450
Decision Flow and Logic
The model follows a hierarchical decision-making process. The logic is encapsulated in the rollout (for generation) and teacher_forcing (for training) methods.
This diagram illustrates the auto-regressive cycle of adding atoms and bonds until the termination signal is sampled.
Sources: python/dgllife/model/model_zoo/dgmg.py:539-563
Graph Propagation and Message Passing
The GraphProp module updates the hidden state $h_v$ of each atom. It uses a GRU-based update rule after aggregating messages from neighbors. Messages are formed by concatenating the source atom representation and the bond representation.
DGMG performs internal message passing every time a new bond is added to ensure node representations reflect the updated topology.
Sources: python/dgllife/model/model_zoo/dgmg.py:207-264
Junction Tree Variational Autoencoder (JT-VAE / JTNN)
JT-VAE addresses the validity of generated molecules by representing them as junction trees where each node is a chemical cluster (e.g., rings or bonds). This bypasses the issue of invalid intermediate states during atom-by-atom generation.
Architecture Overview
The model encodes a molecule into two latent vectors: $z_T$ (tree structure) and $z_G$ (molecular graph).
- Encoder: Decomposes the graph into a junction tree and encodes both.
- Decoder:
- Tree Decoder: Generates the junction tree structure node-by-node.
- Graph Decoder: Assembles the actual molecular graph by combining the clusters defined in the tree nodes.
Sources: examples/generative_models/jtvae/README.md, python/dgllife/model/model_zoo/jtnn/jtnn_vae.py (inferred from context)
Vocabulary and Tree Decomposition
Molecules are decomposed into clusters. A vocabulary of these clusters must be built from the training set before the model can be trained.
The vocabulary management is handled by the Vocab class and DGLMolTree utility.
Sources: examples/generative_models/jtvae/vocab.py:18-40, tests/data/test_datasets.py:165-170
Training and Data Management
Both models require specific data handling and training configurations. DGMG uses a multi-process CPU approach for speedup, while JT-VAE utilizes GPU acceleration.
Training Configuration
| Parameter | DGMG Default | JT-VAE Default |
|---|---|---|
| Optimizer | Adam (MultiProcess) | Adam |
| Learning Rate | Configurable (e.g., 1e-4) | 1e-3 (with ExponentialLR) |
| Batch Size | 1 (per process) | 40 |
| Hidden Size | 128 | 200 |
| Latent Size | N/A | 56 |
Sources: examples/generative_models/dgmg/train.py:155-175, examples/generative_models/jtvae/train.py:100-115
Data Preprocessing Limitations (DGMG)
DGMG has specific limitations regarding chemical features:
- Protonation and chirality are ignored during generation.
- Charged molecules (e.g.,
[N+],[O-]) are typically filtered out to ensure validity and novelty.
Sources: examples/generative_models/dgmg/README.md:16-25
Evaluation Metrics
The performance of these generative models is evaluated based on three primary statistics after generating a large sample (e.g., 100,000 molecules):
- Validity: Percentage of generated molecules that are valid chemical structures (parsed by RDKit).
- Uniqueness: Percentage of valid molecules that are not duplicates within the generated set.
- Novelty: Percentage of unique valid molecules that were not present in the training data.
Sources: examples/generative_models/dgmg/eval.py:87-94, examples/generative_models/dgmg/README.md:118-125
Pre-trained Model Performance
DGL-LifeSci provides pre-trained models for ZINC and ChEMBL datasets. Canonical ordering of atoms significantly improves validity compared to random ordering.
| Model | % Valid | % Unique (among valid) | % Novel (among unique) |
|---|---|---|---|
DGMG_ChEMBL_canonical | 78.80 | 99.19 | 98.60 |
DGMG_ZINC_canonical | 74.60 | 99.87 | 99.87 |
JTNN_ZINC (Recon Acc) | 73.7 | - | - |
Sources: examples/generative_models/dgmg/README.md:133-140, examples/generative_models/jtvae/README.md:73-77
Conclusion
The generative model module in DGL-LifeSci provides two complementary approaches to molecular design. DGMG offers a granular, step-by-step graph construction method using auto-regressive sampling, while JT-VAE (JTNN) utilizes chemical domain knowledge through junction tree decomposition to ensure high structural validity. Both models are integrated with DGL for efficient graph operations and include comprehensive scripts for training, evaluation, and visualization.
Sources: examples/generative_models/dgmg/README.md, examples/generative_models/jtvae/README.md, python/dgllife/model/model_zoo/dgmg.py