Open Bernadette-Mohr opened 6 months ago
The other quantities parse fine as well. Here is the code I am using, but it should be identical to yours except the changes above
class GromacsMdpParser(TextParser): def __init__(self): super().__init__(None) 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: 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() else: 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
The other quantities parse fine as well. Here is the code I am using, but it should be identical to yours except the changes above