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}.\]
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.
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-6
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.453506095478 -0.94 5.4 509ms
2 -8.455627974060 -2.67 -1.77 1.0 835ms
3 -8.455776155390 -3.83 -2.89 1.8 190ms
4 -8.455790070241 -4.86 -3.26 3.0 272ms
5 -8.455790174295 -6.98 -3.75 1.1 162ms
6 -8.455790186373 -7.92 -4.60 1.2 160ms
7 -8.455790187662 -8.89 -5.13 2.3 230ms
8 -8.455790187711 -10.31 -6.10 1.8 205ms
Solving response problem
Iter Restart Krydim log10(res) avg(CG) Δtime Comment
---- ------- ------ ---------- ------- ------ ---------------
17.2 7.57s Non-interacting
1 0 1 0.11 12.8 16.3s
2 0 2 -0.70 11.4 857ms
3 0 3 -1.71 10.2 455ms
4 0 4 -2.78 8.1 393ms
5 0 5 -4.04 5.4 313ms
6 0 6 -5.56 1.9 195ms
7 0 7 -7.81 1.0 166ms
8 1 1 -6.40 16.4 925ms Restart
16.1 1.86s 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.3124738960206517e-5
-2.312513639000055e-5
-2.3125136390000578e-5
2.0414502794972667e-9
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.005319958178919801
0.0020248992796911055
0.0020248992796911055
0.003351912698495846
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.51857308742134 GPa
C12: 59.574593491889345 GPa
C44: 98.61667611618394 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.453511209394 -0.94 5.3 409ms
2 -8.455637339304 -2.67 -1.77 1.0 148ms
3 -8.455783497943 -3.84 -2.89 1.8 218ms
4 -8.455795203265 -4.93 -3.31 3.0 275ms
5 -8.455795304846 -6.99 -3.88 1.5 182ms
6 -8.455795314546 -8.01 -5.02 1.5 184ms
7 -8.455795315195 -9.19 -5.76 3.0 280ms
8 -8.455795315198 -11.52 -6.50 1.7 197ms
n Energy log10(ΔE) log10(Δρ) Diag Δtime
--- --------------- --------- --------- ---- ------
1 -8.453416732818 -0.94 5.4 384ms
2 -8.455614832461 -2.66 -1.78 1.0 154ms
3 -8.455768135892 -3.81 -2.87 1.9 204ms
4 -8.455782139171 -4.85 -3.29 3.0 282ms
5 -8.455782241548 -6.99 -3.82 1.1 157ms
6 -8.455782253528 -7.92 -4.98 1.4 181ms
7 -8.455782254365 -9.08 -5.52 2.9 361ms
8 -8.455782254371 -11.27 -5.94 1.5 866ms
9 -8.455782254371 -12.31 -6.62 1.2 164ms
C11 (FD): 156.2978251123254 GPa
C12 (FD): 59.52247178781136 GPa
C44 (FD): 98.55086132436232 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])
stress, (dstress,) = value_and_pushforward(AutoForwardDiff(), zeros(6),
(strain_pattern,)) do voigt_strain
stress_from_strain(model_r2scanl, voigt_strain;
symmetries=symmetries_strain, Ecut, kgrid, tol)
end;┌ Warning: Meta-GGAs with a Δρ term have not yet been thoroughly tested.
└ @ DFTK ~/work/DFTK.jl/DFTK.jl/src/terms/xc.jl:121
n Energy log10(ΔE) log10(Δρ) Diag Δtime
--- --------------- --------- --------- ---- ------
1 -8.490404420874 -0.92 5.7 2.61s
2 -8.493556259514 -2.50 -1.80 1.0 530ms
3 -8.493817474211 -3.58 -2.64 2.1 287ms
4 -8.493840447557 -4.64 -3.35 2.4 311ms
5 -8.493846354540 -5.23 -3.75 2.5 293ms
6 -8.493849026922 -5.57 -4.04 2.1 271ms
7 -8.493850406583 -5.86 -4.38 2.8 309ms
8 -8.493850693568 -6.54 -4.76 2.6 300ms
9 -8.493850750954 -7.24 -5.10 3.2 335ms
10 -8.493850753642 -8.57 -5.60 2.0 257ms
11 -8.493850755085 -8.84 -5.89 2.0 273ms
12 -8.493850755498 -9.38 -6.18 2.0 274ms
Solving response problem
Iter Restart Krydim log10(res) avg(CG) Δtime Comment
---- ------- ------ ---------- ------- ------ ---------------
17.1 648ms Non-interacting
1 0 1 0.11 12.5 2.55s
2 0 2 -0.67 10.4 541ms
3 0 3 -1.30 8.3 463ms
4 0 4 -1.86 6.6 400ms
5 0 5 -2.56 4.9 350ms
6 0 6 -2.89 2.2 263ms
7 0 7 -3.36 2.1 258ms
8 0 8 -3.79 2.0 262ms
9 0 9 -4.26 1.9 1.07s
10 0 10 -4.98 1.3 224ms
11 0 11 -7.19 1.0 213ms
12 1 1 -4.55 18.7 1.07s Restart
13 1 2 -4.92 4.7 338ms
14 1 3 -5.19 2.9 280ms
15 1 4 -5.54 2.9 277ms
16 1 5 -5.99 2.0 254ms
17 1 6 -6.39 2.0 256ms
16.4 732ms Final orbitals
Note here that the value_and_pushforward(...) do voigt_strain ... end syntax defines an anonymous function to compute the stress from a given strain, i.e. defining the same kind of function as stress_fn in the above example. See the Julia documentation on the do-block-syntax for details.
We again inspect the r2SCAN-L stress, which is still small (despite using the PBE lattice constant), so we remain close to the equilibrium:
stress6-element StaticArraysCore.SVector{6, Float64} with indices SOneTo(6):
-1.991256420983935e-5
-1.9912587560657566e-5
-1.9912587560657553e-5
5.137737501840054e-10
0.0
0.0Finally, the r2SCAN-L elastic constants, which agree well with PBE:
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: 155.91239471093328 GPa
C12: 59.34780630662757 GPa
C44: 97.947590200967 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).
- 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.
- 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).