pyretis.forcefield package

Definition of force field classes and potential functions.

In PyRETIS a force field is just a collection of potential functions with some parameters. This module defines the force field and the potential functions that can be used to build up force fields.

Package structure

Modules

forcefield.py (pyretis.forcefield.forcefield)
Defines the force field class (ForceField) which can be used to represent a generic force field.
potential.py (pyretis.forcefield.potential)
Defines the generic potential function class (PotentialFunction) which is sub-classed in other potential functions.
factory.py (pyretis.forcefield.factory)
Defines a method for creating potentials from input settings.

Sub-packages

potentials (pyretis.forcefield.potentials)
Definition of potential functions for force fields.

Important classes defined in this package

ForceField (ForceField)
A class representing a general force field.
PotentialFunction (PotentialFunction)
A class representing a general potential function.

Subpackages

pyretis.forcefield.forcefield module

This file contains a class for a generic force field.

This module defines the class used for representing a force field. The forcefield class is built up of potential functions.

Important classes defined here

ForceField (ForceField)
A class representing a generic Force Field.
class pyretis.forcefield.forcefield.ForceField(desc, potential=None, params=None)[source]

Bases: object

Represents a generic force field.

This class described a generic Force Field. A force field is assumed to consist of a number of potential functions with parameters.

desc

Description of the force field.

Type:string
potential

The potential functions that the force field is built up from.

Type:list
params

The parameters for the corresponding potential functions.

Type:list
__init__(desc, potential=None, params=None)[source]

Initialise the force field object.

Parameters:
  • desc (string) – Description of the force field.
  • potential (list, optional) – Potential functions that the force field is built up from.
  • params (list, optional) – Parameters for the potential(s). If too few parameters are given, we will just assume a None.
__str__()[source]

Return a string representation of the force field.

The string representation is built using the string descriptions of the potential functions.

Returns:out (string) – Description of the force field and the potential functions included in the force field.
add_potential(potential, parameters=None)[source]

Add a potential with parameters to the force field.

Parameters:
  • potential (object like PotentialFunction) – Potential function to add.
  • parameters (dict, optional) – Parameters for the potential.
Returns:

out (boolean) – Returns True and updates self.potential and self.params if the potential was added. Returns False otherwise.

evaluate_force(system)[source]

Evaluate the force on the particles.

Parameters:system (object like System) – The system we evaluate the forces in.
Returns:
  • out[0] (numpy.array) – The forces on the particles.
  • out[1] (numpy.array) – The virial.
evaluate_potential(system)[source]

Evaluate the potential energy.

Parameters:system (object like System) – The system we evaluate the potential in.
Returns:out (float) – The potential energy.
evaluate_potential_and_force(system)[source]

Evaluate the potential energy and the force.

Parameters:system (object like System) – The system we evaluate the potential energy and force in.
Returns:
  • out[0] (float) – The potential energy.
  • out[1] (numpy.array) – The calculated forces.
  • out[2] (numpy.array) – The calculated virial.
print_potentials()[source]

Print information on potentials in the force field.

This is intended as a lighter alternative to self.__str__ which can be verbose. This function will not actually do the printing, but it returns a string which can be printed.

Returns:out (string) – Description of the potential functions in this force field.
remove_potential(potential)[source]

Remove a selected potential from the force field.

Parameters:potential (object like PotentialFunction) – The potential function to remove.
Returns:out (None or tuple) – Returns None if not potential was removed, otherwise it will return the removed potential and its parameters.
update_potential_parameters(potential, params)[source]

Update the potential parameters of the given potential function.

Parameters:
  • potential (object like PotentialFunction) – Potential to update. Should be in self.potential.
  • params (dict) – The new parameters to set.
Returns:

out (None) – Returns None but will update parameters of the selected potential and modify the corresponding self.params.

pyretis.forcefield.potential module

Define the class for a generic potential function.

This module defines the generic class for potential functions. This class is sub-classed in all potential functions.

Important classes defined here

PotentialFunction (PotentialFunction)
A class for representing generic potential functions.
class pyretis.forcefield.potential.PotentialFunction(dim=1, desc='')[source]

Bases: object

Base class for a generic potential function.

Generic class for potential functions.

desc

Short description of the potential.

Type:string
dim

Represents the spatial dimensionality of the potential.

Type:int
params

The parameters for the potential. This dict defines, on initiation, the parameters the potential will handle and store.

Type:dict
__init__(dim=1, desc='')[source]

Initialise the potential.

Parameters:
  • dim (int, optional) – Represents the dimensionality.
  • desc (string, optional) – Description of the potential function. Used to print out information about the potential.
__str__()[source]

Return the string description of the potential.

check_parameters()[source]

Check the consistency of the parameters.

Returns:out (boolean) – True if the check(s) pass.
set_parameters(parameters)[source]

Update all parameters. Input is assumed to be a dict.

pyretis.forcefield.factory module

Define a factory for potentials.

pyretis.forcefield.factory.potential_factory(settings)[source]

Create a potential according to the given settings.

This function is included as a convenient way of setting up and selecting a potential function.

Parameters:settings (dict) – This defines how we set up and select the potential.
Returns:out[0] (object like PotentialFunction) – This object represents the potential.