SchNet
¶
SchNet(
hidden_channels: int = 128,
num_filters: int = 128,
num_interactions: int = 6,
num_gaussians: int = 50,
cutoff: float = 10.0,
interaction_graph: Optional[Callable] = None,
max_num_neighbors: int = 32,
readout: Literal["add", "sum", "mean"] = "add",
dipole: bool = False,
mean: Optional[float] = None,
std: Optional[float] = None,
atomref: Optional[array] = None,
)
Bases: Module
The continuous-filter convolutional neural network SchNet from the "SchNet: A Continuous-filter Convolutional Neural Network for Modeling Quantum Interactions" paper, with interaction blocks of the form
where \(h_{\mathbf{\Theta}}\) denotes an MLP and \(\mathbf{e}_{j,i}\) the interatomic distances.
The model follows PyG's SchNet (same
arguments, parameters and initialization). It takes the atomic numbers
z and positions pos of the atoms and returns one prediction per
molecule. The interaction graph connects the atoms closer than cutoff
(with radius_graph(), which keeps the
max_num_neighbors closest neighbors when there are more).
Note
The mini-batches of molecules all have different numbers of atoms
and edges, 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. Default: |
128
|
num_filters
|
int
|
The number of filters to use. Default: |
128
|
num_interactions
|
int
|
The number of interaction blocks. Default: |
6
|
num_gaussians
|
int
|
The number of gaussians \(\mu\). Default: |
50
|
cutoff
|
float
|
Cutoff distance for interatomic interactions. Default: |
10.0
|
interaction_graph
|
Optional[Callable]
|
The function computing the interaction graph and
the interatomic distances, given |
None
|
max_num_neighbors
|
int
|
The maximum number of neighbors of each atom in the
interaction graph. Default: |
32
|
readout
|
Literal['add', 'sum', 'mean']
|
The global aggregation, |
'add'
|
dipole
|
bool
|
If |
False
|
mean
|
Optional[float]
|
The mean of the property to predict. Default: |
None
|
std
|
Optional[float]
|
The standard deviation of the property to predict.
Default: |
None
|
atomref
|
Optional[array]
|
The reference of single-atom properties, of shape
|
None
|
Example:
import mlx.core as mx
from mlx_graphs.nn import SchNet
model = SchNet(hidden_channels=64, num_interactions=3, cutoff=5.0)
z = mx.array([6, 1, 1, 1, 1, 8, 1, 1]) # CH4 and H2O
pos = mx.random.normal((8, 3))
batch_indices = mx.array([0, 0, 0, 0, 0, 1, 1, 1])
model(z, pos, batch_indices).shape
>>> (2, 1)
Methods:
| Name | Description |
|---|---|
__call__ |
Predicts the target property of each molecule. |
Source code in mlx_graphs/nn/models/schnet.py
__call__
¶
__call__(z: array, pos: array, batch_indices: Optional[array] = None) -> array
Predicts the target property 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 |
Source code in mlx_graphs/nn/models/schnet.py
from mlx_graphs.nn import SchNet · mlx_graphs/nn/models/schnet.py