Unit systems

Contributed by George Trenins.

Some common unit systems for converting to and from SI. A unit system is defined in terms of seven base units that span the dimensions of length, mass, time, electric current, amount of substance, luminous intensity, and thermodynamic temperature.

class tools.units.SI[source]

Base units of metre, kilogram, second, ampere, mole, candela and Kelvin.

class tools.units.atomic[source]

Base units of \(\hbar\), mass of electron, Bohr radius, and charge of electron.

class tools.units.hartAng[source]

Base units of \(\hbar\), Hartree, angstrom, and charge of electron.

class tools.units.kcalAfs[source]

Base units of \(\text{kcal}\cdot\text{mol}^{-1}\), angstrom, femtosecond, and \(1/4\pi\epsilon_0\)

class tools.units.kcalAamu[source]

Base units of \(\text{kcal}\cdot\text{mol}^{-1}\), angstrom, Dalton, and \(1/4\pi\epsilon_0\)

class tools.units.eVAamu[source]

Base units of electronvolt, angstrom, Dalton, and coulomb

Physical constants

You can get the values of some physical constants by instantiating a unit system and accessing the corresponding property

import units

atomic = units.atomic()
print(atomic.hbar)       # 1.0
print(atomic.amu)        # 1822.8884862173131
print(atomic.kb)         # 3.1668115634438576e-06

The following constants are implemented in all unit-system classes

class tools.units.SI[source]

Base units of metre, kilogram, second, ampere, mole, candela and Kelvin.

property hbar

Value of the reduced Planck constant in base units.

property e

Absolute value of the charge of the electron in base units.

property kb

Boltzmann constant in base units.

property amu

Atomic mass unit (Dalton) in base units.

property me

Mass of the electron in base units.

property c

Speed of light in vacuum, in base units.

Dimensions

There is a similar mechanism for getting the base dimensional unit converted to SI (implemented dimensions are energy, length, time, mass, charge, luminous_intensity, amount, current, temperature, action, angular_momentum, vacuum_permitivity)

print(atomic.length)     # 5.29177210903e-11
print(atomic.mass)       # 9.1093837015e-31
print(atomic.action)     # 1.0545718176461567e-34

Unit conversion

A “human-readable” unit conversion can be done using the methods

class tools.units.SI[source]

Base units of metre, kilogram, second, ampere, mole, candela and Kelvin.

str2base(string)[source]

Given a string representation of a quantity, such as ‘1 mm’, return the corresponding numerical value in base units. If not of type str, the input us returned unchanged. If the string contains no units, it is simply converted to a float.

Parameters:

quantity (string) – a physical quantity in the format ‘value unit’

Returns:

converted quantity

Return type:

float

str2SI(string)[source]

Return the numerical value of the input string in SI units. See str2base for details.

atomic.str2base("1 mp")  # mass of proton in atomic units, prints 1836.15267344
atomic.str2SI("1 a0")    # Bohr radius in metres, prints 5.29177210903e-11
atomic.str2base("1 fs")  # femtosecond in atomic units of time, 41.341373335335184

Conversion to/from wavenumbers

Conversion between base units of energy or radial frequency and wavenumbers (\(\text{cm}^{-1}\)) is handled separately.

class tools.units.SI[source]

Base units of metre, kilogram, second, ampere, mole, candela and Kelvin.

energy2wn(E)[source]

Convert from energy to wavenumbers.

Parameters:

E – energy in base units

Returns:

wavenumber in \(\mathrm{cm}^{-1}\)

Return type:

float

wn2energy(wn)[source]

Convert from wavenumbers to energy.

Parameters:

wn – wavenumber in \(\mathrm{cm}^{-1}\)

Returns:

energy in base units

Return type:

float

omega2wn(w)[source]

Convert from radial frequency to wavenumbers.

Parameters:

w – radial frequency in units of rad per base unit of time

Returns:

wavenumber in \(\mathrm{cm}^{-1}\)

Return type:

float

wn2omega(wn)[source]

Convert from wavenumbers to radial frequency .

Parameters:

wn – wavenumber in \(\mathrm{cm}^{-1}\)

Returns:

radial frequency in units of rad per base unit of time

Return type:

float