Elastic constants

We compute clamped-ion elastic constants of a crystal using the algorithmic differentiation density-functional perturbation theory (AD-DFPT) approach as introduced in [SPH25].

We consider a crystal in its equilibrium configuration, where all atomic forces and stresses vanish. Homogeneous strains $η$ are then applied relative to this relaxed structure. The elastic constants are derived from the stress-strain relationship. In Voigt notation, the stress $\sigma$ and strain $\eta$ tensors are represented as 6-component vectors. The elastic constants $C$ are then given by the Jacobian of the stress with respect to strain, forming a $6 \times 6$ matrix

\[ C = \frac{\partial \sigma}{\partial \eta}.\]

This example computes the clamped-ion elastic tensor, keeping internal atomic positions fixed under strain. The relaxed-ion tensor includes additional corrections from internal relaxations, which can be obtained from first-order atomic displacements in DFPT (see [Wu2005]).

using DFTK
using PseudoPotentialData
using LinearAlgebra
using ForwardDiff
using DifferentiationInterface
using AtomsBuilder
using Unitful
using UnitfulAtomic

Computing PBE elastic constants

We start with the PBE [PBE1996] functional.

pseudopotentials = PseudoFamily("dojo.nc.sr.pbe.v0_4_1.standard.upf")
a0_pbe = 10.33u"bohr"  # Equilibrium lattice constant of silicon with PBE
model0 = model_DFT(bulk(:Si; a=a0_pbe); pseudopotentials, functionals=PBE())

Ecut = recommended_cutoff(model0).Ecut
kgrid = [4, 4, 4]
tol = 1e-6
1.0e-6

The elastic_tensor postprocessing function automatically detects crystal symmetry and chooses the appropriate strain patterns to extract all independent elastic constants:

basis = PlaneWaveBasis(model0; Ecut, kgrid)
scfres = self_consistent_field(basis; tol)
(; C) = elastic_tensor(scfres)

println("C11: ", uconvert(u"GPa", C[1, 1] * u"hartree" / u"bohr"^3))
println("C12: ", uconvert(u"GPa", C[1, 2] * u"hartree" / u"bohr"^3))
println("C44: ", uconvert(u"GPa", C[4, 4] * u"hartree" / u"bohr"^3))
n     Energy            log10(ΔE)   log10(Δρ)   Diag   Δtime 
---   ---------------   ---------   ---------   ----   ------
  1   -8.453374233754                   -0.94    5.5    223ms
  2   -8.455586866358       -2.66       -1.78    1.0    103ms
  3   -8.455776489905       -3.72       -2.86    1.9    143ms
  4   -8.455790089744       -4.87       -3.41    3.1    157ms
  5   -8.455790181982       -7.04       -4.03    1.6    122ms
  6   -8.455790187338       -8.27       -5.33    2.0    130ms
  7   -8.455790187713       -9.43       -6.22    3.5    169ms
n     Energy            log10(ΔE)   log10(Δρ)   Diag   Δtime 
---   ---------------   ---------   ---------   ----   ------
  1   -8.455790187713                   -7.08   20.4    1.29s
Solving response problem
Iter  Restart  Krydim  log10(res)  avg(CG)  Δtime   Comment
----  -------  ------  ----------  -------  ------  ---------------
                                      18.4   7.64s  Non-interacting
   1        0       1        0.11     14.3   16.7s  
   2        0       2       -0.70     13.2   887ms  
   3        0       3       -1.71     11.7   579ms  
   4        0       4       -2.78      9.8   1.14s  
   5        0       5       -4.04      7.4   350ms  
   6        0       6       -5.57      3.7   237ms  
   7        0       7       -7.26      1.2   157ms  
   8        1       1       -7.03     18.3   876ms  Restart
   9        1       2       -7.95      2.6   208ms  
                                      17.3   2.01s  Final orbitals
C11: 156.51823600433463 GPa
C12: 59.574605748089446 GPa
C44: 98.61661623865251 GPa

Here are AD-DFPT results from increasing discretization parameters:

Ecutkgridc11c12c44
18[4, 4, 4]156.5159.5798.61
18[8, 8, 8]153.5356.90100.07
24[8, 8, 8]153.2656.8299.97
24[14, 14, 14]153.0356.71100.09

For comparison, Materials Project for PBE relaxed-ion elastic constants of silicon mp-149: c11 = 153 GPa, c12 = 57 GPa, c44 = 74 GPa. Note the discrepancy in c44, which is due to us not yet including ionic relaxation in this example.

Moving to meta-GGA functionals

To make the problem a little more interesting we will now compute the elastic constants using the Laplacian-dependent r2SCAN-L functional (a deorbitalized version of r2SCAN, see [MT2020]), again using AD-DFPT.

