{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "Back to the main [Index](index.ipynb) " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Post-processing tools for electron band energies\n", "\n", "In this notebook we discuss how to plot electron band structures and density of states (DOS) \n", "using the netcdf files produced by Abinit. \n", "\n", "For the tutorial, we will use the netcdf files shipped with AbiPy. \n", "The function `abidata.ref_file` returns the absolute path of the reference file. \n", "In your scripts, you have to replace `data.ref_file(\"abipy_filename\")` with a string giving\n", "the location of your netcdf file.\n", " \n", "Alteratively, one can use the `abiopen.py` script to open the file inside the shell with the syntax:\n", "\n", " abiopen.py out_GSR.nc \n", " \n", "This command will start the ipython interpreter so that one can interact directly \n", "with the `GsrFile` object (named `abifile` inside ipython).\n", "To generate a jupyter notebook use:\n", "\n", " abiopen.py out_GSR.nc -nb\n", " \n", "For a quick visualization of the data, use the `--expose` options:\n", "\n", " abiopen.py out_GSR.nc -e\n", " \n", "\n", "## Table of Contents\n", "[[back to top](#top)]\n", "\n", "- [The GSR File](#The-GSR-File)\n", "- [Plotting band structures](#Plotting-band-structures)\n", "- [DOS with the Gaussian technique](#DOS-with-the-Gaussian-technique)\n", "- [Joint density of states](#Joint-density-of-states)\n", "- [Plotting the Fermi surface](#Plotting-the-Fermi-surface)\n", "- [Analyzing multiple GSR files with robots](#Analyzing-multiple-GSR-files-with-robots)" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "# Use this at the beginning of your script so that your code will be compatible with python3\n", "from __future__ import division, print_function, unicode_literals\n", "\n", "import warnings \n", "warnings.filterwarnings(\"ignore\") # Ignore warnings\n", "\n", "from abipy import abilab\n", "abilab.enable_notebook() # This line tells AbiPy we are running inside a notebook\n", "# Import abipy reference data.\n", "import abipy.data as abidata\n", "\n", "# This line configures matplotlib to show figures embedded in the notebook.\n", "# Replace `inline` with `notebook` in classic notebook\n", "%matplotlib inline \n", "\n", "# Option available in jupyterlab. See https://github.com/matplotlib/jupyter-matplotlib\n", "#%matplotlib widget " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## The GSR File\n", "[[back to top](#top)]\n", "\n", "The `GSR` file (mnemonics: Ground-State Results) is a netcdf file with the \n", "results produced by SCF or NSCF ground-state calculations \n", "(band energies, forces, energies, stress tensor).\n", "To open a `GSR` file, use the `abiopen` function defined in `abilab`:" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "gsr = abilab.abiopen(abidata.ref_file(\"si_scf_GSR.nc\"))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The gsr object has a `Structure`:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Full Formula (Si2)\n", "Reduced Formula: Si\n", "abc : 3.866975 3.866975 3.866975\n", "angles: 60.000000 60.000000 60.000000\n", "Sites (2)\n", " # SP a b c cartesian_forces\n", "--- ---- ---- ---- ---- -----------------------------------------------------------\n", " 0 Si 0 0 0 [-5.89948306e-27 -1.93366149e-27 2.91016904e-27] eV ang^-1\n", " 1 Si 0.25 0.25 0.25 [ 5.89948306e-27 1.93366149e-27 -2.91016904e-27] eV ang^-1\n", "\n", "Abinit Spacegroup: spgid: 227, num_spatial_symmetries: 48, has_timerev: True, symmorphic: True\n" ] } ], "source": [ "print(gsr.structure)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "and an `ElectronBands` object with the band energies, the occupation factors, the list of k-points:" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "================================= Structure =================================\n", "Full Formula (Si2)\n", "Reduced Formula: Si\n", "abc : 3.866975 3.866975 3.866975\n", "angles: 60.000000 60.000000 60.000000\n", "Sites (2)\n", " # SP a b c cartesian_forces\n", "--- ---- ---- ---- ---- -----------------------------------------------------------\n", " 0 Si 0 0 0 [-5.89948306e-27 -1.93366149e-27 2.91016904e-27] eV ang^-1\n", " 1 Si 0.25 0.25 0.25 [ 5.89948306e-27 1.93366149e-27 -2.91016904e-27] eV ang^-1\n", "\n", "Abinit Spacegroup: spgid: 227, num_spatial_symmetries: 48, has_timerev: True, symmorphic: True\n", "\n", "Number of electrons: 8.0, Fermi level: 5.598 (eV)\n", "nsppol: 1, nkpt: 29, mband: 8, nspinor: 1, nspden: 1\n", "smearing scheme: none (occopt 1), tsmear_eV: 0.272\n", "Direct gap:\n", " Energy: 2.532 (eV)\n", " Initial state: spin: 0, kpt: [+0.000, +0.000, +0.000], weight: 0.002, band: 3, eig: 5.598, occ: 2.000\n", " Final state: spin: 0, kpt: [+0.000, +0.000, +0.000], weight: 0.002, band: 4, eig: 8.130, occ: 0.000\n", "Fundamental gap:\n", " Energy: 0.562 (eV)\n", " Initial state: spin: 0, kpt: [+0.000, +0.000, +0.000], weight: 0.002, band: 3, eig: 5.598, occ: 2.000\n", " Final state: spin: 0, kpt: [+0.375, +0.375, +0.000], weight: 0.012, band: 4, eig: 6.161, occ: 0.000\n", "Bandwidth: 11.856 (eV)\n", "Valence maximum located at:\n", " spin: 0, kpt: [+0.000, +0.000, +0.000], weight: 0.002, band: 3, eig: 5.598, occ: 2.000\n", "Conduction minimum located at:\n", " spin: 0, kpt: [+0.375, +0.375, +0.000], weight: 0.012, band: 4, eig: 6.161, occ: 0.000\n", "\n", "TIP: Call set_fermie_to_vbm() to set the Fermi level to the VBM if this is a non-magnetic semiconductor\n", "\n" ] } ], "source": [ "print(gsr.ebands)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "