parmed.unit.unit module

Module simtk.unit

Contains classes Unit and ScaledUnit.

This is part of the OpenMM molecular simulation toolkit originating from Simbios, the NIH National Center for Physics-Based Simulation of Biological Structures at Stanford, funded under the NIH Roadmap for Medical Research, grant U54 GM072970. See https://simtk.org.

Portions copyright (c) 2012 Stanford University and the Authors. Authors: Christopher M. Bruns Contributors: Peter Eastman

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

class parmed.unit.unit.ScaledUnit(factor, master, name, symbol)[source]

Bases: object

ScaledUnit is like a BaseUnit, but it is based on another Unit.

ScaledUnit and BaseUnit are both used in the internals of Unit. They should only be used during the construction of Units.

Methods

get_dimension_tuple()

Returns a sorted tuple of (BaseDimension, exponent) pairs, that can be used as a dictionary key.

iter_base_dimensions()

Returns a sorted tuple of (BaseDimension, exponent) pairs, describing the dimension of this unit.

conversion_factor_to

get_conversion_factor_to_base_units

iter_base_units

conversion_factor_to(other)[source]
get_conversion_factor_to_base_units()[source]
get_dimension_tuple()[source]

Returns a sorted tuple of (BaseDimension, exponent) pairs, that can be used as a dictionary key.

iter_base_dimensions()[source]

Returns a sorted tuple of (BaseDimension, exponent) pairs, describing the dimension of this unit.

iter_base_units()[source]
class parmed.unit.unit.Unit(base_or_scaled_units)[source]

Bases: object

Physical unit such as meter or ampere.

Methods

conversion_factor_to(other)

Returns conversion factor for computing all of the common dimensions between self and other from self base units to other base units.

create_unit(scale, name, symbol)

Convenience method for creating a new simple unit from another simple unit.

get_conversion_factor_to_base_units()

There may be ScaleUnit components to this Unit.

get_name()

Returns a unit name (string) for this Unit, composed of its various BaseUnit symbols.

get_symbol()

Returns a unit symbol (string) for this Unit, composed of its various BaseUnit symbols.

in_unit_system(system)

Returns a new Unit with the same dimensions as this one, expressed in a particular unit system.

is_compatible(other)

Returns True if two Units share the same dimension.

is_dimensionless()

Returns True if this Unit has no dimensions.

iter_all_base_units()

Yields (BaseUnit, exponent) tuples comprising this unit, including those BaseUnits found within ScaledUnits.

iter_base_dimensions()

Yields (BaseDimension, exponent) tuples comprising this unit.

iter_top_base_units()

Yields (BaseUnit, exponent) tuples in this Unit, excluding those within BaseUnits.

sqrt()

Returns square root of a unit.

iter_base_or_scaled_units

iter_scaled_units

conversion_factor_to(other)[source]

Returns conversion factor for computing all of the common dimensions between self and other from self base units to other base units.

The two units need not share all of the same dimensions. In case they do not, the conversion factor applies only to the BaseUnits of self that correspond to different BaseUnits in other.

This method requires strict compatibility between the two units.

create_unit(scale, name, symbol)[source]

Convenience method for creating a new simple unit from another simple unit. Both units must consist of a single BaseUnit.

get_conversion_factor_to_base_units()[source]

There may be ScaleUnit components to this Unit. Returns conversion factor to the set of BaseUnits returned by iter_all_base_units().

Units comprised of only BaseUnits return 1.0

get_name()[source]

Returns a unit name (string) for this Unit, composed of its various BaseUnit symbols. e.g. ‘kilogram meter**2 secon**-1’.

get_symbol()[source]

Returns a unit symbol (string) for this Unit, composed of its various BaseUnit symbols. e.g. ‘kg m**2 s**-1’

in_unit_system(system)[source]

Returns a new Unit with the same dimensions as this one, expressed in a particular unit system.

Strips off any ScaledUnits in the Unit, leaving only BaseUnits.

Parameters
  • system: a dictionary of (BaseDimension, BaseUnit) pairs

is_compatible(other)[source]

Returns True if two Units share the same dimension. Returns False otherwise.

is_dimensionless()[source]

Returns True if this Unit has no dimensions. Returns False otherwise.

iter_all_base_units()[source]

Yields (BaseUnit, exponent) tuples comprising this unit, including those BaseUnits found within ScaledUnits.

There might be multiple BaseUnits with the same dimension.

iter_base_dimensions()[source]

Yields (BaseDimension, exponent) tuples comprising this unit.

iter_base_or_scaled_units()[source]
iter_scaled_units()[source]
iter_top_base_units()[source]

Yields (BaseUnit, exponent) tuples in this Unit, excluding those within BaseUnits.

sqrt()[source]

Returns square root of a unit.

Raises ArithmeticError if component exponents are not even. This behavior can be changed if you present a reasonable real life case to me.

class parmed.unit.unit.UnitSystem(units)[source]

Bases: object

A complete system of units defining the base unit in each dimension

Parameters
units: ``list``

List of base units from which to construct the unit system

Methods

express_unit

express_unit(old_unit)[source]
parmed.unit.unit.is_unit(x)[source]

Returns True if x is a Unit, False otherwise.

Examples

>>> is_unit(16)
False