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 UnitfulAtomicComputing 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-61.0e-6The 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.453347444097 -0.94 5.6 212ms
2 -8.455582480498 -2.65 -1.78 1.0 99.4ms
3 -8.455778781071 -3.71 -2.85 2.0 127ms
4 -8.455790091679 -4.95 -3.52 3.0 151ms
5 -8.455790184916 -7.03 -4.49 2.0 127ms
6 -8.455790187654 -8.56 -5.31 2.8 151ms
7 -8.455790187712 -10.23 -6.05 2.8 223ms
n Energy log10(ΔE) log10(Δρ) Diag Δtime
--- --------------- --------- --------- ---- ------
1 -8.455790187713 -6.67 19.3 1.11s
Solving response problem
Iter Restart Krydim log10(res) avg(CG) Δtime Comment
---- ------- ------ ---------- ------- ------ ---------------
17.8 8.15s Non-interacting
1 0 1 0.11 13.7 15.7s
2 0 2 -0.70 12.4 826ms
3 0 3 -1.71 10.9 463ms
4 0 4 -2.78 8.9 405ms
5 0 5 -4.04 6.6 325ms
6 0 6 -5.56 2.7 205ms
7 0 7 -7.72 1.0 155ms
8 1 1 -6.71 17.8 921ms Restart
16.7 1.86s Final orbitals
C11: 156.51814179140155 GPa
C12: 59.574602669774634 GPa
C44: 98.61657735035254 GPa
Here are AD-DFPT results from increasing discretization parameters:
| Ecut | kgrid | c11 | c12 | c44 |
|---|---|---|---|---|
| 18 | [4, 4, 4] | 156.51 | 59.57 | 98.61 |
| 18 | [8, 8, 8] | 153.53 | 56.90 | 100.07 |
| 24 | [8, 8, 8] | 153.26 | 56.82 | 99.97 |
| 24 | [14, 14, 14] | 153.03 | 56.71 | 100.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.99129404096201e-5, -1.9912936137206824e-5, -1.9912936137206824e-5, -7.86780340270696e-12, 0.0, 0.0], C = [0.00529935165429528 0.0020171883036380397 0.0020171883036380397 0.0 0.0 0.0; 0.0020171883036380397 0.00529935165429528 0.0020171883036380397 0.0 0.0 0.0; 0.0020171883036380397 0.0020171883036380397 0.00529935165429528 0.0 0.0 0.0; 0.0 0.0 0.0 0.0033291644189902586 0.0 0.0; 0.0 0.0 0.0 0.0 0.0033291644189902586 0.0; 0.0 0.0 0.0 0.0 0.0 0.0033291644189902586])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.9123082029903 GPa
C12: 59.34772874439575 GPa
C44: 97.9473986277787 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.453455638312 -0.94 5.3 339ms
2 -8.455622351858 -2.66 -1.78 1.0 180ms
3 -8.455776162118 -3.81 -2.90 1.8 180ms
4 -8.455790055934 -4.86 -3.27 3.1 281ms
5 -8.455790169082 -6.95 -3.70 1.2 149ms
6 -8.455790186248 -7.77 -4.86 1.4 165ms
7 -8.455790187694 -8.84 -5.21 2.9 259ms
8 -8.455790187712 -10.74 -6.18 1.1 154ms
Solving response problem
Iter Restart Krydim log10(res) avg(CG) Δtime Comment
---- ------- ------ ---------- ------- ------ ---------------
17.2 595ms Non-interacting
1 0 1 0.11 12.8 549ms
2 0 2 -0.70 11.6 486ms
3 0 3 -1.71 10.2 436ms
4 0 4 -2.78 8.2 369ms
5 0 5 -4.04 5.5 295ms
6 0 6 -5.55 1.9 184ms
7 0 7 -7.81 1.0 1.02s
8 1 1 -6.44 16.9 741ms Restart
16.1 668ms Final orbitals
We can inspect the stress to verify it is small (close to equilibrium):
stress6-element StaticArraysCore.SVector{6, Float64} with indices SOneTo(6):
-2.3123512732154052e-5
-2.3123940492604113e-5
-2.3123940492604126e-5
-2.20363963194026e-10
0.0
0.0The response of the stress to strain_pattern contains the elastic constants in atomic units, with the expected pattern $(c11, c12, c12, c44, 0, 0)$:
dstress6-element StaticArraysCore.SVector{6, Float64} with indices SOneTo(6):
0.0053199524914534215
0.002024898145353127
0.002024898145353127
0.003351914155300128
0.0
0.0Convert 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.5184057563837 GPa
C12: 59.57456011851387 GPa
C44: 98.61671897684558 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.453494210541 -0.94 5.3 368ms
2 -8.455639347049 -2.67 -1.77 1.0 138ms
3 -8.455781833289 -3.85 -2.90 1.9 286ms
4 -8.455795187424 -4.87 -3.26 3.0 1.06s
5 -8.455795298335 -6.96 -3.73 1.1 143ms
6 -8.455795313836 -7.81 -4.97 1.4 162ms
7 -8.455795315189 -8.87 -5.36 3.1 265ms
8 -8.455795315197 -11.10 -5.76 1.0 139ms
9 -8.455795315198 -11.93 -6.82 1.2 158ms
n Energy log10(ΔE) log10(Δρ) Diag Δtime
--- --------------- --------- --------- ---- ------
1 -8.453455688067 -0.94 5.3 452ms
2 -8.455622470543 -2.66 -1.77 1.0 951ms
3 -8.455768223931 -3.84 -2.89 1.8 175ms
4 -8.455782120499 -4.86 -3.25 3.0 252ms
5 -8.455782237405 -6.93 -3.70 1.1 145ms
6 -8.455782252716 -7.82 -4.82 1.2 147ms
7 -8.455782254345 -8.79 -5.18 2.9 251ms
8 -8.455782254369 -10.62 -5.77 1.3 199ms
9 -8.455782254371 -11.72 -6.63 1.6 174ms
C11 (FD): 156.28275791576525 GPa
C12 (FD): 59.5064967226803 GPa
C44 (FD): 98.54758010754259 GPa
- SPH25Schmitz, N. F., Ploumhans, B., & Herbst, M. F. (2026) Algorithmic differentiation for plane-wave DFT: materials design, error control and learning model parameters. npj Computational Materials 12, 6 (2026). (Supplementary material and computational scripts).
- Wu2005Wu, X., Vanderbilt, D., & Hamann, D. R. (2005). Systematic treatment of displacements, strains, and electric fields in density-functional perturbation theory. Physical Review B, 72(3), 035105.
- PBE1996Perdew, J. P., Burke, K., & Ernzerhof, M. (1996). Generalized Gradient Approximation Made Simple. Physical Review Letters, 77(18), 3865-3868.
- MT2020Mejía-Rodríguez, D., & Trickey, S. B. (2020). Meta-GGA performance in solids at almost GGA cost. Physical Review B, 102(12), 121109(R).
- Nye1985Nye, J. F. (1985). Physical Properties of Crystals. Oxford University Press. Comment: Since the elastic tensor transforms equivariantly under rotations, its numerical components depend on the chosen Cartesian coordinate frame. These tabulated patterns assume a standardized orientation of the structure with respect to conventional crystallographic axes.