pylj.pairwise

Generally these are functions required by pylj which involve a pair-wise comparison of particles.

pylj.pairwise.calculate_pressure(particles, box_length, temperature, cut_off, constants, forcefield, mass)[source]

Calculates the instantaneous pressure of the simulation cell, found with the following relationship: .. math:

p = \langle \rho k_b T \rangle + \bigg\langle \frac{1}{3V}\sum_{i}
\sum_{j<i} \mathbf{r}_{ij}\mathbf{f}_{ij} \bigg\rangle
Parameters:
  • particles (util.particle_dt, array_like) – Information about the particles.

  • box_length (float) – Length of a single dimension of the simulation square, in Angstrom.

  • temperature (float) – Instantaneous temperature of the simulation.

  • cut_off (float) – The distance greater than which the forces between particles is taken as zero.

  • constants (float, array_like (optional)) – The constants associated with the particular forcefield used, e.g. for the function forcefields.lennard_jones, theses are [A, B]

  • forcefield (function (optional)) – The particular forcefield to be used to find the energy and forces.

  • mass (float (optional)) – The mass of the particle being simulated (units of atomic mass units).

Returns:

Instantaneous pressure of the simulation.

Return type:

float

pylj.pairwise.compute_force(particles, box_length, cut_off, constants, forcefield, mass)[source]

Calculates the forces and therefore the accelerations on each of the particles in the simulation. :param particles: Information about the particles. :type particles: util.particle_dt, array_like :param box_length: Length of a single dimension of the simulation square, in Angstrom. :type box_length: float :param cut_off: The distance greater than which the forces between particles is taken

as zero.

Parameters:
  • constants (float, array_like (optional)) – The constants associated with the particular forcefield used, e.g. for the function forcefields.lennard_jones, theses are [A, B]

  • forcefield (function (optional)) – The particular forcefield to be used to find the energy and forces.

  • mass (float (optional)) – The mass of the particle being simulated (units of atomic mass units).

Returns:

  • util.particle_dt, array_like – Information about particles, with updated accelerations and forces.

  • float, array_like – Current distances between pairs of particles in the simulation.

  • float, array_like – Current forces between pairs of particles in the simulation.

  • float, array_like – Current energies between pairs of particles in the simulation.

pylj.pairwise.create_dist_identifiers(type_identifier)[source]

Creates correct distance identifier matrix for particular type of particle :param type identifiers: the identifier array listing 1 for particles of that type

or 0 for particles of a different type

Returns:

distances – the distance identifier for interactions between each particle of that type, or 0 for interactions involving particles of a different type

Return type:

float, array_like

pylj.pairwise.dist(xposition, yposition, box_length, types)[source]

Returns the distance array for the set of particles. :param xpos: Array of length N, where N is the number of particles, providing the

x-dimension positions of the particles.

Parameters:
  • ypos (float, array_like (N)) – Array of length N, where N is the number of particles, providing the y-dimension positions of the particles.

  • box_length (float) – The box length of the simulation cell.

  • types (str, array_like (N)) – Array of length N, where N is the number of particles, providing the type of each particle.

Returns:

  • drr (float, array_like ((N - 1) * N / 2))) – The pairs of distances between the particles.

  • dxr (float, array_like ((N - 1) * N / 2))) – The pairs of distances between the particles, in only the x-dimension.

  • dyr (float, array_like ((N - 1) * N / 2))) – The pairs of distances between the particles, in only the y-dimension.

  • pair_types (str, array_like ((N - 1) * N / 2))) – The types of the two particles in each interaction, saved as ‘type1,type2’ for each

pylj.pairwise.heat_bath(particles, temperature_sample, bath_temp)[source]

Rescales the velocities of the particles in the system to control the temperature of the simulation. Thereby allowing for an NVT ensemble. The velocities are rescaled according the following relationship, .. math:

v_{\text{new}} = v_{\text{old}} \times
\sqrt{\frac{T_{\text{desired}}}{\bar{T}}}
Parameters:
  • particles (util.particle_dt, array_like) – Information about the particles.

  • temperature_sample (float, array_like) – The temperature at each timestep in the simulation.

  • bath_temp (float) – The desired temperature of the simulation.

Returns:

Information about the particles with new, rescaled velocities.

Return type:

util.particle_dt, array_like

pylj.pairwise.lennard_jones_energy(A, B, dr)[source]

pairwise.lennard_jones_energy has been deprecated, please use forcefields.lennard_jones instead

Calculate the energy of a pair of particles at a given distance.

Parameters:
  • A (float) – The value of the A parameter for the Lennard-Jones potential.

  • B (float) – The value of the B parameter for the Lennard-Jones potential.

  • dr (float) – The distance between the two particles.

Returns:

The potential energy between the two particles.

Return type:

float

pylj.pairwise.lennard_jones_force(A, B, dr)[source]

pairwise.lennard_jones_energy has been deprecated, please use forcefields.lennard_jones with force=True instead

Calculate the force between a pair of particles at a given distance.

Parameters:
  • A (float) – The value of the A parameter for the Lennard-Jones potential.

  • B (float) – The value of the B parameter for the Lennard-Jones potential.

  • dr (float) – The distance between the two particles.

Returns:

The force between the two particles.

Return type:

float

pylj.pairwise.pbc_correction(position, cell)[source]

Correct for the periodic boundary condition. :param position: Particle position. :type position: float :param cell: Cell vector. :type cell: float

Returns:

Corrected particle position.

Return type:

float

pylj.pairwise.second_law(f, m, d1, d2)[source]

Newton’s second law of motion to get the acceleration of the particle in a given dimension. :param f: The force on the pair of particles. :type f: float :param m: Mass of the particle. :type m: float :param d1: Distance between the particles in a single dimension. :type d1: float :param d2: Distance between the particles across all dimensions. :type d2: float

Returns:

Acceleration of the particle in a given dimension.

Return type:

float

pylj.pairwise.separation(dx, dy)[source]

Calculate the distance in 2D space. :param dx: Vector in the x dimension :type dx: float :param dy: Vector in the y dimension :type dy: float :param Returns: :param float: Magnitude of the 2D vector.

pylj.pairwise.update_accelerations(particles, f, m, dx, dy, dr)[source]

Update the acceleration arrays of particles. :param particles: Information about the particles. :type particles: util.particle_dt, array_like :param f: The force on the pair of particles. :type f: float :param m: Mass of the particles. :type m: float :param dx: Distance between the particles in the x dimension. :type dx: float :param dy: Distance between the particles in the y dimension. :type dy: float :param dr: Distance between the particles. :type dr: float

Returns:

Information about the particles with updated accelerations.

Return type:

util.particle_dt, array_like