{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "# useful to autoreload the module without restarting the kernel\n", "%load_ext autoreload\n", "%autoreload 2" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "from mppi import Parsers as P" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Tutorial of the PwParser class" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This tutorial describes the usage of the class PwParser of mppi used to extract information for the XML output file data-file-schema produced\n", "by pw." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Parse of a output file of Silicon " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "__Follow the tutorial for the QeCalculator to produce the xml file used by the PwParser.__\n", "\n", "The class is initialized by specifying the name of the xml file including its relative path " ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Parse file : QeCalculator_test/ecut_40.save/data-file-schema.xml\n" ] } ], "source": [ "results = P.PwParser('QeCalculator_test/ecut_40.save/data-file-schema.xml')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "When the object is initialized several attributes are set, for instance" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'Hartree atomic units'" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "results.units" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "2\n", "{'Si': ['2.808600000000000e1', 'Si.pbe-mt_fhi.UPF']}\n", "[['Si', [-1.2875, 1.2875, 1.2875]], ['Si', [1.2875, -1.2875, -1.2875]]]\n", "4\n", "32\n", "2\n" ] } ], "source": [ "print(results.natoms)\n", "print(results.atomic_species)\n", "print(results.atomic_positions)\n", "print(results.nbands)\n", "print(results.nkpoints)\n", "print(results.spin_degen)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can print the ks energies and weight for each kpoint" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[0. 0. 0.] [-0.21237932 0.22480586 0.22480586 0.22480586] [0.00925926]\n", "[-0.16666667 0.16666667 -0.16666667] [-0.19919102 0.13751175 0.20843984 0.20843984] [0.05555556]\n", "[-0.33333333 0.33333333 -0.33333333] [-0.16220083 0.02987301 0.18835642 0.18835642] [0.05555556]\n", "[ 0.5 -0.5 0.5] [-0.12757113 -0.02957086 0.18109825 0.18109825] [0.02777778]\n", "[0. 0.33333333 0. ] [-0.19470782 0.14932662 0.18151751 0.18151751] [0.05555556]\n", "[-0.16666667 0.5 -0.16666667] [-0.16499801 0.06224724 0.15213876 0.16134166] [0.11111111]\n", "[ 0.66666667 -0.33333333 0.66666667] [-0.12170161 -0.01655811 0.1235651 0.16017894] [0.11111111]\n", "[ 0.5 -0.16666667 0.5 ] [-0.13567139 0.00519533 0.11383623 0.1775689 ] [0.11111111]\n", "[3.33333333e-01 2.77555756e-17 3.33333333e-01] [-0.17775389 0.08840259 0.137224 0.20418049] [0.05555556]\n", "[0. 0.66666667 0. ] [-0.1429486 0.04085118 0.13689062 0.13689062] [0.05555556]\n", "[ 0.83333333 -0.16666667 0.83333333] [-0.10058122 -0.01575679 0.09290269 0.13189392] [0.11111111]\n", "[ 6.66666667e-01 -5.55111512e-17 6.66666667e-01] [-0.09353762 -0.02311024 0.06458375 0.1479812 ] [0.05555556]\n", "[ 0. -1. 0.] [-0.06133252 -0.06133252 0.1210312 0.1210312 ] [0.02777778]\n", "[ 0.66666667 -0.33333333 1. ] [-0.12894983 0.01788475 0.09513755 0.14145801] [0.11111111]\n", "[ 0.5 -0.16666667 0.83333333] [-0.09319151 -0.02566662 0.07905522 0.12455972] [0.11111111]\n", "[-0.33333333 -1. 0. ] [-0.05705807 -0.05705807 0.0924765 0.09247651] [0.11111111]\n", "[-0.16666667 0.16666667 0.16666667] [-0.19919102 0.13751175 0.20843984 0.20843984] [0.01851852]\n", "[-0.33333333 0.33333333 0.33333333] [-0.16220083 0.02987301 0.18835642 0.18835642] [0.01851852]\n", "[ 0.5 -0.5 -0.5] [-0.12757113 -0.02957086 0.18109825 0.18109825] [0.00925926]\n", "[ 0.16666667 -0.16666667 0.5 ] [-0.16499801 0.06224724 0.15213876 0.16134165] [0.05555556]\n", "[-0.16666667 0.16666667 0.5 ] [-0.16499801 0.06224724 0.15213877 0.16134165] [0.05555556]\n", "[-0.66666667 0.66666667 -0.33333333] [-0.12170161 -0.01655811 0.1235651 0.16017894] [0.05555556]\n", "[ 0.66666667 -0.66666667 -0.33333333] [-0.12170161 -0.01655811 0.1235651 0.16017894] [0.05555556]\n", "[-0.5 0.5 -0.16666667] [-0.13567139 0.00519533 0.11383624 0.1775689 ] [0.05555556]\n", "[ 0.5 -0.5 -0.16666667] [-0.13567139 0.00519533 0.11383624 0.1775689 ] [0.05555556]\n", "[-0.33333333 0.33333333 0. ] [-0.17775389 0.08840259 0.137224 0.20418049] [0.05555556]\n", "[-0.83333333 0.83333333 -0.16666667] [-0.10058122 -0.01575679 0.09290269 0.13189392] [0.05555556]\n", "[ 0.83333333 -0.83333333 -0.16666667] [-0.10058122 -0.01575679 0.0929027 0.13189392] [0.05555556]\n", "[-0.66666667 0.66666667 0. ] [-0.09353762 -0.02311024 0.06458376 0.14798119] [0.05555556]\n", "[-0.66666667 1. -0.33333333] [-0.12894983 0.01788475 0.09513755 0.14145801] [0.11111111]\n", "[0.5 0.83333333 0.16666667] [-0.09319151 -0.02566662 0.07905522 0.12455972] [0.05555556]\n", "[ 0.5 -0.83333333 -0.16666667] [-0.09319151 -0.02566662 0.07905522 0.12455972] [0.05555556]\n" ] } ], "source": [ "for k,e,w in zip(results.kpoints,results.evals,results.weights):\n", " print(k,e,w)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "There are also several get methods, for instance" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "6.117279040435398" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "results.get_fermi()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The method get_evals return an array with the ks energies for each kpoint. The energies are expressed in eV and the \n", "energy of VBM is used as reference. A gap, both direct or indirect, can be set. In this case the energies of the empty ks states is\n", "shifted. This procedure __does not__ update the occupation levels of the empty states" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "There are no empty bands. `Set gap` has not been applied\n" ] }, { "data": { "text/plain": [ "array([-1.18964146e+01, -3.99369533e-08, -1.83300486e-09, 0.00000000e+00])" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "results.get_evals(set_gap=1.2)[0]" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "There are no empty states. Gap cannot be computed.\n" ] } ], "source": [ "results.get_gap()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We test the PwParser using a nscf output file, in this case empty bands are present and the gap can be computed" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Parse file : QeCalculator_test/bands_12.save/data-file-schema.xml\n" ] } ], "source": [ "result_nscf = P.PwParser('QeCalculator_test/bands_12.save/data-file-schema.xml')" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([1., 1., 1., 1., 0., 0., 0., 0., 0., 0., 0., 0.])" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "result_nscf.occupations[0]" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Indirect gap system\n", "===================\n", "Gap : 0.7363567574170764 eV\n", "Direct gap : 2.5651333558109854 eV\n" ] }, { "data": { "text/plain": [ "{'gap': 0.7363567574170764,\n", " 'direct_gap': 2.5651333558109854,\n", " 'position_cbm': 12,\n", " 'positon_vbm': 0}" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "result_nscf.get_gap()" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Apply a scissor of 0.43486664418901455 eV\n" ] }, { "data": { "text/plain": [ "array([-1.18964110e+01, -9.74240383e-07, -9.74234497e-07, 0.00000000e+00,\n", " 3.00000000e+00, 3.00000056e+00, 3.00000056e+00, 3.58353139e+00,\n", " 8.17161688e+00, 8.17161688e+00, 8.29564293e+00, 1.16527216e+01])" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "result_nscf.get_evals(set_direct_gap=3.0)[0]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "we see that in this case the energy of the 5-th states has been shift to 3 eV to implement the set_direct_gap requirement. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "It is also possible to add an explicit scissor to shift the empty bands" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Apply a scissor of 1.0 eV\n" ] }, { "data": { "text/plain": [ "array([-1.18964110e+01, -9.74240383e-07, -9.74234497e-07, 0.00000000e+00,\n", " 3.56513336e+00, 3.56513391e+00, 3.56513391e+00, 4.14866474e+00,\n", " 8.73675023e+00, 8.73675023e+00, 8.86077629e+00, 1.22178550e+01])" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "result_nscf.get_evals(set_scissor=1.)[0]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We compute the transition energies from the full to empty bands. Here we show the transition\n", "for the first k point" ] }, { "cell_type": "code", "execution_count": 68, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Apply a scissor of 0.43486664418901455 eV\n" ] }, { "data": { "text/plain": [ "array([14.89641099, 14.89641154, 14.89641154, 15.47994237, 20.06802786,\n", " 20.06802786, 20.19205392, 23.54913261, 3.00000097, 3.00000153,\n", " 3.00000153, 3.58353236, 8.17161785, 8.17161785, 8.29564391,\n", " 11.6527226 , 3.00000097, 3.00000153, 3.00000153, 3.58353236,\n", " 8.17161785, 8.17161785, 8.29564391, 11.6527226 , 3. ,\n", " 3.00000056, 3.00000056, 3.58353139, 8.17161688, 8.17161688,\n", " 8.29564293, 11.65272162])" ] }, "execution_count": 68, "metadata": {}, "output_type": "execute_result" } ], "source": [ "result_nscf.get_transitions(set_direct_gap=3.0)[0]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Parse of a Graphene output file" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "__Run the Analysis_BandStructure notebook to produce the xml file used by the PwParser.__\n", "\n", "We parse a graphene output file to test if systems without a gap are correctly parsed." ] }, { "cell_type": "code", "execution_count": 69, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Parse file : Pw_bands/graphene_nscf.save/data-file-schema.xml\n" ] } ], "source": [ "results_gra = P.PwParser('Pw_bands/graphene_nscf.save/data-file-schema.xml')" ] }, { "cell_type": "code", "execution_count": 70, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'smearing'" ] }, "execution_count": 70, "metadata": {}, "output_type": "execute_result" } ], "source": [ "results_gra.occupations_kind" ] }, { "cell_type": "code", "execution_count": 71, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([1.00000000e+00, 1.00000000e+00, 1.00000000e+00, 1.00000000e+00,\n", " 4.22181265e-29, 6.89778699e-37, 1.76721673e-41, 1.28104982e-57])" ] }, "execution_count": 71, "metadata": {}, "output_type": "execute_result" } ], "source": [ "results_gra.occupations[0]" ] }, { "cell_type": "code", "execution_count": 72, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([1. , 1. , 1. , 0.5, 0.5, 0. , 0. , 0. ])" ] }, "execution_count": 72, "metadata": {}, "output_type": "execute_result" } ], "source": [ "results_gra.occupations[18] #the position of K" ] }, { "cell_type": "code", "execution_count": 73, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Direct gap system\n", "=================\n", "Gap : 2.715685454290906e-10 eV\n" ] }, { "data": { "text/plain": [ "{'gap': 2.715685454290906e-10,\n", " 'direct_gap': 2.715685454290906e-10,\n", " 'position_cbm': 18,\n", " 'positon_vbm': 18}" ] }, "execution_count": 73, "metadata": {}, "output_type": "execute_result" } ], "source": [ "results_gra.get_gap()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.8.5" } }, "nbformat": 4, "nbformat_minor": 4 }