DimeNet
¶
DimeNet(
hidden_channels: int,
out_channels: int,
num_blocks: int,
num_bilinear: int,
num_spherical: int,
num_radial: int,
cutoff: float = 5.0,
max_num_neighbors: int = 32,
envelope_exponent: int = 5,
num_before_skip: int = 1,
num_after_skip: int = 2,
num_output_layers: int = 3,
act: Union[str, Callable] = "swish",
output_initializer: OutputInitializer = "zeros",
)
Bases: Module
The directional message passing neural network (DimeNet) from the "Directional Message Passing for Molecular Graphs" paper.
DimeNet embeds the directed edges j -> i of the graph of atoms closer
than cutoff, and updates them with messages from the edges k -> j
transformed with the angle \(\angle kji\) (with a 2D spherical
Fourier-Bessel basis), which makes the model invariant to rotations.
The model follows PyG's DimeNet
(same arguments, parameters and initialization). It requires the
sympy and scipy packages. The interaction graph and the triplets
are computed on the host (see radius_graph() and
triplets()), the distances and angles on the device, so that the
output can be differentiated with respect to pos.
Note
The mini-batches of molecules all have different numbers of atoms,
edges and triplets, so MLX rarely reuses the buffers it frees and its buffer
cache can grow to tens of GB during training. Bound it, e.g. with
mx.set_cache_limit(1024**3) before training.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hidden_channels
|
int
|
Hidden embedding size. |
required |
out_channels
|
int
|
Size of each output sample. |
required |
num_blocks
|
int
|
Number of building blocks. |
required |
num_bilinear
|
int
|
Size of the bilinear layer tensor. |
required |
num_spherical
|
int
|
Number of spherical harmonics. |
required |
num_radial
|
int
|
Number of radial basis functions. |
required |
cutoff
|
float
|
Cutoff distance for interatomic interactions. Default: |
5.0
|
max_num_neighbors
|
int
|
The maximum number of neighbors of each atom
within |
32
|
envelope_exponent
|
int
|
Shape of the smooth cutoff. Default: |
5
|
num_before_skip
|
int
|
Number of residual layers in the interaction blocks
before the skip connection. Default: |
1
|
num_after_skip
|
int
|
Number of residual layers in the interaction blocks
after the skip connection. Default: |
2
|
num_output_layers
|
int
|
Number of linear layers for the output blocks.
Default: |
3
|
act
|
Union[str, Callable]
|
The activation function, a name (e.g. |
'swish'
|
output_initializer
|
OutputInitializer
|
The initialization of the output layer,
|
'zeros'
|
Example:
import mlx.core as mx
from mlx_graphs.nn import DimeNet
model = DimeNet(
hidden_channels=32, out_channels=1, num_blocks=2, num_bilinear=4,
num_spherical=3, num_radial=4,
)
z = mx.array([6, 1, 1, 1, 1])
pos = mx.random.normal((5, 3))
model(z, pos, mx.zeros(5, dtype=mx.int32)).shape
>>> (1, 1)
Methods:
| Name | Description |
|---|---|
__call__ |
Predicts the target properties of each molecule. |
Source code in mlx_graphs/nn/models/dimenet.py
__call__
¶
__call__(z: array, pos: array, batch_indices: Optional[array] = None) -> array
Predicts the target properties of each molecule.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
z
|
array
|
Atomic number of each atom, of shape |
required |
pos
|
array
|
Coordinates of each atom, of shape |
required |
batch_indices
|
Optional[array]
|
Molecule of each atom, of shape |
None
|
Returns:
| Type | Description |
|---|---|
array
|
The predictions, of shape |
array
|
|
Source code in mlx_graphs/nn/models/dimenet.py
from mlx_graphs.nn import DimeNet · mlx_graphs/nn/models/dimenet.py