Skip to content

Commit

Permalink
Fix bug in regex for perturbed atoms
Browse files Browse the repository at this point in the history
  • Loading branch information
bastonero committed Dec 5, 2023
1 parent 4e28e25 commit 7aa81fd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/aiida_quantumespresso_hp/utils/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def is_perturb_only_atom(parameters: dict) -> int | None:
match = None # making sure that if the dictionary is empty we don't raise an `UnboundLocalError`

for key in parameters.keys():
match = re.search(r'perturb_only_atom.*([0-9]).*', key)
match = re.search(r'perturb_only_atom.*?(\d+).*', key)
if match:
if not parameters[key]: # also the key must be `True`
match = None # making sure to have `None`
Expand Down
3 changes: 3 additions & 0 deletions tests/utils/test_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@ def test_is_perturb_only_atom():
parameters = {'perturb_only_atom(1)': True}
assert is_perturb_only_atom(parameters) == 1

parameters = {'perturb_only_atom(20)': True}
assert is_perturb_only_atom(parameters) == 20

parameters = {'perturb_only_atom(1)': False}
assert is_perturb_only_atom(parameters) is None

0 comments on commit 7aa81fd

Please sign in to comment.