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.

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.

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.

desc

string – Description of the force field.

potential

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

params

list – The parameters for the corresponding potential functions.

__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 – 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.

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

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

Return type:

boolean

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 – The potential energy.
Return type:float
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 – Description of the potential functions in this force field.
Return type:string
remove_potential(potential)[source]

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.

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

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

Return type:

None

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

string – Short description of the potential.

dim

int – Represents the spatial dimensionality of the potential.

params

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

__str__()[source]

Return the string description of the potential.

check_parameters()[source]

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
set_parameters(parameters)[source]

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