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₂, 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.921722336821                   -0.69    5.2    194ms
  2   -7.926138500384       -2.35       -1.22    1.0    143ms
  3   -7.926833450490       -3.16       -2.37    2.0    220ms
  4   -7.926861303769       -4.56       -3.01    3.0    205ms
  5   -7.926861655258       -6.45       -3.45    2.0    195ms
  6   -7.926861674885       -7.71       -4.00    1.9    158ms
  7   -7.926861677830       -8.53       -4.05    1.6    157ms
  8   -7.926861678283       -9.34       -4.08    1.0    234ms
  9   -7.926861681707       -8.47       -4.38    1.0    143ms
 10   -7.926861681850       -9.84       -4.67    1.0    936ms
 11   -7.926861681843   +  -11.17       -4.52    1.1    147ms
 12   -7.926861681862      -10.72       -4.77    1.0    146ms
 13   -7.926861681869      -11.19       -5.25    1.0    146ms
 14   -7.926861681866   +  -11.52       -5.01    1.1    149ms
 15   -7.926861681872      -11.19       -5.83    1.0    146ms
 16   -7.926861681873      -12.80       -6.11    1.2    150ms
 17   -7.926861681873      -13.64       -7.13    1.4    152ms
 18   -7.926861681873      -14.57       -7.23    3.1    190ms
 19   -7.926861681873   +  -14.75       -7.75    1.0    155ms
 20   -7.926861681873      -14.57       -7.87    1.5    156ms
 21   -7.926861681873   +  -14.75       -8.31    1.2    150ms

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.921715864429                   -0.69    5.5    279ms
  2   -7.926139424646       -2.35       -1.22    1.0    144ms
  3   -7.926834721718       -3.16       -2.37    2.0    166ms
  4   -7.926861279054       -4.58       -3.03    2.9    197ms
  5   -7.926861659717       -6.42       -3.50    2.1    205ms
  6   -7.926861676931       -7.76       -4.11    1.8    160ms
  7   -7.926861675138   +   -8.75       -3.96    1.8    160ms
  8   -7.926861681196       -8.22       -4.42    1.0    151ms
  9   -7.926861681810       -9.21       -4.82    1.5    153ms
 10   -7.926861681862      -10.28       -5.26    1.5    155ms
 11   -7.926861681872      -11.03       -5.98    1.5    162ms
 12   -7.926861681873      -12.09       -6.51    2.1    167ms
 13   -7.926861681873      -13.03       -6.78    2.0    176ms
 14   -7.926861681873      -14.15       -7.05    1.1    154ms
 15   -7.926861681873   +    -Inf       -7.74    1.2    153ms
 16   -7.926861681873      -14.57       -7.80    2.4    174ms
 17   -7.926861681873   +  -14.57       -7.88    1.5    161ms
 18   -7.926861681873      -15.05       -8.70    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:
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.921710163366                   -0.69    5.5    212ms
  2   -7.926141446582       -2.35       -1.22    1.0    123ms
  3   -7.926836719149       -3.16       -2.37    2.0    169ms
  4   -7.926864671221       -4.55       -3.00    2.8    183ms
  5   -7.926865053160       -6.42       -3.37    2.0    154ms
  6   -7.926865080272       -7.57       -3.81    1.5    130ms
  7   -7.926865090500       -7.99       -4.17    1.6    138ms

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₀")