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 (pyretis.forcefield.forcefield)
Defines the force field class (ForceField) which can be used to represent a generic force field. (pyretis.forcefield.potential)
Defines the generic potential function class (PotentialFunction) which is sub-classed in other potential functions.


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.

pyretis.forcefield.forcefield module

This file contains a class for a generic force field.

This module defines the class used for representing 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.


string – Description of the force field.


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


list – The parameters for the corresponding potential functions.


Return a string representation of the force field.

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

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

Add a potential with parameters to the force field.

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

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

Return type:



Evaluate the force on the particles.

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

Evaluate the potential energy.

Parameters:system (object like System) – The system we evaluate the potential in.
Returns:out – The potential energy.
Return type:float

Evaluate the potential energy and the force.

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

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 – Description of the potential functions in this force field.
Return type:string

Remove a selected potential from the force field.

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

Update the potential parameters of the given potential function.

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

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

Return type:


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.


string – Short description of the potential.


int – Represents the spatial dimensionality of the potential.


dict – Contains the parameters. This dict defines on initiation what parameters the potential will handle and store.


Return the string description of the potential.


Check on the consistency of the parameters.

This can be implemented for the different potential functions.

Returns:out – True if the check(s) pass.
Return type:boolean

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