kups.potential.mliap.torch.mace
¶
MACE adapter for the universal torch MLFF interface.
Provides a thin torch.nn.Module (MACEModule)
that translates the universal
AtomGraphInput into
MACE's PyG-style input format, plus a load_mace
loader returning a TorchMliap.
Example
Requires the torch dependency group: uv sync --group torch.
MACEModule
¶
Bases: Module
Adapter: AtomGraphInput → MACE PyG-style input → energy + gradients.
Wraps a MACE nn.Module and translates the universal graph input into
the (node_attrs, positions, edge_index, batch, ptr,
shifts, cell) tuple that MACE expects. Returns gradients of energy
w.r.t. positions (and optionally cell vectors).
Attributes:
| Name | Type | Description |
|---|---|---|
mace |
Underlying MACE |
|
species_to_index |
Tensor
|
Buffer mapping atomic number |
num_species |
Number of species the MACE model was trained on. |
|
compute_cell_gradients |
Whether to compute cell gradients (stress). |
Source code in src/kups/potential/mliap/torch/mace.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | |
__init__(mace_model, species_to_index, num_species, compute_cell_gradients=False)
¶
Initialise MACEModule.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mace_model
|
Module
|
Underlying MACE |
required |
species_to_index
|
Tensor
|
Tensor mapping |
required |
num_species
|
int
|
Number of species the MACE model was trained on. |
required |
compute_cell_gradients
|
bool
|
Whether to compute cell gradients. |
False
|
Source code in src/kups/potential/mliap/torch/mace.py
forward(input)
¶
Run MACE on a universal AtomGraphInput and return gradients.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input
|
dict[str, Tensor]
|
Dict matching the universal |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Tensor]
|
Dict with |
dict[str, Tensor]
|
and optionally |
Source code in src/kups/potential/mliap/torch/mace.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | |
load_mace(model_path, device='cuda', dtype='float32', compute_cell_gradients=False, cutoff=None)
¶
Load a PyTorch MACE .model into a universal TorchMliap.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_path
|
str | Path
|
Path to a MACE |
required |
device
|
str
|
Device to load the model onto. |
'cuda'
|
dtype
|
Literal['float32', 'float64']
|
Model precision — |
'float32'
|
compute_cell_gradients
|
bool
|
Whether to also compute virials/stress. |
False
|
cutoff
|
float | None
|
Cutoff radius [Å]. When |
None
|
Returns:
| Type | Description |
|---|---|
TorchMliap
|
|