{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "Back to the main [Index](index.ipynb) " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Analyzing Lobster output files with AbiPy" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This example shows how to analyze the output files\n", "produced by [Lobster](http://schmeling.ac.rwth-aachen.de/cohp)\n", "\n", "Use \n", "\n", " abiopen.py FILE \n", " \n", "with the `--expose` or `--print` for a command line interface\n", "and `--notebook` to generate a jupyter notebook from a lobster `FILE`.\n", "\n", "Note: The code in this notebook requires abipy >= 0.6\n", "\n", "## Table of Contents\n", "[[back to top](#top)]\n", "\n", "- [How to analyze the COHPCAR file](#How-to-analyze-the-COHPCAR-file)\n", "- [How to analyze the DOSCAR file](#How-to-analyze-the-DOSCAR-file)\n", "- [Analyzing all Lobster output files](#Analyzing-all-Lobster-output-files-with-LobsterAnalyzer)\n", "\n", "Let's start by importing the basic modules needed for this tutorial." ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# Use this at the beginning of your script so that your code will be compatible with python3\n", "from __future__ import print_function, division, 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.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": [ "## How to analyze the COHPCAR file \n", "[[back to top](#top)]" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "COHP: Number of energies: 401, from -14.035 to 6.015 (eV) with E_fermi set 0 (was 2.298)\n", "has_partial_projections: True, nsppol: 1\n", "Number of pairs: 2\n", "[0] Ga@0 --> As@1\n", "[1] As@1 --> Ga@0\n" ] } ], "source": [ "# Path to one of the reference file shipped with AbiPy\n", "import os\n", "dirpath = os.path.join(abidata.dirpath, \"refs\", \"lobster_gaas\")\n", "filename = os.path.join(dirpath, \"GaAs_COHPCAR.lobster.gz\")\n", "\n", "# Open the COHPCAR.lobster file (same API for COOPCAR.lobster)\n", "cohp_file = abilab.abiopen(filename)\n", "print(cohp_file)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To plot the COHP averaged over all atom pairs specified:" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "collapsed": false }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "55792d85cb684021867806dab2a4fbd6", "version_major": 2, "version_minor": 0 }, "text/html": [ "

Failed to display Jupyter Widget of type FigureCanvasNbAgg.

\n", "

\n", " If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean\n", " that the widgets JavaScript is still loading. If this message persists, it\n", " likely means that the widgets JavaScript library is either not installed or\n", " not enabled. See the Jupyter\n", " Widgets Documentation for setup instructions.\n", "

\n", "

\n", " If you're reading this message in another frontend (for example, a static\n", " rendering on GitHub or NBViewer),\n", " it may mean that your frontend doesn't currently support widgets.\n", "

\n" ], "text/plain": [ "FigureCanvasNbAgg()" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "cohp_file.plot(title=\"GaAs COHP\");" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To plot the integrated COHP averaged over all atom pairs:" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "collapsed": false }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "609d3c85ffa04cfe9045faf5c17a8502", "version_major": 2, "version_minor": 0 }, "text/html": [ "

Failed to display Jupyter Widget of type FigureCanvasNbAgg.

\n", "

\n", " If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean\n", " that the widgets JavaScript is still loading. If this message persists, it\n", " likely means that the widgets JavaScript library is either not installed or\n", " not enabled. See the Jupyter\n", " Widgets Documentation for setup instructions.\n", "

\n", "

\n", " If you're reading this message in another frontend (for example, a static\n", " rendering on GitHub or NBViewer),\n", " it may mean that your frontend doesn't currently support widgets.\n", "

\n" ], "text/plain": [ "FigureCanvasNbAgg()" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "cohp_file.plot(what=\"i\", title=\"GaAs integrated COHP\");" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To plot the total overlap for all sites listed in `from_site_index`" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "collapsed": false }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "0c1bf3fbb85c4423844550019d97534c", "version_major": 2, "version_minor": 0 }, "text/html": [ "

Failed to display Jupyter Widget of type FigureCanvasNbAgg.

\n", "

\n", " If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean\n", " that the widgets JavaScript is still loading. If this message persists, it\n", " likely means that the widgets JavaScript library is either not installed or\n", " not enabled. See the Jupyter\n", " Widgets Documentation for setup instructions.\n", "

\n", "

\n", " If you're reading this message in another frontend (for example, a static\n", " rendering on GitHub or NBViewer),\n", " it may mean that your frontend doesn't currently support widgets.\n", "

\n" ], "text/plain": [ "FigureCanvasNbAgg()" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "cohp_file.plot_site_pairs_total(from_site_index=[0, 1], title=\"COHP total overlap for site index 0\");" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To plot partial crystal orbital projections for all sites listed in `from_site_index`:" ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "collapsed": false }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "5bfa88287d8d41dfb581e5061a30b36e", "version_major": 2, "version_minor": 0 }, "text/html": [ "

Failed to display Jupyter Widget of type FigureCanvasNbAgg.

\n", "

\n", " If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean\n", " that the widgets JavaScript is still loading. If this message persists, it\n", " likely means that the widgets JavaScript library is either not installed or\n", " not enabled. See the Jupyter\n", " Widgets Documentation for setup instructions.\n", "

\n", "

\n", " If you're reading this message in another frontend (for example, a static\n", " rendering on GitHub or NBViewer),\n", " it may mean that your frontend doesn't currently support widgets.\n", "

\n" ], "text/plain": [ "FigureCanvasNbAgg()" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "cohp_file.plot_site_pairs_partial(from_site_index=[0, 1], \n", " title=\"COHP with orbital projections from site index 0\", \n", " fontsize=6, tight_layout=True);" ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "collapsed": false }, "outputs": [], "source": [ "#cohp_file.plot_average_pairs(with_site_index=[0]);" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Use `abiopen` to open the MDF:" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## How to analyze the ICOHPLIST file \n", "[[back to top](#top)]" ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Number of pairs: 2\n", "index0 index1 type0 type1 spin average distance n_bonds pair\n", " 0 1 Ga As 0 -4.36062 2.49546 None (0, 1)\n", " 1 0 As Ga 0 -4.36062 2.49546 None (1, 0)\n" ] } ], "source": [ "# Path to one of the AbiPy file\n", "dirpath = os.path.join(abidata.dirpath, \"refs\", \"lobster_gaas\")\n", "filename = os.path.join(dirpath, \"GaAs_ICOHPLIST.lobster.gz\")\n", "\n", "# Open the ICOHPCAR.lobster file.\n", "icohp_file = abilab.abiopen(filename)\n", "print(icohp_file)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## How to analyze the DOSCAR file \n", "[[back to top](#top)]" ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Number of energies: 401, from -14.035 to 6.015 (eV) with E_fermi set to 0 (was 2.298)\n", "nsppol: 1\n", "Number of sites in projected DOS: 2\n", "0 --> {4s, 4p_y, 4p_z, 4p_x}\n", "1 --> {4s, 4p_y, 4p_z, 4p_x}\n" ] } ], "source": [ "dirpath = os.path.join(abidata.dirpath, \"refs\", \"lobster_gaas\")\n", "filename = os.path.join(dirpath, \"GaAs_DOSCAR.lobster.gz\")\n", "\n", "# Open the ICOHPCAR.lobster file.\n", "doscar = abilab.abiopen(filename)\n", "print(doscar)" ] }, { "cell_type": "code", "execution_count": 19, "metadata": { "collapsed": false }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "aa97e9de08264a87af79e799060fd465", "version_major": 2, "version_minor": 0 }, "text/html": [ "

Failed to display Jupyter Widget of type FigureCanvasNbAgg.

\n", "

\n", " If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean\n", " that the widgets JavaScript is still loading. If this message persists, it\n", " likely means that the widgets JavaScript library is either not installed or\n", " not enabled. See the Jupyter\n", " Widgets Documentation for setup instructions.\n", "

\n", "

\n", " If you're reading this message in another frontend (for example, a static\n", " rendering on GitHub or NBViewer),\n", " it may mean that your frontend doesn't currently support widgets.\n", "

\n" ], "text/plain": [ "FigureCanvasNbAgg()" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "doscar.plot();" ] }, { "cell_type": "code", "execution_count": 20, "metadata": { "collapsed": false }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "4c03e19c8a4144ec82fe14f6824e0557", "version_major": 2, "version_minor": 0 }, "text/html": [ "

Failed to display Jupyter Widget of type FigureCanvasNbAgg.

\n", "

\n", " If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean\n", " that the widgets JavaScript is still loading. If this message persists, it\n", " likely means that the widgets JavaScript library is either not installed or\n", " not enabled. See the Jupyter\n", " Widgets Documentation for setup instructions.\n", "

\n", "

\n", " If you're reading this message in another frontend (for example, a static\n", " rendering on GitHub or NBViewer),\n", " it may mean that your frontend doesn't currently support widgets.\n", "

\n" ], "text/plain": [ "FigureCanvasNbAgg()" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "doscar.plot_pdos_site(site_index=[0, 1]);" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Analyzing all Lobster output files with LobsterAnalyzer\n", "[[back to top](#top)]\n", "\n", "Let's assume we have a directory with lobster output files \n", "for COOP, COHP, DOS and we need to produce plots showing all these results altogether.\n", "In this case, one can use the `LobsterAnalyzer` object and initialize it from the directory\n", "containing the output files." ] }, { "cell_type": "code", "execution_count": 21, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "================================= COOP File =================================\n", "Name: GaAs_COOPCAR.lobster.gz\n", "Directory: /Users/gmatteo/git_repos/abipy/abipy/data/refs/lobster_gaas\n", "Size: 23.04 kb\n", "Access Time: Mon Aug 6 01:15:08 2018\n", "Modification Time: Sat Jul 14 00:27:22 2018\n", "Change Time: Sat Jul 14 00:27:22 2018\n", "\n", "COOP: Number of energies: 401, from -14.035 to 6.015 (eV) with E_fermi set 0 (was 2.298)\n", "has_partial_projections: True, nsppol: 1\n", "Number of pairs: 2\n", "[0] Ga@0 --> As@1\n", "[1] As@1 --> Ga@0\n", "\n", "================================= COHP File =================================\n", "Name: GaAs_COHPCAR.lobster.gz\n", "Directory: /Users/gmatteo/git_repos/abipy/abipy/data/refs/lobster_gaas\n", "Size: 24.06 kb\n", "Access Time: Mon Aug 6 01:15:08 2018\n", "Modification Time: Sat Jul 14 00:27:22 2018\n", "Change Time: Sat Jul 14 00:27:22 2018\n", "\n", "COHP: Number of energies: 401, from -14.035 to 6.015 (eV) with E_fermi set 0 (was 2.298)\n", "has_partial_projections: True, nsppol: 1\n", "Number of pairs: 2\n", "[0] Ga@0 --> As@1\n", "[1] As@1 --> Ga@0\n", "\n", "============================== ICHOHPLIST File ==============================\n", "Number of pairs: 2\n", "index0 index1 type0 type1 spin average distance n_bonds pair\n", " 0 1 Ga As 0 -4.36062 2.49546 None (0, 1)\n", " 1 0 As Ga 0 -4.36062 2.49546 None (1, 0)\n", "\n", "=============================== Lobster DOSCAR ===============================\n", "Number of energies: 401, from -14.035 to 6.015 (eV) with E_fermi set to 0 (was 2.298)\n", "nsppol: 1\n", "Number of sites in projected DOS: 2\n", "0 --> {4s, 4p_y, 4p_z, 4p_x}\n", "1 --> {4s, 4p_y, 4p_z, 4p_x}\n", "\n" ] } ], "source": [ "dirpath = os.path.join(abidata.dirpath, \"refs\", \"lobster_gaas\")\n", "\n", "# Open the all the lobster files produced in directory dirpath\n", "# with the (optional) prefix GaAs_\n", "lobana = abilab.LobsterAnalyzer.from_dir(dirpath, prefix=\"GaAs_\")\n", "print(lobana.to_string(verbose=1))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To plot COOP + COHP + DOS, use:" ] }, { "cell_type": "code", "execution_count": 22, "metadata": { "collapsed": false }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "af126fe5d7574874884d8986dc6d9eba", "version_major": 2, "version_minor": 0 }, "text/html": [ "

Failed to display Jupyter Widget of type FigureCanvasNbAgg.

\n", "

\n", " If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean\n", " that the widgets JavaScript is still loading. If this message persists, it\n", " likely means that the widgets JavaScript library is either not installed or\n", " not enabled. See the Jupyter\n", " Widgets Documentation for setup instructions.\n", "

\n", "

\n", " If you're reading this message in another frontend (for example, a static\n", " rendering on GitHub or NBViewer),\n", " it may mean that your frontend doesn't currently support widgets.\n", "

\n" ], "text/plain": [ "FigureCanvasNbAgg()" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "lobana.plot(title=\"COOP + COHP + DOS\");" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To plot COHP for all sites in from_site_index and Lobster DOS:" ] }, { "cell_type": "code", "execution_count": 23, "metadata": { "collapsed": false }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "e7a9326f168a40f2ae63d4ec75f0ad30", "version_major": 2, "version_minor": 0 }, "text/html": [ "

Failed to display Jupyter Widget of type FigureCanvasNbAgg.

\n", "

\n", " If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean\n", " that the widgets JavaScript is still loading. If this message persists, it\n", " likely means that the widgets JavaScript library is either not installed or\n", " not enabled. See the Jupyter\n", " Widgets Documentation for setup instructions.\n", "

\n", "

\n", " If you're reading this message in another frontend (for example, a static\n", " rendering on GitHub or NBViewer),\n", " it may mean that your frontend doesn't currently support widgets.\n", "

\n" ], "text/plain": [ "FigureCanvasNbAgg()" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "lobana.plot_coxp_with_dos(from_site_index=[0, 1]);" ] }, { "cell_type": "code", "execution_count": 24, "metadata": { "collapsed": false }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "400119111b5a47c88157d038e0f77c08", "version_major": 2, "version_minor": 0 }, "text/html": [ "

Failed to display Jupyter Widget of type FigureCanvasNbAgg.

\n", "

\n", " If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean\n", " that the widgets JavaScript is still loading. If this message persists, it\n", " likely means that the widgets JavaScript library is either not installed or\n", " not enabled. See the Jupyter\n", " Widgets Documentation for setup instructions.\n", "

\n", "

\n", " If you're reading this message in another frontend (for example, a static\n", " rendering on GitHub or NBViewer),\n", " it may mean that your frontend doesn't currently support widgets.\n", "

\n" ], "text/plain": [ "FigureCanvasNbAgg()" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# Plot orbital projections.\n", "lobana.plot_coxp_with_dos(from_site_index=[0], with_orbitals=True);" ] }, { "cell_type": "code", "execution_count": 25, "metadata": { "collapsed": true }, "outputs": [], "source": [ "#lobana.plot_with_ebands(ebands=\"out_GSR.nc\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "For a command line interface, use: `abiview.py lobster .`.\n", "Use the `--expose` option to generate plots automatically.\n", "
\n", "\n", "Back to the main [Index](index.ipynb)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python [default]", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.1" }, "latex_envs": { "bibliofile": "biblio.bib", "cite_by": "apalike", "current_citInitial": 1, "eqLabelWithNumbers": true, "eqNumInitial": 0 } }, "nbformat": 4, "nbformat_minor": 2 }