MappedParameterAttribute

class openff.toolkit.typing.engines.smirnoff.parameters.MappedParameterAttribute(default: Any = UNDEFINED, unit: Unit | None = None, converter: Callable | None = None, docstring: str = '')[source]

The attribute of a parameter in which each term is a mapping.

The substantial difference with IndexedParameterAttribute is that, unlike indexing, the mapping can be based on artbitrary references, like indices but can starting at non-zero values and include non-adjacent keys.

Parameters:
  • default (object, optional) – When specified, the descriptor makes this attribute optional by attaching a default value to it.

  • unit (Quantity, optional) – When specified, only sequences of mappings where values are quantities with compatible units are allowed to be set.

  • converter (callable, optional) – An optional function that can be used to validate and cast each component of each element of the sequence before setting the attribute.

See also

IndexedParameterAttribute

A parameter attribute representing a sequence.

IndexedMappedParameterAttribute

A parameter attribute representing a sequence, each term of which is a mapping.

Examples

Create an optional indexed attribute with unit of angstrom.

>>> from openff.toolkit import unit
>>> class MyParameter:
...     length = MappedParameterAttribute(default=None, unit=unit.angstrom)
...
>>> my_par = MyParameter()
>>> my_par.length is None
True

Like other ParameterAttribute objects, strings are parsed into Quantity objects.

>>> my_par.length = {1:'1.5 * angstrom', 2: '1.4 * angstrom'}
>>> my_par.length[1]
<Quantity(1.5, 'angstrom')>

Unlike other ParameterAttribute objects, the reference points can do not need ot be zero-indexed, non-adjancent, such as interpolating defining a bond parameter for interpolation by defining references values and bond orders 2 and 3:

>>> my_par.length = {2:'1.42 * angstrom', 3: '1.35 * angstrom'}
>>> my_par.length[2]
<Quantity(1.42, 'angstrom')>
__init__(default: Any = UNDEFINED, unit: Unit | None = None, converter: Callable | None = None, docstring: str = '')

Methods

__init__([default, unit, converter, docstring])

converter(converter)

Create a new ParameterAttribute with an associated converter.

Attributes

name

UNDEFINED

alias of _UNDEFINED

converter(converter)

Create a new ParameterAttribute with an associated converter.

This is meant to be used as a decorator (see main examples).