GROMACS QM/MM drop-in

librgpot_gromacs puts any rgpot potential behind the C API of the CP2K library. A GROMACS built with -DGMX_CP2K=ON against it evaluates the QM group of gmx mdrun with rgpot, in process, once per step, with no PLUMED. The grompp -qmi file chooses the potential. It is a pot_spec name with its options, such as LJ, SuttonChen, EAMTable or TersoffSi. Or it is an rgpot_engine_* library (UMA, Metatomic, XTB, …) with its Cap’n Proto parameters. The elements come from the atomic numbers of the GROMACS atom types.

The energy enters GROMACS as Quantum En., part of the potential and the conserved energy. The forces enter the force buffer without a virial, so the pressure leaves the rgpot term out and NPT is not supported. For NPT, use the PLUMED route of :doc:`engine-gromacs`.

Why the drop-in implements the CP2K interface is in GROMACS QM/MM through the CP2K interface. The &RGPOT keys, the units, the cell, the errors and the limits are in GROMACS QM/MM drop-in reference.

Build

Configure rgpot with the drop-in, which is off by default:

meson setup bbdir -Dwith_gromacs_dropin=enabled
meson compile -C bbdir

This builds librgpot_gromacs.so. It also writes bbdir/engines/gromacs/pkgconfig/libcp2k.pc, which GROMACS reads through CP2K_DIR. GROMACS needs no change, only these CMake options (it also enables Fortran, so a Fortran compiler must be present):

cmake .. -DGMX_DOUBLE=ON -DGMX_MPI=OFF -DGMX_CP2K=ON \
  -DCP2K_DIR=/path/to/bbdir/engines/gromacs

engines/gromacs/build_gromacs.sh VERSION PREFIX BUILD downloads a pinned GROMACS (2024.6, 2025.5 or 2026.4) and checks its sha256. It builds it this way into PREFIX and checks that libgromacs_d links librgpot_gromacs. After meson install, CP2K_DIR is <prefix>/<libdir>/rgpot/gromacs, where the installed libcp2k.pc lives. gmx_d finds the library without LD_LIBRARY_PATH, through the rpath that libcp2k.pc adds.

Input

The run uses qmmm-cp2k-qmmethod = INPUT and a -qmi file with an &RGPOT section. The keys grompp checks stay as CP2K has them.

; md.mdp
qmmm-cp2k-active   = true
qmmm-cp2k-qmgroup  = QM
qmmm-cp2k-qmmethod = INPUT
&GLOBAL
  RUN_TYPE ENERGY_FORCE
&END GLOBAL
&FORCE_EVAL
  &DFT
    CHARGE 0
    MULTIPLICITY 1
  &END DFT
  &SUBSYS
    &TOPOLOGY
      COORD_FILE_NAME rgpot.pdb
      COORD_FILE_FORMAT PDB
      CHARGE_EXTENDED TRUE
    &END TOPOLOGY
  &END SUBSYS
&END FORCE_EVAL
&RGPOT
  POTENTIAL SuttonChen
  OPTIONS preset platinum cutoff 5.0
&END
gmx_d grompp -f md.mdp -c conf.gro -p topol.top -n index.ndx -qmi rgpot.inp -o md.tpr
gmx_d mdrun -deffnm md -ntmpi 1

mdrun writes the PDB file itself and passes its name in place of COORD_FILE_NAME. To run an engine library instead, replace POTENTIAL and OPTIONS with ENGINE and CONFIG. An engine’s configuration is the flat message the engine ABI takes, for example:

capnp encode CppCore/rgpot/rpc/Potentials.capnp BuiltinParams \
  <<< '(name = "tersoff")' > tersoff.bin

Tests

Meson defines the tests only when it finds a Python with pytest and numpy. gromacs_dropin_api calls the library through ctypes in both box layouts and compares the energy and forces with rgpot-eval, and with the classical engine library when the build has it and capnp is on PATH. It also checks the unit factors and that every malformed input stops with its message. gromacs_dropin_mdrun runs gmx mdrun when gromacs_dropin_gmx names a gmx_d built as above, or one is on PATH. It compares Quantum En. and the .trr forces with rgpot-eval on the same frame for Lennard-Jones argon, Sutton-Chen platinum in a triclinic box, Tersoff silicon and the CuNi EAMTable alloy (with -Dwith_eam_table=true). It also checks the engine route, a QM subset, an isolated cluster with CELL NONE, a run on four OpenMP threads and the conserved energy of 2500-step NVE runs, and that bad inputs stop mdrun. The NVE runs use switched Lennard-Jones, Tersoff and EAMTable: SuttonChen is truncated without a switch, so its energy jumps when a pair crosses the cutoff.

meson setup bbdir -Dwith_tests=true -Dwith_gromacs_dropin=enabled \
  -Dgromacs_dropin_gmx=/path/to/gmx_d
meson test -C bbdir gromacs_dropin_api gromacs_dropin_mdrun

On GROMACS 2024.6, 2025.5 and 2026.4 the energies agree to better than \(10^{-15}\) relative and the forces to better than \(2 \times 10^{-13}\) of the largest component.

Benchmark

engines/gromacs/bench_dropin.py runs a short MD trajectory with the drop-in, keeps every frame, and times on one thread:

  • fixed: pot_spec’s evaluation of the first frame, repeated 200 times;

  • bare: pot_spec’s evaluation of each frame, wrapped as the shim wraps it;

  • shim: the same frames through the libcp2k calls GROMACS makes each step;

  • off and on: gmx mdrun per step with the QM/MM interface off (free particles) and with the drop-in, from the difference of a 1020-step and a 20-step run.

The table gives microseconds per step or call, each the median of 5 fresh processes over 1000 frames or steps. It was measured on an 8-core “Intel(R) Xeon(R) Processor” virtual machine (one thread per core, 47 GiB), Linux 6.12, GCC 13.3, a release build of rgpot and GROMACS 2026.4 in double precision.

System

Atoms

fixed

bare

shim

off

on

LJ argon

864

711.7

4044.8

4056.8

7

4087.0

Tersoff silicon

512

320.2

841.5

850.2

4

865.0

Sutton-Chen Pt

864

1115.4

6448.8

6449.2

6

6479.0

EAMTable CuNi

2048

25243.8

25442.5

25390.1

15

25068.0

The drop-in adds on minus off minus bare to each step: 35 microseconds for argon (0.9% of the step), 20 for silicon (2.3%) and 24 for platinum (0.4%). For CuNi mdrun was faster than the bare replay in each of the five repeats (1.5% in the medians), so the cost there is below what this measurement resolves. The gap between fixed and bare is the kernels’ neighbour-list rebuilds when atoms cross a face of the cell (see the limits in GROMACS QM/MM drop-in reference), which any per-step evaluation of wrapped positions pays.

python3 engines/gromacs/bench_dropin.py --gmx /path/to/gmx_d --build bbdir \
  --eam CppCore/tests/data/eam_table/CuNi.eam.alloy --json bench.json