pyPRISM.util.UnitConverter module

class pyPRISM.util.UnitConverter.UnitConverter(dc=1.0, dc_unit='nanometer', mc=14.02, mc_unit='gram/mole', ec=2.48, ec_unit='kilojoule/mole')[source]

Bases: object

Unit conversion utility

Description

pyPRISM operates in a system of reduced units commonly called ‘Lennard Jones units’. In this unit system, all measures are reported relative to characteristic values: length = \(d_c\), mass = \(m_c\), and energy = \(e_c\). This class is designed to make some common conversions between reduced and real units easier.

See the Theory.General notebook of the Tutorial for a more detailed discussion of these units and how to work with the UnitConverter utility.

Note

The methods prefixed with “to” all expect floating point values in reduced units and convert to real units.

Warning

This class uses the Pint package. While the rest of pyPRISM will function without Pint, this class will not be available without this dependency installed in the current environment.

Example

import pyPRISM

domain = pyPRISM.Domain(length=4096,dr=0.25)

# create unit converter utility
uc = pyPRISM.util.UnitConverter(dc=1.5,dc_unit='nm')

# convert wavenumber from LJ units to real units
# using built-in conversion
real_k = uc.toInvAngstrom(domain.k)
real_k_magnitudes = real_k.magnitude

# convert radius in real units to reduced units
# manually using pint
real_radius = 123.5 # angstrom
reduced_radius = real_radius * uc('angstrom').to('dc').magnitude
__call__(unit_string)[source]

Convenience method for accessing the pint UnitRegistry

__init__(dc=1.0, dc_unit='nanometer', mc=14.02, mc_unit='gram/mole', ec=2.48, ec_unit='kilojoule/mole')[source]

Constructor

Parameters:
  • dc,dc_unit (float,str) – Magnitude and unit of characteristic distance
  • mc,mc_unit (float,str) – Magnitude and unit of characteristic mass
  • ec,ec_unit (float,str) – Magnitude and unit of characteristic energy
d,dc

The defined characteristic distance as a defined Pint Quantity.

Type:Pint Quantity
m,mc

The defined characteristic mass as a defined Pint Quantity.

Type:Pint Quantity
e,ec

The defined characteristic energy as a defined Pint Quantity.

Type:Pint Quantity
toCelcius(temperature)[source]

Convert thermal energy to temperature units in Celcius

Parameters:temperature (float or np.ndarray of floats) – Value of thermal energy (\(k_{B}T\)) to be converted
Returns:temperature – temperature in Kelvin as a Pint Quantity. Use the magnitude attribute (temperature.magnitude) to obtain the numerical value of the temperature as a floating point value.
Return type:Pint Quantity
toConcentration(density)[source]

Convert reduced number density to real concentration units

Parameters:density (float, or np.ndarray of floats) – Value(s) of density to be converted
Returns:concentration – density in \(mol/L\) as a Pint Quantity. Use the magnitude attribute (concentration.magnitude) to obtain the numerical value of the contration as a floating point value.
Return type:Pint Quantity
toInvAngstrom(wavenumber)[source]

Convert wavenumbers to real units

Parameters:wavenumber (float, or np.ndarray of floats) – Value(s) of wavenumbers to be converted
Returns:wavenumber – wavenumbers in \(AA^{-1}\) as a Pint Quantity. Use the magnitude attribute (wavenumber.magnitude) to obtain the numerical value of the wavenumber as a floating point value.
Return type:Pint Quantity
toInvNanometer(wavenumber)[source]

Convert wavenumbers to real units

Parameters:wavenumber (float, or np.ndarray of floats) – Value(s) of wavenumbers to be converted
Returns:wavenumber – wavenumbers in \(nm^{-1}\) as a Pint Quantity. Use the magnitude attribute (wavenumber.magnitude) to obtain the numerical value of the wavenumber as a floating point value.
Return type:Pint Quantity
toKelvin(temperature)[source]

Convert thermal energy to temperature units in \(K\)

Parameters:temperature (float or np.ndarray of floats) – Value of thermal energy (\(k_{B}T\)) to be converted
Returns:temperature – temperature in \(K\) as a Pint Quantity. Use the magnitude attribute (temperature.magnitude) to obtain the numerical value of the temperature as a floating point value.
Return type:Pint Quantity
toVolumeFraction(density, diameter)[source]

Convert reduced number density to volume fraction

Parameters:
  • density (float, or np.ndarray of floats) – Value(s) of density to be converted
  • diameter (float) – diameter of the site associated with the density
Returns:

vol_fraction – unitless volume as a Pint Quantity. Use the magnitude attribute (vol_fraction.magnitude) to obtain the numerical value of the volume fraction as a floating point value.

Return type:

Pint Quantity