AtomsBase integration

AtomsBase.jl is a common interface for representing atomic structures in Julia. DFTK directly supports using such structures to run a calculation as is demonstrated here.

using DFTK
using AtomsBase
using Unitful
using UnitfulAtomic

# Construct a system in the AtomsBase world
a = 10.26u"bohr"  # Silicon lattice constant
lattice = a / 2 * [[0, 1, 1.],  # Lattice as vector of vectors
                   [1, 0, 1.],
                   [1, 1, 0.]]
atoms  = [:Si => ones(3)/8, :Si => -ones(3)/8]
system = periodic_system(atoms, lattice; fractional=true)
FlexibleSystem(Si₂, AtomsBase.Periodic, box=[[0.0, 5.13, 5.13], [5.13, 0.0, 5.13], [5.13, 5.13, 0.0]]u"a₀")

System is an AtomsBase-compatible system. To use it in DFTK, we attach pseudopotentials, construct a DFT model, discretise and solve:

system = attach_psp(system; family="hgh", functional="lda")

model  = model_LDA(system; temperature=1e-3)
basis  = PlaneWaveBasis(model; Ecut=15, kgrid=[4, 4, 4])
scfres = self_consistent_field(basis, tol=1e-8);
n     Energy            log10(ΔE)   log10(Δρ)   Diag
---   ---------------   ---------   ---------   ----
  1   -7.921715375082                   -0.69    5.8
  2   -7.926165543359       -2.35       -1.22    1.0
  3   -7.926855148759       -3.16       -2.37    2.1
  4   -7.926865042374       -5.00       -3.15    3.0
  5   -7.926865072818       -7.52       -3.53    2.1
  6   -7.926865085904       -7.88       -3.88    2.1
  7   -7.926865092835       -8.16       -4.74    2.5

At any point we can also get back the DFTK model as an AtomsBase-compatible AbstractSystem:

newsystem = atomic_system(model)
FlexibleSystem(Si₂, AtomsBase.Periodic, box=[[0.0, 5.13, 5.13], [5.13, 0.0, 5.13], [5.13, 5.13, 0.0]]u"a₀")