model_r2scanl = model_DFT(bulk(:Si; a=a0_pbe);
                       pseudopotentials, functionals=[:mgga_x_r2scanl, :mgga_c_r2scanl])
basis_r2scanl = PlaneWaveBasis(model_r2scanl; Ecut, kgrid)
scfres_r2scanl = self_consistent_field(basis_r2scanl; tol)
(; C) = elastic_tensor(scfres_r2scanl)
(voigt_stress = [-1.99130426134204e-5, -1.991303783315364e-5, -1.991303783315364e-5, 1.4510554202425465e-12, 0.0, 0.0], C = [0.005299352474828059 0.0020171886733295354 0.0020171886733295354 0.0 0.0 0.0; 0.0020171886733295354 0.005299352474828059 0.0020171886733295354 0.0 0.0 0.0; 0.0020171886733295354 0.0020171886733295354 0.005299352474828059 0.0 0.0 0.0; 0.0 0.0 0.0 0.003329164200287696 0.0 0.0; 0.0 0.0 0.0 0.0 0.003329164200287696 0.0; 0.0 0.0 0.0 0.0 0.0 0.003329164200287696])

The r2SCAN-L elastic constants, which agree well with PBE:

println("C11: ", uconvert(u"GPa", C[1, 1] * u"hartree" / u"bohr"^3))
println("C12: ", uconvert(u"GPa", C[1, 2] * u"hartree" / u"bohr"^3))
println("C44: ", uconvert(u"GPa", C[4, 4] * u"hartree" / u"bohr"^3))
C11: 155.91233234389804 GPa
C12: 59.34773962109505 GPa
C44: 97.94739219332716 GPa

Manual AD-DFPT derivation

For reference, the following shows how elastic_tensor works under the hood for cubic crystals. The sparsity pattern of the matrix $C$ follows from crystal symmetry and is tabulated in standard references (eg. Table 9 in [Nye1985]). This sparsity can be used a priori to reduce the number of strain patterns that need to be probed to extract all independent components of $C$. For example, cubic crystals have only three independent elastic constants $C_{11}$, $C_{12}$ and $C_{44}$, with the pattern

\[C = \begin{pmatrix} C_{11} & C_{12} & C_{12} & 0 & 0 & 0 \\ C_{12} & C_{11} & C_{12} & 0 & 0 & 0 \\ C_{12} & C_{12} & C_{11} & 0 & 0 & 0 \\ 0 & 0 & 0 & C_{44} & 0 & 0 \\ 0 & 0 & 0 & 0 & C_{44} & 0 \\ 0 & 0 & 0 & 0 & 0 & C_{44} \\ \end{pmatrix}.\]

Thus we can just choose a suitable strain pattern $\dot{\eta} = (1, 0, 0, 1, 0, 0)^\top$, such that $C\dot{\eta} = (C_{11}, C_{12}, C_{12}, C_{44}, 0, 0)^\top$. That is, for cubic crystals like diamond silicon we obtain all independent elastic constants from a single Jacobian-vector product on the stress-strain function.

function symmetries_from_strain(model0, voigt_strain)
    lattice = DFTK.voigt_strain_to_full(voigt_strain) * model0.lattice
    model = Model(model0; lattice, symmetries=true)
    model.symmetries
end

strain_pattern = [1., 0., 0., 1., 0., 0.];  # recovers [c11, c12, c12, c44, 0, 0]

For elastic constants beyond the bulk modulus, symmetry-breaking strains are required. That is, the symmetry group of the crystal is reduced. Here we simply precompute the relevant subgroup by applying the automatic symmetry detection (spglib) to the finitely perturbed crystal.

symmetries_strain = symmetries_from_strain(model0, 0.01 * strain_pattern)


function stress_from_strain(model0, voigt_strain; symmetries, Ecut, kgrid, tol)
    lattice = DFTK.voigt_strain_to_full(voigt_strain) * model0.lattice
    model = Model(model0; lattice, symmetries)
    basis = PlaneWaveBasis(model; Ecut, kgrid)
    scfres = self_consistent_field(basis; tol)
    DFTK.full_stress_to_voigt(compute_stresses_cart(scfres))
end

stress_fn(voigt_strain) = stress_from_strain(model0, voigt_strain;
                                             symmetries=symmetries_strain,
                                             Ecut, kgrid, tol)
stress, (dstress,) = value_and_pushforward(stress_fn, AutoForwardDiff(),
                                           zeros(6), (strain_pattern,));
