Skip to content

Commit

Permalink
Address review 2
Browse files Browse the repository at this point in the history
  • Loading branch information
bastonero committed Jun 26, 2024
1 parent f72e4b8 commit 1f55493
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 41 deletions.
25 changes: 12 additions & 13 deletions src/aiida_quantumespresso/parsers/parse_raw/ph.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,16 +442,16 @@ def parse_ph_dynmat(data, logs, lattice_parameter=None, also_eigenvectors=False,
return parsed_data


def parse_initialization_qpoints(stdout: str) -> tuple[dict, bool]:
def parse_initialization_qpoints(stdout: str) -> dict:
"""Return the number of q-points from an initialization run.
Here, the initialization run refers to the one performed by specifying
`start_irr` and `last_irr` to 0 in the inputs.
:return: (parsed dictionary, error found), the last is a boolean
regarding whether an expected quantity has not been properly
parse; it also checks that the number of q-points parsed within
parenthesis and the amount of q-points parsed from coordinaes coincide.
:return: parsed dictionary
:raise: `RuntimeError` if the number of q-points cannot be parsed or it
differs from the number of q-points in the stdout list.
"""
import re

Expand All @@ -462,6 +462,8 @@ def parse_initialization_qpoints(stdout: str) -> tuple[dict, bool]:
match = re.search(pattern, stdout)
if match:
parameters.update({'number_of_qpoints': int(match.group(1))})
else:
raise RuntimeError('the number of q-points cannot be parsed')

# Regular expression pattern to match the q-points section
pattern = r'\(\s*\d+\s*q-points\):\s*\n\s*N\s*xq\(1\)\s*xq\(2\)\s*xq\(3\)\s*\n((?:\s*\d+\s*[\d\.\-\s]+\n?)*)'
Expand All @@ -475,13 +477,10 @@ def parse_initialization_qpoints(stdout: str) -> tuple[dict, bool]:

coords = re.findall(coord_pattern, q_points_block) # Find all coordinates in the block
q_points = [list(map(float, coord)) for coord in coords]
else:
raise RuntimeError('the list of q-points cannot be parsed')

parameters.update({'q_points': q_points})

if 'number_of_qpoints' not in parameters and 'q_points' not in parameters:
return parameters, False

if parameters['number_of_qpoints'] != len(parameters['q_points']):
return parameters, False
if parameters['number_of_qpoints'] != len(q_points):
raise RuntimeError('the number of q-points do not coincde with the number of listed q-points')

return parameters, True
return parameters
7 changes: 4 additions & 3 deletions src/aiida_quantumespresso/parsers/ph.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ def parse(self, **kwargs):
# When `start_irr` and `last_irr` are set to 0, `JOB DONE` is not in stdout (expected behaviour).
# Though, we at least expect that `stdout` is not empty, otherwise something went wrong.
if stdout and _is_initialization(self.node.inputs.parameters.get_dict()):
parameters, parsed_ok = parse_initialization_qpoints(stdout)
if parsed_ok:
try:
parameters = parse_initialization_qpoints(stdout)
self.out('output_parameters', orm.Dict(parameters))
return
# we let it go, as it should exit with STDOUT_INCOMPLETE or similar
except RuntimeError as exc:
logs.error.append('ERROR_OUTPUT_STDOUT_INCOMPLETE')

# If the scheduler detected OOW, simply keep that exit code by not returning anything more specific.
if self.node.exit_status == PhCalculation.exit_codes.ERROR_SCHEDULER_OUT_OF_WALLTIME:
Expand Down
25 changes: 0 additions & 25 deletions tests/parsers/test_ph/test_ph_initialization.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1 @@
number_of_qpoints: 8
q_points:
- - 0.0
- 0.0
- 0.0
- - 0.0
- 0.0
- -0.061660223
- - 0.0
- -0.577350269
- 0.0
- - 0.0
- -0.577350269
- -0.061660223
- - -0.5
- -0.288675135
- 0.0
- - -0.5
- -0.288675135
- -0.061660223
- - -0.5
- -0.866025404
- 0.0
- - -0.5
- -0.866025404
- -0.061660223

0 comments on commit 1f55493

Please sign in to comment.