torchspin.lft.units#

Graph-safe unit factors for the ligand-field tools (torchspin.lft).

The public API of torchspin.lft follows torchspin: energies and couplings in MHz, fields in mT, frequencies in GHz, angles in radians, molar susceptibility in m^3/mol (SI, as torchspin.curry() returns it). Ligand-field energies are far easier to read in cm^-1, so every function that returns energies takes units= and every ligand-field plot defaults to cm^-1. The conversions are plain Python floats derived from torchspin.constants, so multiplying a tensor by one keeps the autograd graph (unlike the NumPy torchspin.unitconvert()).

  • Energy units: 'MHz', 'GHz', 'Hz', 'cm^-1' (aliases 'cm-1', 'cm⁻¹', '1/cm', 'wavenumber'), 'K', 'eV', 'meV', 'J'.

  • Field units: 'mT', 'T', 'G'.

  • Molar susceptibility: 'SI' (m^3/mol) and 'cgs' (cm^3/mol, emu), related by chi_cgs = chi_SI * 1e6 / (4 pi).

Examples

>>> from torchspin.lft import units
>>> round(units.energy_factor("cm^-1", "MHz"), 4)
29979.2458
>>> import torch
>>> B = units.convert_field(torch.tensor(3400.0, requires_grad=True), "G", "mT")
>>> round(B.item(), 6), B.requires_grad
(340.0, True)
>>> units.canonical_energy_unit("1/cm"), units.energy_label("cm-1")
('cm^-1', 'cm⁻¹')
torchspin.lft.units.PLOT_ENERGY_UNITS = 'cm^-1'#

Default unit of every ligand-field plot (level, Tanabe-Sugano, Zeeman and angle diagrams).

torchspin.lft.units.energy_factor(from_, to)[source]#

Factor that converts an energy from from_ to to (a Python float).

Raises ValueError for an unknown unit.

torchspin.lft.units.convert_energy(x, from_, to)[source]#

Convert an energy from from_ to to.

x may be a float, array or tensor (the autograd graph is kept); returned unchanged when the factor is 1. Raises ValueError for an unknown unit.

torchspin.lft.units.field_factor(from_, to)[source]#

Factor that converts a magnetic field from from_ to to ('mT', 'T', 'G').

Raises ValueError for an unknown unit.

torchspin.lft.units.convert_field(x, from_, to)[source]#

Convert a magnetic field x (float, array or tensor; graph kept) from from_ to to.

Raises ValueError for an unknown unit.

torchspin.lft.units.chi_factor(from_, to)[source]#

Factor that converts a molar susceptibility from from_ to to.

Units 'SI' (m^3/mol) or 'cgs' (cm^3/mol); raises ValueError otherwise.

torchspin.lft.units.convert_chi(x, from_, to)[source]#

Convert a molar susceptibility x (float, array or tensor; graph kept) between 'SI' and 'cgs'.

Raises ValueError for an unknown unit.

torchspin.lft.units.energy_label(unit)[source]#

Axis-label text for an energy unit ('cm^-1' -> 'cm⁻¹'); raises ValueError for an unknown unit.

torchspin.lft.units.canonical_energy_unit(unit)[source]#

Canonical spelling of an energy unit ('cm-1' -> 'cm^-1').

Raises:

ValueError – For an unknown unit.