IndexedParameterAttribute

class openff.toolkit.typing.engines.smirnoff.parameters.IndexedParameterAttribute(default=UNDEFINED, unit=None, converter=None, docstring='')[source]

The attribute of a parameter with an unspecified number of terms.

Some parameters can be associated to multiple terms, For example, torsions have parameters such as k1, k2, …, and IndexedParameterAttribute can be used to encapsulate the sequence of terms.

The only substantial difference with ParameterAttribute is that only sequences are supported as values and converters and units are checked on each element of the sequence.

Currently, the descriptor makes the sequence immutable. This is to avoid that an element of the sequence could be set without being properly validated. In the future, the data could be wrapped in a safe list that would safely allow mutability.

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

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

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

See also

ParameterAttribute

A simple parameter attribute.

MappedParameterAttribute

A parameter attribute representing a mapping.

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 openmm import unit
>>> class MyParameter:
...     length = IndexedParameterAttribute(default=None, unit=unit.angstrom)
...
>>> my_par = MyParameter()
>>> my_par.length is None
True

Strings are parsed into Quantity objects.

>>> my_par.length = ['1 * angstrom', 0.5 * unit.nanometer]
>>> my_par.length[0]
Quantity(value=1, unit=angstrom)

Similarly, custom converters work as with ParameterAttribute, but they are used to validate each value in the sequence.

>>> class MyParameter:
...     attr_indexed = IndexedParameterAttribute(converter=float)
...
>>> my_par = MyParameter()
>>> my_par.attr_indexed = [1, '1.0', '1e-2', 4.0]
>>> my_par.attr_indexed
[1.0, 1.0, 0.01, 4.0]
__init__(default=UNDEFINED, unit=None, converter=None, docstring='')

Methods

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

converter(converter)

Create a new ParameterAttribute with an associated converter.

Attributes

name

class UNDEFINED

Custom type used by ParameterAttribute to differentiate between None and undeclared default.

converter(converter)

Create a new ParameterAttribute with an associated converter.

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