Input and output formats

This section provides an overview of the input and output formats supported by DFTK, usually via integration with a third-party library.

Reading input formats supported by ASE

ASE is short for the atomistic simulation environment, a Python package to simplify the process of setting up, running and analysing results from atomistic simulations across different programs. If it is installed it is automatically used by DFTK in order to read a wide range of input files, such as xyz, CIF, input files of various other codes (e.g. Quantum Espresso, VASP, ABINIT, CASTEP, …). The full list of formats can be found in the ASE IO documentation.

As an example we start the calculation of a simple antiferromagnetic iron crystal using a Quantum-Espresso input file, Fe_afm.pwi. From this file the lattice, atomic positions and the initial magnetisation are read. For more details about calculations on magnetic systems using collinear spin, see Collinear spin and magnetic systems.

First we parse the Quantum Espresso input file to DFTK datastructures using the load_atoms, load_positions and load_lattice functions.

In [1]:
using DFTK

qe_input  = "Fe_afm.pwi"
atoms     = load_atoms(qe_input)
positions = load_positions(qe_input)
lattice   = load_lattice(qe_input)
magnetic_moments = load_magnetic_moments(qe_input)
2-element Vector{StaticArraysCore.SVector{3, Float64}}:
 [0.0, 0.0, -9.6]
 [0.0, 0.0, -9.6]

At this point a file of any format supported by ASE could be passed instead, e.g. an xyz file or an ABINIT input file. Behind the scenes ASE takes care to select the right parser and extract the required structural information.

Next we attach the pseudopotential information, since this information is currently not exposed inside the ASE datastructures.

In [2]:
atoms = map(atoms) do el
    @assert el.symbol == :Fe
    ElementPsp(:Fe, psp=load_psp("hgh/pbe/fe-q16.hgh"))

Finally we run the calculation.

In [3]:
model = model_LDA(lattice, atoms, positions; magnetic_moments, temperature=0.01)
basis = PlaneWaveBasis(model; Ecut=10, kgrid=(2, 2, 2))
ρ0 = guess_density(basis, magnetic_moments)
scfres = self_consistent_field(basis, tol=1e-4, ρ=ρ0, mixing=KerkerMixing());
n     Energy            log10(ΔE)   log10(Δρ)   Magnet   Diag
---   ---------------   ---------   ---------   ------   ----
  1   -223.7489425591                    0.22   -6.320    5.3
  2   -224.1788756629       -0.37       -0.23   -3.271    2.1
  3   -224.2163108645       -1.43       -1.07   -1.804    2.7
  4   -224.2185318178       -2.65       -1.34   -1.344    1.9
  5   -224.1979414874   +   -1.69       -1.16   -0.882    2.4
  6   -224.2152069107       -1.76       -1.43   -0.803    2.8
  7   -224.2210751679       -2.23       -1.90   -0.588    1.8
  8   -224.2212378431       -3.79       -2.10   -0.254    1.0
  9   -224.2213393513       -3.99       -2.33   -0.085    1.0
 10   -224.2213784547       -4.41       -2.53   -0.035    1.0

Writing VTK files for visualization

For visualizing the density or the Kohn-Sham orbitals DFTK supports storing the result of an SCF calculations in the form of VTK files. These can afterwards be visualized using tools such as paraview. Using this feature requires the WriteVTK.jl Julia package.

In [4]:
using WriteVTK
save_scfres("iron_afm.vts", scfres; save_ψ=true);

This will save the iron calculation above into the file iron_afm.vts, using save_ψ=true to also include the KS orbitals.

Writing and reading JLD2 files

The full state of a DFTK self-consistent field calculation can be stored on disk in form of an JLD2.jl file. This file can be read from other Julia scripts as well as other external codes supporting the HDF5 file format (since the JLD2 format is based on HDF5).

In [5]:
using JLD2
save_scfres("iron_afm.jld2", scfres);

Since such JLD2 can also be read by DFTK to start or continue a calculation, these can also be used for checkpointing or for transferring results to a different computer. See Saving SCF results on disk and SCF checkpoints for details.

(Cleanup files generated by this notebook.)

In [6]: