How to use Neural Network Potentials in Gromacs 2025

GROMACS version: 2025.1
GROMACS modification: No

Hi,

I am wondering how one properly runs gromacs when using a neural network potential as described here:
Neural Network Potentials - GROMACS 2026.0-dev-20250516-6ea4e95 documentation

I am currently trying to run a simple test system (a box of water) and have generated the NN potential model as described in the documentation. I added

; use ani2x
nnpot-active = true
nnpot-modelfile = ani2x.pt

to my mdp file, which as far I understand should try to apply the NN potential to the entire system. However I am running into the following error message:

I>nternal error (bug):

Environment variable GMX_NN_DEVICE was set to cuda, but no CUDA device is
available.

No matter what I specify for GMX_NN_DEVICE (for example with cuda:0 it tells me there is no cuda device).
I would really like to know if I am just using this wrong or if this is a bug.

Hi! Thanks for your interest in the neural network potential interface. Yes, by default the NNP will be applied to the whole system. You should also set the inputs that the NNP needs, in the case of ANI the complete input could look like

nnpot-active       = yes
nnpot-modelfile    = ani2x.pt
nnpot-input-group  = System
nnpot-model-input1 = atom-positions
nnpot-model-input2 = atom-numbers
nnpot-model-input3 = box
nnpot-model-input4 = pbc

Have you tried running inference on the CPU, i.e. setting export GMX_NN_DEVICE=cpu?

Other possible causes would be that you didn’t compile with the proper Libtorch version (should have CUDA support), or that your CUDA installation is not present in your PATH.

You can also have look on this GitHub page, where I’m currently compiling some how-to guides to run NNP/MM simulations with different models. Any feedback is appreciated.

Hi @lmullender,

thanks for the reply. I tried setting

export GMX_NN_DEVICE=cpu

With this the run started but I now get this error:

GMX_NN_DEVICE environment variable found. Using device: cpu.


Program: gmx grompp, version 2025.1

Unknown exception:
(exception type: N5torch3jit11ErrorReportE)

Unknown type name ‘torch.torch.classes.cuaev.CuaevComputer’:
File “code/torch/torchani/aev.py”, line 15
training : bool
_is_full_backward_hook : NoneType
cuaev_computer : torch.torch.classes.cuaev.CuaevComputer
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <— HERE
cuaev_enabled : bool
num_species : Final[int] = 7

Thanks already for your help.

TorchANI adds the CuaevComputer as an extra class to Pytorch. Therefore, we also need to tell the Libtorch installation that is used by GROMACS about this extension, or disable it’s use. The CuaevComputer is optimized CUDA code though, so you would need to set GMX_NN_DEVICE to cuda. Have a look at the export.ipynb notebook on the Github page I linked above, where I also explain this and how to disable the CuaevComputer.