Skip to content

Commit

Permalink
XspectraCrystalWorkChain: Requested Changes 1
Browse files Browse the repository at this point in the history
Changes requested for PR aiidateam#1028:

* Small refactor of input validation code to condense checks into fewer
  lines.
* Re-arranged checks to ensure that `site_index` validation occurs
  *after* `required_keys` are checked. Previous behaviour would not
indicate which entry/entries were missing the `site_index`
* Fixed a small formatting error in the error message for mismatch in
  absorbing elements.
  • Loading branch information
PNOGillespie committed May 23, 2024
1 parent 0f06292 commit fdc821e
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions src/aiida_quantumespresso/workflows/xspectra/crystal.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,26 +461,21 @@ def validate_inputs(inputs, _):
# We assume otherwise that the user knows what they're doing and has set everything else
# to their preferences correctly.
for site_label, value in equivalent_sites_data.items():
required_keys_found = []
entry_invalid = False

if value['site_index'] < 0:
raise ValidationError(
f'The site index for {site_label} ({value["site_index"]}) is below the range of '
+ f'sites within the structure (0-{len(structure.sites) -1}).'
)
if value['site_index'] >= len(structure.sites):
raise ValidationError(
f'The site index for {site_label} ({value["site_index"]}) is above the range of '
+ f'sites within the structure (0-{len(structure.sites) -1}).'
)
for key in value:
if key in required_keys:
required_keys_found.append(key)
if sorted(required_keys_found) != required_keys:
if not set(required_keys).issubset(set(value.keys())) :
invalid_entries.append(site_label)
entry_invalid = True
elif value['symbol'] not in input_elements:
input_elements.append(value['symbol'])

if not entry_invalid:
if value['site_index'] < 0 or value['site_index'] >= len(structure.sites):
raise ValidationError(
f'The site index for {site_label} ({value["site_index"]}) is outside the range of '
+ f'sites within the structure (0-{len(structure.sites) -1}).'
)

if len(invalid_entries) != 0:
raise ValidationError(
f'The required keys ({required_keys}) were not found in the following entries: {invalid_entries}'
Expand All @@ -490,7 +485,7 @@ def validate_inputs(inputs, _):
if sorted_input_elements != absorbing_elements_list:
raise ValidationError(
f'Elements defined for sites in `equivalent_sites_data` ({sorted_input_elements}) do not match the'
+ f'list of absorbing elements ({absorbing_elements_list})'
+ f' list of absorbing elements ({absorbing_elements_list})'
)


Expand Down

0 comments on commit fdc821e

Please sign in to comment.