aiida_pseudo.groups.mixins.cutoffs
==================================

.. py:module:: aiida_pseudo.groups.mixins.cutoffs

.. autoapi-nested-parse::

   Mixin that adds support of recommended cutoffs to a ``Group`` subclass, using its extras.



Classes
-------

.. autoapisummary::

   aiida_pseudo.groups.mixins.cutoffs.RecommendedCutoffMixin


Module Contents
---------------

.. py:class:: RecommendedCutoffMixin

   Mixin that adds support of recommended cutoffs to a ``Group`` subclass, using its extras.

   This class assumes that the cutoffs apply to a plane-wave based code and as such the cutoffs pertain to the wave
   functions and the charge density. The units have to be in electronvolt.


   .. py:attribute:: DEFAULT_UNIT
      :value: 'eV'



   .. py:attribute:: _key_cutoffs
      :value: '_cutoffs'



   .. py:attribute:: _key_cutoffs_unit
      :value: '_cutoffs_unit'



   .. py:attribute:: _key_default_stringency
      :value: '_default_stringency'



   .. py:method:: validate_cutoffs(elements: set, cutoffs: dict) -> None
      :staticmethod:


      Validate a cutoff dictionary for a given set of elements.

      :param elements: set of elements for which to validate the cutoffs dictionary.
      :param cutoffs: dictionary with recommended cutoffs. Format: set of recommended cutoffs written as a
          dictionary that maps each element for which the family contains a pseudopotential to a dictionary that
          specifies the ``cutoff_wfc`` and ``cutoff_rho`` keys, corresponding a float value with the recommended
          cutoff to be used for the wave functions and charge density, respectively. For example:

          .. code-block::

              {
                  "Ag": {
                      "cutoff_wfc": 50.0,
                      "cutoff_rho": 200.0
                  },
                  ...
              }
      :raises ValueError: if the set of elements and those defined in the cutoffs do not match exactly, or if the
          cutoffs dictionary has an invalid format.



   .. py:method:: validate_cutoffs_unit(unit: str) -> None
      :staticmethod:


      Validate the cutoffs unit.

      The unit should be a name that is recognized by the ``pint`` library to be a unit of energy.

      :raises ValueError: if an invalid unit is specified.



   .. py:method:: validate_stringency(stringency: Optional[str]) -> None

      Validate a cutoff stringency.

      Check if the stringency is defined for the family. If no stringency input is passed, the method checks if a
      default stringency has been set.

      :param stringency: the cutoff stringency to validate.
      :raises ValueError: if `stringency` is equal to `None` and the family defines no default stringency.
      :raises ValueError: if the family does not define cutoffs for the specified stringency.



   .. py:method:: _get_cutoffs_dict() -> dict

      Return the cutoffs dictionary that maps the stringencies to the recommended cutoffs.

      :return: the cutoffs extra or an empty dictionary if it has not yet been set.



   .. py:method:: _get_cutoffs_unit_dict() -> dict

      Return the cutoffs units for each of the stringencies.

      :return: the cutoffs units extra or an empty dictionary if it has not yet been set.



   .. py:method:: get_default_stringency() -> str

      Return the default stringency if defined.

      :return: the default stringency.
      :raises ValueError: if default stringency has not been defined.



   .. py:method:: set_default_stringency(default_stringency: str) -> None

      Set the default stringency for the recommended cutoffs.

      :param default_stringency: the default stringency to be used for the recommended cutoffs.
      :raises ValueError: if the provided default stringency is not in the tuple of available cutoff stringencies for
          the pseudo family.
      :raises ValueError: if the user tries to unset the stringency by providing ``None`` as an input.



   .. py:method:: get_cutoff_stringencies() -> tuple

      Return a tuple of the available cutoff stringencies.

      :return: the tuple of stringencies that are defined for this family.



   .. py:method:: set_cutoffs(cutoffs: dict, stringency: str, unit: Optional[str] = None) -> None

      Set the recommended cutoffs for the pseudos in this family and a specified stringency.

      .. note: If, after the cutoffs have been set, there is only one stringency defined for the pseudo family, this
          method will automatically set this as the default. Use the ``set_default_stringency`` method to change the
          default when setting multiple stringencies.

      :param cutoffs: dictionary with recommended cutoffs. Format: set of recommended cutoffs written as a
          dictionary that maps each element for which the family contains a pseudopotential to a dictionary that
          specifies the ``cutoff_wfc`` and ``cutoff_rho`` keys, corresponding a float value with the recommended
          cutoff to be used for the wave functions and charge density, respectively. For example:

          .. code-block::

              {
                  "Ag": {
                      "cutoff_wfc": 50.0,
                      "cutoff_rho": 200.0
                  },
                  ...
              }
      :param stringency: the stringency corresponding to the provided cutoffs.
      :param unit: string definition of a unit of energy as recognized by the ``UnitRegistry`` of the ``pint`` lib.
          Defaults to electronvolt.
      :raises ValueError: if the cutoffs have an invalid format or the unit is not a valid energy unit.



   .. py:method:: get_cutoffs(stringency: Optional[str] = None) -> dict

      Return a set of cutoffs for the given stringency.

      :param stringency: optional stringency for which to retrieve the cutoffs. If not specified, the default
          stringency of the family is used.
      :raises ValueError: if no stringency is specified and no default stringency is defined for the family.
      :raises ValueError: if the requested stringency is not defined for this family.



   .. py:method:: delete_cutoffs(stringency: str) -> None

      Delete the recommended cutoffs for a specified stringency.

      .. note: If, after the cutoffs have been deleted, there is only one stringency defined for the pseudo family,
          this method will automatically set this as the default. Use the ``set_default_stringency`` method to change
          the default in case multiple stringencies are still defined.

      :param stringency: stringency for which to delete the cutoffs.
      :raises ValueError: if the requested stringency is not defined for this family.



   .. py:method:: get_cutoffs_unit(stringency: Optional[str] = None) -> str

      Return the cutoffs unit for the specified or family default stringency.

      :param stringency: optional stringency for which to retrieve the unit. If not specified, the default stringency
          of the family is used.
      :return: the string representation of the unit of the cutoffs.
      :raises ValueError: if no stringency is specified and no default stringency is defined for the family.
      :raises ValueError: if the requested stringency is not defined for this family.



   .. py:method:: get_recommended_cutoffs(*, elements=None, structure=None, stringency=None, unit=None)

      Return tuple of recommended wavefunction and density cutoffs for the given elements or ``StructureData``.

      .. note:: at least one and only one of arguments ``elements`` or ``structure`` should be passed.

      :param elements: single or tuple of elements.
      :param structure: a ``StructureData`` node.
      :param stringency: optional stringency if different from the default.
      :param unit: string definition of a unit of energy as recognized by the ``UnitRegistry`` of the ``pint`` lib.
      :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).



