perturbopy.postproc.utils.constants.conversion_factor
- perturbopy.postproc.utils.constants.conversion_factor(init_units, final_units, units_names, units_vals)
Finds the conversion factor between two units.
- Parameters:
init_units (str) – The initial units in the conversion.
final_units (str) – The final units in the conversion.
units_names (dict) – A dictionary specifying the standard unit name corresponding to a set of possible units names (case-insensitive). See prefix_and_base_units for details.
units_vals (dict) –
A dictionary specifying the conversion factors between different units, with units labeled by their standard name as specified in units_names. Values are represented as tuples (base, exponent).
- Example: For energies, possible units include hartrees and electron-volts.’ Setting one value (hartree = 1), the remaining values
are the conversion factors between different units and hartrees.
energy_units_vals = {‘eV’: (2.7211396132, 1), ‘Ha’: (1, 0),’Ry’: (0.5, 0)}
- Returns:
conversion_factor – The conversion factor to convert from init_units to final_units.
- Return type:
float
- Raises:
ValueError – If the base units of init_units or final_units are not in the keys of units_vals
Examples
>>> conversion_factor('fm', 'cm', {m': ['m', 'meter']}, {'m': (5.29177249, -11)}) 1e-13 >>> conversion_factor('a.u', 'bohr', {'bohr': ['bohr', 'a.u'], 'angstrom': ['angstrom, a']}, {'bohr': (1, 0), 'angstrom': (0.529177249, 0)}) 1.0 >>> conversion_factor('a.u', 'angstrom', {'bohr': ['bohr', 'a.u'], 'angstrom': ['angstrom, a']}, {'bohr': (1, 0), 'angstrom': (0.529177249, 0)}) 0.529177249