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 LennardJones interactions.
 pairpotential.py (
pairpotential
)  This module defines some helper functions for pair potentials.
 wca.py (
wca
)  Potential functions for WCAtype interactions.
Important classes defined in this package¶
 PairLennardJonesCut (
PairLennardJonesCut
)  A class defining a LennardJones potential.
 PairLennardJonesCutnp (
PairLennardJonesCutnp
)  A class defining a LennardJones potential using numpy for the evaluation.
 DoubleWellWCA (
DoubleWellWCA
)  This class defines a double well WCA potential.
List of submodules¶
pyretis.forcefield.potentials.pairpotentials.lennardjones module¶
Module defining LennardJones pair potentials.
This module defines the LennardJones potential for PyRETIS.
Important classes defined here¶
 PairLennardJonesCut (
PairLennardJonesCut
)  A class representing a LennardJones 612 potential implemented in pure python.
 PairLennardJonesCutnp (
PairLennardJonesCutnp
)  A class representing a LennardJones 612 potential implemented using numpy.

class
pyretis.forcefield.potentials.pairpotentials.lennardjones.
PairLennardJonesCut
(dim=3, shift=True, mixing='geometric', desc='LennardJones pair potential')[source]¶ Bases:
PotentialFunction
LennardJones 612 potential in pure Python.
This class implements as simple LennardJones 612 potential which employs a simple cutoff and can be shifted. The potential energy () is defined in the usual way for an interacting pair of particles a distance apart,
where and and are the potential parameters. The parameters are stored as attributes of the potential, 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

_lj
¶ LennardJones parameters used for calculation of the force. Keys are the pairs (particle types) that may interact.
[1] Calculated as:48.0 * epsilon * sigma**12
[2] Calculated as:24.0 * epsilon * sigma**6
[3] Calculated as:4.0 * epsilon * sigma**12
[4] Calculated as:4.0 * epsilon * sigma**6
Type: dict of dict

_offset
¶ Potential values for shifting the potential if requested. This is the potential evaluated at the cutoff.
Type: dict

_rcut2
¶ The squared cutoff for each interaction type. Keys are the pairs (particle types) that may interact.
Type: dict

__init__
(dim=3, shift=True, mixing='geometric', desc='LennardJones pair potential')[source]¶ Initialise the LennardJones 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 LennardJones 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 LennardJones 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 LennardJones 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.


class
pyretis.forcefield.potentials.pairpotentials.lennardjones.
PairLennardJonesCutnp
(dim=3, shift=True, mixing='geometric', desc='LennardJones pair potential (numpy)')[source]¶ Bases:
PairLennardJonesCut
LennardJones 612 potential with numpy.
A LennardJones 612 potential with a simple cutoff 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='LennardJones pair potential (numpy)')[source]¶ Initialise the LennardJones 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 LennardJones 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 LennardJones 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 LennardJones 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, sigma, rcut, mixing='geometric')[source]¶ Define the socalled mixing rules.
These mixing rules are used for some force fields when generating cross interactions. The known mixing rules are:
Geometric:
Arithmetic:
Sixthpower
Parameters:  epsilon (list of float) – LennardJones epsilon parameter for a particle of type i and ‘j’.
 sigma (list of float) – LennardJones sigma parameter for a particle of type i and ‘j’.
 rcut (list of float) – LennardJones cutoff value for a particle of type i and ‘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:
PotentialFunction
A double well potential.
This class defines a double well WCA potential. The potential energy () for a pair of particles separated by a distance is given by,
where gives the ‘height’ of the potential, the minimum and 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 atrzero+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 atrzero + 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
.
 out[0] (float) – Minimum number one, located at:

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.
