{ "cells": [ { "cell_type": "markdown", "source": [ "# Input and output formats" ], "metadata": {} }, { "cell_type": "markdown", "source": [ "This section provides an overview of the input and output formats\n", "supported by DFTK, usually via integration with a third-party library.\n", "\n", "## Reading input formats supported by ASE\n", "ASE is short for the\n", "[atomistic simulation environment](https://wiki.fysik.dtu.dk/ase/index.html),\n", "a Python package to simplify the process of setting up, running and\n", "analysing results from atomistic simulations across different programs.\n", "If it is installed it is automatically used by DFTK in order to read a wide range\n", "of input files, such as xyz, CIF, input files of various other codes\n", "(e.g. Quantum Espresso, VASP, ABINIT, CASTEP, ...).\n", "The full list of formats\n", "can be found in the [ASE IO documentation](https://wiki.fysik.dtu.dk/ase/ase/io/io.html).\n", "\n", "As an example we start the calculation of a simple antiferromagnetic iron crystal\n", "using a Quantum-Espresso input file, [Fe_afm.pwi](Fe_afm.pwi).\n", "From this file the lattice, atomic positions and the initial magnetisation are read.\n", "For more details about calculations on magnetic systems\n", "using collinear spin, see Collinear spin and magnetic systems.\n", "\n", "First we parse the Quantum Espresso input file to DFTK datastructures:" ], "metadata": {} }, { "outputs": [ { "output_type": "execute_result", "data": { "text/plain": "2-element Vector{StaticArrays.SVector{3, Float64}}:\n [0.0, 0.0, -9.6]\n [0.0, 0.0, -9.6]" }, "metadata": {}, "execution_count": 1 } ], "cell_type": "code", "source": [ "using DFTK\n", "\n", "qe_input = \"Fe_afm.pwi\"\n", "atoms = load_atoms(qe_input)\n", "positions = load_positions(qe_input)\n", "lattice = load_lattice(qe_input)\n", "magnetic_moments = load_magnetic_moments(qe_input)" ], "metadata": {}, "execution_count": 1 }, { "cell_type": "markdown", "source": [ "At this point a file of any format supported by ASE could be passed instead,\n", "e.g. an `xyz` file or an ABINIT input file. Behind the scenes ASE takes care\n", "to select the right parser and extract the required structural information." ], "metadata": {} }, { "cell_type": "markdown", "source": [ "Next we attach the pseudopotential information, since this information is currently\n", "not exposed inside the ASE datastructures.\n", "See Creating slabs with ASE for more details." ], "metadata": {} }, { "outputs": [], "cell_type": "code", "source": [ "atoms = map(atoms) do el\n", " @assert el.symbol == :Fe\n", " ElementPsp(:Fe, psp=load_psp(\"hgh/pbe/fe-q16.hgh\"))\n", "end;" ], "metadata": {}, "execution_count": 2 }, { "cell_type": "markdown", "source": [ "Finally we run the calculation." ], "metadata": {} }, { "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "n Energy log10(ΔE) log10(Δρ) Magnet Diag\n", "--- --------------- --------- --------- ------ ----\n", " 1 -223.7481251797 0.22 -6.320 4.8\n", " 2 -224.1772718812 -0.37 -0.23 -3.269 1.7\n", " 3 -224.2162787092 -1.41 -1.07 -1.801 2.7\n", " 4 -224.2192866470 -2.52 -1.36 -1.353 2.2\n", " 5 -224.2205739132 -2.89 -1.67 -0.898 1.3\n", " 6 -224.2199931366 + -3.24 -1.71 -0.636 1.0\n", " 7 -224.2197562215 + -3.63 -1.70 -0.554 1.6\n", " 8 -224.2212925914 -2.81 -2.13 -0.322 1.0\n", " 9 -224.2214136286 -3.92 -2.63 -0.048 1.1\n", " 10 -224.2214166997 -5.51 -2.96 -0.009 1.1\n" ] } ], "cell_type": "code", "source": [ "model = model_LDA(lattice, atoms, positions; magnetic_moments, temperature=0.01)\n", "basis = PlaneWaveBasis(model; Ecut=10, kgrid=(2, 2, 2))\n", "ρ0 = guess_density(basis, magnetic_moments)\n", "scfres = self_consistent_field(basis, tol=1e-4, ρ=ρ0, mixing=KerkerMixing());" ], "metadata": {}, "execution_count": 3 }, { "cell_type": "markdown", "source": [ "!!! note \"DFTK and ASE\"\n", " DFTK also supports using ASE to setup a calculation\n", " and provides two-way conversion routines between key DFTK\n", " and ASE datastructures. See Creating slabs with ASE for details.\n", "\n", "## Writing VTK files for visualization\n", "For visualizing the density or the Kohn-Sham orbitals DFTK supports storing\n", "the result of an SCF calculations in the form of VTK files.\n", "These can afterwards be visualized using tools such\n", "as [paraview](https://www.paraview.org/).\n", "Using this feature requires\n", "the [WriteVTK.jl](https://github.com/jipolanco/WriteVTK.jl/) Julia package." ], "metadata": {} }, { "outputs": [], "cell_type": "code", "source": [ "using WriteVTK\n", "save_scfres(\"iron_afm.vts\", scfres; save_ψ=true);" ], "metadata": {}, "execution_count": 4 }, { "cell_type": "markdown", "source": [ "This will save the iron calculation above into the file `iron_afm.vts`,\n", "using `save_ψ=true` to also include the KS orbitals." ], "metadata": {} }, { "cell_type": "markdown", "source": [ "## Writing and reading JLD2 files\n", "The full state of a DFTK self-consistent field calculation can be\n", "stored on disk in form of an [JLD2.jl](https://github.com/JuliaIO/JLD2.jl) file.\n", "This file can be read from other Julia scripts\n", "as well as other external codes supporting the HDF5 file format\n", "(since the JLD2 format is based on HDF5)." ], "metadata": {} }, { "outputs": [], "cell_type": "code", "source": [ "using JLD2\n", "save_scfres(\"iron_afm.jld2\", scfres);" ], "metadata": {}, "execution_count": 5 }, { "cell_type": "markdown", "source": [ "Since such JLD2 can also be read by DFTK to start or continue a calculation,\n", "these can also be used for checkpointing or for transferring results\n", "to a different computer.\n", "See Saving SCF results on disk and SCF checkpoints for details." ], "metadata": {} }, { "cell_type": "markdown", "source": [ "(Cleanup files generated by this notebook)" ], "metadata": {} }, { "outputs": [], "cell_type": "code", "source": [ "rm(\"iron_afm.vts\")\n", "rm(\"iron_afm.jld2\")" ], "metadata": {}, "execution_count": 6 } ], "nbformat_minor": 3, "metadata": { "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", "version": "1.7.3" }, "kernelspec": { "name": "julia-1.7", "display_name": "Julia 1.7.3", "language": "julia" } }, "nbformat": 4 }