moldesign.units package¶
Submodules¶
moldesign.units.constants module¶
moldesign.units.quantity module¶
Set up physical constants and unit systems
-
class
moldesign.units.quantity.
Array
(*args)[source]¶ Bases:
moldesign.units.quantity.MdtQuantity
A matrix quantity (i.e., a matrix of floats) with attached units, which behaves like a 2-dimensional numpy array
-
class
moldesign.units.quantity.
MdtQuantity
[source]¶ Bases:
pint.unit.Quantity
This is a ‘patched’ version of pint’s quantities that can be pickled (slightly hacky) and supports more numpy operations. Users should never need to instantiate this directly - instead, construct MDT quantities by multiplying numbers/arrays with the pre-defined units
Examples
>>> 5.0 * units.femtoseconds >>> [1.0,2.0,3.0] * units.eV
-
compare
(other, op)[source]¶ Augments the
pint._Quantity
method with the following features: - Comparisons to dimensionless 0 can proceed without unit checking
-
defunits
()[source]¶ Return this quantity in moldesign’s default unit system (as specified in moldesign.units.default)
-
ldot
(other)[source]¶ Left-multiplication version of dot. Use this to preserve units (built-in numpy versions don’t) getting hackier ...
-
shape
¶
-
value_in
(units)¶ Quantity’s magnitude expressed in particular units.
Parameters: units (Quantity, str or dict) – destination units
-
-
class
moldesign.units.quantity.
MdtUnit
[source]¶ Bases:
pint.unit.Unit
Pickleable version of pint’s Unit class.
-
class
moldesign.units.quantity.
Scalar
(*args)[source]¶ Bases:
moldesign.units.quantity.MdtQuantity
A scalar quantity (i.e., a single floating point number) with attached units
-
class
moldesign.units.quantity.
Tensor
(*args)[source]¶ Bases:
moldesign.units.quantity.MdtQuantity
A vector quantity (i.e., a list of floats) with attached units, which behaves like a multidimensional numpy array
-
class
moldesign.units.quantity.
Vector
(*args)[source]¶ Bases:
moldesign.units.quantity.MdtQuantity
A vector quantity (i.e., a list of floats) with attached units, which behaves like a 1-dimensional numpy array
moldesign.units.tools module¶
-
moldesign.units.tools.
array
(qlist, baseunit=None)[source]¶ - Facilitates creating an array with units - like numpy.array, but it also checks
units for all components of the array
- Args:
- qlist (List[MdtQuantity]): List-like object of quantity objects baseunit (MdtUnit) unit to standardize with
Returns: array with standardized units Return type: MdtQuantity
-
moldesign.units.tools.
units_transfer
(from_var, to_var, force=False)[source]¶ Give the “to_var” object the same units as “from_var”
Parameters: - from_var (MdtQuantity) – use this quantities units
- to_var (MdtQuantity) – apply units to this quantity
- force (bool) – Transfer the units even if from_var and to_var have incompatible units
Returns: to_var with from_var’s units
Return type:
moldesign.units.unitsystem module¶
-
class
moldesign.units.unitsystem.
UnitSystem
(length, mass, time, energy, temperature=<Unit('kelvin')>, force=None, momentum=None, angle=<Unit('radian')>, charge=<Unit('elementary_charge')>)[source]¶ Bases:
object
Class for standardizing units - specifies preferred units for length, mass, energy etc.
In MDT, many methods will automatically convert output using the UnitSystem at
moldesign.units.default
-
convert
(quantity)[source]¶ Convert a quantity into this unit system
Parameters: quantity (MdtQuantity) – quantity to convert
-
force
¶
-
momentum
¶
-