Multiple phonon bands with DDB robotΒΆ

This example shows how to plot several phonon band structures on a grid.


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.

We start by defining a list of DDB files: obtained with the same structure but different k-mesh and tmear:

from abipy import abilab
import as abidata
import os

paths = [

paths = [os.path.join(abidata.dirpath, "refs", "mgb2_phonons_nkpt_tsmear", f) for f in paths]

Now we initialize the DdbRobot from this list of paths:


odict_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'])

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.

robot.remap_labels(lambda ddb: "nkpt: %s, tsmear: %.2f" % (ddb.header["nkpt"], ddb.header["tsmear"]))


odict_keys(['nkpt: 256, tsmear: 0.01', 'nkpt: 256, tsmear: 0.04', 'nkpt: 864, tsmear: 0.01', 'nkpt: 864, tsmear: 0.04'])

Invoke anaddb to build a PhononBands plotter. We use a small q-mesh for the ph-DOS to speedup the computation:

To group the results by tsmear use:

tsmear = 0.01, tsmear = 0.04


<Figure size 640x480 with 2 Axes>

If Phonon DOSes are wanted, use:

r.phbands_plotter.gridplot_with_hue("tsmear", with_dos=True)


tsmear = 0.01, tsmear = 0.04

Total running time of the script: ( 0 minutes 5.266 seconds)

Gallery generated by Sphinx-Gallery