XDM forces, stress, and phonon frequencies in periodic solids

These notes describe the implementation of the XDM dispersion contribution to atomic forces, stress tensor, and the dynamical matrix (required to calculate phonon frequencies) in Quantum ESPRESSO. They also describe the implementation of the same quantities for any energy term that is written as an absolutely convergent atomic pairwise summation.

Pairwise Summation in Periodic Solids

Sketch of a periodic solid
Sketch of a periodic solid or a large, periodic molecule.

Let us consider a finite system (a molecule) that is composed of repeated cells, such as the one shown in the right. We assume that the energy in this system is given by a sum over atomic pairs of a function that depends only on the nature of the atoms and the distance between them, with . The also has the property that it decays with distance quickly enough that an infinite sum over atomic pairs in three dimensions is absolutely convergent. For instance, if represents a dispersion interaction, the leading term in the asymptotic limit would be , which meets this convergence requirement.

The pairwise energy is calculated as:

where the sum runs over all unique pairs of atoms in the whole system. Since , we can write this more conveniently as:

This time we use a double sum over all atoms in the system, adding the equal ij and ji contributions and then dividing by two.

We now focus on a single atom and consider shells of other atoms around it. For a shell at a distance , the number of atoms inside the shell is roughly proportional to its surface () and, since decays with distance faster than , then the contribution from atomic shells at increasing distance from the central atom decays as well. Therefore, a given atom only perceives the interactions from a sphere of atoms up to a certain distance. This sphere of atoms is called the environment of the atom in the rest of this document.

If is large enough, then most of the atoms in the system see a full environment around them (the bulk atoms). The exception are the atoms on the edges and surface of the system. The energy contribution from the edge and surface atoms decreases relative to the bulk atoms as increases. This is because the number of atoms on the surface is proportional to and the number of atoms in the bulk increases as , where is some length measure of the system size (e.g. its radius). Therefore, for large , we can approximate the average energy per cell as:

The prime means that the sum includes all atoms in the whole system or in the environment except for . In the second sum, we replaced the sum over all atoms in the system with a sum over an environment that is the union of the environments of all atoms in the cell over which index i runs. In the limit of infinite (the thermodynamic limit) this expression becomes exact, and we write the pairwise energy per cell as:

Because the system is periodic, we write this expression equivalently as a double sum over atoms in the unit cell plus a sum over lattice vectors:

where runs over lattice vectors in the environment and the prime in the second equation indicates that the case where and is discarded. The distance with the lattice vector superscript is defined as:

Note that but . We can always choose the environment in a way that if a lattice vector is in the environment then its opposite is also included. With this assumption, we can use that to note that the double sum above contains terms that are twice repeated and re-write the energy as a sum over pairs of atoms in the unit cell:

Distance Derivatives

The calculation of the derivatives of the energy with respect to the atomic positions requires the derivatives of the distance between two atoms. In the general case, the distance is:

The first derivatives are:

where is the Cartesian coordinate (one of x, y, and z). Note that:

For the second derivatives, we have six possibilities resulting from the three combinations of the two indices (ii, jj, ij) and the two cases when and . We start with the ii case:

Combining the two expressions:

and the others can be obtained by using the index switch property of the first derivative:

In the most general case:

The case where is an atom in the environment (instead of the cell) gives exactly the same derivatives, since it reduces to having in the expressions above.

Atomic Forces

The pairwise energy expression is (the “cell” subscript of the energy has been dropped for simplicity):

The component of the force exerted on atom i is defined as:

Of all the terms in the sum, only those involving atom will give a contribution. Since the sum runs over all pairs, these terms will either be , if , or , if . Hence:

Note that:

The sum over the environment lattice vectors contains all and pairs, which means:

Therefore, we can combine the two partial sums into one and then apply the chain rule:

where is the distance derivative of the function. Unpacking the distance derivative, we arrive at the expression for the atomic force:

Stress and Strain

To calculate the strain tensor, we consider an infinitesimal uniform deformation of the solid given by the strain tensor . The positions of the atoms in the deformed geometry are given by:

The strain tensor is symmetric () because we are not interested in whole-body rotations of the solid. The stress tensor is defined as:

with the unit cell volume.

