pyretis.forcefield.potentials.pairpotentials package

Package defining classes for pair potentials.

This package defines different pair potentials for use with an internal calculation in PyRETIS.

Package structure

Modules

lennardjones.py (lennardjones)
Potential functions for Lennard-Jones interactions.
pairpotential.py (pairpotential)
This module defines some helper functions for pair potentials.
wca.py (wca)
Potential functions for WCA-type interactions.

Important classes defined in this package

PairLennardJonesCut (PairLennardJonesCut)
A class defining a Lennard-Jones potential.
PairLennardJonesCutnp (PairLennardJonesCutnp)
A class defining a Lennard-Jones potential using numpy for the evaluation.
DoubleWellWCA (DoubleWellWCA)
This class defines a double well WCA potential.

pyretis.forcefield.potentials.pairpotentials.lennardjones module

Module defining Lennard-Jones pair potentials.

This module defines the Lennard-Jones potential for PyRETIS.

Important classes defined here

PairLennardJonesCut (PairLennardJonesCut)
A class representing a Lennard-Jones 6-12 potential implemented in pure python.
PairLennardJonesCutnp (PairLennardJonesCutnp)
A class representing a Lennard-Jones 6-12 potential implemented using numpy.
class pyretis.forcefield.potentials.pairpotentials.lennardjones.PairLennardJonesCut(dim=3, shift=True, mixing='geometric', desc='Lennard-Jones pair potential')[source]

Bases: pyretis.forcefield.potential.PotentialFunction

Lennard-Jones 6-12 potential in pure Python.

This class implements as simple Lennard-Jones 6-12 potential which employs a simple cut-off and can be shifted. The potential energy (V_\text{pot}) is defined in the usual way for an interacting pair of particles a distance r apart,

V_\text{pot} = 4 \varepsilon \left( x^{12} - x^{6} \right),

where x = \sigma/r and \varepsilon and \sigma are the potential parameters. The parameters are stored as attributes of the potential and we store one set for each kind of pair interaction. Parameters can be generated with a specific mixing rule by the force field.

This implementation is in pure python (yes we are double looping!) and it is slow. It should not be used for production, please consider the numpy aware PairLennardJonesCutnp instead.

params

The parameters for the potential. This dict is assumed to contain parameters for pairs, i.e. for interactions.

Type:dict
_lj1

Lennard-Jones parameters used for calculation of the force. Keys are the pairs (particle types) that may interact. Calculated as: 48.0 * epsilon * sigma**12

Type:dict
_lj2

Lennard-Jones parameters used for calculation of the force. Keys are the pairs (particle types) that may interact. Calculated as: 24.0 * epsilon * sigma**6

Type:dict
_lj3

Lennard-Jones parameters used for calculation of the potential. Keys are the pairs (particle types) that may interact. Calculated as: 4.0 * epsilon * sigma**12

Type:dict
_lj4

Lennard-Jones parameters used for calculation of the potential. Keys are the pairs (particle types) that may interact. Calculated as: 4.0 * epsilon * sigma**6

Type:dict
_offset

Potential values for shifting the potential if requested. This is the potential evaluated at the cut-off.

Type:dict
_rcut2

The squared cut-off for each interaction type. Keys are the pairs (particle types) that may interact.

Type:dict
__init__(dim=3, shift=True, mixing='geometric', desc='Lennard-Jones pair potential')[source]

Initialise the Lennard-Jones potential.

Parameters:
  • dim (int, optional) – The dimensionality to use.
  • shift (boolean, optional) – Determines if the potential should be shifted or not.
  • mixing (string, optional) – Determines how we should mix potential parameters.
  • desc (string, optional) – Description of the potential.
__str__()[source]

Generate a string with the potential parameters.

It will generate a string with both pair and atom parameters.

Returns:out (string) – Table with the parameters of all interactions.
force(system)[source]

Calculate the force for the Lennard-Jones interaction.

We also calculate the virial here, since the force is evaluated.

Parameters:system (object like System) – The system for which we calculate the force.
Returns:
  • out[0] (numpy.array) – The force as a numpy.array.
  • out[1] (numpy.array) – The virial as a numpy.array.
potential(system)[source]

Calculate the potential energy for the Lennard-Jones interaction.

Parameters:system (object like System) – The system for which we calculate the potential.
Returns:The potential energy as a float.
potential_and_force(system)[source]

Calculate potential and force for the Lennard-Jones interaction.

Since the force is evaluated, the virial is also calculated.

Parameters:system (object like System) – The system for which we calculate the potential and force.

Note

Currently, the virial is only calculated for all the particles. It is not calculated as per atom virial. The virial per atom might be useful to obtain a local pressure or stress, however, this needs some consideration. Perhaps it’s best to fully implement this as a method of planes or something similar.

Returns:
  • out[0] (float) – The potential energy as a float.
  • out[1] (numpy.array) – The force as a numpy.array of the same shape as the positions in particles.pos.
  • out[2] (numpy.array) – The virial, as a symmetric matrix with dimensions (dim, dim) where dim is given by the box/system dimensions.
set_parameters(parameters)[source]

Update all parameters.

Here, we generate pair interactions, since that is what this potential actually is using.

Parameters:parameters (dict) – The input pair parameters.
class pyretis.forcefield.potentials.pairpotentials.lennardjones.PairLennardJonesCutnp(dim=3, shift=True, mixing='geometric', desc='Lennard-Jones pair potential (numpy)')[source]

Bases: pyretis.forcefield.potentials.pairpotentials.lennardjones.PairLennardJonesCut

Lennard-Jones 6-12 potential with numpy.

A Lennard-Jones 6-12 potential with a simple cut-off which can be shifted. PairLennardJonesCutnp uses numpy for calculations, i.e. most operations are recast as numpy.array operations. Otherwise, it is similar to PairLennardJonesCut.

__init__(dim=3, shift=True, mixing='geometric', desc='Lennard-Jones pair potential (numpy)')[source]

Initialise the Lennard-Jones potential.

Parameters:
  • dim (int, optional) – The dimensionality to use.
  • shift (boolean, optional) – Determines if the potential should be shifted or not.
  • mixing (string, optional) – Describes the mixing rules for the parameters.
  • desc (string, optional) – Description of the potential.
force(system)[source]

Calculate the force for the Lennard-Jones interaction.

We also calculate the virial here, since the force is evaluated.

Parameters:system (object like System) – The system for which we calculate the force.

Note

The way the “dim” is used may be reconsidered. There is already a self.dim parameter for the potential class.

Returns:
  • out[0] (numpy.array) – The force as a numpy.array of the same shape as the positions in particles.pos.
  • out[1] (numpy.array) – The virial, as a symmetric matrix with dimensions (dim, dim) where dim is given by the box.
potential(system)[source]

Calculate the potential energy for the Lennard-Jones interaction.

Parameters:system (object like System) – The system for which we calculate the potential.
Returns:out (float) – The potential energy as a float.
potential_and_force(system)[source]

Calculate the potential & force for the Lennard-Jones interaction.

We also calculate the virial here, since the force is evaluated.

Parameters:system (object like System) – The system for which we calculate the potential and force.

Note

Currently, the virial is only calculated for all the particles. It is not calculated as a per atom virial. The virial per atom might be useful to obtain a local pressure or stress, however, this needs some consideration. Perhaps it’s best to fully implement this as a method of planes or something similar.

Returns:
  • out[0] (float) – The potential energy as a float.
  • out[1] (numpy.array) – The force as a numpy.array of the same shape as the positions in particles.pos.
  • out[2] (numpy.array) – The virial, as a symmetric matrix with dimensions (dim, dim) where dim is given by the box.

pyretis.forcefield.potentials.pairpotentials.pairpotential module

This module defines some helper functions for pair potentials.

Important methods defined here

mixing_parameters (mixing_parameters())
Definition of mixing rules which are used in some force fields for generating cross interactions.
generate_pair_interactions (generate_pair_interactions())
Function to generate pair parameters from atom parameters.
pyretis.forcefield.potentials.pairpotentials.pairpotential._check_pair_parameters(parameters)[source]

Check that the required pair parameters are given.

If the parameters are not given, we will just set them to default values.

Parameters:parameters (dict) – The settings for the potential.

Note

This function will not return anything, but it will update the input parameters with default values.

pyretis.forcefield.potentials.pairpotentials.pairpotential.generate_pair_interactions(parameters, mixing)[source]

Generate pair parameters from atom parameters.

The parameters are given as a dictionary where the keys are either just integers – which defines atom parameters – or tuples which define pair interactions.

Parameters:
  • parameters (dict) – This dict contain the atom parameters.
  • mixing (string) – Determines how we should mix pair interactions.
pyretis.forcefield.potentials.pairpotentials.pairpotential.mixing_parameters(epsilon_i, sigma_i, rcut_i, epsilon_j, sigma_j, rcut_j, mixing='geometric')[source]

Define the so-called mixing rules.

These mixing rules are used for some force fields when generating cross interactions. The known mixing rules are:

  1. Geometric:

    • \epsilon_{ij} = \sqrt{\epsilon_{i} \times \epsilon_{j}}

    • \sigma_{ij} = \sqrt{\sigma_{i} \times \sigma_{j}}

    • r_{\text{c},ij} = \sqrt{r_{\text{c},i} \times r_{\text{c},j}}

  2. Arithmetic:

    • \epsilon_{ij} = \sqrt{\epsilon_{i} \times \epsilon_{j}}

    • \sigma_{ij} = \frac{\sigma_{i} \times \sigma_{j}}{2}

    • r_{\text{c},ij} = \frac{r_{\text{c},i} \times r_{\text{c},j}}{2}

  3. Sixthpower

    • \epsilon_{ij} = 2 \sqrt{\epsilon_{i} \times \epsilon_{j}}
\frac{\sigma_i^3 \times \sigma_j^3}{\sigma_i^6 + \sigma_j^6}

    • \sigma_{ij} = \left( \frac{\sigma_{i}^6 \times
\sigma_{j}^6}{2} \right)^{1/6}

    • r_{\text{c},ij} = \left(\frac{r_{\text{c},i}^6 \times
r_{\text{c},j}^6}{2}\right)^{1/6}

Parameters:
  • epsilon_i (float) – Lennard-Jones epsilon parameter for a particle of type i.
  • sigma_i (float) – Lennard-Jones sigma parameter for a particle of type i.
  • rcut_i (float) – Lennard-Jones cut-off value for a particle of type i.
  • epsilon_j (float) – Lennard-Jones epsilon parameter for a particle of type j.
  • sigma_j (float) – Lennard-Jones sigma parameter for a particle of type j.
  • rcut_j (float) – Lennard-Jones cut-off value for a particle of type j.
  • mixing (string, optional) – Represents what kind of mixing that should be done.
Returns:

  • out[0] (float) – The mixed epsilon_ij parameter.
  • out[1] (float) – The mixed sigma_ij parameter.
  • out[2] (float) – The mixed rcut_ij parameter.

pyretis.forcefield.potentials.pairpotentials.wca module

This file contains a WCA double well potential.

Important classes defined here

DoubleWellWCA (DoubleWellWCA)
This class defines a double well WCA potential.
class pyretis.forcefield.potentials.pairpotentials.wca.DoubleWellWCA(dim=3, desc='A WCA double well potential')[source]

Bases: pyretis.forcefield.potential.PotentialFunction

A double well potential.

This class defines a double well WCA potential. The potential energy (V_\text{pot}) for a pair of particles separated by a distance r is given by,

V_\text{pot} = h (1 - (r - r_0 - w)^2/w^2)^2,

where h gives the ‘height’ of the potential, r_0 the minimum and w the width. These parameters are stored in the attributes height, rzero and width respectively.

params

Contains the parameters. These are:

  • height: A float describing the “height” of the potential.
  • height4: A float equal to 4.0 * height. (This variable is just included for convenience).
  • rzero: A float defining the two minimums. One is located at rzero, the other at rzero+2*width.
  • types: A set defining what kind of particle pairs to consider for this interaction. If types is not set (i.e. equal to None), it will be assumed to apply to ALL particles.
  • width: A float describing the “width” of the potential.
  • width2: A float equal to width*width (for convenience).
Type:dict
__init__(dim=3, desc='A WCA double well potential')[source]

Initialise the Double Well WCA potential.

Parameters:
  • dim (int, optional) – The dimensionality of the potential.
  • desc (string, optional) – Description of the force field.
_activate(itype, jtype)[source]

Determine if we should calculate a interaction or not.

Parameters:
  • itype (string) – Particle type for particle i.
  • jtype (string) – Particle type for particle j.
force(system)[source]

Calculate the force.

We also calculate the virial here, since the force is evaluated.

Parameters:system (object like System) – The system we evaluate the potential in.
Returns:
  • forces (numpy.array) – The force as a numpy.array of the same shape as the positions in particles.pos.
  • virial (numpy.array) – The virial, as a symmetric matrix with dimensions (dim, dim) where dim is given by the box.
min_max()[source]

Return the minima & maximum of the DoubleWellWCA potential.

The minima are located at rzero & rzero + 2*width. The maximum is located at rzero + width.

Returns:
  • out[0] (float) – Minimum number one, located at: rzero.
  • out[1] (float) – Minimum number two, located at: rzero + 2*width.
  • out[2] (float) – Maximum, located at: rzero + width.
potential(system)[source]

Calculate the potential energy.

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

Calculate the force & potential.

We also calculate the virial here, since the force is evaluated.

Parameters:system (object like System) – The system we evaluate the potential in.
Returns:
  • out[0] (float) – The potential energy as a float.
  • out[1] (numpy.array) – The force as a numpy.array of the same shape as the positions in particles.pos.
  • out[2] (numpy.array) – The virial, as a symmetric matrix with dimensions (dim, dim) where dim is given by the box.
set_parameters(parameters)[source]

Add new potential parameters to the potential.

Parameters:parameters (dict) – The new parameters, they are assume to be dicts on the form {'types': set([(0,0)]), 'rzero': 1.0, 'width': 0.25, 'height': 6.0}