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: store the unit of cutoffs in extras #57

Merged
merged 2 commits into from
Apr 9, 2021

Conversation

sphuber
Copy link
Contributor

@sphuber sphuber commented Mar 17, 2021

Fixes #47

By storing the unit of the cutoffs values explicitly in the extras, it
not only will give more certainty to the user of what the cutoffs mean
because they can inspect the unit, but the get_recommended_cutoffs
method can also provide the unit argument to automatically convert it
to another unit of energy if so desired.

The conversion between units is provided by the pint library, which is
added as a dependency. Users can specify units in the API through
strings using the names that are recognized by pint. Both the
shorthand, e.g. eV, as well as the long version electron_volt can be
used. Other common energy units are Ry and Eh, for Rydberg and
Hartree atomic units respectively.

The default unit that is set when defining recommended cutoffs is still
set to be electron volt, which was the implicitly assumed unit uptil now.
Families that have been created with versions preceding this commit,
will not actually have the unit defined in the unit, but
get_cutoffs_unit will return the default electron volt if it is
missing. This does mean that the RecommendedCutoffMixin.DEFAULT_UNIT
cannot be changed or this would lead to old families to be interpreted
to have the incorrect unit.

@sphuber sphuber requested a review from mbercx March 17, 2021 18:43
@sphuber
Copy link
Contributor Author

sphuber commented Mar 17, 2021

@mbercx I served you a cold one! 🍺

Copy link
Member

@mbercx mbercx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deze PR is bijna even lekker als een Tripel Karmeliet! 🍺

Still left a few comments. Main issue is the fact that the units are set to None in the extras when no unit is specified in the set_cutoffs method.

aiida_pseudo/groups/mixins/cutoffs.py Outdated Show resolved Hide resolved
@@ -107,16 +128,19 @@ def set_cutoffs(self, cutoffs: dict, default_stringency: str = None) -> None:
:param default_stringency: the default stringency to be used when ``get_recommended_cutoffs`` is called. If is
possible to not specify this if and only if the cutoffs only contain a single stringency set. That one will
then automatically be set as default.
:param unit: TODO
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

external-content duckduckgo com

aiida_pseudo/groups/mixins/cutoffs.py Show resolved Hide resolved
tests/groups/mixins/test_cutoffs.py Outdated Show resolved Hide resolved
tests/groups/mixins/test_cutoffs.py Outdated Show resolved Hide resolved
By storing the unit of the cutoffs values explicitly in the extras, it
not only will give more certainty to the user of what the cutoffs mean
because they can inspect the unit, but the `get_recommended_cutoffs`
method can also provide the `unit` argument to automatically convert it
to another unit of energy if so desired.

The conversion between units is provided by the `pint` library, which is
added as a dependency. Users can specify units in the API through
strings using the names that are recognized by `pint`. Both the
shorthand, e.g. `eV`, as well as the long version `electron_volt` can be
used. Other common energy units are `Ry` and `Eh`, for Rydberg and
Hartree atomic units respectively.

The default unit that is set when defining recommended cutoffs is still
set to be electron volt, which was the implicitly assumed unit uptil now.
Families that have been created with versions preceding this commit,
will not actually have the unit defined in the unit, but
`get_cutoffs_unit` will return the default electron volt if it is
missing. This does mean that the `RecommendedCutoffMixin`DEFAULT_UNIT`
cannot be changed or this would lead to old families to be interpreted
to have the incorrect unit.
@sphuber sphuber force-pushed the fix/047/add-recommended-cutoff-units branch from 3686caa to 24eb652 Compare April 9, 2021 07:13
@sphuber sphuber modified the milestone: v0.6.0 Apr 9, 2021
@sphuber sphuber requested a review from mbercx April 9, 2021 07:16
mbercx
mbercx previously approved these changes Apr 9, 2021
Copy link
Member

@mbercx mbercx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another round, bartender!

aiida_pseudo/cli/install.py Show resolved Hide resolved
tests/groups/mixins/test_cutoffs.py Outdated Show resolved Hide resolved
tests/groups/mixins/test_cutoffs.py Outdated Show resolved Hide resolved
tests/groups/mixins/test_cutoffs.py Outdated Show resolved Hide resolved
tests/groups/mixins/test_cutoffs.py Outdated Show resolved Hide resolved
tests/groups/mixins/test_cutoffs.py Outdated Show resolved Hide resolved
tests/conftest.py Show resolved Hide resolved
@@ -143,13 +169,17 @@ def get_recommended_cutoffs(self, *, elements=None, structure=None, stringency=N
:param stringency: optional stringency if different from the default.
:return: tuple of recommended wavefunction and density cutoff.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the unit parameter? 😁

Copy link
Member

@mbercx mbercx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⭐ ⭐ ⭐ ⭐ ⭐ Would review again.

@sphuber sphuber merged commit bf621e7 into master Apr 9, 2021
@sphuber sphuber deleted the fix/047/add-recommended-cutoff-units branch April 9, 2021 09:47
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.

Storing the units for the recommended cuttoffs
2 participants