From 4abd041653202c6ed3698d50990b51a131cbf31d Mon Sep 17 00:00:00 2001 From: Lester Hedges Date: Thu, 5 Feb 2026 14:26:42 +0000 Subject: [PATCH] Backport fix from PR #121. [ci skip] --- src/somd2/runner/_repex.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/somd2/runner/_repex.py b/src/somd2/runner/_repex.py index 058e028..fe7b34b 100644 --- a/src/somd2/runner/_repex.py +++ b/src/somd2/runner/_repex.py @@ -309,6 +309,22 @@ def _create_dynamics( ): from openmm.unit import angstrom + # Get the positions from the context. + positions = ( + dynamics.context() + .getState(getPositions=True) + .getPositions(asNumpy=True) + ) / angstrom + + # The positions array also contains the ghost water atoms that + # were added during the GCMC setup. We need to make sure that + # we copy these over to the perturbed positions array. + diff = len(positions) - len(perturbed_positions) + if diff != 0: + perturbed_positions = _np.concatenate( + [perturbed_positions, positions[-diff:]] + ) + dynamics.context().setPeriodicBoxVectors(*perturbed_box * angstrom) dynamics.context().setPositions(perturbed_positions * angstrom)