Skip to content

Commit

Permalink
fixed input params tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jrudz committed Sep 3, 2024
1 parent 4ab78c3 commit e5dbac8
Show file tree
Hide file tree
Showing 5 changed files with 914 additions and 31 deletions.
30 changes: 17 additions & 13 deletions atomisticparsers/gromacs/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ def str_to_input_parameters(val_in):
elif value.replace('.', '', 1).isdigit():
value = float(value) if '.' in value else int(value)
stack[-1][key] = value

continue

# Check for shorthand array
Expand Down Expand Up @@ -1193,7 +1194,7 @@ def get_thermostat_parameters(self, integrator: str = ''):
if 'sd' in integrator:
thermostat_parameters['thermostat_type'] = 'langevin_goga'
if thermostat_parameters['thermostat_type']:
reference_temperature = self.input_parameters.get('grpopts', '').get(
reference_temperature = self.input_parameters.get('grpopts', {}).get(
'ref-t', None
)
if isinstance(reference_temperature, str):
Expand All @@ -1202,7 +1203,7 @@ def get_thermostat_parameters(self, integrator: str = ''):
) # ! simulated annealing protocols not supported
reference_temperature *= ureg.kelvin if reference_temperature else None
thermostat_parameters['reference_temperature'] = reference_temperature
coupling_constant = self.input_parameters.get('grpopts', '').get(
coupling_constant = self.input_parameters.get('grpopts', {}).get(
'tau-t', None
)
if isinstance(coupling_constant, str):
Expand Down Expand Up @@ -1235,7 +1236,9 @@ def get_barostat_parameters(self):
)
barostat_parameters['barostat_type'] = value
if barostat_parameters['barostat_type']:
couplingtype = self.input_parameters.get('pcoupltype', None).lower()
couplingtype = self.input_parameters.get(
'pcoupltype', None
).lower() # TODO fix this problematic None.lower()
couplingtype_map = {
'isotropic': 'isotropic',
'semiisotropic': 'semi_isotropic',
Expand Down Expand Up @@ -1267,12 +1270,12 @@ def get_barostat_parameters(self):
def get_free_energy_calculation_parameters(self):
free_energy_parameters = {}

free_energy = self.input_parameters.get('qm-opts', '').get('free-energy', '')
free_energy = self.input_parameters.get('qm-opts', {}).get('free-energy', '')
free_energy = free_energy.lower() if free_energy else ''
expanded = self.input_parameters.get('qm-opts', '').get('expanded', '')
expanded = self.input_parameters.get('qm-opts', {}).get('expanded', '')
expanded = expanded.lower() if expanded else ''
delta_lambda = int(
self.input_parameters.get('qm-opts', '').get('delta-lamda', -1)
self.input_parameters.get('qm-opts', {}).get('delta-lamda', -1)
)
if free_energy == 'yes' and expanded == 'yes':
self.logger.warning(
Expand Down Expand Up @@ -1323,15 +1326,15 @@ def get_free_energy_calculation_parameters(self):
if lambdas[gromacs_key]
]
free_energy_parameters['lambda_index'] = self.input_parameters.get(
'qm-opts', None
'qm-opts', {}
).get('init-lambda-state', None)

#! Some free energy info seems to be missing from log and is difficult to extract.
#! Using the mdp file directly.
atoms_info = self.traj_parser._results['atoms_info']
atoms_moltypes = np.array(atoms_info['moltypes'])
couple_moltype = (
self.input_parameters.get('mdp_unique_params', '')
self.input_parameters.get('mdp_unique_params', {})
.get('couple-moltype', '')
.split()
)
Expand All @@ -1358,12 +1361,12 @@ def get_free_energy_calculation_parameters(self):
'none': False,
}
couple_initial = (
self.input_parameters.get('mdp_unique_params', '')
self.input_parameters.get('mdp_unique_params', {})
.get('couple-lambda0', 'none')
.lower()
)
couple_final = (
self.input_parameters.get('mdp_unique_params', '')
self.input_parameters.get('mdp_unique_params', {})
.get('couple-lambda1', 'vdw-q')
.lower()
)
Expand All @@ -1378,7 +1381,7 @@ def get_free_energy_calculation_parameters(self):
]

couple_intramolecular = (
self.input_parameters.get('mdp_unique_params', '')
self.input_parameters.get('mdp_unique_params', {})
.get('couple-intramol', 'on')
.lower()
)
Expand Down Expand Up @@ -1562,7 +1565,7 @@ 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 check_input_parameters_dict_recursive(self, input_dict, key):
if key in input_dict:
return True
for _, v in input_dict.items():
Expand Down Expand Up @@ -1640,6 +1643,7 @@ def write_to_archive(self):
key.replace('_', '-'): val.lower() if isinstance(val, str) else val
for key, val in self.log_parser.get('input_parameters', {}).items()
}

# 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()
self.input_parameters[
Expand Down Expand Up @@ -1689,4 +1693,4 @@ def write_to_archive(self):

self.parse_workflow()

# self.traj_parser.clean()
self.traj_parser.clean()
Loading

0 comments on commit e5dbac8

Please sign in to comment.