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).constraintsmust 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
Interactionobjects for thisParameter- Returns:
All parent
Interactionobjects- Return type:
- Raises:
ValueError – If an added interaction name is not consistent with existing interaction names
ValueError – If an added
Interactionhas a function name not consistent with the function names of an existingInteraction
- set_tie(parameter: Parameter, expr: str) None[source]
This
tiestheParameter.valueto thevalueof anotherParameterExamples
To set the
Parameter.valuetop1.value * 2:>>> Parameter.set_tie(p1, "* 2")
- property tie: float | None
Get the
valueof a theParameterthat thisParameteris tied to- Returns:
The
valueof thetiedParameter- Return type:
- property tied: bool
Get whether this
Parameteris tied- Returns:
True if this
Parameteris tied to anotherParameter, else False- Return type:
- static validate_value(value: float, constraints: tuple) None[source]
Validates the
Parameter.valueby testing if it is within theconstraints- Parameters:
- Raises:
ValueError – If the
valueis not within theconstraints
- property value: float
Get or set the value of the
ParameterThe value will not be changed if it is
fixedortied, or if it is set outside the bounds ofconstraints- Returns:
The value of the
Parameter, including if theParameteristied- Return type:
- Warns:
warnings.warn – If the
Parameterisfixed.warnings.warn – If the
Parameteristied.
- class MDMC.MD.parameters.Parameters(init_parameters: Parameter | list[Parameter] | None = None)[source]
A dict-like object where every element is a
Parameterindexed by name, which contains a number of helper methods for filtering.Although
Parametersis 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 (
Parameteror list of ``Parameter``s, optional, default None) – The initialParameterobjects that theParametersobject contains.
- array
An alphabetically-sorted numpy array of the ``Parameter``s stored in this object.
- Type:
np.ndarray
- append(parameters: list[Parameter] | Parameter) None[source]
Appends a
Parameteror list of ``Parameter``s to the dict, with the parameter name as its key.- Parameters:
parameters (
Parameteror list of ``Parameter``s) – The parameter(s) to be added to the dict.
- property as_array: 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[[Parameter], bool]) Parameters[source]
Filters using a predicate
- Parameters:
predicate (function) – A function that returns a bool which takes a
Parameteras an argument.- Returns:
The
Parameterobjects which meet the condition of the predicate- Return type:
- filter_atom_attribute(attribute: str, value: str | float) Parameters[source]
Filters based on the attribute of
Atomobjects which have eachParameterapplied to them- Parameters:
- Returns:
The
Parameterobjects which are applied to anAtomobject which has the specifiedvalueof the specifiedattribute- Return type:
- filter_function(function_name: str) Parameters[source]
Filters based on the name of the
InteractionFunctionof eachParameter- Parameters:
function_name (str) – The name of the
InteractionFunctionofParameterobjects to return, for example'LennardJones'or'HarmonicPotential'.- Returns:
The
Parameterobjects which have afunctionwith the specifiedfunction_name- Return type:
- filter_interaction(interaction_name: str) Parameters[source]
Filters based on the name of the
Interactionof eachParameter- Parameters:
interaction_name (str) – The name of the
InteractionofParameterobjects to return, for example'Bond'.- Returns:
The
Parameterobjects which have anInteractionwith the specifiedinteraction_name- Return type:
- filter_name(name: str) Parameters[source]
Filters by
name- Parameters:
name (str) – The
nameof theParameterobjects to return.- Returns:
The
Parameterobjects withname- Return type:
- filter_structure(structure_name: str) Parameters[source]
Filters based on the name of the
Structureto which eachParameterapplies- Parameters:
structure_name (str) – The name of a
Structure.- Returns:
The
Parameterobjects which are applied to aStructurewhich has the specifiedstructure_name- Return type:
- filter_value(comparison: str, value: float) Parameters[source]
Filters by
value- Parameters:
- Returns:
The
Parameterobjects which return a True when their values are compared withvalueusing thecomparisonoperator- Return type: