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 AtomsBuilder

Feeding 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₂, 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           
                       
                       
                       
                       

By default the atoms of an AbstractSystem employ the bare Coulomb potential. To make calculations feasible for plane-wave DFT we thus attach pseudopotential information, before passing the system to construct a DFT model, discretise and solve:

system = attach_psp(system; Si="hgh/lda/si-q4")

model  = model_DFT(system; 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.921724495937                   -0.69    6.0    301ms
  2   -7.926164046667       -2.35       -1.22    1.0    204ms
  3   -7.926839164153       -3.17       -2.37    1.9    201ms
  4   -7.926861182278       -4.66       -3.04    2.1    224ms
  5   -7.926861650764       -6.33       -3.41    1.9    199ms
  6   -7.926861670497       -7.70       -3.81    1.5    197ms
  7   -7.926861678713       -8.09       -4.09    1.4    182ms
  8   -7.926861681794       -8.51       -5.00    1.4    183ms
  9   -7.926861681861      -10.18       -5.24    2.8    216ms
 10   -7.926861681872      -10.97       -6.30    1.1    178ms
 11   -7.926861681873      -12.06       -6.53    2.9    230ms
 12   -7.926861681873      -14.35       -6.53    1.1    179ms
 13   -7.926861681873      -14.75       -7.56    1.0    176ms
 14   -7.926861681873      -14.75       -7.75    2.4    213ms
 15   -7.926861681873      -15.05       -8.79    1.1    194ms

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_DFT(system; 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.921709782408                   -0.69    5.9    299ms
  2   -7.926166022236       -2.35       -1.22    1.0    201ms
  3   -7.926839331971       -3.17       -2.37    1.9    218ms
  4   -7.926861203061       -4.66       -3.04    2.2    230ms
  5   -7.926861649907       -6.35       -3.40    2.0    242ms
  6   -7.926861669494       -7.71       -3.78    1.5    192ms
  7   -7.926861678637       -8.04       -4.08    1.6    197ms
  8   -7.926861681796       -8.50       -5.01    1.1    188ms
  9   -7.926861681860      -10.19       -5.23    3.1    235ms
 10   -7.926861681872      -10.95       -6.26    1.0    227ms
 11   -7.926861681873      -12.01       -6.56    2.5    239ms
 12   -7.926861681873      -14.35       -6.60    1.2    192ms
 13   -7.926861681873      -14.45       -7.55    1.0    183ms
 14   -7.926861681873   +    -Inf       -7.67    2.5    226ms
 15   -7.926861681873   +  -15.05       -8.78    1.0    234ms

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_DFT(system; 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.921729327372                   -0.69    5.9    318ms
  2   -7.926166726889       -2.35       -1.22    1.0    202ms
  3   -7.926843212869       -3.17       -2.37    1.9    215ms
  4   -7.926864637666       -4.67       -3.05    2.2    247ms
  5   -7.926865066489       -6.37       -3.43    1.9    210ms
  6   -7.926865083113       -7.78       -3.84    1.6    196ms
  7   -7.926865089611       -8.19       -4.06    1.5    189ms

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