Quantity Library¶

This library contains all classes related to handling physical units in SAMSON.

See also

SAMSON API: The SBDQuantity Library

This module is already imported in the Python Scripting Element as follows

from samson.DataModel import Quantity

This module provides the possibility to operate with quantities in the following unit systems:

Each unit system has an according base class and a set of convenience constructors for the most used units (see the description for each unit system). These convenience constructors present each unit in the unit system and their combinations. These convenience constructors internaly call the unit system’s base class with proper Quantity units. In the case if there is no convenience constructor for a quantity in a unit system that you want to use, you can create it using the unit system’s base class by providing exponents and scales or by combining quantities with existing convenience constructors using arithmetic operations.

Note

For now unit systems support only the integer-based scales i.e. square length but not length to the power of 3/2.

Examples¶

To initialize a physical quantity you can use either the full name of the quantity or its short-name. For example, the next two definitions are equivalent:

Quantity.picometer(1.23)
# is the same as
Quantity.pm(1.23)

Quantity.picometer(1.23) == Quantity.pm(1.23)         # True

It is possible to initialize quantities based on quantites of the same type, e.g.:

Quantity.angstrom(Quantity.nm(1))
# is the same as
Quantity.angstrom(10)

You can get a floating-point value of quantities in the next way:

l = Quantity.nanometer(1.2)
t = Quantity.femtosecond(0.5)
# the same using short-names:
# l = Quantity.nm(1.2)
# t = Quantity.fs(0.5)
l.value
t.value

Quantity.momentOfInertia(3.5).value

You can convert them to another quantity, like this:

l.picometer
t.second
# the same using short-names
l.pm
t.s

Quantity.force(1.0).nN

Arithmetic operations can be used with quantities, for example:

Quantity.nanometer(1.2) / Quantity.femtosecond(0.5)   # which is equal to Quantity.picometerPerSecond(0.6)
# using short-names:
Quantity.nm(1.2) / Quantity.fs(0.5)                   # which is equal to Quantity.pmPerS(0.6)

Conversion between unit systems¶

A Quantity object in each unit system has attributes that provide the possibility of converting it into an appropriate Quantity object in another unit systems, if possibile.

e = Quantity.energy(1.2)                              # energy in the SI unit system
# conversion to eV in the Electronvolt Unit System
e.eV

mass = Quantity.yoctogram(12)                         # using short-names: Quantity.yg(12)
# from yoctogram to dalton
mass_in_dalton = mass.dalton                          # using short-names: mass.Da
# from yoctogram to auMass
mass_in_au = mass.auMass

energy = Quantity.kilojoule(13)                       # using short-names: Quantity.kJ(13)
# from joule to joulePerMole
energy_in_JPerMol = energy.joulePerMole               # using short-names: energy.JPerMol
# from joule to electronvolt
energy_in_eV = energy.electronvolt                    # using short-names: energy.eV
# from joule to kilocaloriePerMole
energy_in_kcalPerMol = energy.kilocaloriePerMole      # using short-names: energy.kcalPerMol
# from joule to hartree
energy_in_hartree = energy.hartree                    # using short-names: energy.Eh

Mathematical functions¶

The Quantity module also provides a set of mathematical functions that can be used with quantities: