Graph Construction
Relevant source files
The following files were used as context for generating this wiki page:
Graph construction is a fundamental stage in DGL-LifeSci that transforms chemical entities, such as molecules and protein-ligand complexes, into DGLGraph objects. This process enables the application of Graph Neural Networks (GNNs) by representing atoms as nodes and chemical bonds or spatial proximities as edges. The system provides flexible utilities to handle various graph topologies, including bigraphs, complete graphs, and nearest neighbor graphs, while supporting custom featurization for both nodes and edges.
Sources: README.md:37-45, python/dgllife/data/alchemy.py:169-180
Molecular Graph Topologies
DGL-LifeSci supports multiple ways to represent a molecule as a graph, depending on the requirements of the underlying model.
Bi-directed Graphs (Bigraphs)
The most common representation is the bi-directed graph, where nodes represent heavy atoms and edges represent chemical bonds. By default, bonds are treated as bi-directed edges to allow bidirectional message passing in GNNs.
The smiles_to_bigraph function serves as a high-level API to convert SMILES strings directly into graphs, handling RDKit molecule parsing and featurization internally.
Sources: python/dgllife/utils/mol_to_graph.py:27-106, tests/utils/test_mol_to_graph.py:28-32
Complete Graphs
For models that require all-to-all atom interactions (often used in quantum chemistry or global attention mechanisms), the system can construct complete graphs where every pair of atoms is connected by an edge.
Sources: python/dgllife/utils/mol_to_graph.py:167-208, python/dgllife/data/alchemy.py:169-172
Nearest Neighbor Graphs
For 3D structural data, graphs can be constructed based on spatial proximity. Edges are formed between atoms if their Euclidean distance is within a specified neighbor_cutoff.
Sources: python/dgllife/utils/mol_to_graph.py:382-446, tests/utils/test_mol_to_graph.py:202-212
Complex Graph Construction
Graph construction for protein-ligand complexes (e.g., ACNN models) involves creating heterogeneous graphs to represent interactions between different atom types.
ACNN Graph Logic
In ACNN graph construction, the ligand and protein atoms are maintained as distinct node types. Edges are categorized based on their source and destination types (e.g., ligand-ligand, protein-protein, or ligand-protein interactions).
| Feature | Description |
|---|---|
| Node Types | protein_atom, ligand_atom |
| Edge Types | protein (P-P), ligand (L-L), complex (L-P, P-L, etc.) |
| Distance-based | Edges are determined by neighbor_cutoff and max_num_neighbors |
| Masking | Supports padding to max_num_ligand_atoms using binary masks |
Sources: python/dgllife/utils/complex_to_graph.py:13-50, tests/utils/test_complex_to_graph.py:44-55
Reaction Graph Construction
Reaction prediction requires tracking changes between reactants and products. The WLNCenterDataset and WLNRankDataset utilize specific construction logic to identify "bond changes" (forming, breaking, or changing bond order).
In these datasets, atoms are renumbered according to their "molAtomMapNumber" to ensure consistency between reactant and product representations.
Sources: python/dgllife/data/uspto.py:255-265, python/dgllife/data/uspto.py:356-370
Key Functions and Parameters
The following table summarizes the primary graph construction utilities available in the package.
| Function | Input | Output | Key Parameters |
|---|---|---|---|
smiles_to_bigraph | SMILES str | DGLGraph | add_self_loop, node_featurizer, edge_featurizer |
mol_to_complete_graph | RDKit Mol | DGLGraph | add_self_loop, canonical_atom_order |
k_nearest_neighbors | Coordinates | Edge Lists | neighbor_cutoff, max_num_neighbors |
ACNN_graph_construction | Ligand & Pocket Mols | DGLGraph | neighbor_cutoff, strip_hydrogens |
Sources: python/dgllife/utils/mol_to_graph.py:27, python/dgllife/utils/mol_to_graph.py:208, python/dgllife/utils/mol_to_graph.py:316, python/dgllife/utils/complex_to_graph.py:13
Summary
Graph construction in DGL-LifeSci provides the bridge between standard cheminformatics formats (SMILES, SDF, PDB) and graph-based deep learning. By offering specialized topologies for different tasks—such as bigraphs for property prediction, complete graphs for quantum chemistry, and heterogeneous graphs for protein-ligand binding—the project provides a robust foundation for various life science applications.