aiidateam / aiida-pseudo

MIT License
5 stars 8 forks source link

CLI: Add support for units to `family show` #97

Closed mbercx closed 3 years ago

mbercx commented 3 years ago

Fixes #96

Although we now support specifying units for the recommended cutoffs, the family show method had not been adapted for this feature.

Here we add the -u/--unit option to the family show method, making sure to show the correct unit in the table header as well as adapting the values in the columns by supplying the unit to the get_recommended_cutoffs method.

There is also some refactoring regarding the validation of the stringencies. The RecommendedCutoffMixin.validate_stringency method was not being used, so we adapt the code for several methods with the stringency input to rely on this validation method. This way we have a consistent and succinct error message in case the user requests a stringency that has not been configured.

mbercx commented 3 years ago

Usage:

$ aiida-pseudo family show -h
Usage: aiida-pseudo family show [OPTIONS] FAMILY

  Show details of pseudo potential family.

Options:
  -s, --stringency TEXT  Stringency level for the recommended cutoffs.
  -u, --unit TEXT        Specify the energy unit of the cutoffs. Must be
                         recognized by the ``UnitRegistry`` of the ``pint``
                         library.

  -r, --raw              Display only raw query results, without any headers
                         or footers.

  -h, --help             Show this message and exit.

Specifying no unit:

$ aiida-pseudo family show SSSP/1.1/PBE/efficiency 
Element    Pseudo                          MD5                                 Wavefunction (Ry)    Charge density (Ry)
---------  ------------------------------  --------------------------------  -------------------  ---------------------
Ag         Ag_ONCV_PBE-1.0.oncvpsp.upf     94f47bd0669c641108e45594df92fabc                 50.0                  200.0
Al         Al.pbe-n-kjpaw_psl.1.0.0.UPF    cfc449ca30b5f3223ec38ddd88ac046d                 30.0                  240.0
Ar         Ar_ONCV_PBE-1.1.oncvpsp.upf     46d28409cdd246843f76b7675277a949                 60.0                  240.0
As         As.pbe-n-rrkjus_psl.0.2.UPF     767315de957beeeb34f87d97bf945c8f                 35.0                  280.0

Specifying hartree:

$ aiida-pseudo family show SSSP/1.1/PBE/efficiency --unit hartree
Element    Pseudo                          MD5                                 Wavefunction (hartree)    Charge density (hartree)
---------  ------------------------------  --------------------------------  ------------------------  --------------------------
Ag         Ag_ONCV_PBE-1.0.oncvpsp.upf     94f47bd0669c641108e45594df92fabc                      25.0                       100.0
Al         Al.pbe-n-kjpaw_psl.1.0.0.UPF    cfc449ca30b5f3223ec38ddd88ac046d                      15.0                       120.0
Ar         Ar_ONCV_PBE-1.1.oncvpsp.upf     46d28409cdd246843f76b7675277a949                      30.0                       120.0
As         As.pbe-n-rrkjus_psl.0.2.UPF     767315de957beeeb34f87d97bf945c8f                      17.5                       140.0

Specifying eV:

$ aiida-pseudo family show SSSP/1.1/PBE/efficiency --unit eV
Element    Pseudo                          MD5                                 Wavefunction (eV)    Charge density (eV)
---------  ------------------------------  --------------------------------  -------------------  ---------------------
Ag         Ag_ONCV_PBE-1.0.oncvpsp.upf     94f47bd0669c641108e45594df92fabc                680.3                 2721.1
Al         Al.pbe-n-kjpaw_psl.1.0.0.UPF    cfc449ca30b5f3223ec38ddd88ac046d                408.2                 3265.4
Ar         Ar_ONCV_PBE-1.1.oncvpsp.upf     46d28409cdd246843f76b7675277a949                816.3                 3265.4
As         As.pbe-n-rrkjus_psl.0.2.UPF     767315de957beeeb34f87d97bf945c8f                476.2                 3809.6

Specifying attojoules (because why not?):

$ aiida-pseudo family show SSSP/1.1/PBE/efficiency --unit aJ
Element    Pseudo                          MD5                                 Wavefunction (aJ)    Charge density (aJ)
---------  ------------------------------  --------------------------------  -------------------  ---------------------
Ag         Ag_ONCV_PBE-1.0.oncvpsp.upf     94f47bd0669c641108e45594df92fabc                109.0                  436.0
Al         Al.pbe-n-kjpaw_psl.1.0.0.UPF    cfc449ca30b5f3223ec38ddd88ac046d                 65.4                  523.2
Ar         Ar_ONCV_PBE-1.1.oncvpsp.upf     46d28409cdd246843f76b7675277a949                130.8                  523.2
As         As.pbe-n-rrkjus_psl.0.2.UPF     767315de957beeeb34f87d97bf945c8f                 76.3                  610.4
mbercx commented 3 years ago

@sphuber this is ready for another round of review! I've still left some comments unresolved since there might still be some discussion.