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.0364073, 0.0442758, -0.111302]u"Å")
    Atom(Al, [-0.0441891,  2.06138,  2.08538]u"Å")
    Atom(Al, [ 2.08334, -0.0343181,  2.19361]u"Å")
    Atom(Al, [ 2.02219,  2.02087, 0.0854093]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))
Crude computational parameters

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 GeometryOptimization.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
GO = GeometryOptimization

results = minimize_energy!(system, calc, GO.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.435660766148                   -1.14   0.80    7.8    5.08s
  2   -9.439947244562       -2.37       -1.68   0.80    1.0    8.80s
  3   -9.440286534723       -3.47       -2.44   0.80    3.2    497ms
  4   -9.440346136387       -4.22       -3.18   0.80    2.9    557ms
  5   -9.440346960729       -6.08       -3.61   0.80    3.3    504ms
  6   -9.440347146768       -6.73       -4.84   0.80    2.3    429ms
  7   -9.440347151051       -8.37       -5.06   0.80    4.4    1.07s
  8   -9.440347151240       -9.72       -5.84   0.80    1.5    333ms
  9   -9.440347151251      -10.95       -6.37   0.80    2.7    519ms
 10   -9.440347151252      -12.36       -7.19   0.80    2.2    419ms
 11   -9.440347151252      -13.64       -7.87   0.80    3.1    544ms
 12   -9.440347151252      -14.75       -8.68   0.80    3.0    470ms
n     Energy            log10(ΔE)   log10(Δρ)   α      Diag   Δtime
---   ---------------   ---------   ---------   ----   ----   ------
  1   -9.440347151252                   -8.66   0.80    1.0    2.20s
  2   -9.440347151252      -14.75       -9.66   0.80    1.0    357ms

Geometry optimisation convergence (in atomic units)
┌─────┬─────────────────┬───────────┬────────────┬────────┐
│   n │          Energy │ log10(ΔE) │ max(Force) │  Δtime │
├─────┼─────────────────┼───────────┼────────────┼────────┤
│   0 │ -9.440347151252 │           │  0.0157971 │  44.9s │
└─────┴─────────────────┴───────────┴────────────┴────────┘

n     Energy            log10(ΔE)   log10(Δρ)   α      Diag   Δtime
---   ---------------   ---------   ---------   ----   ----   ------
  1   -9.440437319317                   -2.90   0.80    1.0    274ms
  2   -9.440443283822       -5.22       -3.71   0.80    1.0    288ms
  3   -9.440443474124       -6.72       -4.06   0.80    3.0    534ms
  4   -9.440443487077       -7.89       -4.48   0.80    2.0    449ms
  5   -9.440443491709       -8.33       -5.62   0.80    2.0    410ms
  6   -9.440443491773      -10.19       -6.06   0.80    3.6    949ms
  7   -9.440443491774      -11.99       -6.86   0.80    2.0    363ms
  8   -9.440443491774      -12.96       -7.82   0.80    2.9    542ms
  9   -9.440443491774   +  -14.75       -8.28   0.80    3.7    602ms
 10   -9.440443491774   +  -14.75       -9.08   0.80    2.2    358ms
n     Energy            log10(ΔE)   log10(Δρ)   α      Diag   Δtime
---   ---------------   ---------   ---------   ----   ----   ------
  1   -9.406290301555                   -1.02   0.80    2.1    412ms
  2   -9.443360461220       -1.43       -2.03   0.80    1.1    284ms
  3   -9.444134461355       -3.11       -2.22   0.80    3.3    901ms
  4   -9.444220311165       -4.07       -2.71   0.80    2.0    419ms
  5   -9.444236571370       -4.79       -3.64   0.80    2.0    371ms
  6   -9.444236998882       -6.37       -3.99   0.80    3.1    584ms
  7   -9.444237032706       -7.47       -4.81   0.80    1.8    318ms
  8   -9.444237034658       -8.71       -5.49   0.80    3.3    588ms
  9   -9.444237034689      -10.51       -5.87   0.80    2.8    414ms
 10   -9.444237034696      -11.14       -7.14   0.80    2.2    392ms
 11   -9.444237034696      -12.74       -7.28   0.80    4.0    753ms
 12   -9.444237034696      -14.27       -7.85   0.80    1.0    306ms
 13   -9.444237034696      -14.45       -8.49   0.80    2.2    709ms
n     Energy            log10(ΔE)   log10(Δρ)   α      Diag   Δtime
---   ---------------   ---------   ---------   ----   ----   ------
  1   -9.444237034696                   -8.45   0.80    1.0    249ms
  2   -9.444237034696   +    -Inf       -9.59   0.80    1.0    283ms

┌─────┬─────────────────┬───────────┬────────────┬────────┐
│   n │          Energy │ log10(ΔE) │ max(Force) │  Δtime │
├─────┼─────────────────┼───────────┼────────────┼────────┤
│   1 │ -9.444237034696 │     -2.41 │ 0.00414274 │  13.5s │
└─────┴─────────────────┴───────────┴────────────┴────────┘

n     Energy            log10(ΔE)   log10(Δρ)   α      Diag   Δtime
---   ---------------   ---------   ---------   ----   ----   ------
  1   -9.436799215557                   -1.29   0.80    2.0    339ms
  2   -9.443594381289       -2.17       -1.88   0.80    1.0    276ms
  3   -9.443945122105       -3.46       -2.43   0.80    2.9    526ms
  4   -9.443984061814       -4.41       -2.95   0.80    2.3    787ms
  5   -9.443989287310       -5.28       -3.72   0.80    2.0    417ms
  6   -9.443989430474       -6.84       -4.28   0.80    3.1    524ms
  7   -9.443989437507       -8.15       -5.03   0.80    2.6    432ms
  8   -9.443989437936       -9.37       -5.84   0.80    3.0    510ms
  9   -9.443989437944      -11.08       -6.41   0.80    3.0    500ms
 10   -9.443989437945      -12.34       -7.45   0.80    2.4    452ms
 11   -9.443989437945      -14.45       -8.19   0.80    3.8    671ms
 12   -9.443989437945      -14.45       -8.85   0.80    2.6    491ms
n     Energy            log10(ΔE)   log10(Δρ)   α      Diag   Δtime
---   ---------------   ---------   ---------   ----   ----   ------
  1   -9.442529947810                   -1.57   0.80    1.0    595ms
  2   -9.444521328317       -2.70       -2.12   0.80    1.0    268ms
  3   -9.444656390091       -3.87       -2.68   0.80    3.2    522ms
  4   -9.444666154756       -5.01       -3.25   0.80    2.5    471ms
  5   -9.444667613125       -5.84       -4.14   0.80    2.2    450ms
  6   -9.444667632872       -7.70       -4.54   0.80    3.9    599ms
  7   -9.444667634205       -8.88       -5.24   0.80    1.8    376ms
  8   -9.444667634314       -9.96       -5.98   0.80    3.0    517ms
  9   -9.444667634316      -11.65       -6.62   0.80    3.0    467ms
 10   -9.444667634316      -13.07       -7.13   0.80    2.6    464ms
 11   -9.444667634316      -14.05       -8.12   0.80    2.0    462ms
 12   -9.444667634316      -14.75       -8.93   0.80    3.8    876ms
n     Energy            log10(ΔE)   log10(Δρ)   α      Diag   Δtime
---   ---------------   ---------   ---------   ----   ----   ------
  1   -9.444667634316                   -9.29   0.80    1.0    257ms
  2   -9.444667634316   +    -Inf      -10.07   0.80    1.0    270ms

┌─────┬─────────────────┬───────────┬────────────┬────────┐
│   n │          Energy │ log10(ΔE) │ max(Force) │  Δtime │
├─────┼─────────────────┼───────────┼────────────┼────────┤
│   2 │ -9.444667634316 │     -3.37 │ 0.0004913… │  13.3s │
└─────┴─────────────────┴───────────┴────────────┴────────┘

n     Energy            log10(ΔE)   log10(Δρ)   α      Diag   Δtime
---   ---------------   ---------   ---------   ----   ----   ------
  1   -9.444663338983                   -2.89   0.80    1.0    284ms
  2   -9.444669894135       -5.18       -3.85   0.80    1.0    273ms
  3   -9.444670054685       -6.79       -4.07   0.80    3.5    605ms
  4   -9.444670078022       -7.63       -4.70   0.80    1.7    631ms
  5   -9.444670078821       -9.10       -5.40   0.80    2.4    433ms
  6   -9.444670078860      -10.41       -6.23   0.80    2.6    442ms
  7   -9.444670078861      -11.92       -6.64   0.80    2.8    530ms
  8   -9.444670078861      -12.72       -7.47   0.80    2.3    393ms
  9   -9.444670078861      -14.45       -8.07   0.80    2.8    535ms
 10   -9.444670078861      -14.75       -8.40   0.80    2.5    402ms
 11   -9.444670078861   +    -Inf       -9.36   0.80    2.0    374ms
n     Energy            log10(ΔE)   log10(Δρ)   α      Diag   Δtime
---   ---------------   ---------   ---------   ----   ----   ------
  1   -9.444620893835                   -2.45   0.80    1.0    578ms
  2   -9.444671533026       -4.30       -3.40   0.80    1.0    269ms
  3   -9.444672772514       -5.91       -3.62   0.80    3.6    563ms
  4   -9.444672952045       -6.75       -4.26   0.80    1.7    372ms
  5   -9.444672958273       -8.21       -4.94   0.80    2.4    455ms
  6   -9.444672958595       -9.49       -5.81   0.80    2.2    422ms
  7   -9.444672958603      -11.09       -6.17   0.80    3.3    540ms
  8   -9.444672958605      -11.78       -7.00   0.80    2.0    390ms
  9   -9.444672958605      -13.32       -7.48   0.80    2.9    542ms
 10   -9.444672958605      -14.15       -7.83   0.80    2.1    380ms
 11   -9.444672958605      -14.75       -8.89   0.80    2.0    362ms
n     Energy            log10(ΔE)   log10(Δρ)   α      Diag   Δtime
---   ---------------   ---------   ---------   ----   ----   ------
  1   -9.444672958605                   -8.82   0.80    1.0    575ms
  2   -9.444672958605      -14.75       -9.85   0.80    1.0    271ms

┌─────┬─────────────────┬───────────┬────────────┬────────┐
│   n │          Energy │ log10(ΔE) │ max(Force) │  Δtime │
├─────┼─────────────────┼───────────┼────────────┼────────┤
│   3 │ -9.444672958605 │     -5.27 │  8.5087e-5 │  11.4s │
└─────┴─────────────────┴───────────┴────────────┴────────┘

n     Energy            log10(ΔE)   log10(Δρ)   α      Diag   Δtime
---   ---------------   ---------   ---------   ----   ----   ------
  1   -9.444672924335                   -3.84   0.80    1.0    262ms
  2   -9.444673005900       -7.09       -4.82   0.80    1.0    273ms
  3   -9.444673007888       -8.70       -5.01   0.80    3.5    577ms
  4   -9.444673008189       -9.52       -5.49   0.80    1.3    299ms
  5   -9.444673008207      -10.75       -6.22   0.80    2.4    421ms
  6   -9.444673008208      -11.96       -6.68   0.80    2.5    489ms
  7   -9.444673008208      -12.84       -7.27   0.80    2.4    428ms
  8   -9.444673008208      -13.85       -7.94   0.80    2.4    735ms
  9   -9.444673008208   +    -Inf       -8.48   0.80    2.4    432ms
n     Energy            log10(ΔE)   log10(Δρ)   α      Diag   Δtime
---   ---------------   ---------   ---------   ----   ----   ------
  1   -9.444671030392                   -3.15   0.80    1.0    272ms
  2   -9.444673063234       -5.69       -4.12   0.80    1.0    276ms
  3   -9.444673112801       -7.30       -4.31   0.80    3.3    565ms
  4   -9.444673120275       -8.13       -4.78   0.80    1.3    302ms
  5   -9.444673120722       -9.35       -5.53   0.80    2.4    422ms
  6   -9.444673120749      -10.56       -5.99   0.80    2.6    551ms
  7   -9.444673120752      -11.47       -6.54   0.80    2.3    646ms
  8   -9.444673120753      -12.36       -7.23   0.80    2.3    473ms
  9   -9.444673120753      -13.91       -7.70   0.80    2.6    430ms
 10   -9.444673120753   +    -Inf       -8.83   0.80    2.0    408ms
n     Energy            log10(ΔE)   log10(Δρ)   α      Diag   Δtime
---   ---------------   ---------   ---------   ----   ----   ------
  1   -9.444673120753                   -9.37   0.80    1.0    258ms
  2   -9.444673120753   +  -14.15       -9.74   0.80    1.0    277ms

┌─────┬─────────────────┬───────────┬────────────┬────────┐
│   n │          Energy │ log10(ΔE) │ max(Force) │  Δtime │
├─────┼─────────────────┼───────────┼────────────┼────────┤
│   4 │ -9.444673120753 │     -6.79 │ 1.15854e-5 │  9.58s │
└─────┴─────────────────┴───────────┴────────────┴────────┘

n     Energy            log10(ΔE)   log10(Δρ)   α      Diag   Δtime
---   ---------------   ---------   ---------   ----   ----   ------
  1   -9.444673121666                   -4.97   0.80    1.0    261ms
  2   -9.444673121983       -9.50       -5.49   0.80    1.0    571ms
  3   -9.444673122008      -10.60       -6.05   0.80    3.5    515ms
  4   -9.444673122010      -11.79       -6.65   0.80    2.5    487ms
  5   -9.444673122010      -12.65       -7.53   0.80    2.0    416ms
  6   -9.444673122010      -14.75       -7.89   0.80    3.6    599ms
  7   -9.444673122010   +    -Inf       -8.55   0.80    2.0    331ms
n     Energy            log10(ΔE)   log10(Δρ)   α      Diag   Δtime
---   ---------------   ---------   ---------   ----   ----   ------
  1   -9.444673116390                   -4.27   0.80    1.0    263ms
  2   -9.444673124172       -8.11       -4.80   0.80    1.0    301ms
  3   -9.444673124793       -9.21       -5.36   0.80    3.3    802ms
  4   -9.444673124833      -10.40       -5.96   0.80    2.1    449ms
  5   -9.444673124839      -11.27       -6.84   0.80    2.0    405ms
  6   -9.444673124839      -12.99       -7.17   0.80    3.7    608ms
  7   -9.444673124839      -14.27       -7.79   0.80    1.7    307ms
  8   -9.444673124839      -14.75       -8.54   0.80    2.9    513ms
n     Energy            log10(ΔE)   log10(Δρ)   α      Diag   Δtime
---   ---------------   ---------   ---------   ----   ----   ------
  1   -9.444673124839                   -8.52   0.80    1.0    262ms
  2   -9.444673124839   +    -Inf       -9.66   0.80    1.0    275ms

┌─────┬─────────────────┬───────────┬────────────┬────────┐
│   n │          Energy │ log10(ΔE) │ max(Force) │  Δtime │
├─────┼─────────────────┼───────────┼────────────┼────────┤
│   5 │ -9.444673124839 │     -8.39 │ 3.71186e-8 │  8.17s │
└─────┴─────────────────┴───────────┴────────────┴────────┘
Automatically adapted calculator parameters

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.444673124838753 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.00626688, 0.0105533, 0.0507743]u"Å")
    Atom(Al, [-0.00626732,  2.03555,  2.07577]u"Å")
    Atom(Al, [ 2.01873, 0.010553,  2.07577]u"Å")
    Atom(Al, [ 2.01873,  2.03555, 0.050775]u"Å")

Some statistics about the optimisation

results.stats
SciMLBase.OptimizationStats
Number of iterations:                              5
Time in seconds:                                   98.819611
Number of function evaluations:                    11
Number of gradient evaluations:                    6
Number of hessian evaluations:                     0

or the details about the selected algorithm:

results.alg
Optim.LBFGS{Nothing, LineSearches.InitialHagerZhang{Float64}, LineSearches.BackTracking{Float64, Int64}, Optim.var"#20#22"}(10, LineSearches.InitialHagerZhang{Float64}
  ψ0: Float64 0.01
  ψ1: Float64 0.2
  ψ2: Float64 2.0
  ψ3: Float64 0.1
  αmax: Float64 Inf
  α0: Float64 1.0
  quadstep: Bool true
  verbose: Bool false
, LineSearches.BackTracking{Float64, Int64}
  c_1: Float64 0.0001
  ρ_hi: Float64 0.5
  ρ_lo: Float64 0.1
  iterations: Int64 1000
  order: Int64 2
  maxstep: Float64 0.8
  cache: Nothing nothing
, nothing, Optim.var"#20#22"(), Optim.Flat(), true)

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.