Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entries missing from input_parameters #104

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
31 changes: 29 additions & 2 deletions atomisticparsers/gromacs/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# limitations under the License.
#
import os

import numpy as np
import logging
import re
Expand Down Expand Up @@ -49,6 +50,7 @@
GeometryOptimizationMethod,
GeometryOptimizationResults,
)

from .metainfo.gromacs import (
x_gromacs_section_control_parameters,
x_gromacs_section_input_output_files,
Expand All @@ -66,7 +68,7 @@
def to_float(string):
try:
value = float(string)
except ValueError:
except (ValueError, TypeError):
value = None
return value

Expand Down Expand Up @@ -199,22 +201,31 @@ def init_quantities(self):
def str_to_input_parameters(val_in):
re_array = re.compile(r"\s*([\w\-]+)\[[\d ]+\]\s*=\s*\{*(.+)")
re_scalar = re.compile(r"\s*([\w\-]+)\s*[=:]\s*(.+)")
re_comment = re.compile(r"^\S+?(?=[\s;])")
parameters = dict()
val = [line.strip() for line in val_in.splitlines()]
for val_n in val:
val_scalar = re_scalar.match(val_n)
if val_scalar:
parameters[val_scalar.group(1)] = val_scalar.group(2)
val_scalar_group2 = val_scalar.group(2)
inline_comment = re_comment.match(val_scalar_group2)
if inline_comment:
parameters[val_scalar.group(1)] = inline_comment.group(1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try this:

parameters[val_scalar.group(1)] = inline_comment.group()

else:
parameters[val_scalar.group(1)] = val_scalar.group(2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not functional, but just to avoid calling the group() twice: parameters[val_scalar.group(1)] = val_scalar_group2

continue
val_array = re_array.match(val_n)
if val_array:
# print("val_array", val_array)
parameters.setdefault(val_array.group(1), [])
value = [
to_float(v) for v in val_array.group(2).rstrip("}").split(",")
]
parameters[val_array.group(1)].append(
value[0] if len(value) == 1 else value
)
# print("\nTEST:", parameters)

return parameters

self._quantities = [
Expand Down Expand Up @@ -1065,6 +1076,7 @@ def parse_method(self):
self.parse_interactions(interactions, sec_model)

input_parameters = self.input_parameters
# print("input_parameters", input_parameters)
sec_force_calculations = ForceCalculations()
sec_force_field.force_calculations = sec_force_calculations
sec_neighbor_searching = NeighborSearching()
Expand All @@ -1075,6 +1087,12 @@ def parse_method(self):
int(nstlist) if nstlist else None
)
rlist = to_float(input_parameters.get("rlist", None))
# rlist = (
# to_float(value)
# if (value := input_parameters.get("rlist")) is not None
# else None
# )

sec_neighbor_searching.neighbor_update_cutoff = (
rlist * ureg.nanometer if rlist else None
)
Expand Down Expand Up @@ -1197,6 +1215,12 @@ def get_barostat_parameters(self):
)
return barostat_parameters

# TODO: implement
def get_umbrella_sampling_parameters(self):
umbrella_sampling_parameters = {}
umbrella_sampling = self.input_parameters.get("pull", "")
# print("test", umbrella_sampling)

def get_free_energy_calculation_parameters(self):
free_energy_parameters = {}
free_energy = self.input_parameters.get("free-energy", "")
Expand Down Expand Up @@ -1241,7 +1265,9 @@ def get_free_energy_calculation_parameters(self):

atoms_info = self.traj_parser._results["atoms_info"]
atoms_moltypes = np.array(atoms_info["moltypes"])
# print("atoms_moltypes", atoms_moltypes)
couple_moltype = self.input_parameters.get("couple-moltype", "").split()
print("couple_moltype", self.input_parameters.get("couple-moltype", ""))
n_atoms = len(atoms_moltypes)
indices = []
if len(couple_moltype) == 1 and couple_moltype[0].lower() == "system":
Expand Down Expand Up @@ -1507,6 +1533,7 @@ def parse_input(self):
sec_run.x_gromacs_section_control_parameters = sec_control_parameters
input_parameters = self.input_parameters
input_parameters.update(self.info.get("header", {}))
# print("input_parameters: ", input_parameters)
for key, val in input_parameters.items():
key = (
"x_gromacs_inout_control_%s"
Expand Down
Loading
Loading