Chemical Reaction Prediction
Relevant source files
The following files were used as context for generating this wiki page:
Chemical Reaction Prediction in DGL-LifeSci implements a template-free approach to predict the outcomes of organic reactions. The system follows a two-stage pipeline: first identifying the reaction center (the specific atoms and bonds where changes occur) and then ranking candidate products formed by those changes. This implementation is based on the Weisfeiler-Lehman Network (WLN) and utilizes the USPTO (United States Patent and Trademark Office) dataset for training and evaluation.
Sources: examples/reaction_prediction/rexgen_direct/README.md:12-19, examples/README.md:104-108
System Architecture
The prediction pipeline is divided into two distinct modeling stages. The first stage uses a Graph Convolutional Neural Network (GCNN) to update atom representations and predict the likelihood of bond formation or cleavage. The second stage enumerates combinations of these predicted changes to generate and rank potential products.
The flow of the chemical reaction prediction system from input reactants to final ranked products.
Sources: examples/reaction_prediction/rexgen_direct/README.md:31-36, examples/reaction_prediction/rexgen_direct/README.md:127-142
Stage 1: Reaction Center Prediction
Reaction center prediction focuses on identifying pairs of atoms that will lose or form a bond. A Weisfeiler-Lehman Network updates the representations of all atoms in the reactant graphs. These representations are then combined for pairs of atoms to predict one of five possible bond changes.
Bond Change Types
Predictions are represented as 3-tuples (a, b, c) where a and b are atom mapping numbers and c is the change type.
| Change Type ID | Change Description | Internal Value |
|---|---|---|
| 0 | Losing a bond | 0.0 |
| 1 | Forming a single bond | 1.0 |
| 2 | Forming a double bond | 2.0 |
| 3 | Forming a triple bond | 3.0 |
| 4 | Forming an aromatic bond | 1.5 |
Sources: examples/reaction_prediction/rexgen_direct/README.md:38-42, python/dgllife/data/uspto.py:126-130, examples/reaction_prediction/rexgen_direct/utils.py:270-272
Featurization
The WLNCenterDataset handles the construction of molecular graphs and featurization for this stage.
- Node Featurizer: Includes atom type, degree, explicit valence, implicit valence, and aromaticity.
- Edge Featurizer: Includes bond type, conjugation status, and whether the bond is in a ring.
- Atom Pair Featurizer: Computes features for every pair of atoms in a complete graph, including reactant membership and existing bond types.
Sources: python/dgllife/data/uspto.py:45-70, python/dgllife/data/uspto.py:328-360
Stage 2: Candidate Ranking
In the second stage, the system takes the top-k scores from the reaction center prediction and performs a combinatorial enumeration.
Ranking Logic
- Selection: Select top-k (default k=80) bond changes.
- Filtering: Remove changes for bonds already present in the reactants.
- Enumeration: Combine atom pairs (up to 5 pairs) into combinations.
- Validity Check: Filter combinations based on connectivity and valence constraints.
- Scoring: Apply changes to the reactant graph to create candidate products, then score them using a WLN.
Sources: examples/reaction_prediction/rexgen_direct/README.md:129-142, python/dgllife/data/uspto.py:643-690
Validation and Constraints
The system enforces chemical validity during candidate generation. The is_valid_combo function ensures that candidates do not violate valence rules (e.g., nitrogen positive charge limits, sulfur even valence, phosphorus odd valence).
The logic flow for validating a candidate combination of bond changes.
Sources: python/dgllife/data/uspto.py:539-550, python/dgllife/data/uspto.py:566-630
Data Processing and Utilities
The system primarily uses the USPTO dataset, which is split into 400K training, 40K validation, and 40K test reactions.
Key Classes and Functions
| Component | File Path | Description |
|---|---|---|
WLNCenterDataset | python/dgllife/data/uspto.py | Dataset for reaction center prediction. |
WLNRankDataset | python/dgllife/data/uspto.py | Dataset for ranking candidate products. |
get_bond_changes | python/dgllife/data/uspto.py | Identifies bond changes between reactants and products. |
edit_mol | examples/rexgen_direct/utils.py | Simulates a reaction via graph editing (RDKit RWMol). |
sanitize_smiles_molvs | examples/rexgen_direct/utils.py | Uses MolVS to standardize SMILES for evaluation. |
Sources: python/dgllife/data/uspto.py:145-190, python/dgllife/data/uspto.py:328, examples/reaction_prediction/rexgen_direct/utils.py:441-550, examples/reaction_prediction/rexgen_direct/utils.py:410-435
Reaction Format
New datasets must provide SMILES in the format reactants>>products, where reactants are separated by . and atom mapping is provided as consecutive integers starting from 1.
Example: [CH3:14][OH:15].[NH2:12]...>>[n:1]1...
Sources: examples/reaction_prediction/rexgen_direct/README.md:83-88, python/dgllife/data/uspto.py:228-240
Conclusion
The Chemical Reaction Prediction module provides a robust, two-stage framework for predicting organic outcomes without relying on pre-defined reaction templates. By combining graph-based atom representations with combinatorial validity checks, it effectively identifies reaction centers and ranks potential products, achieving significant performance improvements and speedups over traditional implementations.
Sources: examples/reaction_prediction/rexgen_direct/README.md:65-72, README.md:143-149