Skip to content

Commit c41a125

Browse files
committed
Write GCMC residues after frame is saved.
1 parent 36a4bdf commit c41a125

2 files changed

Lines changed: 15 additions & 14 deletions

File tree

src/somd2/runner/_repex.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,10 +1265,13 @@ def _run_block(
12651265
),
12661266
)
12671267

1268-
# Perform a GCMC move and write ghost water residue indices after
1269-
# dynamics so that the ghost state is temporally consistent with
1270-
# the saved frame.
12711268
if gcmc_sampler is not None:
1269+
# Write ghost residues before the GCMC move so the ghost state
1270+
# is consistent with the saved frame (which is also captured
1271+
# before the GCMC move).
1272+
if write_gcmc_ghosts:
1273+
gcmc_sampler.write_ghost_residues()
1274+
12721275
if is_gcmc:
12731276
# Push the PyCUDA context on top of the stack.
12741277
gcmc_sampler.push()
@@ -1280,9 +1283,6 @@ def _run_block(
12801283
# Remove the PyCUDA context from the stack.
12811284
gcmc_sampler.pop()
12821285

1283-
if write_gcmc_ghosts:
1284-
gcmc_sampler.write_ghost_residues()
1285-
12861286
# Save the GCMC state.
12871287
self._dynamics_cache.save_gcmc_state(index)
12881288

src/somd2/runner/_runner.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -714,21 +714,22 @@ def generate_lam_vals(lambda_base, increment=0.001):
714714
),
715715
)
716716

717-
# Perform a GCMC move.
718-
_logger.info(
719-
f"Performing GCMC move at {_lam_sym} = {lambda_value:.5f}"
720-
)
721-
gcmc_sampler.move(dynamics.context())
722-
723717
# Update the runtime.
724718
runtime += self._config.energy_frequency
725719

726-
# If a frame is saved, then we need to save current indices
727-
# of the ghost water residues.
720+
# If a frame is saved, write the ghost residue indices
721+
# before the GCMC move so the ghost state is consistent
722+
# with the saved frame.
728723
if save_frames and runtime >= next_frame:
729724
gcmc_sampler.write_ghost_residues()
730725
next_frame += self._config.frame_frequency
731726

727+
# Perform a GCMC move.
728+
_logger.info(
729+
f"Performing GCMC move at {_lam_sym} = {lambda_value:.5f}"
730+
)
731+
gcmc_sampler.move(dynamics.context())
732+
732733
else:
733734
dynamics.run(
734735
checkpoint_frequency,

0 commit comments

Comments
 (0)