Aluminium supercell using density-functional theory
In this example we will optimise the structure of a rattled aluminium system using density-functional theory.
First we build a rattled aluminium system:
using AtomsBuilder
using Unitful
system = rattle!(bulk(:Al; cubic=true), 0.2u"Å")
FlexibleSystem(Al₄, periodicity = TTT):
cell_vectors : [ 4.05 0 0;
0 4.05 0;
0 0 4.05]u"Å"
Atom(Al, [-0.131669, 0.0826157, 0.0899152]u"Å")
Atom(Al, [-0.02982, 2.03639, 2.06913]u"Å")
Atom(Al, [ 1.91269, -0.0223633, 2.09241]u"Å")
Atom(Al, [ 1.98896, 1.8983, -0.0454711]u"Å")
Next we create a calculator employing the density-functional toolkit to compute energies and forces at using the LDA density functional. As pseudopotentials we use the PseudoDojo as available in the PseudoPotentialData package.
using DFTK
using PseudoPotentialData
pseudopotentials = PseudoFamily("dojo.nc.sr.lda.v0_4_1.oncvpsp3.standard.upf")
model_kwargs = (; functionals=LDA(), temperature=1e-3, pseudopotentials)
basis_kwargs = (; kgrid=(3, 3, 3), Ecut=10.0)
scf_kwargs = (; mixing=KerkerMixing())
calc = DFTKCalculator(; model_kwargs, basis_kwargs, scf_kwargs)
DFTKCalculator(functionals=Xc(lda_x, lda_c_pw), pseudopotentials=PseudoFamily("dojo.nc.sr.lda.v0_4_1.standard.upf"), temperature=0.001, Ecut=10.0, kgrid=(3, 3, 3))
Note, that the numerical parameters above are chosen rather crudely in order to give a fast runtime on CI systems. For production calculations one would require larger computational parameters.
We perform the structure optimisation using the LBFGS solver from Optim with solver parameters adapted for our geometry optimisation setting. This is selected by passing the OptimLBFGS solver as the third argument. The verbosity=2
flag makes sure we get output from both the geometry optimisation as well as the inner SCF solver.
using GeometryOptimization
results = minimize_energy!(system, calc, OptimLBFGS();
tol_forces=1e-4u"eV/Å", verbosity=2)
nothing
Downloading artifact: dojo.nc.sr.lda.v0_4_1.standard.upf
n Energy log10(ΔE) log10(Δρ) α Diag Δtime
--- --------------- --------- --------- ---- ---- ------
1 -9.438706578846 -1.16 0.80 7.4 3.28s
2 -9.441341636255 -2.58 -1.68 0.80 1.0 8.87s
3 -9.441614342782 -3.56 -2.57 0.80 3.8 527ms
4 -9.441657052064 -4.37 -3.28 0.80 3.6 588ms
5 -9.441657927862 -6.06 -3.64 0.80 3.1 511ms
6 -9.441658112461 -6.73 -4.59 0.80 1.9 658ms
7 -9.441658117535 -8.29 -5.07 0.80 3.5 581ms
8 -9.441658117691 -9.81 -5.74 0.80 2.1 386ms
9 -9.441658117706 -10.82 -6.20 0.80 2.6 510ms
10 -9.441658117706 -12.08 -7.04 0.80 2.0 385ms
11 -9.441658117707 -13.34 -7.54 0.80 3.1 548ms
12 -9.441658117707 + -14.45 -8.59 0.80 2.2 404ms
n Energy log10(ΔE) log10(Δρ) α Diag Δtime
--- --------------- --------- --------- ---- ---- ------
1 -9.441658117707 -9.22 0.80 1.0 2.67s
2 -9.441658117707 + -14.75 -9.52 0.80 1.0 315ms
Geometry optimisation convergence (in atomic units)
┌─────┬─────────────────┬───────────┬─────────────┬─────────────┬──────────┬────────┐
│ n │ Energy │ log10(ΔE) │ max(Force) │ max(Virial) │ Pressure │ Δtime │
├─────┼─────────────────┼───────────┼─────────────┼─────────────┼──────────┼────────┤
│ 0 │ -9.441658117707 │ │ 0.0127443 │ │ │ 41.3s │
└─────┴─────────────────┴───────────┴─────────────┴─────────────┴──────────┴────────┘
n Energy log10(ΔE) log10(Δρ) α Diag Δtime
--- --------------- --------- --------- ---- ---- ------
1 -9.441835548565 -2.54 0.80 1.0 259ms
2 -9.441865491677 -4.52 -3.29 0.80 1.0 293ms
3 -9.441866549434 -5.98 -3.68 0.80 3.0 720ms
4 -9.441866613457 -7.19 -4.10 0.80 2.0 393ms
5 -9.441866642465 -7.54 -5.21 0.80 2.0 364ms
6 -9.441866643010 -9.26 -5.46 0.80 3.8 650ms
7 -9.441866643038 -10.55 -6.29 0.80 1.3 289ms
8 -9.441866643039 -11.87 -7.14 0.80 3.0 527ms
9 -9.441866643039 -13.80 -7.40 0.80 3.4 536ms
10 -9.441866643039 -14.45 -8.32 0.80 1.5 338ms
11 -9.441866643039 + -Inf -9.11 0.80 3.3 752ms
n Energy log10(ΔE) log10(Δρ) α Diag Δtime
--- --------------- --------- --------- ---- ---- ------
1 -9.424289779502 -1.14 0.80 2.0 325ms
2 -9.443898947933 -1.71 -1.96 0.80 1.0 270ms
3 -9.444476369391 -3.24 -2.26 0.80 3.0 513ms
4 -9.444547278941 -4.15 -2.68 0.80 2.0 429ms
5 -9.444566566305 -4.71 -3.77 0.80 1.9 386ms
6 -9.444566753731 -6.73 -3.91 0.80 4.1 850ms
7 -9.444566793140 -7.40 -4.54 0.80 1.0 272ms
8 -9.444566797383 -8.37 -5.74 0.80 2.8 477ms
9 -9.444566797429 -10.33 -5.92 0.80 4.1 699ms
10 -9.444566797433 -11.42 -6.66 0.80 1.0 268ms
11 -9.444566797433 -12.58 -7.23 0.80 3.0 500ms
12 -9.444566797433 -13.97 -8.25 0.80 2.3 424ms
13 -9.444566797433 -14.45 -8.66 0.80 4.0 618ms
n Energy log10(ΔE) log10(Δρ) α Diag Δtime
--- --------------- --------- --------- ---- ---- ------
1 -9.444566797433 -8.58 0.80 1.0 277ms
2 -9.444566797433 + -14.27 -9.80 0.80 1.0 497ms
n Energy log10(ΔE) log10(Δρ) α Diag Δtime
--- --------------- --------- --------- ---- ---- ------
1 -9.444566797433 -9.53 0.80 1.0 246ms
2 -9.444566797433 + -14.45 -10.31 0.80 1.0 268ms
┌─────┬─────────────────┬───────────┬─────────────┬─────────────┬──────────┬────────┐
│ n │ Energy │ log10(ΔE) │ max(Force) │ max(Virial) │ Pressure │ Δtime │
├─────┼─────────────────┼───────────┼─────────────┼─────────────┼──────────┼────────┤
│ 1 │ -9.444566797433 │ │ 0.00219763 │ │ │ 14.2s │
└─────┴─────────────────┴───────────┴─────────────┴─────────────┴──────────┴────────┘
n Energy log10(ΔE) log10(Δρ) α Diag Δtime
--- --------------- --------- --------- ---- ---- ------
1 -9.444396462086 -1.92 0.80 1.0 253ms
2 -9.444739265154 -3.46 -2.39 0.80 1.0 269ms
3 -9.444776762176 -4.43 -3.06 0.80 3.2 471ms
4 -9.444778628049 -5.73 -3.95 0.80 2.9 521ms
5 -9.444778686518 -7.23 -4.54 0.80 3.3 775ms
6 -9.444778687233 -9.15 -5.70 0.80 2.9 443ms
7 -9.444778687270 -10.42 -6.18 0.80 4.1 671ms
8 -9.444778687271 -12.41 -6.61 0.80 2.3 365ms
9 -9.444778687271 -13.30 -7.58 0.80 2.2 336ms
10 -9.444778687271 -14.15 -8.06 0.80 3.8 583ms
11 -9.444778687271 + -Inf -8.76 0.80 2.4 362ms
n Energy log10(ΔE) log10(Δρ) α Diag Δtime
--- --------------- --------- --------- ---- ---- ------
1 -9.444777473489 -3.01 0.80 1.0 499ms
2 -9.444779671567 -5.66 -3.48 0.80 1.0 263ms
3 -9.444779910263 -6.62 -4.17 0.80 3.2 466ms
4 -9.444779922313 -7.92 -5.05 0.80 2.6 470ms
5 -9.444779922705 -9.41 -5.66 0.80 3.3 537ms
6 -9.444779922710 -11.33 -6.97 0.80 2.7 440ms
7 -9.444779922710 -12.64 -7.36 0.80 4.4 732ms
8 -9.444779922710 + -Inf -7.97 0.80 2.1 330ms
9 -9.444779922710 + -Inf -8.82 0.80 2.7 397ms
n Energy log10(ΔE) log10(Δρ) α Diag Δtime
--- --------------- --------- --------- ---- ---- ------
1 -9.444779922710 -9.25 0.80 1.0 497ms
2 -9.444779922710 -14.75 -9.89 0.80 1.0 264ms
n Energy log10(ΔE) log10(Δρ) α Diag Δtime
--- --------------- --------- --------- ---- ---- ------
1 -9.444779922710 -9.99 0.80 1.0 254ms
2 -9.444779922710 + -14.75 -10.62 0.80 1.0 265ms
┌─────┬─────────────────┬───────────┬─────────────┬─────────────┬──────────┬────────┐
│ n │ Energy │ log10(ΔE) │ max(Force) │ max(Virial) │ Pressure │ Δtime │
├─────┼─────────────────┼───────────┼─────────────┼─────────────┼──────────┼────────┤
│ 2 │ -9.444779922710 │ -3.67 │ 0.000177977 │ │ │ 11.2s │
└─────┴─────────────────┴───────────┴─────────────┴─────────────┴──────────┴────────┘
n Energy log10(ΔE) log10(Δρ) α Diag Δtime
--- --------------- --------- --------- ---- ---- ------
1 -9.444778936068 -3.22 0.80 1.0 251ms
2 -9.444780356026 -5.85 -4.16 0.80 1.0 264ms
3 -9.444780390224 -7.47 -4.45 0.80 3.3 559ms
4 -9.444780393799 -8.45 -5.03 0.80 1.4 521ms
5 -9.444780393889 -10.05 -5.65 0.80 2.9 472ms
6 -9.444780393898 -11.05 -6.47 0.80 2.2 376ms
7 -9.444780393898 -12.36 -6.80 0.80 3.1 524ms
8 -9.444780393898 -13.04 -7.74 0.80 1.9 356ms
9 -9.444780393898 + -14.45 -8.05 0.80 3.3 534ms
10 -9.444780393898 -14.75 -8.57 0.80 1.4 298ms
n Energy log10(ΔE) log10(Δρ) α Diag Δtime
--- --------------- --------- --------- ---- ---- ------
1 -9.444772205654 -2.84 0.80 1.0 277ms
2 -9.444780645593 -5.07 -3.77 0.80 1.0 483ms
3 -9.444780848655 -6.69 -4.06 0.80 3.4 541ms
4 -9.444780869946 -7.67 -4.65 0.80 1.4 315ms
5 -9.444780870482 -9.27 -5.27 0.80 2.5 436ms
6 -9.444780870540 -10.24 -6.06 0.80 2.8 420ms
7 -9.444780870543 -11.56 -6.38 0.80 3.0 494ms
8 -9.444780870544 -12.23 -7.39 0.80 1.9 339ms
9 -9.444780870544 -13.71 -7.64 0.80 3.6 575ms
10 -9.444780870544 + -14.75 -8.19 0.80 1.5 307ms
11 -9.444780870544 + -Inf -9.14 0.80 2.7 695ms
n Energy log10(ΔE) log10(Δρ) α Diag Δtime
--- --------------- --------- --------- ---- ---- ------
1 -9.444780870544 -9.03 0.80 1.0 244ms
2 -9.444780870544 + -Inf -10.17 0.80 1.0 267ms
n Energy log10(ΔE) log10(Δρ) α Diag Δtime
--- --------------- --------- --------- ---- ---- ------
1 -9.444780870544 -9.87 0.80 1.0 252ms
2 -9.444780870544 -14.45 -10.69 0.80 1.0 269ms
┌─────┬─────────────────┬───────────┬─────────────┬─────────────┬──────────┬────────┐
│ n │ Energy │ log10(ΔE) │ max(Force) │ max(Virial) │ Pressure │ Δtime │
├─────┼─────────────────┼───────────┼─────────────┼─────────────┼──────────┼────────┤
│ 3 │ -9.444780870544 │ -6.02 │ 1.80807e-5 │ │ │ 10.8s │
└─────┴─────────────────┴───────────┴─────────────┴─────────────┴──────────┴────────┘
n Energy log10(ΔE) log10(Δρ) α Diag Δtime
--- --------------- --------- --------- ---- ---- ------
1 -9.444780872004 -5.00 0.80 1.0 274ms
2 -9.444780872279 -9.56 -5.53 0.80 1.0 484ms
3 -9.444780872301 -10.66 -6.08 0.80 3.3 500ms
4 -9.444780872302 -11.86 -6.69 0.80 2.5 446ms
5 -9.444780872303 -12.74 -7.56 0.80 2.0 432ms
6 -9.444780872303 + -Inf -8.00 0.80 3.5 527ms
7 -9.444780872303 -14.45 -8.73 0.80 2.1 336ms
n Energy log10(ΔE) log10(Δρ) α Diag Δtime
--- --------------- --------- --------- ---- ---- ------
1 -9.444780857693 -4.07 0.80 1.0 251ms
2 -9.444780877688 -7.70 -4.60 0.80 1.0 530ms
3 -9.444780879276 -8.80 -5.15 0.80 3.3 502ms
4 -9.444780879375 -10.00 -5.76 0.80 2.4 435ms
5 -9.444780879388 -10.88 -6.63 0.80 2.1 425ms
6 -9.444780879388 -12.77 -7.04 0.80 3.4 553ms
7 -9.444780879388 -13.97 -7.75 0.80 2.1 338ms
8 -9.444780879388 -14.75 -8.37 0.80 3.0 499ms
9 -9.444780879388 -14.75 -9.05 0.80 2.3 379ms
n Energy log10(ΔE) log10(Δρ) α Diag Δtime
--- --------------- --------- --------- ---- ---- ------
1 -9.444780879388 -9.42 0.80 1.0 501ms
2 -9.444780879388 -14.75 -10.00 0.80 1.0 266ms
n Energy log10(ΔE) log10(Δρ) α Diag Δtime
--- --------------- --------- --------- ---- ---- ------
1 -9.444780879388 -10.22 0.80 1.0 252ms
2 -9.444780879388 + -14.75 -10.90 0.80 1.0 263ms
┌─────┬─────────────────┬───────────┬─────────────┬─────────────┬──────────┬────────┐
│ n │ Energy │ log10(ΔE) │ max(Force) │ max(Virial) │ Pressure │ Δtime │
├─────┼─────────────────┼───────────┼─────────────┼─────────────┼──────────┼────────┤
│ 4 │ -9.444780879388 │ -8.05 │ 8.7103e-7 │ │ │ 8.95s │
└─────┴─────────────────┴───────────┴─────────────┴─────────────┴──────────┴────────┘
Some calculators (such as DFTK) are able to adapt to the keyword arguments and parameters passed to minimize_energy!
. In this case the SCF tolerance is automatically adapted according to the convergence parameters (here tol_forces
) passed to minimize_energy!
.
The final energy is
results.energy
-9.444780879388365 Eₕ
We can view the final structure
results.system
FlexibleSystem(Al₄, periodicity = TTT):
cell_vectors : [ 4.05 0 0;
0 4.05 0;
0 0 4.05]u"Å"
Atom(Al, [-0.0774592, -0.0137613, 0.0389927]u"Å")
Atom(Al, [-0.0774667, 2.01123, 2.064]u"Å")
Atom(Al, [ 1.94754, -0.013756, 2.064]u"Å")
Atom(Al, [ 1.94754, 2.01124, 0.0389983]u"Å")
The results object returned from Optim (containing some statistics about the optimisation):
results.optimres
* Status: failure
* Candidate solution
Final objective value: -9.444781e+00
* Found with
Algorithm: L-BFGS
* Convergence measures
|x - x'| = 1.76e-04 ≰ -1.0e+00
|x - x'|/|x'| = 1.56e-03 ≰ -1.0e+00
|f(x) - f(x')| = 8.84e-09 ≰ -1.0e+00
|f(x) - f(x')|/|f(x')| = 9.36e-10 ≰ -1.0e+00
|g(x)| = 1.32e-06 ≰ 2.2e-15
* Work counters
Seconds run: 46 (vs limit 31536000)
Iterations: 4
f(x) calls: 9
∇f(x) calls: 5
The final state of the calculator object is also accessible via results.state
and could be employed for postprocessing using the framework of the calculator. E.g. in the case of DFTK
, the results.state
is what DFTK
calls an scfres
and could just be used to plot a density of states or plot bands or compute response properties.