.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/plot_phbands_nkpt_tsmear.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_plot_phbands_nkpt_tsmear.py: Multiple phonon bands with DDB robot ==================================== This example shows how to plot several phonon band structures on a grid. .. important:: Note that a **manager.yml** file and an abinit installation are required to run this script as AbiPy needs to invoke anaddb to compute phonons from the DDB file. .. GENERATED FROM PYTHON SOURCE LINES 15-17 We start by defining a list of DDB files: obtained with the same structure but different k-mesh and tmear: .. GENERATED FROM PYTHON SOURCE LINES 17-37 .. code-block:: Python from abipy import abilab import abipy.data as abidata import os paths = [ #"mgb2_444k_0.01tsmear_DDB", #"mgb2_444k_0.02tsmear_DDB", #"mgb2_444k_0.04tsmear_DDB", "mgb2_888k_0.01tsmear_DDB", #"mgb2_888k_0.02tsmear_DDB", "mgb2_888k_0.04tsmear_DDB", "mgb2_121212k_0.01tsmear_DDB", #"mgb2_121212k_0.02tsmear_DDB", "mgb2_121212k_0.04tsmear_DDB", ] paths = [os.path.join(abidata.dirpath, "refs", "mgb2_phonons_nkpt_tsmear", f) for f in paths] .. GENERATED FROM PYTHON SOURCE LINES 38-39 Now we initialize the DdbRobot from this list of paths: .. GENERATED FROM PYTHON SOURCE LINES 39-43 .. code-block:: Python robot = abilab.DdbRobot.from_files(paths) print(robot.keys()) .. rst-class:: sphx-glr-script-out .. code-block:: none dict_keys(['../../data/refs/mgb2_phonons_nkpt_tsmear/mgb2_888k_0.01tsmear_DDB', '../../data/refs/mgb2_phonons_nkpt_tsmear/mgb2_888k_0.04tsmear_DDB', '../../data/refs/mgb2_phonons_nkpt_tsmear/mgb2_121212k_0.01tsmear_DDB', '../../data/refs/mgb2_phonons_nkpt_tsmear/mgb2_121212k_0.04tsmear_DDB']) .. GENERATED FROM PYTHON SOURCE LINES 44-48 Now we change the keys associated to the different files by defining a function that computes the new label from the info reported in the ddb object. These lables are then used to generate the legend in the matplotlib plot. .. GENERATED FROM PYTHON SOURCE LINES 48-52 .. code-block:: Python robot.remap_labels(lambda ddb: "nkpt: %s, tsmear: %.2f" % (ddb.header["nkpt"], ddb.header["tsmear"])) print(robot.keys()) .. rst-class:: sphx-glr-script-out .. code-block:: none dict_keys(['nkpt: 256, tsmear: 0.01', 'nkpt: 256, tsmear: 0.04', 'nkpt: 864, tsmear: 0.01', 'nkpt: 864, tsmear: 0.04']) .. GENERATED FROM PYTHON SOURCE LINES 53-55 Invoke anaddb to build a PhononBands plotter. We use a small q-mesh for the ph-DOS to speedup the computation: .. GENERATED FROM PYTHON SOURCE LINES 55-58 .. code-block:: Python r = robot.anaget_phonon_plotters(nqsmall=2) .. GENERATED FROM PYTHON SOURCE LINES 59-60 To group the results by tsmear use: .. GENERATED FROM PYTHON SOURCE LINES 60-63 .. code-block:: Python r.phbands_plotter.gridplot_with_hue("tsmear") .. image-sg:: /gallery/images/sphx_glr_plot_phbands_nkpt_tsmear_001.png :alt: tsmear = 0.01, tsmear = 0.04 :srcset: /gallery/images/sphx_glr_plot_phbands_nkpt_tsmear_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 64-65 If Phonon DOSes are wanted, use: .. GENERATED FROM PYTHON SOURCE LINES 65-71 .. code-block:: Python r.phbands_plotter.gridplot_with_hue("tsmear", with_dos=True) #r.phbands_plotter.gridplot() robot.close() .. image-sg:: /gallery/images/sphx_glr_plot_phbands_nkpt_tsmear_002.png :alt: tsmear = 0.01, tsmear = 0.04 :srcset: /gallery/images/sphx_glr_plot_phbands_nkpt_tsmear_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 6.235 seconds) .. _sphx_glr_download_gallery_plot_phbands_nkpt_tsmear.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_phbands_nkpt_tsmear.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_phbands_nkpt_tsmear.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_phbands_nkpt_tsmear.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_