Unit handling

metatrain.utils.units.get_gradient_units(base_unit: str, gradient_name: str, length_unit: str) str[source]

Get the gradient units based on the unit of the base quantity.

For example, if the base unit is “<unit>” and the gradient name is “positions”, the gradient unit will be “<unit>/<length_unit>”.

Parameters:
  • base_unit (str) – The unit of the base quantity.

  • gradient_name (str) – The name of the gradient.

  • length_unit (str) – The unit of lengths.

Returns:

The unit of the gradient.

Return type:

str

metatrain.utils.units.ev_to_mev(value: float, unit: str) Tuple[float, str][source]

If the unit starts with eV, converts the value and its corresponding unit to meV. Otherwise, returns the input.

Parameters:
  • value (float) – The value (potentially in eV or a derived quantity of eV).

  • unit (str) – The unit of the value.

Returns:

If the value is in meV (or a derived quantity), the value and the corresponding unit where eV is converted to meV. Otherwise, the input.

Return type:

Tuple[float, str]