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.453386401393                   -0.94    5.6    193ms
  2   -8.455596730663       -2.66       -1.78    1.0   98.8ms
  3   -8.455779394077       -3.74       -2.85    2.0    122ms
  4   -8.455790102301       -4.97       -3.50    2.9    146ms
  5   -8.455790183393       -7.09       -4.41    1.6    113ms
  6   -8.455790187638       -8.37       -5.23    2.8    165ms
  7   -8.455790187712      -10.13       -5.95    2.5    135ms
  8   -8.455790187713      -11.77       -7.16    2.2    146ms
n     Energy            log10(ΔE)   log10(Δρ)   Diag   Δtime 
---   ---------------   ---------   ---------   ----   ------
  1   -8.455790187713                   -7.73   22.4    1.26s
Solving response problem
Iter  Restart  Krydim  log10(res)  avg(CG)  Δtime   Comment
----  -------  ------  ----------  -------  ------  ---------------
                                      19.3   7.98s  Non-interacting
   1        0       1        0.11     15.3   16.6s  
   2        0       2       -0.70     14.2   889ms  
   3        0       3       -1.71     12.7   519ms  
   4        0       4       -2.78     10.9   460ms  
   5        0       5       -4.04      8.6   389ms  
   6        0       6       -5.57      5.3   286ms  
   7        0       7       -6.90      1.9   177ms  
   8        0       8       -8.93      1.0   153ms  
   9        1       1       -7.93     19.5   1.75s  Restart
                                      18.3   1.90s  Final orbitals
C11: 156.51824057070382 GPa
C12: 59.57460531187625 GPa
C44: 98.6166165732475 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.9912902122283835e-5, -1.9912897082372208e-5, -1.9912897082372195e-5, -1.6850705646325039e-12, 0.0, 0.0], C = [0.005299351499453499 0.002017188084816041 0.002017188084816041 0.0 0.0 0.0; 0.002017188084816041 0.005299351499453499 0.002017188084816041 0.0 0.0 0.0; 0.002017188084816041 0.002017188084816041 0.005299351499453499 0.0 0.0 0.0; 0.0 0.0 0.0 0.0033291626634183104 0.0 0.0; 0.0 0.0 0.0 0.0 0.0033291626634183104 0.0; 0.0 0.0 0.0 0.0 0.0 0.0033291626634183104])

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.9123036473878 GPa
C12: 59.34772230643029 GPa
C44: 97.94734697706885 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.453464385699                   -0.94    5.3    452ms
  2   -8.455625842875       -2.67       -1.78    1.0    172ms
  3   -8.455776188308       -3.82       -2.88    1.8    176ms
  4   -8.455790073173       -4.86       -3.27    3.1    260ms
  5   -8.455790174434       -6.99       -3.77    1.1    147ms
  6   -8.455790186662       -7.91       -4.78    1.4    164ms
  7   -8.455790187698       -8.98       -5.44    2.6    239ms
  8   -8.455790187712      -10.85       -5.87    1.9    195ms
  9   -8.455790187713      -12.04       -6.58    1.4    168ms
Solving response problem
Iter  Restart  Krydim  log10(res)  avg(CG)  Δtime   Comment
----  -------  ------  ----------  -------  ------  ---------------
                                      17.9   708ms  Non-interacting
   1        0       1        0.11     13.7   1.42s  
   2        0       2       -0.70     12.4   506ms  
   3        0       3       -1.71     10.9   452ms  
   4        0       4       -2.78      8.9   388ms  
   5        0       5       -4.04      6.5   320ms  
   6        0       6       -5.56      2.7   198ms  
   7        0       7       -7.80      1.0   153ms  
   8        1       1       -6.71     17.8   787ms  Restart
                                      16.8   640ms  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.3121201005746743e-5
 -2.312119681412203e-5
 -2.3121196814122045e-5
  1.1338179288413104e-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.0053199437042119125
 0.002024899693559051
 0.002024899693559051
 0.0033519090956490695
 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.51814722681334 GPa
C12: 59.57460566830467 GPa
C44: 98.61657011677237 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.453506059546                   -0.94    5.4    374ms
  2   -8.455638343984       -2.67       -1.77    1.0    163ms
  3   -8.455783748227       -3.84       -2.88    1.9    186ms
  4   -8.455795208871       -4.94       -3.32    3.0    266ms
  5   -8.455795304060       -7.02       -3.85    1.1    152ms
  6   -8.455795314536       -7.98       -4.87    1.5    179ms
  7   -8.455795315185       -9.19       -5.36    2.8    246ms
  8   -8.455795315197      -10.90       -6.09    1.4    169ms
n     Energy            log10(ΔE)   log10(Δρ)   Diag   Δtime 
---   ---------------   ---------   ---------   ----   ------
  1   -8.453428538471                   -0.94    5.3    346ms
  2   -8.455612651763       -2.66       -1.78    1.0    138ms
  3   -8.455769515048       -3.80       -2.87    1.9    189ms
  4   -8.455782143472       -4.90       -3.34    3.0    249ms
  5   -8.455782244518       -7.00       -3.88    1.4    169ms
  6   -8.455782253556       -8.04       -4.75    1.4    169ms
  7   -8.455782254348       -9.10       -5.32    2.2    215ms
  8   -8.455782254370      -10.65       -6.10    1.9    202ms
C11 (FD): 156.29031903214312 GPa
C12 (FD): 59.51804403770837 GPa
C44 (FD): 98.52759140212724 GPa