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
Feeding an AtomsBase AbstractSystem to DFTK
In this example we construct a silicon system using the ase.build.bulk
routine from the atomistic simulation environment (ASE), which is exposed by ASEconvert as an AtomsBase AbstractSystem
.
# Construct bulk system and convert to an AbstractSystem
using ASEconvert
system_ase = ase.build.bulk("Si")
system = pyconvert(AbstractSystem, system_ase)
FlexibleSystem(Si₂, periodic = TTT):
bounding_box : [ 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"Å")
Si
Si
To use an AbstractSystem in DFTK, we attach pseudopotentials, construct a DFT model, discretise and solve:
system = attach_psp(system; Si="hgh/lda/si-q4")
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 Δtime
--- --------------- --------- --------- ---- ------
1 -7.921712820750 -0.69 6.1 207ms
2 -7.926166386916 -2.35 -1.22 1.0 153ms
3 -7.926839452802 -3.17 -2.37 1.9 189ms
4 -7.926861170761 -4.66 -3.04 2.1 181ms
5 -7.926861652734 -6.32 -3.41 2.0 166ms
6 -7.926861671339 -7.73 -3.84 1.5 153ms
7 -7.926861678515 -8.14 -4.07 1.2 146ms
8 -7.926861681792 -8.48 -4.92 1.2 156ms
9 -7.926861681858 -10.18 -5.18 2.4 170ms
10 -7.926861681871 -10.86 -6.16 1.0 143ms
11 -7.926861681873 -11.91 -6.39 2.6 184ms
12 -7.926861681873 -14.75 -6.23 1.1 151ms
13 -7.926861681873 -14.21 -7.55 1.0 160ms
┌ Warning: Eigensolver not converged
│ n_iter =
│ 8-element Vector{Int64}:
│ 2
│ 2
│ 2
│ 2
│ 4
│ 3
│ 3
│ 4
└ @ DFTK ~/work/DFTK.jl/DFTK.jl/src/scf/self_consistent_field.jl:76
14 -7.926861681873 + -Inf -7.68 2.8 228ms
15 -7.926861681873 -14.57 -8.46 1.4 149ms
If we did not want to use ASE we could of course use any other package which yields an AbstractSystem object. This includes:
Reading a system using AtomsIO
using AtomsIO
# Read a file using [AtomsIO](https://github.com/mfherbst/AtomsIO.jl),
# which directly yields an AbstractSystem.
system = load_system("Si.extxyz")
# Now run the LDA calculation:
system = attach_psp(system; Si="hgh/lda/si-q4")
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 Δtime
--- --------------- --------- --------- ---- ------
1 -7.921728177321 -0.69 5.9 219ms
2 -7.926164589789 -2.35 -1.22 1.0 151ms
3 -7.926837907342 -3.17 -2.37 1.9 170ms
4 -7.926861184366 -4.63 -3.01 2.1 196ms
5 -7.926861632368 -6.35 -3.33 1.9 162ms
6 -7.926861662767 -7.52 -3.66 1.6 151ms
7 -7.926861679527 -7.78 -4.18 1.2 144ms
8 -7.926861681804 -8.64 -5.20 1.8 170ms
9 -7.926861681864 -10.22 -5.25 3.0 188ms
10 -7.926861681872 -11.09 -6.48 1.0 142ms
11 -7.926861681873 -12.43 -6.80 3.0 190ms
12 -7.926861681873 -14.75 -7.58 1.4 152ms
13 -7.926861681873 -14.27 -7.88 2.5 171ms
14 -7.926861681873 + -14.35 -9.10 1.0 154ms
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:
system = attach_psp(system; Si="hgh/lda/si-q4")
model = model_LDA(system; 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.921708371401 -0.69 5.9 249ms
2 -7.926166463661 -2.35 -1.22 1.0 160ms
3 -7.926843131858 -3.17 -2.37 1.9 195ms
4 -7.926864612531 -4.67 -3.05 2.4 202ms
5 -7.926865067402 -6.34 -3.43 2.0 190ms
6 -7.926865083973 -7.78 -3.87 1.4 153ms
7 -7.926865089343 -8.27 -4.04 1.5 155ms
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₂, periodic = TTT):
bounding_box : [ 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₀")
Si
Si
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; psp=load_psp("hgh/lda/Si-q4"))
atoms = [Si, Si]
positions = [ones(3)/8, -ones(3)/8]
third_system = atomic_system(lattice, atoms, positions)
FlexibleSystem(Si₂, periodic = TTT):
bounding_box : [ 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₀")
Si
Si