{ "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 / writing files supported by AtomsIO\n", "[AtomsIO](https://github.com/mfherbst/AtomsIO.jl) is a Julia package which supports\n", "reading / writing atomistic structures from / to a large range of file formats.\n", "Supported formats include Crystallographic Information Framework (CIF),\n", "XYZ and extxyz files, ASE / Gromacs / LAMMPS / Amber trajectory files\n", "or input files of various other codes (e.g. Quantum Espresso, VASP, ABINIT, CASTEP, …).\n", "The full list of formatis is available in the\n", "[AtomsIO documentation](https://mfherbst.github.io/AtomsIO.jl/stable).\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", "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 using AtomsIO,\n", "which reads the lattice, atomic positions and initial magnetisation\n", "from the input file and returns it as an\n", "[AtomsBase](https://github.com/JuliaMolSim/AtomsBase.jl) `AbstractSystem`,\n", "the JuliaMolSim community standard for representing atomic systems." ], "metadata": {} }, { "outputs": [ { "output_type": "execute_result", "data": { "text/plain": "FlexibleSystem(Fe₂, periodic = TTT):\n bounding_box : [ 2.86814 0 0;\n 0 2.86814 0;\n 0 0 2.86814]u\"Å\"\n\n Atom(Fe, [ 0, 0, 0]u\"Å\")\n Atom(Fe, [ 1.43407, 1.43407, 0]u\"Å\")\n" }, "metadata": {}, "execution_count": 1 } ], "cell_type": "code", "source": [ "using AtomsIO\n", "system = load_system(\"Fe_afm.pwi\")" ], "metadata": {}, "execution_count": 1 }, { "cell_type": "markdown", "source": [ "Next we attach pseudopotential information, since currently the parser is not\n", "yet capable to read this information from the file." ], "metadata": {} }, { "outputs": [ { "output_type": "execute_result", "data": { "text/plain": "FlexibleSystem(Fe₂, periodic = TTT):\n bounding_box : [ 2.86814 0 0;\n 0 2.86814 0;\n 0 0 2.86814]u\"Å\"\n\n Atom(Fe, [ 0, 0, 0]u\"Å\")\n Atom(Fe, [ 1.43407, 1.43407, 0]u\"Å\")\n" }, "metadata": {}, "execution_count": 2 } ], "cell_type": "code", "source": [ "using DFTK\n", "system = attach_psp(system, Fe=\"hgh/pbe/fe-q16.hgh\")" ], "metadata": {}, "execution_count": 2 }, { "cell_type": "markdown", "source": [ "Finally we make use of DFTK's AtomsBase integration to run the calculation." ], "metadata": {} }, { "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "n Energy log10(ΔE) log10(Δρ) Magnet Diag\n", "--- --------------- --------- --------- ------ ----\n", " 1 -223.7487038464 0.22 -6.320 5.3\n", " 2 -224.1789079735 -0.37 -0.23 -3.273 2.1\n", " 3 -224.2163489078 -1.43 -1.07 -1.804 2.8\n", " 4 -224.2191781775 -2.55 -1.35 -1.346 1.0\n", " 5 -224.2204940441 -2.88 -1.64 -0.916 1.0\n", " 6 -224.2210310690 -3.27 -1.86 -0.656 1.0\n", " 7 -224.2212868289 -3.59 -2.10 -0.381 1.2\n", " 8 -224.2214127270 -3.90 -2.60 -0.063 1.6\n", " 9 -224.2214204926 -5.11 -3.27 -0.022 2.0\n" ] } ], "cell_type": "code", "source": [ "model = model_LDA(system; temperature=0.01)\n", "basis = PlaneWaveBasis(model; Ecut=10, kgrid=(2, 2, 2))\n", "ρ0 = guess_density(basis, system)\n", "scfres = self_consistent_field(basis, tol=1e-3, ρ=ρ0, mixing=KerkerMixing());" ], "metadata": {}, "execution_count": 3 }, { "cell_type": "markdown", "source": [ "## 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.8.4" }, "kernelspec": { "name": "julia-1.8", "display_name": "Julia 1.8.4", "language": "julia" } }, "nbformat": 4 }