# 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 / writing files supported by AtomsIO

AtomsIO is a Julia package which supports reading / writing atomistic structures from / to a large range of file formats. Supported formats include Crystallographic Information Framework (CIF), XYZ and extxyz files, ASE / Gromacs / LAMMPS / Amber trajectory files or input files of various other codes (e.g. Quantum Espresso, VASP, ABINIT, CASTEP, …). The full list of formatis is available in the AtomsIO documentation.

As an example we start the calculation of a simple antiferromagnetic iron crystal using a Quantum-Espresso input file, Fe_afm.pwi. 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 using AtomsIO, which reads the lattice, atomic positions and initial magnetisation from the input file and returns it as an AtomsBase AbstractSystem, the JuliaMolSim community standard for representing atomic systems.

using AtomsIO
system = load_system("Fe_afm.pwi")
FlexibleSystem(Fe₂, periodic = TTT):
bounding_box      : [ 2.86814        0        0;
0  2.86814        0;
0        0  2.86814]u"Å"

Atom(Fe, [       0,        0,        0]u"Å")
Atom(Fe, [ 1.43407,  1.43407,        0]u"Å")


Next we attach pseudopotential information, since currently the parser is not yet capable to read this information from the file.

using DFTK
system = attach_psp(system, Fe="hgh/pbe/fe-q16.hgh")
FlexibleSystem(Fe₂, periodic = TTT):
bounding_box      : [ 2.86814        0        0;
0  2.86814        0;
0        0  2.86814]u"Å"

Atom(Fe, [       0,        0,        0]u"Å")
Atom(Fe, [ 1.43407,  1.43407,        0]u"Å")


Finally we make use of DFTK's AtomsBase integration to run the calculation.

model = model_LDA(system; temperature=0.01)
basis = PlaneWaveBasis(model; Ecut=10, kgrid=(2, 2, 2))
ρ0 = guess_density(basis, system)
scfres = self_consistent_field(basis, tol=1e-3, ρ=ρ0, mixing=KerkerMixing());
n     Energy            log10(ΔE)   log10(Δρ)   Magnet   Diag   Δtime
---   ---------------   ---------   ---------   ------   ----   ------
1   -223.7492983768                    0.22   -6.321    5.3
2   -224.1789571227       -0.37       -0.23   -3.272    2.1    297ms
3   -224.2163423974       -1.43       -1.07   -1.804    2.8    371ms
4   -224.2191798716       -2.55       -1.35   -1.346    1.0    246ms
5   -224.2204971822       -2.88       -1.64   -0.916    1.0    242ms
6   -224.2210312177       -3.27       -1.86   -0.655    1.0    244ms
7   -224.2212870047       -3.59       -2.10   -0.380    1.4    260ms
8   -224.2214121522       -3.90       -2.60   -0.064    1.2    262ms
9   -224.2214200879       -5.10       -3.28   -0.023    2.2    296ms

## 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.

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).

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.)

rm("iron_afm.vts")
rm("iron_afm.jld2")