Skip to content

Commit

Permalink
Some minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
wehs7661 committed Mar 25, 2024
1 parent 2a76ea5 commit ab675f4
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ nosetests.xml
coverage.xml
*.cover
.hypothesis/
sim_*

# Translations
*.mo
Expand Down
6 changes: 3 additions & 3 deletions ensemble_md/replica_exchange_EE.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ def get_ref_dist(self, pullx_file=None):
Gets the reference distance(s) to use starting from the second iteration if distance restraint(s) are used.
Specifically, a reference distance determined here is the initial COM distance between the pull groups
in the input GRO file. This function initializes the attribute :code:`ref_dist`.
Parameter
---------
pullx_file : str
Expand Down Expand Up @@ -920,7 +920,7 @@ def get_swapping_pattern(self, dhdl_files, states):

swap = ReplicaExchangeEE.propose_swap(swappables)
print(f'\nProposed swap: {swap}')
if swap == []: # the same as len(swappables) == 0, self.proposal must not be exhaustive if this line is reached.
if swap == []: # the same as len(swappables) == 0, self.proposal must not be exhaustive if this line is reached. # noqa: E501
self.n_empty_swappable += 1
print('No swap is proposed because there is no swappable pair at all.')
break # no need to re-identify swappable pairs and draw new samples
Expand Down Expand Up @@ -1332,7 +1332,7 @@ def _run_grompp(self, n, swap_pattern):
else:
gro = f"{self.gro}"
else:
gro = f"{self.working_dir}/sim_{swap_pattern[i]}/iteration_{n-1}/confout.gro" # This effectively swap out GRO files
gro = f"{self.working_dir}/sim_{swap_pattern[i]}/iteration_{n-1}/confout.gro" # This effectively swap out GRO files # noqa: E501

if isinstance(self.top, list):
top = f"{self.top[i]}"
Expand Down
48 changes: 48 additions & 0 deletions ensemble_md/tests/test_mpi_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
comm = MPI.COMM_WORLD
rank = comm.Get_rank()


@pytest.fixture
def params_dict():
"""
Expand Down Expand Up @@ -59,6 +60,40 @@ def get_REXEE_instance(input_dict, yml_file='params.yaml'):
return REXEE


def get_gmx_cmd_from_output(output):
"""
Given a GROMACS output file like a LOG file or `mdout.mdp`, extract the GROMACS command that was run.
Parameters
----------
output : str
The path to the GROMACS output file.
Returns
-------
cmd : str
The GROMACS command that was run.
flags : dict
The flags and values that were used in the GROMACS command.
"""
f = open(output, 'r')
lines = f.readlines()
f.close()
n = -1
for l in lines: # noqa: E741
n += 1
if l.startswith('Command line'):
cmd = lines[n+1].strip()

flags = {}
cmd_split = cmd.split(' ')
for i in range(len(cmd_split)):
if cmd_split[i].startswith('-'):
flags[cmd_split[i]] = cmd_split[i+1]

return cmd, flags


@pytest.mark.mpi
def test_run_grompp(params_dict):
params_dict['grompp_args'] = {'-maxwarn': '1'}
Expand All @@ -80,4 +115,17 @@ def test_run_grompp(params_dict):
for i in range(params_dict['n_sim']):
assert os.path.isfile(f'{REXEE.working_dir}/sim_{i}/iteration_0/sys_EE.tpr') is True
assert os.path.isfile(f'{REXEE.working_dir}/sim_{i}/iteration_0/mdout.mdp') is True

# Here we check if the command executed was what we expected
mdp = f'{REXEE.working_dir}/sim_{i}/iteration_0/mdout.mdp'
gro = params_dict['gro']
top = params_dict['top']
tpr = f'{REXEE.working_dir}/sim_{i}/iteration_0/sys_EE.tpr'
mdout = f'{REXEE.working_dir}/sim_{i}/iteration_0/mdout.mdp'
cmd = f'{REXEE.check_gmx_executable} -f {mdp} -c {gro} -p {top} -o {tpr} -po {mdout} -maxwarn 1'
assert get_gmx_cmd_from_output(mdout)[0] == cmd

shutil.rmtree(f'{REXEE.working_dir}/sim_{i}')

# Case 2: Other iterations, i.e., n != 0
# More to come ...
3 changes: 1 addition & 2 deletions ensemble_md/tests/test_replica_exchange_EE.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ def test_update_MDP(self, params_dict):
REXEE.equil = [-1, 1, 0, -1] # i.e., the 3rd replica will use fixed weights in the next iteration
MDP_1 = REXEE.update_MDP(
new_template, 2, iter_idx, states, wl_delta, weights) # third replica

REXEE.get_ref_dist('ensemble_md/tests/data/pullx.xvg') # so that we can test the pull code
MDP_2 = REXEE.update_MDP(
new_template, 3, iter_idx, states, wl_delta, weights, counts) # fourth replica
Expand Down Expand Up @@ -663,7 +663,6 @@ def test_get_swapping_pattern(self, params_dict):
assert pattern_4_3 == [0, 2, 1, 3]
assert swap_list_4_3 == [(1, 2)]


def test_calc_prob_acc(self, capfd, params_dict):
# k = 1.380649e-23; NA = 6.0221408e23; T = 298; kT = k * NA * T / 1000 = 2.4777098766670016
REXEE = get_REXEE_instance(params_dict)
Expand Down

0 comments on commit ab675f4

Please sign in to comment.