@@ -722,6 +722,29 @@ def generate_lam_vals(lambda_base, increment=0.001):
722722
723723 # Loop until we reach the runtime.
724724 while runtime < checkpoint_frequency :
725+ # Perform a GCMC move before dynamics so the ghost
726+ # state is consistent with the energies computed
727+ # during dynamics.
728+ _logger .info (
729+ f"Performing GCMC move at { _lam_sym } = { lambda_value :.5f} "
730+ )
731+ gcmc_sampler .push ()
732+ try :
733+ gcmc_sampler .move (dynamics .context ())
734+ finally :
735+ gcmc_sampler .pop ()
736+
737+ # Write ghost residues immediately after the GCMC
738+ # move if a frame will be saved in the upcoming
739+ # dynamics block.
740+ if (
741+ save_frames
742+ and runtime + self ._config .energy_frequency
743+ >= next_frame
744+ ):
745+ gcmc_sampler .write_ghost_residues ()
746+ next_frame += self ._config .frame_frequency
747+
725748 # Run the dynamics in blocks of the GCMC frequency.
726749 dynamics .run (
727750 self ._config .gcmc_frequency ,
@@ -748,23 +771,6 @@ def generate_lam_vals(lambda_base, increment=0.001):
748771 # Update the runtime.
749772 runtime += self ._config .energy_frequency
750773
751- # If a frame is saved, write the ghost residue indices
752- # before the GCMC move so the ghost state is consistent
753- # with the saved frame.
754- if save_frames and runtime >= next_frame :
755- gcmc_sampler .write_ghost_residues ()
756- next_frame += self ._config .frame_frequency
757-
758- # Perform a GCMC move.
759- _logger .info (
760- f"Performing GCMC move at { _lam_sym } = { lambda_value :.5f} "
761- )
762- gcmc_sampler .push ()
763- try :
764- gcmc_sampler .move (dynamics .context ())
765- finally :
766- gcmc_sampler .pop ()
767-
768774 else :
769775 dynamics .run (
770776 checkpoint_frequency ,
@@ -948,7 +954,29 @@ def generate_lam_vals(lambda_base, increment=0.001):
948954 next_frame = self ._config .frame_frequency
949955
950956 # Loop until we reach the runtime.
951- while runtime <= time :
957+ while runtime < time :
958+ # Perform a GCMC move before dynamics so the ghost
959+ # state is consistent with the energies computed
960+ # during dynamics.
961+ _logger .info (
962+ f"Performing GCMC move at { _lam_sym } = { lambda_value :.5f} "
963+ )
964+ gcmc_sampler .push ()
965+ try :
966+ gcmc_sampler .move (dynamics .context ())
967+ finally :
968+ gcmc_sampler .pop ()
969+
970+ # Write ghost residues immediately after the GCMC
971+ # move if a frame will be saved in the upcoming
972+ # dynamics block.
973+ if (
974+ save_frames
975+ and runtime + self ._config .energy_frequency >= next_frame
976+ ):
977+ gcmc_sampler .write_ghost_residues ()
978+ next_frame += self ._config .frame_frequency
979+
952980 # Run the dynamics in blocks of the GCMC frequency.
953981 dynamics .run (
954982 self ._config .gcmc_frequency ,
@@ -963,24 +991,8 @@ def generate_lam_vals(lambda_base, increment=0.001):
963991 save_crash_report = self ._config .save_crash_report ,
964992 )
965993
966- # Perform a GCMC move.
967- _logger .info (
968- f"Performing GCMC move at { _lam_sym } = { lambda_value :.5f} "
969- )
970- gcmc_sampler .push ()
971- try :
972- gcmc_sampler .move (dynamics .context ())
973- finally :
974- gcmc_sampler .pop ()
975-
976994 # Update the runtime.
977995 runtime += self ._config .energy_frequency
978-
979- # If a frame is saved, then we need to save current indices
980- # of the ghost water residues.
981- if save_frames and runtime >= next_frame :
982- gcmc_sampler .write_ghost_residues ()
983- next_frame += self ._config .frame_frequency
984996 else :
985997 dynamics .run (
986998 time ,
0 commit comments