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.921672534470 -0.69 5.8 2 -7.926167862025 -2.35 -1.22 1.0 3 -7.926855247635 -3.16 -2.36 2.1 4 -7.926865039523 -5.01 -3.14 3.0 5 -7.926865071010 -7.50 -3.51 2.0 6 -7.926865085272 -7.85 -3.86 2.0 7 -7.926865092847 -8.12 -4.76 2.8
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₀")