Skip to content

Commit

Permalink
fixed inf problem in test_gromacs
Browse files Browse the repository at this point in the history
  • Loading branch information
jrudz committed Sep 3, 2024
1 parent e5dbac8 commit 1a9cce7
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 10 deletions.
36 changes: 31 additions & 5 deletions atomisticparsers/gromacs/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1565,7 +1565,31 @@ def parse_workflow(self):
# sec_fe.value_total_energy_differences_magnitude = columns[:, 2:-1]
# sec_fe.value_PV_energy_magnitude = columns[:, -1]

def check_input_parameters_dict_recursive(self, input_dict, key):
def standardize_input_parameters_dict_recursive(self, input_dict: dict):
"""_summary_
Args:
input_dict (dict): _description_
"""
for key, val in input_dict.items():
if isinstance(val, dict):
self.standardize_input_parameters_dict_recursive(val)
elif isinstance(val, str):
input_dict[key.replace('_', '-')] = val.lower()
elif isinstance(val, float):
if abs(val) == np.inf:
input_dict[key] = 'inf' if val > 0 else '-inf'

def check_input_parameters_dict_recursive(self, input_dict: dict, key: str):
"""_summary_
Args:
input_dict (dict): _description_
key (str): _description_
Returns:
_type_: _description_
"""
if key in input_dict:
return True
for _, v in input_dict.items():
Expand Down Expand Up @@ -1639,10 +1663,12 @@ def write_to_archive(self):
sec_run.x_gromacs_number_of_tasks = host_info[2]

# parse the input parameters using log file's hierarchical structure as default
self.input_parameters = {
key.replace('_', '-'): val.lower() if isinstance(val, str) else val
for key, val in self.log_parser.get('input_parameters', {}).items()
}
# self.input_parameters = {
# key.replace('_', '-'): val.lower() if isinstance(val, str) else val
# for key, val in self.log_parser.get('input_parameters', {}).items()
# }
self.input_parameters = self.log_parser.get('input_parameters', {})
self.standardize_input_parameters_dict_recursive(self.input_parameters)

# read the mdp output or input to supplement the log inputs (i.e., only store if not found in log)
self.mdp_parser.mainfile = self.get_mdp_file()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"rcoulomb-switch": 0,
"rcoulomb": 1.1,
"epsilon-r": 15,
"epsilon-rf": null,
"epsilon-rf": "inf",
"vdw-type": "cut-off",
"vdw-modifier": "potential-shift",
"rvdw-switch": 0,
Expand Down
2 changes: 1 addition & 1 deletion tests/data/gromacs/input_parameters/input_parameters.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"rcoulomb-switch": 0,
"rcoulomb": 1.1,
"epsilon-r": 15,
"epsilon-rf": null,
"epsilon-rf": "inf",
"vdw-type": "cut-off",
"vdw-modifier": "potential-shift",
"rvdw-switch": 0,
Expand Down
5 changes: 2 additions & 3 deletions tests/test_gromacsparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -546,9 +546,6 @@ def assert_dict_equal(d1, d2):
assert d1.keys() == d2.keys(), f'Keys mismatch: {d1.keys()} != {d2.keys()}'

for key in d1:
if key == 'epsilon-rf': # TODO remove this once the inf issue is resolved
continue

if isinstance(d1[key], dict) and isinstance(d2[key], dict):
assert_dict_equal(d1[key], d2[key])
else:
Expand All @@ -560,6 +557,8 @@ def assert_dict_equal(d1, d2):
assert np.isclose(
d1[key], d2[key]
).all(), f"Value mismatch for key '{key}': {d1[key]} != {d2[key]}"
elif abs(d1[key]) == float('inf'):
assert 'inf' == d2[key] if d1[key] > 0 else '-inf' == d2[key]
else:
assert d1[key] == approx(
d2[key]
Expand Down

0 comments on commit 1a9cce7

Please sign in to comment.