As in the case of the forces, we first calculate the distance derivatives with respect to the strain, then apply the chain rule. The interatomic distance between atoms i and j separated by lattice vector is given by:

When the strain is applied, the distance becomes:

Because the strain is infinitesimal, we can neglect any term that contains a product of two strains. Therefore, the strain matrix product in the middle of this expression simplifies to:

where we used the fact that . This transformation simplifies the distance expression:

Taking the derivative with respect to an element of the strain tensor:

and solving, we have:

From this, the stress tensor is obtained by straightforward application of the chain rule:

The Dynamical Matrix

Phonon eigenvectors and phonon frequencies are calculated by diagonalizing the dynamical matrix:

where is the nth phonon eigenvector at vector in the first Brillouin zone. The phonon eigenvectors have elements and the dynamical matrix is a Hermitian matrix that is defined as:

where the matrix is:

The matrix, which is the Fourier transform of , is called the interatomic force constant matrix (IFC). It is defined as:

The IFC matrix is calculated as the second derivative of the energy with respect to atomic displacements (equivalently, positions). One of the atoms (i) is in the unit cell, and the other (j) is translated by a lattice vector . Note that, because of translational symmetry:

it does not make much sense to have more than one lattice vector indexing the IFC matrix. Using the definition of atomic force, we have:

The atomic force is:

where in this case we sum over the environment directly instead of using a sum over lattice vectors. We have added an superscript to environment atom j to keep track of which lattice vector it corresponds to.

Let us first consider the case in which atom and atom translated by are different. In this case, only one of the terms in the atomic force sum will contribute to the IFC matrix element , namely, the one whose index corresponds to atom j translated by lattice vector . We define the distance function as:

so the IFC matrix can be written as:

with . If ,

and if ,

Combining the two results, we have:

In the case where and , we have:

Therefore, the same-atom IFC matrix elements can be calculated using the zero-sum rule:

Finally, the massless dynamical matrix is:


Pairwise Energy Functions

The expressions above allow the calculation of forces, stress, and dynamical matrix contributions from any pairwise atomic energy term. For a pairwise interaction given by:

we only need the function, its derivative (), the function, and its derivative (). These are easily obtained from a computer algebra program such as maxima (see at the end for the cantor script). The radial functions for the D2 and XDM dispersion corrections are given now.

Pairwise Energy Functions for the D2 Dispersion Correction

We first define the exponential function:

The pairwise energy:

where and are adjustable parameters, are the (fixed) dispersion coefficients and is the sum of van der Waals radii. The distance derivative of this function is:

The h-function is:

and its derivative is:

Pairwise Energy Functions for the XDM Dispersion Correction

The XDM dispersion coefficients depend on the geometry of the system but they usually change very slowly when atoms move and, in general, it is a good approximation to assume that the dispersion coefficients are constant. The pairwise energy contribution for each pair is:

and its derivative:

The h-function is:

and its derivative:

Testing routines

A simple way to check the consistency of the four functions (, , , ) is to use a small Fortran program that writes a table of values in a simple case (e.g. graphite), then use octave to verify all the values against numerical derivatives of and . An advantage of this method is that, once written and tested, the routines can be transported as a whole into Quantum ESPRESSO. For D2:

subroutine calcgh_d2(d,g,gp,h,hp)
  implicit none
  real*8, intent(in) :: d
  real*8, intent(out) :: g, gp, h, hp

  real*8 :: ed, fij, d6, d7, d2, scal6, c6_ij, r_sum, beta

  ! graphite
  scal6 = 0.75d0
  c6_ij = 60.71d0
  r_sum = 5.488d0
  beta = 20d0

  d2 = d * d
  d6 = d**6
  d7 = d6 * d
  ed = exp(-beta * (d / r_sum - 1.d0))
  fij = 1.d0 / (1.d0 + ed)
  g = c6_ij * scal6 / d6 * fij
  gp = c6_ij * scal6 / d6 / (1.d0 + ed) * (beta * ed / r_sum / (1.d0 + ed) - 6.d0 / d)
  h = gp / d
  hp = c6_ij * scal6 / d7 / (1.d0 + ed) * (48.d0 / d2 - &
     13.d0 * beta * ed / r_sum / d / (1.d0 + ed) - &
     beta**2 * ed / r_sum**2 / (1.d0 + ed)**2 * (1.d0 - ed))

end subroutine calcgh_d2

For XDM:

subroutine calcgh_xdm(d,g,gp,h,hp)
  implicit none
  real*8, intent(in) :: d
  real*8, intent(out) :: g, gp, h, hp

  real*8 :: c6, c8, c10, rvdw
  real*8 :: d2, d4, d6, d8, d10, dpr6, dpr8, dpr10, r2, r6, r8, r10
  real*8 :: d5, d7, d9, dpr6sq, dpr8sq, dpr10sq, d17, d13, d3, dpr6cub
  real*8 :: dpr8cub, dpr10cub

  ! graphite
  c6 = 1.771066d+01 * 2d0 ! to ry
  c8 = 6.829096d+02 * 2d0 ! to ry
  c10 = 2.876529d+04 * 2d0 ! to ry
  rvdw = 7.308851d0

  r2 = rvdw * rvdw
  r6 = r2 * r2 * r2
  r8 = r6 * r2
  r10 = r8 * r2

  d2 = d * d
  d3 = d2 * d
  d4 = d2 * d2
  d5 = d4 * d
  d6 = d4 * d2
  d7 = d6 * d
  d8 = d6 * d2
  d9 = d8 * d
  d10 = d8 * d2
  d13 = d6 * d7
  d17 = d10 * d7

  dpr6 = r6 + d6
  dpr8 = r8 + d8
  dpr10 = r10 + d10
  dpr6sq = dpr6 * dpr6
  dpr8sq = dpr8 * dpr8
  dpr10sq = dpr10 * dpr10
  dpr6cub = dpr6sq * dpr6
  dpr8cub = dpr8sq * dpr8
  dpr10cub = dpr10sq * dpr10

  g = c6 / dpr6 + c8 / dpr8 + c10 / dpr10
  gp = -10d0 * c10 * d9 / dpr10sq - 8d0 * c8 * d7 / dpr8sq - 6d0 * c6 * d5 / dpr6sq
  h = gp / d
  hp = -80d0 * c10 * d7 / dpr10sq + 200d0 * c10 * d17 / dpr10cub - 48d0 * c8 * d5 / dpr8sq &
     + 128d0 * c8 * d13 / dpr8cub - 24 * c6 * d3 / dpr6sq + 72d0 * c6 * d9 / dpr6cub

end subroutine calcgh_xdm

The octave script to verify the consistency of the implemented pairwise energy functions is:

load aa

d = aa(:,2);
g = aa(:,3);
gp = aa(:,4);
h = aa(:,5);
hp = aa(:,6);

gavg = 0.5 * (g(1:end-1)+g(2:end));
gpavg = 0.5 * (gp(1:end-1)+gp(2:end));
numgpavg = diff(g) ./ diff(d);
havg = 0.5 * (h(1:end-1)+h(2:end));
hpavg = 0.5 * (hp(1:end-1)+hp(2:end));
numhpavg = diff(h) ./ diff(d);

printf("gp = dg/dd (rel) : %.4e\n",max(abs(gpavg - numgpavg) ./ abs(gpavg)));
printf("h = gp/d   (abs) : %.4e\n",max(abs(h - gp ./ d)));
printf("hp = dh/dd (rel) : %.4e\n",max(abs(hpavg - numhpavg) ./ abs(hpavg)));

The output of this test for XDM is:

gp = dg/dd (rel) : 1.1023e-04
h = gp/d   (abs) : 1.3031e-17
hp = dh/dd (rel) : 4.5022e-04

indicating that the numerical and analytical derivatives agree with each other to about one in ten thousand. The program and script files are given at the end of this document.

The consistency of the routine can be tested in Quantum ESPRESSO directly by performing the dispersion energy sum from within the phonon calculation. The dispersion energy in ph.x and the one obtained from pw.x must be equal.

Supporting files

Program and script for testing the pairwise energy routines:

Cantor notebook file with the derivatives of the pairwise energy functions:

QE implementation of the XDM dynamical matrix contribution:

QE implementation of the D2 dynamical matrix contribution: