IndexedParameterAttribute
- class openff.toolkit.typing.engines.smirnoff.parameters.IndexedParameterAttribute(default: Any = UNDEFINED, unit: Unit | str | None = None, converter: Callable | None = None, docstring: str = '')[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 – When specified, the descriptor makes this attribute optional by attaching a default value to it.
unit – When specified, only sequences of quantities with compatible units are allowed to be set.
converter – 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 openff.toolkit 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(1, '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: Any = UNDEFINED, unit: Unit | str | 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