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 as value.

  • **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 this Parameter

Returns

All parent Interaction objects

Return type

list

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 existing Interaction

set_tie(parameter: MDMC.MD.parameters.Parameter, expr: str) None[source]

This ties the Parameter.value to the value of another Parameter

Parameters
  • parameter (Parameter) – The Parameter to tie to

  • expr (str) – A mathematical expression

Examples

To set the Parameter.value to p1.value * 2:

>>> Parameter.set_tie(p1, "* 2")
property tie: Optional[float]

Get the value of a the Parameter that this Parameter is tied to

Returns

The value of the tied Parameter

Return type

float

property tied: bool

Get whether this Parameter is tied

Returns

True if this Parameter is tied to another Parameter, else False

Return type

bool

static validate_value(value: float, constraints: tuple) None[source]

Validates the Parameter.value by testing if it is within the constraints

Parameters
  • values (float) – The value of the Parameter

  • constraints (tuple) – A 2-tuple of the lower and upper constraints respectively.

Raises

ValueError – If the value is not within the constraints

property value: float

Get or set the value of the Parameter

The value will not be changed if it is fixed or tied, or if it is set outside the bounds of constraints

Returns

The value of the Parameter, including if the Parameter is tied

Return type

float

Warns
  • warnings.warn – If the Parameter is fixed.

  • warnings.warn – If the Parameter is tied.

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 initial Parameter objects that the Parameters 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

Parameters

filter_atom_attribute(attribute: str, value: Union[str, float]) MDMC.MD.parameters.Parameters[source]

Filters based on the attribute of Atom objects which have each Parameter applied to them

Parameters
  • attribute (str) – An attribute of an Atom. Attributes to match to must be either float or str.

  • value (str, float) – The value of the Atom attribute.

Returns

The Parameter objects which are applied to an Atom object which has the specified value of the specified attribute

Return type

Parameters

filter_function(function_name: str) MDMC.MD.parameters.Parameters[source]

Filters based on the name of the InteractionFunction of each Parameter

Parameters

function_name (str) – The name of the InteractionFunction of Parameter objects to return, for example 'LennardJones' or 'HarmonicPotential'.

Returns

The Parameter objects which have a function with the specified function_name

Return type

Parameters

filter_interaction(interaction_name: str) MDMC.MD.parameters.Parameters[source]

Filters based on the name of the Interaction of each Parameter

Parameters

interaction_name (str) – The name of the Interaction of Parameter objects to return, for example 'Bond'.

Returns

The Parameter objects which have an Interaction with the specified interaction_name

Return type

Parameters

filter_name(name: str) MDMC.MD.parameters.Parameters[source]

Filters by name

Parameters

name (str) – The name of the Parameter objects to return.

Returns

The Parameter objects with name

Return type

Parameters

filter_structure(structure_name: str) MDMC.MD.parameters.Parameters[source]

Filters based on the name of the Structure to which each Parameter applies

Parameters

structure_name (str) – The name of a Structure.

Returns

The Parameter objects which are applied to a Structure which has the specified structure_name

Return type

Parameters

filter_value(comparison: str, value: float) MDMC.MD.parameters.Parameters[source]

Filters by value

Parameters
  • comparison (str) – A str representing a comparison operator, '>', '<', '>=', '<=', '==', '!='.

  • value (float) – A float with which Parameter values are compared, using the comparison operator.

Returns

The Parameter objects which return a True when their values are compared with value using the comparison operator

Return type

Parameters

log_parameters() None[source]

Logs all Parameters by ID