perturbopy.postproc.utils.constants.find_prefix_and_base_units

perturbopy.postproc.utils.constants.find_prefix_and_base_units(user_input_units, units_dict)

Dissects units to a prefix and base units, both with standardized names as specified by units_dict. For example, for the units ‘meV’, the prefix is ‘m’ and the base units are ‘eV’.

Parameters:
  • user_input_units (str) – The units to be analyzed for its prefix and base.

  • units_dict (dict) –

    A dictionary specifying the standard unit name corresponding to a set of possible units names (case-insensitive).

    For example, several possible variations of the unit hatree include Ha, hartree, etc. If Ha is chosen as the standard name, then the dictionary entry will be: {‘Ha’: [‘ha’, ‘hartree’, ‘eh’, ‘e_h’, ‘hartrees’]}

    Adding the unit Joule to the dict, and setting its standard name to ‘J’: {‘Ha’: [‘ha’, ‘hartree’, ‘eh’, ‘e_h’, ‘hartrees’], ‘J’: [‘j’, ‘joule’, ‘joules’]}

Returns:

  • prefix (str) – The standardized prefix.

  • standard_units_name (str) – The standardized base unit name.

Raises:

ValueError – If the user_input_units, after removing any prefixes, is not in the keys or values of the units_dict.

Examples

>>> find_prefix_and_base_units('nm', {'m':['m', 'meter']})
('n', 'm')
>>> find_prefix_and_base_units('nmeter', {'m':['m', 'meter']})
('n', 'm')
>>> find_prefix_and_base_units('meter', {'m':['m', 'meter']})
('', 'm')
>>> find_prefix_and_base_units('cm', {'m':['m', 'meter']}, 'bohr': ['bohr', 'a.u'])
('c', 'm')
>>> find_prefix_and_base_units('a.u.', {'m':['m', 'meter']}, 'bohr': ['bohr', 'a.u.'])
('', 'bohr')