IndexedMappedParameterAttribute
- class openff.toolkit.typing.engines.smirnoff.parameters.IndexedMappedParameterAttribute(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, where each term is a mapping.
Some parameters can be associated to multiple terms, where those terms have multiple components. For example, torsions with fractional bond orders have parameters such as k1_bondorder1, k1_bondorder2, k2_bondorder1, k2_bondorder2, …, and
IndexedMappedParameterAttribute
can be used to encapsulate the sequence of terms as mappings (typically,dict
s) of their components.The only substantial difference with
IndexedParameterAttribute
is that only sequences of mappings are supported as values and converters and units are checked on each component of each element in 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 mappings where values are quantities with compatible units are allowed to be set.
converter – 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.
MappedParameterAttribute
A parameter attribute representing a mapping.
Examples
Create an optional indexed attribute with unit of angstrom.
>>> from openff.toolkit import unit >>> class MyParameter: ... length = IndexedMappedParameterAttribute(default=None, unit=unit.angstrom) ... >>> my_par = MyParameter() >>> my_par.length is None True
Strings are parsed into Quantity objects.
>>> my_par.length = [{1:'1 * angstrom'}, {1: 0.5 * unit.nanometer}] >>> my_par.length[0] {1: <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 = IndexedMappedParameterAttribute(converter=float) ... >>> my_par = MyParameter() >>> my_par.attr_indexed = [{1: 1}, {2: '1.0', 3: '1e-2'}, {4: 4.0}] >>> my_par.attr_indexed [{1: 1.0}, {2: 1.0, 3: 0.01}, {4: 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