n     Energy            log10(ΔE)   log10(Δρ)   Diag   Δtime 
---   ---------------   ---------   ---------   ----   ------
  1   -8.453455375408                   -0.94    5.4    425ms
  2   -8.455624219232       -2.66       -1.78    1.0    251ms
  3   -8.455776540482       -3.82       -2.89    1.8    925ms
  4   -8.455790072501       -4.87       -3.29    2.9    255ms
  5   -8.455790173359       -7.00       -3.79    1.2    154ms
  6   -8.455790186813       -7.87       -4.98    1.6    181ms
  7   -8.455790187706       -9.05       -5.40    3.1    273ms
  8   -8.455790187713      -11.15       -5.93    1.2    161ms
  9   -8.455790187713      -12.15       -6.89    1.3    163ms
Solving response problem
Iter  Restart  Krydim  log10(res)  avg(CG)  Δtime   Comment
----  -------  ------  ----------  -------  ------  ---------------
                                      18.4   649ms  Non-interacting
   1        0       1        0.11     14.2   607ms  
   2        0       2       -0.70     12.7   536ms  
   3        0       3       -1.71     11.3   491ms  
   4        0       4       -2.78      9.6   428ms  
   5        0       5       -4.04      7.1   352ms  
   6        0       6       -5.57      3.3   225ms  
   7        0       7       -7.40      1.2   158ms  
   8        1       1       -6.85     18.2   1.65s  Restart
   9        1       2       -7.82      2.6   194ms  
                                      17.3   665ms  Final orbitals

We can inspect the stress to verify it is small (close to equilibrium):

stress
6-element StaticArraysCore.SVector{6, Float64} with indices SOneTo(6):
 -2.3121423596563626e-5
 -2.3121471366571004e-5
 -2.3121471366571004e-5
  1.9247641847793155e-10
  0.0
  0.0

The response of the stress to strain_pattern contains the elastic constants in atomic units, with the expected pattern $(c11, c12, c12, c44, 0, 0)$:

dstress
6-element StaticArraysCore.SVector{6, Float64} with indices SOneTo(6):
 0.005319945356903753
 0.002024899789001197
 0.002024899789001197
 0.003351909428897078
 0.0
 0.0

Convert to GPa:

println("C11: ", uconvert(u"GPa", dstress[1] * u"hartree" / u"bohr"^3))
println("C12: ", uconvert(u"GPa", dstress[2] * u"hartree" / u"bohr"^3))
println("C44: ", uconvert(u"GPa", dstress[4] * u"hartree" / u"bohr"^3))
C11: 156.5181958506859 GPa
C12: 59.57460847630954 GPa
C44: 98.61657992126726 GPa

These results can be compared directly to finite differences of the stress_fn:

h = 1e-3
dstress_fd = (stress_fn(h * strain_pattern) - stress_fn(-h * strain_pattern)) / 2h
println("C11 (FD): ", uconvert(u"GPa", dstress_fd[1] * u"hartree" / u"bohr"^3))
println("C12 (FD): ", uconvert(u"GPa", dstress_fd[2] * u"hartree" / u"bohr"^3))
println("C44 (FD): ", uconvert(u"GPa", dstress_fd[4] * u"hartree" / u"bohr"^3))
n     Energy            log10(ΔE)   log10(Δρ)   Diag   Δtime 
---   ---------------   ---------   ---------   ----   ------
  1   -8.453517500129                   -0.94    5.4    411ms
  2   -8.455640229641       -2.67       -1.77    1.0    180ms
  3   -8.455784072417       -3.84       -2.89    1.9    201ms
  4   -8.455795211040       -4.95       -3.33    2.9    282ms
  5   -8.455795305667       -7.02       -3.88    1.2    175ms
  6   -8.455795314574       -8.05       -4.92    1.4    181ms
  7   -8.455795315188       -9.21       -5.39    2.9    281ms
  8   -8.455795315197      -11.04       -6.04    1.4    187ms
n     Energy            log10(ΔE)   log10(Δρ)   Diag   Δtime 
---   ---------------   ---------   ---------   ----   ------
  1   -8.453419729430                   -0.94    5.4    385ms
  2   -8.455616428372       -2.66       -1.77    1.0    156ms
  3   -8.455769757728       -3.81       -2.87    1.9    205ms
  4   -8.455782160209       -4.91       -3.32    3.0    283ms
  5   -8.455782245546       -7.07       -3.89    1.2    171ms
  6   -8.455782253584       -8.09       -4.80    1.6    190ms
  7   -8.455782254364       -9.11       -5.75    2.6    260ms
  8   -8.455782254371      -11.13       -6.22    2.4    241ms
C11 (FD): 156.22509865516196 GPa
C12 (FD): 59.44979192843247 GPa
C44 (FD): 98.54310124456173 GPa