Crash on first frame of cavity test-particle insertion (integrator = tpic) since 2025.0

Summary

Every integrator = tpic run crashes on step 0 of the first rerun frame in GROMACS 2025.0 through 2026.4 and on main.

When commit 2774fb50b9dd (!4333 (merged), 2024-06-25, "Add TestParticleInsertion class") extracted class TestParticleInsertion out of LegacySimulator::do_tpi(), do_tpi() continued to populate the local massesDefiningCavity vector (1 by default, or parsed from GMX_TPIC_MASSES) and check the rerun frame atom count against it, while TestParticleInsertion's constructor omitted that argument. As a result, TestParticleInsertion::massesDefiningCavity_ stays empty, insertIntoFrame() enters the center-of-mass branch with totalMass = 0, and x_init /= totalMass divides by zero on the first frame.

GROMACS version

Reproduced on unmodified release tag v2026.4 (gmx --version: 2026.4, GCC 15.2.0, AVX2_256) and current main (fb41eeec50). By git ancestry (git tag --contains 2774fb50b9dd), all 2025.x and 2026.x releases (v2025.0 through v2026.4) are affected; release-2024 (v2024.x) is not affected.

Steps to reproduce

Using the standard spc216 water box (648 solvent atoms) with one methane test molecule in the topology and one extra cavity-center coordinate at (0.931, 0.931, 0.931) appended to the rerun .gro frame (649 atoms total):

integrator  = tpic
nsteps      = 100
ld-seed     = 1993
rtpi        = 0.15
coulombtype = PME
rcoulomb    = 0.9
rvdw        = 0.9
tc-grps     = System
tau-t       = 0.5
ref-t       = 298
gmx grompp -f tpic.mdp -c spc216_with_methane.gro -p spc216_with_methane.top -o tpic.tpr
gmx mdrun -ntmpi 1 -ntomp 1 -s tpic.tpr -rerun spc216_cavity_649.gro

What is the current bug behavior?

  • In -DCMAKE_BUILD_TYPE=RelWithAssert builds on v2026.4, mdrun aborts immediately on frame 0 (SIGABRT) inside TestParticleInsertion::insertIntoFrame():
    Reading frame       0 time    0.000   gmx: .../api/legacy/include/gromacs/utility/vectypes.h:170:
    constexpr gmx::BasicVector<ValueType>& gmx::BasicVector<ValueType>::operator/=(const ValueType&) [with ValueType = float]:
    Assertion `(right != 0 && "Cannot divide by zero")' failed.
  • In -DCMAKE_BUILD_TYPE=Release builds (assertions disabled), 0.0 / 0.0 produces NaN cavity coordinates and mdrun segfaults (SIGSEGV) inside putAtomsOnGrid().

What did you expect the correct behavior to be?

mdrun should compute the cavity center from massesDefiningCavity, run the requested insertions in each frame, and report finite <V> and <mu> values.

Possible fixes

Pass massesDefiningCavity from LegacySimulator::do_tpi() into the TestParticleInsertion constructor (src/gromacs/mdrun/tpi.cpp) to initialize massesDefiningCavity_, and add a tpitest.cpp integration test covering integrator = tpic.