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

Conversation

Bernadette-Mohr
Copy link
Collaborator

No description provided.

@Bernadette-Mohr Bernadette-Mohr linked an issue Apr 16, 2024 that may be closed by this pull request
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()

if inline_comment:
parameters[val_scalar.group(1)] = inline_comment.group(1)
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

@JFRudzinski
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for Umbrella Sampling Calculations in NOMAD
2 participants