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 AtomsBuilderFeeding an AtomsBase AbstractSystem to DFTK
In this example we construct a bulk silicon system using the bulk function from AtomsBuilder. This function uses tabulated data to set up a reasonable starting geometry and lattice for bulk silicon.
system = bulk(:Si)FlexibleSystem(Si₂, periodicity = TTT):
cell_vectors : [ 0 2.715 2.715;
2.715 0 2.715;
2.715 2.715 0]u"Å"
Atom(Si, [ 0, 0, 0]u"Å")
Atom(Si, [ 1.3575, 1.3575, 1.3575]u"Å")
By default the atoms of an AbstractSystem employ the bare Coulomb potential. To employ pseudpotential models (which is almost always advisable for plane-wave DFT) one employs the pseudopotential keyword argument in model constructors such as model_DFT. For example we can employ a PseudoFamily object from the PseudoPotentialData package. See its documentation for more information on the available pseudopotential families and how to select them.
using PseudoPotentialData # defines PseudoFamily
pd_lda_family = PseudoFamily("dojo.nc.sr.lda.v0_4_1.standard.upf")
model = model_DFT(system; functionals=LDA(), temperature=1e-3,
pseudopotentials=pd_lda_family)Model(lda_x+lda_c_pw, 3D):
lattice (in Bohr) : [0 , 5.13061 , 5.13061 ]
[5.13061 , 0 , 5.13061 ]
[5.13061 , 5.13061 , 0 ]
unit cell volume : 270.11 Bohr³
atoms : Si₂
pseudopot. family : PseudoFamily("dojo.nc.sr.lda.v0_4_1.standard.upf")
num. electrons : 8
spin polarization : none
temperature : 0.001 Ha
smearing : DFTK.Smearing.FermiDirac()
terms : Kinetic()
AtomicLocal()
AtomicNonlocal()
Ewald(nothing)
PspCorrection()
Hartree()
Xc(lda_x, lda_c_pw)
Entropy()Alternatively the pseudopotentials object also accepts a Dict{Symbol,String}, which provides for each element symbol the filename or identifier of the pseudopotential to be employed, e.g.
path_to_pspfile = PseudoFamily("cp2k.nc.sr.lda.v0_1.semicore.gth")[:Si]
model = model_DFT(system; functionals=LDA(), temperature=1e-3,
pseudopotentials=Dict(:Si => path_to_pspfile))Model(lda_x+lda_c_pw, 3D):
lattice (in Bohr) : [0 , 5.13061 , 5.13061 ]
[5.13061 , 0 , 5.13061 ]
[5.13061 , 5.13061 , 0 ]
unit cell volume : 270.11 Bohr³
atoms : Si₂
atom potentials : ElementPsp(:Si, "/home/runner/.julia/artifacts/966fd9cdcd7dbaba6dc2bf43ee50dd81e63e8837/Si.gth")
ElementPsp(:Si, "/home/runner/.julia/artifacts/966fd9cdcd7dbaba6dc2bf43ee50dd81e63e8837/Si.gth")
num. electrons : 8
spin polarization : none
temperature : 0.001 Ha
smearing : DFTK.Smearing.FermiDirac()
terms : Kinetic()
AtomicLocal()
AtomicNonlocal()
Ewald(nothing)
PspCorrection()
Hartree()
Xc(lda_x, lda_c_pw)
Entropy()We can then discretise such a model and solve:
basis = PlaneWaveBasis(model; Ecut=15, kgrid=[4, 4, 4])
scfres = self_consistent_field(basis, tol=1e-8);n Energy log10(ΔE) log10(Δρ) Diag Δtime
--- --------------- --------- --------- ---- ------
1 -7.921732102656 -0.69 5.5 203ms
2 -7.926132252121 -2.36 -1.22 1.0 203ms
3 -7.926832466457 -3.15 -2.37 2.0 167ms
4 -7.926861263545 -4.54 -2.97 3.0 235ms
5 -7.926861636636 -6.43 -3.34 2.0 172ms
6 -7.926861666703 -7.52 -3.75 1.5 153ms
7 -7.926861679823 -7.88 -4.25 1.4 157ms
8 -7.926861681809 -8.70 -5.17 2.0 168ms
9 -7.926861681859 -10.30 -5.16 2.9 199ms
10 -7.926861681871 -10.94 -5.75 1.0 153ms
11 -7.926861681873 -11.73 -6.54 1.5 161ms
12 -7.926861681873 -13.31 -7.31 2.6 186ms
13 -7.926861681873 -14.35 -7.63 2.2 188ms
14 -7.926861681873 -15.05 -7.74 1.0 149ms
15 -7.926861681873 + -Inf -8.39 1.5 162ms
If we did not want to use AtomsBuilder we could of course use any other package which yields an AbstractSystem object. This includes:
Reading a system using AtomsIO
Read a file using AtomsIO, which directly yields an AbstractSystem.
using AtomsIO
system = load_system("Si.extxyz");Run the LDA calculation:
pseudopotentials = PseudoFamily("cp2k.nc.sr.lda.v0_1.semicore.gth")
model = model_DFT(system; pseudopotentials, functionals=LDA(), 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 Δtime
--- --------------- --------- --------- ---- ------
1 -7.921700011472 -0.69 5.6 264ms
2 -7.926130865682 -2.35 -1.22 1.0 148ms
3 -7.926834023612 -3.15 -2.37 2.0 198ms
4 -7.926861328191 -4.56 -3.02 3.0 207ms
5 -7.926861657226 -6.48 -3.47 2.1 185ms
6 -7.926861675744 -7.73 -4.06 1.6 157ms
7 -7.926861678371 -8.58 -4.09 2.0 171ms
8 -7.926861678865 -9.31 -4.13 1.0 151ms
9 -7.926861681730 -8.54 -4.31 1.0 152ms
10 -7.926861681844 -9.94 -4.50 1.0 148ms
11 -7.926861681848 -11.36 -4.46 1.0 231ms
12 -7.926861681843 + -11.31 -4.37 1.0 879ms
13 -7.926861681837 + -11.17 -4.42 1.0 151ms
14 -7.926861681864 -10.56 -4.93 1.0 148ms
15 -7.926861681864 + -14.27 -5.02 1.0 149ms
16 -7.926861681865 -12.51 -5.02 1.0 149ms
17 -7.926861681858 + -11.18 -4.97 1.0 150ms
18 -7.926861681871 -10.87 -5.66 1.0 148ms
19 -7.926861681873 -11.92 -6.28 1.4 153ms
20 -7.926861681873 + -14.27 -6.18 1.4 153ms
21 -7.926861681873 -13.55 -6.32 1.0 147ms
22 -7.926861681873 -14.01 -6.64 1.0 148ms
23 -7.926861681873 -14.75 -6.87 1.0 158ms
24 -7.926861681873 + -15.05 -7.03 1.0 149ms
25 -7.926861681873 -15.05 -7.43 1.0 150ms
26 -7.926861681873 + -Inf -7.37 1.6 159ms
27 -7.926861681873 -15.05 -7.50 1.0 155ms
28 -7.926861681873 + -14.75 -8.01 1.0 149ms
The same could be achieved using ExtXYZ by system = Atoms(read_frame("Si.extxyz")), since the ExtXYZ.Atoms object is directly AtomsBase-compatible.
Directly setting up a system in AtomsBase
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)
# Now run the LDA calculation:
pseudopotentials = PseudoFamily("cp2k.nc.sr.lda.v0_1.semicore.gth")
model = model_DFT(system; pseudopotentials, functionals=LDA(), temperature=1e-3)
basis = PlaneWaveBasis(model; Ecut=15, kgrid=[4, 4, 4])
scfres = self_consistent_field(basis, tol=1e-4);n Energy log10(ΔE) log10(Δρ) Diag Δtime
--- --------------- --------- --------- ---- ------
1 -7.921695182286 -0.69 5.8 234ms
2 -7.926134762230 -2.35 -1.22 1.0 161ms
3 -7.926836126253 -3.15 -2.37 2.0 156ms
4 -7.926864544567 -4.55 -2.99 3.0 203ms
5 -7.926865061051 -6.29 -3.37 2.0 183ms
6 -7.926865081771 -7.68 -3.84 1.5 139ms
7 -7.926865089427 -8.12 -4.05 1.9 149ms
Obtaining an AbstractSystem from DFTK data
At any point we can also get back the DFTK model as an AtomsBase-compatible AbstractSystem:
second_system = atomic_system(model)FlexibleSystem(Si₂, periodicity = TTT):
cell_vectors : [ 0 5.13 5.13;
5.13 0 5.13;
5.13 5.13 0]u"a₀"
Atom(Si, [ 1.2825, 1.2825, 1.2825]u"a₀")
Atom(Si, [ -1.2825, -1.2825, -1.2825]u"a₀")
Similarly DFTK offers a method to the atomic_system and periodic_system functions (from AtomsBase), which enable a seamless conversion of the usual data structures for setting up DFTK calculations into an AbstractSystem:
lattice = 5.431u"Å" / 2 * [[0 1 1.];
[1 0 1.];
[1 1 0.]];
Si = ElementPsp(:Si, pseudopotentials)
atoms = [Si, Si]
positions = [ones(3)/8, -ones(3)/8]
third_system = atomic_system(lattice, atoms, positions)FlexibleSystem(Si₂, periodicity = TTT):
cell_vectors : [ 0 5.13155 5.13155;
5.13155 0 5.13155;
5.13155 5.13155 0]u"a₀"
Atom(Si, [ 1.28289, 1.28289, 1.28289]u"a₀")
Atom(Si, [-1.28289, -1.28289, -1.28289]u"a₀")