parameters
A module for the Parameter and Parameters classes
Parameter defines the name and value of each force field parameter, and whether it is fixed, has constraints or is tied.
Parameters inherits from lists and implements a number of methods for filterting a sequence of Parameter objects.
- class MDMC.MD.parameters.Parameter(value, name, fixed=False, constraints=None, **settings)[source]
A force field parameter which can be fixed or constrained within limits
The value of a parameter cannot be set if
fixed==True
.- Parameters
value (float) – The value of the parameter.
name (str) – The name of the parameter.
fixed (bool) – Whether or not the value can be changed.
constraints (tuple) – The closed range of the
Parameter.value
, (lower, upper).constraints
must have the same units asvalue
.**settings –
unit
(str)The unit. If this is not provided then the unit will be taken from the object passed as
value
.
- property interactions: list
Get or append to the parent
Interaction
objects for thisParameter
- Returns
All parent
Interaction
objects- Return type
- Raises
ValueError – If an added interaction name is not consistent with existing interaction names
ValueError – If an added
Interaction
has a function name not consistent with the function names of an existingInteraction
- set_tie(parameter: MDMC.MD.parameters.Parameter, expr: str) None [source]
This
ties
theParameter.value
to thevalue
of anotherParameter
Examples
To set the
Parameter.value
top1.value * 2
:>>> Parameter.set_tie(p1, "* 2")
- property tie: Optional[float]
Get the
value
of a theParameter
that thisParameter
is tied to- Returns
The
value
of thetied
Parameter
- Return type
- property tied: bool
Get whether this
Parameter
is tied- Returns
True if this
Parameter
is tied to anotherParameter
, else False- Return type
- static validate_value(value: float, constraints: tuple) None [source]
Validates the
Parameter.value
by testing if it is within theconstraints
- Parameters
- Raises
ValueError – If the
value
is not within theconstraints
- property value: float
Get or set the value of the
Parameter
The value will not be changed if it is
fixed
ortied
, or if it is set outside the bounds ofconstraints
- Returns
The value of the
Parameter
, including if theParameter
istied
- Return type
- Warns
warnings.warn – If the
Parameter
isfixed
.warnings.warn – If the
Parameter
istied
.
- class MDMC.MD.parameters.Parameters(init_parameters: Optional[Union[MDMC.MD.parameters.Parameter, list[MDMC.MD.parameters.Parameter]]] = None)[source]
A dict-like object where every element is a
Parameter
indexed by name, which contains a number of helper methods for filtering.Although
Parameters
is a dict, it should be treated like a list when writing to it; i.e. initialise it using a list and use append to add to it. These parameters can then be accessed by their name as a key.In short; Parameters writes like a list and reads like a dict.
- Parameters
init_parameters (
Parameter
or list of ``Parameter``s, optional, default None) – The initialParameter
objects that theParameters
object contains.
- array
An alphabetically-sorted numpy array of the ``Parameter``s stored in this object.
- Type
np.ndarray
- append(parameters: Union[list[MDMC.MD.parameters.Parameter], MDMC.MD.parameters.Parameter]) None [source]
Appends a
Parameter
or list of ``Parameter``s to the dict, with the parameter name as its key.- Parameters
parameters (
Parameter
or list of ``Parameter``s) – The parameter(s) to be added to the dict.
- property as_array: numpy.ndarray
The parameters in the object as a sorted numpy array.
- Returns
An alphabetically-sorted array of parameter values in the object.
- Return type
np.ndarray
- filter(predicate: Callable[[MDMC.MD.parameters.Parameter], bool]) MDMC.MD.parameters.Parameters [source]
Filters using a predicate
- Parameters
predicate (function) – A function that returns a bool which takes a
Parameter
as an argument.- Returns
The
Parameter
objects which meet the condition of the predicate- Return type
- filter_atom_attribute(attribute: str, value: Union[str, float]) MDMC.MD.parameters.Parameters [source]
Filters based on the attribute of
Atom
objects which have eachParameter
applied to them- Parameters
- Returns
The
Parameter
objects which are applied to anAtom
object which has the specifiedvalue
of the specifiedattribute
- Return type
- filter_function(function_name: str) MDMC.MD.parameters.Parameters [source]
Filters based on the name of the
InteractionFunction
of eachParameter
- Parameters
function_name (str) – The name of the
InteractionFunction
ofParameter
objects to return, for example'LennardJones'
or'HarmonicPotential'
.- Returns
The
Parameter
objects which have afunction
with the specifiedfunction_name
- Return type
- filter_interaction(interaction_name: str) MDMC.MD.parameters.Parameters [source]
Filters based on the name of the
Interaction
of eachParameter
- Parameters
interaction_name (str) – The name of the
Interaction
ofParameter
objects to return, for example'Bond'
.- Returns
The
Parameter
objects which have anInteraction
with the specifiedinteraction_name
- Return type
- filter_name(name: str) MDMC.MD.parameters.Parameters [source]
Filters by
name
- Parameters
name (str) – The
name
of theParameter
objects to return.- Returns
The
Parameter
objects withname
- Return type
- filter_structure(structure_name: str) MDMC.MD.parameters.Parameters [source]
Filters based on the name of the
Structure
to which eachParameter
applies- Parameters
structure_name (str) – The name of a
Structure
.- Returns
The
Parameter
objects which are applied to aStructure
which has the specifiedstructure_name
- Return type
- filter_value(comparison: str, value: float) MDMC.MD.parameters.Parameters [source]
Filters by
value
- Parameters
- Returns
The
Parameter
objects which return a True when their values are compared withvalue
using thecomparison
operator- Return type