Skip to content

Commit

Permalink
Prevent swaps from being attempted twice on restart
Browse files Browse the repository at this point in the history
  • Loading branch information
ajfriedman22 committed Dec 11, 2024
1 parent b8e91d8 commit c258d76
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions ensemble_md/cli/run_REXEE.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,14 +311,17 @@ def main():
gro_2 = f'{REXEE.working_dir}/sim_{swap_list[j][1]}/iteration_{i-1}/confout.gro'
print(f' - {gro_1}\n - {gro_2}')

# Now we rename gro_1 and gro_2 to back them up
gro_1_backup = gro_1.split('.gro')[0] + '_backup.gro'
gro_2_backup = gro_2.split('.gro')[0] + '_backup.gro'
os.rename(gro_1, gro_1_backup)
os.rename(gro_2, gro_2_backup)

# Here we input gro_1_backup and gro_2_backup and modify_coords_fn will save the modified gro files as gro_1 and gro_2 # noqa: E501
REXEE.modify_coords_fn(gro_1_backup, gro_2_backup) # the order should not matter
if os.path.exists(gro_1.split('.gro')[0] + '_backup.gro') and os.path.exists(gro_2.split('.gro')[0] + '_backup.gro'):
print('\nSwap already performed')
else:
# Now we rename gro_1 and gro_2 to back them up
gro_1_backup = gro_1.split('.gro')[0] + '_backup.gro'
gro_2_backup = gro_2.split('.gro')[0] + '_backup.gro'
os.rename(gro_1, gro_1_backup)
os.rename(gro_2, gro_2_backup)

# Here we input gro_1_backup and gro_2_backup and modify_coords_fn will save the modified gro files as gro_1 and gro_2 # noqa: E501
REXEE.modify_coords_fn(gro_1_backup, gro_2_backup) # the order should not matter
except Exception:
print('\n--------------------------------------------------------------------------\n')
print(f'\nAn error occurred on rank 0:\n{traceback.format_exc()}')
Expand Down

0 comments on commit c258d76

Please sign in to comment.