{ "cells": [ { "cell_type": "markdown", "source": [ "# AtomsBase integration" ], "metadata": {} }, { "cell_type": "markdown", "source": [ "[AtomsBase.jl](https://github.com/JuliaMolSim/AtomsBase.jl) is a common interface\n", "for representing atomic structures in Julia. DFTK directly supports using such\n", "structures to run a calculation as is demonstrated here." ], "metadata": {} }, { "outputs": [ { "output_type": "execute_result", "data": { "text/plain": "FlexibleSystem(Si₂, AtomsBase.Periodic, box=[[0.0, 5.13, 5.13], [5.13, 0.0, 5.13], [5.13, 5.13, 0.0]]u\"a₀\")" }, "metadata": {}, "execution_count": 1 } ], "cell_type": "code", "source": [ "using DFTK\n", "using AtomsBase\n", "using Unitful\n", "using UnitfulAtomic\n", "\n", "# Construct a system in the AtomsBase world\n", "a = 10.26u\"bohr\" # Silicon lattice constant\n", "lattice = a / 2 * [[0, 1, 1.], # Lattice as vector of vectors\n", " [1, 0, 1.],\n", " [1, 1, 0.]]\n", "atoms = [:Si => ones(3)/8, :Si => -ones(3)/8]\n", "system = periodic_system(atoms, lattice; fractional=true)" ], "metadata": {}, "execution_count": 1 }, { "cell_type": "markdown", "source": [ "System is an AtomsBase-compatible system. To use it in DFTK,\n", "we attach pseudopotentials, construct a DFT model, discretise and solve:" ], "metadata": {} }, { "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "n Energy log10(ΔE) log10(Δρ) Diag\n", "--- --------------- --------- --------- ----\n", " 1 -7.921672534470 -0.69 5.8\n", " 2 -7.926167862025 -2.35 -1.22 1.0\n", " 3 -7.926855247635 -3.16 -2.36 2.1\n", " 4 -7.926865039523 -5.01 -3.14 3.0\n", " 5 -7.926865071010 -7.50 -3.51 2.0\n", " 6 -7.926865085272 -7.85 -3.86 2.0\n", " 7 -7.926865092847 -8.12 -4.76 2.8\n" ] } ], "cell_type": "code", "source": [ "system = attach_psp(system; family=\"hgh\", functional=\"lda\")\n", "\n", "model = model_LDA(system; temperature=1e-3)\n", "basis = PlaneWaveBasis(model; Ecut=15, kgrid=[4, 4, 4])\n", "scfres = self_consistent_field(basis, tol=1e-8);" ], "metadata": {}, "execution_count": 2 }, { "cell_type": "markdown", "source": [ "At any point we can also get back the DFTK model as an\n", "AtomsBase-compatible `AbstractSystem`:" ], "metadata": {} }, { "outputs": [ { "output_type": "execute_result", "data": { "text/plain": "FlexibleSystem(Si₂, AtomsBase.Periodic, box=[[0.0, 5.13, 5.13], [5.13, 0.0, 5.13], [5.13, 5.13, 0.0]]u\"a₀\")" }, "metadata": {}, "execution_count": 3 } ], "cell_type": "code", "source": [ "newsystem = atomic_system(model)" ], "metadata": {}, "execution_count": 3 } ], "nbformat_minor": 3, "metadata": { "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", "version": "1.8.3" }, "kernelspec": { "name": "julia-1.8", "display_name": "Julia 1.8.3", "language": "julia" } }, "nbformat": 4 }