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

RecommendedCutoffMixin: improve error messages #86

Merged
merged 2 commits into from
May 6, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions aiida_pseudo/groups/mixins/cutoffs.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,21 +220,25 @@ def delete_cutoffs(self, stringency) -> None:
try:
if stringency == self.get_default_stringency():
self.delete_extra('_default_stringency')
warning += f'`{stringency}` was the default stringency of this family. '
warning += f'`{stringency}` was the default stringency of this family.'
assign_new_default = True
else:
assign_new_default = False
except ValueError:
assign_new_default = True

if assign_new_default:
if len(cutoffs_dict) == 1:
if len(cutoffs_dict) == 0:
warning += (
' Since no other stringencies are defined for this family, no new default can be specified.'
)
elif len(cutoffs_dict) == 1:
final_stringency = list(cutoffs_dict.keys())[0]
self.set_default_stringency(final_stringency)
warning += f'Setting `{final_stringency}` as the default since it is now the only defined stringency.'
warning += f' Setting `{final_stringency}` as the default since it is now the only defined stringency.'
else:
warning += (
f'Please set one of {self.get_cutoff_stringencies()} as the new default stringency with the '
f' Please set one of {self.get_cutoff_stringencies()} as the new default stringency with the '
'`set_default_stringency` method.'
)

Expand Down Expand Up @@ -276,6 +280,7 @@ def get_recommended_cutoffs(self, *, elements=None, structure=None, stringency=N
:return: tuple of recommended wavefunction and density cutoff.
:raises ValueError: if the requested stringency is not defined for this family.
:raises ValueError: if optional unit specified is invalid.
:raises ValueError: if the family does not have a pseudo for one of the elements (of the structure).
"""
if (elements is None and structure is None) or (elements is not None and structure is not None):
raise ValueError('at least one and only one of `elements` or `structure` should be defined')
Expand All @@ -299,6 +304,9 @@ def get_recommended_cutoffs(self, *, elements=None, structure=None, stringency=N

for element in symbols:

if element not in cutoffs:
raise ValueError(f'family does not contain a pseudo for element `{element}`.')
mbercx marked this conversation as resolved.
Show resolved Hide resolved

if unit is not None:
current_unit = self.get_cutoffs_unit(stringency)
values = {k: U.Quantity(v, current_unit).to(unit).to_tuple()[0] for k, v in cutoffs[element].items()}
Expand Down