<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.yambo-code.eu/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=FulvioPaleari</id>
	<title>The Yambo Project - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.yambo-code.eu/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=FulvioPaleari"/>
	<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Special:Contributions/FulvioPaleari"/>
	<updated>2026-05-13T21:42:32Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.8</generator>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=First_steps_in_Yambopy&amp;diff=9348</id>
		<title>First steps in Yambopy</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=First_steps_in_Yambopy&amp;diff=9348"/>
		<updated>2026-03-19T13:52:50Z</updated>

		<summary type="html">&lt;p&gt;FulvioPaleari: /* Tutorials */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The yambopy project aims to develop python tools to: &lt;br /&gt;
&lt;br /&gt;
* Read and edit yambo and quantum espresso input files&lt;br /&gt;
* Easily perform pre- and post-processing of the simulation data for these two codes - including hard-to-get, database-encoded data beyond standard outputs&lt;br /&gt;
* Provide easy visualization and plotting options &lt;br /&gt;
* Set up simple automatization workflows (e.g., convergence tests)&lt;br /&gt;
&lt;br /&gt;
=== Setup ===&lt;br /&gt;
First of all, make sure that you have a suitable python environment (crated for example with [https://docs.anaconda.com/miniconda/install/ conda] or [https://docs.python.org/3/library/venv.html venv]) with &#039;&#039;&#039;python &amp;gt;=3.8&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
If you are not used with python environments, here two simple commands that you can use&lt;br /&gt;
 python -m venv MYPATH/yamboenv/&lt;br /&gt;
(you can replace `MYPATH` with any path you prefer, e.g. `~/`)&lt;br /&gt;
 source MYPATH/yamboenv/bin/activate&lt;br /&gt;
(for bash users, you can add to your .bashrt the line `. MYPATH/yamboenv/bin/activate`)&lt;br /&gt;
&lt;br /&gt;
Then, you may install yambopy in one of the following ways.&lt;br /&gt;
&lt;br /&gt;
==== Quick installation from PyPI repository ====&lt;br /&gt;
&lt;br /&gt;
* In order to quickly install the officially released version type:&lt;br /&gt;
&lt;br /&gt;
 pip install yambopy&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Installation from tarball ====&lt;br /&gt;
&lt;br /&gt;
* In case you don&#039;t want to download from the pip repository and prefer to install a version of yambopy locally, you may download the appropriate tarball from the [https://github.com/yambo-code/yambopy/releases| yambopy github page]. Extract the tarball, enter the yambopy folder and type &amp;lt;code&amp;gt;pip install .&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Installation of latest patch ====&lt;br /&gt;
&lt;br /&gt;
* In case you want the latest version of the code including new updates and patches that might not be present in the official version, then you can clone the yambopy git repository (a basic knowledge of git may be helpful):&lt;br /&gt;
&lt;br /&gt;
 git clone https://github.com/yambo-code/yambopy.git&lt;br /&gt;
 cd yambopy&lt;br /&gt;
 pip install .&lt;br /&gt;
&lt;br /&gt;
==== Installation for developers ====&lt;br /&gt;
* If you want to install YamboPy in developing mode (to modify or add new functions) you have to download the code from github repository then go in the YamboPy folder and install with the command:&lt;br /&gt;
&lt;br /&gt;
 pip install -e .&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important:&#039;&#039;&#039; if you want your changes to be included into a new patch/version of Yambopy, you need to first create your own personal fork of the git repository, make the changes there, and then create a pull request for the original repository. &lt;br /&gt;
&lt;br /&gt;
==== Dependencies ====&lt;br /&gt;
&lt;br /&gt;
* In principle, &amp;lt;code&amp;gt;pip&amp;lt;/code&amp;gt; should take care of the required python dependencies. They are &amp;lt;code&amp;gt;numpy&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;scipy&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;matplotlib&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;netCDF4&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;h5py&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;lxml&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;PyYAML&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;monty&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;scikit-learn&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;tqdm&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;spglib&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;spgrep&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;pykdtree&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;numba&amp;lt;/code&amp;gt;. In case some dependency-related problem arises, you can install each of them separately beforehand with:&lt;br /&gt;
&lt;br /&gt;
 pip install &amp;lt;code&amp;gt;dependency-name&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* If you experience errors related to &amp;lt;code&amp;gt;NetCDF4&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;hdf5&amp;lt;/code&amp;gt;, these are usually due to incompatibilities between the python modules the library in your environment. In this case, you can force the python installation to match the system library. For example, if you have an &amp;lt;code&amp;gt;hdf5&amp;lt;/code&amp;gt; problem and you are using conda, you could try:&lt;br /&gt;
&lt;br /&gt;
 conda install --force-reinstall h5py hdf5&lt;br /&gt;
&lt;br /&gt;
=== Tutorials ===&lt;br /&gt;
Now yambopy is ready to use! Just go to the tutorials folder and follow the docs!&lt;br /&gt;
&lt;br /&gt;
 cd tutorial/&lt;br /&gt;
&lt;br /&gt;
On this wiki, we provide steps for the following tutorials:&lt;br /&gt;
&lt;br /&gt;
1. Data postprocessing:&lt;br /&gt;
* [[Yambopy tutorial: band structures | Database and plotting tutorial for quantum espresso (qepy) and GW &#039;&#039;&#039;band structures&#039;&#039;&#039;]] (Get the databases: [https://media.yambo-code.eu/educational/tutorials/files/databases_qepy.tar.gz databases_qepy], 46.5MB)&lt;br /&gt;
* [[Yambopy tutorial: Yambo databases | Database and plotting tutorial for yambo (yambopy) and &#039;&#039;&#039;exciton&#039;&#039;&#039; analysis ]] (Get the databases: [https://media.yambo-code.eu/educational/tutorials/files/databases_yambopy.tar.gz databases_yambopy], 99MB)&lt;br /&gt;
2. Manage QE and Yambo runs: [WARNING: these tutorials are currently under maintenance due to updates to the scheduler class]&lt;br /&gt;
* [[GW tutorial. Convergence and approximations (BN)]]&lt;br /&gt;
* [[Bethe-Salpeter equation tutorial. Optical absorption (BN)]]&lt;br /&gt;
3. Advanced topics:&lt;br /&gt;
* [[Yambopy tutorial: electron-phonon coupling|Databases and plotting tutorial for electron-phonon coupling with yambopy]] (Get the databases: [https://media.yambo-code.eu/educational/tutorials/files/yambopy_electron_phonon.tar.gz electron_phonon], 490M)&lt;br /&gt;
* [[Exciton-phonon coupling and luminescence]]&lt;br /&gt;
* [[Phonon-assisted luminescence by finite atomic displacements]]&lt;br /&gt;
&lt;br /&gt;
=== How to cite ===&lt;br /&gt;
If yambopy helped you with your data analysis, workflow management of figure preparation, you can consider citing us.&lt;br /&gt;
&lt;br /&gt;
The way to do so in BibTeX format is the following:&lt;br /&gt;
 @misc{yambopy, &lt;br /&gt;
      author = {Paleari, Fulvio and Molina-Sánchez, Alejandro and Nalabothula, Muralidhar and Reho, Riccardo and Bonacci, Miki and Castelo, José M. and Cervantes-Villanueva, Jorge and Pionteck, Mike and Silvetti, Martino and Attaccalite, Claudio and Pereira Coutada Miranda, Henrique},&lt;br /&gt;
      title = {Yambopy},&lt;br /&gt;
      month = mar,&lt;br /&gt;
      year = 2025,&lt;br /&gt;
      publisher = {Zenodo},&lt;br /&gt;
      version = {0.4.0}, &lt;br /&gt;
      doi = {10.5281/zenodo.15012962},&lt;br /&gt;
      url = {[[https://doi.org/10.5281/zenodo.15012962 https://doi.org/10.5281/zenodo.15012962]]}, }&lt;/div&gt;</summary>
		<author><name>FulvioPaleari</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=First_steps_in_Yambopy&amp;diff=9347</id>
		<title>First steps in Yambopy</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=First_steps_in_Yambopy&amp;diff=9347"/>
		<updated>2026-03-19T13:51:37Z</updated>

		<summary type="html">&lt;p&gt;FulvioPaleari: /* Tutorials */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The yambopy project aims to develop python tools to: &lt;br /&gt;
&lt;br /&gt;
* Read and edit yambo and quantum espresso input files&lt;br /&gt;
* Easily perform pre- and post-processing of the simulation data for these two codes - including hard-to-get, database-encoded data beyond standard outputs&lt;br /&gt;
* Provide easy visualization and plotting options &lt;br /&gt;
* Set up simple automatization workflows (e.g., convergence tests)&lt;br /&gt;
&lt;br /&gt;
=== Setup ===&lt;br /&gt;
First of all, make sure that you have a suitable python environment (crated for example with [https://docs.anaconda.com/miniconda/install/ conda] or [https://docs.python.org/3/library/venv.html venv]) with &#039;&#039;&#039;python &amp;gt;=3.8&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
If you are not used with python environments, here two simple commands that you can use&lt;br /&gt;
 python -m venv MYPATH/yamboenv/&lt;br /&gt;
(you can replace `MYPATH` with any path you prefer, e.g. `~/`)&lt;br /&gt;
 source MYPATH/yamboenv/bin/activate&lt;br /&gt;
(for bash users, you can add to your .bashrt the line `. MYPATH/yamboenv/bin/activate`)&lt;br /&gt;
&lt;br /&gt;
Then, you may install yambopy in one of the following ways.&lt;br /&gt;
&lt;br /&gt;
==== Quick installation from PyPI repository ====&lt;br /&gt;
&lt;br /&gt;
* In order to quickly install the officially released version type:&lt;br /&gt;
&lt;br /&gt;
 pip install yambopy&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Installation from tarball ====&lt;br /&gt;
&lt;br /&gt;
* In case you don&#039;t want to download from the pip repository and prefer to install a version of yambopy locally, you may download the appropriate tarball from the [https://github.com/yambo-code/yambopy/releases| yambopy github page]. Extract the tarball, enter the yambopy folder and type &amp;lt;code&amp;gt;pip install .&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Installation of latest patch ====&lt;br /&gt;
&lt;br /&gt;
* In case you want the latest version of the code including new updates and patches that might not be present in the official version, then you can clone the yambopy git repository (a basic knowledge of git may be helpful):&lt;br /&gt;
&lt;br /&gt;
 git clone https://github.com/yambo-code/yambopy.git&lt;br /&gt;
 cd yambopy&lt;br /&gt;
 pip install .&lt;br /&gt;
&lt;br /&gt;
==== Installation for developers ====&lt;br /&gt;
* If you want to install YamboPy in developing mode (to modify or add new functions) you have to download the code from github repository then go in the YamboPy folder and install with the command:&lt;br /&gt;
&lt;br /&gt;
 pip install -e .&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important:&#039;&#039;&#039; if you want your changes to be included into a new patch/version of Yambopy, you need to first create your own personal fork of the git repository, make the changes there, and then create a pull request for the original repository. &lt;br /&gt;
&lt;br /&gt;
==== Dependencies ====&lt;br /&gt;
&lt;br /&gt;
* In principle, &amp;lt;code&amp;gt;pip&amp;lt;/code&amp;gt; should take care of the required python dependencies. They are &amp;lt;code&amp;gt;numpy&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;scipy&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;matplotlib&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;netCDF4&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;h5py&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;lxml&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;PyYAML&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;monty&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;scikit-learn&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;tqdm&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;spglib&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;spgrep&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;pykdtree&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;numba&amp;lt;/code&amp;gt;. In case some dependency-related problem arises, you can install each of them separately beforehand with:&lt;br /&gt;
&lt;br /&gt;
 pip install &amp;lt;code&amp;gt;dependency-name&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* If you experience errors related to &amp;lt;code&amp;gt;NetCDF4&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;hdf5&amp;lt;/code&amp;gt;, these are usually due to incompatibilities between the python modules the library in your environment. In this case, you can force the python installation to match the system library. For example, if you have an &amp;lt;code&amp;gt;hdf5&amp;lt;/code&amp;gt; problem and you are using conda, you could try:&lt;br /&gt;
&lt;br /&gt;
 conda install --force-reinstall h5py hdf5&lt;br /&gt;
&lt;br /&gt;
=== Tutorials ===&lt;br /&gt;
Now yambopy is ready to use! Just go to the tutorials folder and follow the docs!&lt;br /&gt;
&lt;br /&gt;
 cd tutorial/&lt;br /&gt;
&lt;br /&gt;
On this wiki, we provide steps for the following tutorials:&lt;br /&gt;
&lt;br /&gt;
1. Data postprocessing:&lt;br /&gt;
* [[Yambopy tutorial: band structures (including GW) | Database and plotting tutorial for quantum espresso (qepy) and GW &#039;&#039;&#039;band structures&#039;&#039;&#039;]] (Get the databases: [https://media.yambo-code.eu/educational/tutorials/files/databases_qepy.tar.gz databases_qepy], 46.5MB)&lt;br /&gt;
* [[Yambopy tutorial: Yambo databases and exciton analysis | Database and plotting tutorial for yambo (yambopy) and &#039;&#039;&#039;exciton&#039;&#039;&#039; analysis ]] (Get the databases: [https://media.yambo-code.eu/educational/tutorials/files/databases_yambopy.tar.gz databases_yambopy], 99MB)&lt;br /&gt;
2. Manage QE and Yambo runs: [WARNING: these tutorials are currently under maintenance due to updates to the scheduler class]&lt;br /&gt;
* [[GW tutorial. Convergence and approximations (BN)]]&lt;br /&gt;
* [[Bethe-Salpeter equation tutorial. Optical absorption (BN)]]&lt;br /&gt;
3. Advanced topics:&lt;br /&gt;
* [[Yambopy tutorial: electron-phonon coupling|Databases and plotting tutorial for electron-phonon coupling with yambopy]] (Get the databases: [https://media.yambo-code.eu/educational/tutorials/files/yambopy_electron_phonon.tar.gz electron_phonon], 490M)&lt;br /&gt;
* [[Exciton-phonon coupling and luminescence]]&lt;br /&gt;
* [[Phonon-assisted luminescence by finite atomic displacements]]&lt;br /&gt;
&lt;br /&gt;
=== How to cite ===&lt;br /&gt;
If yambopy helped you with your data analysis, workflow management of figure preparation, you can consider citing us.&lt;br /&gt;
&lt;br /&gt;
The way to do so in BibTeX format is the following:&lt;br /&gt;
 @misc{yambopy, &lt;br /&gt;
      author = {Paleari, Fulvio and Molina-Sánchez, Alejandro and Nalabothula, Muralidhar and Reho, Riccardo and Bonacci, Miki and Castelo, José M. and Cervantes-Villanueva, Jorge and Pionteck, Mike and Silvetti, Martino and Attaccalite, Claudio and Pereira Coutada Miranda, Henrique},&lt;br /&gt;
      title = {Yambopy},&lt;br /&gt;
      month = mar,&lt;br /&gt;
      year = 2025,&lt;br /&gt;
      publisher = {Zenodo},&lt;br /&gt;
      version = {0.4.0}, &lt;br /&gt;
      doi = {10.5281/zenodo.15012962},&lt;br /&gt;
      url = {[[https://doi.org/10.5281/zenodo.15012962 https://doi.org/10.5281/zenodo.15012962]]}, }&lt;/div&gt;</summary>
		<author><name>FulvioPaleari</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_Yambo_databases&amp;diff=9346</id>
		<title>Yambopy tutorial: Yambo databases</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_Yambo_databases&amp;diff=9346"/>
		<updated>2026-03-13T15:28:55Z</updated>

		<summary type="html">&lt;p&gt;FulvioPaleari: /* Exciton intro 1: read and sort data */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial we will see some examples on how to read and analyse the data contained in the Yambo netCDF databases, which are not readily available as human readable outputs.&lt;br /&gt;
&lt;br /&gt;
In particular we will take a look at:&lt;br /&gt;
* Lattice geometry data (Yambo database: &amp;lt;code&amp;gt;ns.db1&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
* Dipole matrix elements (Yambo databases: &amp;lt;code&amp;gt;ndb.dipoles&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboDipolesDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
* Exciton energies, symmetries, wavefunctions and spectra (Yambo databases: &amp;lt;code&amp;gt;ndb.BS_diago_Q*&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboExcitonDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
We will also check the command line instructions to quickly generate yambo SAVE folders.&lt;br /&gt;
&lt;br /&gt;
The scripts of the tutorial, but not the databases, can be found in the yambopy directory:&lt;br /&gt;
 $cd tutorial/databases_yambopy&lt;br /&gt;
&lt;br /&gt;
The full tutorial, including the Quantum espresso and Yambo databases that we will read, can be downloaded and extracted from the yambo website:&lt;br /&gt;
 $wget https://media.yambo-code.eu/educational/tutorials/files/databases_yambopy.tar.gz&lt;br /&gt;
 $tar -xvzf databases_yambopy.tar.gz&lt;br /&gt;
 $cd databases_yambopy&lt;br /&gt;
&lt;br /&gt;
We will work with monolayer hexagonal boron nitride electron-phonon and exciton data obtained on a &amp;lt;code&amp;gt;12x12x1&amp;lt;/code&amp;gt; kpoint grid. Beware that these are certainly not converged.&lt;br /&gt;
&lt;br /&gt;
=== Command line: generating the Yambo SAVE ===&lt;br /&gt;
Yambopy offers a set of command line options. In order to review them, you can type&lt;br /&gt;
 $yambopy&lt;br /&gt;
which will print the output&lt;br /&gt;
 yambopy v0.7&lt;br /&gt;
 Available commands are:&lt;br /&gt;
 &lt;br /&gt;
       plotem1s -&amp;gt;     Plot em1s calculation.&lt;br /&gt;
     analysebse -&amp;gt;     Study the convergence of BSE calculations.&lt;br /&gt;
      analysegw -&amp;gt;     Study the convergence of GW calculations by looking at the change in band-gap value.&lt;br /&gt;
   plotexcitons -&amp;gt;     Plot excitons calculation.&lt;br /&gt;
          addqp -&amp;gt;     Add corrections from QP databases.&lt;br /&gt;
        mergeqp -&amp;gt;     Merge QP databases.&lt;br /&gt;
           save -&amp;gt;     Produce a SAVE folder.&lt;br /&gt;
           gkkp -&amp;gt;     Produce a SAVE folder including elph_gkkp databases.&lt;br /&gt;
          bands -&amp;gt;     Script to produce band structure data and visualization from QE.&lt;br /&gt;
         serial -&amp;gt;     Script to update serial numbers of yambo ndb.* databases in order to import them to new calculations.&lt;br /&gt;
     gwsubspace -&amp;gt;     Script to calculate off-diago corrections of yambo ndb.QP databases in order to plot band structure.&lt;br /&gt;
          phinp -&amp;gt;     Script to update the explicit list of q-points in a ph input file (ldisp=.false., qplot=.true.).&lt;br /&gt;
        convert -&amp;gt;     Script to convert RL number in Ry energy units using ndb.gops.&lt;br /&gt;
        bsesize -&amp;gt;     Script to calculate the expected BSE kernel size, in GB, to be loaded by each MPI task.&lt;br /&gt;
            l2y -&amp;gt;     Calculate gauge-invariant electron-phonon matrix elements with LetzElPhC and convert them into Yambo format.&lt;br /&gt;
      exc-irrep -&amp;gt;     Script to get the irreducible representation labels for excitonic states. [-h for help]&lt;br /&gt;
         exc-wf -&amp;gt;     Real space exciton wf for either fixed hole/electron. [-h for help]&lt;br /&gt;
       exc-sort -&amp;gt;     Script to sort excitonic states according to energies and intensities. [-h for help]&lt;br /&gt;
&lt;br /&gt;
For this tutorial, we will need the &amp;lt;code&amp;gt;save&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;gkkp&amp;lt;/code&amp;gt; options.&lt;br /&gt;
By typing in one of these, additional information about how to run the commands will be printed, e.g.:&lt;br /&gt;
 $yambopy save&lt;br /&gt;
 &lt;br /&gt;
 Produce a SAVE folder&lt;br /&gt;
 &lt;br /&gt;
 Arguments are:&lt;br /&gt;
   -nscf, --nscf_dir  -&amp;gt; Path to nscf save folder&lt;br /&gt;
   -y, --yambo_dir    -&amp;gt; &amp;lt;Optional&amp;gt; Path to yambo executables&lt;br /&gt;
&lt;br /&gt;
The quantum espresso save for hBN is provided in the directory &amp;lt;code&amp;gt;BSE_saves/QE_saves/hBN.save&amp;lt;/code&amp;gt; (you can check the contents of the various folders). &lt;br /&gt;
Then, following the instructions printed on screen, we can generate a yambo SAVE from the hBN.save by typing&lt;br /&gt;
&lt;br /&gt;
 $yambopy save -nscf BSE_saves/QE_saves/hBN.save&lt;br /&gt;
&lt;br /&gt;
This should produce a SAVE folder in the current directory.&lt;br /&gt;
&lt;br /&gt;
=== Lattice intro: plot k-point coordinates in IBZ/BZ ===&lt;br /&gt;
For this section we will use the script &amp;lt;code&amp;gt;bz_plot.py&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
By inspecting the SAVE folder we have just generated, we will find the &amp;lt;code&amp;gt;ns.db1&amp;lt;/code&amp;gt; database which contains all the geometry and lattice information.&lt;br /&gt;
We are now going to read it in python by using the Yambopy class &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
&lt;br /&gt;
 from yambopy import YamboLatticeDB&lt;br /&gt;
 ylat = YamboLatticeDB.from_db_file(filename=&amp;quot;PATH/TO/SAVE/ns.db1&amp;quot;)&lt;br /&gt;
(remember to edit the variable &amp;lt;code&amp;gt;save_path&amp;lt;/code&amp;gt; in order to point at your yambo SAVE).&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;ylat&amp;lt;/code&amp;gt; object now contains many useful information as attributes, such as the k-points in Cartesian or crystal coordinates, the system symmetries, lattice constants and basis vectors in real and reciprocal space, etc.&lt;br /&gt;
The k-points are also automatically expanded in the full Brillouin zone from the irreducible one (you can turn this off with the option &amp;lt;code&amp;gt;Expand=False&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Directly printing the object with&lt;br /&gt;
 print(ylat)&lt;br /&gt;
will also give us some general parameters related to the database. &lt;br /&gt;
&lt;br /&gt;
Now check the &amp;lt;code&amp;gt;bz_plot.py&amp;lt;/code&amp;gt; script. You will see that it performs three plots: &lt;br /&gt;
* Scatterplot of the k-points in Cartesian coordinates with both expanded and unexpanded grids, with annotated indices [&amp;lt;code&amp;gt;Cartesian_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Scatterplot of the k-points in crystal coordinates [&amp;lt;code&amp;gt;Crystal_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Manual transformation of a chosen k-point from irreducible to full Brillouin zone (you can change the index &amp;lt;code&amp;gt;i_k&amp;lt;/code&amp;gt; in the script to check different cases) [&amp;lt;code&amp;gt;Symmetry_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
Below, the result of the first plot.&lt;br /&gt;
&lt;br /&gt;
[[File:Car kpoints hbn.jpg|YamboLatticeDB plot from yambopy tutorial| 500px]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What about the units?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Below we report the relation between units used in Yambo, Quantum Espresso, and Yambopy.&lt;br /&gt;
&lt;br /&gt;
* bohr^-1 (atomic units):                                     &amp;lt;code&amp;gt;YamboLatticeDB.car_kpoints*2.*pi&amp;lt;/code&amp;gt;. Divide by the bohr-to-angstrom conversion factor to obtain angs^-1 &lt;br /&gt;
* Yambo cartesian units (&amp;lt;code&amp;gt;[cc]&amp;lt;/code&amp;gt; in Yambo outputs): &amp;lt;code&amp;gt;YamboLatticeDB.car_kpoints*2.*pi&amp;lt;/code&amp;gt; (same as above).&lt;br /&gt;
* QE cartesian units (&amp;lt;code&amp;gt;[cart. coord. in units 2pi/alat]&amp;lt;/code&amp;gt; in QE outputs): &amp;lt;code&amp;gt;YamboLatticeDB.car_kpoints*YamboLatticeDB.alat[0]&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Internal yambo units (&amp;lt;code&amp;gt;[iku]&amp;lt;/code&amp;gt; in yambo outputs): &amp;lt;code&amp;gt;YamboLatticeDB.iku_kpoints&amp;lt;/code&amp;gt;&lt;br /&gt;
* Fractional coordinates (&amp;lt;code&amp;gt;[rlu]&amp;lt;/code&amp;gt; in yambo, &amp;lt;code&amp;gt;cryst. coord.&amp;lt;/code&amp;gt; in QE): &amp;lt;code&amp;gt;YamboLatticeDB.red_kpoints&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Dipoles intro: plots of dipoles on BZ, plot of IP absorption ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;dipoles_plot.py&amp;lt;/code&amp;gt; and read the dipole databases generated in an optical absorption calculation by yambo. Keep in mind that from now on we will use the &amp;quot;BSE&amp;quot; yambo SAVE generated in the [[#Command line: generating the Yambo SAVE|first section]].&lt;br /&gt;
&lt;br /&gt;
The databases written after a calculation of optical properties with yambo (dipoles, static screening, excitons) are in the directory &amp;lt;code&amp;gt;BSE_saves/BSE_databases&amp;lt;/code&amp;gt;. Here we will also find &amp;lt;code&amp;gt;ndb.dipoles&amp;lt;/code&amp;gt; which is needed now, since it contains the matrix elements d_{vck}(\alpha) where vk and ck are the valence and electron states involved in the transition and \alpha the polarisation direction of the external electric field.&lt;br /&gt;
&lt;br /&gt;
In order to read it in python we use the Yambopy class &amp;lt;code&amp;gt;YamboDipolesDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
 ydip = YamboDipolesDB(ylat,save=&#039;path/to/BSE/databases&#039;,filename=&#039;ndb.dipoles&#039;)&lt;br /&gt;
(notice that it requires a previous instance of &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
In addition, in order to read the Kohn-Sham energies, we can also instance the &amp;lt;code&amp;gt;YamboElectronsDB&amp;lt;/code&amp;gt; as&lt;br /&gt;
 yel = YamboElectronsDB.from_db_file(folder=&#039;path/to/SAVE&#039;) &lt;br /&gt;
&lt;br /&gt;
The object &amp;lt;code&amp;gt;ydip&amp;lt;/code&amp;gt; now has a method that permits to retrieve the independent-particle absorption spectrum with customly chosen energy range, steps, and broadening:&lt;br /&gt;
 w, eps2 = ydip.ip_eps2(yel)&lt;br /&gt;
&lt;br /&gt;
In order to see all this in action, take a look at the &amp;lt;code&amp;gt;dipoles_plot.py&amp;lt;/code&amp;gt; script. You will see that it performs two plots:&lt;br /&gt;
* Plot of |d(k)| in the BZ for selected v,c and \alpha (we choose the layer plane &#039;xy&#039;) [&amp;lt;code&amp;gt;Kspace_Plot=True&amp;lt;/code&amp;gt;]. From this plot you can appreciate which sections of the BZ contribute the most to the absorption rate.&lt;br /&gt;
* Plot of the independent-particles absorption spectrum [&amp;lt;code&amp;gt;Absorption_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
You can play with the indices and the plot parameters to check what happens.&lt;br /&gt;
&lt;br /&gt;
[[File:Dipoles hbn2.png|YamboDipolesDB plot from yambopy tutorial|500px]]&lt;br /&gt;
&lt;br /&gt;
=== Exciton intro 1: read and sort data ===&lt;br /&gt;
In this section we will use both the script &amp;lt;code&amp;gt;exc_read.py&amp;lt;/code&amp;gt; and the command line in order to read the exciton data resulting from a BSE calculation to familiarise with their structure. This time we are going to read the &amp;lt;code&amp;gt;ndb.BS_diago_Q*&amp;lt;/code&amp;gt; databases which correspond to BSE calculations at various momenta Q (Q=1 being the zero-momentum optical absorption limit - notice that python indexing starts from 0, while the databases are counted starting from 1).&lt;br /&gt;
&lt;br /&gt;
In order to read them in python we use the Yambopy class &amp;lt;code&amp;gt;YamboExcitonDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
 yexc = YamboExcitonDB.from_db_file(ylat,filename=f&#039;path/to/BSE/databases/ndb.BS_diago_Q{i}&#039;)&lt;br /&gt;
(where i is the number of BS_diago_Qi file. Notice that it requires a previous instance of &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Now the &amp;lt;code&amp;gt;yexc&amp;lt;/code&amp;gt; object contains information about the exciton energies (&amp;lt;code&amp;gt;yexc.eigenvalues&amp;lt;/code&amp;gt;), wave functions (&amp;lt;code&amp;gt;yexc.eigenvectors&amp;lt;/code&amp;gt;) and intensities (&amp;lt;code&amp;gt;yexc.l_residuals&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yexc.r_residuals&amp;lt;/code&amp;gt;) for Qpoint i_Q. You can start by keeping &amp;lt;code&amp;gt;Q1&amp;lt;/code&amp;gt; which is the optical limit and then check other momenta.&lt;br /&gt;
&lt;br /&gt;
The exciton wave function components A_{vck}^{\lambda Q} (\lambda being the exciton index) are stored as A_{t}^{\lambda} in each Q-dependent database, with t being the transition index grouping the single-particle indices vck. Therefore, &amp;lt;code&amp;gt;yexc.eigenvectors&amp;lt;/code&amp;gt; is an array with (N_excitons,N_transitions) dimension. In order to make the connection t-&amp;gt;kcv, the table &amp;lt;code&amp;gt;yexc.table&amp;lt;/code&amp;gt; provides k,v,c and spin indices corresponding to each transition.&lt;br /&gt;
&lt;br /&gt;
In order to get a clearer picture, take a look at the script &amp;lt;code&amp;gt;exc_read.py&amp;lt;/code&amp;gt;. Run it and try to understand the outputs.&lt;br /&gt;
  $ python exc_read.py&lt;br /&gt;
&lt;br /&gt;
Actually, we can produce output files with the sorted exciton energies in a much more convenient way by using the command line instruction &amp;lt;code&amp;gt;exc-sort&amp;lt;/code&amp;gt;. Check its syntax via:&lt;br /&gt;
 $ yambopy exc-sort -h&lt;br /&gt;
&lt;br /&gt;
Then, we run it for our specific calculation with:&lt;br /&gt;
 $ yambopy exc-sort --save BSE_saves/YAMBO_saves/SAVE -J BSE_saves/BSE_databases --iqpt 1&lt;br /&gt;
&lt;br /&gt;
Recall that that the path given to &amp;lt;code&amp;gt;--save&amp;lt;/code&amp;gt; must be the directory that contains the &amp;lt;code&amp;gt;ns.db1&amp;lt;/code&amp;gt; yambo database (usually called... &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt;). The path given to &amp;lt;code&amp;gt;-J&amp;lt;/code&amp;gt; must be the directory that contains the results of the BSE calculation, namely the &amp;lt;code&amp;gt;ndb.BS_diago_Q1&amp;lt;/code&amp;gt; file. The final argument is the center-of-mass momentum of the exciton. In a standard absorption calculation, you only need the first Q-point which describes vertical electronic transitions. However, if you calculate the exciton dispersion, you will produce a &amp;lt;code&amp;gt;ndb.BS_diago_QN&amp;lt;/code&amp;gt; at each momentum index N that you selected for the yambo BSE calculation.&lt;br /&gt;
&lt;br /&gt;
This command should produce the &amp;lt;code&amp;gt;o-BSE_databases.exc_qpt1_sorted_E.dat&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;o-BSE_databases.exc_qpt1_sorted_I.dat&amp;lt;/code&amp;gt; output files for you to inspect. These are very useful as they allow for identification of degenerate states and degree of optical activity. You will see that in our system most states are doubly degenerate, a byproduct of crystal symmetry. This is an updated version of the ypp exciton analysis that you can find [[How to analyse excitons#Sort the excitonic eigenvalues|here]].&lt;br /&gt;
&lt;br /&gt;
=== Exciton intro 2: symmetry analysis and wavefunction plot in real space ===&lt;br /&gt;
&lt;br /&gt;
==== Symmetries of excitons====&lt;br /&gt;
We can analyse the symmetries of the excitonic wavefunctions in terms of irreducible representation of the point group of the system (if at Q=0) or the Q little group. For more information, the methodology is explained in Ref. &amp;lt;ref&amp;gt;Symmetries of excitons, M. Nalabothula et al., [https://arxiv.org/abs/2511.21540 preprint arXiv]&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
We use the &amp;lt;code&amp;gt;exc-irrep&amp;lt;/code&amp;gt; command line option, check the arguments with:&lt;br /&gt;
 $ yambopy exc-irrep -h&lt;br /&gt;
&lt;br /&gt;
We know from the previous section (by inspecting the sorted energies) that the first four BSE eigenvalues correspond to two doubly-degenerate bright states. Let us analyse their symmetry by running&lt;br /&gt;
 $ yambopy exc-irrep --path BSE_saves/YAMBO_saves -J BSE_saves/BSE_databases --iqpt 1 --nstates 4&lt;br /&gt;
&lt;br /&gt;
This command first loads the electronic wave functions and calculated the electronic representation matrices (called &amp;lt;code&amp;gt;Dmats&amp;lt;/code&amp;gt; in the code). As a second step, they are used to compute the &#039;&#039;&#039;excitonic&#039;&#039;&#039; representation matrices. &lt;br /&gt;
&lt;br /&gt;
We obtain the following output:&lt;br /&gt;
&lt;br /&gt;
 ========================================&lt;br /&gt;
 Group theory analysis for Q point : (0.000000, 0.000000, 0.000000)&lt;br /&gt;
 ****************************************&lt;br /&gt;
 Little group :  D3h&lt;br /&gt;
 Little group symmetries :  [ 1  2  3  4  5  6  7  8  9 10 11 12]&lt;br /&gt;
 Classes (symmetry indices in each class):&lt;br /&gt;
                E    :  [1]&lt;br /&gt;
             2S_3    :  [2 6]&lt;br /&gt;
             2C_3    :  [3 5]&lt;br /&gt;
          sigma_h    :  [4]&lt;br /&gt;
             3C_2    :  [ 7  9 11]&lt;br /&gt;
         3sigma_v    :  [ 8 10 12]&lt;br /&gt;
 &lt;br /&gt;
 ====== Exciton representations ======&lt;br /&gt;
 Energy (eV),  degeneracy  : representation&lt;br /&gt;
 ----------------------------------------&lt;br /&gt;
 1.9139                2  :  E&#039;&lt;br /&gt;
 2.5988                2  :  E&#039;&lt;br /&gt;
 ****************************************&lt;br /&gt;
&lt;br /&gt;
This is similar to the group theory analysis done by Quantum Espresso on the electronic states, and is actually analogous to the one performed for the phonon modes of crystals. We see that the first two states transform as the E&#039; representation of the D3h point group of the crystal. By optical selection rules, only states with this symmetry can form absorption peaks in monolayer BN when light is polarized along the layer plane.&lt;br /&gt;
&lt;br /&gt;
We could go further and calculate the total crystal angular momentum of these states, while also rotate the degenerate exciton states so that they are both eigenvectors of the BSE Hamiltonian and the total crystal angular momentum operator. This is very useful for analyses involving selection rules, exciton-boson couplings, chirality, etc. This is an advanced topic and will not be covered, nonetheless an example script is provided in the tutorial folder called &amp;lt;code&amp;gt;total_crystal_angular_momentum_exciton.py&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; What to do when symmetry analysis does not seem to work well &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Check for warnings during execution. If the BSE calculation was done with a response function that breaks the symmetries (such as the longitudinal response in place of the transverse one at q=0), that may explain the issues.&lt;br /&gt;
&lt;br /&gt;
* If the exciton density of states is very high (such as for a bulk 3D system or for a 2D system at higher energies in the optical spectrum), the analyser may fail to resolve degenerate states, and incorporate a bunch of states together. The symmetry analysis will still be performed but the representation labels will appear as summed. In severe cases, the code may crash. You can try to get a better result by carefully selecting the degeneracy tolerance with &amp;lt;code&amp;gt;degen_tol&amp;lt;/code&amp;gt; and restricting the number of states with &amp;lt;code&amp;gt;nstates&amp;lt;/code&amp;gt; in the command line options.&lt;br /&gt;
&lt;br /&gt;
====Exciton wave functions in real space====&lt;br /&gt;
We can also plot the wave functions of the exciton states on the crystal lattice. In practice, what we do is set the position of the hole at a &amp;quot;physical&amp;quot; point, and then visualize the resulting electronic distribution:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;I^{e}_{\lambda \mathbf{Q}}(\mathbf{r}_e)= |\Psi_{\alpha \mathbf{Q}}(\mathbf{r}_e,\mathbf{r}_h=\mathbf{r}_0)|^2&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let us focus on the lowest exciton state, which gives rise to the largest peak in absorption (see the last part of the tutorial). We will set the hole position on top of a nitrogen atom, since that&#039;s where the &amp;lt;math&amp;gt;p_z&amp;lt;/math&amp;gt; orbitals where the hole comes from are mostly localized.&lt;br /&gt;
&lt;br /&gt;
If we don&#039;t know the correct coordinates, we can modify the &amp;lt;code&amp;gt;bz_plot.py&amp;lt;/code&amp;gt; script by adding (after instancing the lattice object):&lt;br /&gt;
 for iat in range(len(ylat.atomic_numbers)): print(ylat.atomic_numbers[iat],ylat.red_atomic_positions[iat])&lt;br /&gt;
which will print&lt;br /&gt;
 5 [0.6666667 0.3333333 0.       ]&lt;br /&gt;
 7 [-0.6666667 -0.3333333  0.       ]&lt;br /&gt;
&lt;br /&gt;
In order to make the plot, we have to give yambopy the same inputs that are used in the equivalent [[How to analyse excitons#Plot the exciton spatial distribution| ypp calculation]]. First, let&#039;s check all the options via&lt;br /&gt;
 $ yambopy exc-wf -h&lt;br /&gt;
&lt;br /&gt;
Then, we can run our calculation (by selecting a 9x9x1 supercell and a 30 Ry cutoff) as &lt;br /&gt;
 $ yambopy exc-wf --path BSE_saves/YAMBO_saves -J BSE_saves/BSE_databases --iqpt 1 --iexe 1 --supercell 9 9 1 --wfc_cutoff 30 --hole 0.33333333 0.66666667 0.03&lt;br /&gt;
&lt;br /&gt;
Yambopy will produce a *.cube file that can be visualized with VESTA, xcrysden or the like, producing a figure similar to the one below.&lt;br /&gt;
&lt;br /&gt;
The example script &amp;lt;code&amp;gt;exc_real_wf.py&amp;lt;/code&amp;gt;, which runs the same calculation by explicitly calling the necessary functions, will give you more info about what is happening behind the scenes.&lt;br /&gt;
&lt;br /&gt;
[[File:Exc BN yambopy.png|YamboExcitonDB exciton wave function|400px]]&lt;br /&gt;
&lt;br /&gt;
We see that electron is localised in &amp;lt;math&amp;gt;p_z&amp;lt;/math&amp;gt;-like distributions on top of boron atoms around the nitrogen where the hole is set.&lt;br /&gt;
&lt;br /&gt;
=== Exciton intro 3: plot exciton weights on k-BZ and (interpolated) band structure ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;exc_kspace_plot.py&amp;lt;/code&amp;gt; and work with the quantities defined in the previous section.&lt;br /&gt;
&lt;br /&gt;
For now, only the i_Q=0 case is implemented in this section.&lt;br /&gt;
We want to check the relative importance of the various (vk-&amp;gt;ck) electronic transitions in forming a certain excitonic state. &lt;br /&gt;
&lt;br /&gt;
Since many excitonic states are degenerate, we first need to tell Yambopy which states we want to check. For example, in monolayer hexagonal boron nitride, the lowest-bound exciton - forming the main peak in the BSE absorption spectrum - is doubly degenerate. In order to analyse it, in the &amp;lt;code&amp;gt;exc_kspace_plot.py&amp;lt;/code&amp;gt; script we set&lt;br /&gt;
 states = [1,2]&lt;br /&gt;
(we can also set [3,4] to check the second excitonic state, and then [5] for the non-degenerate third state, and so on; we can check degeneracies by printing the energies using the script &amp;lt;code&amp;gt;exc_read.py&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
In order to make a band structure plot, it is necessary to read the band energies, for example with the &amp;lt;code&amp;gt;YamboSaveDB&amp;lt;/code&amp;gt; class&lt;br /&gt;
 yel = YamboSaveDB.from_db_file(folder=&#039;path/to/SAVE&#039;)&lt;br /&gt;
and specify the path in the BZ using crystal coordinates via the &amp;lt;code&amp;gt;Path&amp;lt;/code&amp;gt; function:   &lt;br /&gt;
 npoints = 20&lt;br /&gt;
 path = Path([ [[  0.0,  0.0,  0.0],&#039;$\Gamma$&#039;],&lt;br /&gt;
               [[  0.5,  0.0,  0.0],&#039;M&#039;],&lt;br /&gt;
               [[1./3.,1./3.,  0.0],&#039;K&#039;],&lt;br /&gt;
               [[  0.0,  0.0,  0.0],&#039;$\Gamma$&#039;]],&lt;br /&gt;
               [int(npoints*2),int(npoints),int(sqrt(5)*npoints)] )&lt;br /&gt;
&lt;br /&gt;
Now let&#039;s take a closer look at the &amp;lt;code&amp;gt;exc_kspace_plot.py&amp;lt;/code&amp;gt; script. You will see that it performs three plots:&lt;br /&gt;
* Plot of |A(k)| in the k-BZ for the selected exciton state. You can see how most contributions come from the area around K and the MK direction [&amp;lt;code&amp;gt;Kspace_Plot=True&amp;lt;/code&amp;gt;]. &lt;br /&gt;
* Plot of |A(v,c,k)| on the electronic band structure for the selected exciton state. Here you can better see how the top valence and bottom conduction around MK are mostly involved [&amp;lt;code&amp;gt;Bands_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Plot of interpolated |A(v,c,k)| on the interpolated electronic band structure for the selected exciton state [&amp;lt;code&amp;gt;Bands_Plot_Interpolated=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
As always, try to play with the parameters, for example by changing the excitonic states to analyse.&lt;br /&gt;
&lt;br /&gt;
[[File:Exc bands1 hbn.jpg|YamboExcitonDB plot from yambopy tutorial|300px| Uninterpolated exciton weights on top of band structure]][[File:Exc bands2 hbn.jpg|YamboExcitonDB plot from yambopy tutorial|300px]]&lt;br /&gt;
&lt;br /&gt;
=== Exciton intro 4: plot BSE optical absorption with custom options ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;exc_abs_plot.py&amp;lt;/code&amp;gt; and work with the quantities defined in the previous sections.&lt;br /&gt;
&lt;br /&gt;
The class &amp;lt;code&amp;gt;YamboExcitonDB&amp;lt;/code&amp;gt; also enables us, of course, to read the dielectric function eps(w) and print absorption and related spectra in python.&lt;br /&gt;
&lt;br /&gt;
The advantages over using the standard human-readable yambo outputs are mainly two:&lt;br /&gt;
# We can freely select energy ranges, energy steps, peak broadenings and number of excitonic states included without having to rerun the &amp;lt;code&amp;gt;yambo&amp;lt;/code&amp;gt; executable every time. This reduces the chance of mistakenly editing the yambo input and allows for greater freedom since these plots can now be done in your local machine without having to transfer the output data from a remote cluster.&lt;br /&gt;
# The dielectric function constructed from netCDF database variables has a much higher precision (number of significant digits) than the human readable output, which may be important if you want to perform additional operations in python (e.g., computing refractive index, reflectivity and other optical spectra from it, performing finite-difference derivatives, etc).&lt;br /&gt;
&lt;br /&gt;
We can read eps(w) as a &amp;lt;code&amp;gt;numpy&amp;lt;/code&amp;gt; array with the specified options as (energy values are in eV):&lt;br /&gt;
 w, eps = yexc.get_chi(nexcitons=&#039;all&#039;,emin=0,emax=7,estep=0.005,broad=0.04)&lt;br /&gt;
Or, you can directly prepare a plot of its imaginary part with&lt;br /&gt;
 w, chi = yexc.plot_chi_ax(ax,nexcitons=&#039;all&#039;,emin=0,emax=7,estep=0.005,broad=0.04)&lt;br /&gt;
where &amp;lt;code&amp;gt;ax&amp;lt;/code&amp;gt; is a previously defined &amp;lt;code&amp;gt;Axes&amp;lt;/code&amp;gt; object from &amp;lt;code&amp;gt;matplotlib&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In order to see how this works, let&#039;s take a look at the &amp;lt;code&amp;gt;exc_abs_plot.py&amp;lt;/code&amp;gt; script.&lt;br /&gt;
You will see that it performs the two operations described above:&lt;br /&gt;
* Plotting the BSE absorption spectrum [&amp;lt;code&amp;gt;Absorption_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Reading the complex dielectric function.&lt;br /&gt;
&lt;br /&gt;
Try to customise the plots by changing the &amp;lt;code&amp;gt;nexcitons&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;emin&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;emax&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;estep&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;broad&amp;lt;/code&amp;gt; parameters.&lt;br /&gt;
&lt;br /&gt;
[[File:Absalpha.png|Yambo alpha_2D tutorial plot|700px]]&lt;br /&gt;
&lt;br /&gt;
==Links==&lt;br /&gt;
* Back to [[Rome 2023#Tutorials]]&lt;br /&gt;
* Back to [[ICTP 2022#Tutorials]]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;/div&gt;</summary>
		<author><name>FulvioPaleari</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_Yambo_databases&amp;diff=9345</id>
		<title>Yambopy tutorial: Yambo databases</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_Yambo_databases&amp;diff=9345"/>
		<updated>2026-03-13T15:25:59Z</updated>

		<summary type="html">&lt;p&gt;FulvioPaleari: /* Exciton intro 1: read and sort data */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial we will see some examples on how to read and analyse the data contained in the Yambo netCDF databases, which are not readily available as human readable outputs.&lt;br /&gt;
&lt;br /&gt;
In particular we will take a look at:&lt;br /&gt;
* Lattice geometry data (Yambo database: &amp;lt;code&amp;gt;ns.db1&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
* Dipole matrix elements (Yambo databases: &amp;lt;code&amp;gt;ndb.dipoles&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboDipolesDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
* Exciton energies, symmetries, wavefunctions and spectra (Yambo databases: &amp;lt;code&amp;gt;ndb.BS_diago_Q*&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboExcitonDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
We will also check the command line instructions to quickly generate yambo SAVE folders.&lt;br /&gt;
&lt;br /&gt;
The scripts of the tutorial, but not the databases, can be found in the yambopy directory:&lt;br /&gt;
 $cd tutorial/databases_yambopy&lt;br /&gt;
&lt;br /&gt;
The full tutorial, including the Quantum espresso and Yambo databases that we will read, can be downloaded and extracted from the yambo website:&lt;br /&gt;
 $wget https://media.yambo-code.eu/educational/tutorials/files/databases_yambopy.tar.gz&lt;br /&gt;
 $tar -xvzf databases_yambopy.tar.gz&lt;br /&gt;
 $cd databases_yambopy&lt;br /&gt;
&lt;br /&gt;
We will work with monolayer hexagonal boron nitride electron-phonon and exciton data obtained on a &amp;lt;code&amp;gt;12x12x1&amp;lt;/code&amp;gt; kpoint grid. Beware that these are certainly not converged.&lt;br /&gt;
&lt;br /&gt;
=== Command line: generating the Yambo SAVE ===&lt;br /&gt;
Yambopy offers a set of command line options. In order to review them, you can type&lt;br /&gt;
 $yambopy&lt;br /&gt;
which will print the output&lt;br /&gt;
 yambopy v0.7&lt;br /&gt;
 Available commands are:&lt;br /&gt;
 &lt;br /&gt;
       plotem1s -&amp;gt;     Plot em1s calculation.&lt;br /&gt;
     analysebse -&amp;gt;     Study the convergence of BSE calculations.&lt;br /&gt;
      analysegw -&amp;gt;     Study the convergence of GW calculations by looking at the change in band-gap value.&lt;br /&gt;
   plotexcitons -&amp;gt;     Plot excitons calculation.&lt;br /&gt;
          addqp -&amp;gt;     Add corrections from QP databases.&lt;br /&gt;
        mergeqp -&amp;gt;     Merge QP databases.&lt;br /&gt;
           save -&amp;gt;     Produce a SAVE folder.&lt;br /&gt;
           gkkp -&amp;gt;     Produce a SAVE folder including elph_gkkp databases.&lt;br /&gt;
          bands -&amp;gt;     Script to produce band structure data and visualization from QE.&lt;br /&gt;
         serial -&amp;gt;     Script to update serial numbers of yambo ndb.* databases in order to import them to new calculations.&lt;br /&gt;
     gwsubspace -&amp;gt;     Script to calculate off-diago corrections of yambo ndb.QP databases in order to plot band structure.&lt;br /&gt;
          phinp -&amp;gt;     Script to update the explicit list of q-points in a ph input file (ldisp=.false., qplot=.true.).&lt;br /&gt;
        convert -&amp;gt;     Script to convert RL number in Ry energy units using ndb.gops.&lt;br /&gt;
        bsesize -&amp;gt;     Script to calculate the expected BSE kernel size, in GB, to be loaded by each MPI task.&lt;br /&gt;
            l2y -&amp;gt;     Calculate gauge-invariant electron-phonon matrix elements with LetzElPhC and convert them into Yambo format.&lt;br /&gt;
      exc-irrep -&amp;gt;     Script to get the irreducible representation labels for excitonic states. [-h for help]&lt;br /&gt;
         exc-wf -&amp;gt;     Real space exciton wf for either fixed hole/electron. [-h for help]&lt;br /&gt;
       exc-sort -&amp;gt;     Script to sort excitonic states according to energies and intensities. [-h for help]&lt;br /&gt;
&lt;br /&gt;
For this tutorial, we will need the &amp;lt;code&amp;gt;save&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;gkkp&amp;lt;/code&amp;gt; options.&lt;br /&gt;
By typing in one of these, additional information about how to run the commands will be printed, e.g.:&lt;br /&gt;
 $yambopy save&lt;br /&gt;
 &lt;br /&gt;
 Produce a SAVE folder&lt;br /&gt;
 &lt;br /&gt;
 Arguments are:&lt;br /&gt;
   -nscf, --nscf_dir  -&amp;gt; Path to nscf save folder&lt;br /&gt;
   -y, --yambo_dir    -&amp;gt; &amp;lt;Optional&amp;gt; Path to yambo executables&lt;br /&gt;
&lt;br /&gt;
The quantum espresso save for hBN is provided in the directory &amp;lt;code&amp;gt;BSE_saves/QE_saves/hBN.save&amp;lt;/code&amp;gt; (you can check the contents of the various folders). &lt;br /&gt;
Then, following the instructions printed on screen, we can generate a yambo SAVE from the hBN.save by typing&lt;br /&gt;
&lt;br /&gt;
 $yambopy save -nscf BSE_saves/QE_saves/hBN.save&lt;br /&gt;
&lt;br /&gt;
This should produce a SAVE folder in the current directory.&lt;br /&gt;
&lt;br /&gt;
=== Lattice intro: plot k-point coordinates in IBZ/BZ ===&lt;br /&gt;
For this section we will use the script &amp;lt;code&amp;gt;bz_plot.py&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
By inspecting the SAVE folder we have just generated, we will find the &amp;lt;code&amp;gt;ns.db1&amp;lt;/code&amp;gt; database which contains all the geometry and lattice information.&lt;br /&gt;
We are now going to read it in python by using the Yambopy class &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
&lt;br /&gt;
 from yambopy import YamboLatticeDB&lt;br /&gt;
 ylat = YamboLatticeDB.from_db_file(filename=&amp;quot;PATH/TO/SAVE/ns.db1&amp;quot;)&lt;br /&gt;
(remember to edit the variable &amp;lt;code&amp;gt;save_path&amp;lt;/code&amp;gt; in order to point at your yambo SAVE).&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;ylat&amp;lt;/code&amp;gt; object now contains many useful information as attributes, such as the k-points in Cartesian or crystal coordinates, the system symmetries, lattice constants and basis vectors in real and reciprocal space, etc.&lt;br /&gt;
The k-points are also automatically expanded in the full Brillouin zone from the irreducible one (you can turn this off with the option &amp;lt;code&amp;gt;Expand=False&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Directly printing the object with&lt;br /&gt;
 print(ylat)&lt;br /&gt;
will also give us some general parameters related to the database. &lt;br /&gt;
&lt;br /&gt;
Now check the &amp;lt;code&amp;gt;bz_plot.py&amp;lt;/code&amp;gt; script. You will see that it performs three plots: &lt;br /&gt;
* Scatterplot of the k-points in Cartesian coordinates with both expanded and unexpanded grids, with annotated indices [&amp;lt;code&amp;gt;Cartesian_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Scatterplot of the k-points in crystal coordinates [&amp;lt;code&amp;gt;Crystal_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Manual transformation of a chosen k-point from irreducible to full Brillouin zone (you can change the index &amp;lt;code&amp;gt;i_k&amp;lt;/code&amp;gt; in the script to check different cases) [&amp;lt;code&amp;gt;Symmetry_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
Below, the result of the first plot.&lt;br /&gt;
&lt;br /&gt;
[[File:Car kpoints hbn.jpg|YamboLatticeDB plot from yambopy tutorial| 500px]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What about the units?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Below we report the relation between units used in Yambo, Quantum Espresso, and Yambopy.&lt;br /&gt;
&lt;br /&gt;
* bohr^-1 (atomic units):                                     &amp;lt;code&amp;gt;YamboLatticeDB.car_kpoints*2.*pi&amp;lt;/code&amp;gt;. Divide by the bohr-to-angstrom conversion factor to obtain angs^-1 &lt;br /&gt;
* Yambo cartesian units (&amp;lt;code&amp;gt;[cc]&amp;lt;/code&amp;gt; in Yambo outputs): &amp;lt;code&amp;gt;YamboLatticeDB.car_kpoints*2.*pi&amp;lt;/code&amp;gt; (same as above).&lt;br /&gt;
* QE cartesian units (&amp;lt;code&amp;gt;[cart. coord. in units 2pi/alat]&amp;lt;/code&amp;gt; in QE outputs): &amp;lt;code&amp;gt;YamboLatticeDB.car_kpoints*YamboLatticeDB.alat[0]&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Internal yambo units (&amp;lt;code&amp;gt;[iku]&amp;lt;/code&amp;gt; in yambo outputs): &amp;lt;code&amp;gt;YamboLatticeDB.iku_kpoints&amp;lt;/code&amp;gt;&lt;br /&gt;
* Fractional coordinates (&amp;lt;code&amp;gt;[rlu]&amp;lt;/code&amp;gt; in yambo, &amp;lt;code&amp;gt;cryst. coord.&amp;lt;/code&amp;gt; in QE): &amp;lt;code&amp;gt;YamboLatticeDB.red_kpoints&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Dipoles intro: plots of dipoles on BZ, plot of IP absorption ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;dipoles_plot.py&amp;lt;/code&amp;gt; and read the dipole databases generated in an optical absorption calculation by yambo. Keep in mind that from now on we will use the &amp;quot;BSE&amp;quot; yambo SAVE generated in the [[#Command line: generating the Yambo SAVE|first section]].&lt;br /&gt;
&lt;br /&gt;
The databases written after a calculation of optical properties with yambo (dipoles, static screening, excitons) are in the directory &amp;lt;code&amp;gt;BSE_saves/BSE_databases&amp;lt;/code&amp;gt;. Here we will also find &amp;lt;code&amp;gt;ndb.dipoles&amp;lt;/code&amp;gt; which is needed now, since it contains the matrix elements d_{vck}(\alpha) where vk and ck are the valence and electron states involved in the transition and \alpha the polarisation direction of the external electric field.&lt;br /&gt;
&lt;br /&gt;
In order to read it in python we use the Yambopy class &amp;lt;code&amp;gt;YamboDipolesDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
 ydip = YamboDipolesDB(ylat,save=&#039;path/to/BSE/databases&#039;,filename=&#039;ndb.dipoles&#039;)&lt;br /&gt;
(notice that it requires a previous instance of &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
In addition, in order to read the Kohn-Sham energies, we can also instance the &amp;lt;code&amp;gt;YamboElectronsDB&amp;lt;/code&amp;gt; as&lt;br /&gt;
 yel = YamboElectronsDB.from_db_file(folder=&#039;path/to/SAVE&#039;) &lt;br /&gt;
&lt;br /&gt;
The object &amp;lt;code&amp;gt;ydip&amp;lt;/code&amp;gt; now has a method that permits to retrieve the independent-particle absorption spectrum with customly chosen energy range, steps, and broadening:&lt;br /&gt;
 w, eps2 = ydip.ip_eps2(yel)&lt;br /&gt;
&lt;br /&gt;
In order to see all this in action, take a look at the &amp;lt;code&amp;gt;dipoles_plot.py&amp;lt;/code&amp;gt; script. You will see that it performs two plots:&lt;br /&gt;
* Plot of |d(k)| in the BZ for selected v,c and \alpha (we choose the layer plane &#039;xy&#039;) [&amp;lt;code&amp;gt;Kspace_Plot=True&amp;lt;/code&amp;gt;]. From this plot you can appreciate which sections of the BZ contribute the most to the absorption rate.&lt;br /&gt;
* Plot of the independent-particles absorption spectrum [&amp;lt;code&amp;gt;Absorption_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
You can play with the indices and the plot parameters to check what happens.&lt;br /&gt;
&lt;br /&gt;
[[File:Dipoles hbn2.png|YamboDipolesDB plot from yambopy tutorial|500px]]&lt;br /&gt;
&lt;br /&gt;
=== Exciton intro 1: read and sort data ===&lt;br /&gt;
In this section we will use both the script &amp;lt;code&amp;gt;exc_read.py&amp;lt;/code&amp;gt; and the command line in order to read the exciton data resulting from a BSE calculation to familiarise with their structure. This time we are going to read the &amp;lt;code&amp;gt;ndb.BS_diago_Q*&amp;lt;/code&amp;gt; databases which correspond to BSE calculations at various momenta Q (Q=1 being the zero-momentum optical absorption limit - notice that python indexing starts from 0, while the databases are counted starting from 1).&lt;br /&gt;
&lt;br /&gt;
In order to read them in python we use the Yambopy class &amp;lt;code&amp;gt;YamboExcitonDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
 yexc = YamboExcitonDB.from_db_file(ylat,filename=f&#039;path/to/BSE/databases/ndb.BS_diago_Q{i}&#039;)&lt;br /&gt;
(where i is the number of BS_diago_Qi file. Notice that it requires a previous instance of &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Now the &amp;lt;code&amp;gt;yexc&amp;lt;/code&amp;gt; object contains information about the exciton energies (&amp;lt;code&amp;gt;yexc.eigenvalues&amp;lt;/code&amp;gt;), wave functions (&amp;lt;code&amp;gt;yexc.eigenvectors&amp;lt;/code&amp;gt;) and intensities (&amp;lt;code&amp;gt;yexc.l_residuals&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yexc.r_residuals&amp;lt;/code&amp;gt;) for Qpoint i_Q. You can start by keeping &amp;lt;code&amp;gt;Q1&amp;lt;/code&amp;gt; which is the optical limit and then check other momenta.&lt;br /&gt;
&lt;br /&gt;
The exciton wave function components A_{vck}^{\lambda Q} (\lambda being the exciton index) are stored as A_{t}^{\lambda} in each Q-dependent database, with t being the transition index grouping the single-particle indices vck. Therefore, &amp;lt;code&amp;gt;yexc.eigenvectors&amp;lt;/code&amp;gt; is an array with (N_excitons,N_transitions) dimension. In order to make the connection t-&amp;gt;kcv, the table &amp;lt;code&amp;gt;yexc.table&amp;lt;/code&amp;gt; provides k,v,c and spin indices corresponding to each transition.&lt;br /&gt;
&lt;br /&gt;
In order to get a clearer picture, take a look at the script &amp;lt;code&amp;gt;exc_read.py&amp;lt;/code&amp;gt;. Run it and try to understand the outputs.&lt;br /&gt;
  $ python exc_read.py&lt;br /&gt;
&lt;br /&gt;
Actually, we can produce output files with the sorted exciton energies in a much more convenient way by using the command line instruction &amp;lt;code&amp;gt;exc-sort&amp;lt;/code&amp;gt;. Check its syntax via:&lt;br /&gt;
 $ yambopy exc-sort -h&lt;br /&gt;
&lt;br /&gt;
Then, we run it for our specific calculation with:&lt;br /&gt;
 $ yambopy exc-sort --save BSE_saves/YAMBO_saves/SAVE -J BSE_saves/BSE_databases --iqpt 1&lt;br /&gt;
&lt;br /&gt;
Recall that that the path given &amp;lt;code&amp;gt;--save&amp;lt;/code&amp;gt; must be the directory that contains the &amp;lt;code&amp;gt;ns.db1&amp;lt;/code&amp;gt; yambo database (usually called... &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt;). The path given to &amp;lt;code&amp;gt;-J&amp;lt;/code&amp;gt; must be the directory that cotains the results of the BSE calculation, namely the &amp;lt;code&amp;gt;ndb.BS_diago_Q1&amp;lt;/code&amp;gt; file. &lt;br /&gt;
This should produce the &amp;lt;code&amp;gt;o-BSE_databases.exc_qpt1_sorted_E.dat&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;o-BSE_databases.exc_qpt1_sorted_I.dat&amp;lt;/code&amp;gt; output files for you to inspect. These are very useful as they allow for identification of degenerate states and degree of optical activity. You will see that in our system most states are doubly degenerate, a byproduct of crystal symmetry. This is an updated version of the ypp exciton analysis that you can find [[How to analyse excitons#Sort the excitonic eigenvalues|here]].&lt;br /&gt;
&lt;br /&gt;
=== Exciton intro 2: symmetry analysis and wavefunction plot in real space ===&lt;br /&gt;
&lt;br /&gt;
==== Symmetries of excitons====&lt;br /&gt;
We can analyse the symmetries of the excitonic wavefunctions in terms of irreducible representation of the point group of the system (if at Q=0) or the Q little group. For more information, the methodology is explained in Ref. &amp;lt;ref&amp;gt;Symmetries of excitons, M. Nalabothula et al., [https://arxiv.org/abs/2511.21540 preprint arXiv]&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
We use the &amp;lt;code&amp;gt;exc-irrep&amp;lt;/code&amp;gt; command line option, check the arguments with:&lt;br /&gt;
 $ yambopy exc-irrep -h&lt;br /&gt;
&lt;br /&gt;
We know from the previous section (by inspecting the sorted energies) that the first four BSE eigenvalues correspond to two doubly-degenerate bright states. Let us analyse their symmetry by running&lt;br /&gt;
 $ yambopy exc-irrep --path BSE_saves/YAMBO_saves -J BSE_saves/BSE_databases --iqpt 1 --nstates 4&lt;br /&gt;
&lt;br /&gt;
This command first loads the electronic wave functions and calculated the electronic representation matrices (called &amp;lt;code&amp;gt;Dmats&amp;lt;/code&amp;gt; in the code). As a second step, they are used to compute the &#039;&#039;&#039;excitonic&#039;&#039;&#039; representation matrices. &lt;br /&gt;
&lt;br /&gt;
We obtain the following output:&lt;br /&gt;
&lt;br /&gt;
 ========================================&lt;br /&gt;
 Group theory analysis for Q point : (0.000000, 0.000000, 0.000000)&lt;br /&gt;
 ****************************************&lt;br /&gt;
 Little group :  D3h&lt;br /&gt;
 Little group symmetries :  [ 1  2  3  4  5  6  7  8  9 10 11 12]&lt;br /&gt;
 Classes (symmetry indices in each class):&lt;br /&gt;
                E    :  [1]&lt;br /&gt;
             2S_3    :  [2 6]&lt;br /&gt;
             2C_3    :  [3 5]&lt;br /&gt;
          sigma_h    :  [4]&lt;br /&gt;
             3C_2    :  [ 7  9 11]&lt;br /&gt;
         3sigma_v    :  [ 8 10 12]&lt;br /&gt;
 &lt;br /&gt;
 ====== Exciton representations ======&lt;br /&gt;
 Energy (eV),  degeneracy  : representation&lt;br /&gt;
 ----------------------------------------&lt;br /&gt;
 1.9139                2  :  E&#039;&lt;br /&gt;
 2.5988                2  :  E&#039;&lt;br /&gt;
 ****************************************&lt;br /&gt;
&lt;br /&gt;
This is similar to the group theory analysis done by Quantum Espresso on the electronic states, and is actually analogous to the one performed for the phonon modes of crystals. We see that the first two states transform as the E&#039; representation of the D3h point group of the crystal. By optical selection rules, only states with this symmetry can form absorption peaks in monolayer BN when light is polarized along the layer plane.&lt;br /&gt;
&lt;br /&gt;
We could go further and calculate the total crystal angular momentum of these states, while also rotate the degenerate exciton states so that they are both eigenvectors of the BSE Hamiltonian and the total crystal angular momentum operator. This is very useful for analyses involving selection rules, exciton-boson couplings, chirality, etc. This is an advanced topic and will not be covered, nonetheless an example script is provided in the tutorial folder called &amp;lt;code&amp;gt;total_crystal_angular_momentum_exciton.py&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; What to do when symmetry analysis does not seem to work well &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Check for warnings during execution. If the BSE calculation was done with a response function that breaks the symmetries (such as the longitudinal response in place of the transverse one at q=0), that may explain the issues.&lt;br /&gt;
&lt;br /&gt;
* If the exciton density of states is very high (such as for a bulk 3D system or for a 2D system at higher energies in the optical spectrum), the analyser may fail to resolve degenerate states, and incorporate a bunch of states together. The symmetry analysis will still be performed but the representation labels will appear as summed. In severe cases, the code may crash. You can try to get a better result by carefully selecting the degeneracy tolerance with &amp;lt;code&amp;gt;degen_tol&amp;lt;/code&amp;gt; and restricting the number of states with &amp;lt;code&amp;gt;nstates&amp;lt;/code&amp;gt; in the command line options.&lt;br /&gt;
&lt;br /&gt;
====Exciton wave functions in real space====&lt;br /&gt;
We can also plot the wave functions of the exciton states on the crystal lattice. In practice, what we do is set the position of the hole at a &amp;quot;physical&amp;quot; point, and then visualize the resulting electronic distribution:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;I^{e}_{\lambda \mathbf{Q}}(\mathbf{r}_e)= |\Psi_{\alpha \mathbf{Q}}(\mathbf{r}_e,\mathbf{r}_h=\mathbf{r}_0)|^2&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let us focus on the lowest exciton state, which gives rise to the largest peak in absorption (see the last part of the tutorial). We will set the hole position on top of a nitrogen atom, since that&#039;s where the &amp;lt;math&amp;gt;p_z&amp;lt;/math&amp;gt; orbitals where the hole comes from are mostly localized.&lt;br /&gt;
&lt;br /&gt;
If we don&#039;t know the correct coordinates, we can modify the &amp;lt;code&amp;gt;bz_plot.py&amp;lt;/code&amp;gt; script by adding (after instancing the lattice object):&lt;br /&gt;
 for iat in range(len(ylat.atomic_numbers)): print(ylat.atomic_numbers[iat],ylat.red_atomic_positions[iat])&lt;br /&gt;
which will print&lt;br /&gt;
 5 [0.6666667 0.3333333 0.       ]&lt;br /&gt;
 7 [-0.6666667 -0.3333333  0.       ]&lt;br /&gt;
&lt;br /&gt;
In order to make the plot, we have to give yambopy the same inputs that are used in the equivalent [[How to analyse excitons#Plot the exciton spatial distribution| ypp calculation]]. First, let&#039;s check all the options via&lt;br /&gt;
 $ yambopy exc-wf -h&lt;br /&gt;
&lt;br /&gt;
Then, we can run our calculation (by selecting a 9x9x1 supercell and a 30 Ry cutoff) as &lt;br /&gt;
 $ yambopy exc-wf --path BSE_saves/YAMBO_saves -J BSE_saves/BSE_databases --iqpt 1 --iexe 1 --supercell 9 9 1 --wfc_cutoff 30 --hole 0.33333333 0.66666667 0.03&lt;br /&gt;
&lt;br /&gt;
Yambopy will produce a *.cube file that can be visualized with VESTA, xcrysden or the like, producing a figure similar to the one below.&lt;br /&gt;
&lt;br /&gt;
The example script &amp;lt;code&amp;gt;exc_real_wf.py&amp;lt;/code&amp;gt;, which runs the same calculation by explicitly calling the necessary functions, will give you more info about what is happening behind the scenes.&lt;br /&gt;
&lt;br /&gt;
[[File:Exc BN yambopy.png|YamboExcitonDB exciton wave function|400px]]&lt;br /&gt;
&lt;br /&gt;
We see that electron is localised in &amp;lt;math&amp;gt;p_z&amp;lt;/math&amp;gt;-like distributions on top of boron atoms around the nitrogen where the hole is set.&lt;br /&gt;
&lt;br /&gt;
=== Exciton intro 3: plot exciton weights on k-BZ and (interpolated) band structure ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;exc_kspace_plot.py&amp;lt;/code&amp;gt; and work with the quantities defined in the previous section.&lt;br /&gt;
&lt;br /&gt;
For now, only the i_Q=0 case is implemented in this section.&lt;br /&gt;
We want to check the relative importance of the various (vk-&amp;gt;ck) electronic transitions in forming a certain excitonic state. &lt;br /&gt;
&lt;br /&gt;
Since many excitonic states are degenerate, we first need to tell Yambopy which states we want to check. For example, in monolayer hexagonal boron nitride, the lowest-bound exciton - forming the main peak in the BSE absorption spectrum - is doubly degenerate. In order to analyse it, in the &amp;lt;code&amp;gt;exc_kspace_plot.py&amp;lt;/code&amp;gt; script we set&lt;br /&gt;
 states = [1,2]&lt;br /&gt;
(we can also set [3,4] to check the second excitonic state, and then [5] for the non-degenerate third state, and so on; we can check degeneracies by printing the energies using the script &amp;lt;code&amp;gt;exc_read.py&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
In order to make a band structure plot, it is necessary to read the band energies, for example with the &amp;lt;code&amp;gt;YamboSaveDB&amp;lt;/code&amp;gt; class&lt;br /&gt;
 yel = YamboSaveDB.from_db_file(folder=&#039;path/to/SAVE&#039;)&lt;br /&gt;
and specify the path in the BZ using crystal coordinates via the &amp;lt;code&amp;gt;Path&amp;lt;/code&amp;gt; function:   &lt;br /&gt;
 npoints = 20&lt;br /&gt;
 path = Path([ [[  0.0,  0.0,  0.0],&#039;$\Gamma$&#039;],&lt;br /&gt;
               [[  0.5,  0.0,  0.0],&#039;M&#039;],&lt;br /&gt;
               [[1./3.,1./3.,  0.0],&#039;K&#039;],&lt;br /&gt;
               [[  0.0,  0.0,  0.0],&#039;$\Gamma$&#039;]],&lt;br /&gt;
               [int(npoints*2),int(npoints),int(sqrt(5)*npoints)] )&lt;br /&gt;
&lt;br /&gt;
Now let&#039;s take a closer look at the &amp;lt;code&amp;gt;exc_kspace_plot.py&amp;lt;/code&amp;gt; script. You will see that it performs three plots:&lt;br /&gt;
* Plot of |A(k)| in the k-BZ for the selected exciton state. You can see how most contributions come from the area around K and the MK direction [&amp;lt;code&amp;gt;Kspace_Plot=True&amp;lt;/code&amp;gt;]. &lt;br /&gt;
* Plot of |A(v,c,k)| on the electronic band structure for the selected exciton state. Here you can better see how the top valence and bottom conduction around MK are mostly involved [&amp;lt;code&amp;gt;Bands_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Plot of interpolated |A(v,c,k)| on the interpolated electronic band structure for the selected exciton state [&amp;lt;code&amp;gt;Bands_Plot_Interpolated=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
As always, try to play with the parameters, for example by changing the excitonic states to analyse.&lt;br /&gt;
&lt;br /&gt;
[[File:Exc bands1 hbn.jpg|YamboExcitonDB plot from yambopy tutorial|300px| Uninterpolated exciton weights on top of band structure]][[File:Exc bands2 hbn.jpg|YamboExcitonDB plot from yambopy tutorial|300px]]&lt;br /&gt;
&lt;br /&gt;
=== Exciton intro 4: plot BSE optical absorption with custom options ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;exc_abs_plot.py&amp;lt;/code&amp;gt; and work with the quantities defined in the previous sections.&lt;br /&gt;
&lt;br /&gt;
The class &amp;lt;code&amp;gt;YamboExcitonDB&amp;lt;/code&amp;gt; also enables us, of course, to read the dielectric function eps(w) and print absorption and related spectra in python.&lt;br /&gt;
&lt;br /&gt;
The advantages over using the standard human-readable yambo outputs are mainly two:&lt;br /&gt;
# We can freely select energy ranges, energy steps, peak broadenings and number of excitonic states included without having to rerun the &amp;lt;code&amp;gt;yambo&amp;lt;/code&amp;gt; executable every time. This reduces the chance of mistakenly editing the yambo input and allows for greater freedom since these plots can now be done in your local machine without having to transfer the output data from a remote cluster.&lt;br /&gt;
# The dielectric function constructed from netCDF database variables has a much higher precision (number of significant digits) than the human readable output, which may be important if you want to perform additional operations in python (e.g., computing refractive index, reflectivity and other optical spectra from it, performing finite-difference derivatives, etc).&lt;br /&gt;
&lt;br /&gt;
We can read eps(w) as a &amp;lt;code&amp;gt;numpy&amp;lt;/code&amp;gt; array with the specified options as (energy values are in eV):&lt;br /&gt;
 w, eps = yexc.get_chi(nexcitons=&#039;all&#039;,emin=0,emax=7,estep=0.005,broad=0.04)&lt;br /&gt;
Or, you can directly prepare a plot of its imaginary part with&lt;br /&gt;
 w, chi = yexc.plot_chi_ax(ax,nexcitons=&#039;all&#039;,emin=0,emax=7,estep=0.005,broad=0.04)&lt;br /&gt;
where &amp;lt;code&amp;gt;ax&amp;lt;/code&amp;gt; is a previously defined &amp;lt;code&amp;gt;Axes&amp;lt;/code&amp;gt; object from &amp;lt;code&amp;gt;matplotlib&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In order to see how this works, let&#039;s take a look at the &amp;lt;code&amp;gt;exc_abs_plot.py&amp;lt;/code&amp;gt; script.&lt;br /&gt;
You will see that it performs the two operations described above:&lt;br /&gt;
* Plotting the BSE absorption spectrum [&amp;lt;code&amp;gt;Absorption_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Reading the complex dielectric function.&lt;br /&gt;
&lt;br /&gt;
Try to customise the plots by changing the &amp;lt;code&amp;gt;nexcitons&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;emin&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;emax&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;estep&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;broad&amp;lt;/code&amp;gt; parameters.&lt;br /&gt;
&lt;br /&gt;
[[File:Absalpha.png|Yambo alpha_2D tutorial plot|700px]]&lt;br /&gt;
&lt;br /&gt;
==Links==&lt;br /&gt;
* Back to [[Rome 2023#Tutorials]]&lt;br /&gt;
* Back to [[ICTP 2022#Tutorials]]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;/div&gt;</summary>
		<author><name>FulvioPaleari</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Exciton-phonon_coupling_and_luminescence&amp;diff=9344</id>
		<title>Exciton-phonon coupling and luminescence</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Exciton-phonon_coupling_and_luminescence&amp;diff=9344"/>
		<updated>2026-03-13T14:56:00Z</updated>

		<summary type="html">&lt;p&gt;FulvioPaleari: /* Step 6: obtain the electron-phonon matrix elements */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:Tdgw-phonon-usc-01-1024x829.jpg|thumb|right|400px|(c) Zhenglu Li, University of Southern California]]&lt;br /&gt;
&lt;br /&gt;
In this advanced tutorial, we will calculate exciton-phonon interactions from first principles by interfacing DFPT (for phonon calculations) and BSE (for exciton calculations).&lt;br /&gt;
&lt;br /&gt;
The DFTP calculations are run with Quantum ESPRESSO, while the many-body GW-BSE calculations are run with Yambo. Finally, the exciton-phonon interaction will be obtained by combining and postprocessing the databases computed in the two previous runs. The great advantage of this workflow is that the calculations can be run in the irreducible Brillouin zones both for the electronic momenta (&#039;&#039;&#039;k&#039;&#039;&#039;) and the transfer momenta (&#039;&#039;&#039;Q&#039;&#039;&#039;, &#039;&#039;&#039;q&#039;&#039;&#039;) of excitons and phonons, thus speeding up considerably the jobs while reducing the IO and memory load.&lt;br /&gt;
&lt;br /&gt;
We will first compute the exciton-phonon coupling matrix elements: these are the building blocks needed to construct experimental observables such as phonon-assisted optical spectra (such as luminescence), Raman spectra and exciton lifetimes. We will do this in the case of monolayer MoS&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;, a 2D system with large spin-orbit interaction.&lt;br /&gt;
&lt;br /&gt;
As an example of application, we will consider the case of phonon-assisted luminescence. We will do this in the case of bulk hBN, a layered indirect insulator with strong electron-phonon coupling.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; this tutorial will be updated when new exc-ph tools become available in Yambopy (including full-python postprocessing, Raman spectra, interpolated lifetimes, etc).&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
This is an advanced topic: we assume that you already know something about the theory&amp;lt;ref name=&amp;quot;toyozawa2003&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;antonius2017&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;cudazzo2020&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;paleari2019_PhD&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;paleari2022&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;lechifflart2023_PhD&amp;quot; /&amp;gt; and applications&amp;lt;ref name=&amp;quot;paleari2019&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;cannuccia2019&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;chen2020&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;zanfrognini2023&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;lechifflart2023&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;chan2023&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;marini2024&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;murali2025&amp;quot; /&amp;gt; of exciton-phonon physics. &lt;br /&gt;
&lt;br /&gt;
Also, we assume that you already know how to run both a basic &#039;&#039;&#039;Yambo&#039;&#039;&#039; GW-BSE calculation and a DFPT phonon calculation with &#039;&#039;&#039;Quantum ESPRESSO&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Besides the QE executables &amp;lt;code&amp;gt;pw.x&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ph.x&amp;lt;/code&amp;gt;, we also use the yambo phonon-specific executable &amp;lt;code&amp;gt;yambo_ph&amp;lt;/code&amp;gt; and the python utility &#039;&#039;&#039;Yambopy&#039;&#039;&#039;. The auxiliary code &#039;&#039;&#039;LetzElPhC&#039;&#039;&#039; (executable &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt;) will be used to obtain the electron-phonon matrix elements by reading the same electronic wavefunctions used by Yambo (and stored in the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory), while also making full use of crystal symmetries. [https://github.com/yambo-code/LetzElPhC LetzElPhC] will be run by Yambopy, but it must nonetheless be installed. Finally, the exciton-phonon properties can be computed either using &amp;lt;code&amp;gt;yambo_ph&amp;lt;/code&amp;gt; or using Yambopy itself. Both cases will be covered in this tutorial.&lt;br /&gt;
&lt;br /&gt;
[[File:Workflow scheme.png|800px|center]]&lt;br /&gt;
&lt;br /&gt;
== Step 0: Pseudopotentials, equilibrium structure and convergence ==&lt;br /&gt;
&lt;br /&gt;
In a real calculation, it is important to ensure that both the pseudopotential and the lattice parameters that we are using are compatible and perform well for the electronic excited states and for the lattice vibrations simultaneously. Furthermore, you have to make sure that the wave function cutoff &amp;lt;code&amp;gt;ecutwfc&amp;lt;/code&amp;gt; is converged with respect to the DFPT step and not just to the DFT one. This is in addition to the other customary convergence tests for DFT, DFPT, GW and BSE calculations.&lt;br /&gt;
&lt;br /&gt;
This is often the most time-demanding step when starting on a new system.&lt;br /&gt;
&lt;br /&gt;
For the sake of this tutorial, we assume that we have already done all these tests and we are starting the final workflow to get the exciton-phonon properties.&lt;br /&gt;
&lt;br /&gt;
== Step 1: scf calculation ==&lt;br /&gt;
&lt;br /&gt;
First of all, we run a standard scf calculation with &amp;lt;code&amp;gt;pw.x&amp;lt;/code&amp;gt; for Yambo. We stick with non-symmorphic symmetries. At the end, we will have the QE &amp;lt;code&amp;gt;save&amp;lt;/code&amp;gt; directory.&lt;br /&gt;
&lt;br /&gt;
This is the input &amp;lt;code&amp;gt;mos2.scf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 &amp;amp;control&lt;br /&gt;
           wf_collect = .true.,&lt;br /&gt;
          calculation = &amp;quot;scf&amp;quot;,&lt;br /&gt;
            verbosity = &#039;high&#039;,&lt;br /&gt;
           pseudo_dir = &#039;$PSEUDO_DIR&#039;,&lt;br /&gt;
               prefix = &amp;quot;mos2&amp;quot;,&lt;br /&gt;
               outdir = &#039;.&#039;,&lt;br /&gt;
  /&amp;amp;end&lt;br /&gt;
  &amp;amp;system&lt;br /&gt;
              ecutwfc = 100.0,&lt;br /&gt;
          occupations = &#039;fixed&#039;,&lt;br /&gt;
                ibrav = 4,&lt;br /&gt;
            celldm(1) = 5.9000811881,&lt;br /&gt;
            celldm(3) = 6.7795677253,&lt;br /&gt;
                  nat = 3,&lt;br /&gt;
                 ntyp = 2,&lt;br /&gt;
             lspinorb = .true.&lt;br /&gt;
             noncolin = .true.&lt;br /&gt;
             assume_isolated = &#039;2D&#039;&lt;br /&gt;
         force_symmorphic = .true.&lt;br /&gt;
  /&amp;amp;end&lt;br /&gt;
  &amp;amp;electrons&lt;br /&gt;
     electron_maxstep = 200,&lt;br /&gt;
          mixing_beta = 0.7,&lt;br /&gt;
             conv_thr = 1.d-08,&lt;br /&gt;
  /&amp;amp;end&lt;br /&gt;
   ATOMIC_SPECIES&lt;br /&gt;
    Mo  95.940      Mo_ONCV_PBE_FR-1.0.upf&lt;br /&gt;
    S    32.065     S_ONCV_PBE_FR-1.1.upf&lt;br /&gt;
   ATOMIC_POSITIONS { crystal }&lt;br /&gt;
 Mo       0.333333333   0.666666667   0.000000000&lt;br /&gt;
 S        0.666666667   0.333333333   0.073413577&lt;br /&gt;
 S        0.666666667   0.333333333  -0.073413577&lt;br /&gt;
  K_POINTS { automatic }&lt;br /&gt;
 6 6 1 0 0 0&lt;br /&gt;
&lt;br /&gt;
Here we are using full relativistic pseudopotentials from the SG-15 database.&lt;br /&gt;
&lt;br /&gt;
We can run it on our machine (for example using 4 MPI tasks) as:&lt;br /&gt;
&lt;br /&gt;
 mpirun -np 4 pw.x -inp mos2.scf &amp;gt; scf.out&lt;br /&gt;
&lt;br /&gt;
== Step 2: nscf calculation for Yambo ==&lt;br /&gt;
&lt;br /&gt;
Copy the QE &amp;lt;code&amp;gt;save&amp;lt;/code&amp;gt; directory from the scf calculation and run the nscf calculation for any number of empty states, with the correct &amp;lt;code&amp;gt;k&amp;lt;/code&amp;gt;-grid we want to use in Yambo. Here we are using a badly underconverged grid of 6x6x1.&lt;br /&gt;
&lt;br /&gt;
This reciprocal-space grid will also match the momentum transfer &amp;lt;code&amp;gt;q&amp;lt;/code&amp;gt; grid on which excitons and phonons will be defined!&lt;br /&gt;
&lt;br /&gt;
The electronic wavefunctions computed at this step and stored in the new nscf &amp;lt;code&amp;gt;save&amp;lt;/code&amp;gt; directory will be used both by Yambo and by the electron-phonon code: this is important because using different sets of wavefunctions would lead to a phase mismatch issue in the exciton-phonon matrix elements.&lt;br /&gt;
&lt;br /&gt;
The nscf input &amp;lt;code&amp;gt;mos2.nscf&amp;lt;/code&amp;gt; is&lt;br /&gt;
 &amp;amp;control&lt;br /&gt;
           wf_collect = .true.,&lt;br /&gt;
          calculation = &amp;quot;nscf&amp;quot;,&lt;br /&gt;
            verbosity = &#039;high&#039;,&lt;br /&gt;
           pseudo_dir = &#039;$PSEUDO_DIR&#039;,&lt;br /&gt;
               prefix = &amp;quot;mos2&amp;quot;,&lt;br /&gt;
               outdir = &#039;.&#039;,&lt;br /&gt;
  /&amp;amp;end&lt;br /&gt;
  &amp;amp;system&lt;br /&gt;
              ecutwfc = 100.0,&lt;br /&gt;
          occupations = &#039;fixed&#039;,&lt;br /&gt;
                ibrav = 4,&lt;br /&gt;
            celldm(1) = 5.9000811881,&lt;br /&gt;
            celldm(3) = 6.7795677253,&lt;br /&gt;
                  nat = 3,&lt;br /&gt;
                 ntyp = 2,&lt;br /&gt;
             lspinorb = .true.&lt;br /&gt;
             noncolin = .true.&lt;br /&gt;
                nbnd  = 250&lt;br /&gt;
             assume_isolated = &#039;2D&#039;&lt;br /&gt;
         force_symmorphic = .true.&lt;br /&gt;
  /&amp;amp;end&lt;br /&gt;
  &amp;amp;electrons&lt;br /&gt;
     electron_maxstep = 200,&lt;br /&gt;
          mixing_beta = 0.7,&lt;br /&gt;
             conv_thr = 1.d-08,&lt;br /&gt;
  /&amp;amp;end&lt;br /&gt;
   ATOMIC_SPECIES&lt;br /&gt;
    Mo  95.940      Mo_ONCV_PBE_FR-1.0.upf&lt;br /&gt;
    S    32.065     S_ONCV_PBE_FR-1.1.upf&lt;br /&gt;
   ATOMIC_POSITIONS { crystal }&lt;br /&gt;
 Mo       0.333333333   0.666666667   0.000000000&lt;br /&gt;
 S        0.666666667   0.333333333   0.073413577&lt;br /&gt;
 S        0.666666667   0.333333333  -0.073413577&lt;br /&gt;
  K_POINTS { automatic }&lt;br /&gt;
 6 6 1 0 0 0&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Again, we run the calculation&lt;br /&gt;
&lt;br /&gt;
 mpirun -np 4 pw.x -inp mos2.nscf &amp;gt; nscf.out&lt;br /&gt;
&lt;br /&gt;
== Step 3: dvscf phonon calculation ==&lt;br /&gt;
&lt;br /&gt;
Now we run the phonon calculation.&lt;br /&gt;
&lt;br /&gt;
Copy the &amp;lt;code&amp;gt;save&amp;lt;/code&amp;gt; directory from the &#039;&#039;&#039;scf&#039;&#039;&#039; calculation and run &amp;lt;code&amp;gt;ph.x&amp;lt;/code&amp;gt; for a dvscf calculation with a standard &amp;lt;code&amp;gt;q&amp;lt;/code&amp;gt;-grid matching the &amp;lt;code&amp;gt;k&amp;lt;/code&amp;gt;-grid we wanna use in Yambo.&lt;br /&gt;
&lt;br /&gt;
At the end, we will have the &amp;lt;code&amp;gt;_ph0&amp;lt;/code&amp;gt; directory containing the variation of the self-consistent potential, &amp;lt;math&amp;gt;\Delta V_{SCF}(q)&amp;lt;/math&amp;gt;, and the &amp;lt;code&amp;gt;*.dyn&amp;lt;/code&amp;gt; files with the phonon energies and eigenvectors.&lt;br /&gt;
&lt;br /&gt;
NB: one could further refine the phonon energies by enforcing the acoustic sum rule, including non-analytic long-range contributions, interpolating to finer grids... all of this can be done within Quantum ESPRESSO and will not be covered in this version of the tutorial.&lt;br /&gt;
&lt;br /&gt;
The input is &amp;lt;code&amp;gt;mos2.dvscf&amp;lt;/code&amp;gt;:&lt;br /&gt;
 &lt;br /&gt;
 mos2_dvscf&lt;br /&gt;
 &amp;amp;inputph&lt;br /&gt;
   tr2_ph=1.0d-12,&lt;br /&gt;
   verbosity=&#039;high&#039;&lt;br /&gt;
   prefix=&#039;mos2&#039;,&lt;br /&gt;
   fildvscf = &#039;mos2-dvscf&#039;,&lt;br /&gt;
   electron_phonon = &#039;dvscf&#039;,&lt;br /&gt;
   fildyn=&#039;mos2.dyn&#039;,&lt;br /&gt;
   epsil=.false.,&lt;br /&gt;
   ldisp=.true.,&lt;br /&gt;
   recover=.true.,&lt;br /&gt;
   nq1=6,&lt;br /&gt;
   nq2=6,&lt;br /&gt;
   nq3=1&lt;br /&gt;
 /&lt;br /&gt;
&lt;br /&gt;
And now we run as&lt;br /&gt;
&lt;br /&gt;
 nohup mpirun -np 8 ph.x -inp mos2.dvscf &amp;gt; dvscf.out &amp;amp;&lt;br /&gt;
&lt;br /&gt;
This time we use nohup and more processes because this calculation may take some time. It is a good idea to set &amp;lt;code&amp;gt;recover=.true.&amp;lt;/code&amp;gt; as in a real calculation you will easily breach walltime, and in this way you can safely restart.&lt;br /&gt;
&lt;br /&gt;
== Step 4: create Yambo &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory ==&lt;br /&gt;
&lt;br /&gt;
This is just the standard Yambo initialization: run &lt;br /&gt;
 &lt;br /&gt;
 p2y &lt;br /&gt;
&lt;br /&gt;
and then &lt;br /&gt;
&lt;br /&gt;
 yambo &lt;br /&gt;
&lt;br /&gt;
in the &#039;&#039;&#039;nscf&#039;&#039;&#039; &amp;lt;code&amp;gt;save&amp;lt;/code&amp;gt; folder and then move the newly generated &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory to a convenient place.&lt;br /&gt;
&lt;br /&gt;
== Step 5: run a BSE calculation ==&lt;br /&gt;
&lt;br /&gt;
Now we switch from QE to Yambo. Here, we forgo the GW step for simplicity (we can use a scissor operator to open the band gap).&lt;br /&gt;
&lt;br /&gt;
This calculation has a couple of differences with respect to a standard BSE calculation for optical absorption. We can look at the input file &amp;lt;code&amp;gt;bse.in&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Runlevels&amp;lt;/span&amp;gt;&lt;br /&gt;
 optics                       # [R OPT] Optics&lt;br /&gt;
 rim_cut                      # [R RIM CUT] Coulomb potential&lt;br /&gt;
 bss                          # [R BSS] Bethe Salpeter Equation solver&lt;br /&gt;
 em1s                         # [R Xs] Static Inverse Dielectric Matrix&lt;br /&gt;
 bse                          # [R BSE] Bethe Salpeter Equation.&lt;br /&gt;
 bsk                          # [R BSK] Bethe Salpeter Equation kernel&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# RIM and cutoff settings&amp;lt;/span&amp;gt;&lt;br /&gt;
 RandQpts=1000000             # [RIM] Number of random q-points in the BZ&lt;br /&gt;
 RandGvec= 100            RL    # [RIM] Coulomb interaction RS components&lt;br /&gt;
 CUTGeo= &amp;quot;slab z&amp;quot;               # [CUT] Coulomb Cutoff geometry: box/cylinder/sphere X/Y/Z/XY..&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Static screening&amp;lt;/span&amp;gt;&lt;br /&gt;
 X_and_IO_CPU= &amp;quot;1 1 4 2 1&amp;quot;       # [PARALLEL] CPUs for each role&lt;br /&gt;
 X_and_IO_ROLEs= &amp;quot;q g k c v&amp;quot;      # [PARALLEL] CPUs roles (q,g,k,c,v)&lt;br /&gt;
 X_and_IO_nCPU_LinAlg_INV=-1      # [PARALLEL] CPUs for Linear Algebra (if -1 it is automatically set)&lt;br /&gt;
 Chimod= &amp;quot;hartree&amp;quot;            # [X] IP/Hartree/ALDA/LRC/BSfxc&lt;br /&gt;
 % BndsRnXs&lt;br /&gt;
    1 |  200 |                 # [Xs] Polarization function bands&lt;br /&gt;
 %&lt;br /&gt;
 % LongDrXs&lt;br /&gt;
  1.000000 | 1.000000 | 1.000000 |        # [Xs] [cc] Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 NGsBlkXs= 8000            mRy    # [Xs] Response block size&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# BSE&amp;lt;/span&amp;gt;&lt;br /&gt;
 BS_CPU= &amp;quot;4.1.2&amp;quot;                   # [PARALLEL] CPUs for each role&lt;br /&gt;
 BS_ROLEs= &amp;quot;k.eh.t&amp;quot;                 # [PARALLEL] CPUs roles (k,eh,t)&lt;br /&gt;
 BS_nCPU_diago=4              # [PARALLEL] CPUs for matrix diagonalization&lt;br /&gt;
 BSEmod= &amp;quot;causal&amp;quot;             # [BSE] resonant/causal/coupling&lt;br /&gt;
 BSKmod= &amp;quot;SEX&amp;quot;                # [BSE] IP/Hartree/HF/ALDA/SEX/BSfxc&lt;br /&gt;
 BSSmod= &amp;quot;d&amp;quot;                  # [BSS] (h)aydock/(d)iagonalization/(s)lepc/(i)nversion/(t)ddft`&lt;br /&gt;
 BSENGexx=  40000      mRy    # [BSK] Exchange components&lt;br /&gt;
 ALLGexx                      # [BSS] Force the use use all RL vectors for the exchange part&lt;br /&gt;
 BSENGBlk=  8000       mRy    # [BSK] Screened interaction block size&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;Lkind=&amp;quot;full&amp;quot;                  #[BSE,X] bar(default)/full/tilde&amp;lt;/span&amp;gt;&lt;br /&gt;
 % KfnQP_E&lt;br /&gt;
  1.000000 | 1.000000 | 1.000000 |        # [EXTQP BSK BSS] E parameters  (c/v) eV|adim|adim&lt;br /&gt;
 %&lt;br /&gt;
 % BEnRange&lt;br /&gt;
   0.00000 |  4.00000 | eV    # [BSS] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 % BDmRange&lt;br /&gt;
   0.05000 |  0.05000 | eV    # [BSS] Damping range&lt;br /&gt;
 %&lt;br /&gt;
 BEnSteps= 2000               # [BSS] Energy steps&lt;br /&gt;
 % BLongDir&lt;br /&gt;
  1.000000 | 0.000000 | 0.000000 |        # [BSS] [cc] Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;% BSEQptR&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 1 | 7 |                     # [BSK] Transferred momenta range&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;%&amp;lt;/span&amp;gt;&lt;br /&gt;
 % BSEBands&lt;br /&gt;
    25 |  28 |                 # [BSK] Bands range&lt;br /&gt;
 %&lt;br /&gt;
 WRbsWF                      # [BSS] Write to disk excitonic the FWs&lt;br /&gt;
 &lt;br /&gt;
This file was generated using the command: &amp;lt;code&amp;gt; yambo -X s -o b -k sex -y d -r&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
First of all, we compute the excitons for all the momenta in the irreducible Brillouin zone for our discrete grid via the &amp;lt;code&amp;gt;BSEQptR&amp;lt;/code&amp;gt; variable. This will be a &#039;&#039;&#039;finite-momentum&#039;&#039;&#039; BSE calculation, analogous to the phonon one.&lt;br /&gt;
&lt;br /&gt;
Second, we change the variable &amp;lt;code&amp;gt;Lkind&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;bar&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;full&amp;lt;/code&amp;gt;. In Yambo, &amp;lt;code&amp;gt;Lkind=&amp;quot;bar&amp;quot;&amp;lt;/code&amp;gt;, which is the default for optical absorption, means that we are computing the excitonic response function without the long-range component of the exchange interaction. This cannot be used when computing the exciton momentum dependence, where the long-range exchange interaction can play a role, therefore we have to include it with &amp;lt;code&amp;gt;Lkind=&amp;quot;full&amp;quot;&amp;lt;/code&amp;gt;. This allows for the calculation of the excitonic longitudinal-transverse splitting (in 3D systems) as well.&lt;br /&gt;
&lt;br /&gt;
We can now run the code:&lt;br /&gt;
&lt;br /&gt;
 nohup mpirun -np 8 yambo -F bse.in -J bse_Lfull -C bse_Lfull &amp;amp;&lt;br /&gt;
&lt;br /&gt;
At the end of the calculation, we have obtained the &amp;lt;code&amp;gt;ndb.BS_diago_Q*&amp;lt;/code&amp;gt; databases inside the directory &amp;lt;code&amp;gt;bse_Lfull&amp;lt;/code&amp;gt;. They contain information on the exciton energies and wavefunctions at each momentum. Do not forget to check the report and logs of your calculation in the same directory to make sure that the code is doing what you want.&lt;br /&gt;
&lt;br /&gt;
== Step 6: obtain the electron-phonon matrix elements ==&lt;br /&gt;
&lt;br /&gt;
We have finished the heavy simulations. Now it&#039;s time for the postprocessing. The first order of business is the reconstruction of the electron-phonon coupling matrix elements from the dvscf results and the electronic wavefunctions.&lt;br /&gt;
&lt;br /&gt;
In order to do this, we will run the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable of the &#039;&#039;&#039;LetzElPhC&#039;&#039;&#039; code. We will run via command line using yambopy, although it will be instructive to have look at the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; input files later.&lt;br /&gt;
&lt;br /&gt;
We run in the same directory where the Yambo &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; is (remember than you can also virtually move it with a symbolic link).&lt;br /&gt;
&lt;br /&gt;
Type:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y&lt;br /&gt;
&lt;br /&gt;
to see the help for the calculation. Have a look at the various flags and their description.&lt;br /&gt;
For example, if we want to do a serial run of LetzElPhC for bands from &amp;lt;math&amp;gt;n_i&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;n_f&amp;lt;/math&amp;gt;, we should type:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph path/of/ph_input.in -b n_i n_f&lt;br /&gt;
&lt;br /&gt;
Here &amp;lt;math&amp;gt;n_i&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;n_f&amp;lt;/math&amp;gt; are integers representing the initial and final band indices. &#039;&#039;&#039;Please note&#039;&#039;&#039;: in this case, the band index starts from 1 and the the interval of bands read by the code is &amp;lt;math&amp;gt;[n_i,n_f]&amp;lt;/math&amp;gt; including the extrema of the interval.&lt;br /&gt;
&lt;br /&gt;
These should coincide with those used for the Bethe-Salpeter kernel, i.e. those specified in the &amp;lt;code&amp;gt;BSEBands&amp;lt;/code&amp;gt; variable of the BSE input file (this is not strictly necessary, but certainly efficient since these calculations use a lot of disk space). &lt;br /&gt;
&lt;br /&gt;
For our system, we want to do a parallel calculation with 4 qpools and 2 kpools. In addition, we want to explicitly specify the path of the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable and avoid automatically deleting the LetzElPhC data. So we type:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph path/of/dvscf/mos2.dvscf -b 25 28 -par 4 2 -lelphc path/to/lelphc_exe&lt;br /&gt;
&lt;br /&gt;
At the end, check your directory: you should find the &amp;lt;code&amp;gt;lelphc.in&amp;lt;/code&amp;gt; input file that was run, let&#039;s inspect it: &lt;br /&gt;
&lt;br /&gt;
 # LetzElPhC input for yambo generated by yambopy&lt;br /&gt;
 nqpool      = 2&lt;br /&gt;
 nkpool      = 4&lt;br /&gt;
 start_bnd   = 25&lt;br /&gt;
 end_bnd     = 28&lt;br /&gt;
 save_dir    = ./SAVE&lt;br /&gt;
 kernel      = dfpt&lt;br /&gt;
 ph_save_dir = dvscf/ph_save&lt;br /&gt;
 convention = yambo&lt;br /&gt;
&lt;br /&gt;
Notice the variable &amp;lt;code&amp;gt;convention=yambo&amp;lt;/code&amp;gt;: what does it mean? At variance with QE and many other codes, Yambo uses the &amp;quot;backward&amp;quot; momentum transfer convention for electronic scatterings. That is, an electronic transition goes from band &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; and momentum &amp;lt;math&amp;gt;k-q&amp;lt;/math&amp;gt; to band &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; and momentum &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;. In the &amp;quot;forward&amp;quot; momentum transfer convention (the more standard one), the transitions go from &amp;lt;math&amp;gt;nk&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;mk+q&amp;lt;/math&amp;gt;. Therefore, this variable ensures that the electron-phonon coupling matrix elements are computed as &amp;lt;math&amp;gt;\langle mk|dV|nk-q\rangle&amp;lt;/math&amp;gt;. This will have consequences also in the formulation of the &#039;&#039;exciton&#039;&#039;-phonon coupling matrix element.&lt;br /&gt;
&lt;br /&gt;
You will also find a &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; database that contains the computed electron-phonon matrix elements, in the output format of &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In addition, if you check the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; folder:&lt;br /&gt;
&lt;br /&gt;
 ls SAVE/ndb.elph_gkkp*&lt;br /&gt;
&lt;br /&gt;
you will see that yambopy has created the Yambo-compatible electron-phonon databases.&lt;br /&gt;
&lt;br /&gt;
If you want to run LetzElPhC directly, without using yambopy, you can refer to its [https://github.com/yambo-code/LetzElPhC/blob/main/docs/tex_doc/main.pdf|user guide].&lt;br /&gt;
Keep in mind that in this case, in order to convert the database to the &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases of Yambo, you will then need a couple of lines of python using the Yambopy class &amp;lt;code&amp;gt;ConvertElectronPhononDB&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;yambopy/letzelph_interface/lelph2y.py&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t need the &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases -- e.g., because you are doing the exc-ph postprocessing with yambopy -- you can run &amp;lt;code&amp;gt;yambopy l2y ...&amp;lt;/code&amp;gt; with the &amp;lt;code&amp;gt;--no_gkkp&amp;lt;/code&amp;gt; option.&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t need the &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; databases -- e.g., because you are using &amp;lt;code&amp;gt;yambo_ph&amp;lt;/code&amp;gt; for the exc-ph part -- you can run &amp;lt;code&amp;gt;yambopy l2y ...&amp;lt;/code&amp;gt; with the &amp;lt;code&amp;gt;--no_lelphc_dbs&amp;lt;/code&amp;gt; option.&lt;br /&gt;
&lt;br /&gt;
== Step 7: Obtain the exciton-phonon coupling ==&lt;br /&gt;
&lt;br /&gt;
Now, we can finally access our basic building block for exciton-phonon physics. This could be done entirely in python (using &#039;&#039;&#039;Yambopy&#039;&#039;&#039;), or by running &#039;&#039;&#039;Yambo&#039;&#039;&#039;. &lt;br /&gt;
&lt;br /&gt;
* For the &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&#039;&#039;&#039;Yambo postprocessing&#039;&#039;&#039;&amp;lt;/span&amp;gt; case (running yambo inputs with the &amp;lt;code&amp;gt;yambo_ph&amp;lt;/code&amp;gt; executable), &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&#039;&#039;&#039;follow the alternative route to Steps 7-8 [[Exciton-phonon coupling and luminescence - Yambo postprocessing|at this link]]&#039;&#039;&#039;&amp;lt;/span&amp;gt;.&lt;br /&gt;
* For the &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&#039;&#039;&#039;Yambopy postprocessing&#039;&#039;&#039;&amp;lt;/span&amp;gt; case (using flexible python scripting), &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&#039;&#039;&#039;keep following Steps 7-8 on this page&#039;&#039;&#039;&amp;lt;/span&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Our objective is obtaining the following quantity: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\mathcal{G}^\mu_{\alpha\lambda}(0,q)=\sum_{vv^\prime c k} A^{\alpha, *}_{cv^\prime} (k, q) g_{vv^\prime}^\mu (k,q) A^{\lambda}_{cv}(k,0) - \sum_{cc^\prime vk} A^{\alpha, *}_{c^\prime v} (k+q, q) g_{c^\prime c}^\mu (k+q,q) A^{\lambda}_{cv}(k, 0)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here, &amp;lt;math&amp;gt;A^{\alpha}_{cv}(k,q)&amp;lt;/math&amp;gt; are the exciton coefficients extracted from the eigenvector of the two-particles Hamiltonian during the BSE calculation in step 5, while &amp;lt;math&amp;gt;g_{nm}^\mu (k,q)&amp;lt;/math&amp;gt; are the electron-phonon coupling matrix elements obtained in step 6. As you can see, the exciton &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; undergoes phonon-mediated scattering to state &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; via phonon mode &amp;lt;math&amp;gt;\mu&amp;lt;/math&amp;gt;. The scattering can happen for the hole (valence, &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt;) or for the electron (conduction, &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
NB: &lt;br /&gt;
&lt;br /&gt;
(1) This is written in the &amp;quot;backward&amp;quot; momentum transfer convention used by Yambo. The momentum dependence is different in the &amp;quot;forward&amp;quot; transfer convention. &lt;br /&gt;
&lt;br /&gt;
(2) For simplicity, this is written for zero initial exciton momentum. This means that one of the two states involved in the phonon-mediated scattering process will be in the optical limit (and possibly an optically generated exciton), while the other state can have any momentum: this momentum will be the same as the phonon one. This matrix element can be used to describe phonon-assisted absorption and emission spectra.&lt;br /&gt;
&lt;br /&gt;
In order to calculate this quantity using python, we need the &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; databases natively generated by the &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; code, as well as the BSE databases &amp;lt;code&amp;gt;ndb.BS_diago_Q*&amp;lt;/code&amp;gt; containing the information on exciton wavefunctions and energies.&lt;br /&gt;
&lt;br /&gt;
Next, we write a python user script importing the yambopy exciton-phonon tools. You can find a version of this script in &amp;lt;code&amp;gt;yambopy/tutorials/exciton-phonon/calculate_excph.py&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
 import numpy as np &lt;br /&gt;
 from yambopy import YamboLatticeDB,YamboWFDB,LetzElphElectronPhononDB &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;#Specific Yambopy dbs loading classes&amp;lt;/span&amp;gt;&lt;br /&gt;
 from yambopy.exciton_phonon.excph_matrix_elements import exciton_phonon_matelem &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;#Specific exc-ph functions&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 path = &#039;1L_MoS2&#039;&lt;br /&gt;
 bands_range=[24,28] &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# 2 valence bands, 2 conduction bands&amp;lt;/span&amp;gt;&lt;br /&gt;
 nexc = 12 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# number of excitonic states&amp;lt;/span&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 bsepath    = f&#039;{path}/bse-allq_full&#039; &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Path to BSE calculation (Lin=Lout)&amp;lt;/span&amp;gt;&lt;br /&gt;
 savepath   = f&#039;{path}/SAVE&#039;     &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Yambo SAVE&amp;lt;/span&amp;gt;&lt;br /&gt;
 ndb_elph   = f&#039;{path}/ndb.elph&#039; &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# LetzElPhC electron-phonon database (any convention)&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Read lattice&amp;lt;/span&amp;gt;&lt;br /&gt;
 lattice = YamboLatticeDB.from_db_file(filename=f&#039;{savepath}/ns.db1&#039;)&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Read electron-phonon&amp;lt;/span&amp;gt;&lt;br /&gt;
 elph    = LetzElphElectronPhononDB(ndb_elph,read_all=False)&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Read wave functions&amp;lt;/span&amp;gt;&lt;br /&gt;
 wfcs    = YamboWFDB(filename=&#039;ns.wf&#039;,save=savepath,latdb=lattice,bands_range=bands_range)&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Calculate exciton-phonon matrix elements&amp;lt;/span&amp;gt;&lt;br /&gt;
 exph = exciton_phonon_matelem(lattice,elph,wfcs,BSE_dir=bsepath,nexc_in=nexc,nexc_out=nexc,dmat_mode=&#039;save&#039;,exph_file=&#039;MoS2_Ex-ph.npy&#039;)&lt;br /&gt;
&lt;br /&gt;
In this script, we can select the number exciton states &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; with &amp;lt;code&amp;gt;nexc&amp;lt;/code&amp;gt;, the single-particle bands range with &amp;lt;code&amp;gt;bands_range&amp;lt;/code&amp;gt;. &#039;&#039;&#039;Please note&#039;&#039;&#039;: in this case, the band index starts from 0 (python indexing) and the the interval of bands read by the code is &amp;lt;math&amp;gt;[n_i,n_f)&amp;lt;/math&amp;gt;, therefore the last value (28 in the example) is excluded. That is, in the example we are selecting the 25th, 26th, 27th and 28th bands. Those bands have to be present in both the electron-phonon and BSE calculations. &lt;br /&gt;
&lt;br /&gt;
Here we calculate the couplings of the first twelve states at each finite-&amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; point including &amp;lt;math&amp;gt;q=0&amp;lt;/math&amp;gt;. We also include all the nine phonon modes of monolayer MoS2. We also need access to the Yambo &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory in order to read the electronic wavefunctions: they are used to compute the electronic representation matrices (&amp;lt;code&amp;gt;dmat&amp;lt;/code&amp;gt; in the code). The argument &amp;lt;code&amp;gt;dmat_mode&amp;lt;/code&amp;gt; can be set to &amp;lt;code&amp;gt;&#039;load&#039;&amp;lt;/code&amp;gt; for subsequent calculations.&lt;br /&gt;
&lt;br /&gt;
When we are satisfied with the input, we run the code:&lt;br /&gt;
&lt;br /&gt;
 python calculate_excph.py&lt;br /&gt;
&lt;br /&gt;
If you check the output, you should find the &amp;lt;code&amp;gt;MoS2_Ex-ph.npy&amp;lt;/code&amp;gt; binary file in the directory where you ran.&lt;br /&gt;
&lt;br /&gt;
=== Analysis of the couplings ===&lt;br /&gt;
&lt;br /&gt;
It is a good idea to have a look at what we computed up to now in order to make sure nothing has gone wrong. &lt;br /&gt;
&lt;br /&gt;
It is not easy to know what to expect (apart from symmetry and gauge compliance of the matrix elements), but one can work out the exciton-phonon selection rules in advance, check that the magnitude is reasonable, etc.&lt;br /&gt;
&lt;br /&gt;
It is also not easy to meaningfully plot this quantity. We have to make sure that we are not breaking degenerate states, otherwise the plots will not be invariant. &lt;br /&gt;
&lt;br /&gt;
First of all, we have to know our system: in monolayer MoS&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;, the first four excitons are all doubly degenerate. The first exciton responsible for a bright peak in the absorption spectrum (the &#039;&#039;&#039;A&#039;&#039;&#039; peak), is the second state, corresponding to state indices &amp;lt;code&amp;gt;(3,4)&amp;lt;/code&amp;gt; in fortran indexing or &amp;lt;code&amp;gt;(2,3)&amp;lt;/code&amp;gt; in python indexing. &lt;br /&gt;
&lt;br /&gt;
All these information can be obtained by analyzing the BSE results (this stuff is explained in the BSE tutorials) and by knowledge of the system or class of systems from the literature.&lt;br /&gt;
&lt;br /&gt;
Thus, a good quantity to plot may be the norm of the matrix elements, summed over the degenerate subspace of exciton A, for a certain number of scattered final states mediated by certain phonon modes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;F_A(q)= \sqrt{ \sum_{\alpha \in A,\lambda,\mu} |\mathcal{G}_{\alpha\lambda}^\mu (0,q)|^2 }&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In order to do this, we create a python script &amp;lt;code&amp;gt;analyse_excph.py&amp;lt;/code&amp;gt; in which we first load the excph dabatases. &lt;br /&gt;
You can find a version of this script in the yambopy directory, in &amp;lt;code&amp;gt;tutorials/exciton-phonon&amp;lt;/code&amp;gt;. &lt;br /&gt;
First, we select the exciton and phonon states to be included in &amp;lt;code&amp;gt;F_A&amp;lt;/code&amp;gt;, together with the path of databases and plot details:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Exciton &amp;quot;in&amp;quot; states&amp;lt;/span&amp;gt;&lt;br /&gt;
 exc_in  = [2,3]  &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# First bright peak (A: 2,3 -- B: 6,7)&amp;lt;/span&amp;gt;&lt;br /&gt;
 exc_out = [0,1,2,3] &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# first 4 states (dispersion of dark triplet state and A)&amp;lt;/span&amp;gt;&lt;br /&gt;
 ph_in  = &#039;all&#039;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Paths of databases&amp;lt;/span&amp;gt;&lt;br /&gt;
 ns_db1 =f&#039;{path}/SAVE/ns.db1&#039;&lt;br /&gt;
 ns_ypy = &#039;MoS2_Ex-ph.npy&#039;&lt;br /&gt;
 &lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
Then, we load the data:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Read lattice and k-space info&amp;lt;/span&amp;gt;&lt;br /&gt;
 ylat = YamboLatticeDB.from_db_file(filename=ns_db1)&lt;br /&gt;
 print(ylat)&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Load exc-ph database&amp;lt;/span&amp;gt;&lt;br /&gt;
 X_py = np.load(ns_ypy)&lt;br /&gt;
 G_squared = np.abs(X_py)**2.&lt;br /&gt;
&lt;br /&gt;
The quantity &amp;lt;math&amp;gt;F_A(q)&amp;lt;/math&amp;gt; is obtained from a dedicated function as:&lt;br /&gt;
 &lt;br /&gt;
 if exc_in  == &#039;all&#039;: exc_in  = range(G_squared.shape[2])&lt;br /&gt;
 if exc_out == &#039;all&#039;: exc_out = range(G_squared.shape[3])&lt;br /&gt;
 if ph_in   == &#039;all&#039;: ph_in   = range(G_squared.shape[1])&lt;br /&gt;
 &lt;br /&gt;
 G_squared = G_squared[:, ph_in, :, :].sum(axis=(1))&lt;br /&gt;
 G_squared = G_squared[:, exc_in, :].sum(axis=(1))&lt;br /&gt;
 G_squared = G_squared[:, exc_out].sum(axis=(1))&lt;br /&gt;
 &lt;br /&gt;
 F_q = np.sqrt( G_squared )*ha2ev &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Switch from Ha to eV&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And finally, we have to make a plotting function. For this tutorial we will use a custom scatterplot employing some of the plotting tools provided by yambopy (but you can do whatever you want).&lt;br /&gt;
&lt;br /&gt;
 plot_2D_excph(qgrid,G2_to_plot,rlat=ylat.rlat,plt_cbar=True,\&lt;br /&gt;
               marker=&#039;H&#039;,s=700,cmap=&#039;magma&#039;)&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
You can get more experience on using Yambopy for these kinds of visualization by following the [https://wiki.yambo-code.eu/wiki/index.php?title=First_steps_in_Yambopy Yambopy tutorials]. In fact, remember that these scripts and all the other Yambopy tutorial scripts are just suggestions, not source code written in stone: if you know &amp;lt;code&amp;gt;numpy&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;matplotlib&amp;lt;/code&amp;gt; you can do your own analysis and your own plots, you just need to import the required Yambopy modules to load the data.&lt;br /&gt;
&lt;br /&gt;
In our case, the resulting plot is the following.&lt;br /&gt;
&lt;br /&gt;
[[File:1L MoS2 MoS2 Ex-ph.png|500px|center]]&lt;br /&gt;
&lt;br /&gt;
This can be checked against Fig. 2(d) of reference &amp;lt;ref name=&amp;quot;chan2023&amp;quot; /&amp;gt;, although you have to keep in mind that our results are badly undersampled in terms of the reciprocal-space grid, as can be easily seen, and the quantity plotted is not exactly the same. However, the main features are already there since they are dictated mostly by crystal symmetries.&lt;br /&gt;
&lt;br /&gt;
Now that we have the exciton-phonon matrix elements, we can use them to build several kinds of observables. Below, we give an example related to phonon-assisted luminescence, but we may update this tutorial in the future to include more cases.&lt;br /&gt;
&lt;br /&gt;
== Step 8: Compute phonon-assisted luminescence ==&lt;br /&gt;
&lt;br /&gt;
[[File:Luminescence scheme.png|250px|right]]&lt;br /&gt;
&lt;br /&gt;
We want to compute the experimental optical signature due to the phonon-assisted recombination of an exciton (as sketched in the figure).&lt;br /&gt;
&lt;br /&gt;
The signal from the phonon replicas can be modeled as a second-order scattering process involving one phonon and one photon:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;I^{Sat}(\omega)=\frac{1}{ N_q} \frac{1}{3} \sum_{\epsilon s\beta \mu q} \frac{1}{E_{\beta q}-s\Omega_{\mu q}}\left|\sum_\alpha\frac{ D^{\epsilon}_\alpha \mathcal{G}_{\beta \alpha}^{\mu,*}(q)}{E_\alpha -E_{\beta q} +s\Omega_{\mu q}+\mathrm{i}\eta}\right|^2 \frac{N^{exc}_{\beta q}(T_{exc})[\frac{1+s}{2}+n_{\mu q}(T)]}{\omega -[E_{\beta q}-s\Omega_{\mu q}]+\mathrm{i}\eta}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this equation, the oscillator strength of the peak is given by the exciton-phonon coupling matrix elements &amp;lt;math&amp;gt;\mathcal{G}&amp;lt;/math&amp;gt; multiplied by the exciton dipoles &amp;lt;math&amp;gt;D&amp;lt;/math&amp;gt; (they are called &amp;quot;residuals&amp;quot; in Yambo). Here &amp;lt;math&amp;gt;E_\lambda&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;E_{\alpha q}&amp;lt;/math&amp;gt; are the energies of the optical and finite-momentum excitons, respectively, while &amp;lt;math&amp;gt;\Omega_{\mu q}&amp;lt;/math&amp;gt; are the phonon energies. &lt;br /&gt;
&lt;br /&gt;
Here, &amp;lt;math&amp;gt;n_{\mu q}(T)&amp;lt;/math&amp;gt; is the temperature-dependent phonon Bose-Einstein occupation function. As it can be seen, &amp;lt;math&amp;gt;s=1&amp;lt;/math&amp;gt; corresponds to processes of phonon &#039;&#039;emission&#039;&#039; (&amp;lt;math&amp;gt;\propto n(T)+1&amp;lt;/math&amp;gt;), while &amp;lt;math&amp;gt;s=-1&amp;lt;/math&amp;gt; corresponds to processes of phonon &#039;&#039;absorption&#039;&#039; (&amp;lt;math&amp;gt;\propto n(T)&amp;lt;/math&amp;gt;). Therefore, &amp;lt;math&amp;gt;I^{Sat}_{PL}(\omega;T)&amp;lt;/math&amp;gt; describes &#039;&#039;light&#039;&#039; emission by recombining excitons mediated by either &#039;&#039;phonon&#039;&#039; absorption or emission. &lt;br /&gt;
&lt;br /&gt;
The quantity &amp;lt;math&amp;gt; N_{\alpha q}(T_{exc})&amp;lt;/math&amp;gt; is the exciton occupation function. Luminescence is technically an out-of-equilibrium process, but we can assume that for very low density of excitations and in steady-state conditions, the exciton population can be approximately described by an equilibrium distribution evaluated at an effective temperature. Here, we use the Boltzmann distribution. Experimentally, &amp;lt;math&amp;gt;T_{exc}&amp;lt;/math&amp;gt; tends to coincide with the lattice temperature &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt; more or less above 100 K, while at very low temperature (&amp;lt; 10 K), &amp;lt;math&amp;gt;T_{exc}&amp;lt;/math&amp;gt; may vary between 10-50 K. It goes without saying that this needs to carefully be checked in your realistic calculations.&lt;br /&gt;
&lt;br /&gt;
Finally, the spectrum is averaged over the polarization directions of the emitted photons (&amp;lt;math&amp;gt;\epsilon=x,y,z&amp;lt;/math&amp;gt; representing the respective dipole components).&lt;br /&gt;
&lt;br /&gt;
=== Running the jobs ===&lt;br /&gt;
&lt;br /&gt;
In order to study luminescence in a paradigmatic system, we switch to bulk hexagonal boron nitride and we repeat the workflow. As you can easily see, one can think about automatizing the execution of all these calculations via scripting or more advanced tools. However, in the case of very large simulations (memory-limited or disk-space limited) or for systems whose electronic and lattice properties are fragile with respect to tiny calculation details, one must be very careful and run many basic tests.&lt;br /&gt;
&lt;br /&gt;
Fortunately, we are running a fast underconverged example. We use LDA pseudopotentials from the pseudo-dojo library and the following are the calculations steps.&lt;br /&gt;
&lt;br /&gt;
1. Input &amp;lt;code&amp;gt;hbn.scf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 &amp;amp;control&lt;br /&gt;
     calculation=&#039;scf&#039;,&lt;br /&gt;
     prefix=&#039;hBN&#039;,&lt;br /&gt;
     restart_mode=&#039;from_scratch&#039;&lt;br /&gt;
     pseudo_dir = &#039;$PSEUDO_DIR&#039;,&lt;br /&gt;
     outdir = &#039;./tmp&#039;&lt;br /&gt;
     verbosity = &#039;high&#039;&lt;br /&gt;
     wf_collect=.true.&lt;br /&gt;
 /&lt;br /&gt;
 &amp;amp;system&lt;br /&gt;
     ibrav = 4,&lt;br /&gt;
     celldm(1) = 4.703675849&lt;br /&gt;
     celldm(3) = 2.603711434&lt;br /&gt;
     nat= 4,&lt;br /&gt;
     ntyp= 2,&lt;br /&gt;
     force_symmorphic=.true.&lt;br /&gt;
     ecutwfc = 100,&lt;br /&gt;
 /&lt;br /&gt;
 &amp;amp;electrons&lt;br /&gt;
   diago_david_ndim = 2&lt;br /&gt;
   diago_full_acc=.true.&lt;br /&gt;
   diago_thr_init=5.0e-6&lt;br /&gt;
   mixing_mode = &#039;plain&#039;&lt;br /&gt;
   mixing_beta = 0.7&lt;br /&gt;
   conv_thr =  1.0d-16&lt;br /&gt;
 /&lt;br /&gt;
 ATOMIC_SPECIES&lt;br /&gt;
  B 10.81100  B_LDA_dojo.UPF&lt;br /&gt;
  N 14.00674  N_LDA_dojo.UPF&lt;br /&gt;
 ATOMIC_POSITIONS {crystal}&lt;br /&gt;
 N             0.6666666670        0.3333333330        -0.250000000000&lt;br /&gt;
 B             0.3333333330        0.6666666670        -0.250000000000&lt;br /&gt;
 B             0.6666666670        0.3333333330        0.25000000000&lt;br /&gt;
 N             0.3333333330        0.6666666670        0.25000000000&lt;br /&gt;
 K_POINTS {automatic}&lt;br /&gt;
 6 6 2 0 0 0&lt;br /&gt;
&lt;br /&gt;
 mpirun -np 4 pw.x -inp hbn.scf &amp;gt; scf.out&lt;br /&gt;
&lt;br /&gt;
2. Input &amp;lt;code&amp;gt;hbn.nscf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 &amp;amp;control&lt;br /&gt;
     calculation=&#039;nscf&#039;,&lt;br /&gt;
     prefix=&#039;hBN&#039;,&lt;br /&gt;
     restart_mode=&#039;from_scratch&#039;&lt;br /&gt;
     pseudo_dir = &#039;$PSEUDO_DIR&#039;&lt;br /&gt;
     outdir = &#039;./&#039;&lt;br /&gt;
     verbosity = &#039;high&#039;&lt;br /&gt;
     wf_collect=.true.&lt;br /&gt;
 /&lt;br /&gt;
 &amp;amp;system&lt;br /&gt;
     ibrav = 4,&lt;br /&gt;
     celldm(1) = 4.703675849&lt;br /&gt;
     celldm(3) = 2.603711434&lt;br /&gt;
     nat= 4,&lt;br /&gt;
     ntyp= 2,&lt;br /&gt;
     force_symmorphic=.true.&lt;br /&gt;
     ecutwfc = 100,&lt;br /&gt;
 	nbnd = 120&lt;br /&gt;
 /&lt;br /&gt;
 &amp;amp;electrons&lt;br /&gt;
   diago_david_ndim = 2&lt;br /&gt;
   diago_full_acc=.true.&lt;br /&gt;
   diago_thr_init=5.0e-6&lt;br /&gt;
   mixing_mode = &#039;plain&#039;&lt;br /&gt;
   mixing_beta = 0.7&lt;br /&gt;
   conv_thr =  1.0d-16&lt;br /&gt;
 /&lt;br /&gt;
 ATOMIC_SPECIES&lt;br /&gt;
  B 10.81100  B_LDA_dojo.UPF&lt;br /&gt;
  N 14.00674  N_LDA_dojo.UPF&lt;br /&gt;
 ATOMIC_POSITIONS {crystal}&lt;br /&gt;
 N             0.6666666670        0.3333333330        -0.250000000000&lt;br /&gt;
 B             0.3333333330        0.6666666670        -0.250000000000&lt;br /&gt;
 B             0.6666666670        0.3333333330        0.25000000000&lt;br /&gt;
 N             0.3333333330        0.6666666670        0.25000000000&lt;br /&gt;
 K_POINTS {automatic}&lt;br /&gt;
 6 6 2 0 0 0&lt;br /&gt;
&lt;br /&gt;
 mpirun -np 4 pw.x -inp hbn.nscf &amp;gt; nscf.out&lt;br /&gt;
&lt;br /&gt;
3. Input &amp;lt;code&amp;gt;hbn.dvscf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 hbn_dvscf&lt;br /&gt;
 &amp;amp;inputph&lt;br /&gt;
   tr2_ph=1.0d-12,&lt;br /&gt;
   verbosity=&#039;high&#039;&lt;br /&gt;
   prefix=&#039;hBN&#039;,&lt;br /&gt;
   fildvscf = &#039;hBN-dvscf&#039;,&lt;br /&gt;
   electron_phonon = &#039;dvscf&#039;,&lt;br /&gt;
   fildyn=&#039;hBN.dyn&#039;,&lt;br /&gt;
   epsil=.false.,&lt;br /&gt;
   ldisp=.true.,&lt;br /&gt;
   recover=.true.,&lt;br /&gt;
   nq1=6,&lt;br /&gt;
   nq2=6,&lt;br /&gt;
   nq3=2&lt;br /&gt;
 /&lt;br /&gt;
&lt;br /&gt;
 nohup mpirun -np 8 pw.x -inp hbn.dvscf &amp;gt; dvscf.out &amp;amp;&lt;br /&gt;
&lt;br /&gt;
4. Input &amp;lt;code&amp;gt;bse.in&amp;lt;/code&amp;gt; (we include 2 valence and 2 conduction bands):&lt;br /&gt;
&lt;br /&gt;
 optics                           # [R] Linear Response optical properties&lt;br /&gt;
 bss                              # [R] BSE solver&lt;br /&gt;
 bse                              # [R][BSE] Bethe Salpeter Equation.&lt;br /&gt;
 dipoles                          # [R] Oscillator strenghts (or dipoles)&lt;br /&gt;
 em1s&lt;br /&gt;
 DIP_CPU= &amp;quot;1 8 1&amp;quot;                      # [PARALLEL] CPUs for each role&lt;br /&gt;
 DIP_ROLEs= &amp;quot;k c v&amp;quot;                    # [PARALLEL] CPUs roles (k,c,v)&lt;br /&gt;
 DIP_Threads=0                    # [OPENMP/X] Number of threads for dipoles&lt;br /&gt;
 X_and_IO_CPU= &amp;quot;1 1 1 8 1&amp;quot;                 # [PARALLEL] CPUs for each role&lt;br /&gt;
 X_and_IO_ROLEs= &amp;quot;q g k c v&amp;quot;               # [PARALLEL] CPUs roles (q,g,k,c,v)&lt;br /&gt;
 X_and_IO_nCPU_LinAlg_INV=-1      # [PARALLEL] CPUs for Linear Algebra (if -1 it is automatically set)&lt;br /&gt;
 X_Threads=0                      # [OPENMP/X] Number of threads for response functions&lt;br /&gt;
 BS_CPU= &amp;quot;8 1 1&amp;quot;                       # [PARALLEL] CPUs for each role&lt;br /&gt;
 BS_ROLEs= &amp;quot;k eh t&amp;quot;                     # [PARALLEL] CPUs roles (k,eh,t)&lt;br /&gt;
 BS_nCPU_LinAlg_INV=-1            # [PARALLEL] CPUs for Linear Algebra (if -1 it is automatically set)&lt;br /&gt;
 BS_nCPU_LinAlg_DIAGO=-1          # [PARALLEL] CPUs for Linear Algebra (if -1 it is automatically set)&lt;br /&gt;
 X_Threads=0                      # [OPENMP/X] Number of threads for response functions&lt;br /&gt;
 K_Threads=0                      # [OPENMP/BSK] Number of threads for response functions&lt;br /&gt;
 % QpntsRXs&lt;br /&gt;
    1 | 14 |                         # [Xs] Transferred momenta&lt;br /&gt;
 %&lt;br /&gt;
 % BndsRnXs&lt;br /&gt;
    1 | 120 |                         # [Xs] Polarization function bands&lt;br /&gt;
 %&lt;br /&gt;
 NGsBlkXs= 10                Ry    # [Xs] Response block size&lt;br /&gt;
 % LongDrXs&lt;br /&gt;
  1.000000 | 1.000000 | 1.000000 |        # [Xs] [cc] Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 BSEmod= &amp;quot;resonant&amp;quot;               # [BSE] resonant/retarded/coupling&lt;br /&gt;
 BSKmod= &amp;quot;SEX&amp;quot;                    # [BSE] IP/Hartree/HF/ALDA/SEX/BSfxc&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;Lkind= &amp;quot;Lfull&amp;quot;                    # [BSE] Lbar (default) / full&amp;lt;/span&amp;gt;&lt;br /&gt;
 BSSmod= &amp;quot;d&amp;quot;                      # [BSS] (h)aydock/(d)iagonalization/(s)lepc/(i)nversion/(t)ddft`&lt;br /&gt;
 % DipBands&lt;br /&gt;
    1 | 120 |                         # [DIP] Bands range for dipoles&lt;br /&gt;
 %&lt;br /&gt;
 DipApproach= &amp;quot;G-space v&amp;quot;         # [DIP] [G-space v/R-space x/Covariant/Shifted grids]&lt;br /&gt;
 DipComputed= &amp;quot;R V P&amp;quot;             # [DIP] [default R P V; extra P2 Spin Orb]&lt;br /&gt;
 BSENGexx= 30000            Ry    # [BSK] Exchange components&lt;br /&gt;
 #ALLGexx                       # [BSS] Force the use use all RL vectors for the exchange part&lt;br /&gt;
 BSENGBlk=  9000            Ry    # [BSK] Screened interaction block size [if -1 uses all the G-vectors of W(q,G,Gp)]&lt;br /&gt;
 % KfnQP_E&lt;br /&gt;
  1.25997 | 1.08816 | 1.12683 |        # [EXTQP BSK BSS] E parameters  (c/v) eV|adim|adim&lt;br /&gt;
 %&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;% BSEQptR&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 1 | 14 |                     # [BSK] Transferred momenta range&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;%&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;% BSEBands&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;   7 | 10 |                         # [BSK] Bands range&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;%&amp;lt;/span&amp;gt;&lt;br /&gt;
 % BEnRange&lt;br /&gt;
   0.50000 | 8.00000 |         eV    # [BSS] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 % BDmRange&lt;br /&gt;
  0.050000 | 0.050000 |         eV    # [BSS] Damping range&lt;br /&gt;
 %&lt;br /&gt;
 BEnSteps= 1000                    # [BSS] Energy steps&lt;br /&gt;
 % BLongDir&lt;br /&gt;
  1.000000 | 1.000000 | 0.000000 |        # [BSS] [cc] Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 WRbsWF                        # [BSS] Write to disk excitonic the WFs&lt;br /&gt;
&lt;br /&gt;
 nohup mpirun -np 8 yambo -F bse.in -J bse_Lfull -C bse_Lfull &amp;amp;&lt;br /&gt;
&lt;br /&gt;
Importantly, since we want to describe the phonon-assisted recombination process of an *optical* exciton (i.e., emitting a transverse photon), this time we also run an additional calculation at `Q=0` omitting the nonanalytic long-range Coulomb exchange. Make a second input &amp;lt;code&amp;gt;bse_Lbar.in&amp;lt;/code&amp;gt; with the following changes: &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;Lkind= &amp;quot;Lbar&amp;quot;                    # [BSE] Lbar (default) / full&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;% BSEQptR&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 1 | 1 |                     # [BSK] Transferred momenta range&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;%&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4b. So now we make a second BSE run in a different directory specified by &amp;lt;code&amp;gt;-J&amp;lt;/code&amp;gt;. Here, we also pass to yambo the directory of the previous run as it includes the important screening databases &amp;lt;code&amp;gt;ndb.em1s*&amp;lt;/code&amp;gt; that we do not want to recompute from scratch.&lt;br /&gt;
 &lt;br /&gt;
 mpirun -np 8 yambo -F bse_Lbar.in -J bse_Lbar,bse_Lfull -C bse_Lbar&lt;br /&gt;
&lt;br /&gt;
5. Now we run &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; (with or without yambopy: in the latter case remember the option &amp;lt;code&amp;gt;-D&amp;lt;/code&amp;gt;) to get the el-ph matrix elements, particularly the &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; databases:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph path/of/dvscf/hbn.dvscf -b 7 10 -par 4 2 -D&lt;br /&gt;
&lt;br /&gt;
=== Luminescence calculation ===&lt;br /&gt;
&lt;br /&gt;
6. And finally we calculate exciton-phonon matrix elements and the luminescence spectrum in one go using a python script importing the Yambopy exciton-phonon tools: in order to do this, we need to take a look at all the necessary input variables for the formula written above.&lt;br /&gt;
&lt;br /&gt;
We can start from the script &amp;lt;code&amp;gt;luminescence.py&amp;lt;/code&amp;gt; available in &amp;lt;code&amp;gt;tutorials/exciton-phonon&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
 import numpy as np&lt;br /&gt;
 import matplotlib.pyplot as plt&lt;br /&gt;
 from yambopy.exciton_phonon.excph_luminescence import exc_ph_luminescence&lt;br /&gt;
 from yambopy.exciton_phonon.excph_input_data import exc_ph_get_inputs&lt;br /&gt;
&lt;br /&gt;
We import the necessary tools...&lt;br /&gt;
&lt;br /&gt;
 path = &#039;3D_hBN&#039;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Path to BSE calculation (Lout--&amp;gt; response is Lfull)&amp;lt;/span&amp;gt;&lt;br /&gt;
 bsepath =  f&#039;{path}/bse_Lfull&#039; &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# ndb.BS_diago_Q* databases are needed&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Path to BSE calculation for optically active exciton (Lin --&amp;gt; response is Lbar)&amp;lt;/span&amp;gt;&lt;br /&gt;
 bseBARpath =  f&#039;{path}/bse_Lbar&#039;  &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# ndb.BS_diago_Q1 database is needed&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Path to electron-phonon calculation&amp;lt;/span&amp;gt;&lt;br /&gt;
 elphpath = path &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# ndb.elph is needed&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Path to unprojected dipoles matrix elements (optional)&amp;lt;/span&amp;gt;&lt;br /&gt;
 dipolespath = bsepath &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# ndb.dipoles is needed (optional)&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Path to lattice and k-space info&amp;lt;/span&amp;gt;&lt;br /&gt;
 savepath = f&#039;{path}/SAVE&#039; &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# ns.db1 database is needed&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
... and we specify the paths to the necessary databases. Note that, if we want to perform polarization averaging, we have to recompute the excitonic dipoles in python as seen here.&lt;br /&gt;
&lt;br /&gt;
What about &amp;lt;code&amp;gt;bseBARpath&amp;lt;/code&amp;gt;? This variable points to the directory where the databases for the optical (zero-momentum) excitons &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; (which may be computed with &amp;lt;code&amp;gt;Lkind=&#039;Lbar&#039;&amp;lt;/code&amp;gt;) is located, which can be different from the directory with the full indirect exciton dispersion &amp;lt;math&amp;gt;\beta&amp;lt;/math&amp;gt; (usually computed with &amp;lt;code&amp;gt;Lkind=&#039;Lfull&#039;&amp;lt;/code&amp;gt;, however &amp;lt;code&amp;gt;Lkind=&#039;Ltilde&#039;&amp;lt;/code&amp;gt; can also be used if one is interested in &amp;quot;irreducible&amp;quot; excitons). This makes it possible to compute the coupling between different exciton kinds.&lt;br /&gt;
&lt;br /&gt;
 bands_range=[6,10] &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# 2 valence, 2 conduction bands&amp;lt;/span&amp;gt;&lt;br /&gt;
 phonons_range=[0,12] &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# All phonons&amp;lt;/span&amp;gt;&lt;br /&gt;
 nexc_out = 12 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# 12 excitonic states at each momentum (Lout)&amp;lt;/span&amp;gt;&lt;br /&gt;
 nexc_in  = 12 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# 12 excitonic states at Q=0 (Lin)&amp;lt;/span&amp;gt;&lt;br /&gt;
 T_ph  = 10 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Lattice temperature&amp;lt;/span&amp;gt;&lt;br /&gt;
 T_exc = 10 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Effective excitonic temperature&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 emin=4.4      &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Energy range and plot details (in eV)&amp;lt;/span&amp;gt;&lt;br /&gt;
 emax=4.7&lt;br /&gt;
 estep=0.0002&lt;br /&gt;
 broad = 0.005 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Broadening parameter for peak width (in eV)&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next, we specify the parameters for the calculation. We include valence bands from 7 to 10 (6 to 9 in python index) and the contribution of all 12 phonon modes. We consider 12 excitonic states for the coupling matrix elements.&lt;br /&gt;
&lt;br /&gt;
Here &amp;lt;code&amp;gt;T_ph&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;T_exc&amp;lt;/code&amp;gt; are the lattice and excitonic temperatures, respectively.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# We calculate and load all the inputs:&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# * Exciton-phonon matrix elements&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# * Excitonic dipole matrix elements&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# * Exciton energies&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# * Phonon energies&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# * We specify bse_path2=bseBARpath meaning we use Lbar calculation for Q=0 excitons&amp;lt;/span&amp;gt;&lt;br /&gt;
 input_data = exc_ph_get_inputs(savepath,elphpath,bsepath,\&lt;br /&gt;
                                bse_path2=bseBARpath,dipoles_path=dipolespath,\&lt;br /&gt;
                                nexc_in=12,nexc_out=12,\&lt;br /&gt;
                                bands_range=[6,10],phonons_range=[0,12])&lt;br /&gt;
&lt;br /&gt;
 ph_energies, exc_energies, exc_energies_in, G, exc_dipoles = input_data&lt;br /&gt;
&lt;br /&gt;
The function &amp;lt;code&amp;gt;exc_ph_get_inputs&amp;lt;/code&amp;gt; gives us all the input data for luminescence in the correct format: phonon energies, exciton energies, optical exciton energies (if needed), exciton-phonon matrix elements (calculated on the fly and printed to file), unprojected exciton dipoles (optional, calculated on the fly and printed to file).&lt;br /&gt;
The exc-ph matrix element calculation is just a wrapper of the same tools that we have tested in the above section on MoS2.&lt;br /&gt;
&lt;br /&gt;
Finally, there is the calculation of the luminescence spectrum via the function &amp;lt;code&amp;gt;exc_ph_luminescence&amp;lt;/code&amp;gt;:&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# We calculate the luminescence spectrum including the input data from before&amp;lt;/span&amp;gt;&lt;br /&gt;
 w,PL = exc_ph_luminescence(T_ph,ph_energies,exc_energies,exc_dipoles,G,\&lt;br /&gt;
                            exc_energies_in=exc_energies_in,exc_temp=T_exc,\&lt;br /&gt;
                            nexc_out=nexc_out,nexc_in=nexc_in,emin=emin,emax=emax,\&lt;br /&gt;
                            estep=estep,broad=broad)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you want to print the luminescence data for later plotting, you can also add the following line to the script:&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Save to file&amp;lt;/span&amp;gt;&lt;br /&gt;
 data = np.column_stack((w, PL))&lt;br /&gt;
 np.savetxt(&amp;quot;hBN_luminescence_12x12x1.dat&amp;quot;, data, fmt=&amp;quot;%.8f&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
It is now time to run the whole script:&lt;br /&gt;
&lt;br /&gt;
 python luminescence.py&lt;br /&gt;
 &lt;br /&gt;
NB: By using Yambopy for Step 6, we have limited the use of the Yambo code to just step 4 in the entire workflow. This option is more flexible, as it allows for a greater degree of control by the user. On the other hand the Yambo postprocessing route features a Yambo-style input that doesn&#039;t require python knowledge and the calculation is currently faster in fortran. However, the luminescence expression computed in Yambo is a slightly different than this one: it is more approximated in the description of the satellite oscillator strengths, but it explicitly includes the renormalization of the direct exciton peak. You can check the differences [[Exciton-phonon coupling and luminescence - Yambo postprocessing|here]].&lt;br /&gt;
&lt;br /&gt;
=== Results ===&lt;br /&gt;
We can plot the results of the step 6 calculation. If we do it in the same script we can add something like this:&lt;br /&gt;
 fig = plt.figure()&lt;br /&gt;
 ax = fig.add_subplot(1,1,1)&lt;br /&gt;
 ax.set_xlim(emin,emax)&lt;br /&gt;
 ax.set_ylim(0,np.max(PL)*1.1)&lt;br /&gt;
 ax.get_yaxis().set_visible(False)&lt;br /&gt;
 &lt;br /&gt;
 ax.plot(w, PL, &#039;-&#039;,c=&#039;red&#039;, label=&amp;quot;AA&#039; hBN luminescence&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
 plt.legend()&lt;br /&gt;
 plt.savefig(&#039;hBN_luminescence.png&#039;)&lt;br /&gt;
 plt.show()&lt;br /&gt;
&lt;br /&gt;
[[File:HBN luminescence satellites.png|500px|center]]&lt;br /&gt;
&lt;br /&gt;
Here, the signal corresponds to a finite-momentum exciton that recombines with the help of several different phonon modes, both optical and acoustic. Each phonon mode whose coupling with the exciton is allowed can generate a peak, and the energy shifts of these peaks with respect to the initial exciton energy correspond to the phonon energies. This result is underconverged, but the main features are all there. In the plot, we show a more converged example using a 12x12x4 grid (all the other parameters being equal). These plots can be compared with Fig. 4(a) of reference &amp;lt;ref name=&amp;quot;zanfrognini2023&amp;quot; /&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;toyozawa2003&amp;quot; &amp;gt;Toyozawa, Yutaka, and Chris Oxlade, &#039;&#039;Optical processes in solids&#039;&#039;, [https://m.booksee.org/book/1121964?force_lang=en Cambridge University Press, (2003)]. &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;lechifflart2023&#039;&amp;gt;P. Lechifflart, F. Paleari, D. Sangalli, C. Attaccalite, &#039;&#039;First-principles study of luminescence in hexagonal boron nitride single layer: Exciton-phonon coupling and the role of substrate&#039;&#039;, &lt;br /&gt;
[https://doi.org/10.1103/PhysRevMaterials.7.024006 Phys. Rev. M, &#039;&#039;&#039;7&#039;&#039;&#039; (2), 024006 (2023)]; [https://arxiv.org/abs/2212.10407 arXiv2212.1047]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;cannuccia2019&#039;&amp;gt;E. Cannuccia, B. Monserrat and C. Attaccalite, &#039;&#039;Theory of phonon-assisted luminescence in solids: Application to hexagonal boron nitride&#039;&#039;, [https://doi.org/10.1103/PhysRevB.99.081109 Phys. Rev. B &#039;&#039;&#039;99&#039;&#039;&#039;, 081109(R) (2019)]; [https://arxiv.org/abs/1807.11797 arXiv1807.11797]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;paleari2019&#039;&amp;gt;F. Paleari et al., &#039;&#039;Exciton-Phonon Coupling in the Ultraviolet Absorption and Emission Spectra of Bulk Hexagonal Boron Nitride&#039;&#039;, [https://doi.org/10.1103/PhysRevLett.122.187401 Phys. Rev. Lett. &#039;&#039;&#039;122&#039;&#039;&#039;, 187401 (2019)]; [https://arxiv.org/abs/1810.08976 arXiv1810.089776] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;chen2020&#039;&amp;gt;&#039;&#039;Exciton-Phonon Interaction and Relaxation Times from First Principles&#039;&#039;,&lt;br /&gt;
Hsiao-Yi Chen, Davide Sangalli, and Marco Bernardi, [https://doi.org/10.1103/PhysRevLett.125.107401  Phys. Rev. Lett. &#039;&#039;&#039;125&#039;&#039;&#039;, 107401 (2020)]; [https://arxiv.org/abs/2002.08913 arXiv 2002.08913 (2020)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;lechifflart2023_PhD&amp;quot;&amp;gt;P. Lechifflart, &#039;&#039;Exciton-phonon coupling and phonon-assisted luminescence in hexagonal Boron Nitride nanostructures&#039;&#039;, [https://hal.science/tel-04266805v1 PhD Thesis, University of Marseille (2023)]; [https://www.yambo-code.eu/wiki/images/5/54/These_final.pdf From the yambo website]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;paleari2019_PhD&#039;&amp;gt;F. Paleari, &#039;&#039;First-principles approaches to the description of indirect absorption and luminescence spectroscopy: exciton-phonon coupling in hexagonal boron nitride&#039;&#039;, [https://wwwen.uni.lu/research/fstm/dphyms/people/fulvio_paleari PhD thesis, University of Luxembourg (2019)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;zanfrognini2023&#039;&amp;gt;M. Zanfrognini et al., &#039;&#039;Distinguishing different stackings in layered materials via luminescence spectroscopy&#039;&#039;, [https://doi.org/10.1103/PhysRevLett.131.206902 Phys. Rev. Lett. &#039;&#039;&#039;131&#039;&#039;&#039;, 206902 (2023)]; [https://arxiv.org/abs/2305.17554 arXiv 2305.17554] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;marini2024&#039;&amp;gt;G. Marini, M. Calandra, P. Cudazzo, &#039;&#039;Optical absorption and photoluminescence of single layer boron nitride from a first principles cumulant approach&#039;&#039;, [https://doi.org/10.1021/acs.nanolett.4c00669 Nano Lett., &#039;&#039;&#039;24&#039;&#039;&#039;, 20, 6017 (2024)]; [https://arxiv.org/abs/2402.03826 arXiv 2402.03826 (2024)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;antonius2017&#039;&amp;gt;G. Antonius, S. G. Louie, &#039;&#039;Theory of exciton-phonon coupling&#039;&#039;, [https://doi.org/10.1103/PhysRevB.105.085111 Phys. Rev. B, &#039;&#039;&#039;105&#039;&#039;&#039;, 085111 (2022)]; [https://arxiv.org/abs/1705.04245 arXiv1705.04245 (2017)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;paleari2022&#039;&amp;gt; F. Paleari, and A. Marini, &#039;&#039;Exciton-phonon interaction calls for a revision of the “exciton” concept&#039;&#039;, [https://doi.org/10.1103/PhysRevB.106.125403 Phys. Rev. B, &#039;&#039;&#039;106&#039;&#039;&#039;, 125403 (2022)]; [https://arxiv.org/abs/2205.02783 arXiv 2205.02783]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;cudazzo2020&#039;&amp;gt; P. Cudazzo, &#039;&#039;First-principles description of the exciton-phonon interaction: A cumulant approach&#039;&#039;, [https://doi.org/10.1103/PhysRevB.102.045136 Phys. Rev. B, &#039;&#039;&#039;102&#039;&#039;&#039;, 045136 (2020)]; [https://orbilu.uni.lu/bitstream/10993/44769/1/main.pdf Open access pdf from Luxembourg University]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;chan2023&#039;&amp;gt;Y-h Chan, J. B. Haber, M. H. Naik, J. B. Neaton, D. Y. Qiu, F. H. da Jornada, S. G. Louie, &#039;&#039;Exciton Lifetime and Optical Line Width Profile via Exciton–Phonon Interactions: Theory and First-Principles Calculations for Monolayer MoS2&#039;&#039;, [https://doi.org/10.1021/acs.nanolett.3c00732 Nano Lett., &#039;&#039;&#039;23&#039;&#039;&#039;, 9 (2023)]; [https://arxiv.org/abs/2212.08451 arXiv 2212.08451 (2023)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;murali2025&#039;&amp;gt;M. Nalabothula, S. Reichardt, L. Wirtz, &#039;&#039;Origin of Interlayer Exciton–Phonon Coupling in 2D Heterostructures&#039;&#039;, [https://doi.org/10.1021/acs.nanolett.5c00355 Nano Lett., &#039;&#039;&#039;25&#039;&#039;&#039;, 15 (2025)], [https://arxiv.org/abs/2407.16111 arXiv 2407.16111 (2025)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>FulvioPaleari</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Exciton-phonon_coupling_and_luminescence&amp;diff=9343</id>
		<title>Exciton-phonon coupling and luminescence</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Exciton-phonon_coupling_and_luminescence&amp;diff=9343"/>
		<updated>2026-03-13T14:47:46Z</updated>

		<summary type="html">&lt;p&gt;FulvioPaleari: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:Tdgw-phonon-usc-01-1024x829.jpg|thumb|right|400px|(c) Zhenglu Li, University of Southern California]]&lt;br /&gt;
&lt;br /&gt;
In this advanced tutorial, we will calculate exciton-phonon interactions from first principles by interfacing DFPT (for phonon calculations) and BSE (for exciton calculations).&lt;br /&gt;
&lt;br /&gt;
The DFTP calculations are run with Quantum ESPRESSO, while the many-body GW-BSE calculations are run with Yambo. Finally, the exciton-phonon interaction will be obtained by combining and postprocessing the databases computed in the two previous runs. The great advantage of this workflow is that the calculations can be run in the irreducible Brillouin zones both for the electronic momenta (&#039;&#039;&#039;k&#039;&#039;&#039;) and the transfer momenta (&#039;&#039;&#039;Q&#039;&#039;&#039;, &#039;&#039;&#039;q&#039;&#039;&#039;) of excitons and phonons, thus speeding up considerably the jobs while reducing the IO and memory load.&lt;br /&gt;
&lt;br /&gt;
We will first compute the exciton-phonon coupling matrix elements: these are the building blocks needed to construct experimental observables such as phonon-assisted optical spectra (such as luminescence), Raman spectra and exciton lifetimes. We will do this in the case of monolayer MoS&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;, a 2D system with large spin-orbit interaction.&lt;br /&gt;
&lt;br /&gt;
As an example of application, we will consider the case of phonon-assisted luminescence. We will do this in the case of bulk hBN, a layered indirect insulator with strong electron-phonon coupling.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; this tutorial will be updated when new exc-ph tools become available in Yambopy (including full-python postprocessing, Raman spectra, interpolated lifetimes, etc).&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
This is an advanced topic: we assume that you already know something about the theory&amp;lt;ref name=&amp;quot;toyozawa2003&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;antonius2017&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;cudazzo2020&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;paleari2019_PhD&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;paleari2022&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;lechifflart2023_PhD&amp;quot; /&amp;gt; and applications&amp;lt;ref name=&amp;quot;paleari2019&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;cannuccia2019&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;chen2020&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;zanfrognini2023&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;lechifflart2023&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;chan2023&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;marini2024&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;murali2025&amp;quot; /&amp;gt; of exciton-phonon physics. &lt;br /&gt;
&lt;br /&gt;
Also, we assume that you already know how to run both a basic &#039;&#039;&#039;Yambo&#039;&#039;&#039; GW-BSE calculation and a DFPT phonon calculation with &#039;&#039;&#039;Quantum ESPRESSO&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Besides the QE executables &amp;lt;code&amp;gt;pw.x&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ph.x&amp;lt;/code&amp;gt;, we also use the yambo phonon-specific executable &amp;lt;code&amp;gt;yambo_ph&amp;lt;/code&amp;gt; and the python utility &#039;&#039;&#039;Yambopy&#039;&#039;&#039;. The auxiliary code &#039;&#039;&#039;LetzElPhC&#039;&#039;&#039; (executable &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt;) will be used to obtain the electron-phonon matrix elements by reading the same electronic wavefunctions used by Yambo (and stored in the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory), while also making full use of crystal symmetries. [https://github.com/yambo-code/LetzElPhC LetzElPhC] will be run by Yambopy, but it must nonetheless be installed. Finally, the exciton-phonon properties can be computed either using &amp;lt;code&amp;gt;yambo_ph&amp;lt;/code&amp;gt; or using Yambopy itself. Both cases will be covered in this tutorial.&lt;br /&gt;
&lt;br /&gt;
[[File:Workflow scheme.png|800px|center]]&lt;br /&gt;
&lt;br /&gt;
== Step 0: Pseudopotentials, equilibrium structure and convergence ==&lt;br /&gt;
&lt;br /&gt;
In a real calculation, it is important to ensure that both the pseudopotential and the lattice parameters that we are using are compatible and perform well for the electronic excited states and for the lattice vibrations simultaneously. Furthermore, you have to make sure that the wave function cutoff &amp;lt;code&amp;gt;ecutwfc&amp;lt;/code&amp;gt; is converged with respect to the DFPT step and not just to the DFT one. This is in addition to the other customary convergence tests for DFT, DFPT, GW and BSE calculations.&lt;br /&gt;
&lt;br /&gt;
This is often the most time-demanding step when starting on a new system.&lt;br /&gt;
&lt;br /&gt;
For the sake of this tutorial, we assume that we have already done all these tests and we are starting the final workflow to get the exciton-phonon properties.&lt;br /&gt;
&lt;br /&gt;
== Step 1: scf calculation ==&lt;br /&gt;
&lt;br /&gt;
First of all, we run a standard scf calculation with &amp;lt;code&amp;gt;pw.x&amp;lt;/code&amp;gt; for Yambo. We stick with non-symmorphic symmetries. At the end, we will have the QE &amp;lt;code&amp;gt;save&amp;lt;/code&amp;gt; directory.&lt;br /&gt;
&lt;br /&gt;
This is the input &amp;lt;code&amp;gt;mos2.scf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 &amp;amp;control&lt;br /&gt;
           wf_collect = .true.,&lt;br /&gt;
          calculation = &amp;quot;scf&amp;quot;,&lt;br /&gt;
            verbosity = &#039;high&#039;,&lt;br /&gt;
           pseudo_dir = &#039;$PSEUDO_DIR&#039;,&lt;br /&gt;
               prefix = &amp;quot;mos2&amp;quot;,&lt;br /&gt;
               outdir = &#039;.&#039;,&lt;br /&gt;
  /&amp;amp;end&lt;br /&gt;
  &amp;amp;system&lt;br /&gt;
              ecutwfc = 100.0,&lt;br /&gt;
          occupations = &#039;fixed&#039;,&lt;br /&gt;
                ibrav = 4,&lt;br /&gt;
            celldm(1) = 5.9000811881,&lt;br /&gt;
            celldm(3) = 6.7795677253,&lt;br /&gt;
                  nat = 3,&lt;br /&gt;
                 ntyp = 2,&lt;br /&gt;
             lspinorb = .true.&lt;br /&gt;
             noncolin = .true.&lt;br /&gt;
             assume_isolated = &#039;2D&#039;&lt;br /&gt;
         force_symmorphic = .true.&lt;br /&gt;
  /&amp;amp;end&lt;br /&gt;
  &amp;amp;electrons&lt;br /&gt;
     electron_maxstep = 200,&lt;br /&gt;
          mixing_beta = 0.7,&lt;br /&gt;
             conv_thr = 1.d-08,&lt;br /&gt;
  /&amp;amp;end&lt;br /&gt;
   ATOMIC_SPECIES&lt;br /&gt;
    Mo  95.940      Mo_ONCV_PBE_FR-1.0.upf&lt;br /&gt;
    S    32.065     S_ONCV_PBE_FR-1.1.upf&lt;br /&gt;
   ATOMIC_POSITIONS { crystal }&lt;br /&gt;
 Mo       0.333333333   0.666666667   0.000000000&lt;br /&gt;
 S        0.666666667   0.333333333   0.073413577&lt;br /&gt;
 S        0.666666667   0.333333333  -0.073413577&lt;br /&gt;
  K_POINTS { automatic }&lt;br /&gt;
 6 6 1 0 0 0&lt;br /&gt;
&lt;br /&gt;
Here we are using full relativistic pseudopotentials from the SG-15 database.&lt;br /&gt;
&lt;br /&gt;
We can run it on our machine (for example using 4 MPI tasks) as:&lt;br /&gt;
&lt;br /&gt;
 mpirun -np 4 pw.x -inp mos2.scf &amp;gt; scf.out&lt;br /&gt;
&lt;br /&gt;
== Step 2: nscf calculation for Yambo ==&lt;br /&gt;
&lt;br /&gt;
Copy the QE &amp;lt;code&amp;gt;save&amp;lt;/code&amp;gt; directory from the scf calculation and run the nscf calculation for any number of empty states, with the correct &amp;lt;code&amp;gt;k&amp;lt;/code&amp;gt;-grid we want to use in Yambo. Here we are using a badly underconverged grid of 6x6x1.&lt;br /&gt;
&lt;br /&gt;
This reciprocal-space grid will also match the momentum transfer &amp;lt;code&amp;gt;q&amp;lt;/code&amp;gt; grid on which excitons and phonons will be defined!&lt;br /&gt;
&lt;br /&gt;
The electronic wavefunctions computed at this step and stored in the new nscf &amp;lt;code&amp;gt;save&amp;lt;/code&amp;gt; directory will be used both by Yambo and by the electron-phonon code: this is important because using different sets of wavefunctions would lead to a phase mismatch issue in the exciton-phonon matrix elements.&lt;br /&gt;
&lt;br /&gt;
The nscf input &amp;lt;code&amp;gt;mos2.nscf&amp;lt;/code&amp;gt; is&lt;br /&gt;
 &amp;amp;control&lt;br /&gt;
           wf_collect = .true.,&lt;br /&gt;
          calculation = &amp;quot;nscf&amp;quot;,&lt;br /&gt;
            verbosity = &#039;high&#039;,&lt;br /&gt;
           pseudo_dir = &#039;$PSEUDO_DIR&#039;,&lt;br /&gt;
               prefix = &amp;quot;mos2&amp;quot;,&lt;br /&gt;
               outdir = &#039;.&#039;,&lt;br /&gt;
  /&amp;amp;end&lt;br /&gt;
  &amp;amp;system&lt;br /&gt;
              ecutwfc = 100.0,&lt;br /&gt;
          occupations = &#039;fixed&#039;,&lt;br /&gt;
                ibrav = 4,&lt;br /&gt;
            celldm(1) = 5.9000811881,&lt;br /&gt;
            celldm(3) = 6.7795677253,&lt;br /&gt;
                  nat = 3,&lt;br /&gt;
                 ntyp = 2,&lt;br /&gt;
             lspinorb = .true.&lt;br /&gt;
             noncolin = .true.&lt;br /&gt;
                nbnd  = 250&lt;br /&gt;
             assume_isolated = &#039;2D&#039;&lt;br /&gt;
         force_symmorphic = .true.&lt;br /&gt;
  /&amp;amp;end&lt;br /&gt;
  &amp;amp;electrons&lt;br /&gt;
     electron_maxstep = 200,&lt;br /&gt;
          mixing_beta = 0.7,&lt;br /&gt;
             conv_thr = 1.d-08,&lt;br /&gt;
  /&amp;amp;end&lt;br /&gt;
   ATOMIC_SPECIES&lt;br /&gt;
    Mo  95.940      Mo_ONCV_PBE_FR-1.0.upf&lt;br /&gt;
    S    32.065     S_ONCV_PBE_FR-1.1.upf&lt;br /&gt;
   ATOMIC_POSITIONS { crystal }&lt;br /&gt;
 Mo       0.333333333   0.666666667   0.000000000&lt;br /&gt;
 S        0.666666667   0.333333333   0.073413577&lt;br /&gt;
 S        0.666666667   0.333333333  -0.073413577&lt;br /&gt;
  K_POINTS { automatic }&lt;br /&gt;
 6 6 1 0 0 0&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Again, we run the calculation&lt;br /&gt;
&lt;br /&gt;
 mpirun -np 4 pw.x -inp mos2.nscf &amp;gt; nscf.out&lt;br /&gt;
&lt;br /&gt;
== Step 3: dvscf phonon calculation ==&lt;br /&gt;
&lt;br /&gt;
Now we run the phonon calculation.&lt;br /&gt;
&lt;br /&gt;
Copy the &amp;lt;code&amp;gt;save&amp;lt;/code&amp;gt; directory from the &#039;&#039;&#039;scf&#039;&#039;&#039; calculation and run &amp;lt;code&amp;gt;ph.x&amp;lt;/code&amp;gt; for a dvscf calculation with a standard &amp;lt;code&amp;gt;q&amp;lt;/code&amp;gt;-grid matching the &amp;lt;code&amp;gt;k&amp;lt;/code&amp;gt;-grid we wanna use in Yambo.&lt;br /&gt;
&lt;br /&gt;
At the end, we will have the &amp;lt;code&amp;gt;_ph0&amp;lt;/code&amp;gt; directory containing the variation of the self-consistent potential, &amp;lt;math&amp;gt;\Delta V_{SCF}(q)&amp;lt;/math&amp;gt;, and the &amp;lt;code&amp;gt;*.dyn&amp;lt;/code&amp;gt; files with the phonon energies and eigenvectors.&lt;br /&gt;
&lt;br /&gt;
NB: one could further refine the phonon energies by enforcing the acoustic sum rule, including non-analytic long-range contributions, interpolating to finer grids... all of this can be done within Quantum ESPRESSO and will not be covered in this version of the tutorial.&lt;br /&gt;
&lt;br /&gt;
The input is &amp;lt;code&amp;gt;mos2.dvscf&amp;lt;/code&amp;gt;:&lt;br /&gt;
 &lt;br /&gt;
 mos2_dvscf&lt;br /&gt;
 &amp;amp;inputph&lt;br /&gt;
   tr2_ph=1.0d-12,&lt;br /&gt;
   verbosity=&#039;high&#039;&lt;br /&gt;
   prefix=&#039;mos2&#039;,&lt;br /&gt;
   fildvscf = &#039;mos2-dvscf&#039;,&lt;br /&gt;
   electron_phonon = &#039;dvscf&#039;,&lt;br /&gt;
   fildyn=&#039;mos2.dyn&#039;,&lt;br /&gt;
   epsil=.false.,&lt;br /&gt;
   ldisp=.true.,&lt;br /&gt;
   recover=.true.,&lt;br /&gt;
   nq1=6,&lt;br /&gt;
   nq2=6,&lt;br /&gt;
   nq3=1&lt;br /&gt;
 /&lt;br /&gt;
&lt;br /&gt;
And now we run as&lt;br /&gt;
&lt;br /&gt;
 nohup mpirun -np 8 ph.x -inp mos2.dvscf &amp;gt; dvscf.out &amp;amp;&lt;br /&gt;
&lt;br /&gt;
This time we use nohup and more processes because this calculation may take some time. It is a good idea to set &amp;lt;code&amp;gt;recover=.true.&amp;lt;/code&amp;gt; as in a real calculation you will easily breach walltime, and in this way you can safely restart.&lt;br /&gt;
&lt;br /&gt;
== Step 4: create Yambo &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory ==&lt;br /&gt;
&lt;br /&gt;
This is just the standard Yambo initialization: run &lt;br /&gt;
 &lt;br /&gt;
 p2y &lt;br /&gt;
&lt;br /&gt;
and then &lt;br /&gt;
&lt;br /&gt;
 yambo &lt;br /&gt;
&lt;br /&gt;
in the &#039;&#039;&#039;nscf&#039;&#039;&#039; &amp;lt;code&amp;gt;save&amp;lt;/code&amp;gt; folder and then move the newly generated &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory to a convenient place.&lt;br /&gt;
&lt;br /&gt;
== Step 5: run a BSE calculation ==&lt;br /&gt;
&lt;br /&gt;
Now we switch from QE to Yambo. Here, we forgo the GW step for simplicity (we can use a scissor operator to open the band gap).&lt;br /&gt;
&lt;br /&gt;
This calculation has a couple of differences with respect to a standard BSE calculation for optical absorption. We can look at the input file &amp;lt;code&amp;gt;bse.in&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Runlevels&amp;lt;/span&amp;gt;&lt;br /&gt;
 optics                       # [R OPT] Optics&lt;br /&gt;
 rim_cut                      # [R RIM CUT] Coulomb potential&lt;br /&gt;
 bss                          # [R BSS] Bethe Salpeter Equation solver&lt;br /&gt;
 em1s                         # [R Xs] Static Inverse Dielectric Matrix&lt;br /&gt;
 bse                          # [R BSE] Bethe Salpeter Equation.&lt;br /&gt;
 bsk                          # [R BSK] Bethe Salpeter Equation kernel&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# RIM and cutoff settings&amp;lt;/span&amp;gt;&lt;br /&gt;
 RandQpts=1000000             # [RIM] Number of random q-points in the BZ&lt;br /&gt;
 RandGvec= 100            RL    # [RIM] Coulomb interaction RS components&lt;br /&gt;
 CUTGeo= &amp;quot;slab z&amp;quot;               # [CUT] Coulomb Cutoff geometry: box/cylinder/sphere X/Y/Z/XY..&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Static screening&amp;lt;/span&amp;gt;&lt;br /&gt;
 X_and_IO_CPU= &amp;quot;1 1 4 2 1&amp;quot;       # [PARALLEL] CPUs for each role&lt;br /&gt;
 X_and_IO_ROLEs= &amp;quot;q g k c v&amp;quot;      # [PARALLEL] CPUs roles (q,g,k,c,v)&lt;br /&gt;
 X_and_IO_nCPU_LinAlg_INV=-1      # [PARALLEL] CPUs for Linear Algebra (if -1 it is automatically set)&lt;br /&gt;
 Chimod= &amp;quot;hartree&amp;quot;            # [X] IP/Hartree/ALDA/LRC/BSfxc&lt;br /&gt;
 % BndsRnXs&lt;br /&gt;
    1 |  200 |                 # [Xs] Polarization function bands&lt;br /&gt;
 %&lt;br /&gt;
 % LongDrXs&lt;br /&gt;
  1.000000 | 1.000000 | 1.000000 |        # [Xs] [cc] Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 NGsBlkXs= 8000            mRy    # [Xs] Response block size&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# BSE&amp;lt;/span&amp;gt;&lt;br /&gt;
 BS_CPU= &amp;quot;4.1.2&amp;quot;                   # [PARALLEL] CPUs for each role&lt;br /&gt;
 BS_ROLEs= &amp;quot;k.eh.t&amp;quot;                 # [PARALLEL] CPUs roles (k,eh,t)&lt;br /&gt;
 BS_nCPU_diago=4              # [PARALLEL] CPUs for matrix diagonalization&lt;br /&gt;
 BSEmod= &amp;quot;causal&amp;quot;             # [BSE] resonant/causal/coupling&lt;br /&gt;
 BSKmod= &amp;quot;SEX&amp;quot;                # [BSE] IP/Hartree/HF/ALDA/SEX/BSfxc&lt;br /&gt;
 BSSmod= &amp;quot;d&amp;quot;                  # [BSS] (h)aydock/(d)iagonalization/(s)lepc/(i)nversion/(t)ddft`&lt;br /&gt;
 BSENGexx=  40000      mRy    # [BSK] Exchange components&lt;br /&gt;
 ALLGexx                      # [BSS] Force the use use all RL vectors for the exchange part&lt;br /&gt;
 BSENGBlk=  8000       mRy    # [BSK] Screened interaction block size&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;Lkind=&amp;quot;full&amp;quot;                  #[BSE,X] bar(default)/full/tilde&amp;lt;/span&amp;gt;&lt;br /&gt;
 % KfnQP_E&lt;br /&gt;
  1.000000 | 1.000000 | 1.000000 |        # [EXTQP BSK BSS] E parameters  (c/v) eV|adim|adim&lt;br /&gt;
 %&lt;br /&gt;
 % BEnRange&lt;br /&gt;
   0.00000 |  4.00000 | eV    # [BSS] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 % BDmRange&lt;br /&gt;
   0.05000 |  0.05000 | eV    # [BSS] Damping range&lt;br /&gt;
 %&lt;br /&gt;
 BEnSteps= 2000               # [BSS] Energy steps&lt;br /&gt;
 % BLongDir&lt;br /&gt;
  1.000000 | 0.000000 | 0.000000 |        # [BSS] [cc] Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;% BSEQptR&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 1 | 7 |                     # [BSK] Transferred momenta range&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;%&amp;lt;/span&amp;gt;&lt;br /&gt;
 % BSEBands&lt;br /&gt;
    25 |  28 |                 # [BSK] Bands range&lt;br /&gt;
 %&lt;br /&gt;
 WRbsWF                      # [BSS] Write to disk excitonic the FWs&lt;br /&gt;
 &lt;br /&gt;
This file was generated using the command: &amp;lt;code&amp;gt; yambo -X s -o b -k sex -y d -r&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
First of all, we compute the excitons for all the momenta in the irreducible Brillouin zone for our discrete grid via the &amp;lt;code&amp;gt;BSEQptR&amp;lt;/code&amp;gt; variable. This will be a &#039;&#039;&#039;finite-momentum&#039;&#039;&#039; BSE calculation, analogous to the phonon one.&lt;br /&gt;
&lt;br /&gt;
Second, we change the variable &amp;lt;code&amp;gt;Lkind&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;bar&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;full&amp;lt;/code&amp;gt;. In Yambo, &amp;lt;code&amp;gt;Lkind=&amp;quot;bar&amp;quot;&amp;lt;/code&amp;gt;, which is the default for optical absorption, means that we are computing the excitonic response function without the long-range component of the exchange interaction. This cannot be used when computing the exciton momentum dependence, where the long-range exchange interaction can play a role, therefore we have to include it with &amp;lt;code&amp;gt;Lkind=&amp;quot;full&amp;quot;&amp;lt;/code&amp;gt;. This allows for the calculation of the excitonic longitudinal-transverse splitting (in 3D systems) as well.&lt;br /&gt;
&lt;br /&gt;
We can now run the code:&lt;br /&gt;
&lt;br /&gt;
 nohup mpirun -np 8 yambo -F bse.in -J bse_Lfull -C bse_Lfull &amp;amp;&lt;br /&gt;
&lt;br /&gt;
At the end of the calculation, we have obtained the &amp;lt;code&amp;gt;ndb.BS_diago_Q*&amp;lt;/code&amp;gt; databases inside the directory &amp;lt;code&amp;gt;bse_Lfull&amp;lt;/code&amp;gt;. They contain information on the exciton energies and wavefunctions at each momentum. Do not forget to check the report and logs of your calculation in the same directory to make sure that the code is doing what you want.&lt;br /&gt;
&lt;br /&gt;
== Step 6: obtain the electron-phonon matrix elements ==&lt;br /&gt;
&lt;br /&gt;
We have finished the heavy simulations. Now it&#039;s time for the postprocessing. The first order of business is the reconstruction of the electron-phonon coupling matrix elements from the dvscf results and the electronic wavefunctions.&lt;br /&gt;
&lt;br /&gt;
In order to do this, we will run the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable of the &#039;&#039;&#039;LetzElPhC&#039;&#039;&#039; code. We will run via command line using yambopy, although it will be instructive to have look at the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; input files later.&lt;br /&gt;
&lt;br /&gt;
We run in the same directory where the Yambo &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; is (remember than you can also virtually move it with a symbolic link).&lt;br /&gt;
&lt;br /&gt;
Type:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y&lt;br /&gt;
&lt;br /&gt;
to see the help for the calculation. Have a look at the various flags and their description.&lt;br /&gt;
For example, if we want to do a serial run of LetzElPhC for bands from &amp;lt;math&amp;gt;n_i&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;n_f&amp;lt;/math&amp;gt;, we should type:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph path/of/ph_input.in -b n_i n_f&lt;br /&gt;
&lt;br /&gt;
Here &amp;lt;math&amp;gt;n_i&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;n_f&amp;lt;/math&amp;gt; are integers representing the initial and final band indices. &#039;&#039;&#039;Please note&#039;&#039;&#039;: in this case, the band index starts from 1 and the the interval of bands read by the code is &amp;lt;math&amp;gt;[n_i,n_f]&amp;lt;/math&amp;gt; including the extrema of the interval.&lt;br /&gt;
&lt;br /&gt;
These should coincide with those used for the Bethe-Salpeter kernel, i.e. those specified in the &amp;lt;code&amp;gt;BSEBands&amp;lt;/code&amp;gt; variable of the BSE input file (this is not strictly necessary, but certainly efficient since these calculations use a lot of disk space). &lt;br /&gt;
&lt;br /&gt;
For our system, we want to do a parallel calculation with 4 qpools and 2 kpools. In addition, we want to explicitly specify the path of the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable and avoid automatically deleting the LetzElPhC data. So we type:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph path/of/dvscf/mos2.dvscf -b 25 28 -par 4 2 -lelphc path/to/lelphc_exe&lt;br /&gt;
&lt;br /&gt;
At the end, check your directory: you should find the &amp;lt;code&amp;gt;lelphc.in&amp;lt;/code&amp;gt; input file that was run, let&#039;s inspect it: &lt;br /&gt;
&lt;br /&gt;
 # LetzElPhC input for yambo generated by yambopy&lt;br /&gt;
 nqpool      = 2&lt;br /&gt;
 nkpool      = 4&lt;br /&gt;
 start_bnd   = 25&lt;br /&gt;
 end_bnd     = 28&lt;br /&gt;
 save_dir    = ./SAVE&lt;br /&gt;
 kernel      = dfpt&lt;br /&gt;
 ph_save_dir = dvscf/ph_save&lt;br /&gt;
 convention = yambo&lt;br /&gt;
&lt;br /&gt;
Notice the variable &amp;lt;code&amp;gt;convention=yambo&amp;lt;/code&amp;gt;: what does it mean? At variance with QE and many other codes, Yambo uses the &amp;quot;backward&amp;quot; momentum transfer convention for electronic scatterings. That is, an electronic transition goes from band &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; and momentum &amp;lt;math&amp;gt;k-q&amp;lt;/math&amp;gt; to band &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; and momentum &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;. In the &amp;quot;forward&amp;quot; momentum transfer convention (the more standard one), the transitions go from &amp;lt;math&amp;gt;nk&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;mk+q&amp;lt;/math&amp;gt;. Therefore, this variable ensures that the electron-phonon coupling matrix elements are computed as &amp;lt;math&amp;gt;\langle mk|dV|nk-q\rangle&amp;lt;/math&amp;gt;. This will have consequences also in the formulation of the &#039;&#039;exciton&#039;&#039;-phonon coupling matrix element.&lt;br /&gt;
&lt;br /&gt;
You will also find a &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; database that contains the computed electron-phonon matrix elements, in the output format of &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In addition, if you check the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; folder:&lt;br /&gt;
&lt;br /&gt;
 ls SAVE/ndb.elph_gkkp*&lt;br /&gt;
&lt;br /&gt;
you will see that yambopy has created the Yambo-compatible electron-phonon databases.&lt;br /&gt;
&lt;br /&gt;
If you want to run LetzElPhC directly, without using yambopy, you can refer to its [[https://gitlab.com/lumen-code/LetzElPhC/-/blob/main/docs/main.pdf?ref_type=heads|user guide]].&lt;br /&gt;
Keep in mind that in this case, in order to convert the database to the &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases of Yambo, you will then need a couple of lines of python using the Yambopy class &amp;lt;code&amp;gt;ConvertElectronPhononDB&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;yambopy/letzelph_interface/lelph2y.py&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t need the &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases -- e.g., because you are doing the exc-ph postprocessing with yambopy -- you can run &amp;lt;code&amp;gt;yambopy l2y ...&amp;lt;/code&amp;gt; with the &amp;lt;code&amp;gt;--no_gkkp&amp;lt;/code&amp;gt; option.&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t need the &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; databases -- e.g., because you are using &amp;lt;code&amp;gt;yambo_ph&amp;lt;/code&amp;gt; for the exc-ph part -- you can run &amp;lt;code&amp;gt;yambopy l2y ...&amp;lt;/code&amp;gt; with the &amp;lt;code&amp;gt;--no_lelphc_dbs&amp;lt;/code&amp;gt; option.&lt;br /&gt;
&lt;br /&gt;
== Step 7: Obtain the exciton-phonon coupling ==&lt;br /&gt;
&lt;br /&gt;
Now, we can finally access our basic building block for exciton-phonon physics. This could be done entirely in python (using &#039;&#039;&#039;Yambopy&#039;&#039;&#039;), or by running &#039;&#039;&#039;Yambo&#039;&#039;&#039;. &lt;br /&gt;
&lt;br /&gt;
* For the &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&#039;&#039;&#039;Yambo postprocessing&#039;&#039;&#039;&amp;lt;/span&amp;gt; case (running yambo inputs with the &amp;lt;code&amp;gt;yambo_ph&amp;lt;/code&amp;gt; executable), &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&#039;&#039;&#039;follow the alternative route to Steps 7-8 [[Exciton-phonon coupling and luminescence - Yambo postprocessing|at this link]]&#039;&#039;&#039;&amp;lt;/span&amp;gt;.&lt;br /&gt;
* For the &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&#039;&#039;&#039;Yambopy postprocessing&#039;&#039;&#039;&amp;lt;/span&amp;gt; case (using flexible python scripting), &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&#039;&#039;&#039;keep following Steps 7-8 on this page&#039;&#039;&#039;&amp;lt;/span&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Our objective is obtaining the following quantity: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\mathcal{G}^\mu_{\alpha\lambda}(0,q)=\sum_{vv^\prime c k} A^{\alpha, *}_{cv^\prime} (k, q) g_{vv^\prime}^\mu (k,q) A^{\lambda}_{cv}(k,0) - \sum_{cc^\prime vk} A^{\alpha, *}_{c^\prime v} (k+q, q) g_{c^\prime c}^\mu (k+q,q) A^{\lambda}_{cv}(k, 0)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here, &amp;lt;math&amp;gt;A^{\alpha}_{cv}(k,q)&amp;lt;/math&amp;gt; are the exciton coefficients extracted from the eigenvector of the two-particles Hamiltonian during the BSE calculation in step 5, while &amp;lt;math&amp;gt;g_{nm}^\mu (k,q)&amp;lt;/math&amp;gt; are the electron-phonon coupling matrix elements obtained in step 6. As you can see, the exciton &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; undergoes phonon-mediated scattering to state &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; via phonon mode &amp;lt;math&amp;gt;\mu&amp;lt;/math&amp;gt;. The scattering can happen for the hole (valence, &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt;) or for the electron (conduction, &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
NB: &lt;br /&gt;
&lt;br /&gt;
(1) This is written in the &amp;quot;backward&amp;quot; momentum transfer convention used by Yambo. The momentum dependence is different in the &amp;quot;forward&amp;quot; transfer convention. &lt;br /&gt;
&lt;br /&gt;
(2) For simplicity, this is written for zero initial exciton momentum. This means that one of the two states involved in the phonon-mediated scattering process will be in the optical limit (and possibly an optically generated exciton), while the other state can have any momentum: this momentum will be the same as the phonon one. This matrix element can be used to describe phonon-assisted absorption and emission spectra.&lt;br /&gt;
&lt;br /&gt;
In order to calculate this quantity using python, we need the &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; databases natively generated by the &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; code, as well as the BSE databases &amp;lt;code&amp;gt;ndb.BS_diago_Q*&amp;lt;/code&amp;gt; containing the information on exciton wavefunctions and energies.&lt;br /&gt;
&lt;br /&gt;
Next, we write a python user script importing the yambopy exciton-phonon tools. You can find a version of this script in &amp;lt;code&amp;gt;yambopy/tutorials/exciton-phonon/calculate_excph.py&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
 import numpy as np &lt;br /&gt;
 from yambopy import YamboLatticeDB,YamboWFDB,LetzElphElectronPhononDB &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;#Specific Yambopy dbs loading classes&amp;lt;/span&amp;gt;&lt;br /&gt;
 from yambopy.exciton_phonon.excph_matrix_elements import exciton_phonon_matelem &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;#Specific exc-ph functions&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 path = &#039;1L_MoS2&#039;&lt;br /&gt;
 bands_range=[24,28] &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# 2 valence bands, 2 conduction bands&amp;lt;/span&amp;gt;&lt;br /&gt;
 nexc = 12 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# number of excitonic states&amp;lt;/span&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 bsepath    = f&#039;{path}/bse-allq_full&#039; &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Path to BSE calculation (Lin=Lout)&amp;lt;/span&amp;gt;&lt;br /&gt;
 savepath   = f&#039;{path}/SAVE&#039;     &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Yambo SAVE&amp;lt;/span&amp;gt;&lt;br /&gt;
 ndb_elph   = f&#039;{path}/ndb.elph&#039; &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# LetzElPhC electron-phonon database (any convention)&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Read lattice&amp;lt;/span&amp;gt;&lt;br /&gt;
 lattice = YamboLatticeDB.from_db_file(filename=f&#039;{savepath}/ns.db1&#039;)&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Read electron-phonon&amp;lt;/span&amp;gt;&lt;br /&gt;
 elph    = LetzElphElectronPhononDB(ndb_elph,read_all=False)&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Read wave functions&amp;lt;/span&amp;gt;&lt;br /&gt;
 wfcs    = YamboWFDB(filename=&#039;ns.wf&#039;,save=savepath,latdb=lattice,bands_range=bands_range)&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Calculate exciton-phonon matrix elements&amp;lt;/span&amp;gt;&lt;br /&gt;
 exph = exciton_phonon_matelem(lattice,elph,wfcs,BSE_dir=bsepath,nexc_in=nexc,nexc_out=nexc,dmat_mode=&#039;save&#039;,exph_file=&#039;MoS2_Ex-ph.npy&#039;)&lt;br /&gt;
&lt;br /&gt;
In this script, we can select the number exciton states &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; with &amp;lt;code&amp;gt;nexc&amp;lt;/code&amp;gt;, the single-particle bands range with &amp;lt;code&amp;gt;bands_range&amp;lt;/code&amp;gt;. &#039;&#039;&#039;Please note&#039;&#039;&#039;: in this case, the band index starts from 0 (python indexing) and the the interval of bands read by the code is &amp;lt;math&amp;gt;[n_i,n_f)&amp;lt;/math&amp;gt;, therefore the last value (28 in the example) is excluded. That is, in the example we are selecting the 25th, 26th, 27th and 28th bands. Those bands have to be present in both the electron-phonon and BSE calculations. &lt;br /&gt;
&lt;br /&gt;
Here we calculate the couplings of the first twelve states at each finite-&amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; point including &amp;lt;math&amp;gt;q=0&amp;lt;/math&amp;gt;. We also include all the nine phonon modes of monolayer MoS2. We also need access to the Yambo &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory in order to read the electronic wavefunctions: they are used to compute the electronic representation matrices (&amp;lt;code&amp;gt;dmat&amp;lt;/code&amp;gt; in the code). The argument &amp;lt;code&amp;gt;dmat_mode&amp;lt;/code&amp;gt; can be set to &amp;lt;code&amp;gt;&#039;load&#039;&amp;lt;/code&amp;gt; for subsequent calculations.&lt;br /&gt;
&lt;br /&gt;
When we are satisfied with the input, we run the code:&lt;br /&gt;
&lt;br /&gt;
 python calculate_excph.py&lt;br /&gt;
&lt;br /&gt;
If you check the output, you should find the &amp;lt;code&amp;gt;MoS2_Ex-ph.npy&amp;lt;/code&amp;gt; binary file in the directory where you ran.&lt;br /&gt;
&lt;br /&gt;
=== Analysis of the couplings ===&lt;br /&gt;
&lt;br /&gt;
It is a good idea to have a look at what we computed up to now in order to make sure nothing has gone wrong. &lt;br /&gt;
&lt;br /&gt;
It is not easy to know what to expect (apart from symmetry and gauge compliance of the matrix elements), but one can work out the exciton-phonon selection rules in advance, check that the magnitude is reasonable, etc.&lt;br /&gt;
&lt;br /&gt;
It is also not easy to meaningfully plot this quantity. We have to make sure that we are not breaking degenerate states, otherwise the plots will not be invariant. &lt;br /&gt;
&lt;br /&gt;
First of all, we have to know our system: in monolayer MoS&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;, the first four excitons are all doubly degenerate. The first exciton responsible for a bright peak in the absorption spectrum (the &#039;&#039;&#039;A&#039;&#039;&#039; peak), is the second state, corresponding to state indices &amp;lt;code&amp;gt;(3,4)&amp;lt;/code&amp;gt; in fortran indexing or &amp;lt;code&amp;gt;(2,3)&amp;lt;/code&amp;gt; in python indexing. &lt;br /&gt;
&lt;br /&gt;
All these information can be obtained by analyzing the BSE results (this stuff is explained in the BSE tutorials) and by knowledge of the system or class of systems from the literature.&lt;br /&gt;
&lt;br /&gt;
Thus, a good quantity to plot may be the norm of the matrix elements, summed over the degenerate subspace of exciton A, for a certain number of scattered final states mediated by certain phonon modes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;F_A(q)= \sqrt{ \sum_{\alpha \in A,\lambda,\mu} |\mathcal{G}_{\alpha\lambda}^\mu (0,q)|^2 }&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In order to do this, we create a python script &amp;lt;code&amp;gt;analyse_excph.py&amp;lt;/code&amp;gt; in which we first load the excph dabatases. &lt;br /&gt;
You can find a version of this script in the yambopy directory, in &amp;lt;code&amp;gt;tutorials/exciton-phonon&amp;lt;/code&amp;gt;. &lt;br /&gt;
First, we select the exciton and phonon states to be included in &amp;lt;code&amp;gt;F_A&amp;lt;/code&amp;gt;, together with the path of databases and plot details:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Exciton &amp;quot;in&amp;quot; states&amp;lt;/span&amp;gt;&lt;br /&gt;
 exc_in  = [2,3]  &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# First bright peak (A: 2,3 -- B: 6,7)&amp;lt;/span&amp;gt;&lt;br /&gt;
 exc_out = [0,1,2,3] &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# first 4 states (dispersion of dark triplet state and A)&amp;lt;/span&amp;gt;&lt;br /&gt;
 ph_in  = &#039;all&#039;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Paths of databases&amp;lt;/span&amp;gt;&lt;br /&gt;
 ns_db1 =f&#039;{path}/SAVE/ns.db1&#039;&lt;br /&gt;
 ns_ypy = &#039;MoS2_Ex-ph.npy&#039;&lt;br /&gt;
 &lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
Then, we load the data:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Read lattice and k-space info&amp;lt;/span&amp;gt;&lt;br /&gt;
 ylat = YamboLatticeDB.from_db_file(filename=ns_db1)&lt;br /&gt;
 print(ylat)&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Load exc-ph database&amp;lt;/span&amp;gt;&lt;br /&gt;
 X_py = np.load(ns_ypy)&lt;br /&gt;
 G_squared = np.abs(X_py)**2.&lt;br /&gt;
&lt;br /&gt;
The quantity &amp;lt;math&amp;gt;F_A(q)&amp;lt;/math&amp;gt; is obtained from a dedicated function as:&lt;br /&gt;
 &lt;br /&gt;
 if exc_in  == &#039;all&#039;: exc_in  = range(G_squared.shape[2])&lt;br /&gt;
 if exc_out == &#039;all&#039;: exc_out = range(G_squared.shape[3])&lt;br /&gt;
 if ph_in   == &#039;all&#039;: ph_in   = range(G_squared.shape[1])&lt;br /&gt;
 &lt;br /&gt;
 G_squared = G_squared[:, ph_in, :, :].sum(axis=(1))&lt;br /&gt;
 G_squared = G_squared[:, exc_in, :].sum(axis=(1))&lt;br /&gt;
 G_squared = G_squared[:, exc_out].sum(axis=(1))&lt;br /&gt;
 &lt;br /&gt;
 F_q = np.sqrt( G_squared )*ha2ev &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Switch from Ha to eV&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And finally, we have to make a plotting function. For this tutorial we will use a custom scatterplot employing some of the plotting tools provided by yambopy (but you can do whatever you want).&lt;br /&gt;
&lt;br /&gt;
 plot_2D_excph(qgrid,G2_to_plot,rlat=ylat.rlat,plt_cbar=True,\&lt;br /&gt;
               marker=&#039;H&#039;,s=700,cmap=&#039;magma&#039;)&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
You can get more experience on using Yambopy for these kinds of visualization by following the [https://wiki.yambo-code.eu/wiki/index.php?title=First_steps_in_Yambopy Yambopy tutorials]. In fact, remember that these scripts and all the other Yambopy tutorial scripts are just suggestions, not source code written in stone: if you know &amp;lt;code&amp;gt;numpy&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;matplotlib&amp;lt;/code&amp;gt; you can do your own analysis and your own plots, you just need to import the required Yambopy modules to load the data.&lt;br /&gt;
&lt;br /&gt;
In our case, the resulting plot is the following.&lt;br /&gt;
&lt;br /&gt;
[[File:1L MoS2 MoS2 Ex-ph.png|500px|center]]&lt;br /&gt;
&lt;br /&gt;
This can be checked against Fig. 2(d) of reference &amp;lt;ref name=&amp;quot;chan2023&amp;quot; /&amp;gt;, although you have to keep in mind that our results are badly undersampled in terms of the reciprocal-space grid, as can be easily seen, and the quantity plotted is not exactly the same. However, the main features are already there since they are dictated mostly by crystal symmetries.&lt;br /&gt;
&lt;br /&gt;
Now that we have the exciton-phonon matrix elements, we can use them to build several kinds of observables. Below, we give an example related to phonon-assisted luminescence, but we may update this tutorial in the future to include more cases.&lt;br /&gt;
&lt;br /&gt;
== Step 8: Compute phonon-assisted luminescence ==&lt;br /&gt;
&lt;br /&gt;
[[File:Luminescence scheme.png|250px|right]]&lt;br /&gt;
&lt;br /&gt;
We want to compute the experimental optical signature due to the phonon-assisted recombination of an exciton (as sketched in the figure).&lt;br /&gt;
&lt;br /&gt;
The signal from the phonon replicas can be modeled as a second-order scattering process involving one phonon and one photon:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;I^{Sat}(\omega)=\frac{1}{ N_q} \frac{1}{3} \sum_{\epsilon s\beta \mu q} \frac{1}{E_{\beta q}-s\Omega_{\mu q}}\left|\sum_\alpha\frac{ D^{\epsilon}_\alpha \mathcal{G}_{\beta \alpha}^{\mu,*}(q)}{E_\alpha -E_{\beta q} +s\Omega_{\mu q}+\mathrm{i}\eta}\right|^2 \frac{N^{exc}_{\beta q}(T_{exc})[\frac{1+s}{2}+n_{\mu q}(T)]}{\omega -[E_{\beta q}-s\Omega_{\mu q}]+\mathrm{i}\eta}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this equation, the oscillator strength of the peak is given by the exciton-phonon coupling matrix elements &amp;lt;math&amp;gt;\mathcal{G}&amp;lt;/math&amp;gt; multiplied by the exciton dipoles &amp;lt;math&amp;gt;D&amp;lt;/math&amp;gt; (they are called &amp;quot;residuals&amp;quot; in Yambo). Here &amp;lt;math&amp;gt;E_\lambda&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;E_{\alpha q}&amp;lt;/math&amp;gt; are the energies of the optical and finite-momentum excitons, respectively, while &amp;lt;math&amp;gt;\Omega_{\mu q}&amp;lt;/math&amp;gt; are the phonon energies. &lt;br /&gt;
&lt;br /&gt;
Here, &amp;lt;math&amp;gt;n_{\mu q}(T)&amp;lt;/math&amp;gt; is the temperature-dependent phonon Bose-Einstein occupation function. As it can be seen, &amp;lt;math&amp;gt;s=1&amp;lt;/math&amp;gt; corresponds to processes of phonon &#039;&#039;emission&#039;&#039; (&amp;lt;math&amp;gt;\propto n(T)+1&amp;lt;/math&amp;gt;), while &amp;lt;math&amp;gt;s=-1&amp;lt;/math&amp;gt; corresponds to processes of phonon &#039;&#039;absorption&#039;&#039; (&amp;lt;math&amp;gt;\propto n(T)&amp;lt;/math&amp;gt;). Therefore, &amp;lt;math&amp;gt;I^{Sat}_{PL}(\omega;T)&amp;lt;/math&amp;gt; describes &#039;&#039;light&#039;&#039; emission by recombining excitons mediated by either &#039;&#039;phonon&#039;&#039; absorption or emission. &lt;br /&gt;
&lt;br /&gt;
The quantity &amp;lt;math&amp;gt; N_{\alpha q}(T_{exc})&amp;lt;/math&amp;gt; is the exciton occupation function. Luminescence is technically an out-of-equilibrium process, but we can assume that for very low density of excitations and in steady-state conditions, the exciton population can be approximately described by an equilibrium distribution evaluated at an effective temperature. Here, we use the Boltzmann distribution. Experimentally, &amp;lt;math&amp;gt;T_{exc}&amp;lt;/math&amp;gt; tends to coincide with the lattice temperature &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt; more or less above 100 K, while at very low temperature (&amp;lt; 10 K), &amp;lt;math&amp;gt;T_{exc}&amp;lt;/math&amp;gt; may vary between 10-50 K. It goes without saying that this needs to carefully be checked in your realistic calculations.&lt;br /&gt;
&lt;br /&gt;
Finally, the spectrum is averaged over the polarization directions of the emitted photons (&amp;lt;math&amp;gt;\epsilon=x,y,z&amp;lt;/math&amp;gt; representing the respective dipole components).&lt;br /&gt;
&lt;br /&gt;
=== Running the jobs ===&lt;br /&gt;
&lt;br /&gt;
In order to study luminescence in a paradigmatic system, we switch to bulk hexagonal boron nitride and we repeat the workflow. As you can easily see, one can think about automatizing the execution of all these calculations via scripting or more advanced tools. However, in the case of very large simulations (memory-limited or disk-space limited) or for systems whose electronic and lattice properties are fragile with respect to tiny calculation details, one must be very careful and run many basic tests.&lt;br /&gt;
&lt;br /&gt;
Fortunately, we are running a fast underconverged example. We use LDA pseudopotentials from the pseudo-dojo library and the following are the calculations steps.&lt;br /&gt;
&lt;br /&gt;
1. Input &amp;lt;code&amp;gt;hbn.scf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 &amp;amp;control&lt;br /&gt;
     calculation=&#039;scf&#039;,&lt;br /&gt;
     prefix=&#039;hBN&#039;,&lt;br /&gt;
     restart_mode=&#039;from_scratch&#039;&lt;br /&gt;
     pseudo_dir = &#039;$PSEUDO_DIR&#039;,&lt;br /&gt;
     outdir = &#039;./tmp&#039;&lt;br /&gt;
     verbosity = &#039;high&#039;&lt;br /&gt;
     wf_collect=.true.&lt;br /&gt;
 /&lt;br /&gt;
 &amp;amp;system&lt;br /&gt;
     ibrav = 4,&lt;br /&gt;
     celldm(1) = 4.703675849&lt;br /&gt;
     celldm(3) = 2.603711434&lt;br /&gt;
     nat= 4,&lt;br /&gt;
     ntyp= 2,&lt;br /&gt;
     force_symmorphic=.true.&lt;br /&gt;
     ecutwfc = 100,&lt;br /&gt;
 /&lt;br /&gt;
 &amp;amp;electrons&lt;br /&gt;
   diago_david_ndim = 2&lt;br /&gt;
   diago_full_acc=.true.&lt;br /&gt;
   diago_thr_init=5.0e-6&lt;br /&gt;
   mixing_mode = &#039;plain&#039;&lt;br /&gt;
   mixing_beta = 0.7&lt;br /&gt;
   conv_thr =  1.0d-16&lt;br /&gt;
 /&lt;br /&gt;
 ATOMIC_SPECIES&lt;br /&gt;
  B 10.81100  B_LDA_dojo.UPF&lt;br /&gt;
  N 14.00674  N_LDA_dojo.UPF&lt;br /&gt;
 ATOMIC_POSITIONS {crystal}&lt;br /&gt;
 N             0.6666666670        0.3333333330        -0.250000000000&lt;br /&gt;
 B             0.3333333330        0.6666666670        -0.250000000000&lt;br /&gt;
 B             0.6666666670        0.3333333330        0.25000000000&lt;br /&gt;
 N             0.3333333330        0.6666666670        0.25000000000&lt;br /&gt;
 K_POINTS {automatic}&lt;br /&gt;
 6 6 2 0 0 0&lt;br /&gt;
&lt;br /&gt;
 mpirun -np 4 pw.x -inp hbn.scf &amp;gt; scf.out&lt;br /&gt;
&lt;br /&gt;
2. Input &amp;lt;code&amp;gt;hbn.nscf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 &amp;amp;control&lt;br /&gt;
     calculation=&#039;nscf&#039;,&lt;br /&gt;
     prefix=&#039;hBN&#039;,&lt;br /&gt;
     restart_mode=&#039;from_scratch&#039;&lt;br /&gt;
     pseudo_dir = &#039;$PSEUDO_DIR&#039;&lt;br /&gt;
     outdir = &#039;./&#039;&lt;br /&gt;
     verbosity = &#039;high&#039;&lt;br /&gt;
     wf_collect=.true.&lt;br /&gt;
 /&lt;br /&gt;
 &amp;amp;system&lt;br /&gt;
     ibrav = 4,&lt;br /&gt;
     celldm(1) = 4.703675849&lt;br /&gt;
     celldm(3) = 2.603711434&lt;br /&gt;
     nat= 4,&lt;br /&gt;
     ntyp= 2,&lt;br /&gt;
     force_symmorphic=.true.&lt;br /&gt;
     ecutwfc = 100,&lt;br /&gt;
 	nbnd = 120&lt;br /&gt;
 /&lt;br /&gt;
 &amp;amp;electrons&lt;br /&gt;
   diago_david_ndim = 2&lt;br /&gt;
   diago_full_acc=.true.&lt;br /&gt;
   diago_thr_init=5.0e-6&lt;br /&gt;
   mixing_mode = &#039;plain&#039;&lt;br /&gt;
   mixing_beta = 0.7&lt;br /&gt;
   conv_thr =  1.0d-16&lt;br /&gt;
 /&lt;br /&gt;
 ATOMIC_SPECIES&lt;br /&gt;
  B 10.81100  B_LDA_dojo.UPF&lt;br /&gt;
  N 14.00674  N_LDA_dojo.UPF&lt;br /&gt;
 ATOMIC_POSITIONS {crystal}&lt;br /&gt;
 N             0.6666666670        0.3333333330        -0.250000000000&lt;br /&gt;
 B             0.3333333330        0.6666666670        -0.250000000000&lt;br /&gt;
 B             0.6666666670        0.3333333330        0.25000000000&lt;br /&gt;
 N             0.3333333330        0.6666666670        0.25000000000&lt;br /&gt;
 K_POINTS {automatic}&lt;br /&gt;
 6 6 2 0 0 0&lt;br /&gt;
&lt;br /&gt;
 mpirun -np 4 pw.x -inp hbn.nscf &amp;gt; nscf.out&lt;br /&gt;
&lt;br /&gt;
3. Input &amp;lt;code&amp;gt;hbn.dvscf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 hbn_dvscf&lt;br /&gt;
 &amp;amp;inputph&lt;br /&gt;
   tr2_ph=1.0d-12,&lt;br /&gt;
   verbosity=&#039;high&#039;&lt;br /&gt;
   prefix=&#039;hBN&#039;,&lt;br /&gt;
   fildvscf = &#039;hBN-dvscf&#039;,&lt;br /&gt;
   electron_phonon = &#039;dvscf&#039;,&lt;br /&gt;
   fildyn=&#039;hBN.dyn&#039;,&lt;br /&gt;
   epsil=.false.,&lt;br /&gt;
   ldisp=.true.,&lt;br /&gt;
   recover=.true.,&lt;br /&gt;
   nq1=6,&lt;br /&gt;
   nq2=6,&lt;br /&gt;
   nq3=2&lt;br /&gt;
 /&lt;br /&gt;
&lt;br /&gt;
 nohup mpirun -np 8 pw.x -inp hbn.dvscf &amp;gt; dvscf.out &amp;amp;&lt;br /&gt;
&lt;br /&gt;
4. Input &amp;lt;code&amp;gt;bse.in&amp;lt;/code&amp;gt; (we include 2 valence and 2 conduction bands):&lt;br /&gt;
&lt;br /&gt;
 optics                           # [R] Linear Response optical properties&lt;br /&gt;
 bss                              # [R] BSE solver&lt;br /&gt;
 bse                              # [R][BSE] Bethe Salpeter Equation.&lt;br /&gt;
 dipoles                          # [R] Oscillator strenghts (or dipoles)&lt;br /&gt;
 em1s&lt;br /&gt;
 DIP_CPU= &amp;quot;1 8 1&amp;quot;                      # [PARALLEL] CPUs for each role&lt;br /&gt;
 DIP_ROLEs= &amp;quot;k c v&amp;quot;                    # [PARALLEL] CPUs roles (k,c,v)&lt;br /&gt;
 DIP_Threads=0                    # [OPENMP/X] Number of threads for dipoles&lt;br /&gt;
 X_and_IO_CPU= &amp;quot;1 1 1 8 1&amp;quot;                 # [PARALLEL] CPUs for each role&lt;br /&gt;
 X_and_IO_ROLEs= &amp;quot;q g k c v&amp;quot;               # [PARALLEL] CPUs roles (q,g,k,c,v)&lt;br /&gt;
 X_and_IO_nCPU_LinAlg_INV=-1      # [PARALLEL] CPUs for Linear Algebra (if -1 it is automatically set)&lt;br /&gt;
 X_Threads=0                      # [OPENMP/X] Number of threads for response functions&lt;br /&gt;
 BS_CPU= &amp;quot;8 1 1&amp;quot;                       # [PARALLEL] CPUs for each role&lt;br /&gt;
 BS_ROLEs= &amp;quot;k eh t&amp;quot;                     # [PARALLEL] CPUs roles (k,eh,t)&lt;br /&gt;
 BS_nCPU_LinAlg_INV=-1            # [PARALLEL] CPUs for Linear Algebra (if -1 it is automatically set)&lt;br /&gt;
 BS_nCPU_LinAlg_DIAGO=-1          # [PARALLEL] CPUs for Linear Algebra (if -1 it is automatically set)&lt;br /&gt;
 X_Threads=0                      # [OPENMP/X] Number of threads for response functions&lt;br /&gt;
 K_Threads=0                      # [OPENMP/BSK] Number of threads for response functions&lt;br /&gt;
 % QpntsRXs&lt;br /&gt;
    1 | 14 |                         # [Xs] Transferred momenta&lt;br /&gt;
 %&lt;br /&gt;
 % BndsRnXs&lt;br /&gt;
    1 | 120 |                         # [Xs] Polarization function bands&lt;br /&gt;
 %&lt;br /&gt;
 NGsBlkXs= 10                Ry    # [Xs] Response block size&lt;br /&gt;
 % LongDrXs&lt;br /&gt;
  1.000000 | 1.000000 | 1.000000 |        # [Xs] [cc] Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 BSEmod= &amp;quot;resonant&amp;quot;               # [BSE] resonant/retarded/coupling&lt;br /&gt;
 BSKmod= &amp;quot;SEX&amp;quot;                    # [BSE] IP/Hartree/HF/ALDA/SEX/BSfxc&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;Lkind= &amp;quot;Lfull&amp;quot;                    # [BSE] Lbar (default) / full&amp;lt;/span&amp;gt;&lt;br /&gt;
 BSSmod= &amp;quot;d&amp;quot;                      # [BSS] (h)aydock/(d)iagonalization/(s)lepc/(i)nversion/(t)ddft`&lt;br /&gt;
 % DipBands&lt;br /&gt;
    1 | 120 |                         # [DIP] Bands range for dipoles&lt;br /&gt;
 %&lt;br /&gt;
 DipApproach= &amp;quot;G-space v&amp;quot;         # [DIP] [G-space v/R-space x/Covariant/Shifted grids]&lt;br /&gt;
 DipComputed= &amp;quot;R V P&amp;quot;             # [DIP] [default R P V; extra P2 Spin Orb]&lt;br /&gt;
 BSENGexx= 30000            Ry    # [BSK] Exchange components&lt;br /&gt;
 #ALLGexx                       # [BSS] Force the use use all RL vectors for the exchange part&lt;br /&gt;
 BSENGBlk=  9000            Ry    # [BSK] Screened interaction block size [if -1 uses all the G-vectors of W(q,G,Gp)]&lt;br /&gt;
 % KfnQP_E&lt;br /&gt;
  1.25997 | 1.08816 | 1.12683 |        # [EXTQP BSK BSS] E parameters  (c/v) eV|adim|adim&lt;br /&gt;
 %&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;% BSEQptR&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 1 | 14 |                     # [BSK] Transferred momenta range&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;%&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;% BSEBands&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;   7 | 10 |                         # [BSK] Bands range&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;%&amp;lt;/span&amp;gt;&lt;br /&gt;
 % BEnRange&lt;br /&gt;
   0.50000 | 8.00000 |         eV    # [BSS] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 % BDmRange&lt;br /&gt;
  0.050000 | 0.050000 |         eV    # [BSS] Damping range&lt;br /&gt;
 %&lt;br /&gt;
 BEnSteps= 1000                    # [BSS] Energy steps&lt;br /&gt;
 % BLongDir&lt;br /&gt;
  1.000000 | 1.000000 | 0.000000 |        # [BSS] [cc] Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 WRbsWF                        # [BSS] Write to disk excitonic the WFs&lt;br /&gt;
&lt;br /&gt;
 nohup mpirun -np 8 yambo -F bse.in -J bse_Lfull -C bse_Lfull &amp;amp;&lt;br /&gt;
&lt;br /&gt;
Importantly, since we want to describe the phonon-assisted recombination process of an *optical* exciton (i.e., emitting a transverse photon), this time we also run an additional calculation at `Q=0` omitting the nonanalytic long-range Coulomb exchange. Make a second input &amp;lt;code&amp;gt;bse_Lbar.in&amp;lt;/code&amp;gt; with the following changes: &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;Lkind= &amp;quot;Lbar&amp;quot;                    # [BSE] Lbar (default) / full&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;% BSEQptR&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 1 | 1 |                     # [BSK] Transferred momenta range&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;%&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4b. So now we make a second BSE run in a different directory specified by &amp;lt;code&amp;gt;-J&amp;lt;/code&amp;gt;. Here, we also pass to yambo the directory of the previous run as it includes the important screening databases &amp;lt;code&amp;gt;ndb.em1s*&amp;lt;/code&amp;gt; that we do not want to recompute from scratch.&lt;br /&gt;
 &lt;br /&gt;
 mpirun -np 8 yambo -F bse_Lbar.in -J bse_Lbar,bse_Lfull -C bse_Lbar&lt;br /&gt;
&lt;br /&gt;
5. Now we run &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; (with or without yambopy: in the latter case remember the option &amp;lt;code&amp;gt;-D&amp;lt;/code&amp;gt;) to get the el-ph matrix elements, particularly the &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; databases:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph path/of/dvscf/hbn.dvscf -b 7 10 -par 4 2 -D&lt;br /&gt;
&lt;br /&gt;
=== Luminescence calculation ===&lt;br /&gt;
&lt;br /&gt;
6. And finally we calculate exciton-phonon matrix elements and the luminescence spectrum in one go using a python script importing the Yambopy exciton-phonon tools: in order to do this, we need to take a look at all the necessary input variables for the formula written above.&lt;br /&gt;
&lt;br /&gt;
We can start from the script &amp;lt;code&amp;gt;luminescence.py&amp;lt;/code&amp;gt; available in &amp;lt;code&amp;gt;tutorials/exciton-phonon&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
 import numpy as np&lt;br /&gt;
 import matplotlib.pyplot as plt&lt;br /&gt;
 from yambopy.exciton_phonon.excph_luminescence import exc_ph_luminescence&lt;br /&gt;
 from yambopy.exciton_phonon.excph_input_data import exc_ph_get_inputs&lt;br /&gt;
&lt;br /&gt;
We import the necessary tools...&lt;br /&gt;
&lt;br /&gt;
 path = &#039;3D_hBN&#039;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Path to BSE calculation (Lout--&amp;gt; response is Lfull)&amp;lt;/span&amp;gt;&lt;br /&gt;
 bsepath =  f&#039;{path}/bse_Lfull&#039; &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# ndb.BS_diago_Q* databases are needed&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Path to BSE calculation for optically active exciton (Lin --&amp;gt; response is Lbar)&amp;lt;/span&amp;gt;&lt;br /&gt;
 bseBARpath =  f&#039;{path}/bse_Lbar&#039;  &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# ndb.BS_diago_Q1 database is needed&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Path to electron-phonon calculation&amp;lt;/span&amp;gt;&lt;br /&gt;
 elphpath = path &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# ndb.elph is needed&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Path to unprojected dipoles matrix elements (optional)&amp;lt;/span&amp;gt;&lt;br /&gt;
 dipolespath = bsepath &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# ndb.dipoles is needed (optional)&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Path to lattice and k-space info&amp;lt;/span&amp;gt;&lt;br /&gt;
 savepath = f&#039;{path}/SAVE&#039; &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# ns.db1 database is needed&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
... and we specify the paths to the necessary databases. Note that, if we want to perform polarization averaging, we have to recompute the excitonic dipoles in python as seen here.&lt;br /&gt;
&lt;br /&gt;
What about &amp;lt;code&amp;gt;bseBARpath&amp;lt;/code&amp;gt;? This variable points to the directory where the databases for the optical (zero-momentum) excitons &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; (which may be computed with &amp;lt;code&amp;gt;Lkind=&#039;Lbar&#039;&amp;lt;/code&amp;gt;) is located, which can be different from the directory with the full indirect exciton dispersion &amp;lt;math&amp;gt;\beta&amp;lt;/math&amp;gt; (usually computed with &amp;lt;code&amp;gt;Lkind=&#039;Lfull&#039;&amp;lt;/code&amp;gt;, however &amp;lt;code&amp;gt;Lkind=&#039;Ltilde&#039;&amp;lt;/code&amp;gt; can also be used if one is interested in &amp;quot;irreducible&amp;quot; excitons). This makes it possible to compute the coupling between different exciton kinds.&lt;br /&gt;
&lt;br /&gt;
 bands_range=[6,10] &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# 2 valence, 2 conduction bands&amp;lt;/span&amp;gt;&lt;br /&gt;
 phonons_range=[0,12] &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# All phonons&amp;lt;/span&amp;gt;&lt;br /&gt;
 nexc_out = 12 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# 12 excitonic states at each momentum (Lout)&amp;lt;/span&amp;gt;&lt;br /&gt;
 nexc_in  = 12 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# 12 excitonic states at Q=0 (Lin)&amp;lt;/span&amp;gt;&lt;br /&gt;
 T_ph  = 10 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Lattice temperature&amp;lt;/span&amp;gt;&lt;br /&gt;
 T_exc = 10 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Effective excitonic temperature&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 emin=4.4      &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Energy range and plot details (in eV)&amp;lt;/span&amp;gt;&lt;br /&gt;
 emax=4.7&lt;br /&gt;
 estep=0.0002&lt;br /&gt;
 broad = 0.005 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Broadening parameter for peak width (in eV)&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next, we specify the parameters for the calculation. We include valence bands from 7 to 10 (6 to 9 in python index) and the contribution of all 12 phonon modes. We consider 12 excitonic states for the coupling matrix elements.&lt;br /&gt;
&lt;br /&gt;
Here &amp;lt;code&amp;gt;T_ph&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;T_exc&amp;lt;/code&amp;gt; are the lattice and excitonic temperatures, respectively.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# We calculate and load all the inputs:&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# * Exciton-phonon matrix elements&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# * Excitonic dipole matrix elements&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# * Exciton energies&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# * Phonon energies&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# * We specify bse_path2=bseBARpath meaning we use Lbar calculation for Q=0 excitons&amp;lt;/span&amp;gt;&lt;br /&gt;
 input_data = exc_ph_get_inputs(savepath,elphpath,bsepath,\&lt;br /&gt;
                                bse_path2=bseBARpath,dipoles_path=dipolespath,\&lt;br /&gt;
                                nexc_in=12,nexc_out=12,\&lt;br /&gt;
                                bands_range=[6,10],phonons_range=[0,12])&lt;br /&gt;
&lt;br /&gt;
 ph_energies, exc_energies, exc_energies_in, G, exc_dipoles = input_data&lt;br /&gt;
&lt;br /&gt;
The function &amp;lt;code&amp;gt;exc_ph_get_inputs&amp;lt;/code&amp;gt; gives us all the input data for luminescence in the correct format: phonon energies, exciton energies, optical exciton energies (if needed), exciton-phonon matrix elements (calculated on the fly and printed to file), unprojected exciton dipoles (optional, calculated on the fly and printed to file).&lt;br /&gt;
The exc-ph matrix element calculation is just a wrapper of the same tools that we have tested in the above section on MoS2.&lt;br /&gt;
&lt;br /&gt;
Finally, there is the calculation of the luminescence spectrum via the function &amp;lt;code&amp;gt;exc_ph_luminescence&amp;lt;/code&amp;gt;:&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# We calculate the luminescence spectrum including the input data from before&amp;lt;/span&amp;gt;&lt;br /&gt;
 w,PL = exc_ph_luminescence(T_ph,ph_energies,exc_energies,exc_dipoles,G,\&lt;br /&gt;
                            exc_energies_in=exc_energies_in,exc_temp=T_exc,\&lt;br /&gt;
                            nexc_out=nexc_out,nexc_in=nexc_in,emin=emin,emax=emax,\&lt;br /&gt;
                            estep=estep,broad=broad)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you want to print the luminescence data for later plotting, you can also add the following line to the script:&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Save to file&amp;lt;/span&amp;gt;&lt;br /&gt;
 data = np.column_stack((w, PL))&lt;br /&gt;
 np.savetxt(&amp;quot;hBN_luminescence_12x12x1.dat&amp;quot;, data, fmt=&amp;quot;%.8f&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
It is now time to run the whole script:&lt;br /&gt;
&lt;br /&gt;
 python luminescence.py&lt;br /&gt;
 &lt;br /&gt;
NB: By using Yambopy for Step 6, we have limited the use of the Yambo code to just step 4 in the entire workflow. This option is more flexible, as it allows for a greater degree of control by the user. On the other hand the Yambo postprocessing route features a Yambo-style input that doesn&#039;t require python knowledge and the calculation is currently faster in fortran. However, the luminescence expression computed in Yambo is a slightly different than this one: it is more approximated in the description of the satellite oscillator strengths, but it explicitly includes the renormalization of the direct exciton peak. You can check the differences [[Exciton-phonon coupling and luminescence - Yambo postprocessing|here]].&lt;br /&gt;
&lt;br /&gt;
=== Results ===&lt;br /&gt;
We can plot the results of the step 6 calculation. If we do it in the same script we can add something like this:&lt;br /&gt;
 fig = plt.figure()&lt;br /&gt;
 ax = fig.add_subplot(1,1,1)&lt;br /&gt;
 ax.set_xlim(emin,emax)&lt;br /&gt;
 ax.set_ylim(0,np.max(PL)*1.1)&lt;br /&gt;
 ax.get_yaxis().set_visible(False)&lt;br /&gt;
 &lt;br /&gt;
 ax.plot(w, PL, &#039;-&#039;,c=&#039;red&#039;, label=&amp;quot;AA&#039; hBN luminescence&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
 plt.legend()&lt;br /&gt;
 plt.savefig(&#039;hBN_luminescence.png&#039;)&lt;br /&gt;
 plt.show()&lt;br /&gt;
&lt;br /&gt;
[[File:HBN luminescence satellites.png|500px|center]]&lt;br /&gt;
&lt;br /&gt;
Here, the signal corresponds to a finite-momentum exciton that recombines with the help of several different phonon modes, both optical and acoustic. Each phonon mode whose coupling with the exciton is allowed can generate a peak, and the energy shifts of these peaks with respect to the initial exciton energy correspond to the phonon energies. This result is underconverged, but the main features are all there. In the plot, we show a more converged example using a 12x12x4 grid (all the other parameters being equal). These plots can be compared with Fig. 4(a) of reference &amp;lt;ref name=&amp;quot;zanfrognini2023&amp;quot; /&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;toyozawa2003&amp;quot; &amp;gt;Toyozawa, Yutaka, and Chris Oxlade, &#039;&#039;Optical processes in solids&#039;&#039;, [https://m.booksee.org/book/1121964?force_lang=en Cambridge University Press, (2003)]. &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;lechifflart2023&#039;&amp;gt;P. Lechifflart, F. Paleari, D. Sangalli, C. Attaccalite, &#039;&#039;First-principles study of luminescence in hexagonal boron nitride single layer: Exciton-phonon coupling and the role of substrate&#039;&#039;, &lt;br /&gt;
[https://doi.org/10.1103/PhysRevMaterials.7.024006 Phys. Rev. M, &#039;&#039;&#039;7&#039;&#039;&#039; (2), 024006 (2023)]; [https://arxiv.org/abs/2212.10407 arXiv2212.1047]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;cannuccia2019&#039;&amp;gt;E. Cannuccia, B. Monserrat and C. Attaccalite, &#039;&#039;Theory of phonon-assisted luminescence in solids: Application to hexagonal boron nitride&#039;&#039;, [https://doi.org/10.1103/PhysRevB.99.081109 Phys. Rev. B &#039;&#039;&#039;99&#039;&#039;&#039;, 081109(R) (2019)]; [https://arxiv.org/abs/1807.11797 arXiv1807.11797]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;paleari2019&#039;&amp;gt;F. Paleari et al., &#039;&#039;Exciton-Phonon Coupling in the Ultraviolet Absorption and Emission Spectra of Bulk Hexagonal Boron Nitride&#039;&#039;, [https://doi.org/10.1103/PhysRevLett.122.187401 Phys. Rev. Lett. &#039;&#039;&#039;122&#039;&#039;&#039;, 187401 (2019)]; [https://arxiv.org/abs/1810.08976 arXiv1810.089776] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;chen2020&#039;&amp;gt;&#039;&#039;Exciton-Phonon Interaction and Relaxation Times from First Principles&#039;&#039;,&lt;br /&gt;
Hsiao-Yi Chen, Davide Sangalli, and Marco Bernardi, [https://doi.org/10.1103/PhysRevLett.125.107401  Phys. Rev. Lett. &#039;&#039;&#039;125&#039;&#039;&#039;, 107401 (2020)]; [https://arxiv.org/abs/2002.08913 arXiv 2002.08913 (2020)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;lechifflart2023_PhD&amp;quot;&amp;gt;P. Lechifflart, &#039;&#039;Exciton-phonon coupling and phonon-assisted luminescence in hexagonal Boron Nitride nanostructures&#039;&#039;, [https://hal.science/tel-04266805v1 PhD Thesis, University of Marseille (2023)]; [https://www.yambo-code.eu/wiki/images/5/54/These_final.pdf From the yambo website]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;paleari2019_PhD&#039;&amp;gt;F. Paleari, &#039;&#039;First-principles approaches to the description of indirect absorption and luminescence spectroscopy: exciton-phonon coupling in hexagonal boron nitride&#039;&#039;, [https://wwwen.uni.lu/research/fstm/dphyms/people/fulvio_paleari PhD thesis, University of Luxembourg (2019)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;zanfrognini2023&#039;&amp;gt;M. Zanfrognini et al., &#039;&#039;Distinguishing different stackings in layered materials via luminescence spectroscopy&#039;&#039;, [https://doi.org/10.1103/PhysRevLett.131.206902 Phys. Rev. Lett. &#039;&#039;&#039;131&#039;&#039;&#039;, 206902 (2023)]; [https://arxiv.org/abs/2305.17554 arXiv 2305.17554] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;marini2024&#039;&amp;gt;G. Marini, M. Calandra, P. Cudazzo, &#039;&#039;Optical absorption and photoluminescence of single layer boron nitride from a first principles cumulant approach&#039;&#039;, [https://doi.org/10.1021/acs.nanolett.4c00669 Nano Lett., &#039;&#039;&#039;24&#039;&#039;&#039;, 20, 6017 (2024)]; [https://arxiv.org/abs/2402.03826 arXiv 2402.03826 (2024)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;antonius2017&#039;&amp;gt;G. Antonius, S. G. Louie, &#039;&#039;Theory of exciton-phonon coupling&#039;&#039;, [https://doi.org/10.1103/PhysRevB.105.085111 Phys. Rev. B, &#039;&#039;&#039;105&#039;&#039;&#039;, 085111 (2022)]; [https://arxiv.org/abs/1705.04245 arXiv1705.04245 (2017)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;paleari2022&#039;&amp;gt; F. Paleari, and A. Marini, &#039;&#039;Exciton-phonon interaction calls for a revision of the “exciton” concept&#039;&#039;, [https://doi.org/10.1103/PhysRevB.106.125403 Phys. Rev. B, &#039;&#039;&#039;106&#039;&#039;&#039;, 125403 (2022)]; [https://arxiv.org/abs/2205.02783 arXiv 2205.02783]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;cudazzo2020&#039;&amp;gt; P. Cudazzo, &#039;&#039;First-principles description of the exciton-phonon interaction: A cumulant approach&#039;&#039;, [https://doi.org/10.1103/PhysRevB.102.045136 Phys. Rev. B, &#039;&#039;&#039;102&#039;&#039;&#039;, 045136 (2020)]; [https://orbilu.uni.lu/bitstream/10993/44769/1/main.pdf Open access pdf from Luxembourg University]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;chan2023&#039;&amp;gt;Y-h Chan, J. B. Haber, M. H. Naik, J. B. Neaton, D. Y. Qiu, F. H. da Jornada, S. G. Louie, &#039;&#039;Exciton Lifetime and Optical Line Width Profile via Exciton–Phonon Interactions: Theory and First-Principles Calculations for Monolayer MoS2&#039;&#039;, [https://doi.org/10.1021/acs.nanolett.3c00732 Nano Lett., &#039;&#039;&#039;23&#039;&#039;&#039;, 9 (2023)]; [https://arxiv.org/abs/2212.08451 arXiv 2212.08451 (2023)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;murali2025&#039;&amp;gt;M. Nalabothula, S. Reichardt, L. Wirtz, &#039;&#039;Origin of Interlayer Exciton–Phonon Coupling in 2D Heterostructures&#039;&#039;, [https://doi.org/10.1021/acs.nanolett.5c00355 Nano Lett., &#039;&#039;&#039;25&#039;&#039;&#039;, 15 (2025)], [https://arxiv.org/abs/2407.16111 arXiv 2407.16111 (2025)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>FulvioPaleari</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Exciton-phonon_coupling_and_luminescence&amp;diff=9342</id>
		<title>Exciton-phonon coupling and luminescence</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Exciton-phonon_coupling_and_luminescence&amp;diff=9342"/>
		<updated>2026-03-13T14:45:50Z</updated>

		<summary type="html">&lt;p&gt;FulvioPaleari: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[exc-ph scheme| Tdgw-phonon-usc-01-1024x829.jpg| (c) Zhenglu Li, University of Southern California |400px | right ]]&lt;br /&gt;
&lt;br /&gt;
In this advanced tutorial, we will calculate exciton-phonon interactions from first principles by interfacing DFPT (for phonon calculations) and BSE (for exciton calculations).&lt;br /&gt;
&lt;br /&gt;
The DFTP calculations are run with Quantum ESPRESSO, while the many-body GW-BSE calculations are run with Yambo. Finally, the exciton-phonon interaction will be obtained by combining and postprocessing the databases computed in the two previous runs. The great advantage of this workflow is that the calculations can be run in the irreducible Brillouin zones both for the electronic momenta (&#039;&#039;&#039;k&#039;&#039;&#039;) and the transfer momenta (&#039;&#039;&#039;Q&#039;&#039;&#039;, &#039;&#039;&#039;q&#039;&#039;&#039;) of excitons and phonons, thus speeding up considerably the jobs while reducing the IO and memory load.&lt;br /&gt;
&lt;br /&gt;
We will first compute the exciton-phonon coupling matrix elements: these are the building blocks needed to construct experimental observables such as phonon-assisted optical spectra (such as luminescence), Raman spectra and exciton lifetimes. We will do this in the case of monolayer MoS&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;, a 2D system with large spin-orbit interaction.&lt;br /&gt;
&lt;br /&gt;
As an example of application, we will consider the case of phonon-assisted luminescence. We will do this in the case of bulk hBN, a layered indirect insulator with strong electron-phonon coupling.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; this tutorial will be updated when new exc-ph tools become available in Yambopy (including full-python postprocessing, Raman spectra, interpolated lifetimes, etc).&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
This is an advanced topic: we assume that you already know something about the theory&amp;lt;ref name=&amp;quot;toyozawa2003&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;antonius2017&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;cudazzo2020&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;paleari2019_PhD&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;paleari2022&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;lechifflart2023_PhD&amp;quot; /&amp;gt; and applications&amp;lt;ref name=&amp;quot;paleari2019&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;cannuccia2019&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;chen2020&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;zanfrognini2023&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;lechifflart2023&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;chan2023&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;marini2024&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;murali2025&amp;quot; /&amp;gt; of exciton-phonon physics. &lt;br /&gt;
&lt;br /&gt;
Also, we assume that you already know how to run both a basic &#039;&#039;&#039;Yambo&#039;&#039;&#039; GW-BSE calculation and a DFPT phonon calculation with &#039;&#039;&#039;Quantum ESPRESSO&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Besides the QE executables &amp;lt;code&amp;gt;pw.x&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ph.x&amp;lt;/code&amp;gt;, we also use the yambo phonon-specific executable &amp;lt;code&amp;gt;yambo_ph&amp;lt;/code&amp;gt; and the python utility &#039;&#039;&#039;Yambopy&#039;&#039;&#039;. The auxiliary code &#039;&#039;&#039;LetzElPhC&#039;&#039;&#039; (executable &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt;) will be used to obtain the electron-phonon matrix elements by reading the same electronic wavefunctions used by Yambo (and stored in the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory), while also making full use of crystal symmetries. [https://github.com/yambo-code/LetzElPhC LetzElPhC] will be run by Yambopy, but it must nonetheless be installed. Finally, the exciton-phonon properties can be computed either using &amp;lt;code&amp;gt;yambo_ph&amp;lt;/code&amp;gt; or using Yambopy itself. Both cases will be covered in this tutorial.&lt;br /&gt;
&lt;br /&gt;
[[File:Workflow scheme.png|800px|center]]&lt;br /&gt;
&lt;br /&gt;
== Step 0: Pseudopotentials, equilibrium structure and convergence ==&lt;br /&gt;
&lt;br /&gt;
In a real calculation, it is important to ensure that both the pseudopotential and the lattice parameters that we are using are compatible and perform well for the electronic excited states and for the lattice vibrations simultaneously. Furthermore, you have to make sure that the wave function cutoff &amp;lt;code&amp;gt;ecutwfc&amp;lt;/code&amp;gt; is converged with respect to the DFPT step and not just to the DFT one. This is in addition to the other customary convergence tests for DFT, DFPT, GW and BSE calculations.&lt;br /&gt;
&lt;br /&gt;
This is often the most time-demanding step when starting on a new system.&lt;br /&gt;
&lt;br /&gt;
For the sake of this tutorial, we assume that we have already done all these tests and we are starting the final workflow to get the exciton-phonon properties.&lt;br /&gt;
&lt;br /&gt;
== Step 1: scf calculation ==&lt;br /&gt;
&lt;br /&gt;
First of all, we run a standard scf calculation with &amp;lt;code&amp;gt;pw.x&amp;lt;/code&amp;gt; for Yambo. We stick with non-symmorphic symmetries. At the end, we will have the QE &amp;lt;code&amp;gt;save&amp;lt;/code&amp;gt; directory.&lt;br /&gt;
&lt;br /&gt;
This is the input &amp;lt;code&amp;gt;mos2.scf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 &amp;amp;control&lt;br /&gt;
           wf_collect = .true.,&lt;br /&gt;
          calculation = &amp;quot;scf&amp;quot;,&lt;br /&gt;
            verbosity = &#039;high&#039;,&lt;br /&gt;
           pseudo_dir = &#039;$PSEUDO_DIR&#039;,&lt;br /&gt;
               prefix = &amp;quot;mos2&amp;quot;,&lt;br /&gt;
               outdir = &#039;.&#039;,&lt;br /&gt;
  /&amp;amp;end&lt;br /&gt;
  &amp;amp;system&lt;br /&gt;
              ecutwfc = 100.0,&lt;br /&gt;
          occupations = &#039;fixed&#039;,&lt;br /&gt;
                ibrav = 4,&lt;br /&gt;
            celldm(1) = 5.9000811881,&lt;br /&gt;
            celldm(3) = 6.7795677253,&lt;br /&gt;
                  nat = 3,&lt;br /&gt;
                 ntyp = 2,&lt;br /&gt;
             lspinorb = .true.&lt;br /&gt;
             noncolin = .true.&lt;br /&gt;
             assume_isolated = &#039;2D&#039;&lt;br /&gt;
         force_symmorphic = .true.&lt;br /&gt;
  /&amp;amp;end&lt;br /&gt;
  &amp;amp;electrons&lt;br /&gt;
     electron_maxstep = 200,&lt;br /&gt;
          mixing_beta = 0.7,&lt;br /&gt;
             conv_thr = 1.d-08,&lt;br /&gt;
  /&amp;amp;end&lt;br /&gt;
   ATOMIC_SPECIES&lt;br /&gt;
    Mo  95.940      Mo_ONCV_PBE_FR-1.0.upf&lt;br /&gt;
    S    32.065     S_ONCV_PBE_FR-1.1.upf&lt;br /&gt;
   ATOMIC_POSITIONS { crystal }&lt;br /&gt;
 Mo       0.333333333   0.666666667   0.000000000&lt;br /&gt;
 S        0.666666667   0.333333333   0.073413577&lt;br /&gt;
 S        0.666666667   0.333333333  -0.073413577&lt;br /&gt;
  K_POINTS { automatic }&lt;br /&gt;
 6 6 1 0 0 0&lt;br /&gt;
&lt;br /&gt;
Here we are using full relativistic pseudopotentials from the SG-15 database.&lt;br /&gt;
&lt;br /&gt;
We can run it on our machine (for example using 4 MPI tasks) as:&lt;br /&gt;
&lt;br /&gt;
 mpirun -np 4 pw.x -inp mos2.scf &amp;gt; scf.out&lt;br /&gt;
&lt;br /&gt;
== Step 2: nscf calculation for Yambo ==&lt;br /&gt;
&lt;br /&gt;
Copy the QE &amp;lt;code&amp;gt;save&amp;lt;/code&amp;gt; directory from the scf calculation and run the nscf calculation for any number of empty states, with the correct &amp;lt;code&amp;gt;k&amp;lt;/code&amp;gt;-grid we want to use in Yambo. Here we are using a badly underconverged grid of 6x6x1.&lt;br /&gt;
&lt;br /&gt;
This reciprocal-space grid will also match the momentum transfer &amp;lt;code&amp;gt;q&amp;lt;/code&amp;gt; grid on which excitons and phonons will be defined!&lt;br /&gt;
&lt;br /&gt;
The electronic wavefunctions computed at this step and stored in the new nscf &amp;lt;code&amp;gt;save&amp;lt;/code&amp;gt; directory will be used both by Yambo and by the electron-phonon code: this is important because using different sets of wavefunctions would lead to a phase mismatch issue in the exciton-phonon matrix elements.&lt;br /&gt;
&lt;br /&gt;
The nscf input &amp;lt;code&amp;gt;mos2.nscf&amp;lt;/code&amp;gt; is&lt;br /&gt;
 &amp;amp;control&lt;br /&gt;
           wf_collect = .true.,&lt;br /&gt;
          calculation = &amp;quot;nscf&amp;quot;,&lt;br /&gt;
            verbosity = &#039;high&#039;,&lt;br /&gt;
           pseudo_dir = &#039;$PSEUDO_DIR&#039;,&lt;br /&gt;
               prefix = &amp;quot;mos2&amp;quot;,&lt;br /&gt;
               outdir = &#039;.&#039;,&lt;br /&gt;
  /&amp;amp;end&lt;br /&gt;
  &amp;amp;system&lt;br /&gt;
              ecutwfc = 100.0,&lt;br /&gt;
          occupations = &#039;fixed&#039;,&lt;br /&gt;
                ibrav = 4,&lt;br /&gt;
            celldm(1) = 5.9000811881,&lt;br /&gt;
            celldm(3) = 6.7795677253,&lt;br /&gt;
                  nat = 3,&lt;br /&gt;
                 ntyp = 2,&lt;br /&gt;
             lspinorb = .true.&lt;br /&gt;
             noncolin = .true.&lt;br /&gt;
                nbnd  = 250&lt;br /&gt;
             assume_isolated = &#039;2D&#039;&lt;br /&gt;
         force_symmorphic = .true.&lt;br /&gt;
  /&amp;amp;end&lt;br /&gt;
  &amp;amp;electrons&lt;br /&gt;
     electron_maxstep = 200,&lt;br /&gt;
          mixing_beta = 0.7,&lt;br /&gt;
             conv_thr = 1.d-08,&lt;br /&gt;
  /&amp;amp;end&lt;br /&gt;
   ATOMIC_SPECIES&lt;br /&gt;
    Mo  95.940      Mo_ONCV_PBE_FR-1.0.upf&lt;br /&gt;
    S    32.065     S_ONCV_PBE_FR-1.1.upf&lt;br /&gt;
   ATOMIC_POSITIONS { crystal }&lt;br /&gt;
 Mo       0.333333333   0.666666667   0.000000000&lt;br /&gt;
 S        0.666666667   0.333333333   0.073413577&lt;br /&gt;
 S        0.666666667   0.333333333  -0.073413577&lt;br /&gt;
  K_POINTS { automatic }&lt;br /&gt;
 6 6 1 0 0 0&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Again, we run the calculation&lt;br /&gt;
&lt;br /&gt;
 mpirun -np 4 pw.x -inp mos2.nscf &amp;gt; nscf.out&lt;br /&gt;
&lt;br /&gt;
== Step 3: dvscf phonon calculation ==&lt;br /&gt;
&lt;br /&gt;
Now we run the phonon calculation.&lt;br /&gt;
&lt;br /&gt;
Copy the &amp;lt;code&amp;gt;save&amp;lt;/code&amp;gt; directory from the &#039;&#039;&#039;scf&#039;&#039;&#039; calculation and run &amp;lt;code&amp;gt;ph.x&amp;lt;/code&amp;gt; for a dvscf calculation with a standard &amp;lt;code&amp;gt;q&amp;lt;/code&amp;gt;-grid matching the &amp;lt;code&amp;gt;k&amp;lt;/code&amp;gt;-grid we wanna use in Yambo.&lt;br /&gt;
&lt;br /&gt;
At the end, we will have the &amp;lt;code&amp;gt;_ph0&amp;lt;/code&amp;gt; directory containing the variation of the self-consistent potential, &amp;lt;math&amp;gt;\Delta V_{SCF}(q)&amp;lt;/math&amp;gt;, and the &amp;lt;code&amp;gt;*.dyn&amp;lt;/code&amp;gt; files with the phonon energies and eigenvectors.&lt;br /&gt;
&lt;br /&gt;
NB: one could further refine the phonon energies by enforcing the acoustic sum rule, including non-analytic long-range contributions, interpolating to finer grids... all of this can be done within Quantum ESPRESSO and will not be covered in this version of the tutorial.&lt;br /&gt;
&lt;br /&gt;
The input is &amp;lt;code&amp;gt;mos2.dvscf&amp;lt;/code&amp;gt;:&lt;br /&gt;
 &lt;br /&gt;
 mos2_dvscf&lt;br /&gt;
 &amp;amp;inputph&lt;br /&gt;
   tr2_ph=1.0d-12,&lt;br /&gt;
   verbosity=&#039;high&#039;&lt;br /&gt;
   prefix=&#039;mos2&#039;,&lt;br /&gt;
   fildvscf = &#039;mos2-dvscf&#039;,&lt;br /&gt;
   electron_phonon = &#039;dvscf&#039;,&lt;br /&gt;
   fildyn=&#039;mos2.dyn&#039;,&lt;br /&gt;
   epsil=.false.,&lt;br /&gt;
   ldisp=.true.,&lt;br /&gt;
   recover=.true.,&lt;br /&gt;
   nq1=6,&lt;br /&gt;
   nq2=6,&lt;br /&gt;
   nq3=1&lt;br /&gt;
 /&lt;br /&gt;
&lt;br /&gt;
And now we run as&lt;br /&gt;
&lt;br /&gt;
 nohup mpirun -np 8 ph.x -inp mos2.dvscf &amp;gt; dvscf.out &amp;amp;&lt;br /&gt;
&lt;br /&gt;
This time we use nohup and more processes because this calculation may take some time. It is a good idea to set &amp;lt;code&amp;gt;recover=.true.&amp;lt;/code&amp;gt; as in a real calculation you will easily breach walltime, and in this way you can safely restart.&lt;br /&gt;
&lt;br /&gt;
== Step 4: create Yambo &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory ==&lt;br /&gt;
&lt;br /&gt;
This is just the standard Yambo initialization: run &lt;br /&gt;
 &lt;br /&gt;
 p2y &lt;br /&gt;
&lt;br /&gt;
and then &lt;br /&gt;
&lt;br /&gt;
 yambo &lt;br /&gt;
&lt;br /&gt;
in the &#039;&#039;&#039;nscf&#039;&#039;&#039; &amp;lt;code&amp;gt;save&amp;lt;/code&amp;gt; folder and then move the newly generated &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory to a convenient place.&lt;br /&gt;
&lt;br /&gt;
== Step 5: run a BSE calculation ==&lt;br /&gt;
&lt;br /&gt;
Now we switch from QE to Yambo. Here, we forgo the GW step for simplicity (we can use a scissor operator to open the band gap).&lt;br /&gt;
&lt;br /&gt;
This calculation has a couple of differences with respect to a standard BSE calculation for optical absorption. We can look at the input file &amp;lt;code&amp;gt;bse.in&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Runlevels&amp;lt;/span&amp;gt;&lt;br /&gt;
 optics                       # [R OPT] Optics&lt;br /&gt;
 rim_cut                      # [R RIM CUT] Coulomb potential&lt;br /&gt;
 bss                          # [R BSS] Bethe Salpeter Equation solver&lt;br /&gt;
 em1s                         # [R Xs] Static Inverse Dielectric Matrix&lt;br /&gt;
 bse                          # [R BSE] Bethe Salpeter Equation.&lt;br /&gt;
 bsk                          # [R BSK] Bethe Salpeter Equation kernel&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# RIM and cutoff settings&amp;lt;/span&amp;gt;&lt;br /&gt;
 RandQpts=1000000             # [RIM] Number of random q-points in the BZ&lt;br /&gt;
 RandGvec= 100            RL    # [RIM] Coulomb interaction RS components&lt;br /&gt;
 CUTGeo= &amp;quot;slab z&amp;quot;               # [CUT] Coulomb Cutoff geometry: box/cylinder/sphere X/Y/Z/XY..&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Static screening&amp;lt;/span&amp;gt;&lt;br /&gt;
 X_and_IO_CPU= &amp;quot;1 1 4 2 1&amp;quot;       # [PARALLEL] CPUs for each role&lt;br /&gt;
 X_and_IO_ROLEs= &amp;quot;q g k c v&amp;quot;      # [PARALLEL] CPUs roles (q,g,k,c,v)&lt;br /&gt;
 X_and_IO_nCPU_LinAlg_INV=-1      # [PARALLEL] CPUs for Linear Algebra (if -1 it is automatically set)&lt;br /&gt;
 Chimod= &amp;quot;hartree&amp;quot;            # [X] IP/Hartree/ALDA/LRC/BSfxc&lt;br /&gt;
 % BndsRnXs&lt;br /&gt;
    1 |  200 |                 # [Xs] Polarization function bands&lt;br /&gt;
 %&lt;br /&gt;
 % LongDrXs&lt;br /&gt;
  1.000000 | 1.000000 | 1.000000 |        # [Xs] [cc] Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 NGsBlkXs= 8000            mRy    # [Xs] Response block size&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# BSE&amp;lt;/span&amp;gt;&lt;br /&gt;
 BS_CPU= &amp;quot;4.1.2&amp;quot;                   # [PARALLEL] CPUs for each role&lt;br /&gt;
 BS_ROLEs= &amp;quot;k.eh.t&amp;quot;                 # [PARALLEL] CPUs roles (k,eh,t)&lt;br /&gt;
 BS_nCPU_diago=4              # [PARALLEL] CPUs for matrix diagonalization&lt;br /&gt;
 BSEmod= &amp;quot;causal&amp;quot;             # [BSE] resonant/causal/coupling&lt;br /&gt;
 BSKmod= &amp;quot;SEX&amp;quot;                # [BSE] IP/Hartree/HF/ALDA/SEX/BSfxc&lt;br /&gt;
 BSSmod= &amp;quot;d&amp;quot;                  # [BSS] (h)aydock/(d)iagonalization/(s)lepc/(i)nversion/(t)ddft`&lt;br /&gt;
 BSENGexx=  40000      mRy    # [BSK] Exchange components&lt;br /&gt;
 ALLGexx                      # [BSS] Force the use use all RL vectors for the exchange part&lt;br /&gt;
 BSENGBlk=  8000       mRy    # [BSK] Screened interaction block size&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;Lkind=&amp;quot;full&amp;quot;                  #[BSE,X] bar(default)/full/tilde&amp;lt;/span&amp;gt;&lt;br /&gt;
 % KfnQP_E&lt;br /&gt;
  1.000000 | 1.000000 | 1.000000 |        # [EXTQP BSK BSS] E parameters  (c/v) eV|adim|adim&lt;br /&gt;
 %&lt;br /&gt;
 % BEnRange&lt;br /&gt;
   0.00000 |  4.00000 | eV    # [BSS] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 % BDmRange&lt;br /&gt;
   0.05000 |  0.05000 | eV    # [BSS] Damping range&lt;br /&gt;
 %&lt;br /&gt;
 BEnSteps= 2000               # [BSS] Energy steps&lt;br /&gt;
 % BLongDir&lt;br /&gt;
  1.000000 | 0.000000 | 0.000000 |        # [BSS] [cc] Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;% BSEQptR&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 1 | 7 |                     # [BSK] Transferred momenta range&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;%&amp;lt;/span&amp;gt;&lt;br /&gt;
 % BSEBands&lt;br /&gt;
    25 |  28 |                 # [BSK] Bands range&lt;br /&gt;
 %&lt;br /&gt;
 WRbsWF                      # [BSS] Write to disk excitonic the FWs&lt;br /&gt;
 &lt;br /&gt;
This file was generated using the command: &amp;lt;code&amp;gt; yambo -X s -o b -k sex -y d -r&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
First of all, we compute the excitons for all the momenta in the irreducible Brillouin zone for our discrete grid via the &amp;lt;code&amp;gt;BSEQptR&amp;lt;/code&amp;gt; variable. This will be a &#039;&#039;&#039;finite-momentum&#039;&#039;&#039; BSE calculation, analogous to the phonon one.&lt;br /&gt;
&lt;br /&gt;
Second, we change the variable &amp;lt;code&amp;gt;Lkind&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;bar&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;full&amp;lt;/code&amp;gt;. In Yambo, &amp;lt;code&amp;gt;Lkind=&amp;quot;bar&amp;quot;&amp;lt;/code&amp;gt;, which is the default for optical absorption, means that we are computing the excitonic response function without the long-range component of the exchange interaction. This cannot be used when computing the exciton momentum dependence, where the long-range exchange interaction can play a role, therefore we have to include it with &amp;lt;code&amp;gt;Lkind=&amp;quot;full&amp;quot;&amp;lt;/code&amp;gt;. This allows for the calculation of the excitonic longitudinal-transverse splitting (in 3D systems) as well.&lt;br /&gt;
&lt;br /&gt;
We can now run the code:&lt;br /&gt;
&lt;br /&gt;
 nohup mpirun -np 8 yambo -F bse.in -J bse_Lfull -C bse_Lfull &amp;amp;&lt;br /&gt;
&lt;br /&gt;
At the end of the calculation, we have obtained the &amp;lt;code&amp;gt;ndb.BS_diago_Q*&amp;lt;/code&amp;gt; databases inside the directory &amp;lt;code&amp;gt;bse_Lfull&amp;lt;/code&amp;gt;. They contain information on the exciton energies and wavefunctions at each momentum. Do not forget to check the report and logs of your calculation in the same directory to make sure that the code is doing what you want.&lt;br /&gt;
&lt;br /&gt;
== Step 6: obtain the electron-phonon matrix elements ==&lt;br /&gt;
&lt;br /&gt;
We have finished the heavy simulations. Now it&#039;s time for the postprocessing. The first order of business is the reconstruction of the electron-phonon coupling matrix elements from the dvscf results and the electronic wavefunctions.&lt;br /&gt;
&lt;br /&gt;
In order to do this, we will run the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable of the &#039;&#039;&#039;LetzElPhC&#039;&#039;&#039; code. We will run via command line using yambopy, although it will be instructive to have look at the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; input files later.&lt;br /&gt;
&lt;br /&gt;
We run in the same directory where the Yambo &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; is (remember than you can also virtually move it with a symbolic link).&lt;br /&gt;
&lt;br /&gt;
Type:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y&lt;br /&gt;
&lt;br /&gt;
to see the help for the calculation. Have a look at the various flags and their description.&lt;br /&gt;
For example, if we want to do a serial run of LetzElPhC for bands from &amp;lt;math&amp;gt;n_i&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;n_f&amp;lt;/math&amp;gt;, we should type:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph path/of/ph_input.in -b n_i n_f&lt;br /&gt;
&lt;br /&gt;
Here &amp;lt;math&amp;gt;n_i&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;n_f&amp;lt;/math&amp;gt; are integers representing the initial and final band indices. &#039;&#039;&#039;Please note&#039;&#039;&#039;: in this case, the band index starts from 1 and the the interval of bands read by the code is &amp;lt;math&amp;gt;[n_i,n_f]&amp;lt;/math&amp;gt; including the extrema of the interval.&lt;br /&gt;
&lt;br /&gt;
These should coincide with those used for the Bethe-Salpeter kernel, i.e. those specified in the &amp;lt;code&amp;gt;BSEBands&amp;lt;/code&amp;gt; variable of the BSE input file (this is not strictly necessary, but certainly efficient since these calculations use a lot of disk space). &lt;br /&gt;
&lt;br /&gt;
For our system, we want to do a parallel calculation with 4 qpools and 2 kpools. In addition, we want to explicitly specify the path of the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable and avoid automatically deleting the LetzElPhC data. So we type:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph path/of/dvscf/mos2.dvscf -b 25 28 -par 4 2 -lelphc path/to/lelphc_exe&lt;br /&gt;
&lt;br /&gt;
At the end, check your directory: you should find the &amp;lt;code&amp;gt;lelphc.in&amp;lt;/code&amp;gt; input file that was run, let&#039;s inspect it: &lt;br /&gt;
&lt;br /&gt;
 # LetzElPhC input for yambo generated by yambopy&lt;br /&gt;
 nqpool      = 2&lt;br /&gt;
 nkpool      = 4&lt;br /&gt;
 start_bnd   = 25&lt;br /&gt;
 end_bnd     = 28&lt;br /&gt;
 save_dir    = ./SAVE&lt;br /&gt;
 kernel      = dfpt&lt;br /&gt;
 ph_save_dir = dvscf/ph_save&lt;br /&gt;
 convention = yambo&lt;br /&gt;
&lt;br /&gt;
Notice the variable &amp;lt;code&amp;gt;convention=yambo&amp;lt;/code&amp;gt;: what does it mean? At variance with QE and many other codes, Yambo uses the &amp;quot;backward&amp;quot; momentum transfer convention for electronic scatterings. That is, an electronic transition goes from band &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; and momentum &amp;lt;math&amp;gt;k-q&amp;lt;/math&amp;gt; to band &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; and momentum &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;. In the &amp;quot;forward&amp;quot; momentum transfer convention (the more standard one), the transitions go from &amp;lt;math&amp;gt;nk&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;mk+q&amp;lt;/math&amp;gt;. Therefore, this variable ensures that the electron-phonon coupling matrix elements are computed as &amp;lt;math&amp;gt;\langle mk|dV|nk-q\rangle&amp;lt;/math&amp;gt;. This will have consequences also in the formulation of the &#039;&#039;exciton&#039;&#039;-phonon coupling matrix element.&lt;br /&gt;
&lt;br /&gt;
You will also find a &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; database that contains the computed electron-phonon matrix elements, in the output format of &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In addition, if you check the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; folder:&lt;br /&gt;
&lt;br /&gt;
 ls SAVE/ndb.elph_gkkp*&lt;br /&gt;
&lt;br /&gt;
you will see that yambopy has created the Yambo-compatible electron-phonon databases.&lt;br /&gt;
&lt;br /&gt;
If you want to run LetzElPhC directly, without using yambopy, you can refer to its [[https://gitlab.com/lumen-code/LetzElPhC/-/blob/main/docs/main.pdf?ref_type=heads|user guide]].&lt;br /&gt;
Keep in mind that in this case, in order to convert the database to the &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases of Yambo, you will then need a couple of lines of python using the Yambopy class &amp;lt;code&amp;gt;ConvertElectronPhononDB&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;yambopy/letzelph_interface/lelph2y.py&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t need the &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases -- e.g., because you are doing the exc-ph postprocessing with yambopy -- you can run &amp;lt;code&amp;gt;yambopy l2y ...&amp;lt;/code&amp;gt; with the &amp;lt;code&amp;gt;--no_gkkp&amp;lt;/code&amp;gt; option.&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t need the &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; databases -- e.g., because you are using &amp;lt;code&amp;gt;yambo_ph&amp;lt;/code&amp;gt; for the exc-ph part -- you can run &amp;lt;code&amp;gt;yambopy l2y ...&amp;lt;/code&amp;gt; with the &amp;lt;code&amp;gt;--no_lelphc_dbs&amp;lt;/code&amp;gt; option.&lt;br /&gt;
&lt;br /&gt;
== Step 7: Obtain the exciton-phonon coupling ==&lt;br /&gt;
&lt;br /&gt;
Now, we can finally access our basic building block for exciton-phonon physics. This could be done entirely in python (using &#039;&#039;&#039;Yambopy&#039;&#039;&#039;), or by running &#039;&#039;&#039;Yambo&#039;&#039;&#039;. &lt;br /&gt;
&lt;br /&gt;
* For the &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&#039;&#039;&#039;Yambo postprocessing&#039;&#039;&#039;&amp;lt;/span&amp;gt; case (running yambo inputs with the &amp;lt;code&amp;gt;yambo_ph&amp;lt;/code&amp;gt; executable), &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&#039;&#039;&#039;follow the alternative route to Steps 7-8 [[Exciton-phonon coupling and luminescence - Yambo postprocessing|at this link]]&#039;&#039;&#039;&amp;lt;/span&amp;gt;.&lt;br /&gt;
* For the &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&#039;&#039;&#039;Yambopy postprocessing&#039;&#039;&#039;&amp;lt;/span&amp;gt; case (using flexible python scripting), &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&#039;&#039;&#039;keep following Steps 7-8 on this page&#039;&#039;&#039;&amp;lt;/span&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Our objective is obtaining the following quantity: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\mathcal{G}^\mu_{\alpha\lambda}(0,q)=\sum_{vv^\prime c k} A^{\alpha, *}_{cv^\prime} (k, q) g_{vv^\prime}^\mu (k,q) A^{\lambda}_{cv}(k,0) - \sum_{cc^\prime vk} A^{\alpha, *}_{c^\prime v} (k+q, q) g_{c^\prime c}^\mu (k+q,q) A^{\lambda}_{cv}(k, 0)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here, &amp;lt;math&amp;gt;A^{\alpha}_{cv}(k,q)&amp;lt;/math&amp;gt; are the exciton coefficients extracted from the eigenvector of the two-particles Hamiltonian during the BSE calculation in step 5, while &amp;lt;math&amp;gt;g_{nm}^\mu (k,q)&amp;lt;/math&amp;gt; are the electron-phonon coupling matrix elements obtained in step 6. As you can see, the exciton &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; undergoes phonon-mediated scattering to state &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; via phonon mode &amp;lt;math&amp;gt;\mu&amp;lt;/math&amp;gt;. The scattering can happen for the hole (valence, &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt;) or for the electron (conduction, &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
NB: &lt;br /&gt;
&lt;br /&gt;
(1) This is written in the &amp;quot;backward&amp;quot; momentum transfer convention used by Yambo. The momentum dependence is different in the &amp;quot;forward&amp;quot; transfer convention. &lt;br /&gt;
&lt;br /&gt;
(2) For simplicity, this is written for zero initial exciton momentum. This means that one of the two states involved in the phonon-mediated scattering process will be in the optical limit (and possibly an optically generated exciton), while the other state can have any momentum: this momentum will be the same as the phonon one. This matrix element can be used to describe phonon-assisted absorption and emission spectra.&lt;br /&gt;
&lt;br /&gt;
In order to calculate this quantity using python, we need the &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; databases natively generated by the &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; code, as well as the BSE databases &amp;lt;code&amp;gt;ndb.BS_diago_Q*&amp;lt;/code&amp;gt; containing the information on exciton wavefunctions and energies.&lt;br /&gt;
&lt;br /&gt;
Next, we write a python user script importing the yambopy exciton-phonon tools. You can find a version of this script in &amp;lt;code&amp;gt;yambopy/tutorials/exciton-phonon/calculate_excph.py&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
 import numpy as np &lt;br /&gt;
 from yambopy import YamboLatticeDB,YamboWFDB,LetzElphElectronPhononDB &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;#Specific Yambopy dbs loading classes&amp;lt;/span&amp;gt;&lt;br /&gt;
 from yambopy.exciton_phonon.excph_matrix_elements import exciton_phonon_matelem &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;#Specific exc-ph functions&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 path = &#039;1L_MoS2&#039;&lt;br /&gt;
 bands_range=[24,28] &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# 2 valence bands, 2 conduction bands&amp;lt;/span&amp;gt;&lt;br /&gt;
 nexc = 12 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# number of excitonic states&amp;lt;/span&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 bsepath    = f&#039;{path}/bse-allq_full&#039; &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Path to BSE calculation (Lin=Lout)&amp;lt;/span&amp;gt;&lt;br /&gt;
 savepath   = f&#039;{path}/SAVE&#039;     &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Yambo SAVE&amp;lt;/span&amp;gt;&lt;br /&gt;
 ndb_elph   = f&#039;{path}/ndb.elph&#039; &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# LetzElPhC electron-phonon database (any convention)&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Read lattice&amp;lt;/span&amp;gt;&lt;br /&gt;
 lattice = YamboLatticeDB.from_db_file(filename=f&#039;{savepath}/ns.db1&#039;)&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Read electron-phonon&amp;lt;/span&amp;gt;&lt;br /&gt;
 elph    = LetzElphElectronPhononDB(ndb_elph,read_all=False)&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Read wave functions&amp;lt;/span&amp;gt;&lt;br /&gt;
 wfcs    = YamboWFDB(filename=&#039;ns.wf&#039;,save=savepath,latdb=lattice,bands_range=bands_range)&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Calculate exciton-phonon matrix elements&amp;lt;/span&amp;gt;&lt;br /&gt;
 exph = exciton_phonon_matelem(lattice,elph,wfcs,BSE_dir=bsepath,nexc_in=nexc,nexc_out=nexc,dmat_mode=&#039;save&#039;,exph_file=&#039;MoS2_Ex-ph.npy&#039;)&lt;br /&gt;
&lt;br /&gt;
In this script, we can select the number exciton states &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; with &amp;lt;code&amp;gt;nexc&amp;lt;/code&amp;gt;, the single-particle bands range with &amp;lt;code&amp;gt;bands_range&amp;lt;/code&amp;gt;. &#039;&#039;&#039;Please note&#039;&#039;&#039;: in this case, the band index starts from 0 (python indexing) and the the interval of bands read by the code is &amp;lt;math&amp;gt;[n_i,n_f)&amp;lt;/math&amp;gt;, therefore the last value (28 in the example) is excluded. That is, in the example we are selecting the 25th, 26th, 27th and 28th bands. Those bands have to be present in both the electron-phonon and BSE calculations. &lt;br /&gt;
&lt;br /&gt;
Here we calculate the couplings of the first twelve states at each finite-&amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; point including &amp;lt;math&amp;gt;q=0&amp;lt;/math&amp;gt;. We also include all the nine phonon modes of monolayer MoS2. We also need access to the Yambo &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory in order to read the electronic wavefunctions: they are used to compute the electronic representation matrices (&amp;lt;code&amp;gt;dmat&amp;lt;/code&amp;gt; in the code). The argument &amp;lt;code&amp;gt;dmat_mode&amp;lt;/code&amp;gt; can be set to &amp;lt;code&amp;gt;&#039;load&#039;&amp;lt;/code&amp;gt; for subsequent calculations.&lt;br /&gt;
&lt;br /&gt;
When we are satisfied with the input, we run the code:&lt;br /&gt;
&lt;br /&gt;
 python calculate_excph.py&lt;br /&gt;
&lt;br /&gt;
If you check the output, you should find the &amp;lt;code&amp;gt;MoS2_Ex-ph.npy&amp;lt;/code&amp;gt; binary file in the directory where you ran.&lt;br /&gt;
&lt;br /&gt;
=== Analysis of the couplings ===&lt;br /&gt;
&lt;br /&gt;
It is a good idea to have a look at what we computed up to now in order to make sure nothing has gone wrong. &lt;br /&gt;
&lt;br /&gt;
It is not easy to know what to expect (apart from symmetry and gauge compliance of the matrix elements), but one can work out the exciton-phonon selection rules in advance, check that the magnitude is reasonable, etc.&lt;br /&gt;
&lt;br /&gt;
It is also not easy to meaningfully plot this quantity. We have to make sure that we are not breaking degenerate states, otherwise the plots will not be invariant. &lt;br /&gt;
&lt;br /&gt;
First of all, we have to know our system: in monolayer MoS&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;, the first four excitons are all doubly degenerate. The first exciton responsible for a bright peak in the absorption spectrum (the &#039;&#039;&#039;A&#039;&#039;&#039; peak), is the second state, corresponding to state indices &amp;lt;code&amp;gt;(3,4)&amp;lt;/code&amp;gt; in fortran indexing or &amp;lt;code&amp;gt;(2,3)&amp;lt;/code&amp;gt; in python indexing. &lt;br /&gt;
&lt;br /&gt;
All these information can be obtained by analyzing the BSE results (this stuff is explained in the BSE tutorials) and by knowledge of the system or class of systems from the literature.&lt;br /&gt;
&lt;br /&gt;
Thus, a good quantity to plot may be the norm of the matrix elements, summed over the degenerate subspace of exciton A, for a certain number of scattered final states mediated by certain phonon modes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;F_A(q)= \sqrt{ \sum_{\alpha \in A,\lambda,\mu} |\mathcal{G}_{\alpha\lambda}^\mu (0,q)|^2 }&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In order to do this, we create a python script &amp;lt;code&amp;gt;analyse_excph.py&amp;lt;/code&amp;gt; in which we first load the excph dabatases. &lt;br /&gt;
You can find a version of this script in the yambopy directory, in &amp;lt;code&amp;gt;tutorials/exciton-phonon&amp;lt;/code&amp;gt;. &lt;br /&gt;
First, we select the exciton and phonon states to be included in &amp;lt;code&amp;gt;F_A&amp;lt;/code&amp;gt;, together with the path of databases and plot details:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Exciton &amp;quot;in&amp;quot; states&amp;lt;/span&amp;gt;&lt;br /&gt;
 exc_in  = [2,3]  &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# First bright peak (A: 2,3 -- B: 6,7)&amp;lt;/span&amp;gt;&lt;br /&gt;
 exc_out = [0,1,2,3] &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# first 4 states (dispersion of dark triplet state and A)&amp;lt;/span&amp;gt;&lt;br /&gt;
 ph_in  = &#039;all&#039;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Paths of databases&amp;lt;/span&amp;gt;&lt;br /&gt;
 ns_db1 =f&#039;{path}/SAVE/ns.db1&#039;&lt;br /&gt;
 ns_ypy = &#039;MoS2_Ex-ph.npy&#039;&lt;br /&gt;
 &lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
Then, we load the data:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Read lattice and k-space info&amp;lt;/span&amp;gt;&lt;br /&gt;
 ylat = YamboLatticeDB.from_db_file(filename=ns_db1)&lt;br /&gt;
 print(ylat)&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Load exc-ph database&amp;lt;/span&amp;gt;&lt;br /&gt;
 X_py = np.load(ns_ypy)&lt;br /&gt;
 G_squared = np.abs(X_py)**2.&lt;br /&gt;
&lt;br /&gt;
The quantity &amp;lt;math&amp;gt;F_A(q)&amp;lt;/math&amp;gt; is obtained from a dedicated function as:&lt;br /&gt;
 &lt;br /&gt;
 if exc_in  == &#039;all&#039;: exc_in  = range(G_squared.shape[2])&lt;br /&gt;
 if exc_out == &#039;all&#039;: exc_out = range(G_squared.shape[3])&lt;br /&gt;
 if ph_in   == &#039;all&#039;: ph_in   = range(G_squared.shape[1])&lt;br /&gt;
 &lt;br /&gt;
 G_squared = G_squared[:, ph_in, :, :].sum(axis=(1))&lt;br /&gt;
 G_squared = G_squared[:, exc_in, :].sum(axis=(1))&lt;br /&gt;
 G_squared = G_squared[:, exc_out].sum(axis=(1))&lt;br /&gt;
 &lt;br /&gt;
 F_q = np.sqrt( G_squared )*ha2ev &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Switch from Ha to eV&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And finally, we have to make a plotting function. For this tutorial we will use a custom scatterplot employing some of the plotting tools provided by yambopy (but you can do whatever you want).&lt;br /&gt;
&lt;br /&gt;
 plot_2D_excph(qgrid,G2_to_plot,rlat=ylat.rlat,plt_cbar=True,\&lt;br /&gt;
               marker=&#039;H&#039;,s=700,cmap=&#039;magma&#039;)&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
You can get more experience on using Yambopy for these kinds of visualization by following the [https://wiki.yambo-code.eu/wiki/index.php?title=First_steps_in_Yambopy Yambopy tutorials]. In fact, remember that these scripts and all the other Yambopy tutorial scripts are just suggestions, not source code written in stone: if you know &amp;lt;code&amp;gt;numpy&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;matplotlib&amp;lt;/code&amp;gt; you can do your own analysis and your own plots, you just need to import the required Yambopy modules to load the data.&lt;br /&gt;
&lt;br /&gt;
In our case, the resulting plot is the following.&lt;br /&gt;
&lt;br /&gt;
[[File:1L MoS2 MoS2 Ex-ph.png|500px|center]]&lt;br /&gt;
&lt;br /&gt;
This can be checked against Fig. 2(d) of reference &amp;lt;ref name=&amp;quot;chan2023&amp;quot; /&amp;gt;, although you have to keep in mind that our results are badly undersampled in terms of the reciprocal-space grid, as can be easily seen, and the quantity plotted is not exactly the same. However, the main features are already there since they are dictated mostly by crystal symmetries.&lt;br /&gt;
&lt;br /&gt;
Now that we have the exciton-phonon matrix elements, we can use them to build several kinds of observables. Below, we give an example related to phonon-assisted luminescence, but we may update this tutorial in the future to include more cases.&lt;br /&gt;
&lt;br /&gt;
== Step 8: Compute phonon-assisted luminescence ==&lt;br /&gt;
&lt;br /&gt;
[[File:Luminescence scheme.png|250px|right]]&lt;br /&gt;
&lt;br /&gt;
We want to compute the experimental optical signature due to the phonon-assisted recombination of an exciton (as sketched in the figure).&lt;br /&gt;
&lt;br /&gt;
The signal from the phonon replicas can be modeled as a second-order scattering process involving one phonon and one photon:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;I^{Sat}(\omega)=\frac{1}{ N_q} \frac{1}{3} \sum_{\epsilon s\beta \mu q} \frac{1}{E_{\beta q}-s\Omega_{\mu q}}\left|\sum_\alpha\frac{ D^{\epsilon}_\alpha \mathcal{G}_{\beta \alpha}^{\mu,*}(q)}{E_\alpha -E_{\beta q} +s\Omega_{\mu q}+\mathrm{i}\eta}\right|^2 \frac{N^{exc}_{\beta q}(T_{exc})[\frac{1+s}{2}+n_{\mu q}(T)]}{\omega -[E_{\beta q}-s\Omega_{\mu q}]+\mathrm{i}\eta}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this equation, the oscillator strength of the peak is given by the exciton-phonon coupling matrix elements &amp;lt;math&amp;gt;\mathcal{G}&amp;lt;/math&amp;gt; multiplied by the exciton dipoles &amp;lt;math&amp;gt;D&amp;lt;/math&amp;gt; (they are called &amp;quot;residuals&amp;quot; in Yambo). Here &amp;lt;math&amp;gt;E_\lambda&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;E_{\alpha q}&amp;lt;/math&amp;gt; are the energies of the optical and finite-momentum excitons, respectively, while &amp;lt;math&amp;gt;\Omega_{\mu q}&amp;lt;/math&amp;gt; are the phonon energies. &lt;br /&gt;
&lt;br /&gt;
Here, &amp;lt;math&amp;gt;n_{\mu q}(T)&amp;lt;/math&amp;gt; is the temperature-dependent phonon Bose-Einstein occupation function. As it can be seen, &amp;lt;math&amp;gt;s=1&amp;lt;/math&amp;gt; corresponds to processes of phonon &#039;&#039;emission&#039;&#039; (&amp;lt;math&amp;gt;\propto n(T)+1&amp;lt;/math&amp;gt;), while &amp;lt;math&amp;gt;s=-1&amp;lt;/math&amp;gt; corresponds to processes of phonon &#039;&#039;absorption&#039;&#039; (&amp;lt;math&amp;gt;\propto n(T)&amp;lt;/math&amp;gt;). Therefore, &amp;lt;math&amp;gt;I^{Sat}_{PL}(\omega;T)&amp;lt;/math&amp;gt; describes &#039;&#039;light&#039;&#039; emission by recombining excitons mediated by either &#039;&#039;phonon&#039;&#039; absorption or emission. &lt;br /&gt;
&lt;br /&gt;
The quantity &amp;lt;math&amp;gt; N_{\alpha q}(T_{exc})&amp;lt;/math&amp;gt; is the exciton occupation function. Luminescence is technically an out-of-equilibrium process, but we can assume that for very low density of excitations and in steady-state conditions, the exciton population can be approximately described by an equilibrium distribution evaluated at an effective temperature. Here, we use the Boltzmann distribution. Experimentally, &amp;lt;math&amp;gt;T_{exc}&amp;lt;/math&amp;gt; tends to coincide with the lattice temperature &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt; more or less above 100 K, while at very low temperature (&amp;lt; 10 K), &amp;lt;math&amp;gt;T_{exc}&amp;lt;/math&amp;gt; may vary between 10-50 K. It goes without saying that this needs to carefully be checked in your realistic calculations.&lt;br /&gt;
&lt;br /&gt;
Finally, the spectrum is averaged over the polarization directions of the emitted photons (&amp;lt;math&amp;gt;\epsilon=x,y,z&amp;lt;/math&amp;gt; representing the respective dipole components).&lt;br /&gt;
&lt;br /&gt;
=== Running the jobs ===&lt;br /&gt;
&lt;br /&gt;
In order to study luminescence in a paradigmatic system, we switch to bulk hexagonal boron nitride and we repeat the workflow. As you can easily see, one can think about automatizing the execution of all these calculations via scripting or more advanced tools. However, in the case of very large simulations (memory-limited or disk-space limited) or for systems whose electronic and lattice properties are fragile with respect to tiny calculation details, one must be very careful and run many basic tests.&lt;br /&gt;
&lt;br /&gt;
Fortunately, we are running a fast underconverged example. We use LDA pseudopotentials from the pseudo-dojo library and the following are the calculations steps.&lt;br /&gt;
&lt;br /&gt;
1. Input &amp;lt;code&amp;gt;hbn.scf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 &amp;amp;control&lt;br /&gt;
     calculation=&#039;scf&#039;,&lt;br /&gt;
     prefix=&#039;hBN&#039;,&lt;br /&gt;
     restart_mode=&#039;from_scratch&#039;&lt;br /&gt;
     pseudo_dir = &#039;$PSEUDO_DIR&#039;,&lt;br /&gt;
     outdir = &#039;./tmp&#039;&lt;br /&gt;
     verbosity = &#039;high&#039;&lt;br /&gt;
     wf_collect=.true.&lt;br /&gt;
 /&lt;br /&gt;
 &amp;amp;system&lt;br /&gt;
     ibrav = 4,&lt;br /&gt;
     celldm(1) = 4.703675849&lt;br /&gt;
     celldm(3) = 2.603711434&lt;br /&gt;
     nat= 4,&lt;br /&gt;
     ntyp= 2,&lt;br /&gt;
     force_symmorphic=.true.&lt;br /&gt;
     ecutwfc = 100,&lt;br /&gt;
 /&lt;br /&gt;
 &amp;amp;electrons&lt;br /&gt;
   diago_david_ndim = 2&lt;br /&gt;
   diago_full_acc=.true.&lt;br /&gt;
   diago_thr_init=5.0e-6&lt;br /&gt;
   mixing_mode = &#039;plain&#039;&lt;br /&gt;
   mixing_beta = 0.7&lt;br /&gt;
   conv_thr =  1.0d-16&lt;br /&gt;
 /&lt;br /&gt;
 ATOMIC_SPECIES&lt;br /&gt;
  B 10.81100  B_LDA_dojo.UPF&lt;br /&gt;
  N 14.00674  N_LDA_dojo.UPF&lt;br /&gt;
 ATOMIC_POSITIONS {crystal}&lt;br /&gt;
 N             0.6666666670        0.3333333330        -0.250000000000&lt;br /&gt;
 B             0.3333333330        0.6666666670        -0.250000000000&lt;br /&gt;
 B             0.6666666670        0.3333333330        0.25000000000&lt;br /&gt;
 N             0.3333333330        0.6666666670        0.25000000000&lt;br /&gt;
 K_POINTS {automatic}&lt;br /&gt;
 6 6 2 0 0 0&lt;br /&gt;
&lt;br /&gt;
 mpirun -np 4 pw.x -inp hbn.scf &amp;gt; scf.out&lt;br /&gt;
&lt;br /&gt;
2. Input &amp;lt;code&amp;gt;hbn.nscf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 &amp;amp;control&lt;br /&gt;
     calculation=&#039;nscf&#039;,&lt;br /&gt;
     prefix=&#039;hBN&#039;,&lt;br /&gt;
     restart_mode=&#039;from_scratch&#039;&lt;br /&gt;
     pseudo_dir = &#039;$PSEUDO_DIR&#039;&lt;br /&gt;
     outdir = &#039;./&#039;&lt;br /&gt;
     verbosity = &#039;high&#039;&lt;br /&gt;
     wf_collect=.true.&lt;br /&gt;
 /&lt;br /&gt;
 &amp;amp;system&lt;br /&gt;
     ibrav = 4,&lt;br /&gt;
     celldm(1) = 4.703675849&lt;br /&gt;
     celldm(3) = 2.603711434&lt;br /&gt;
     nat= 4,&lt;br /&gt;
     ntyp= 2,&lt;br /&gt;
     force_symmorphic=.true.&lt;br /&gt;
     ecutwfc = 100,&lt;br /&gt;
 	nbnd = 120&lt;br /&gt;
 /&lt;br /&gt;
 &amp;amp;electrons&lt;br /&gt;
   diago_david_ndim = 2&lt;br /&gt;
   diago_full_acc=.true.&lt;br /&gt;
   diago_thr_init=5.0e-6&lt;br /&gt;
   mixing_mode = &#039;plain&#039;&lt;br /&gt;
   mixing_beta = 0.7&lt;br /&gt;
   conv_thr =  1.0d-16&lt;br /&gt;
 /&lt;br /&gt;
 ATOMIC_SPECIES&lt;br /&gt;
  B 10.81100  B_LDA_dojo.UPF&lt;br /&gt;
  N 14.00674  N_LDA_dojo.UPF&lt;br /&gt;
 ATOMIC_POSITIONS {crystal}&lt;br /&gt;
 N             0.6666666670        0.3333333330        -0.250000000000&lt;br /&gt;
 B             0.3333333330        0.6666666670        -0.250000000000&lt;br /&gt;
 B             0.6666666670        0.3333333330        0.25000000000&lt;br /&gt;
 N             0.3333333330        0.6666666670        0.25000000000&lt;br /&gt;
 K_POINTS {automatic}&lt;br /&gt;
 6 6 2 0 0 0&lt;br /&gt;
&lt;br /&gt;
 mpirun -np 4 pw.x -inp hbn.nscf &amp;gt; nscf.out&lt;br /&gt;
&lt;br /&gt;
3. Input &amp;lt;code&amp;gt;hbn.dvscf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 hbn_dvscf&lt;br /&gt;
 &amp;amp;inputph&lt;br /&gt;
   tr2_ph=1.0d-12,&lt;br /&gt;
   verbosity=&#039;high&#039;&lt;br /&gt;
   prefix=&#039;hBN&#039;,&lt;br /&gt;
   fildvscf = &#039;hBN-dvscf&#039;,&lt;br /&gt;
   electron_phonon = &#039;dvscf&#039;,&lt;br /&gt;
   fildyn=&#039;hBN.dyn&#039;,&lt;br /&gt;
   epsil=.false.,&lt;br /&gt;
   ldisp=.true.,&lt;br /&gt;
   recover=.true.,&lt;br /&gt;
   nq1=6,&lt;br /&gt;
   nq2=6,&lt;br /&gt;
   nq3=2&lt;br /&gt;
 /&lt;br /&gt;
&lt;br /&gt;
 nohup mpirun -np 8 pw.x -inp hbn.dvscf &amp;gt; dvscf.out &amp;amp;&lt;br /&gt;
&lt;br /&gt;
4. Input &amp;lt;code&amp;gt;bse.in&amp;lt;/code&amp;gt; (we include 2 valence and 2 conduction bands):&lt;br /&gt;
&lt;br /&gt;
 optics                           # [R] Linear Response optical properties&lt;br /&gt;
 bss                              # [R] BSE solver&lt;br /&gt;
 bse                              # [R][BSE] Bethe Salpeter Equation.&lt;br /&gt;
 dipoles                          # [R] Oscillator strenghts (or dipoles)&lt;br /&gt;
 em1s&lt;br /&gt;
 DIP_CPU= &amp;quot;1 8 1&amp;quot;                      # [PARALLEL] CPUs for each role&lt;br /&gt;
 DIP_ROLEs= &amp;quot;k c v&amp;quot;                    # [PARALLEL] CPUs roles (k,c,v)&lt;br /&gt;
 DIP_Threads=0                    # [OPENMP/X] Number of threads for dipoles&lt;br /&gt;
 X_and_IO_CPU= &amp;quot;1 1 1 8 1&amp;quot;                 # [PARALLEL] CPUs for each role&lt;br /&gt;
 X_and_IO_ROLEs= &amp;quot;q g k c v&amp;quot;               # [PARALLEL] CPUs roles (q,g,k,c,v)&lt;br /&gt;
 X_and_IO_nCPU_LinAlg_INV=-1      # [PARALLEL] CPUs for Linear Algebra (if -1 it is automatically set)&lt;br /&gt;
 X_Threads=0                      # [OPENMP/X] Number of threads for response functions&lt;br /&gt;
 BS_CPU= &amp;quot;8 1 1&amp;quot;                       # [PARALLEL] CPUs for each role&lt;br /&gt;
 BS_ROLEs= &amp;quot;k eh t&amp;quot;                     # [PARALLEL] CPUs roles (k,eh,t)&lt;br /&gt;
 BS_nCPU_LinAlg_INV=-1            # [PARALLEL] CPUs for Linear Algebra (if -1 it is automatically set)&lt;br /&gt;
 BS_nCPU_LinAlg_DIAGO=-1          # [PARALLEL] CPUs for Linear Algebra (if -1 it is automatically set)&lt;br /&gt;
 X_Threads=0                      # [OPENMP/X] Number of threads for response functions&lt;br /&gt;
 K_Threads=0                      # [OPENMP/BSK] Number of threads for response functions&lt;br /&gt;
 % QpntsRXs&lt;br /&gt;
    1 | 14 |                         # [Xs] Transferred momenta&lt;br /&gt;
 %&lt;br /&gt;
 % BndsRnXs&lt;br /&gt;
    1 | 120 |                         # [Xs] Polarization function bands&lt;br /&gt;
 %&lt;br /&gt;
 NGsBlkXs= 10                Ry    # [Xs] Response block size&lt;br /&gt;
 % LongDrXs&lt;br /&gt;
  1.000000 | 1.000000 | 1.000000 |        # [Xs] [cc] Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 BSEmod= &amp;quot;resonant&amp;quot;               # [BSE] resonant/retarded/coupling&lt;br /&gt;
 BSKmod= &amp;quot;SEX&amp;quot;                    # [BSE] IP/Hartree/HF/ALDA/SEX/BSfxc&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;Lkind= &amp;quot;Lfull&amp;quot;                    # [BSE] Lbar (default) / full&amp;lt;/span&amp;gt;&lt;br /&gt;
 BSSmod= &amp;quot;d&amp;quot;                      # [BSS] (h)aydock/(d)iagonalization/(s)lepc/(i)nversion/(t)ddft`&lt;br /&gt;
 % DipBands&lt;br /&gt;
    1 | 120 |                         # [DIP] Bands range for dipoles&lt;br /&gt;
 %&lt;br /&gt;
 DipApproach= &amp;quot;G-space v&amp;quot;         # [DIP] [G-space v/R-space x/Covariant/Shifted grids]&lt;br /&gt;
 DipComputed= &amp;quot;R V P&amp;quot;             # [DIP] [default R P V; extra P2 Spin Orb]&lt;br /&gt;
 BSENGexx= 30000            Ry    # [BSK] Exchange components&lt;br /&gt;
 #ALLGexx                       # [BSS] Force the use use all RL vectors for the exchange part&lt;br /&gt;
 BSENGBlk=  9000            Ry    # [BSK] Screened interaction block size [if -1 uses all the G-vectors of W(q,G,Gp)]&lt;br /&gt;
 % KfnQP_E&lt;br /&gt;
  1.25997 | 1.08816 | 1.12683 |        # [EXTQP BSK BSS] E parameters  (c/v) eV|adim|adim&lt;br /&gt;
 %&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;% BSEQptR&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 1 | 14 |                     # [BSK] Transferred momenta range&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;%&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;% BSEBands&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;   7 | 10 |                         # [BSK] Bands range&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;%&amp;lt;/span&amp;gt;&lt;br /&gt;
 % BEnRange&lt;br /&gt;
   0.50000 | 8.00000 |         eV    # [BSS] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 % BDmRange&lt;br /&gt;
  0.050000 | 0.050000 |         eV    # [BSS] Damping range&lt;br /&gt;
 %&lt;br /&gt;
 BEnSteps= 1000                    # [BSS] Energy steps&lt;br /&gt;
 % BLongDir&lt;br /&gt;
  1.000000 | 1.000000 | 0.000000 |        # [BSS] [cc] Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 WRbsWF                        # [BSS] Write to disk excitonic the WFs&lt;br /&gt;
&lt;br /&gt;
 nohup mpirun -np 8 yambo -F bse.in -J bse_Lfull -C bse_Lfull &amp;amp;&lt;br /&gt;
&lt;br /&gt;
Importantly, since we want to describe the phonon-assisted recombination process of an *optical* exciton (i.e., emitting a transverse photon), this time we also run an additional calculation at `Q=0` omitting the nonanalytic long-range Coulomb exchange. Make a second input &amp;lt;code&amp;gt;bse_Lbar.in&amp;lt;/code&amp;gt; with the following changes: &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;Lkind= &amp;quot;Lbar&amp;quot;                    # [BSE] Lbar (default) / full&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;% BSEQptR&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 1 | 1 |                     # [BSK] Transferred momenta range&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;%&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4b. So now we make a second BSE run in a different directory specified by &amp;lt;code&amp;gt;-J&amp;lt;/code&amp;gt;. Here, we also pass to yambo the directory of the previous run as it includes the important screening databases &amp;lt;code&amp;gt;ndb.em1s*&amp;lt;/code&amp;gt; that we do not want to recompute from scratch.&lt;br /&gt;
 &lt;br /&gt;
 mpirun -np 8 yambo -F bse_Lbar.in -J bse_Lbar,bse_Lfull -C bse_Lbar&lt;br /&gt;
&lt;br /&gt;
5. Now we run &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; (with or without yambopy: in the latter case remember the option &amp;lt;code&amp;gt;-D&amp;lt;/code&amp;gt;) to get the el-ph matrix elements, particularly the &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; databases:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph path/of/dvscf/hbn.dvscf -b 7 10 -par 4 2 -D&lt;br /&gt;
&lt;br /&gt;
=== Luminescence calculation ===&lt;br /&gt;
&lt;br /&gt;
6. And finally we calculate exciton-phonon matrix elements and the luminescence spectrum in one go using a python script importing the Yambopy exciton-phonon tools: in order to do this, we need to take a look at all the necessary input variables for the formula written above.&lt;br /&gt;
&lt;br /&gt;
We can start from the script &amp;lt;code&amp;gt;luminescence.py&amp;lt;/code&amp;gt; available in &amp;lt;code&amp;gt;tutorials/exciton-phonon&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
 import numpy as np&lt;br /&gt;
 import matplotlib.pyplot as plt&lt;br /&gt;
 from yambopy.exciton_phonon.excph_luminescence import exc_ph_luminescence&lt;br /&gt;
 from yambopy.exciton_phonon.excph_input_data import exc_ph_get_inputs&lt;br /&gt;
&lt;br /&gt;
We import the necessary tools...&lt;br /&gt;
&lt;br /&gt;
 path = &#039;3D_hBN&#039;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Path to BSE calculation (Lout--&amp;gt; response is Lfull)&amp;lt;/span&amp;gt;&lt;br /&gt;
 bsepath =  f&#039;{path}/bse_Lfull&#039; &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# ndb.BS_diago_Q* databases are needed&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Path to BSE calculation for optically active exciton (Lin --&amp;gt; response is Lbar)&amp;lt;/span&amp;gt;&lt;br /&gt;
 bseBARpath =  f&#039;{path}/bse_Lbar&#039;  &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# ndb.BS_diago_Q1 database is needed&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Path to electron-phonon calculation&amp;lt;/span&amp;gt;&lt;br /&gt;
 elphpath = path &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# ndb.elph is needed&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Path to unprojected dipoles matrix elements (optional)&amp;lt;/span&amp;gt;&lt;br /&gt;
 dipolespath = bsepath &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# ndb.dipoles is needed (optional)&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Path to lattice and k-space info&amp;lt;/span&amp;gt;&lt;br /&gt;
 savepath = f&#039;{path}/SAVE&#039; &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# ns.db1 database is needed&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
... and we specify the paths to the necessary databases. Note that, if we want to perform polarization averaging, we have to recompute the excitonic dipoles in python as seen here.&lt;br /&gt;
&lt;br /&gt;
What about &amp;lt;code&amp;gt;bseBARpath&amp;lt;/code&amp;gt;? This variable points to the directory where the databases for the optical (zero-momentum) excitons &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; (which may be computed with &amp;lt;code&amp;gt;Lkind=&#039;Lbar&#039;&amp;lt;/code&amp;gt;) is located, which can be different from the directory with the full indirect exciton dispersion &amp;lt;math&amp;gt;\beta&amp;lt;/math&amp;gt; (usually computed with &amp;lt;code&amp;gt;Lkind=&#039;Lfull&#039;&amp;lt;/code&amp;gt;, however &amp;lt;code&amp;gt;Lkind=&#039;Ltilde&#039;&amp;lt;/code&amp;gt; can also be used if one is interested in &amp;quot;irreducible&amp;quot; excitons). This makes it possible to compute the coupling between different exciton kinds.&lt;br /&gt;
&lt;br /&gt;
 bands_range=[6,10] &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# 2 valence, 2 conduction bands&amp;lt;/span&amp;gt;&lt;br /&gt;
 phonons_range=[0,12] &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# All phonons&amp;lt;/span&amp;gt;&lt;br /&gt;
 nexc_out = 12 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# 12 excitonic states at each momentum (Lout)&amp;lt;/span&amp;gt;&lt;br /&gt;
 nexc_in  = 12 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# 12 excitonic states at Q=0 (Lin)&amp;lt;/span&amp;gt;&lt;br /&gt;
 T_ph  = 10 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Lattice temperature&amp;lt;/span&amp;gt;&lt;br /&gt;
 T_exc = 10 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Effective excitonic temperature&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 emin=4.4      &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Energy range and plot details (in eV)&amp;lt;/span&amp;gt;&lt;br /&gt;
 emax=4.7&lt;br /&gt;
 estep=0.0002&lt;br /&gt;
 broad = 0.005 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Broadening parameter for peak width (in eV)&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next, we specify the parameters for the calculation. We include valence bands from 7 to 10 (6 to 9 in python index) and the contribution of all 12 phonon modes. We consider 12 excitonic states for the coupling matrix elements.&lt;br /&gt;
&lt;br /&gt;
Here &amp;lt;code&amp;gt;T_ph&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;T_exc&amp;lt;/code&amp;gt; are the lattice and excitonic temperatures, respectively.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# We calculate and load all the inputs:&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# * Exciton-phonon matrix elements&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# * Excitonic dipole matrix elements&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# * Exciton energies&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# * Phonon energies&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# * We specify bse_path2=bseBARpath meaning we use Lbar calculation for Q=0 excitons&amp;lt;/span&amp;gt;&lt;br /&gt;
 input_data = exc_ph_get_inputs(savepath,elphpath,bsepath,\&lt;br /&gt;
                                bse_path2=bseBARpath,dipoles_path=dipolespath,\&lt;br /&gt;
                                nexc_in=12,nexc_out=12,\&lt;br /&gt;
                                bands_range=[6,10],phonons_range=[0,12])&lt;br /&gt;
&lt;br /&gt;
 ph_energies, exc_energies, exc_energies_in, G, exc_dipoles = input_data&lt;br /&gt;
&lt;br /&gt;
The function &amp;lt;code&amp;gt;exc_ph_get_inputs&amp;lt;/code&amp;gt; gives us all the input data for luminescence in the correct format: phonon energies, exciton energies, optical exciton energies (if needed), exciton-phonon matrix elements (calculated on the fly and printed to file), unprojected exciton dipoles (optional, calculated on the fly and printed to file).&lt;br /&gt;
The exc-ph matrix element calculation is just a wrapper of the same tools that we have tested in the above section on MoS2.&lt;br /&gt;
&lt;br /&gt;
Finally, there is the calculation of the luminescence spectrum via the function &amp;lt;code&amp;gt;exc_ph_luminescence&amp;lt;/code&amp;gt;:&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# We calculate the luminescence spectrum including the input data from before&amp;lt;/span&amp;gt;&lt;br /&gt;
 w,PL = exc_ph_luminescence(T_ph,ph_energies,exc_energies,exc_dipoles,G,\&lt;br /&gt;
                            exc_energies_in=exc_energies_in,exc_temp=T_exc,\&lt;br /&gt;
                            nexc_out=nexc_out,nexc_in=nexc_in,emin=emin,emax=emax,\&lt;br /&gt;
                            estep=estep,broad=broad)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you want to print the luminescence data for later plotting, you can also add the following line to the script:&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Save to file&amp;lt;/span&amp;gt;&lt;br /&gt;
 data = np.column_stack((w, PL))&lt;br /&gt;
 np.savetxt(&amp;quot;hBN_luminescence_12x12x1.dat&amp;quot;, data, fmt=&amp;quot;%.8f&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
It is now time to run the whole script:&lt;br /&gt;
&lt;br /&gt;
 python luminescence.py&lt;br /&gt;
 &lt;br /&gt;
NB: By using Yambopy for Step 6, we have limited the use of the Yambo code to just step 4 in the entire workflow. This option is more flexible, as it allows for a greater degree of control by the user. On the other hand the Yambo postprocessing route features a Yambo-style input that doesn&#039;t require python knowledge and the calculation is currently faster in fortran. However, the luminescence expression computed in Yambo is a slightly different than this one: it is more approximated in the description of the satellite oscillator strengths, but it explicitly includes the renormalization of the direct exciton peak. You can check the differences [[Exciton-phonon coupling and luminescence - Yambo postprocessing|here]].&lt;br /&gt;
&lt;br /&gt;
=== Results ===&lt;br /&gt;
We can plot the results of the step 6 calculation. If we do it in the same script we can add something like this:&lt;br /&gt;
 fig = plt.figure()&lt;br /&gt;
 ax = fig.add_subplot(1,1,1)&lt;br /&gt;
 ax.set_xlim(emin,emax)&lt;br /&gt;
 ax.set_ylim(0,np.max(PL)*1.1)&lt;br /&gt;
 ax.get_yaxis().set_visible(False)&lt;br /&gt;
 &lt;br /&gt;
 ax.plot(w, PL, &#039;-&#039;,c=&#039;red&#039;, label=&amp;quot;AA&#039; hBN luminescence&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
 plt.legend()&lt;br /&gt;
 plt.savefig(&#039;hBN_luminescence.png&#039;)&lt;br /&gt;
 plt.show()&lt;br /&gt;
&lt;br /&gt;
[[File:HBN luminescence satellites.png|500px|center]]&lt;br /&gt;
&lt;br /&gt;
Here, the signal corresponds to a finite-momentum exciton that recombines with the help of several different phonon modes, both optical and acoustic. Each phonon mode whose coupling with the exciton is allowed can generate a peak, and the energy shifts of these peaks with respect to the initial exciton energy correspond to the phonon energies. This result is underconverged, but the main features are all there. In the plot, we show a more converged example using a 12x12x4 grid (all the other parameters being equal). These plots can be compared with Fig. 4(a) of reference &amp;lt;ref name=&amp;quot;zanfrognini2023&amp;quot; /&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;toyozawa2003&amp;quot; &amp;gt;Toyozawa, Yutaka, and Chris Oxlade, &#039;&#039;Optical processes in solids&#039;&#039;, [https://m.booksee.org/book/1121964?force_lang=en Cambridge University Press, (2003)]. &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;lechifflart2023&#039;&amp;gt;P. Lechifflart, F. Paleari, D. Sangalli, C. Attaccalite, &#039;&#039;First-principles study of luminescence in hexagonal boron nitride single layer: Exciton-phonon coupling and the role of substrate&#039;&#039;, &lt;br /&gt;
[https://doi.org/10.1103/PhysRevMaterials.7.024006 Phys. Rev. M, &#039;&#039;&#039;7&#039;&#039;&#039; (2), 024006 (2023)]; [https://arxiv.org/abs/2212.10407 arXiv2212.1047]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;cannuccia2019&#039;&amp;gt;E. Cannuccia, B. Monserrat and C. Attaccalite, &#039;&#039;Theory of phonon-assisted luminescence in solids: Application to hexagonal boron nitride&#039;&#039;, [https://doi.org/10.1103/PhysRevB.99.081109 Phys. Rev. B &#039;&#039;&#039;99&#039;&#039;&#039;, 081109(R) (2019)]; [https://arxiv.org/abs/1807.11797 arXiv1807.11797]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;paleari2019&#039;&amp;gt;F. Paleari et al., &#039;&#039;Exciton-Phonon Coupling in the Ultraviolet Absorption and Emission Spectra of Bulk Hexagonal Boron Nitride&#039;&#039;, [https://doi.org/10.1103/PhysRevLett.122.187401 Phys. Rev. Lett. &#039;&#039;&#039;122&#039;&#039;&#039;, 187401 (2019)]; [https://arxiv.org/abs/1810.08976 arXiv1810.089776] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;chen2020&#039;&amp;gt;&#039;&#039;Exciton-Phonon Interaction and Relaxation Times from First Principles&#039;&#039;,&lt;br /&gt;
Hsiao-Yi Chen, Davide Sangalli, and Marco Bernardi, [https://doi.org/10.1103/PhysRevLett.125.107401  Phys. Rev. Lett. &#039;&#039;&#039;125&#039;&#039;&#039;, 107401 (2020)]; [https://arxiv.org/abs/2002.08913 arXiv 2002.08913 (2020)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;lechifflart2023_PhD&amp;quot;&amp;gt;P. Lechifflart, &#039;&#039;Exciton-phonon coupling and phonon-assisted luminescence in hexagonal Boron Nitride nanostructures&#039;&#039;, [https://hal.science/tel-04266805v1 PhD Thesis, University of Marseille (2023)]; [https://www.yambo-code.eu/wiki/images/5/54/These_final.pdf From the yambo website]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;paleari2019_PhD&#039;&amp;gt;F. Paleari, &#039;&#039;First-principles approaches to the description of indirect absorption and luminescence spectroscopy: exciton-phonon coupling in hexagonal boron nitride&#039;&#039;, [https://wwwen.uni.lu/research/fstm/dphyms/people/fulvio_paleari PhD thesis, University of Luxembourg (2019)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;zanfrognini2023&#039;&amp;gt;M. Zanfrognini et al., &#039;&#039;Distinguishing different stackings in layered materials via luminescence spectroscopy&#039;&#039;, [https://doi.org/10.1103/PhysRevLett.131.206902 Phys. Rev. Lett. &#039;&#039;&#039;131&#039;&#039;&#039;, 206902 (2023)]; [https://arxiv.org/abs/2305.17554 arXiv 2305.17554] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;marini2024&#039;&amp;gt;G. Marini, M. Calandra, P. Cudazzo, &#039;&#039;Optical absorption and photoluminescence of single layer boron nitride from a first principles cumulant approach&#039;&#039;, [https://doi.org/10.1021/acs.nanolett.4c00669 Nano Lett., &#039;&#039;&#039;24&#039;&#039;&#039;, 20, 6017 (2024)]; [https://arxiv.org/abs/2402.03826 arXiv 2402.03826 (2024)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;antonius2017&#039;&amp;gt;G. Antonius, S. G. Louie, &#039;&#039;Theory of exciton-phonon coupling&#039;&#039;, [https://doi.org/10.1103/PhysRevB.105.085111 Phys. Rev. B, &#039;&#039;&#039;105&#039;&#039;&#039;, 085111 (2022)]; [https://arxiv.org/abs/1705.04245 arXiv1705.04245 (2017)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;paleari2022&#039;&amp;gt; F. Paleari, and A. Marini, &#039;&#039;Exciton-phonon interaction calls for a revision of the “exciton” concept&#039;&#039;, [https://doi.org/10.1103/PhysRevB.106.125403 Phys. Rev. B, &#039;&#039;&#039;106&#039;&#039;&#039;, 125403 (2022)]; [https://arxiv.org/abs/2205.02783 arXiv 2205.02783]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;cudazzo2020&#039;&amp;gt; P. Cudazzo, &#039;&#039;First-principles description of the exciton-phonon interaction: A cumulant approach&#039;&#039;, [https://doi.org/10.1103/PhysRevB.102.045136 Phys. Rev. B, &#039;&#039;&#039;102&#039;&#039;&#039;, 045136 (2020)]; [https://orbilu.uni.lu/bitstream/10993/44769/1/main.pdf Open access pdf from Luxembourg University]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;chan2023&#039;&amp;gt;Y-h Chan, J. B. Haber, M. H. Naik, J. B. Neaton, D. Y. Qiu, F. H. da Jornada, S. G. Louie, &#039;&#039;Exciton Lifetime and Optical Line Width Profile via Exciton–Phonon Interactions: Theory and First-Principles Calculations for Monolayer MoS2&#039;&#039;, [https://doi.org/10.1021/acs.nanolett.3c00732 Nano Lett., &#039;&#039;&#039;23&#039;&#039;&#039;, 9 (2023)]; [https://arxiv.org/abs/2212.08451 arXiv 2212.08451 (2023)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;murali2025&#039;&amp;gt;M. Nalabothula, S. Reichardt, L. Wirtz, &#039;&#039;Origin of Interlayer Exciton–Phonon Coupling in 2D Heterostructures&#039;&#039;, [https://doi.org/10.1021/acs.nanolett.5c00355 Nano Lett., &#039;&#039;&#039;25&#039;&#039;&#039;, 15 (2025)], [https://arxiv.org/abs/2407.16111 arXiv 2407.16111 (2025)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>FulvioPaleari</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Exciton-phonon_coupling_and_luminescence&amp;diff=9341</id>
		<title>Exciton-phonon coupling and luminescence</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Exciton-phonon_coupling_and_luminescence&amp;diff=9341"/>
		<updated>2026-03-13T14:45:40Z</updated>

		<summary type="html">&lt;p&gt;FulvioPaleari: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[exc-ph scheme| File:Tdgw-phonon-usc-01-1024x829.jpg| (c) Zhenglu Li, University of Southern California |400px | right ]]&lt;br /&gt;
&lt;br /&gt;
In this advanced tutorial, we will calculate exciton-phonon interactions from first principles by interfacing DFPT (for phonon calculations) and BSE (for exciton calculations).&lt;br /&gt;
&lt;br /&gt;
The DFTP calculations are run with Quantum ESPRESSO, while the many-body GW-BSE calculations are run with Yambo. Finally, the exciton-phonon interaction will be obtained by combining and postprocessing the databases computed in the two previous runs. The great advantage of this workflow is that the calculations can be run in the irreducible Brillouin zones both for the electronic momenta (&#039;&#039;&#039;k&#039;&#039;&#039;) and the transfer momenta (&#039;&#039;&#039;Q&#039;&#039;&#039;, &#039;&#039;&#039;q&#039;&#039;&#039;) of excitons and phonons, thus speeding up considerably the jobs while reducing the IO and memory load.&lt;br /&gt;
&lt;br /&gt;
We will first compute the exciton-phonon coupling matrix elements: these are the building blocks needed to construct experimental observables such as phonon-assisted optical spectra (such as luminescence), Raman spectra and exciton lifetimes. We will do this in the case of monolayer MoS&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;, a 2D system with large spin-orbit interaction.&lt;br /&gt;
&lt;br /&gt;
As an example of application, we will consider the case of phonon-assisted luminescence. We will do this in the case of bulk hBN, a layered indirect insulator with strong electron-phonon coupling.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; this tutorial will be updated when new exc-ph tools become available in Yambopy (including full-python postprocessing, Raman spectra, interpolated lifetimes, etc).&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
This is an advanced topic: we assume that you already know something about the theory&amp;lt;ref name=&amp;quot;toyozawa2003&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;antonius2017&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;cudazzo2020&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;paleari2019_PhD&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;paleari2022&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;lechifflart2023_PhD&amp;quot; /&amp;gt; and applications&amp;lt;ref name=&amp;quot;paleari2019&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;cannuccia2019&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;chen2020&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;zanfrognini2023&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;lechifflart2023&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;chan2023&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;marini2024&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;murali2025&amp;quot; /&amp;gt; of exciton-phonon physics. &lt;br /&gt;
&lt;br /&gt;
Also, we assume that you already know how to run both a basic &#039;&#039;&#039;Yambo&#039;&#039;&#039; GW-BSE calculation and a DFPT phonon calculation with &#039;&#039;&#039;Quantum ESPRESSO&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Besides the QE executables &amp;lt;code&amp;gt;pw.x&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ph.x&amp;lt;/code&amp;gt;, we also use the yambo phonon-specific executable &amp;lt;code&amp;gt;yambo_ph&amp;lt;/code&amp;gt; and the python utility &#039;&#039;&#039;Yambopy&#039;&#039;&#039;. The auxiliary code &#039;&#039;&#039;LetzElPhC&#039;&#039;&#039; (executable &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt;) will be used to obtain the electron-phonon matrix elements by reading the same electronic wavefunctions used by Yambo (and stored in the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory), while also making full use of crystal symmetries. [https://github.com/yambo-code/LetzElPhC LetzElPhC] will be run by Yambopy, but it must nonetheless be installed. Finally, the exciton-phonon properties can be computed either using &amp;lt;code&amp;gt;yambo_ph&amp;lt;/code&amp;gt; or using Yambopy itself. Both cases will be covered in this tutorial.&lt;br /&gt;
&lt;br /&gt;
[[File:Workflow scheme.png|800px|center]]&lt;br /&gt;
&lt;br /&gt;
== Step 0: Pseudopotentials, equilibrium structure and convergence ==&lt;br /&gt;
&lt;br /&gt;
In a real calculation, it is important to ensure that both the pseudopotential and the lattice parameters that we are using are compatible and perform well for the electronic excited states and for the lattice vibrations simultaneously. Furthermore, you have to make sure that the wave function cutoff &amp;lt;code&amp;gt;ecutwfc&amp;lt;/code&amp;gt; is converged with respect to the DFPT step and not just to the DFT one. This is in addition to the other customary convergence tests for DFT, DFPT, GW and BSE calculations.&lt;br /&gt;
&lt;br /&gt;
This is often the most time-demanding step when starting on a new system.&lt;br /&gt;
&lt;br /&gt;
For the sake of this tutorial, we assume that we have already done all these tests and we are starting the final workflow to get the exciton-phonon properties.&lt;br /&gt;
&lt;br /&gt;
== Step 1: scf calculation ==&lt;br /&gt;
&lt;br /&gt;
First of all, we run a standard scf calculation with &amp;lt;code&amp;gt;pw.x&amp;lt;/code&amp;gt; for Yambo. We stick with non-symmorphic symmetries. At the end, we will have the QE &amp;lt;code&amp;gt;save&amp;lt;/code&amp;gt; directory.&lt;br /&gt;
&lt;br /&gt;
This is the input &amp;lt;code&amp;gt;mos2.scf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 &amp;amp;control&lt;br /&gt;
           wf_collect = .true.,&lt;br /&gt;
          calculation = &amp;quot;scf&amp;quot;,&lt;br /&gt;
            verbosity = &#039;high&#039;,&lt;br /&gt;
           pseudo_dir = &#039;$PSEUDO_DIR&#039;,&lt;br /&gt;
               prefix = &amp;quot;mos2&amp;quot;,&lt;br /&gt;
               outdir = &#039;.&#039;,&lt;br /&gt;
  /&amp;amp;end&lt;br /&gt;
  &amp;amp;system&lt;br /&gt;
              ecutwfc = 100.0,&lt;br /&gt;
          occupations = &#039;fixed&#039;,&lt;br /&gt;
                ibrav = 4,&lt;br /&gt;
            celldm(1) = 5.9000811881,&lt;br /&gt;
            celldm(3) = 6.7795677253,&lt;br /&gt;
                  nat = 3,&lt;br /&gt;
                 ntyp = 2,&lt;br /&gt;
             lspinorb = .true.&lt;br /&gt;
             noncolin = .true.&lt;br /&gt;
             assume_isolated = &#039;2D&#039;&lt;br /&gt;
         force_symmorphic = .true.&lt;br /&gt;
  /&amp;amp;end&lt;br /&gt;
  &amp;amp;electrons&lt;br /&gt;
     electron_maxstep = 200,&lt;br /&gt;
          mixing_beta = 0.7,&lt;br /&gt;
             conv_thr = 1.d-08,&lt;br /&gt;
  /&amp;amp;end&lt;br /&gt;
   ATOMIC_SPECIES&lt;br /&gt;
    Mo  95.940      Mo_ONCV_PBE_FR-1.0.upf&lt;br /&gt;
    S    32.065     S_ONCV_PBE_FR-1.1.upf&lt;br /&gt;
   ATOMIC_POSITIONS { crystal }&lt;br /&gt;
 Mo       0.333333333   0.666666667   0.000000000&lt;br /&gt;
 S        0.666666667   0.333333333   0.073413577&lt;br /&gt;
 S        0.666666667   0.333333333  -0.073413577&lt;br /&gt;
  K_POINTS { automatic }&lt;br /&gt;
 6 6 1 0 0 0&lt;br /&gt;
&lt;br /&gt;
Here we are using full relativistic pseudopotentials from the SG-15 database.&lt;br /&gt;
&lt;br /&gt;
We can run it on our machine (for example using 4 MPI tasks) as:&lt;br /&gt;
&lt;br /&gt;
 mpirun -np 4 pw.x -inp mos2.scf &amp;gt; scf.out&lt;br /&gt;
&lt;br /&gt;
== Step 2: nscf calculation for Yambo ==&lt;br /&gt;
&lt;br /&gt;
Copy the QE &amp;lt;code&amp;gt;save&amp;lt;/code&amp;gt; directory from the scf calculation and run the nscf calculation for any number of empty states, with the correct &amp;lt;code&amp;gt;k&amp;lt;/code&amp;gt;-grid we want to use in Yambo. Here we are using a badly underconverged grid of 6x6x1.&lt;br /&gt;
&lt;br /&gt;
This reciprocal-space grid will also match the momentum transfer &amp;lt;code&amp;gt;q&amp;lt;/code&amp;gt; grid on which excitons and phonons will be defined!&lt;br /&gt;
&lt;br /&gt;
The electronic wavefunctions computed at this step and stored in the new nscf &amp;lt;code&amp;gt;save&amp;lt;/code&amp;gt; directory will be used both by Yambo and by the electron-phonon code: this is important because using different sets of wavefunctions would lead to a phase mismatch issue in the exciton-phonon matrix elements.&lt;br /&gt;
&lt;br /&gt;
The nscf input &amp;lt;code&amp;gt;mos2.nscf&amp;lt;/code&amp;gt; is&lt;br /&gt;
 &amp;amp;control&lt;br /&gt;
           wf_collect = .true.,&lt;br /&gt;
          calculation = &amp;quot;nscf&amp;quot;,&lt;br /&gt;
            verbosity = &#039;high&#039;,&lt;br /&gt;
           pseudo_dir = &#039;$PSEUDO_DIR&#039;,&lt;br /&gt;
               prefix = &amp;quot;mos2&amp;quot;,&lt;br /&gt;
               outdir = &#039;.&#039;,&lt;br /&gt;
  /&amp;amp;end&lt;br /&gt;
  &amp;amp;system&lt;br /&gt;
              ecutwfc = 100.0,&lt;br /&gt;
          occupations = &#039;fixed&#039;,&lt;br /&gt;
                ibrav = 4,&lt;br /&gt;
            celldm(1) = 5.9000811881,&lt;br /&gt;
            celldm(3) = 6.7795677253,&lt;br /&gt;
                  nat = 3,&lt;br /&gt;
                 ntyp = 2,&lt;br /&gt;
             lspinorb = .true.&lt;br /&gt;
             noncolin = .true.&lt;br /&gt;
                nbnd  = 250&lt;br /&gt;
             assume_isolated = &#039;2D&#039;&lt;br /&gt;
         force_symmorphic = .true.&lt;br /&gt;
  /&amp;amp;end&lt;br /&gt;
  &amp;amp;electrons&lt;br /&gt;
     electron_maxstep = 200,&lt;br /&gt;
          mixing_beta = 0.7,&lt;br /&gt;
             conv_thr = 1.d-08,&lt;br /&gt;
  /&amp;amp;end&lt;br /&gt;
   ATOMIC_SPECIES&lt;br /&gt;
    Mo  95.940      Mo_ONCV_PBE_FR-1.0.upf&lt;br /&gt;
    S    32.065     S_ONCV_PBE_FR-1.1.upf&lt;br /&gt;
   ATOMIC_POSITIONS { crystal }&lt;br /&gt;
 Mo       0.333333333   0.666666667   0.000000000&lt;br /&gt;
 S        0.666666667   0.333333333   0.073413577&lt;br /&gt;
 S        0.666666667   0.333333333  -0.073413577&lt;br /&gt;
  K_POINTS { automatic }&lt;br /&gt;
 6 6 1 0 0 0&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Again, we run the calculation&lt;br /&gt;
&lt;br /&gt;
 mpirun -np 4 pw.x -inp mos2.nscf &amp;gt; nscf.out&lt;br /&gt;
&lt;br /&gt;
== Step 3: dvscf phonon calculation ==&lt;br /&gt;
&lt;br /&gt;
Now we run the phonon calculation.&lt;br /&gt;
&lt;br /&gt;
Copy the &amp;lt;code&amp;gt;save&amp;lt;/code&amp;gt; directory from the &#039;&#039;&#039;scf&#039;&#039;&#039; calculation and run &amp;lt;code&amp;gt;ph.x&amp;lt;/code&amp;gt; for a dvscf calculation with a standard &amp;lt;code&amp;gt;q&amp;lt;/code&amp;gt;-grid matching the &amp;lt;code&amp;gt;k&amp;lt;/code&amp;gt;-grid we wanna use in Yambo.&lt;br /&gt;
&lt;br /&gt;
At the end, we will have the &amp;lt;code&amp;gt;_ph0&amp;lt;/code&amp;gt; directory containing the variation of the self-consistent potential, &amp;lt;math&amp;gt;\Delta V_{SCF}(q)&amp;lt;/math&amp;gt;, and the &amp;lt;code&amp;gt;*.dyn&amp;lt;/code&amp;gt; files with the phonon energies and eigenvectors.&lt;br /&gt;
&lt;br /&gt;
NB: one could further refine the phonon energies by enforcing the acoustic sum rule, including non-analytic long-range contributions, interpolating to finer grids... all of this can be done within Quantum ESPRESSO and will not be covered in this version of the tutorial.&lt;br /&gt;
&lt;br /&gt;
The input is &amp;lt;code&amp;gt;mos2.dvscf&amp;lt;/code&amp;gt;:&lt;br /&gt;
 &lt;br /&gt;
 mos2_dvscf&lt;br /&gt;
 &amp;amp;inputph&lt;br /&gt;
   tr2_ph=1.0d-12,&lt;br /&gt;
   verbosity=&#039;high&#039;&lt;br /&gt;
   prefix=&#039;mos2&#039;,&lt;br /&gt;
   fildvscf = &#039;mos2-dvscf&#039;,&lt;br /&gt;
   electron_phonon = &#039;dvscf&#039;,&lt;br /&gt;
   fildyn=&#039;mos2.dyn&#039;,&lt;br /&gt;
   epsil=.false.,&lt;br /&gt;
   ldisp=.true.,&lt;br /&gt;
   recover=.true.,&lt;br /&gt;
   nq1=6,&lt;br /&gt;
   nq2=6,&lt;br /&gt;
   nq3=1&lt;br /&gt;
 /&lt;br /&gt;
&lt;br /&gt;
And now we run as&lt;br /&gt;
&lt;br /&gt;
 nohup mpirun -np 8 ph.x -inp mos2.dvscf &amp;gt; dvscf.out &amp;amp;&lt;br /&gt;
&lt;br /&gt;
This time we use nohup and more processes because this calculation may take some time. It is a good idea to set &amp;lt;code&amp;gt;recover=.true.&amp;lt;/code&amp;gt; as in a real calculation you will easily breach walltime, and in this way you can safely restart.&lt;br /&gt;
&lt;br /&gt;
== Step 4: create Yambo &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory ==&lt;br /&gt;
&lt;br /&gt;
This is just the standard Yambo initialization: run &lt;br /&gt;
 &lt;br /&gt;
 p2y &lt;br /&gt;
&lt;br /&gt;
and then &lt;br /&gt;
&lt;br /&gt;
 yambo &lt;br /&gt;
&lt;br /&gt;
in the &#039;&#039;&#039;nscf&#039;&#039;&#039; &amp;lt;code&amp;gt;save&amp;lt;/code&amp;gt; folder and then move the newly generated &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory to a convenient place.&lt;br /&gt;
&lt;br /&gt;
== Step 5: run a BSE calculation ==&lt;br /&gt;
&lt;br /&gt;
Now we switch from QE to Yambo. Here, we forgo the GW step for simplicity (we can use a scissor operator to open the band gap).&lt;br /&gt;
&lt;br /&gt;
This calculation has a couple of differences with respect to a standard BSE calculation for optical absorption. We can look at the input file &amp;lt;code&amp;gt;bse.in&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Runlevels&amp;lt;/span&amp;gt;&lt;br /&gt;
 optics                       # [R OPT] Optics&lt;br /&gt;
 rim_cut                      # [R RIM CUT] Coulomb potential&lt;br /&gt;
 bss                          # [R BSS] Bethe Salpeter Equation solver&lt;br /&gt;
 em1s                         # [R Xs] Static Inverse Dielectric Matrix&lt;br /&gt;
 bse                          # [R BSE] Bethe Salpeter Equation.&lt;br /&gt;
 bsk                          # [R BSK] Bethe Salpeter Equation kernel&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# RIM and cutoff settings&amp;lt;/span&amp;gt;&lt;br /&gt;
 RandQpts=1000000             # [RIM] Number of random q-points in the BZ&lt;br /&gt;
 RandGvec= 100            RL    # [RIM] Coulomb interaction RS components&lt;br /&gt;
 CUTGeo= &amp;quot;slab z&amp;quot;               # [CUT] Coulomb Cutoff geometry: box/cylinder/sphere X/Y/Z/XY..&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Static screening&amp;lt;/span&amp;gt;&lt;br /&gt;
 X_and_IO_CPU= &amp;quot;1 1 4 2 1&amp;quot;       # [PARALLEL] CPUs for each role&lt;br /&gt;
 X_and_IO_ROLEs= &amp;quot;q g k c v&amp;quot;      # [PARALLEL] CPUs roles (q,g,k,c,v)&lt;br /&gt;
 X_and_IO_nCPU_LinAlg_INV=-1      # [PARALLEL] CPUs for Linear Algebra (if -1 it is automatically set)&lt;br /&gt;
 Chimod= &amp;quot;hartree&amp;quot;            # [X] IP/Hartree/ALDA/LRC/BSfxc&lt;br /&gt;
 % BndsRnXs&lt;br /&gt;
    1 |  200 |                 # [Xs] Polarization function bands&lt;br /&gt;
 %&lt;br /&gt;
 % LongDrXs&lt;br /&gt;
  1.000000 | 1.000000 | 1.000000 |        # [Xs] [cc] Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 NGsBlkXs= 8000            mRy    # [Xs] Response block size&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# BSE&amp;lt;/span&amp;gt;&lt;br /&gt;
 BS_CPU= &amp;quot;4.1.2&amp;quot;                   # [PARALLEL] CPUs for each role&lt;br /&gt;
 BS_ROLEs= &amp;quot;k.eh.t&amp;quot;                 # [PARALLEL] CPUs roles (k,eh,t)&lt;br /&gt;
 BS_nCPU_diago=4              # [PARALLEL] CPUs for matrix diagonalization&lt;br /&gt;
 BSEmod= &amp;quot;causal&amp;quot;             # [BSE] resonant/causal/coupling&lt;br /&gt;
 BSKmod= &amp;quot;SEX&amp;quot;                # [BSE] IP/Hartree/HF/ALDA/SEX/BSfxc&lt;br /&gt;
 BSSmod= &amp;quot;d&amp;quot;                  # [BSS] (h)aydock/(d)iagonalization/(s)lepc/(i)nversion/(t)ddft`&lt;br /&gt;
 BSENGexx=  40000      mRy    # [BSK] Exchange components&lt;br /&gt;
 ALLGexx                      # [BSS] Force the use use all RL vectors for the exchange part&lt;br /&gt;
 BSENGBlk=  8000       mRy    # [BSK] Screened interaction block size&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;Lkind=&amp;quot;full&amp;quot;                  #[BSE,X] bar(default)/full/tilde&amp;lt;/span&amp;gt;&lt;br /&gt;
 % KfnQP_E&lt;br /&gt;
  1.000000 | 1.000000 | 1.000000 |        # [EXTQP BSK BSS] E parameters  (c/v) eV|adim|adim&lt;br /&gt;
 %&lt;br /&gt;
 % BEnRange&lt;br /&gt;
   0.00000 |  4.00000 | eV    # [BSS] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 % BDmRange&lt;br /&gt;
   0.05000 |  0.05000 | eV    # [BSS] Damping range&lt;br /&gt;
 %&lt;br /&gt;
 BEnSteps= 2000               # [BSS] Energy steps&lt;br /&gt;
 % BLongDir&lt;br /&gt;
  1.000000 | 0.000000 | 0.000000 |        # [BSS] [cc] Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;% BSEQptR&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 1 | 7 |                     # [BSK] Transferred momenta range&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;%&amp;lt;/span&amp;gt;&lt;br /&gt;
 % BSEBands&lt;br /&gt;
    25 |  28 |                 # [BSK] Bands range&lt;br /&gt;
 %&lt;br /&gt;
 WRbsWF                      # [BSS] Write to disk excitonic the FWs&lt;br /&gt;
 &lt;br /&gt;
This file was generated using the command: &amp;lt;code&amp;gt; yambo -X s -o b -k sex -y d -r&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
First of all, we compute the excitons for all the momenta in the irreducible Brillouin zone for our discrete grid via the &amp;lt;code&amp;gt;BSEQptR&amp;lt;/code&amp;gt; variable. This will be a &#039;&#039;&#039;finite-momentum&#039;&#039;&#039; BSE calculation, analogous to the phonon one.&lt;br /&gt;
&lt;br /&gt;
Second, we change the variable &amp;lt;code&amp;gt;Lkind&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;bar&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;full&amp;lt;/code&amp;gt;. In Yambo, &amp;lt;code&amp;gt;Lkind=&amp;quot;bar&amp;quot;&amp;lt;/code&amp;gt;, which is the default for optical absorption, means that we are computing the excitonic response function without the long-range component of the exchange interaction. This cannot be used when computing the exciton momentum dependence, where the long-range exchange interaction can play a role, therefore we have to include it with &amp;lt;code&amp;gt;Lkind=&amp;quot;full&amp;quot;&amp;lt;/code&amp;gt;. This allows for the calculation of the excitonic longitudinal-transverse splitting (in 3D systems) as well.&lt;br /&gt;
&lt;br /&gt;
We can now run the code:&lt;br /&gt;
&lt;br /&gt;
 nohup mpirun -np 8 yambo -F bse.in -J bse_Lfull -C bse_Lfull &amp;amp;&lt;br /&gt;
&lt;br /&gt;
At the end of the calculation, we have obtained the &amp;lt;code&amp;gt;ndb.BS_diago_Q*&amp;lt;/code&amp;gt; databases inside the directory &amp;lt;code&amp;gt;bse_Lfull&amp;lt;/code&amp;gt;. They contain information on the exciton energies and wavefunctions at each momentum. Do not forget to check the report and logs of your calculation in the same directory to make sure that the code is doing what you want.&lt;br /&gt;
&lt;br /&gt;
== Step 6: obtain the electron-phonon matrix elements ==&lt;br /&gt;
&lt;br /&gt;
We have finished the heavy simulations. Now it&#039;s time for the postprocessing. The first order of business is the reconstruction of the electron-phonon coupling matrix elements from the dvscf results and the electronic wavefunctions.&lt;br /&gt;
&lt;br /&gt;
In order to do this, we will run the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable of the &#039;&#039;&#039;LetzElPhC&#039;&#039;&#039; code. We will run via command line using yambopy, although it will be instructive to have look at the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; input files later.&lt;br /&gt;
&lt;br /&gt;
We run in the same directory where the Yambo &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; is (remember than you can also virtually move it with a symbolic link).&lt;br /&gt;
&lt;br /&gt;
Type:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y&lt;br /&gt;
&lt;br /&gt;
to see the help for the calculation. Have a look at the various flags and their description.&lt;br /&gt;
For example, if we want to do a serial run of LetzElPhC for bands from &amp;lt;math&amp;gt;n_i&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;n_f&amp;lt;/math&amp;gt;, we should type:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph path/of/ph_input.in -b n_i n_f&lt;br /&gt;
&lt;br /&gt;
Here &amp;lt;math&amp;gt;n_i&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;n_f&amp;lt;/math&amp;gt; are integers representing the initial and final band indices. &#039;&#039;&#039;Please note&#039;&#039;&#039;: in this case, the band index starts from 1 and the the interval of bands read by the code is &amp;lt;math&amp;gt;[n_i,n_f]&amp;lt;/math&amp;gt; including the extrema of the interval.&lt;br /&gt;
&lt;br /&gt;
These should coincide with those used for the Bethe-Salpeter kernel, i.e. those specified in the &amp;lt;code&amp;gt;BSEBands&amp;lt;/code&amp;gt; variable of the BSE input file (this is not strictly necessary, but certainly efficient since these calculations use a lot of disk space). &lt;br /&gt;
&lt;br /&gt;
For our system, we want to do a parallel calculation with 4 qpools and 2 kpools. In addition, we want to explicitly specify the path of the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable and avoid automatically deleting the LetzElPhC data. So we type:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph path/of/dvscf/mos2.dvscf -b 25 28 -par 4 2 -lelphc path/to/lelphc_exe&lt;br /&gt;
&lt;br /&gt;
At the end, check your directory: you should find the &amp;lt;code&amp;gt;lelphc.in&amp;lt;/code&amp;gt; input file that was run, let&#039;s inspect it: &lt;br /&gt;
&lt;br /&gt;
 # LetzElPhC input for yambo generated by yambopy&lt;br /&gt;
 nqpool      = 2&lt;br /&gt;
 nkpool      = 4&lt;br /&gt;
 start_bnd   = 25&lt;br /&gt;
 end_bnd     = 28&lt;br /&gt;
 save_dir    = ./SAVE&lt;br /&gt;
 kernel      = dfpt&lt;br /&gt;
 ph_save_dir = dvscf/ph_save&lt;br /&gt;
 convention = yambo&lt;br /&gt;
&lt;br /&gt;
Notice the variable &amp;lt;code&amp;gt;convention=yambo&amp;lt;/code&amp;gt;: what does it mean? At variance with QE and many other codes, Yambo uses the &amp;quot;backward&amp;quot; momentum transfer convention for electronic scatterings. That is, an electronic transition goes from band &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; and momentum &amp;lt;math&amp;gt;k-q&amp;lt;/math&amp;gt; to band &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; and momentum &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;. In the &amp;quot;forward&amp;quot; momentum transfer convention (the more standard one), the transitions go from &amp;lt;math&amp;gt;nk&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;mk+q&amp;lt;/math&amp;gt;. Therefore, this variable ensures that the electron-phonon coupling matrix elements are computed as &amp;lt;math&amp;gt;\langle mk|dV|nk-q\rangle&amp;lt;/math&amp;gt;. This will have consequences also in the formulation of the &#039;&#039;exciton&#039;&#039;-phonon coupling matrix element.&lt;br /&gt;
&lt;br /&gt;
You will also find a &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; database that contains the computed electron-phonon matrix elements, in the output format of &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In addition, if you check the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; folder:&lt;br /&gt;
&lt;br /&gt;
 ls SAVE/ndb.elph_gkkp*&lt;br /&gt;
&lt;br /&gt;
you will see that yambopy has created the Yambo-compatible electron-phonon databases.&lt;br /&gt;
&lt;br /&gt;
If you want to run LetzElPhC directly, without using yambopy, you can refer to its [[https://gitlab.com/lumen-code/LetzElPhC/-/blob/main/docs/main.pdf?ref_type=heads|user guide]].&lt;br /&gt;
Keep in mind that in this case, in order to convert the database to the &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases of Yambo, you will then need a couple of lines of python using the Yambopy class &amp;lt;code&amp;gt;ConvertElectronPhononDB&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;yambopy/letzelph_interface/lelph2y.py&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t need the &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases -- e.g., because you are doing the exc-ph postprocessing with yambopy -- you can run &amp;lt;code&amp;gt;yambopy l2y ...&amp;lt;/code&amp;gt; with the &amp;lt;code&amp;gt;--no_gkkp&amp;lt;/code&amp;gt; option.&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t need the &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; databases -- e.g., because you are using &amp;lt;code&amp;gt;yambo_ph&amp;lt;/code&amp;gt; for the exc-ph part -- you can run &amp;lt;code&amp;gt;yambopy l2y ...&amp;lt;/code&amp;gt; with the &amp;lt;code&amp;gt;--no_lelphc_dbs&amp;lt;/code&amp;gt; option.&lt;br /&gt;
&lt;br /&gt;
== Step 7: Obtain the exciton-phonon coupling ==&lt;br /&gt;
&lt;br /&gt;
Now, we can finally access our basic building block for exciton-phonon physics. This could be done entirely in python (using &#039;&#039;&#039;Yambopy&#039;&#039;&#039;), or by running &#039;&#039;&#039;Yambo&#039;&#039;&#039;. &lt;br /&gt;
&lt;br /&gt;
* For the &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&#039;&#039;&#039;Yambo postprocessing&#039;&#039;&#039;&amp;lt;/span&amp;gt; case (running yambo inputs with the &amp;lt;code&amp;gt;yambo_ph&amp;lt;/code&amp;gt; executable), &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&#039;&#039;&#039;follow the alternative route to Steps 7-8 [[Exciton-phonon coupling and luminescence - Yambo postprocessing|at this link]]&#039;&#039;&#039;&amp;lt;/span&amp;gt;.&lt;br /&gt;
* For the &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&#039;&#039;&#039;Yambopy postprocessing&#039;&#039;&#039;&amp;lt;/span&amp;gt; case (using flexible python scripting), &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&#039;&#039;&#039;keep following Steps 7-8 on this page&#039;&#039;&#039;&amp;lt;/span&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Our objective is obtaining the following quantity: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\mathcal{G}^\mu_{\alpha\lambda}(0,q)=\sum_{vv^\prime c k} A^{\alpha, *}_{cv^\prime} (k, q) g_{vv^\prime}^\mu (k,q) A^{\lambda}_{cv}(k,0) - \sum_{cc^\prime vk} A^{\alpha, *}_{c^\prime v} (k+q, q) g_{c^\prime c}^\mu (k+q,q) A^{\lambda}_{cv}(k, 0)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here, &amp;lt;math&amp;gt;A^{\alpha}_{cv}(k,q)&amp;lt;/math&amp;gt; are the exciton coefficients extracted from the eigenvector of the two-particles Hamiltonian during the BSE calculation in step 5, while &amp;lt;math&amp;gt;g_{nm}^\mu (k,q)&amp;lt;/math&amp;gt; are the electron-phonon coupling matrix elements obtained in step 6. As you can see, the exciton &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; undergoes phonon-mediated scattering to state &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; via phonon mode &amp;lt;math&amp;gt;\mu&amp;lt;/math&amp;gt;. The scattering can happen for the hole (valence, &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt;) or for the electron (conduction, &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
NB: &lt;br /&gt;
&lt;br /&gt;
(1) This is written in the &amp;quot;backward&amp;quot; momentum transfer convention used by Yambo. The momentum dependence is different in the &amp;quot;forward&amp;quot; transfer convention. &lt;br /&gt;
&lt;br /&gt;
(2) For simplicity, this is written for zero initial exciton momentum. This means that one of the two states involved in the phonon-mediated scattering process will be in the optical limit (and possibly an optically generated exciton), while the other state can have any momentum: this momentum will be the same as the phonon one. This matrix element can be used to describe phonon-assisted absorption and emission spectra.&lt;br /&gt;
&lt;br /&gt;
In order to calculate this quantity using python, we need the &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; databases natively generated by the &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; code, as well as the BSE databases &amp;lt;code&amp;gt;ndb.BS_diago_Q*&amp;lt;/code&amp;gt; containing the information on exciton wavefunctions and energies.&lt;br /&gt;
&lt;br /&gt;
Next, we write a python user script importing the yambopy exciton-phonon tools. You can find a version of this script in &amp;lt;code&amp;gt;yambopy/tutorials/exciton-phonon/calculate_excph.py&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
 import numpy as np &lt;br /&gt;
 from yambopy import YamboLatticeDB,YamboWFDB,LetzElphElectronPhononDB &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;#Specific Yambopy dbs loading classes&amp;lt;/span&amp;gt;&lt;br /&gt;
 from yambopy.exciton_phonon.excph_matrix_elements import exciton_phonon_matelem &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;#Specific exc-ph functions&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 path = &#039;1L_MoS2&#039;&lt;br /&gt;
 bands_range=[24,28] &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# 2 valence bands, 2 conduction bands&amp;lt;/span&amp;gt;&lt;br /&gt;
 nexc = 12 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# number of excitonic states&amp;lt;/span&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 bsepath    = f&#039;{path}/bse-allq_full&#039; &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Path to BSE calculation (Lin=Lout)&amp;lt;/span&amp;gt;&lt;br /&gt;
 savepath   = f&#039;{path}/SAVE&#039;     &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Yambo SAVE&amp;lt;/span&amp;gt;&lt;br /&gt;
 ndb_elph   = f&#039;{path}/ndb.elph&#039; &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# LetzElPhC electron-phonon database (any convention)&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Read lattice&amp;lt;/span&amp;gt;&lt;br /&gt;
 lattice = YamboLatticeDB.from_db_file(filename=f&#039;{savepath}/ns.db1&#039;)&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Read electron-phonon&amp;lt;/span&amp;gt;&lt;br /&gt;
 elph    = LetzElphElectronPhononDB(ndb_elph,read_all=False)&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Read wave functions&amp;lt;/span&amp;gt;&lt;br /&gt;
 wfcs    = YamboWFDB(filename=&#039;ns.wf&#039;,save=savepath,latdb=lattice,bands_range=bands_range)&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Calculate exciton-phonon matrix elements&amp;lt;/span&amp;gt;&lt;br /&gt;
 exph = exciton_phonon_matelem(lattice,elph,wfcs,BSE_dir=bsepath,nexc_in=nexc,nexc_out=nexc,dmat_mode=&#039;save&#039;,exph_file=&#039;MoS2_Ex-ph.npy&#039;)&lt;br /&gt;
&lt;br /&gt;
In this script, we can select the number exciton states &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; with &amp;lt;code&amp;gt;nexc&amp;lt;/code&amp;gt;, the single-particle bands range with &amp;lt;code&amp;gt;bands_range&amp;lt;/code&amp;gt;. &#039;&#039;&#039;Please note&#039;&#039;&#039;: in this case, the band index starts from 0 (python indexing) and the the interval of bands read by the code is &amp;lt;math&amp;gt;[n_i,n_f)&amp;lt;/math&amp;gt;, therefore the last value (28 in the example) is excluded. That is, in the example we are selecting the 25th, 26th, 27th and 28th bands. Those bands have to be present in both the electron-phonon and BSE calculations. &lt;br /&gt;
&lt;br /&gt;
Here we calculate the couplings of the first twelve states at each finite-&amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; point including &amp;lt;math&amp;gt;q=0&amp;lt;/math&amp;gt;. We also include all the nine phonon modes of monolayer MoS2. We also need access to the Yambo &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory in order to read the electronic wavefunctions: they are used to compute the electronic representation matrices (&amp;lt;code&amp;gt;dmat&amp;lt;/code&amp;gt; in the code). The argument &amp;lt;code&amp;gt;dmat_mode&amp;lt;/code&amp;gt; can be set to &amp;lt;code&amp;gt;&#039;load&#039;&amp;lt;/code&amp;gt; for subsequent calculations.&lt;br /&gt;
&lt;br /&gt;
When we are satisfied with the input, we run the code:&lt;br /&gt;
&lt;br /&gt;
 python calculate_excph.py&lt;br /&gt;
&lt;br /&gt;
If you check the output, you should find the &amp;lt;code&amp;gt;MoS2_Ex-ph.npy&amp;lt;/code&amp;gt; binary file in the directory where you ran.&lt;br /&gt;
&lt;br /&gt;
=== Analysis of the couplings ===&lt;br /&gt;
&lt;br /&gt;
It is a good idea to have a look at what we computed up to now in order to make sure nothing has gone wrong. &lt;br /&gt;
&lt;br /&gt;
It is not easy to know what to expect (apart from symmetry and gauge compliance of the matrix elements), but one can work out the exciton-phonon selection rules in advance, check that the magnitude is reasonable, etc.&lt;br /&gt;
&lt;br /&gt;
It is also not easy to meaningfully plot this quantity. We have to make sure that we are not breaking degenerate states, otherwise the plots will not be invariant. &lt;br /&gt;
&lt;br /&gt;
First of all, we have to know our system: in monolayer MoS&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;, the first four excitons are all doubly degenerate. The first exciton responsible for a bright peak in the absorption spectrum (the &#039;&#039;&#039;A&#039;&#039;&#039; peak), is the second state, corresponding to state indices &amp;lt;code&amp;gt;(3,4)&amp;lt;/code&amp;gt; in fortran indexing or &amp;lt;code&amp;gt;(2,3)&amp;lt;/code&amp;gt; in python indexing. &lt;br /&gt;
&lt;br /&gt;
All these information can be obtained by analyzing the BSE results (this stuff is explained in the BSE tutorials) and by knowledge of the system or class of systems from the literature.&lt;br /&gt;
&lt;br /&gt;
Thus, a good quantity to plot may be the norm of the matrix elements, summed over the degenerate subspace of exciton A, for a certain number of scattered final states mediated by certain phonon modes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;F_A(q)= \sqrt{ \sum_{\alpha \in A,\lambda,\mu} |\mathcal{G}_{\alpha\lambda}^\mu (0,q)|^2 }&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In order to do this, we create a python script &amp;lt;code&amp;gt;analyse_excph.py&amp;lt;/code&amp;gt; in which we first load the excph dabatases. &lt;br /&gt;
You can find a version of this script in the yambopy directory, in &amp;lt;code&amp;gt;tutorials/exciton-phonon&amp;lt;/code&amp;gt;. &lt;br /&gt;
First, we select the exciton and phonon states to be included in &amp;lt;code&amp;gt;F_A&amp;lt;/code&amp;gt;, together with the path of databases and plot details:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Exciton &amp;quot;in&amp;quot; states&amp;lt;/span&amp;gt;&lt;br /&gt;
 exc_in  = [2,3]  &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# First bright peak (A: 2,3 -- B: 6,7)&amp;lt;/span&amp;gt;&lt;br /&gt;
 exc_out = [0,1,2,3] &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# first 4 states (dispersion of dark triplet state and A)&amp;lt;/span&amp;gt;&lt;br /&gt;
 ph_in  = &#039;all&#039;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Paths of databases&amp;lt;/span&amp;gt;&lt;br /&gt;
 ns_db1 =f&#039;{path}/SAVE/ns.db1&#039;&lt;br /&gt;
 ns_ypy = &#039;MoS2_Ex-ph.npy&#039;&lt;br /&gt;
 &lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
Then, we load the data:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Read lattice and k-space info&amp;lt;/span&amp;gt;&lt;br /&gt;
 ylat = YamboLatticeDB.from_db_file(filename=ns_db1)&lt;br /&gt;
 print(ylat)&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Load exc-ph database&amp;lt;/span&amp;gt;&lt;br /&gt;
 X_py = np.load(ns_ypy)&lt;br /&gt;
 G_squared = np.abs(X_py)**2.&lt;br /&gt;
&lt;br /&gt;
The quantity &amp;lt;math&amp;gt;F_A(q)&amp;lt;/math&amp;gt; is obtained from a dedicated function as:&lt;br /&gt;
 &lt;br /&gt;
 if exc_in  == &#039;all&#039;: exc_in  = range(G_squared.shape[2])&lt;br /&gt;
 if exc_out == &#039;all&#039;: exc_out = range(G_squared.shape[3])&lt;br /&gt;
 if ph_in   == &#039;all&#039;: ph_in   = range(G_squared.shape[1])&lt;br /&gt;
 &lt;br /&gt;
 G_squared = G_squared[:, ph_in, :, :].sum(axis=(1))&lt;br /&gt;
 G_squared = G_squared[:, exc_in, :].sum(axis=(1))&lt;br /&gt;
 G_squared = G_squared[:, exc_out].sum(axis=(1))&lt;br /&gt;
 &lt;br /&gt;
 F_q = np.sqrt( G_squared )*ha2ev &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Switch from Ha to eV&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And finally, we have to make a plotting function. For this tutorial we will use a custom scatterplot employing some of the plotting tools provided by yambopy (but you can do whatever you want).&lt;br /&gt;
&lt;br /&gt;
 plot_2D_excph(qgrid,G2_to_plot,rlat=ylat.rlat,plt_cbar=True,\&lt;br /&gt;
               marker=&#039;H&#039;,s=700,cmap=&#039;magma&#039;)&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
You can get more experience on using Yambopy for these kinds of visualization by following the [https://wiki.yambo-code.eu/wiki/index.php?title=First_steps_in_Yambopy Yambopy tutorials]. In fact, remember that these scripts and all the other Yambopy tutorial scripts are just suggestions, not source code written in stone: if you know &amp;lt;code&amp;gt;numpy&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;matplotlib&amp;lt;/code&amp;gt; you can do your own analysis and your own plots, you just need to import the required Yambopy modules to load the data.&lt;br /&gt;
&lt;br /&gt;
In our case, the resulting plot is the following.&lt;br /&gt;
&lt;br /&gt;
[[File:1L MoS2 MoS2 Ex-ph.png|500px|center]]&lt;br /&gt;
&lt;br /&gt;
This can be checked against Fig. 2(d) of reference &amp;lt;ref name=&amp;quot;chan2023&amp;quot; /&amp;gt;, although you have to keep in mind that our results are badly undersampled in terms of the reciprocal-space grid, as can be easily seen, and the quantity plotted is not exactly the same. However, the main features are already there since they are dictated mostly by crystal symmetries.&lt;br /&gt;
&lt;br /&gt;
Now that we have the exciton-phonon matrix elements, we can use them to build several kinds of observables. Below, we give an example related to phonon-assisted luminescence, but we may update this tutorial in the future to include more cases.&lt;br /&gt;
&lt;br /&gt;
== Step 8: Compute phonon-assisted luminescence ==&lt;br /&gt;
&lt;br /&gt;
[[File:Luminescence scheme.png|250px|right]]&lt;br /&gt;
&lt;br /&gt;
We want to compute the experimental optical signature due to the phonon-assisted recombination of an exciton (as sketched in the figure).&lt;br /&gt;
&lt;br /&gt;
The signal from the phonon replicas can be modeled as a second-order scattering process involving one phonon and one photon:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;I^{Sat}(\omega)=\frac{1}{ N_q} \frac{1}{3} \sum_{\epsilon s\beta \mu q} \frac{1}{E_{\beta q}-s\Omega_{\mu q}}\left|\sum_\alpha\frac{ D^{\epsilon}_\alpha \mathcal{G}_{\beta \alpha}^{\mu,*}(q)}{E_\alpha -E_{\beta q} +s\Omega_{\mu q}+\mathrm{i}\eta}\right|^2 \frac{N^{exc}_{\beta q}(T_{exc})[\frac{1+s}{2}+n_{\mu q}(T)]}{\omega -[E_{\beta q}-s\Omega_{\mu q}]+\mathrm{i}\eta}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this equation, the oscillator strength of the peak is given by the exciton-phonon coupling matrix elements &amp;lt;math&amp;gt;\mathcal{G}&amp;lt;/math&amp;gt; multiplied by the exciton dipoles &amp;lt;math&amp;gt;D&amp;lt;/math&amp;gt; (they are called &amp;quot;residuals&amp;quot; in Yambo). Here &amp;lt;math&amp;gt;E_\lambda&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;E_{\alpha q}&amp;lt;/math&amp;gt; are the energies of the optical and finite-momentum excitons, respectively, while &amp;lt;math&amp;gt;\Omega_{\mu q}&amp;lt;/math&amp;gt; are the phonon energies. &lt;br /&gt;
&lt;br /&gt;
Here, &amp;lt;math&amp;gt;n_{\mu q}(T)&amp;lt;/math&amp;gt; is the temperature-dependent phonon Bose-Einstein occupation function. As it can be seen, &amp;lt;math&amp;gt;s=1&amp;lt;/math&amp;gt; corresponds to processes of phonon &#039;&#039;emission&#039;&#039; (&amp;lt;math&amp;gt;\propto n(T)+1&amp;lt;/math&amp;gt;), while &amp;lt;math&amp;gt;s=-1&amp;lt;/math&amp;gt; corresponds to processes of phonon &#039;&#039;absorption&#039;&#039; (&amp;lt;math&amp;gt;\propto n(T)&amp;lt;/math&amp;gt;). Therefore, &amp;lt;math&amp;gt;I^{Sat}_{PL}(\omega;T)&amp;lt;/math&amp;gt; describes &#039;&#039;light&#039;&#039; emission by recombining excitons mediated by either &#039;&#039;phonon&#039;&#039; absorption or emission. &lt;br /&gt;
&lt;br /&gt;
The quantity &amp;lt;math&amp;gt; N_{\alpha q}(T_{exc})&amp;lt;/math&amp;gt; is the exciton occupation function. Luminescence is technically an out-of-equilibrium process, but we can assume that for very low density of excitations and in steady-state conditions, the exciton population can be approximately described by an equilibrium distribution evaluated at an effective temperature. Here, we use the Boltzmann distribution. Experimentally, &amp;lt;math&amp;gt;T_{exc}&amp;lt;/math&amp;gt; tends to coincide with the lattice temperature &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt; more or less above 100 K, while at very low temperature (&amp;lt; 10 K), &amp;lt;math&amp;gt;T_{exc}&amp;lt;/math&amp;gt; may vary between 10-50 K. It goes without saying that this needs to carefully be checked in your realistic calculations.&lt;br /&gt;
&lt;br /&gt;
Finally, the spectrum is averaged over the polarization directions of the emitted photons (&amp;lt;math&amp;gt;\epsilon=x,y,z&amp;lt;/math&amp;gt; representing the respective dipole components).&lt;br /&gt;
&lt;br /&gt;
=== Running the jobs ===&lt;br /&gt;
&lt;br /&gt;
In order to study luminescence in a paradigmatic system, we switch to bulk hexagonal boron nitride and we repeat the workflow. As you can easily see, one can think about automatizing the execution of all these calculations via scripting or more advanced tools. However, in the case of very large simulations (memory-limited or disk-space limited) or for systems whose electronic and lattice properties are fragile with respect to tiny calculation details, one must be very careful and run many basic tests.&lt;br /&gt;
&lt;br /&gt;
Fortunately, we are running a fast underconverged example. We use LDA pseudopotentials from the pseudo-dojo library and the following are the calculations steps.&lt;br /&gt;
&lt;br /&gt;
1. Input &amp;lt;code&amp;gt;hbn.scf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 &amp;amp;control&lt;br /&gt;
     calculation=&#039;scf&#039;,&lt;br /&gt;
     prefix=&#039;hBN&#039;,&lt;br /&gt;
     restart_mode=&#039;from_scratch&#039;&lt;br /&gt;
     pseudo_dir = &#039;$PSEUDO_DIR&#039;,&lt;br /&gt;
     outdir = &#039;./tmp&#039;&lt;br /&gt;
     verbosity = &#039;high&#039;&lt;br /&gt;
     wf_collect=.true.&lt;br /&gt;
 /&lt;br /&gt;
 &amp;amp;system&lt;br /&gt;
     ibrav = 4,&lt;br /&gt;
     celldm(1) = 4.703675849&lt;br /&gt;
     celldm(3) = 2.603711434&lt;br /&gt;
     nat= 4,&lt;br /&gt;
     ntyp= 2,&lt;br /&gt;
     force_symmorphic=.true.&lt;br /&gt;
     ecutwfc = 100,&lt;br /&gt;
 /&lt;br /&gt;
 &amp;amp;electrons&lt;br /&gt;
   diago_david_ndim = 2&lt;br /&gt;
   diago_full_acc=.true.&lt;br /&gt;
   diago_thr_init=5.0e-6&lt;br /&gt;
   mixing_mode = &#039;plain&#039;&lt;br /&gt;
   mixing_beta = 0.7&lt;br /&gt;
   conv_thr =  1.0d-16&lt;br /&gt;
 /&lt;br /&gt;
 ATOMIC_SPECIES&lt;br /&gt;
  B 10.81100  B_LDA_dojo.UPF&lt;br /&gt;
  N 14.00674  N_LDA_dojo.UPF&lt;br /&gt;
 ATOMIC_POSITIONS {crystal}&lt;br /&gt;
 N             0.6666666670        0.3333333330        -0.250000000000&lt;br /&gt;
 B             0.3333333330        0.6666666670        -0.250000000000&lt;br /&gt;
 B             0.6666666670        0.3333333330        0.25000000000&lt;br /&gt;
 N             0.3333333330        0.6666666670        0.25000000000&lt;br /&gt;
 K_POINTS {automatic}&lt;br /&gt;
 6 6 2 0 0 0&lt;br /&gt;
&lt;br /&gt;
 mpirun -np 4 pw.x -inp hbn.scf &amp;gt; scf.out&lt;br /&gt;
&lt;br /&gt;
2. Input &amp;lt;code&amp;gt;hbn.nscf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 &amp;amp;control&lt;br /&gt;
     calculation=&#039;nscf&#039;,&lt;br /&gt;
     prefix=&#039;hBN&#039;,&lt;br /&gt;
     restart_mode=&#039;from_scratch&#039;&lt;br /&gt;
     pseudo_dir = &#039;$PSEUDO_DIR&#039;&lt;br /&gt;
     outdir = &#039;./&#039;&lt;br /&gt;
     verbosity = &#039;high&#039;&lt;br /&gt;
     wf_collect=.true.&lt;br /&gt;
 /&lt;br /&gt;
 &amp;amp;system&lt;br /&gt;
     ibrav = 4,&lt;br /&gt;
     celldm(1) = 4.703675849&lt;br /&gt;
     celldm(3) = 2.603711434&lt;br /&gt;
     nat= 4,&lt;br /&gt;
     ntyp= 2,&lt;br /&gt;
     force_symmorphic=.true.&lt;br /&gt;
     ecutwfc = 100,&lt;br /&gt;
 	nbnd = 120&lt;br /&gt;
 /&lt;br /&gt;
 &amp;amp;electrons&lt;br /&gt;
   diago_david_ndim = 2&lt;br /&gt;
   diago_full_acc=.true.&lt;br /&gt;
   diago_thr_init=5.0e-6&lt;br /&gt;
   mixing_mode = &#039;plain&#039;&lt;br /&gt;
   mixing_beta = 0.7&lt;br /&gt;
   conv_thr =  1.0d-16&lt;br /&gt;
 /&lt;br /&gt;
 ATOMIC_SPECIES&lt;br /&gt;
  B 10.81100  B_LDA_dojo.UPF&lt;br /&gt;
  N 14.00674  N_LDA_dojo.UPF&lt;br /&gt;
 ATOMIC_POSITIONS {crystal}&lt;br /&gt;
 N             0.6666666670        0.3333333330        -0.250000000000&lt;br /&gt;
 B             0.3333333330        0.6666666670        -0.250000000000&lt;br /&gt;
 B             0.6666666670        0.3333333330        0.25000000000&lt;br /&gt;
 N             0.3333333330        0.6666666670        0.25000000000&lt;br /&gt;
 K_POINTS {automatic}&lt;br /&gt;
 6 6 2 0 0 0&lt;br /&gt;
&lt;br /&gt;
 mpirun -np 4 pw.x -inp hbn.nscf &amp;gt; nscf.out&lt;br /&gt;
&lt;br /&gt;
3. Input &amp;lt;code&amp;gt;hbn.dvscf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 hbn_dvscf&lt;br /&gt;
 &amp;amp;inputph&lt;br /&gt;
   tr2_ph=1.0d-12,&lt;br /&gt;
   verbosity=&#039;high&#039;&lt;br /&gt;
   prefix=&#039;hBN&#039;,&lt;br /&gt;
   fildvscf = &#039;hBN-dvscf&#039;,&lt;br /&gt;
   electron_phonon = &#039;dvscf&#039;,&lt;br /&gt;
   fildyn=&#039;hBN.dyn&#039;,&lt;br /&gt;
   epsil=.false.,&lt;br /&gt;
   ldisp=.true.,&lt;br /&gt;
   recover=.true.,&lt;br /&gt;
   nq1=6,&lt;br /&gt;
   nq2=6,&lt;br /&gt;
   nq3=2&lt;br /&gt;
 /&lt;br /&gt;
&lt;br /&gt;
 nohup mpirun -np 8 pw.x -inp hbn.dvscf &amp;gt; dvscf.out &amp;amp;&lt;br /&gt;
&lt;br /&gt;
4. Input &amp;lt;code&amp;gt;bse.in&amp;lt;/code&amp;gt; (we include 2 valence and 2 conduction bands):&lt;br /&gt;
&lt;br /&gt;
 optics                           # [R] Linear Response optical properties&lt;br /&gt;
 bss                              # [R] BSE solver&lt;br /&gt;
 bse                              # [R][BSE] Bethe Salpeter Equation.&lt;br /&gt;
 dipoles                          # [R] Oscillator strenghts (or dipoles)&lt;br /&gt;
 em1s&lt;br /&gt;
 DIP_CPU= &amp;quot;1 8 1&amp;quot;                      # [PARALLEL] CPUs for each role&lt;br /&gt;
 DIP_ROLEs= &amp;quot;k c v&amp;quot;                    # [PARALLEL] CPUs roles (k,c,v)&lt;br /&gt;
 DIP_Threads=0                    # [OPENMP/X] Number of threads for dipoles&lt;br /&gt;
 X_and_IO_CPU= &amp;quot;1 1 1 8 1&amp;quot;                 # [PARALLEL] CPUs for each role&lt;br /&gt;
 X_and_IO_ROLEs= &amp;quot;q g k c v&amp;quot;               # [PARALLEL] CPUs roles (q,g,k,c,v)&lt;br /&gt;
 X_and_IO_nCPU_LinAlg_INV=-1      # [PARALLEL] CPUs for Linear Algebra (if -1 it is automatically set)&lt;br /&gt;
 X_Threads=0                      # [OPENMP/X] Number of threads for response functions&lt;br /&gt;
 BS_CPU= &amp;quot;8 1 1&amp;quot;                       # [PARALLEL] CPUs for each role&lt;br /&gt;
 BS_ROLEs= &amp;quot;k eh t&amp;quot;                     # [PARALLEL] CPUs roles (k,eh,t)&lt;br /&gt;
 BS_nCPU_LinAlg_INV=-1            # [PARALLEL] CPUs for Linear Algebra (if -1 it is automatically set)&lt;br /&gt;
 BS_nCPU_LinAlg_DIAGO=-1          # [PARALLEL] CPUs for Linear Algebra (if -1 it is automatically set)&lt;br /&gt;
 X_Threads=0                      # [OPENMP/X] Number of threads for response functions&lt;br /&gt;
 K_Threads=0                      # [OPENMP/BSK] Number of threads for response functions&lt;br /&gt;
 % QpntsRXs&lt;br /&gt;
    1 | 14 |                         # [Xs] Transferred momenta&lt;br /&gt;
 %&lt;br /&gt;
 % BndsRnXs&lt;br /&gt;
    1 | 120 |                         # [Xs] Polarization function bands&lt;br /&gt;
 %&lt;br /&gt;
 NGsBlkXs= 10                Ry    # [Xs] Response block size&lt;br /&gt;
 % LongDrXs&lt;br /&gt;
  1.000000 | 1.000000 | 1.000000 |        # [Xs] [cc] Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 BSEmod= &amp;quot;resonant&amp;quot;               # [BSE] resonant/retarded/coupling&lt;br /&gt;
 BSKmod= &amp;quot;SEX&amp;quot;                    # [BSE] IP/Hartree/HF/ALDA/SEX/BSfxc&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;Lkind= &amp;quot;Lfull&amp;quot;                    # [BSE] Lbar (default) / full&amp;lt;/span&amp;gt;&lt;br /&gt;
 BSSmod= &amp;quot;d&amp;quot;                      # [BSS] (h)aydock/(d)iagonalization/(s)lepc/(i)nversion/(t)ddft`&lt;br /&gt;
 % DipBands&lt;br /&gt;
    1 | 120 |                         # [DIP] Bands range for dipoles&lt;br /&gt;
 %&lt;br /&gt;
 DipApproach= &amp;quot;G-space v&amp;quot;         # [DIP] [G-space v/R-space x/Covariant/Shifted grids]&lt;br /&gt;
 DipComputed= &amp;quot;R V P&amp;quot;             # [DIP] [default R P V; extra P2 Spin Orb]&lt;br /&gt;
 BSENGexx= 30000            Ry    # [BSK] Exchange components&lt;br /&gt;
 #ALLGexx                       # [BSS] Force the use use all RL vectors for the exchange part&lt;br /&gt;
 BSENGBlk=  9000            Ry    # [BSK] Screened interaction block size [if -1 uses all the G-vectors of W(q,G,Gp)]&lt;br /&gt;
 % KfnQP_E&lt;br /&gt;
  1.25997 | 1.08816 | 1.12683 |        # [EXTQP BSK BSS] E parameters  (c/v) eV|adim|adim&lt;br /&gt;
 %&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;% BSEQptR&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 1 | 14 |                     # [BSK] Transferred momenta range&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;%&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;% BSEBands&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;   7 | 10 |                         # [BSK] Bands range&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;%&amp;lt;/span&amp;gt;&lt;br /&gt;
 % BEnRange&lt;br /&gt;
   0.50000 | 8.00000 |         eV    # [BSS] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 % BDmRange&lt;br /&gt;
  0.050000 | 0.050000 |         eV    # [BSS] Damping range&lt;br /&gt;
 %&lt;br /&gt;
 BEnSteps= 1000                    # [BSS] Energy steps&lt;br /&gt;
 % BLongDir&lt;br /&gt;
  1.000000 | 1.000000 | 0.000000 |        # [BSS] [cc] Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 WRbsWF                        # [BSS] Write to disk excitonic the WFs&lt;br /&gt;
&lt;br /&gt;
 nohup mpirun -np 8 yambo -F bse.in -J bse_Lfull -C bse_Lfull &amp;amp;&lt;br /&gt;
&lt;br /&gt;
Importantly, since we want to describe the phonon-assisted recombination process of an *optical* exciton (i.e., emitting a transverse photon), this time we also run an additional calculation at `Q=0` omitting the nonanalytic long-range Coulomb exchange. Make a second input &amp;lt;code&amp;gt;bse_Lbar.in&amp;lt;/code&amp;gt; with the following changes: &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;Lkind= &amp;quot;Lbar&amp;quot;                    # [BSE] Lbar (default) / full&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;% BSEQptR&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 1 | 1 |                     # [BSK] Transferred momenta range&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;%&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4b. So now we make a second BSE run in a different directory specified by &amp;lt;code&amp;gt;-J&amp;lt;/code&amp;gt;. Here, we also pass to yambo the directory of the previous run as it includes the important screening databases &amp;lt;code&amp;gt;ndb.em1s*&amp;lt;/code&amp;gt; that we do not want to recompute from scratch.&lt;br /&gt;
 &lt;br /&gt;
 mpirun -np 8 yambo -F bse_Lbar.in -J bse_Lbar,bse_Lfull -C bse_Lbar&lt;br /&gt;
&lt;br /&gt;
5. Now we run &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; (with or without yambopy: in the latter case remember the option &amp;lt;code&amp;gt;-D&amp;lt;/code&amp;gt;) to get the el-ph matrix elements, particularly the &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; databases:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph path/of/dvscf/hbn.dvscf -b 7 10 -par 4 2 -D&lt;br /&gt;
&lt;br /&gt;
=== Luminescence calculation ===&lt;br /&gt;
&lt;br /&gt;
6. And finally we calculate exciton-phonon matrix elements and the luminescence spectrum in one go using a python script importing the Yambopy exciton-phonon tools: in order to do this, we need to take a look at all the necessary input variables for the formula written above.&lt;br /&gt;
&lt;br /&gt;
We can start from the script &amp;lt;code&amp;gt;luminescence.py&amp;lt;/code&amp;gt; available in &amp;lt;code&amp;gt;tutorials/exciton-phonon&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
 import numpy as np&lt;br /&gt;
 import matplotlib.pyplot as plt&lt;br /&gt;
 from yambopy.exciton_phonon.excph_luminescence import exc_ph_luminescence&lt;br /&gt;
 from yambopy.exciton_phonon.excph_input_data import exc_ph_get_inputs&lt;br /&gt;
&lt;br /&gt;
We import the necessary tools...&lt;br /&gt;
&lt;br /&gt;
 path = &#039;3D_hBN&#039;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Path to BSE calculation (Lout--&amp;gt; response is Lfull)&amp;lt;/span&amp;gt;&lt;br /&gt;
 bsepath =  f&#039;{path}/bse_Lfull&#039; &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# ndb.BS_diago_Q* databases are needed&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Path to BSE calculation for optically active exciton (Lin --&amp;gt; response is Lbar)&amp;lt;/span&amp;gt;&lt;br /&gt;
 bseBARpath =  f&#039;{path}/bse_Lbar&#039;  &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# ndb.BS_diago_Q1 database is needed&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Path to electron-phonon calculation&amp;lt;/span&amp;gt;&lt;br /&gt;
 elphpath = path &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# ndb.elph is needed&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Path to unprojected dipoles matrix elements (optional)&amp;lt;/span&amp;gt;&lt;br /&gt;
 dipolespath = bsepath &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# ndb.dipoles is needed (optional)&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Path to lattice and k-space info&amp;lt;/span&amp;gt;&lt;br /&gt;
 savepath = f&#039;{path}/SAVE&#039; &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# ns.db1 database is needed&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
... and we specify the paths to the necessary databases. Note that, if we want to perform polarization averaging, we have to recompute the excitonic dipoles in python as seen here.&lt;br /&gt;
&lt;br /&gt;
What about &amp;lt;code&amp;gt;bseBARpath&amp;lt;/code&amp;gt;? This variable points to the directory where the databases for the optical (zero-momentum) excitons &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; (which may be computed with &amp;lt;code&amp;gt;Lkind=&#039;Lbar&#039;&amp;lt;/code&amp;gt;) is located, which can be different from the directory with the full indirect exciton dispersion &amp;lt;math&amp;gt;\beta&amp;lt;/math&amp;gt; (usually computed with &amp;lt;code&amp;gt;Lkind=&#039;Lfull&#039;&amp;lt;/code&amp;gt;, however &amp;lt;code&amp;gt;Lkind=&#039;Ltilde&#039;&amp;lt;/code&amp;gt; can also be used if one is interested in &amp;quot;irreducible&amp;quot; excitons). This makes it possible to compute the coupling between different exciton kinds.&lt;br /&gt;
&lt;br /&gt;
 bands_range=[6,10] &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# 2 valence, 2 conduction bands&amp;lt;/span&amp;gt;&lt;br /&gt;
 phonons_range=[0,12] &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# All phonons&amp;lt;/span&amp;gt;&lt;br /&gt;
 nexc_out = 12 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# 12 excitonic states at each momentum (Lout)&amp;lt;/span&amp;gt;&lt;br /&gt;
 nexc_in  = 12 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# 12 excitonic states at Q=0 (Lin)&amp;lt;/span&amp;gt;&lt;br /&gt;
 T_ph  = 10 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Lattice temperature&amp;lt;/span&amp;gt;&lt;br /&gt;
 T_exc = 10 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Effective excitonic temperature&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 emin=4.4      &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Energy range and plot details (in eV)&amp;lt;/span&amp;gt;&lt;br /&gt;
 emax=4.7&lt;br /&gt;
 estep=0.0002&lt;br /&gt;
 broad = 0.005 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Broadening parameter for peak width (in eV)&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next, we specify the parameters for the calculation. We include valence bands from 7 to 10 (6 to 9 in python index) and the contribution of all 12 phonon modes. We consider 12 excitonic states for the coupling matrix elements.&lt;br /&gt;
&lt;br /&gt;
Here &amp;lt;code&amp;gt;T_ph&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;T_exc&amp;lt;/code&amp;gt; are the lattice and excitonic temperatures, respectively.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# We calculate and load all the inputs:&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# * Exciton-phonon matrix elements&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# * Excitonic dipole matrix elements&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# * Exciton energies&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# * Phonon energies&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# * We specify bse_path2=bseBARpath meaning we use Lbar calculation for Q=0 excitons&amp;lt;/span&amp;gt;&lt;br /&gt;
 input_data = exc_ph_get_inputs(savepath,elphpath,bsepath,\&lt;br /&gt;
                                bse_path2=bseBARpath,dipoles_path=dipolespath,\&lt;br /&gt;
                                nexc_in=12,nexc_out=12,\&lt;br /&gt;
                                bands_range=[6,10],phonons_range=[0,12])&lt;br /&gt;
&lt;br /&gt;
 ph_energies, exc_energies, exc_energies_in, G, exc_dipoles = input_data&lt;br /&gt;
&lt;br /&gt;
The function &amp;lt;code&amp;gt;exc_ph_get_inputs&amp;lt;/code&amp;gt; gives us all the input data for luminescence in the correct format: phonon energies, exciton energies, optical exciton energies (if needed), exciton-phonon matrix elements (calculated on the fly and printed to file), unprojected exciton dipoles (optional, calculated on the fly and printed to file).&lt;br /&gt;
The exc-ph matrix element calculation is just a wrapper of the same tools that we have tested in the above section on MoS2.&lt;br /&gt;
&lt;br /&gt;
Finally, there is the calculation of the luminescence spectrum via the function &amp;lt;code&amp;gt;exc_ph_luminescence&amp;lt;/code&amp;gt;:&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# We calculate the luminescence spectrum including the input data from before&amp;lt;/span&amp;gt;&lt;br /&gt;
 w,PL = exc_ph_luminescence(T_ph,ph_energies,exc_energies,exc_dipoles,G,\&lt;br /&gt;
                            exc_energies_in=exc_energies_in,exc_temp=T_exc,\&lt;br /&gt;
                            nexc_out=nexc_out,nexc_in=nexc_in,emin=emin,emax=emax,\&lt;br /&gt;
                            estep=estep,broad=broad)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you want to print the luminescence data for later plotting, you can also add the following line to the script:&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Save to file&amp;lt;/span&amp;gt;&lt;br /&gt;
 data = np.column_stack((w, PL))&lt;br /&gt;
 np.savetxt(&amp;quot;hBN_luminescence_12x12x1.dat&amp;quot;, data, fmt=&amp;quot;%.8f&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
It is now time to run the whole script:&lt;br /&gt;
&lt;br /&gt;
 python luminescence.py&lt;br /&gt;
 &lt;br /&gt;
NB: By using Yambopy for Step 6, we have limited the use of the Yambo code to just step 4 in the entire workflow. This option is more flexible, as it allows for a greater degree of control by the user. On the other hand the Yambo postprocessing route features a Yambo-style input that doesn&#039;t require python knowledge and the calculation is currently faster in fortran. However, the luminescence expression computed in Yambo is a slightly different than this one: it is more approximated in the description of the satellite oscillator strengths, but it explicitly includes the renormalization of the direct exciton peak. You can check the differences [[Exciton-phonon coupling and luminescence - Yambo postprocessing|here]].&lt;br /&gt;
&lt;br /&gt;
=== Results ===&lt;br /&gt;
We can plot the results of the step 6 calculation. If we do it in the same script we can add something like this:&lt;br /&gt;
 fig = plt.figure()&lt;br /&gt;
 ax = fig.add_subplot(1,1,1)&lt;br /&gt;
 ax.set_xlim(emin,emax)&lt;br /&gt;
 ax.set_ylim(0,np.max(PL)*1.1)&lt;br /&gt;
 ax.get_yaxis().set_visible(False)&lt;br /&gt;
 &lt;br /&gt;
 ax.plot(w, PL, &#039;-&#039;,c=&#039;red&#039;, label=&amp;quot;AA&#039; hBN luminescence&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
 plt.legend()&lt;br /&gt;
 plt.savefig(&#039;hBN_luminescence.png&#039;)&lt;br /&gt;
 plt.show()&lt;br /&gt;
&lt;br /&gt;
[[File:HBN luminescence satellites.png|500px|center]]&lt;br /&gt;
&lt;br /&gt;
Here, the signal corresponds to a finite-momentum exciton that recombines with the help of several different phonon modes, both optical and acoustic. Each phonon mode whose coupling with the exciton is allowed can generate a peak, and the energy shifts of these peaks with respect to the initial exciton energy correspond to the phonon energies. This result is underconverged, but the main features are all there. In the plot, we show a more converged example using a 12x12x4 grid (all the other parameters being equal). These plots can be compared with Fig. 4(a) of reference &amp;lt;ref name=&amp;quot;zanfrognini2023&amp;quot; /&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;toyozawa2003&amp;quot; &amp;gt;Toyozawa, Yutaka, and Chris Oxlade, &#039;&#039;Optical processes in solids&#039;&#039;, [https://m.booksee.org/book/1121964?force_lang=en Cambridge University Press, (2003)]. &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;lechifflart2023&#039;&amp;gt;P. Lechifflart, F. Paleari, D. Sangalli, C. Attaccalite, &#039;&#039;First-principles study of luminescence in hexagonal boron nitride single layer: Exciton-phonon coupling and the role of substrate&#039;&#039;, &lt;br /&gt;
[https://doi.org/10.1103/PhysRevMaterials.7.024006 Phys. Rev. M, &#039;&#039;&#039;7&#039;&#039;&#039; (2), 024006 (2023)]; [https://arxiv.org/abs/2212.10407 arXiv2212.1047]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;cannuccia2019&#039;&amp;gt;E. Cannuccia, B. Monserrat and C. Attaccalite, &#039;&#039;Theory of phonon-assisted luminescence in solids: Application to hexagonal boron nitride&#039;&#039;, [https://doi.org/10.1103/PhysRevB.99.081109 Phys. Rev. B &#039;&#039;&#039;99&#039;&#039;&#039;, 081109(R) (2019)]; [https://arxiv.org/abs/1807.11797 arXiv1807.11797]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;paleari2019&#039;&amp;gt;F. Paleari et al., &#039;&#039;Exciton-Phonon Coupling in the Ultraviolet Absorption and Emission Spectra of Bulk Hexagonal Boron Nitride&#039;&#039;, [https://doi.org/10.1103/PhysRevLett.122.187401 Phys. Rev. Lett. &#039;&#039;&#039;122&#039;&#039;&#039;, 187401 (2019)]; [https://arxiv.org/abs/1810.08976 arXiv1810.089776] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;chen2020&#039;&amp;gt;&#039;&#039;Exciton-Phonon Interaction and Relaxation Times from First Principles&#039;&#039;,&lt;br /&gt;
Hsiao-Yi Chen, Davide Sangalli, and Marco Bernardi, [https://doi.org/10.1103/PhysRevLett.125.107401  Phys. Rev. Lett. &#039;&#039;&#039;125&#039;&#039;&#039;, 107401 (2020)]; [https://arxiv.org/abs/2002.08913 arXiv 2002.08913 (2020)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;lechifflart2023_PhD&amp;quot;&amp;gt;P. Lechifflart, &#039;&#039;Exciton-phonon coupling and phonon-assisted luminescence in hexagonal Boron Nitride nanostructures&#039;&#039;, [https://hal.science/tel-04266805v1 PhD Thesis, University of Marseille (2023)]; [https://www.yambo-code.eu/wiki/images/5/54/These_final.pdf From the yambo website]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;paleari2019_PhD&#039;&amp;gt;F. Paleari, &#039;&#039;First-principles approaches to the description of indirect absorption and luminescence spectroscopy: exciton-phonon coupling in hexagonal boron nitride&#039;&#039;, [https://wwwen.uni.lu/research/fstm/dphyms/people/fulvio_paleari PhD thesis, University of Luxembourg (2019)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;zanfrognini2023&#039;&amp;gt;M. Zanfrognini et al., &#039;&#039;Distinguishing different stackings in layered materials via luminescence spectroscopy&#039;&#039;, [https://doi.org/10.1103/PhysRevLett.131.206902 Phys. Rev. Lett. &#039;&#039;&#039;131&#039;&#039;&#039;, 206902 (2023)]; [https://arxiv.org/abs/2305.17554 arXiv 2305.17554] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;marini2024&#039;&amp;gt;G. Marini, M. Calandra, P. Cudazzo, &#039;&#039;Optical absorption and photoluminescence of single layer boron nitride from a first principles cumulant approach&#039;&#039;, [https://doi.org/10.1021/acs.nanolett.4c00669 Nano Lett., &#039;&#039;&#039;24&#039;&#039;&#039;, 20, 6017 (2024)]; [https://arxiv.org/abs/2402.03826 arXiv 2402.03826 (2024)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;antonius2017&#039;&amp;gt;G. Antonius, S. G. Louie, &#039;&#039;Theory of exciton-phonon coupling&#039;&#039;, [https://doi.org/10.1103/PhysRevB.105.085111 Phys. Rev. B, &#039;&#039;&#039;105&#039;&#039;&#039;, 085111 (2022)]; [https://arxiv.org/abs/1705.04245 arXiv1705.04245 (2017)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;paleari2022&#039;&amp;gt; F. Paleari, and A. Marini, &#039;&#039;Exciton-phonon interaction calls for a revision of the “exciton” concept&#039;&#039;, [https://doi.org/10.1103/PhysRevB.106.125403 Phys. Rev. B, &#039;&#039;&#039;106&#039;&#039;&#039;, 125403 (2022)]; [https://arxiv.org/abs/2205.02783 arXiv 2205.02783]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;cudazzo2020&#039;&amp;gt; P. Cudazzo, &#039;&#039;First-principles description of the exciton-phonon interaction: A cumulant approach&#039;&#039;, [https://doi.org/10.1103/PhysRevB.102.045136 Phys. Rev. B, &#039;&#039;&#039;102&#039;&#039;&#039;, 045136 (2020)]; [https://orbilu.uni.lu/bitstream/10993/44769/1/main.pdf Open access pdf from Luxembourg University]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;chan2023&#039;&amp;gt;Y-h Chan, J. B. Haber, M. H. Naik, J. B. Neaton, D. Y. Qiu, F. H. da Jornada, S. G. Louie, &#039;&#039;Exciton Lifetime and Optical Line Width Profile via Exciton–Phonon Interactions: Theory and First-Principles Calculations for Monolayer MoS2&#039;&#039;, [https://doi.org/10.1021/acs.nanolett.3c00732 Nano Lett., &#039;&#039;&#039;23&#039;&#039;&#039;, 9 (2023)]; [https://arxiv.org/abs/2212.08451 arXiv 2212.08451 (2023)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;murali2025&#039;&amp;gt;M. Nalabothula, S. Reichardt, L. Wirtz, &#039;&#039;Origin of Interlayer Exciton–Phonon Coupling in 2D Heterostructures&#039;&#039;, [https://doi.org/10.1021/acs.nanolett.5c00355 Nano Lett., &#039;&#039;&#039;25&#039;&#039;&#039;, 15 (2025)], [https://arxiv.org/abs/2407.16111 arXiv 2407.16111 (2025)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>FulvioPaleari</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Exciton-phonon_coupling_and_luminescence&amp;diff=9340</id>
		<title>Exciton-phonon coupling and luminescence</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Exciton-phonon_coupling_and_luminescence&amp;diff=9340"/>
		<updated>2026-03-13T14:44:44Z</updated>

		<summary type="html">&lt;p&gt;FulvioPaleari: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:Tdgw-phonon-usc-01-1024x829.jpg| 400px | right | caption=(c) Zhenglu Li, University of Southern California]]&lt;br /&gt;
&lt;br /&gt;
In this advanced tutorial, we will calculate exciton-phonon interactions from first principles by interfacing DFPT (for phonon calculations) and BSE (for exciton calculations).&lt;br /&gt;
&lt;br /&gt;
The DFTP calculations are run with Quantum ESPRESSO, while the many-body GW-BSE calculations are run with Yambo. Finally, the exciton-phonon interaction will be obtained by combining and postprocessing the databases computed in the two previous runs. The great advantage of this workflow is that the calculations can be run in the irreducible Brillouin zones both for the electronic momenta (&#039;&#039;&#039;k&#039;&#039;&#039;) and the transfer momenta (&#039;&#039;&#039;Q&#039;&#039;&#039;, &#039;&#039;&#039;q&#039;&#039;&#039;) of excitons and phonons, thus speeding up considerably the jobs while reducing the IO and memory load.&lt;br /&gt;
&lt;br /&gt;
We will first compute the exciton-phonon coupling matrix elements: these are the building blocks needed to construct experimental observables such as phonon-assisted optical spectra (such as luminescence), Raman spectra and exciton lifetimes. We will do this in the case of monolayer MoS&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;, a 2D system with large spin-orbit interaction.&lt;br /&gt;
&lt;br /&gt;
As an example of application, we will consider the case of phonon-assisted luminescence. We will do this in the case of bulk hBN, a layered indirect insulator with strong electron-phonon coupling.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; this tutorial will be updated when new exc-ph tools become available in Yambopy (including full-python postprocessing, Raman spectra, interpolated lifetimes, etc).&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
This is an advanced topic: we assume that you already know something about the theory&amp;lt;ref name=&amp;quot;toyozawa2003&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;antonius2017&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;cudazzo2020&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;paleari2019_PhD&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;paleari2022&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;lechifflart2023_PhD&amp;quot; /&amp;gt; and applications&amp;lt;ref name=&amp;quot;paleari2019&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;cannuccia2019&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;chen2020&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;zanfrognini2023&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;lechifflart2023&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;chan2023&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;marini2024&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;murali2025&amp;quot; /&amp;gt; of exciton-phonon physics. &lt;br /&gt;
&lt;br /&gt;
Also, we assume that you already know how to run both a basic &#039;&#039;&#039;Yambo&#039;&#039;&#039; GW-BSE calculation and a DFPT phonon calculation with &#039;&#039;&#039;Quantum ESPRESSO&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Besides the QE executables &amp;lt;code&amp;gt;pw.x&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ph.x&amp;lt;/code&amp;gt;, we also use the yambo phonon-specific executable &amp;lt;code&amp;gt;yambo_ph&amp;lt;/code&amp;gt; and the python utility &#039;&#039;&#039;Yambopy&#039;&#039;&#039;. The auxiliary code &#039;&#039;&#039;LetzElPhC&#039;&#039;&#039; (executable &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt;) will be used to obtain the electron-phonon matrix elements by reading the same electronic wavefunctions used by Yambo (and stored in the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory), while also making full use of crystal symmetries. [https://github.com/yambo-code/LetzElPhC LetzElPhC] will be run by Yambopy, but it must nonetheless be installed. Finally, the exciton-phonon properties can be computed either using &amp;lt;code&amp;gt;yambo_ph&amp;lt;/code&amp;gt; or using Yambopy itself. Both cases will be covered in this tutorial.&lt;br /&gt;
&lt;br /&gt;
[[File:Workflow scheme.png|800px|center]]&lt;br /&gt;
&lt;br /&gt;
== Step 0: Pseudopotentials, equilibrium structure and convergence ==&lt;br /&gt;
&lt;br /&gt;
In a real calculation, it is important to ensure that both the pseudopotential and the lattice parameters that we are using are compatible and perform well for the electronic excited states and for the lattice vibrations simultaneously. Furthermore, you have to make sure that the wave function cutoff &amp;lt;code&amp;gt;ecutwfc&amp;lt;/code&amp;gt; is converged with respect to the DFPT step and not just to the DFT one. This is in addition to the other customary convergence tests for DFT, DFPT, GW and BSE calculations.&lt;br /&gt;
&lt;br /&gt;
This is often the most time-demanding step when starting on a new system.&lt;br /&gt;
&lt;br /&gt;
For the sake of this tutorial, we assume that we have already done all these tests and we are starting the final workflow to get the exciton-phonon properties.&lt;br /&gt;
&lt;br /&gt;
== Step 1: scf calculation ==&lt;br /&gt;
&lt;br /&gt;
First of all, we run a standard scf calculation with &amp;lt;code&amp;gt;pw.x&amp;lt;/code&amp;gt; for Yambo. We stick with non-symmorphic symmetries. At the end, we will have the QE &amp;lt;code&amp;gt;save&amp;lt;/code&amp;gt; directory.&lt;br /&gt;
&lt;br /&gt;
This is the input &amp;lt;code&amp;gt;mos2.scf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 &amp;amp;control&lt;br /&gt;
           wf_collect = .true.,&lt;br /&gt;
          calculation = &amp;quot;scf&amp;quot;,&lt;br /&gt;
            verbosity = &#039;high&#039;,&lt;br /&gt;
           pseudo_dir = &#039;$PSEUDO_DIR&#039;,&lt;br /&gt;
               prefix = &amp;quot;mos2&amp;quot;,&lt;br /&gt;
               outdir = &#039;.&#039;,&lt;br /&gt;
  /&amp;amp;end&lt;br /&gt;
  &amp;amp;system&lt;br /&gt;
              ecutwfc = 100.0,&lt;br /&gt;
          occupations = &#039;fixed&#039;,&lt;br /&gt;
                ibrav = 4,&lt;br /&gt;
            celldm(1) = 5.9000811881,&lt;br /&gt;
            celldm(3) = 6.7795677253,&lt;br /&gt;
                  nat = 3,&lt;br /&gt;
                 ntyp = 2,&lt;br /&gt;
             lspinorb = .true.&lt;br /&gt;
             noncolin = .true.&lt;br /&gt;
             assume_isolated = &#039;2D&#039;&lt;br /&gt;
         force_symmorphic = .true.&lt;br /&gt;
  /&amp;amp;end&lt;br /&gt;
  &amp;amp;electrons&lt;br /&gt;
     electron_maxstep = 200,&lt;br /&gt;
          mixing_beta = 0.7,&lt;br /&gt;
             conv_thr = 1.d-08,&lt;br /&gt;
  /&amp;amp;end&lt;br /&gt;
   ATOMIC_SPECIES&lt;br /&gt;
    Mo  95.940      Mo_ONCV_PBE_FR-1.0.upf&lt;br /&gt;
    S    32.065     S_ONCV_PBE_FR-1.1.upf&lt;br /&gt;
   ATOMIC_POSITIONS { crystal }&lt;br /&gt;
 Mo       0.333333333   0.666666667   0.000000000&lt;br /&gt;
 S        0.666666667   0.333333333   0.073413577&lt;br /&gt;
 S        0.666666667   0.333333333  -0.073413577&lt;br /&gt;
  K_POINTS { automatic }&lt;br /&gt;
 6 6 1 0 0 0&lt;br /&gt;
&lt;br /&gt;
Here we are using full relativistic pseudopotentials from the SG-15 database.&lt;br /&gt;
&lt;br /&gt;
We can run it on our machine (for example using 4 MPI tasks) as:&lt;br /&gt;
&lt;br /&gt;
 mpirun -np 4 pw.x -inp mos2.scf &amp;gt; scf.out&lt;br /&gt;
&lt;br /&gt;
== Step 2: nscf calculation for Yambo ==&lt;br /&gt;
&lt;br /&gt;
Copy the QE &amp;lt;code&amp;gt;save&amp;lt;/code&amp;gt; directory from the scf calculation and run the nscf calculation for any number of empty states, with the correct &amp;lt;code&amp;gt;k&amp;lt;/code&amp;gt;-grid we want to use in Yambo. Here we are using a badly underconverged grid of 6x6x1.&lt;br /&gt;
&lt;br /&gt;
This reciprocal-space grid will also match the momentum transfer &amp;lt;code&amp;gt;q&amp;lt;/code&amp;gt; grid on which excitons and phonons will be defined!&lt;br /&gt;
&lt;br /&gt;
The electronic wavefunctions computed at this step and stored in the new nscf &amp;lt;code&amp;gt;save&amp;lt;/code&amp;gt; directory will be used both by Yambo and by the electron-phonon code: this is important because using different sets of wavefunctions would lead to a phase mismatch issue in the exciton-phonon matrix elements.&lt;br /&gt;
&lt;br /&gt;
The nscf input &amp;lt;code&amp;gt;mos2.nscf&amp;lt;/code&amp;gt; is&lt;br /&gt;
 &amp;amp;control&lt;br /&gt;
           wf_collect = .true.,&lt;br /&gt;
          calculation = &amp;quot;nscf&amp;quot;,&lt;br /&gt;
            verbosity = &#039;high&#039;,&lt;br /&gt;
           pseudo_dir = &#039;$PSEUDO_DIR&#039;,&lt;br /&gt;
               prefix = &amp;quot;mos2&amp;quot;,&lt;br /&gt;
               outdir = &#039;.&#039;,&lt;br /&gt;
  /&amp;amp;end&lt;br /&gt;
  &amp;amp;system&lt;br /&gt;
              ecutwfc = 100.0,&lt;br /&gt;
          occupations = &#039;fixed&#039;,&lt;br /&gt;
                ibrav = 4,&lt;br /&gt;
            celldm(1) = 5.9000811881,&lt;br /&gt;
            celldm(3) = 6.7795677253,&lt;br /&gt;
                  nat = 3,&lt;br /&gt;
                 ntyp = 2,&lt;br /&gt;
             lspinorb = .true.&lt;br /&gt;
             noncolin = .true.&lt;br /&gt;
                nbnd  = 250&lt;br /&gt;
             assume_isolated = &#039;2D&#039;&lt;br /&gt;
         force_symmorphic = .true.&lt;br /&gt;
  /&amp;amp;end&lt;br /&gt;
  &amp;amp;electrons&lt;br /&gt;
     electron_maxstep = 200,&lt;br /&gt;
          mixing_beta = 0.7,&lt;br /&gt;
             conv_thr = 1.d-08,&lt;br /&gt;
  /&amp;amp;end&lt;br /&gt;
   ATOMIC_SPECIES&lt;br /&gt;
    Mo  95.940      Mo_ONCV_PBE_FR-1.0.upf&lt;br /&gt;
    S    32.065     S_ONCV_PBE_FR-1.1.upf&lt;br /&gt;
   ATOMIC_POSITIONS { crystal }&lt;br /&gt;
 Mo       0.333333333   0.666666667   0.000000000&lt;br /&gt;
 S        0.666666667   0.333333333   0.073413577&lt;br /&gt;
 S        0.666666667   0.333333333  -0.073413577&lt;br /&gt;
  K_POINTS { automatic }&lt;br /&gt;
 6 6 1 0 0 0&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Again, we run the calculation&lt;br /&gt;
&lt;br /&gt;
 mpirun -np 4 pw.x -inp mos2.nscf &amp;gt; nscf.out&lt;br /&gt;
&lt;br /&gt;
== Step 3: dvscf phonon calculation ==&lt;br /&gt;
&lt;br /&gt;
Now we run the phonon calculation.&lt;br /&gt;
&lt;br /&gt;
Copy the &amp;lt;code&amp;gt;save&amp;lt;/code&amp;gt; directory from the &#039;&#039;&#039;scf&#039;&#039;&#039; calculation and run &amp;lt;code&amp;gt;ph.x&amp;lt;/code&amp;gt; for a dvscf calculation with a standard &amp;lt;code&amp;gt;q&amp;lt;/code&amp;gt;-grid matching the &amp;lt;code&amp;gt;k&amp;lt;/code&amp;gt;-grid we wanna use in Yambo.&lt;br /&gt;
&lt;br /&gt;
At the end, we will have the &amp;lt;code&amp;gt;_ph0&amp;lt;/code&amp;gt; directory containing the variation of the self-consistent potential, &amp;lt;math&amp;gt;\Delta V_{SCF}(q)&amp;lt;/math&amp;gt;, and the &amp;lt;code&amp;gt;*.dyn&amp;lt;/code&amp;gt; files with the phonon energies and eigenvectors.&lt;br /&gt;
&lt;br /&gt;
NB: one could further refine the phonon energies by enforcing the acoustic sum rule, including non-analytic long-range contributions, interpolating to finer grids... all of this can be done within Quantum ESPRESSO and will not be covered in this version of the tutorial.&lt;br /&gt;
&lt;br /&gt;
The input is &amp;lt;code&amp;gt;mos2.dvscf&amp;lt;/code&amp;gt;:&lt;br /&gt;
 &lt;br /&gt;
 mos2_dvscf&lt;br /&gt;
 &amp;amp;inputph&lt;br /&gt;
   tr2_ph=1.0d-12,&lt;br /&gt;
   verbosity=&#039;high&#039;&lt;br /&gt;
   prefix=&#039;mos2&#039;,&lt;br /&gt;
   fildvscf = &#039;mos2-dvscf&#039;,&lt;br /&gt;
   electron_phonon = &#039;dvscf&#039;,&lt;br /&gt;
   fildyn=&#039;mos2.dyn&#039;,&lt;br /&gt;
   epsil=.false.,&lt;br /&gt;
   ldisp=.true.,&lt;br /&gt;
   recover=.true.,&lt;br /&gt;
   nq1=6,&lt;br /&gt;
   nq2=6,&lt;br /&gt;
   nq3=1&lt;br /&gt;
 /&lt;br /&gt;
&lt;br /&gt;
And now we run as&lt;br /&gt;
&lt;br /&gt;
 nohup mpirun -np 8 ph.x -inp mos2.dvscf &amp;gt; dvscf.out &amp;amp;&lt;br /&gt;
&lt;br /&gt;
This time we use nohup and more processes because this calculation may take some time. It is a good idea to set &amp;lt;code&amp;gt;recover=.true.&amp;lt;/code&amp;gt; as in a real calculation you will easily breach walltime, and in this way you can safely restart.&lt;br /&gt;
&lt;br /&gt;
== Step 4: create Yambo &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory ==&lt;br /&gt;
&lt;br /&gt;
This is just the standard Yambo initialization: run &lt;br /&gt;
 &lt;br /&gt;
 p2y &lt;br /&gt;
&lt;br /&gt;
and then &lt;br /&gt;
&lt;br /&gt;
 yambo &lt;br /&gt;
&lt;br /&gt;
in the &#039;&#039;&#039;nscf&#039;&#039;&#039; &amp;lt;code&amp;gt;save&amp;lt;/code&amp;gt; folder and then move the newly generated &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory to a convenient place.&lt;br /&gt;
&lt;br /&gt;
== Step 5: run a BSE calculation ==&lt;br /&gt;
&lt;br /&gt;
Now we switch from QE to Yambo. Here, we forgo the GW step for simplicity (we can use a scissor operator to open the band gap).&lt;br /&gt;
&lt;br /&gt;
This calculation has a couple of differences with respect to a standard BSE calculation for optical absorption. We can look at the input file &amp;lt;code&amp;gt;bse.in&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Runlevels&amp;lt;/span&amp;gt;&lt;br /&gt;
 optics                       # [R OPT] Optics&lt;br /&gt;
 rim_cut                      # [R RIM CUT] Coulomb potential&lt;br /&gt;
 bss                          # [R BSS] Bethe Salpeter Equation solver&lt;br /&gt;
 em1s                         # [R Xs] Static Inverse Dielectric Matrix&lt;br /&gt;
 bse                          # [R BSE] Bethe Salpeter Equation.&lt;br /&gt;
 bsk                          # [R BSK] Bethe Salpeter Equation kernel&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# RIM and cutoff settings&amp;lt;/span&amp;gt;&lt;br /&gt;
 RandQpts=1000000             # [RIM] Number of random q-points in the BZ&lt;br /&gt;
 RandGvec= 100            RL    # [RIM] Coulomb interaction RS components&lt;br /&gt;
 CUTGeo= &amp;quot;slab z&amp;quot;               # [CUT] Coulomb Cutoff geometry: box/cylinder/sphere X/Y/Z/XY..&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Static screening&amp;lt;/span&amp;gt;&lt;br /&gt;
 X_and_IO_CPU= &amp;quot;1 1 4 2 1&amp;quot;       # [PARALLEL] CPUs for each role&lt;br /&gt;
 X_and_IO_ROLEs= &amp;quot;q g k c v&amp;quot;      # [PARALLEL] CPUs roles (q,g,k,c,v)&lt;br /&gt;
 X_and_IO_nCPU_LinAlg_INV=-1      # [PARALLEL] CPUs for Linear Algebra (if -1 it is automatically set)&lt;br /&gt;
 Chimod= &amp;quot;hartree&amp;quot;            # [X] IP/Hartree/ALDA/LRC/BSfxc&lt;br /&gt;
 % BndsRnXs&lt;br /&gt;
    1 |  200 |                 # [Xs] Polarization function bands&lt;br /&gt;
 %&lt;br /&gt;
 % LongDrXs&lt;br /&gt;
  1.000000 | 1.000000 | 1.000000 |        # [Xs] [cc] Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 NGsBlkXs= 8000            mRy    # [Xs] Response block size&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# BSE&amp;lt;/span&amp;gt;&lt;br /&gt;
 BS_CPU= &amp;quot;4.1.2&amp;quot;                   # [PARALLEL] CPUs for each role&lt;br /&gt;
 BS_ROLEs= &amp;quot;k.eh.t&amp;quot;                 # [PARALLEL] CPUs roles (k,eh,t)&lt;br /&gt;
 BS_nCPU_diago=4              # [PARALLEL] CPUs for matrix diagonalization&lt;br /&gt;
 BSEmod= &amp;quot;causal&amp;quot;             # [BSE] resonant/causal/coupling&lt;br /&gt;
 BSKmod= &amp;quot;SEX&amp;quot;                # [BSE] IP/Hartree/HF/ALDA/SEX/BSfxc&lt;br /&gt;
 BSSmod= &amp;quot;d&amp;quot;                  # [BSS] (h)aydock/(d)iagonalization/(s)lepc/(i)nversion/(t)ddft`&lt;br /&gt;
 BSENGexx=  40000      mRy    # [BSK] Exchange components&lt;br /&gt;
 ALLGexx                      # [BSS] Force the use use all RL vectors for the exchange part&lt;br /&gt;
 BSENGBlk=  8000       mRy    # [BSK] Screened interaction block size&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;Lkind=&amp;quot;full&amp;quot;                  #[BSE,X] bar(default)/full/tilde&amp;lt;/span&amp;gt;&lt;br /&gt;
 % KfnQP_E&lt;br /&gt;
  1.000000 | 1.000000 | 1.000000 |        # [EXTQP BSK BSS] E parameters  (c/v) eV|adim|adim&lt;br /&gt;
 %&lt;br /&gt;
 % BEnRange&lt;br /&gt;
   0.00000 |  4.00000 | eV    # [BSS] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 % BDmRange&lt;br /&gt;
   0.05000 |  0.05000 | eV    # [BSS] Damping range&lt;br /&gt;
 %&lt;br /&gt;
 BEnSteps= 2000               # [BSS] Energy steps&lt;br /&gt;
 % BLongDir&lt;br /&gt;
  1.000000 | 0.000000 | 0.000000 |        # [BSS] [cc] Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;% BSEQptR&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 1 | 7 |                     # [BSK] Transferred momenta range&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;%&amp;lt;/span&amp;gt;&lt;br /&gt;
 % BSEBands&lt;br /&gt;
    25 |  28 |                 # [BSK] Bands range&lt;br /&gt;
 %&lt;br /&gt;
 WRbsWF                      # [BSS] Write to disk excitonic the FWs&lt;br /&gt;
 &lt;br /&gt;
This file was generated using the command: &amp;lt;code&amp;gt; yambo -X s -o b -k sex -y d -r&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
First of all, we compute the excitons for all the momenta in the irreducible Brillouin zone for our discrete grid via the &amp;lt;code&amp;gt;BSEQptR&amp;lt;/code&amp;gt; variable. This will be a &#039;&#039;&#039;finite-momentum&#039;&#039;&#039; BSE calculation, analogous to the phonon one.&lt;br /&gt;
&lt;br /&gt;
Second, we change the variable &amp;lt;code&amp;gt;Lkind&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;bar&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;full&amp;lt;/code&amp;gt;. In Yambo, &amp;lt;code&amp;gt;Lkind=&amp;quot;bar&amp;quot;&amp;lt;/code&amp;gt;, which is the default for optical absorption, means that we are computing the excitonic response function without the long-range component of the exchange interaction. This cannot be used when computing the exciton momentum dependence, where the long-range exchange interaction can play a role, therefore we have to include it with &amp;lt;code&amp;gt;Lkind=&amp;quot;full&amp;quot;&amp;lt;/code&amp;gt;. This allows for the calculation of the excitonic longitudinal-transverse splitting (in 3D systems) as well.&lt;br /&gt;
&lt;br /&gt;
We can now run the code:&lt;br /&gt;
&lt;br /&gt;
 nohup mpirun -np 8 yambo -F bse.in -J bse_Lfull -C bse_Lfull &amp;amp;&lt;br /&gt;
&lt;br /&gt;
At the end of the calculation, we have obtained the &amp;lt;code&amp;gt;ndb.BS_diago_Q*&amp;lt;/code&amp;gt; databases inside the directory &amp;lt;code&amp;gt;bse_Lfull&amp;lt;/code&amp;gt;. They contain information on the exciton energies and wavefunctions at each momentum. Do not forget to check the report and logs of your calculation in the same directory to make sure that the code is doing what you want.&lt;br /&gt;
&lt;br /&gt;
== Step 6: obtain the electron-phonon matrix elements ==&lt;br /&gt;
&lt;br /&gt;
We have finished the heavy simulations. Now it&#039;s time for the postprocessing. The first order of business is the reconstruction of the electron-phonon coupling matrix elements from the dvscf results and the electronic wavefunctions.&lt;br /&gt;
&lt;br /&gt;
In order to do this, we will run the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable of the &#039;&#039;&#039;LetzElPhC&#039;&#039;&#039; code. We will run via command line using yambopy, although it will be instructive to have look at the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; input files later.&lt;br /&gt;
&lt;br /&gt;
We run in the same directory where the Yambo &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; is (remember than you can also virtually move it with a symbolic link).&lt;br /&gt;
&lt;br /&gt;
Type:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y&lt;br /&gt;
&lt;br /&gt;
to see the help for the calculation. Have a look at the various flags and their description.&lt;br /&gt;
For example, if we want to do a serial run of LetzElPhC for bands from &amp;lt;math&amp;gt;n_i&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;n_f&amp;lt;/math&amp;gt;, we should type:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph path/of/ph_input.in -b n_i n_f&lt;br /&gt;
&lt;br /&gt;
Here &amp;lt;math&amp;gt;n_i&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;n_f&amp;lt;/math&amp;gt; are integers representing the initial and final band indices. &#039;&#039;&#039;Please note&#039;&#039;&#039;: in this case, the band index starts from 1 and the the interval of bands read by the code is &amp;lt;math&amp;gt;[n_i,n_f]&amp;lt;/math&amp;gt; including the extrema of the interval.&lt;br /&gt;
&lt;br /&gt;
These should coincide with those used for the Bethe-Salpeter kernel, i.e. those specified in the &amp;lt;code&amp;gt;BSEBands&amp;lt;/code&amp;gt; variable of the BSE input file (this is not strictly necessary, but certainly efficient since these calculations use a lot of disk space). &lt;br /&gt;
&lt;br /&gt;
For our system, we want to do a parallel calculation with 4 qpools and 2 kpools. In addition, we want to explicitly specify the path of the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable and avoid automatically deleting the LetzElPhC data. So we type:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph path/of/dvscf/mos2.dvscf -b 25 28 -par 4 2 -lelphc path/to/lelphc_exe&lt;br /&gt;
&lt;br /&gt;
At the end, check your directory: you should find the &amp;lt;code&amp;gt;lelphc.in&amp;lt;/code&amp;gt; input file that was run, let&#039;s inspect it: &lt;br /&gt;
&lt;br /&gt;
 # LetzElPhC input for yambo generated by yambopy&lt;br /&gt;
 nqpool      = 2&lt;br /&gt;
 nkpool      = 4&lt;br /&gt;
 start_bnd   = 25&lt;br /&gt;
 end_bnd     = 28&lt;br /&gt;
 save_dir    = ./SAVE&lt;br /&gt;
 kernel      = dfpt&lt;br /&gt;
 ph_save_dir = dvscf/ph_save&lt;br /&gt;
 convention = yambo&lt;br /&gt;
&lt;br /&gt;
Notice the variable &amp;lt;code&amp;gt;convention=yambo&amp;lt;/code&amp;gt;: what does it mean? At variance with QE and many other codes, Yambo uses the &amp;quot;backward&amp;quot; momentum transfer convention for electronic scatterings. That is, an electronic transition goes from band &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; and momentum &amp;lt;math&amp;gt;k-q&amp;lt;/math&amp;gt; to band &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; and momentum &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;. In the &amp;quot;forward&amp;quot; momentum transfer convention (the more standard one), the transitions go from &amp;lt;math&amp;gt;nk&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;mk+q&amp;lt;/math&amp;gt;. Therefore, this variable ensures that the electron-phonon coupling matrix elements are computed as &amp;lt;math&amp;gt;\langle mk|dV|nk-q\rangle&amp;lt;/math&amp;gt;. This will have consequences also in the formulation of the &#039;&#039;exciton&#039;&#039;-phonon coupling matrix element.&lt;br /&gt;
&lt;br /&gt;
You will also find a &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; database that contains the computed electron-phonon matrix elements, in the output format of &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In addition, if you check the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; folder:&lt;br /&gt;
&lt;br /&gt;
 ls SAVE/ndb.elph_gkkp*&lt;br /&gt;
&lt;br /&gt;
you will see that yambopy has created the Yambo-compatible electron-phonon databases.&lt;br /&gt;
&lt;br /&gt;
If you want to run LetzElPhC directly, without using yambopy, you can refer to its [[https://gitlab.com/lumen-code/LetzElPhC/-/blob/main/docs/main.pdf?ref_type=heads|user guide]].&lt;br /&gt;
Keep in mind that in this case, in order to convert the database to the &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases of Yambo, you will then need a couple of lines of python using the Yambopy class &amp;lt;code&amp;gt;ConvertElectronPhononDB&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;yambopy/letzelph_interface/lelph2y.py&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t need the &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases -- e.g., because you are doing the exc-ph postprocessing with yambopy -- you can run &amp;lt;code&amp;gt;yambopy l2y ...&amp;lt;/code&amp;gt; with the &amp;lt;code&amp;gt;--no_gkkp&amp;lt;/code&amp;gt; option.&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t need the &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; databases -- e.g., because you are using &amp;lt;code&amp;gt;yambo_ph&amp;lt;/code&amp;gt; for the exc-ph part -- you can run &amp;lt;code&amp;gt;yambopy l2y ...&amp;lt;/code&amp;gt; with the &amp;lt;code&amp;gt;--no_lelphc_dbs&amp;lt;/code&amp;gt; option.&lt;br /&gt;
&lt;br /&gt;
== Step 7: Obtain the exciton-phonon coupling ==&lt;br /&gt;
&lt;br /&gt;
Now, we can finally access our basic building block for exciton-phonon physics. This could be done entirely in python (using &#039;&#039;&#039;Yambopy&#039;&#039;&#039;), or by running &#039;&#039;&#039;Yambo&#039;&#039;&#039;. &lt;br /&gt;
&lt;br /&gt;
* For the &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&#039;&#039;&#039;Yambo postprocessing&#039;&#039;&#039;&amp;lt;/span&amp;gt; case (running yambo inputs with the &amp;lt;code&amp;gt;yambo_ph&amp;lt;/code&amp;gt; executable), &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&#039;&#039;&#039;follow the alternative route to Steps 7-8 [[Exciton-phonon coupling and luminescence - Yambo postprocessing|at this link]]&#039;&#039;&#039;&amp;lt;/span&amp;gt;.&lt;br /&gt;
* For the &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&#039;&#039;&#039;Yambopy postprocessing&#039;&#039;&#039;&amp;lt;/span&amp;gt; case (using flexible python scripting), &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&#039;&#039;&#039;keep following Steps 7-8 on this page&#039;&#039;&#039;&amp;lt;/span&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Our objective is obtaining the following quantity: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\mathcal{G}^\mu_{\alpha\lambda}(0,q)=\sum_{vv^\prime c k} A^{\alpha, *}_{cv^\prime} (k, q) g_{vv^\prime}^\mu (k,q) A^{\lambda}_{cv}(k,0) - \sum_{cc^\prime vk} A^{\alpha, *}_{c^\prime v} (k+q, q) g_{c^\prime c}^\mu (k+q,q) A^{\lambda}_{cv}(k, 0)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here, &amp;lt;math&amp;gt;A^{\alpha}_{cv}(k,q)&amp;lt;/math&amp;gt; are the exciton coefficients extracted from the eigenvector of the two-particles Hamiltonian during the BSE calculation in step 5, while &amp;lt;math&amp;gt;g_{nm}^\mu (k,q)&amp;lt;/math&amp;gt; are the electron-phonon coupling matrix elements obtained in step 6. As you can see, the exciton &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; undergoes phonon-mediated scattering to state &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; via phonon mode &amp;lt;math&amp;gt;\mu&amp;lt;/math&amp;gt;. The scattering can happen for the hole (valence, &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt;) or for the electron (conduction, &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
NB: &lt;br /&gt;
&lt;br /&gt;
(1) This is written in the &amp;quot;backward&amp;quot; momentum transfer convention used by Yambo. The momentum dependence is different in the &amp;quot;forward&amp;quot; transfer convention. &lt;br /&gt;
&lt;br /&gt;
(2) For simplicity, this is written for zero initial exciton momentum. This means that one of the two states involved in the phonon-mediated scattering process will be in the optical limit (and possibly an optically generated exciton), while the other state can have any momentum: this momentum will be the same as the phonon one. This matrix element can be used to describe phonon-assisted absorption and emission spectra.&lt;br /&gt;
&lt;br /&gt;
In order to calculate this quantity using python, we need the &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; databases natively generated by the &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; code, as well as the BSE databases &amp;lt;code&amp;gt;ndb.BS_diago_Q*&amp;lt;/code&amp;gt; containing the information on exciton wavefunctions and energies.&lt;br /&gt;
&lt;br /&gt;
Next, we write a python user script importing the yambopy exciton-phonon tools. You can find a version of this script in &amp;lt;code&amp;gt;yambopy/tutorials/exciton-phonon/calculate_excph.py&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
 import numpy as np &lt;br /&gt;
 from yambopy import YamboLatticeDB,YamboWFDB,LetzElphElectronPhononDB &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;#Specific Yambopy dbs loading classes&amp;lt;/span&amp;gt;&lt;br /&gt;
 from yambopy.exciton_phonon.excph_matrix_elements import exciton_phonon_matelem &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;#Specific exc-ph functions&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 path = &#039;1L_MoS2&#039;&lt;br /&gt;
 bands_range=[24,28] &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# 2 valence bands, 2 conduction bands&amp;lt;/span&amp;gt;&lt;br /&gt;
 nexc = 12 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# number of excitonic states&amp;lt;/span&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 bsepath    = f&#039;{path}/bse-allq_full&#039; &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Path to BSE calculation (Lin=Lout)&amp;lt;/span&amp;gt;&lt;br /&gt;
 savepath   = f&#039;{path}/SAVE&#039;     &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Yambo SAVE&amp;lt;/span&amp;gt;&lt;br /&gt;
 ndb_elph   = f&#039;{path}/ndb.elph&#039; &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# LetzElPhC electron-phonon database (any convention)&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Read lattice&amp;lt;/span&amp;gt;&lt;br /&gt;
 lattice = YamboLatticeDB.from_db_file(filename=f&#039;{savepath}/ns.db1&#039;)&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Read electron-phonon&amp;lt;/span&amp;gt;&lt;br /&gt;
 elph    = LetzElphElectronPhononDB(ndb_elph,read_all=False)&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Read wave functions&amp;lt;/span&amp;gt;&lt;br /&gt;
 wfcs    = YamboWFDB(filename=&#039;ns.wf&#039;,save=savepath,latdb=lattice,bands_range=bands_range)&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Calculate exciton-phonon matrix elements&amp;lt;/span&amp;gt;&lt;br /&gt;
 exph = exciton_phonon_matelem(lattice,elph,wfcs,BSE_dir=bsepath,nexc_in=nexc,nexc_out=nexc,dmat_mode=&#039;save&#039;,exph_file=&#039;MoS2_Ex-ph.npy&#039;)&lt;br /&gt;
&lt;br /&gt;
In this script, we can select the number exciton states &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; with &amp;lt;code&amp;gt;nexc&amp;lt;/code&amp;gt;, the single-particle bands range with &amp;lt;code&amp;gt;bands_range&amp;lt;/code&amp;gt;. &#039;&#039;&#039;Please note&#039;&#039;&#039;: in this case, the band index starts from 0 (python indexing) and the the interval of bands read by the code is &amp;lt;math&amp;gt;[n_i,n_f)&amp;lt;/math&amp;gt;, therefore the last value (28 in the example) is excluded. That is, in the example we are selecting the 25th, 26th, 27th and 28th bands. Those bands have to be present in both the electron-phonon and BSE calculations. &lt;br /&gt;
&lt;br /&gt;
Here we calculate the couplings of the first twelve states at each finite-&amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; point including &amp;lt;math&amp;gt;q=0&amp;lt;/math&amp;gt;. We also include all the nine phonon modes of monolayer MoS2. We also need access to the Yambo &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory in order to read the electronic wavefunctions: they are used to compute the electronic representation matrices (&amp;lt;code&amp;gt;dmat&amp;lt;/code&amp;gt; in the code). The argument &amp;lt;code&amp;gt;dmat_mode&amp;lt;/code&amp;gt; can be set to &amp;lt;code&amp;gt;&#039;load&#039;&amp;lt;/code&amp;gt; for subsequent calculations.&lt;br /&gt;
&lt;br /&gt;
When we are satisfied with the input, we run the code:&lt;br /&gt;
&lt;br /&gt;
 python calculate_excph.py&lt;br /&gt;
&lt;br /&gt;
If you check the output, you should find the &amp;lt;code&amp;gt;MoS2_Ex-ph.npy&amp;lt;/code&amp;gt; binary file in the directory where you ran.&lt;br /&gt;
&lt;br /&gt;
=== Analysis of the couplings ===&lt;br /&gt;
&lt;br /&gt;
It is a good idea to have a look at what we computed up to now in order to make sure nothing has gone wrong. &lt;br /&gt;
&lt;br /&gt;
It is not easy to know what to expect (apart from symmetry and gauge compliance of the matrix elements), but one can work out the exciton-phonon selection rules in advance, check that the magnitude is reasonable, etc.&lt;br /&gt;
&lt;br /&gt;
It is also not easy to meaningfully plot this quantity. We have to make sure that we are not breaking degenerate states, otherwise the plots will not be invariant. &lt;br /&gt;
&lt;br /&gt;
First of all, we have to know our system: in monolayer MoS&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;, the first four excitons are all doubly degenerate. The first exciton responsible for a bright peak in the absorption spectrum (the &#039;&#039;&#039;A&#039;&#039;&#039; peak), is the second state, corresponding to state indices &amp;lt;code&amp;gt;(3,4)&amp;lt;/code&amp;gt; in fortran indexing or &amp;lt;code&amp;gt;(2,3)&amp;lt;/code&amp;gt; in python indexing. &lt;br /&gt;
&lt;br /&gt;
All these information can be obtained by analyzing the BSE results (this stuff is explained in the BSE tutorials) and by knowledge of the system or class of systems from the literature.&lt;br /&gt;
&lt;br /&gt;
Thus, a good quantity to plot may be the norm of the matrix elements, summed over the degenerate subspace of exciton A, for a certain number of scattered final states mediated by certain phonon modes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;F_A(q)= \sqrt{ \sum_{\alpha \in A,\lambda,\mu} |\mathcal{G}_{\alpha\lambda}^\mu (0,q)|^2 }&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In order to do this, we create a python script &amp;lt;code&amp;gt;analyse_excph.py&amp;lt;/code&amp;gt; in which we first load the excph dabatases. &lt;br /&gt;
You can find a version of this script in the yambopy directory, in &amp;lt;code&amp;gt;tutorials/exciton-phonon&amp;lt;/code&amp;gt;. &lt;br /&gt;
First, we select the exciton and phonon states to be included in &amp;lt;code&amp;gt;F_A&amp;lt;/code&amp;gt;, together with the path of databases and plot details:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Exciton &amp;quot;in&amp;quot; states&amp;lt;/span&amp;gt;&lt;br /&gt;
 exc_in  = [2,3]  &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# First bright peak (A: 2,3 -- B: 6,7)&amp;lt;/span&amp;gt;&lt;br /&gt;
 exc_out = [0,1,2,3] &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# first 4 states (dispersion of dark triplet state and A)&amp;lt;/span&amp;gt;&lt;br /&gt;
 ph_in  = &#039;all&#039;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Paths of databases&amp;lt;/span&amp;gt;&lt;br /&gt;
 ns_db1 =f&#039;{path}/SAVE/ns.db1&#039;&lt;br /&gt;
 ns_ypy = &#039;MoS2_Ex-ph.npy&#039;&lt;br /&gt;
 &lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
Then, we load the data:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Read lattice and k-space info&amp;lt;/span&amp;gt;&lt;br /&gt;
 ylat = YamboLatticeDB.from_db_file(filename=ns_db1)&lt;br /&gt;
 print(ylat)&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Load exc-ph database&amp;lt;/span&amp;gt;&lt;br /&gt;
 X_py = np.load(ns_ypy)&lt;br /&gt;
 G_squared = np.abs(X_py)**2.&lt;br /&gt;
&lt;br /&gt;
The quantity &amp;lt;math&amp;gt;F_A(q)&amp;lt;/math&amp;gt; is obtained from a dedicated function as:&lt;br /&gt;
 &lt;br /&gt;
 if exc_in  == &#039;all&#039;: exc_in  = range(G_squared.shape[2])&lt;br /&gt;
 if exc_out == &#039;all&#039;: exc_out = range(G_squared.shape[3])&lt;br /&gt;
 if ph_in   == &#039;all&#039;: ph_in   = range(G_squared.shape[1])&lt;br /&gt;
 &lt;br /&gt;
 G_squared = G_squared[:, ph_in, :, :].sum(axis=(1))&lt;br /&gt;
 G_squared = G_squared[:, exc_in, :].sum(axis=(1))&lt;br /&gt;
 G_squared = G_squared[:, exc_out].sum(axis=(1))&lt;br /&gt;
 &lt;br /&gt;
 F_q = np.sqrt( G_squared )*ha2ev &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Switch from Ha to eV&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And finally, we have to make a plotting function. For this tutorial we will use a custom scatterplot employing some of the plotting tools provided by yambopy (but you can do whatever you want).&lt;br /&gt;
&lt;br /&gt;
 plot_2D_excph(qgrid,G2_to_plot,rlat=ylat.rlat,plt_cbar=True,\&lt;br /&gt;
               marker=&#039;H&#039;,s=700,cmap=&#039;magma&#039;)&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
You can get more experience on using Yambopy for these kinds of visualization by following the [https://wiki.yambo-code.eu/wiki/index.php?title=First_steps_in_Yambopy Yambopy tutorials]. In fact, remember that these scripts and all the other Yambopy tutorial scripts are just suggestions, not source code written in stone: if you know &amp;lt;code&amp;gt;numpy&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;matplotlib&amp;lt;/code&amp;gt; you can do your own analysis and your own plots, you just need to import the required Yambopy modules to load the data.&lt;br /&gt;
&lt;br /&gt;
In our case, the resulting plot is the following.&lt;br /&gt;
&lt;br /&gt;
[[File:1L MoS2 MoS2 Ex-ph.png|500px|center]]&lt;br /&gt;
&lt;br /&gt;
This can be checked against Fig. 2(d) of reference &amp;lt;ref name=&amp;quot;chan2023&amp;quot; /&amp;gt;, although you have to keep in mind that our results are badly undersampled in terms of the reciprocal-space grid, as can be easily seen, and the quantity plotted is not exactly the same. However, the main features are already there since they are dictated mostly by crystal symmetries.&lt;br /&gt;
&lt;br /&gt;
Now that we have the exciton-phonon matrix elements, we can use them to build several kinds of observables. Below, we give an example related to phonon-assisted luminescence, but we may update this tutorial in the future to include more cases.&lt;br /&gt;
&lt;br /&gt;
== Step 8: Compute phonon-assisted luminescence ==&lt;br /&gt;
&lt;br /&gt;
[[File:Luminescence scheme.png|250px|right]]&lt;br /&gt;
&lt;br /&gt;
We want to compute the experimental optical signature due to the phonon-assisted recombination of an exciton (as sketched in the figure).&lt;br /&gt;
&lt;br /&gt;
The signal from the phonon replicas can be modeled as a second-order scattering process involving one phonon and one photon:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;I^{Sat}(\omega)=\frac{1}{ N_q} \frac{1}{3} \sum_{\epsilon s\beta \mu q} \frac{1}{E_{\beta q}-s\Omega_{\mu q}}\left|\sum_\alpha\frac{ D^{\epsilon}_\alpha \mathcal{G}_{\beta \alpha}^{\mu,*}(q)}{E_\alpha -E_{\beta q} +s\Omega_{\mu q}+\mathrm{i}\eta}\right|^2 \frac{N^{exc}_{\beta q}(T_{exc})[\frac{1+s}{2}+n_{\mu q}(T)]}{\omega -[E_{\beta q}-s\Omega_{\mu q}]+\mathrm{i}\eta}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this equation, the oscillator strength of the peak is given by the exciton-phonon coupling matrix elements &amp;lt;math&amp;gt;\mathcal{G}&amp;lt;/math&amp;gt; multiplied by the exciton dipoles &amp;lt;math&amp;gt;D&amp;lt;/math&amp;gt; (they are called &amp;quot;residuals&amp;quot; in Yambo). Here &amp;lt;math&amp;gt;E_\lambda&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;E_{\alpha q}&amp;lt;/math&amp;gt; are the energies of the optical and finite-momentum excitons, respectively, while &amp;lt;math&amp;gt;\Omega_{\mu q}&amp;lt;/math&amp;gt; are the phonon energies. &lt;br /&gt;
&lt;br /&gt;
Here, &amp;lt;math&amp;gt;n_{\mu q}(T)&amp;lt;/math&amp;gt; is the temperature-dependent phonon Bose-Einstein occupation function. As it can be seen, &amp;lt;math&amp;gt;s=1&amp;lt;/math&amp;gt; corresponds to processes of phonon &#039;&#039;emission&#039;&#039; (&amp;lt;math&amp;gt;\propto n(T)+1&amp;lt;/math&amp;gt;), while &amp;lt;math&amp;gt;s=-1&amp;lt;/math&amp;gt; corresponds to processes of phonon &#039;&#039;absorption&#039;&#039; (&amp;lt;math&amp;gt;\propto n(T)&amp;lt;/math&amp;gt;). Therefore, &amp;lt;math&amp;gt;I^{Sat}_{PL}(\omega;T)&amp;lt;/math&amp;gt; describes &#039;&#039;light&#039;&#039; emission by recombining excitons mediated by either &#039;&#039;phonon&#039;&#039; absorption or emission. &lt;br /&gt;
&lt;br /&gt;
The quantity &amp;lt;math&amp;gt; N_{\alpha q}(T_{exc})&amp;lt;/math&amp;gt; is the exciton occupation function. Luminescence is technically an out-of-equilibrium process, but we can assume that for very low density of excitations and in steady-state conditions, the exciton population can be approximately described by an equilibrium distribution evaluated at an effective temperature. Here, we use the Boltzmann distribution. Experimentally, &amp;lt;math&amp;gt;T_{exc}&amp;lt;/math&amp;gt; tends to coincide with the lattice temperature &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt; more or less above 100 K, while at very low temperature (&amp;lt; 10 K), &amp;lt;math&amp;gt;T_{exc}&amp;lt;/math&amp;gt; may vary between 10-50 K. It goes without saying that this needs to carefully be checked in your realistic calculations.&lt;br /&gt;
&lt;br /&gt;
Finally, the spectrum is averaged over the polarization directions of the emitted photons (&amp;lt;math&amp;gt;\epsilon=x,y,z&amp;lt;/math&amp;gt; representing the respective dipole components).&lt;br /&gt;
&lt;br /&gt;
=== Running the jobs ===&lt;br /&gt;
&lt;br /&gt;
In order to study luminescence in a paradigmatic system, we switch to bulk hexagonal boron nitride and we repeat the workflow. As you can easily see, one can think about automatizing the execution of all these calculations via scripting or more advanced tools. However, in the case of very large simulations (memory-limited or disk-space limited) or for systems whose electronic and lattice properties are fragile with respect to tiny calculation details, one must be very careful and run many basic tests.&lt;br /&gt;
&lt;br /&gt;
Fortunately, we are running a fast underconverged example. We use LDA pseudopotentials from the pseudo-dojo library and the following are the calculations steps.&lt;br /&gt;
&lt;br /&gt;
1. Input &amp;lt;code&amp;gt;hbn.scf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 &amp;amp;control&lt;br /&gt;
     calculation=&#039;scf&#039;,&lt;br /&gt;
     prefix=&#039;hBN&#039;,&lt;br /&gt;
     restart_mode=&#039;from_scratch&#039;&lt;br /&gt;
     pseudo_dir = &#039;$PSEUDO_DIR&#039;,&lt;br /&gt;
     outdir = &#039;./tmp&#039;&lt;br /&gt;
     verbosity = &#039;high&#039;&lt;br /&gt;
     wf_collect=.true.&lt;br /&gt;
 /&lt;br /&gt;
 &amp;amp;system&lt;br /&gt;
     ibrav = 4,&lt;br /&gt;
     celldm(1) = 4.703675849&lt;br /&gt;
     celldm(3) = 2.603711434&lt;br /&gt;
     nat= 4,&lt;br /&gt;
     ntyp= 2,&lt;br /&gt;
     force_symmorphic=.true.&lt;br /&gt;
     ecutwfc = 100,&lt;br /&gt;
 /&lt;br /&gt;
 &amp;amp;electrons&lt;br /&gt;
   diago_david_ndim = 2&lt;br /&gt;
   diago_full_acc=.true.&lt;br /&gt;
   diago_thr_init=5.0e-6&lt;br /&gt;
   mixing_mode = &#039;plain&#039;&lt;br /&gt;
   mixing_beta = 0.7&lt;br /&gt;
   conv_thr =  1.0d-16&lt;br /&gt;
 /&lt;br /&gt;
 ATOMIC_SPECIES&lt;br /&gt;
  B 10.81100  B_LDA_dojo.UPF&lt;br /&gt;
  N 14.00674  N_LDA_dojo.UPF&lt;br /&gt;
 ATOMIC_POSITIONS {crystal}&lt;br /&gt;
 N             0.6666666670        0.3333333330        -0.250000000000&lt;br /&gt;
 B             0.3333333330        0.6666666670        -0.250000000000&lt;br /&gt;
 B             0.6666666670        0.3333333330        0.25000000000&lt;br /&gt;
 N             0.3333333330        0.6666666670        0.25000000000&lt;br /&gt;
 K_POINTS {automatic}&lt;br /&gt;
 6 6 2 0 0 0&lt;br /&gt;
&lt;br /&gt;
 mpirun -np 4 pw.x -inp hbn.scf &amp;gt; scf.out&lt;br /&gt;
&lt;br /&gt;
2. Input &amp;lt;code&amp;gt;hbn.nscf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 &amp;amp;control&lt;br /&gt;
     calculation=&#039;nscf&#039;,&lt;br /&gt;
     prefix=&#039;hBN&#039;,&lt;br /&gt;
     restart_mode=&#039;from_scratch&#039;&lt;br /&gt;
     pseudo_dir = &#039;$PSEUDO_DIR&#039;&lt;br /&gt;
     outdir = &#039;./&#039;&lt;br /&gt;
     verbosity = &#039;high&#039;&lt;br /&gt;
     wf_collect=.true.&lt;br /&gt;
 /&lt;br /&gt;
 &amp;amp;system&lt;br /&gt;
     ibrav = 4,&lt;br /&gt;
     celldm(1) = 4.703675849&lt;br /&gt;
     celldm(3) = 2.603711434&lt;br /&gt;
     nat= 4,&lt;br /&gt;
     ntyp= 2,&lt;br /&gt;
     force_symmorphic=.true.&lt;br /&gt;
     ecutwfc = 100,&lt;br /&gt;
 	nbnd = 120&lt;br /&gt;
 /&lt;br /&gt;
 &amp;amp;electrons&lt;br /&gt;
   diago_david_ndim = 2&lt;br /&gt;
   diago_full_acc=.true.&lt;br /&gt;
   diago_thr_init=5.0e-6&lt;br /&gt;
   mixing_mode = &#039;plain&#039;&lt;br /&gt;
   mixing_beta = 0.7&lt;br /&gt;
   conv_thr =  1.0d-16&lt;br /&gt;
 /&lt;br /&gt;
 ATOMIC_SPECIES&lt;br /&gt;
  B 10.81100  B_LDA_dojo.UPF&lt;br /&gt;
  N 14.00674  N_LDA_dojo.UPF&lt;br /&gt;
 ATOMIC_POSITIONS {crystal}&lt;br /&gt;
 N             0.6666666670        0.3333333330        -0.250000000000&lt;br /&gt;
 B             0.3333333330        0.6666666670        -0.250000000000&lt;br /&gt;
 B             0.6666666670        0.3333333330        0.25000000000&lt;br /&gt;
 N             0.3333333330        0.6666666670        0.25000000000&lt;br /&gt;
 K_POINTS {automatic}&lt;br /&gt;
 6 6 2 0 0 0&lt;br /&gt;
&lt;br /&gt;
 mpirun -np 4 pw.x -inp hbn.nscf &amp;gt; nscf.out&lt;br /&gt;
&lt;br /&gt;
3. Input &amp;lt;code&amp;gt;hbn.dvscf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 hbn_dvscf&lt;br /&gt;
 &amp;amp;inputph&lt;br /&gt;
   tr2_ph=1.0d-12,&lt;br /&gt;
   verbosity=&#039;high&#039;&lt;br /&gt;
   prefix=&#039;hBN&#039;,&lt;br /&gt;
   fildvscf = &#039;hBN-dvscf&#039;,&lt;br /&gt;
   electron_phonon = &#039;dvscf&#039;,&lt;br /&gt;
   fildyn=&#039;hBN.dyn&#039;,&lt;br /&gt;
   epsil=.false.,&lt;br /&gt;
   ldisp=.true.,&lt;br /&gt;
   recover=.true.,&lt;br /&gt;
   nq1=6,&lt;br /&gt;
   nq2=6,&lt;br /&gt;
   nq3=2&lt;br /&gt;
 /&lt;br /&gt;
&lt;br /&gt;
 nohup mpirun -np 8 pw.x -inp hbn.dvscf &amp;gt; dvscf.out &amp;amp;&lt;br /&gt;
&lt;br /&gt;
4. Input &amp;lt;code&amp;gt;bse.in&amp;lt;/code&amp;gt; (we include 2 valence and 2 conduction bands):&lt;br /&gt;
&lt;br /&gt;
 optics                           # [R] Linear Response optical properties&lt;br /&gt;
 bss                              # [R] BSE solver&lt;br /&gt;
 bse                              # [R][BSE] Bethe Salpeter Equation.&lt;br /&gt;
 dipoles                          # [R] Oscillator strenghts (or dipoles)&lt;br /&gt;
 em1s&lt;br /&gt;
 DIP_CPU= &amp;quot;1 8 1&amp;quot;                      # [PARALLEL] CPUs for each role&lt;br /&gt;
 DIP_ROLEs= &amp;quot;k c v&amp;quot;                    # [PARALLEL] CPUs roles (k,c,v)&lt;br /&gt;
 DIP_Threads=0                    # [OPENMP/X] Number of threads for dipoles&lt;br /&gt;
 X_and_IO_CPU= &amp;quot;1 1 1 8 1&amp;quot;                 # [PARALLEL] CPUs for each role&lt;br /&gt;
 X_and_IO_ROLEs= &amp;quot;q g k c v&amp;quot;               # [PARALLEL] CPUs roles (q,g,k,c,v)&lt;br /&gt;
 X_and_IO_nCPU_LinAlg_INV=-1      # [PARALLEL] CPUs for Linear Algebra (if -1 it is automatically set)&lt;br /&gt;
 X_Threads=0                      # [OPENMP/X] Number of threads for response functions&lt;br /&gt;
 BS_CPU= &amp;quot;8 1 1&amp;quot;                       # [PARALLEL] CPUs for each role&lt;br /&gt;
 BS_ROLEs= &amp;quot;k eh t&amp;quot;                     # [PARALLEL] CPUs roles (k,eh,t)&lt;br /&gt;
 BS_nCPU_LinAlg_INV=-1            # [PARALLEL] CPUs for Linear Algebra (if -1 it is automatically set)&lt;br /&gt;
 BS_nCPU_LinAlg_DIAGO=-1          # [PARALLEL] CPUs for Linear Algebra (if -1 it is automatically set)&lt;br /&gt;
 X_Threads=0                      # [OPENMP/X] Number of threads for response functions&lt;br /&gt;
 K_Threads=0                      # [OPENMP/BSK] Number of threads for response functions&lt;br /&gt;
 % QpntsRXs&lt;br /&gt;
    1 | 14 |                         # [Xs] Transferred momenta&lt;br /&gt;
 %&lt;br /&gt;
 % BndsRnXs&lt;br /&gt;
    1 | 120 |                         # [Xs] Polarization function bands&lt;br /&gt;
 %&lt;br /&gt;
 NGsBlkXs= 10                Ry    # [Xs] Response block size&lt;br /&gt;
 % LongDrXs&lt;br /&gt;
  1.000000 | 1.000000 | 1.000000 |        # [Xs] [cc] Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 BSEmod= &amp;quot;resonant&amp;quot;               # [BSE] resonant/retarded/coupling&lt;br /&gt;
 BSKmod= &amp;quot;SEX&amp;quot;                    # [BSE] IP/Hartree/HF/ALDA/SEX/BSfxc&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;Lkind= &amp;quot;Lfull&amp;quot;                    # [BSE] Lbar (default) / full&amp;lt;/span&amp;gt;&lt;br /&gt;
 BSSmod= &amp;quot;d&amp;quot;                      # [BSS] (h)aydock/(d)iagonalization/(s)lepc/(i)nversion/(t)ddft`&lt;br /&gt;
 % DipBands&lt;br /&gt;
    1 | 120 |                         # [DIP] Bands range for dipoles&lt;br /&gt;
 %&lt;br /&gt;
 DipApproach= &amp;quot;G-space v&amp;quot;         # [DIP] [G-space v/R-space x/Covariant/Shifted grids]&lt;br /&gt;
 DipComputed= &amp;quot;R V P&amp;quot;             # [DIP] [default R P V; extra P2 Spin Orb]&lt;br /&gt;
 BSENGexx= 30000            Ry    # [BSK] Exchange components&lt;br /&gt;
 #ALLGexx                       # [BSS] Force the use use all RL vectors for the exchange part&lt;br /&gt;
 BSENGBlk=  9000            Ry    # [BSK] Screened interaction block size [if -1 uses all the G-vectors of W(q,G,Gp)]&lt;br /&gt;
 % KfnQP_E&lt;br /&gt;
  1.25997 | 1.08816 | 1.12683 |        # [EXTQP BSK BSS] E parameters  (c/v) eV|adim|adim&lt;br /&gt;
 %&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;% BSEQptR&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 1 | 14 |                     # [BSK] Transferred momenta range&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;%&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;% BSEBands&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;   7 | 10 |                         # [BSK] Bands range&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;%&amp;lt;/span&amp;gt;&lt;br /&gt;
 % BEnRange&lt;br /&gt;
   0.50000 | 8.00000 |         eV    # [BSS] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 % BDmRange&lt;br /&gt;
  0.050000 | 0.050000 |         eV    # [BSS] Damping range&lt;br /&gt;
 %&lt;br /&gt;
 BEnSteps= 1000                    # [BSS] Energy steps&lt;br /&gt;
 % BLongDir&lt;br /&gt;
  1.000000 | 1.000000 | 0.000000 |        # [BSS] [cc] Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 WRbsWF                        # [BSS] Write to disk excitonic the WFs&lt;br /&gt;
&lt;br /&gt;
 nohup mpirun -np 8 yambo -F bse.in -J bse_Lfull -C bse_Lfull &amp;amp;&lt;br /&gt;
&lt;br /&gt;
Importantly, since we want to describe the phonon-assisted recombination process of an *optical* exciton (i.e., emitting a transverse photon), this time we also run an additional calculation at `Q=0` omitting the nonanalytic long-range Coulomb exchange. Make a second input &amp;lt;code&amp;gt;bse_Lbar.in&amp;lt;/code&amp;gt; with the following changes: &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;Lkind= &amp;quot;Lbar&amp;quot;                    # [BSE] Lbar (default) / full&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;% BSEQptR&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 1 | 1 |                     # [BSK] Transferred momenta range&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;%&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4b. So now we make a second BSE run in a different directory specified by &amp;lt;code&amp;gt;-J&amp;lt;/code&amp;gt;. Here, we also pass to yambo the directory of the previous run as it includes the important screening databases &amp;lt;code&amp;gt;ndb.em1s*&amp;lt;/code&amp;gt; that we do not want to recompute from scratch.&lt;br /&gt;
 &lt;br /&gt;
 mpirun -np 8 yambo -F bse_Lbar.in -J bse_Lbar,bse_Lfull -C bse_Lbar&lt;br /&gt;
&lt;br /&gt;
5. Now we run &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; (with or without yambopy: in the latter case remember the option &amp;lt;code&amp;gt;-D&amp;lt;/code&amp;gt;) to get the el-ph matrix elements, particularly the &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; databases:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph path/of/dvscf/hbn.dvscf -b 7 10 -par 4 2 -D&lt;br /&gt;
&lt;br /&gt;
=== Luminescence calculation ===&lt;br /&gt;
&lt;br /&gt;
6. And finally we calculate exciton-phonon matrix elements and the luminescence spectrum in one go using a python script importing the Yambopy exciton-phonon tools: in order to do this, we need to take a look at all the necessary input variables for the formula written above.&lt;br /&gt;
&lt;br /&gt;
We can start from the script &amp;lt;code&amp;gt;luminescence.py&amp;lt;/code&amp;gt; available in &amp;lt;code&amp;gt;tutorials/exciton-phonon&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
 import numpy as np&lt;br /&gt;
 import matplotlib.pyplot as plt&lt;br /&gt;
 from yambopy.exciton_phonon.excph_luminescence import exc_ph_luminescence&lt;br /&gt;
 from yambopy.exciton_phonon.excph_input_data import exc_ph_get_inputs&lt;br /&gt;
&lt;br /&gt;
We import the necessary tools...&lt;br /&gt;
&lt;br /&gt;
 path = &#039;3D_hBN&#039;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Path to BSE calculation (Lout--&amp;gt; response is Lfull)&amp;lt;/span&amp;gt;&lt;br /&gt;
 bsepath =  f&#039;{path}/bse_Lfull&#039; &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# ndb.BS_diago_Q* databases are needed&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Path to BSE calculation for optically active exciton (Lin --&amp;gt; response is Lbar)&amp;lt;/span&amp;gt;&lt;br /&gt;
 bseBARpath =  f&#039;{path}/bse_Lbar&#039;  &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# ndb.BS_diago_Q1 database is needed&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Path to electron-phonon calculation&amp;lt;/span&amp;gt;&lt;br /&gt;
 elphpath = path &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# ndb.elph is needed&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Path to unprojected dipoles matrix elements (optional)&amp;lt;/span&amp;gt;&lt;br /&gt;
 dipolespath = bsepath &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# ndb.dipoles is needed (optional)&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Path to lattice and k-space info&amp;lt;/span&amp;gt;&lt;br /&gt;
 savepath = f&#039;{path}/SAVE&#039; &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# ns.db1 database is needed&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
... and we specify the paths to the necessary databases. Note that, if we want to perform polarization averaging, we have to recompute the excitonic dipoles in python as seen here.&lt;br /&gt;
&lt;br /&gt;
What about &amp;lt;code&amp;gt;bseBARpath&amp;lt;/code&amp;gt;? This variable points to the directory where the databases for the optical (zero-momentum) excitons &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; (which may be computed with &amp;lt;code&amp;gt;Lkind=&#039;Lbar&#039;&amp;lt;/code&amp;gt;) is located, which can be different from the directory with the full indirect exciton dispersion &amp;lt;math&amp;gt;\beta&amp;lt;/math&amp;gt; (usually computed with &amp;lt;code&amp;gt;Lkind=&#039;Lfull&#039;&amp;lt;/code&amp;gt;, however &amp;lt;code&amp;gt;Lkind=&#039;Ltilde&#039;&amp;lt;/code&amp;gt; can also be used if one is interested in &amp;quot;irreducible&amp;quot; excitons). This makes it possible to compute the coupling between different exciton kinds.&lt;br /&gt;
&lt;br /&gt;
 bands_range=[6,10] &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# 2 valence, 2 conduction bands&amp;lt;/span&amp;gt;&lt;br /&gt;
 phonons_range=[0,12] &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# All phonons&amp;lt;/span&amp;gt;&lt;br /&gt;
 nexc_out = 12 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# 12 excitonic states at each momentum (Lout)&amp;lt;/span&amp;gt;&lt;br /&gt;
 nexc_in  = 12 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# 12 excitonic states at Q=0 (Lin)&amp;lt;/span&amp;gt;&lt;br /&gt;
 T_ph  = 10 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Lattice temperature&amp;lt;/span&amp;gt;&lt;br /&gt;
 T_exc = 10 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Effective excitonic temperature&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 emin=4.4      &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Energy range and plot details (in eV)&amp;lt;/span&amp;gt;&lt;br /&gt;
 emax=4.7&lt;br /&gt;
 estep=0.0002&lt;br /&gt;
 broad = 0.005 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Broadening parameter for peak width (in eV)&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next, we specify the parameters for the calculation. We include valence bands from 7 to 10 (6 to 9 in python index) and the contribution of all 12 phonon modes. We consider 12 excitonic states for the coupling matrix elements.&lt;br /&gt;
&lt;br /&gt;
Here &amp;lt;code&amp;gt;T_ph&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;T_exc&amp;lt;/code&amp;gt; are the lattice and excitonic temperatures, respectively.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# We calculate and load all the inputs:&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# * Exciton-phonon matrix elements&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# * Excitonic dipole matrix elements&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# * Exciton energies&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# * Phonon energies&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# * We specify bse_path2=bseBARpath meaning we use Lbar calculation for Q=0 excitons&amp;lt;/span&amp;gt;&lt;br /&gt;
 input_data = exc_ph_get_inputs(savepath,elphpath,bsepath,\&lt;br /&gt;
                                bse_path2=bseBARpath,dipoles_path=dipolespath,\&lt;br /&gt;
                                nexc_in=12,nexc_out=12,\&lt;br /&gt;
                                bands_range=[6,10],phonons_range=[0,12])&lt;br /&gt;
&lt;br /&gt;
 ph_energies, exc_energies, exc_energies_in, G, exc_dipoles = input_data&lt;br /&gt;
&lt;br /&gt;
The function &amp;lt;code&amp;gt;exc_ph_get_inputs&amp;lt;/code&amp;gt; gives us all the input data for luminescence in the correct format: phonon energies, exciton energies, optical exciton energies (if needed), exciton-phonon matrix elements (calculated on the fly and printed to file), unprojected exciton dipoles (optional, calculated on the fly and printed to file).&lt;br /&gt;
The exc-ph matrix element calculation is just a wrapper of the same tools that we have tested in the above section on MoS2.&lt;br /&gt;
&lt;br /&gt;
Finally, there is the calculation of the luminescence spectrum via the function &amp;lt;code&amp;gt;exc_ph_luminescence&amp;lt;/code&amp;gt;:&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# We calculate the luminescence spectrum including the input data from before&amp;lt;/span&amp;gt;&lt;br /&gt;
 w,PL = exc_ph_luminescence(T_ph,ph_energies,exc_energies,exc_dipoles,G,\&lt;br /&gt;
                            exc_energies_in=exc_energies_in,exc_temp=T_exc,\&lt;br /&gt;
                            nexc_out=nexc_out,nexc_in=nexc_in,emin=emin,emax=emax,\&lt;br /&gt;
                            estep=estep,broad=broad)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you want to print the luminescence data for later plotting, you can also add the following line to the script:&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Save to file&amp;lt;/span&amp;gt;&lt;br /&gt;
 data = np.column_stack((w, PL))&lt;br /&gt;
 np.savetxt(&amp;quot;hBN_luminescence_12x12x1.dat&amp;quot;, data, fmt=&amp;quot;%.8f&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
It is now time to run the whole script:&lt;br /&gt;
&lt;br /&gt;
 python luminescence.py&lt;br /&gt;
 &lt;br /&gt;
NB: By using Yambopy for Step 6, we have limited the use of the Yambo code to just step 4 in the entire workflow. This option is more flexible, as it allows for a greater degree of control by the user. On the other hand the Yambo postprocessing route features a Yambo-style input that doesn&#039;t require python knowledge and the calculation is currently faster in fortran. However, the luminescence expression computed in Yambo is a slightly different than this one: it is more approximated in the description of the satellite oscillator strengths, but it explicitly includes the renormalization of the direct exciton peak. You can check the differences [[Exciton-phonon coupling and luminescence - Yambo postprocessing|here]].&lt;br /&gt;
&lt;br /&gt;
=== Results ===&lt;br /&gt;
We can plot the results of the step 6 calculation. If we do it in the same script we can add something like this:&lt;br /&gt;
 fig = plt.figure()&lt;br /&gt;
 ax = fig.add_subplot(1,1,1)&lt;br /&gt;
 ax.set_xlim(emin,emax)&lt;br /&gt;
 ax.set_ylim(0,np.max(PL)*1.1)&lt;br /&gt;
 ax.get_yaxis().set_visible(False)&lt;br /&gt;
 &lt;br /&gt;
 ax.plot(w, PL, &#039;-&#039;,c=&#039;red&#039;, label=&amp;quot;AA&#039; hBN luminescence&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
 plt.legend()&lt;br /&gt;
 plt.savefig(&#039;hBN_luminescence.png&#039;)&lt;br /&gt;
 plt.show()&lt;br /&gt;
&lt;br /&gt;
[[File:HBN luminescence satellites.png|500px|center]]&lt;br /&gt;
&lt;br /&gt;
Here, the signal corresponds to a finite-momentum exciton that recombines with the help of several different phonon modes, both optical and acoustic. Each phonon mode whose coupling with the exciton is allowed can generate a peak, and the energy shifts of these peaks with respect to the initial exciton energy correspond to the phonon energies. This result is underconverged, but the main features are all there. In the plot, we show a more converged example using a 12x12x4 grid (all the other parameters being equal). These plots can be compared with Fig. 4(a) of reference &amp;lt;ref name=&amp;quot;zanfrognini2023&amp;quot; /&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;toyozawa2003&amp;quot; &amp;gt;Toyozawa, Yutaka, and Chris Oxlade, &#039;&#039;Optical processes in solids&#039;&#039;, [https://m.booksee.org/book/1121964?force_lang=en Cambridge University Press, (2003)]. &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;lechifflart2023&#039;&amp;gt;P. Lechifflart, F. Paleari, D. Sangalli, C. Attaccalite, &#039;&#039;First-principles study of luminescence in hexagonal boron nitride single layer: Exciton-phonon coupling and the role of substrate&#039;&#039;, &lt;br /&gt;
[https://doi.org/10.1103/PhysRevMaterials.7.024006 Phys. Rev. M, &#039;&#039;&#039;7&#039;&#039;&#039; (2), 024006 (2023)]; [https://arxiv.org/abs/2212.10407 arXiv2212.1047]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;cannuccia2019&#039;&amp;gt;E. Cannuccia, B. Monserrat and C. Attaccalite, &#039;&#039;Theory of phonon-assisted luminescence in solids: Application to hexagonal boron nitride&#039;&#039;, [https://doi.org/10.1103/PhysRevB.99.081109 Phys. Rev. B &#039;&#039;&#039;99&#039;&#039;&#039;, 081109(R) (2019)]; [https://arxiv.org/abs/1807.11797 arXiv1807.11797]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;paleari2019&#039;&amp;gt;F. Paleari et al., &#039;&#039;Exciton-Phonon Coupling in the Ultraviolet Absorption and Emission Spectra of Bulk Hexagonal Boron Nitride&#039;&#039;, [https://doi.org/10.1103/PhysRevLett.122.187401 Phys. Rev. Lett. &#039;&#039;&#039;122&#039;&#039;&#039;, 187401 (2019)]; [https://arxiv.org/abs/1810.08976 arXiv1810.089776] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;chen2020&#039;&amp;gt;&#039;&#039;Exciton-Phonon Interaction and Relaxation Times from First Principles&#039;&#039;,&lt;br /&gt;
Hsiao-Yi Chen, Davide Sangalli, and Marco Bernardi, [https://doi.org/10.1103/PhysRevLett.125.107401  Phys. Rev. Lett. &#039;&#039;&#039;125&#039;&#039;&#039;, 107401 (2020)]; [https://arxiv.org/abs/2002.08913 arXiv 2002.08913 (2020)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;lechifflart2023_PhD&amp;quot;&amp;gt;P. Lechifflart, &#039;&#039;Exciton-phonon coupling and phonon-assisted luminescence in hexagonal Boron Nitride nanostructures&#039;&#039;, [https://hal.science/tel-04266805v1 PhD Thesis, University of Marseille (2023)]; [https://www.yambo-code.eu/wiki/images/5/54/These_final.pdf From the yambo website]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;paleari2019_PhD&#039;&amp;gt;F. Paleari, &#039;&#039;First-principles approaches to the description of indirect absorption and luminescence spectroscopy: exciton-phonon coupling in hexagonal boron nitride&#039;&#039;, [https://wwwen.uni.lu/research/fstm/dphyms/people/fulvio_paleari PhD thesis, University of Luxembourg (2019)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;zanfrognini2023&#039;&amp;gt;M. Zanfrognini et al., &#039;&#039;Distinguishing different stackings in layered materials via luminescence spectroscopy&#039;&#039;, [https://doi.org/10.1103/PhysRevLett.131.206902 Phys. Rev. Lett. &#039;&#039;&#039;131&#039;&#039;&#039;, 206902 (2023)]; [https://arxiv.org/abs/2305.17554 arXiv 2305.17554] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;marini2024&#039;&amp;gt;G. Marini, M. Calandra, P. Cudazzo, &#039;&#039;Optical absorption and photoluminescence of single layer boron nitride from a first principles cumulant approach&#039;&#039;, [https://doi.org/10.1021/acs.nanolett.4c00669 Nano Lett., &#039;&#039;&#039;24&#039;&#039;&#039;, 20, 6017 (2024)]; [https://arxiv.org/abs/2402.03826 arXiv 2402.03826 (2024)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;antonius2017&#039;&amp;gt;G. Antonius, S. G. Louie, &#039;&#039;Theory of exciton-phonon coupling&#039;&#039;, [https://doi.org/10.1103/PhysRevB.105.085111 Phys. Rev. B, &#039;&#039;&#039;105&#039;&#039;&#039;, 085111 (2022)]; [https://arxiv.org/abs/1705.04245 arXiv1705.04245 (2017)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;paleari2022&#039;&amp;gt; F. Paleari, and A. Marini, &#039;&#039;Exciton-phonon interaction calls for a revision of the “exciton” concept&#039;&#039;, [https://doi.org/10.1103/PhysRevB.106.125403 Phys. Rev. B, &#039;&#039;&#039;106&#039;&#039;&#039;, 125403 (2022)]; [https://arxiv.org/abs/2205.02783 arXiv 2205.02783]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;cudazzo2020&#039;&amp;gt; P. Cudazzo, &#039;&#039;First-principles description of the exciton-phonon interaction: A cumulant approach&#039;&#039;, [https://doi.org/10.1103/PhysRevB.102.045136 Phys. Rev. B, &#039;&#039;&#039;102&#039;&#039;&#039;, 045136 (2020)]; [https://orbilu.uni.lu/bitstream/10993/44769/1/main.pdf Open access pdf from Luxembourg University]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;chan2023&#039;&amp;gt;Y-h Chan, J. B. Haber, M. H. Naik, J. B. Neaton, D. Y. Qiu, F. H. da Jornada, S. G. Louie, &#039;&#039;Exciton Lifetime and Optical Line Width Profile via Exciton–Phonon Interactions: Theory and First-Principles Calculations for Monolayer MoS2&#039;&#039;, [https://doi.org/10.1021/acs.nanolett.3c00732 Nano Lett., &#039;&#039;&#039;23&#039;&#039;&#039;, 9 (2023)]; [https://arxiv.org/abs/2212.08451 arXiv 2212.08451 (2023)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;murali2025&#039;&amp;gt;M. Nalabothula, S. Reichardt, L. Wirtz, &#039;&#039;Origin of Interlayer Exciton–Phonon Coupling in 2D Heterostructures&#039;&#039;, [https://doi.org/10.1021/acs.nanolett.5c00355 Nano Lett., &#039;&#039;&#039;25&#039;&#039;&#039;, 15 (2025)], [https://arxiv.org/abs/2407.16111 arXiv 2407.16111 (2025)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>FulvioPaleari</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Exciton-phonon_coupling_and_luminescence&amp;diff=9339</id>
		<title>Exciton-phonon coupling and luminescence</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Exciton-phonon_coupling_and_luminescence&amp;diff=9339"/>
		<updated>2026-03-13T14:44:28Z</updated>

		<summary type="html">&lt;p&gt;FulvioPaleari: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:Tdgw-phonon-usc-01-1024x829.jpg| 400px | right | Caption=(c) Zhenglu Li, University of Southern California]]&lt;br /&gt;
&lt;br /&gt;
In this advanced tutorial, we will calculate exciton-phonon interactions from first principles by interfacing DFPT (for phonon calculations) and BSE (for exciton calculations).&lt;br /&gt;
&lt;br /&gt;
The DFTP calculations are run with Quantum ESPRESSO, while the many-body GW-BSE calculations are run with Yambo. Finally, the exciton-phonon interaction will be obtained by combining and postprocessing the databases computed in the two previous runs. The great advantage of this workflow is that the calculations can be run in the irreducible Brillouin zones both for the electronic momenta (&#039;&#039;&#039;k&#039;&#039;&#039;) and the transfer momenta (&#039;&#039;&#039;Q&#039;&#039;&#039;, &#039;&#039;&#039;q&#039;&#039;&#039;) of excitons and phonons, thus speeding up considerably the jobs while reducing the IO and memory load.&lt;br /&gt;
&lt;br /&gt;
We will first compute the exciton-phonon coupling matrix elements: these are the building blocks needed to construct experimental observables such as phonon-assisted optical spectra (such as luminescence), Raman spectra and exciton lifetimes. We will do this in the case of monolayer MoS&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;, a 2D system with large spin-orbit interaction.&lt;br /&gt;
&lt;br /&gt;
As an example of application, we will consider the case of phonon-assisted luminescence. We will do this in the case of bulk hBN, a layered indirect insulator with strong electron-phonon coupling.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; this tutorial will be updated when new exc-ph tools become available in Yambopy (including full-python postprocessing, Raman spectra, interpolated lifetimes, etc).&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
This is an advanced topic: we assume that you already know something about the theory&amp;lt;ref name=&amp;quot;toyozawa2003&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;antonius2017&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;cudazzo2020&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;paleari2019_PhD&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;paleari2022&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;lechifflart2023_PhD&amp;quot; /&amp;gt; and applications&amp;lt;ref name=&amp;quot;paleari2019&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;cannuccia2019&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;chen2020&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;zanfrognini2023&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;lechifflart2023&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;chan2023&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;marini2024&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;murali2025&amp;quot; /&amp;gt; of exciton-phonon physics. &lt;br /&gt;
&lt;br /&gt;
Also, we assume that you already know how to run both a basic &#039;&#039;&#039;Yambo&#039;&#039;&#039; GW-BSE calculation and a DFPT phonon calculation with &#039;&#039;&#039;Quantum ESPRESSO&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Besides the QE executables &amp;lt;code&amp;gt;pw.x&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ph.x&amp;lt;/code&amp;gt;, we also use the yambo phonon-specific executable &amp;lt;code&amp;gt;yambo_ph&amp;lt;/code&amp;gt; and the python utility &#039;&#039;&#039;Yambopy&#039;&#039;&#039;. The auxiliary code &#039;&#039;&#039;LetzElPhC&#039;&#039;&#039; (executable &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt;) will be used to obtain the electron-phonon matrix elements by reading the same electronic wavefunctions used by Yambo (and stored in the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory), while also making full use of crystal symmetries. [https://github.com/yambo-code/LetzElPhC LetzElPhC] will be run by Yambopy, but it must nonetheless be installed. Finally, the exciton-phonon properties can be computed either using &amp;lt;code&amp;gt;yambo_ph&amp;lt;/code&amp;gt; or using Yambopy itself. Both cases will be covered in this tutorial.&lt;br /&gt;
&lt;br /&gt;
[[File:Workflow scheme.png|800px|center]]&lt;br /&gt;
&lt;br /&gt;
== Step 0: Pseudopotentials, equilibrium structure and convergence ==&lt;br /&gt;
&lt;br /&gt;
In a real calculation, it is important to ensure that both the pseudopotential and the lattice parameters that we are using are compatible and perform well for the electronic excited states and for the lattice vibrations simultaneously. Furthermore, you have to make sure that the wave function cutoff &amp;lt;code&amp;gt;ecutwfc&amp;lt;/code&amp;gt; is converged with respect to the DFPT step and not just to the DFT one. This is in addition to the other customary convergence tests for DFT, DFPT, GW and BSE calculations.&lt;br /&gt;
&lt;br /&gt;
This is often the most time-demanding step when starting on a new system.&lt;br /&gt;
&lt;br /&gt;
For the sake of this tutorial, we assume that we have already done all these tests and we are starting the final workflow to get the exciton-phonon properties.&lt;br /&gt;
&lt;br /&gt;
== Step 1: scf calculation ==&lt;br /&gt;
&lt;br /&gt;
First of all, we run a standard scf calculation with &amp;lt;code&amp;gt;pw.x&amp;lt;/code&amp;gt; for Yambo. We stick with non-symmorphic symmetries. At the end, we will have the QE &amp;lt;code&amp;gt;save&amp;lt;/code&amp;gt; directory.&lt;br /&gt;
&lt;br /&gt;
This is the input &amp;lt;code&amp;gt;mos2.scf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 &amp;amp;control&lt;br /&gt;
           wf_collect = .true.,&lt;br /&gt;
          calculation = &amp;quot;scf&amp;quot;,&lt;br /&gt;
            verbosity = &#039;high&#039;,&lt;br /&gt;
           pseudo_dir = &#039;$PSEUDO_DIR&#039;,&lt;br /&gt;
               prefix = &amp;quot;mos2&amp;quot;,&lt;br /&gt;
               outdir = &#039;.&#039;,&lt;br /&gt;
  /&amp;amp;end&lt;br /&gt;
  &amp;amp;system&lt;br /&gt;
              ecutwfc = 100.0,&lt;br /&gt;
          occupations = &#039;fixed&#039;,&lt;br /&gt;
                ibrav = 4,&lt;br /&gt;
            celldm(1) = 5.9000811881,&lt;br /&gt;
            celldm(3) = 6.7795677253,&lt;br /&gt;
                  nat = 3,&lt;br /&gt;
                 ntyp = 2,&lt;br /&gt;
             lspinorb = .true.&lt;br /&gt;
             noncolin = .true.&lt;br /&gt;
             assume_isolated = &#039;2D&#039;&lt;br /&gt;
         force_symmorphic = .true.&lt;br /&gt;
  /&amp;amp;end&lt;br /&gt;
  &amp;amp;electrons&lt;br /&gt;
     electron_maxstep = 200,&lt;br /&gt;
          mixing_beta = 0.7,&lt;br /&gt;
             conv_thr = 1.d-08,&lt;br /&gt;
  /&amp;amp;end&lt;br /&gt;
   ATOMIC_SPECIES&lt;br /&gt;
    Mo  95.940      Mo_ONCV_PBE_FR-1.0.upf&lt;br /&gt;
    S    32.065     S_ONCV_PBE_FR-1.1.upf&lt;br /&gt;
   ATOMIC_POSITIONS { crystal }&lt;br /&gt;
 Mo       0.333333333   0.666666667   0.000000000&lt;br /&gt;
 S        0.666666667   0.333333333   0.073413577&lt;br /&gt;
 S        0.666666667   0.333333333  -0.073413577&lt;br /&gt;
  K_POINTS { automatic }&lt;br /&gt;
 6 6 1 0 0 0&lt;br /&gt;
&lt;br /&gt;
Here we are using full relativistic pseudopotentials from the SG-15 database.&lt;br /&gt;
&lt;br /&gt;
We can run it on our machine (for example using 4 MPI tasks) as:&lt;br /&gt;
&lt;br /&gt;
 mpirun -np 4 pw.x -inp mos2.scf &amp;gt; scf.out&lt;br /&gt;
&lt;br /&gt;
== Step 2: nscf calculation for Yambo ==&lt;br /&gt;
&lt;br /&gt;
Copy the QE &amp;lt;code&amp;gt;save&amp;lt;/code&amp;gt; directory from the scf calculation and run the nscf calculation for any number of empty states, with the correct &amp;lt;code&amp;gt;k&amp;lt;/code&amp;gt;-grid we want to use in Yambo. Here we are using a badly underconverged grid of 6x6x1.&lt;br /&gt;
&lt;br /&gt;
This reciprocal-space grid will also match the momentum transfer &amp;lt;code&amp;gt;q&amp;lt;/code&amp;gt; grid on which excitons and phonons will be defined!&lt;br /&gt;
&lt;br /&gt;
The electronic wavefunctions computed at this step and stored in the new nscf &amp;lt;code&amp;gt;save&amp;lt;/code&amp;gt; directory will be used both by Yambo and by the electron-phonon code: this is important because using different sets of wavefunctions would lead to a phase mismatch issue in the exciton-phonon matrix elements.&lt;br /&gt;
&lt;br /&gt;
The nscf input &amp;lt;code&amp;gt;mos2.nscf&amp;lt;/code&amp;gt; is&lt;br /&gt;
 &amp;amp;control&lt;br /&gt;
           wf_collect = .true.,&lt;br /&gt;
          calculation = &amp;quot;nscf&amp;quot;,&lt;br /&gt;
            verbosity = &#039;high&#039;,&lt;br /&gt;
           pseudo_dir = &#039;$PSEUDO_DIR&#039;,&lt;br /&gt;
               prefix = &amp;quot;mos2&amp;quot;,&lt;br /&gt;
               outdir = &#039;.&#039;,&lt;br /&gt;
  /&amp;amp;end&lt;br /&gt;
  &amp;amp;system&lt;br /&gt;
              ecutwfc = 100.0,&lt;br /&gt;
          occupations = &#039;fixed&#039;,&lt;br /&gt;
                ibrav = 4,&lt;br /&gt;
            celldm(1) = 5.9000811881,&lt;br /&gt;
            celldm(3) = 6.7795677253,&lt;br /&gt;
                  nat = 3,&lt;br /&gt;
                 ntyp = 2,&lt;br /&gt;
             lspinorb = .true.&lt;br /&gt;
             noncolin = .true.&lt;br /&gt;
                nbnd  = 250&lt;br /&gt;
             assume_isolated = &#039;2D&#039;&lt;br /&gt;
         force_symmorphic = .true.&lt;br /&gt;
  /&amp;amp;end&lt;br /&gt;
  &amp;amp;electrons&lt;br /&gt;
     electron_maxstep = 200,&lt;br /&gt;
          mixing_beta = 0.7,&lt;br /&gt;
             conv_thr = 1.d-08,&lt;br /&gt;
  /&amp;amp;end&lt;br /&gt;
   ATOMIC_SPECIES&lt;br /&gt;
    Mo  95.940      Mo_ONCV_PBE_FR-1.0.upf&lt;br /&gt;
    S    32.065     S_ONCV_PBE_FR-1.1.upf&lt;br /&gt;
   ATOMIC_POSITIONS { crystal }&lt;br /&gt;
 Mo       0.333333333   0.666666667   0.000000000&lt;br /&gt;
 S        0.666666667   0.333333333   0.073413577&lt;br /&gt;
 S        0.666666667   0.333333333  -0.073413577&lt;br /&gt;
  K_POINTS { automatic }&lt;br /&gt;
 6 6 1 0 0 0&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Again, we run the calculation&lt;br /&gt;
&lt;br /&gt;
 mpirun -np 4 pw.x -inp mos2.nscf &amp;gt; nscf.out&lt;br /&gt;
&lt;br /&gt;
== Step 3: dvscf phonon calculation ==&lt;br /&gt;
&lt;br /&gt;
Now we run the phonon calculation.&lt;br /&gt;
&lt;br /&gt;
Copy the &amp;lt;code&amp;gt;save&amp;lt;/code&amp;gt; directory from the &#039;&#039;&#039;scf&#039;&#039;&#039; calculation and run &amp;lt;code&amp;gt;ph.x&amp;lt;/code&amp;gt; for a dvscf calculation with a standard &amp;lt;code&amp;gt;q&amp;lt;/code&amp;gt;-grid matching the &amp;lt;code&amp;gt;k&amp;lt;/code&amp;gt;-grid we wanna use in Yambo.&lt;br /&gt;
&lt;br /&gt;
At the end, we will have the &amp;lt;code&amp;gt;_ph0&amp;lt;/code&amp;gt; directory containing the variation of the self-consistent potential, &amp;lt;math&amp;gt;\Delta V_{SCF}(q)&amp;lt;/math&amp;gt;, and the &amp;lt;code&amp;gt;*.dyn&amp;lt;/code&amp;gt; files with the phonon energies and eigenvectors.&lt;br /&gt;
&lt;br /&gt;
NB: one could further refine the phonon energies by enforcing the acoustic sum rule, including non-analytic long-range contributions, interpolating to finer grids... all of this can be done within Quantum ESPRESSO and will not be covered in this version of the tutorial.&lt;br /&gt;
&lt;br /&gt;
The input is &amp;lt;code&amp;gt;mos2.dvscf&amp;lt;/code&amp;gt;:&lt;br /&gt;
 &lt;br /&gt;
 mos2_dvscf&lt;br /&gt;
 &amp;amp;inputph&lt;br /&gt;
   tr2_ph=1.0d-12,&lt;br /&gt;
   verbosity=&#039;high&#039;&lt;br /&gt;
   prefix=&#039;mos2&#039;,&lt;br /&gt;
   fildvscf = &#039;mos2-dvscf&#039;,&lt;br /&gt;
   electron_phonon = &#039;dvscf&#039;,&lt;br /&gt;
   fildyn=&#039;mos2.dyn&#039;,&lt;br /&gt;
   epsil=.false.,&lt;br /&gt;
   ldisp=.true.,&lt;br /&gt;
   recover=.true.,&lt;br /&gt;
   nq1=6,&lt;br /&gt;
   nq2=6,&lt;br /&gt;
   nq3=1&lt;br /&gt;
 /&lt;br /&gt;
&lt;br /&gt;
And now we run as&lt;br /&gt;
&lt;br /&gt;
 nohup mpirun -np 8 ph.x -inp mos2.dvscf &amp;gt; dvscf.out &amp;amp;&lt;br /&gt;
&lt;br /&gt;
This time we use nohup and more processes because this calculation may take some time. It is a good idea to set &amp;lt;code&amp;gt;recover=.true.&amp;lt;/code&amp;gt; as in a real calculation you will easily breach walltime, and in this way you can safely restart.&lt;br /&gt;
&lt;br /&gt;
== Step 4: create Yambo &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory ==&lt;br /&gt;
&lt;br /&gt;
This is just the standard Yambo initialization: run &lt;br /&gt;
 &lt;br /&gt;
 p2y &lt;br /&gt;
&lt;br /&gt;
and then &lt;br /&gt;
&lt;br /&gt;
 yambo &lt;br /&gt;
&lt;br /&gt;
in the &#039;&#039;&#039;nscf&#039;&#039;&#039; &amp;lt;code&amp;gt;save&amp;lt;/code&amp;gt; folder and then move the newly generated &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory to a convenient place.&lt;br /&gt;
&lt;br /&gt;
== Step 5: run a BSE calculation ==&lt;br /&gt;
&lt;br /&gt;
Now we switch from QE to Yambo. Here, we forgo the GW step for simplicity (we can use a scissor operator to open the band gap).&lt;br /&gt;
&lt;br /&gt;
This calculation has a couple of differences with respect to a standard BSE calculation for optical absorption. We can look at the input file &amp;lt;code&amp;gt;bse.in&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Runlevels&amp;lt;/span&amp;gt;&lt;br /&gt;
 optics                       # [R OPT] Optics&lt;br /&gt;
 rim_cut                      # [R RIM CUT] Coulomb potential&lt;br /&gt;
 bss                          # [R BSS] Bethe Salpeter Equation solver&lt;br /&gt;
 em1s                         # [R Xs] Static Inverse Dielectric Matrix&lt;br /&gt;
 bse                          # [R BSE] Bethe Salpeter Equation.&lt;br /&gt;
 bsk                          # [R BSK] Bethe Salpeter Equation kernel&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# RIM and cutoff settings&amp;lt;/span&amp;gt;&lt;br /&gt;
 RandQpts=1000000             # [RIM] Number of random q-points in the BZ&lt;br /&gt;
 RandGvec= 100            RL    # [RIM] Coulomb interaction RS components&lt;br /&gt;
 CUTGeo= &amp;quot;slab z&amp;quot;               # [CUT] Coulomb Cutoff geometry: box/cylinder/sphere X/Y/Z/XY..&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Static screening&amp;lt;/span&amp;gt;&lt;br /&gt;
 X_and_IO_CPU= &amp;quot;1 1 4 2 1&amp;quot;       # [PARALLEL] CPUs for each role&lt;br /&gt;
 X_and_IO_ROLEs= &amp;quot;q g k c v&amp;quot;      # [PARALLEL] CPUs roles (q,g,k,c,v)&lt;br /&gt;
 X_and_IO_nCPU_LinAlg_INV=-1      # [PARALLEL] CPUs for Linear Algebra (if -1 it is automatically set)&lt;br /&gt;
 Chimod= &amp;quot;hartree&amp;quot;            # [X] IP/Hartree/ALDA/LRC/BSfxc&lt;br /&gt;
 % BndsRnXs&lt;br /&gt;
    1 |  200 |                 # [Xs] Polarization function bands&lt;br /&gt;
 %&lt;br /&gt;
 % LongDrXs&lt;br /&gt;
  1.000000 | 1.000000 | 1.000000 |        # [Xs] [cc] Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 NGsBlkXs= 8000            mRy    # [Xs] Response block size&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# BSE&amp;lt;/span&amp;gt;&lt;br /&gt;
 BS_CPU= &amp;quot;4.1.2&amp;quot;                   # [PARALLEL] CPUs for each role&lt;br /&gt;
 BS_ROLEs= &amp;quot;k.eh.t&amp;quot;                 # [PARALLEL] CPUs roles (k,eh,t)&lt;br /&gt;
 BS_nCPU_diago=4              # [PARALLEL] CPUs for matrix diagonalization&lt;br /&gt;
 BSEmod= &amp;quot;causal&amp;quot;             # [BSE] resonant/causal/coupling&lt;br /&gt;
 BSKmod= &amp;quot;SEX&amp;quot;                # [BSE] IP/Hartree/HF/ALDA/SEX/BSfxc&lt;br /&gt;
 BSSmod= &amp;quot;d&amp;quot;                  # [BSS] (h)aydock/(d)iagonalization/(s)lepc/(i)nversion/(t)ddft`&lt;br /&gt;
 BSENGexx=  40000      mRy    # [BSK] Exchange components&lt;br /&gt;
 ALLGexx                      # [BSS] Force the use use all RL vectors for the exchange part&lt;br /&gt;
 BSENGBlk=  8000       mRy    # [BSK] Screened interaction block size&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;Lkind=&amp;quot;full&amp;quot;                  #[BSE,X] bar(default)/full/tilde&amp;lt;/span&amp;gt;&lt;br /&gt;
 % KfnQP_E&lt;br /&gt;
  1.000000 | 1.000000 | 1.000000 |        # [EXTQP BSK BSS] E parameters  (c/v) eV|adim|adim&lt;br /&gt;
 %&lt;br /&gt;
 % BEnRange&lt;br /&gt;
   0.00000 |  4.00000 | eV    # [BSS] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 % BDmRange&lt;br /&gt;
   0.05000 |  0.05000 | eV    # [BSS] Damping range&lt;br /&gt;
 %&lt;br /&gt;
 BEnSteps= 2000               # [BSS] Energy steps&lt;br /&gt;
 % BLongDir&lt;br /&gt;
  1.000000 | 0.000000 | 0.000000 |        # [BSS] [cc] Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;% BSEQptR&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 1 | 7 |                     # [BSK] Transferred momenta range&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;%&amp;lt;/span&amp;gt;&lt;br /&gt;
 % BSEBands&lt;br /&gt;
    25 |  28 |                 # [BSK] Bands range&lt;br /&gt;
 %&lt;br /&gt;
 WRbsWF                      # [BSS] Write to disk excitonic the FWs&lt;br /&gt;
 &lt;br /&gt;
This file was generated using the command: &amp;lt;code&amp;gt; yambo -X s -o b -k sex -y d -r&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
First of all, we compute the excitons for all the momenta in the irreducible Brillouin zone for our discrete grid via the &amp;lt;code&amp;gt;BSEQptR&amp;lt;/code&amp;gt; variable. This will be a &#039;&#039;&#039;finite-momentum&#039;&#039;&#039; BSE calculation, analogous to the phonon one.&lt;br /&gt;
&lt;br /&gt;
Second, we change the variable &amp;lt;code&amp;gt;Lkind&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;bar&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;full&amp;lt;/code&amp;gt;. In Yambo, &amp;lt;code&amp;gt;Lkind=&amp;quot;bar&amp;quot;&amp;lt;/code&amp;gt;, which is the default for optical absorption, means that we are computing the excitonic response function without the long-range component of the exchange interaction. This cannot be used when computing the exciton momentum dependence, where the long-range exchange interaction can play a role, therefore we have to include it with &amp;lt;code&amp;gt;Lkind=&amp;quot;full&amp;quot;&amp;lt;/code&amp;gt;. This allows for the calculation of the excitonic longitudinal-transverse splitting (in 3D systems) as well.&lt;br /&gt;
&lt;br /&gt;
We can now run the code:&lt;br /&gt;
&lt;br /&gt;
 nohup mpirun -np 8 yambo -F bse.in -J bse_Lfull -C bse_Lfull &amp;amp;&lt;br /&gt;
&lt;br /&gt;
At the end of the calculation, we have obtained the &amp;lt;code&amp;gt;ndb.BS_diago_Q*&amp;lt;/code&amp;gt; databases inside the directory &amp;lt;code&amp;gt;bse_Lfull&amp;lt;/code&amp;gt;. They contain information on the exciton energies and wavefunctions at each momentum. Do not forget to check the report and logs of your calculation in the same directory to make sure that the code is doing what you want.&lt;br /&gt;
&lt;br /&gt;
== Step 6: obtain the electron-phonon matrix elements ==&lt;br /&gt;
&lt;br /&gt;
We have finished the heavy simulations. Now it&#039;s time for the postprocessing. The first order of business is the reconstruction of the electron-phonon coupling matrix elements from the dvscf results and the electronic wavefunctions.&lt;br /&gt;
&lt;br /&gt;
In order to do this, we will run the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable of the &#039;&#039;&#039;LetzElPhC&#039;&#039;&#039; code. We will run via command line using yambopy, although it will be instructive to have look at the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; input files later.&lt;br /&gt;
&lt;br /&gt;
We run in the same directory where the Yambo &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; is (remember than you can also virtually move it with a symbolic link).&lt;br /&gt;
&lt;br /&gt;
Type:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y&lt;br /&gt;
&lt;br /&gt;
to see the help for the calculation. Have a look at the various flags and their description.&lt;br /&gt;
For example, if we want to do a serial run of LetzElPhC for bands from &amp;lt;math&amp;gt;n_i&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;n_f&amp;lt;/math&amp;gt;, we should type:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph path/of/ph_input.in -b n_i n_f&lt;br /&gt;
&lt;br /&gt;
Here &amp;lt;math&amp;gt;n_i&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;n_f&amp;lt;/math&amp;gt; are integers representing the initial and final band indices. &#039;&#039;&#039;Please note&#039;&#039;&#039;: in this case, the band index starts from 1 and the the interval of bands read by the code is &amp;lt;math&amp;gt;[n_i,n_f]&amp;lt;/math&amp;gt; including the extrema of the interval.&lt;br /&gt;
&lt;br /&gt;
These should coincide with those used for the Bethe-Salpeter kernel, i.e. those specified in the &amp;lt;code&amp;gt;BSEBands&amp;lt;/code&amp;gt; variable of the BSE input file (this is not strictly necessary, but certainly efficient since these calculations use a lot of disk space). &lt;br /&gt;
&lt;br /&gt;
For our system, we want to do a parallel calculation with 4 qpools and 2 kpools. In addition, we want to explicitly specify the path of the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable and avoid automatically deleting the LetzElPhC data. So we type:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph path/of/dvscf/mos2.dvscf -b 25 28 -par 4 2 -lelphc path/to/lelphc_exe&lt;br /&gt;
&lt;br /&gt;
At the end, check your directory: you should find the &amp;lt;code&amp;gt;lelphc.in&amp;lt;/code&amp;gt; input file that was run, let&#039;s inspect it: &lt;br /&gt;
&lt;br /&gt;
 # LetzElPhC input for yambo generated by yambopy&lt;br /&gt;
 nqpool      = 2&lt;br /&gt;
 nkpool      = 4&lt;br /&gt;
 start_bnd   = 25&lt;br /&gt;
 end_bnd     = 28&lt;br /&gt;
 save_dir    = ./SAVE&lt;br /&gt;
 kernel      = dfpt&lt;br /&gt;
 ph_save_dir = dvscf/ph_save&lt;br /&gt;
 convention = yambo&lt;br /&gt;
&lt;br /&gt;
Notice the variable &amp;lt;code&amp;gt;convention=yambo&amp;lt;/code&amp;gt;: what does it mean? At variance with QE and many other codes, Yambo uses the &amp;quot;backward&amp;quot; momentum transfer convention for electronic scatterings. That is, an electronic transition goes from band &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; and momentum &amp;lt;math&amp;gt;k-q&amp;lt;/math&amp;gt; to band &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; and momentum &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;. In the &amp;quot;forward&amp;quot; momentum transfer convention (the more standard one), the transitions go from &amp;lt;math&amp;gt;nk&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;mk+q&amp;lt;/math&amp;gt;. Therefore, this variable ensures that the electron-phonon coupling matrix elements are computed as &amp;lt;math&amp;gt;\langle mk|dV|nk-q\rangle&amp;lt;/math&amp;gt;. This will have consequences also in the formulation of the &#039;&#039;exciton&#039;&#039;-phonon coupling matrix element.&lt;br /&gt;
&lt;br /&gt;
You will also find a &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; database that contains the computed electron-phonon matrix elements, in the output format of &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In addition, if you check the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; folder:&lt;br /&gt;
&lt;br /&gt;
 ls SAVE/ndb.elph_gkkp*&lt;br /&gt;
&lt;br /&gt;
you will see that yambopy has created the Yambo-compatible electron-phonon databases.&lt;br /&gt;
&lt;br /&gt;
If you want to run LetzElPhC directly, without using yambopy, you can refer to its [[https://gitlab.com/lumen-code/LetzElPhC/-/blob/main/docs/main.pdf?ref_type=heads|user guide]].&lt;br /&gt;
Keep in mind that in this case, in order to convert the database to the &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases of Yambo, you will then need a couple of lines of python using the Yambopy class &amp;lt;code&amp;gt;ConvertElectronPhononDB&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;yambopy/letzelph_interface/lelph2y.py&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t need the &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases -- e.g., because you are doing the exc-ph postprocessing with yambopy -- you can run &amp;lt;code&amp;gt;yambopy l2y ...&amp;lt;/code&amp;gt; with the &amp;lt;code&amp;gt;--no_gkkp&amp;lt;/code&amp;gt; option.&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t need the &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; databases -- e.g., because you are using &amp;lt;code&amp;gt;yambo_ph&amp;lt;/code&amp;gt; for the exc-ph part -- you can run &amp;lt;code&amp;gt;yambopy l2y ...&amp;lt;/code&amp;gt; with the &amp;lt;code&amp;gt;--no_lelphc_dbs&amp;lt;/code&amp;gt; option.&lt;br /&gt;
&lt;br /&gt;
== Step 7: Obtain the exciton-phonon coupling ==&lt;br /&gt;
&lt;br /&gt;
Now, we can finally access our basic building block for exciton-phonon physics. This could be done entirely in python (using &#039;&#039;&#039;Yambopy&#039;&#039;&#039;), or by running &#039;&#039;&#039;Yambo&#039;&#039;&#039;. &lt;br /&gt;
&lt;br /&gt;
* For the &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&#039;&#039;&#039;Yambo postprocessing&#039;&#039;&#039;&amp;lt;/span&amp;gt; case (running yambo inputs with the &amp;lt;code&amp;gt;yambo_ph&amp;lt;/code&amp;gt; executable), &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&#039;&#039;&#039;follow the alternative route to Steps 7-8 [[Exciton-phonon coupling and luminescence - Yambo postprocessing|at this link]]&#039;&#039;&#039;&amp;lt;/span&amp;gt;.&lt;br /&gt;
* For the &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&#039;&#039;&#039;Yambopy postprocessing&#039;&#039;&#039;&amp;lt;/span&amp;gt; case (using flexible python scripting), &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&#039;&#039;&#039;keep following Steps 7-8 on this page&#039;&#039;&#039;&amp;lt;/span&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Our objective is obtaining the following quantity: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\mathcal{G}^\mu_{\alpha\lambda}(0,q)=\sum_{vv^\prime c k} A^{\alpha, *}_{cv^\prime} (k, q) g_{vv^\prime}^\mu (k,q) A^{\lambda}_{cv}(k,0) - \sum_{cc^\prime vk} A^{\alpha, *}_{c^\prime v} (k+q, q) g_{c^\prime c}^\mu (k+q,q) A^{\lambda}_{cv}(k, 0)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here, &amp;lt;math&amp;gt;A^{\alpha}_{cv}(k,q)&amp;lt;/math&amp;gt; are the exciton coefficients extracted from the eigenvector of the two-particles Hamiltonian during the BSE calculation in step 5, while &amp;lt;math&amp;gt;g_{nm}^\mu (k,q)&amp;lt;/math&amp;gt; are the electron-phonon coupling matrix elements obtained in step 6. As you can see, the exciton &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; undergoes phonon-mediated scattering to state &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; via phonon mode &amp;lt;math&amp;gt;\mu&amp;lt;/math&amp;gt;. The scattering can happen for the hole (valence, &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt;) or for the electron (conduction, &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
NB: &lt;br /&gt;
&lt;br /&gt;
(1) This is written in the &amp;quot;backward&amp;quot; momentum transfer convention used by Yambo. The momentum dependence is different in the &amp;quot;forward&amp;quot; transfer convention. &lt;br /&gt;
&lt;br /&gt;
(2) For simplicity, this is written for zero initial exciton momentum. This means that one of the two states involved in the phonon-mediated scattering process will be in the optical limit (and possibly an optically generated exciton), while the other state can have any momentum: this momentum will be the same as the phonon one. This matrix element can be used to describe phonon-assisted absorption and emission spectra.&lt;br /&gt;
&lt;br /&gt;
In order to calculate this quantity using python, we need the &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; databases natively generated by the &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; code, as well as the BSE databases &amp;lt;code&amp;gt;ndb.BS_diago_Q*&amp;lt;/code&amp;gt; containing the information on exciton wavefunctions and energies.&lt;br /&gt;
&lt;br /&gt;
Next, we write a python user script importing the yambopy exciton-phonon tools. You can find a version of this script in &amp;lt;code&amp;gt;yambopy/tutorials/exciton-phonon/calculate_excph.py&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
 import numpy as np &lt;br /&gt;
 from yambopy import YamboLatticeDB,YamboWFDB,LetzElphElectronPhononDB &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;#Specific Yambopy dbs loading classes&amp;lt;/span&amp;gt;&lt;br /&gt;
 from yambopy.exciton_phonon.excph_matrix_elements import exciton_phonon_matelem &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;#Specific exc-ph functions&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 path = &#039;1L_MoS2&#039;&lt;br /&gt;
 bands_range=[24,28] &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# 2 valence bands, 2 conduction bands&amp;lt;/span&amp;gt;&lt;br /&gt;
 nexc = 12 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# number of excitonic states&amp;lt;/span&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 bsepath    = f&#039;{path}/bse-allq_full&#039; &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Path to BSE calculation (Lin=Lout)&amp;lt;/span&amp;gt;&lt;br /&gt;
 savepath   = f&#039;{path}/SAVE&#039;     &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Yambo SAVE&amp;lt;/span&amp;gt;&lt;br /&gt;
 ndb_elph   = f&#039;{path}/ndb.elph&#039; &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# LetzElPhC electron-phonon database (any convention)&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Read lattice&amp;lt;/span&amp;gt;&lt;br /&gt;
 lattice = YamboLatticeDB.from_db_file(filename=f&#039;{savepath}/ns.db1&#039;)&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Read electron-phonon&amp;lt;/span&amp;gt;&lt;br /&gt;
 elph    = LetzElphElectronPhononDB(ndb_elph,read_all=False)&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Read wave functions&amp;lt;/span&amp;gt;&lt;br /&gt;
 wfcs    = YamboWFDB(filename=&#039;ns.wf&#039;,save=savepath,latdb=lattice,bands_range=bands_range)&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Calculate exciton-phonon matrix elements&amp;lt;/span&amp;gt;&lt;br /&gt;
 exph = exciton_phonon_matelem(lattice,elph,wfcs,BSE_dir=bsepath,nexc_in=nexc,nexc_out=nexc,dmat_mode=&#039;save&#039;,exph_file=&#039;MoS2_Ex-ph.npy&#039;)&lt;br /&gt;
&lt;br /&gt;
In this script, we can select the number exciton states &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; with &amp;lt;code&amp;gt;nexc&amp;lt;/code&amp;gt;, the single-particle bands range with &amp;lt;code&amp;gt;bands_range&amp;lt;/code&amp;gt;. &#039;&#039;&#039;Please note&#039;&#039;&#039;: in this case, the band index starts from 0 (python indexing) and the the interval of bands read by the code is &amp;lt;math&amp;gt;[n_i,n_f)&amp;lt;/math&amp;gt;, therefore the last value (28 in the example) is excluded. That is, in the example we are selecting the 25th, 26th, 27th and 28th bands. Those bands have to be present in both the electron-phonon and BSE calculations. &lt;br /&gt;
&lt;br /&gt;
Here we calculate the couplings of the first twelve states at each finite-&amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; point including &amp;lt;math&amp;gt;q=0&amp;lt;/math&amp;gt;. We also include all the nine phonon modes of monolayer MoS2. We also need access to the Yambo &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory in order to read the electronic wavefunctions: they are used to compute the electronic representation matrices (&amp;lt;code&amp;gt;dmat&amp;lt;/code&amp;gt; in the code). The argument &amp;lt;code&amp;gt;dmat_mode&amp;lt;/code&amp;gt; can be set to &amp;lt;code&amp;gt;&#039;load&#039;&amp;lt;/code&amp;gt; for subsequent calculations.&lt;br /&gt;
&lt;br /&gt;
When we are satisfied with the input, we run the code:&lt;br /&gt;
&lt;br /&gt;
 python calculate_excph.py&lt;br /&gt;
&lt;br /&gt;
If you check the output, you should find the &amp;lt;code&amp;gt;MoS2_Ex-ph.npy&amp;lt;/code&amp;gt; binary file in the directory where you ran.&lt;br /&gt;
&lt;br /&gt;
=== Analysis of the couplings ===&lt;br /&gt;
&lt;br /&gt;
It is a good idea to have a look at what we computed up to now in order to make sure nothing has gone wrong. &lt;br /&gt;
&lt;br /&gt;
It is not easy to know what to expect (apart from symmetry and gauge compliance of the matrix elements), but one can work out the exciton-phonon selection rules in advance, check that the magnitude is reasonable, etc.&lt;br /&gt;
&lt;br /&gt;
It is also not easy to meaningfully plot this quantity. We have to make sure that we are not breaking degenerate states, otherwise the plots will not be invariant. &lt;br /&gt;
&lt;br /&gt;
First of all, we have to know our system: in monolayer MoS&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;, the first four excitons are all doubly degenerate. The first exciton responsible for a bright peak in the absorption spectrum (the &#039;&#039;&#039;A&#039;&#039;&#039; peak), is the second state, corresponding to state indices &amp;lt;code&amp;gt;(3,4)&amp;lt;/code&amp;gt; in fortran indexing or &amp;lt;code&amp;gt;(2,3)&amp;lt;/code&amp;gt; in python indexing. &lt;br /&gt;
&lt;br /&gt;
All these information can be obtained by analyzing the BSE results (this stuff is explained in the BSE tutorials) and by knowledge of the system or class of systems from the literature.&lt;br /&gt;
&lt;br /&gt;
Thus, a good quantity to plot may be the norm of the matrix elements, summed over the degenerate subspace of exciton A, for a certain number of scattered final states mediated by certain phonon modes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;F_A(q)= \sqrt{ \sum_{\alpha \in A,\lambda,\mu} |\mathcal{G}_{\alpha\lambda}^\mu (0,q)|^2 }&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In order to do this, we create a python script &amp;lt;code&amp;gt;analyse_excph.py&amp;lt;/code&amp;gt; in which we first load the excph dabatases. &lt;br /&gt;
You can find a version of this script in the yambopy directory, in &amp;lt;code&amp;gt;tutorials/exciton-phonon&amp;lt;/code&amp;gt;. &lt;br /&gt;
First, we select the exciton and phonon states to be included in &amp;lt;code&amp;gt;F_A&amp;lt;/code&amp;gt;, together with the path of databases and plot details:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Exciton &amp;quot;in&amp;quot; states&amp;lt;/span&amp;gt;&lt;br /&gt;
 exc_in  = [2,3]  &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# First bright peak (A: 2,3 -- B: 6,7)&amp;lt;/span&amp;gt;&lt;br /&gt;
 exc_out = [0,1,2,3] &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# first 4 states (dispersion of dark triplet state and A)&amp;lt;/span&amp;gt;&lt;br /&gt;
 ph_in  = &#039;all&#039;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Paths of databases&amp;lt;/span&amp;gt;&lt;br /&gt;
 ns_db1 =f&#039;{path}/SAVE/ns.db1&#039;&lt;br /&gt;
 ns_ypy = &#039;MoS2_Ex-ph.npy&#039;&lt;br /&gt;
 &lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
Then, we load the data:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Read lattice and k-space info&amp;lt;/span&amp;gt;&lt;br /&gt;
 ylat = YamboLatticeDB.from_db_file(filename=ns_db1)&lt;br /&gt;
 print(ylat)&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Load exc-ph database&amp;lt;/span&amp;gt;&lt;br /&gt;
 X_py = np.load(ns_ypy)&lt;br /&gt;
 G_squared = np.abs(X_py)**2.&lt;br /&gt;
&lt;br /&gt;
The quantity &amp;lt;math&amp;gt;F_A(q)&amp;lt;/math&amp;gt; is obtained from a dedicated function as:&lt;br /&gt;
 &lt;br /&gt;
 if exc_in  == &#039;all&#039;: exc_in  = range(G_squared.shape[2])&lt;br /&gt;
 if exc_out == &#039;all&#039;: exc_out = range(G_squared.shape[3])&lt;br /&gt;
 if ph_in   == &#039;all&#039;: ph_in   = range(G_squared.shape[1])&lt;br /&gt;
 &lt;br /&gt;
 G_squared = G_squared[:, ph_in, :, :].sum(axis=(1))&lt;br /&gt;
 G_squared = G_squared[:, exc_in, :].sum(axis=(1))&lt;br /&gt;
 G_squared = G_squared[:, exc_out].sum(axis=(1))&lt;br /&gt;
 &lt;br /&gt;
 F_q = np.sqrt( G_squared )*ha2ev &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Switch from Ha to eV&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And finally, we have to make a plotting function. For this tutorial we will use a custom scatterplot employing some of the plotting tools provided by yambopy (but you can do whatever you want).&lt;br /&gt;
&lt;br /&gt;
 plot_2D_excph(qgrid,G2_to_plot,rlat=ylat.rlat,plt_cbar=True,\&lt;br /&gt;
               marker=&#039;H&#039;,s=700,cmap=&#039;magma&#039;)&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
You can get more experience on using Yambopy for these kinds of visualization by following the [https://wiki.yambo-code.eu/wiki/index.php?title=First_steps_in_Yambopy Yambopy tutorials]. In fact, remember that these scripts and all the other Yambopy tutorial scripts are just suggestions, not source code written in stone: if you know &amp;lt;code&amp;gt;numpy&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;matplotlib&amp;lt;/code&amp;gt; you can do your own analysis and your own plots, you just need to import the required Yambopy modules to load the data.&lt;br /&gt;
&lt;br /&gt;
In our case, the resulting plot is the following.&lt;br /&gt;
&lt;br /&gt;
[[File:1L MoS2 MoS2 Ex-ph.png|500px|center]]&lt;br /&gt;
&lt;br /&gt;
This can be checked against Fig. 2(d) of reference &amp;lt;ref name=&amp;quot;chan2023&amp;quot; /&amp;gt;, although you have to keep in mind that our results are badly undersampled in terms of the reciprocal-space grid, as can be easily seen, and the quantity plotted is not exactly the same. However, the main features are already there since they are dictated mostly by crystal symmetries.&lt;br /&gt;
&lt;br /&gt;
Now that we have the exciton-phonon matrix elements, we can use them to build several kinds of observables. Below, we give an example related to phonon-assisted luminescence, but we may update this tutorial in the future to include more cases.&lt;br /&gt;
&lt;br /&gt;
== Step 8: Compute phonon-assisted luminescence ==&lt;br /&gt;
&lt;br /&gt;
[[File:Luminescence scheme.png|250px|right]]&lt;br /&gt;
&lt;br /&gt;
We want to compute the experimental optical signature due to the phonon-assisted recombination of an exciton (as sketched in the figure).&lt;br /&gt;
&lt;br /&gt;
The signal from the phonon replicas can be modeled as a second-order scattering process involving one phonon and one photon:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;I^{Sat}(\omega)=\frac{1}{ N_q} \frac{1}{3} \sum_{\epsilon s\beta \mu q} \frac{1}{E_{\beta q}-s\Omega_{\mu q}}\left|\sum_\alpha\frac{ D^{\epsilon}_\alpha \mathcal{G}_{\beta \alpha}^{\mu,*}(q)}{E_\alpha -E_{\beta q} +s\Omega_{\mu q}+\mathrm{i}\eta}\right|^2 \frac{N^{exc}_{\beta q}(T_{exc})[\frac{1+s}{2}+n_{\mu q}(T)]}{\omega -[E_{\beta q}-s\Omega_{\mu q}]+\mathrm{i}\eta}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this equation, the oscillator strength of the peak is given by the exciton-phonon coupling matrix elements &amp;lt;math&amp;gt;\mathcal{G}&amp;lt;/math&amp;gt; multiplied by the exciton dipoles &amp;lt;math&amp;gt;D&amp;lt;/math&amp;gt; (they are called &amp;quot;residuals&amp;quot; in Yambo). Here &amp;lt;math&amp;gt;E_\lambda&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;E_{\alpha q}&amp;lt;/math&amp;gt; are the energies of the optical and finite-momentum excitons, respectively, while &amp;lt;math&amp;gt;\Omega_{\mu q}&amp;lt;/math&amp;gt; are the phonon energies. &lt;br /&gt;
&lt;br /&gt;
Here, &amp;lt;math&amp;gt;n_{\mu q}(T)&amp;lt;/math&amp;gt; is the temperature-dependent phonon Bose-Einstein occupation function. As it can be seen, &amp;lt;math&amp;gt;s=1&amp;lt;/math&amp;gt; corresponds to processes of phonon &#039;&#039;emission&#039;&#039; (&amp;lt;math&amp;gt;\propto n(T)+1&amp;lt;/math&amp;gt;), while &amp;lt;math&amp;gt;s=-1&amp;lt;/math&amp;gt; corresponds to processes of phonon &#039;&#039;absorption&#039;&#039; (&amp;lt;math&amp;gt;\propto n(T)&amp;lt;/math&amp;gt;). Therefore, &amp;lt;math&amp;gt;I^{Sat}_{PL}(\omega;T)&amp;lt;/math&amp;gt; describes &#039;&#039;light&#039;&#039; emission by recombining excitons mediated by either &#039;&#039;phonon&#039;&#039; absorption or emission. &lt;br /&gt;
&lt;br /&gt;
The quantity &amp;lt;math&amp;gt; N_{\alpha q}(T_{exc})&amp;lt;/math&amp;gt; is the exciton occupation function. Luminescence is technically an out-of-equilibrium process, but we can assume that for very low density of excitations and in steady-state conditions, the exciton population can be approximately described by an equilibrium distribution evaluated at an effective temperature. Here, we use the Boltzmann distribution. Experimentally, &amp;lt;math&amp;gt;T_{exc}&amp;lt;/math&amp;gt; tends to coincide with the lattice temperature &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt; more or less above 100 K, while at very low temperature (&amp;lt; 10 K), &amp;lt;math&amp;gt;T_{exc}&amp;lt;/math&amp;gt; may vary between 10-50 K. It goes without saying that this needs to carefully be checked in your realistic calculations.&lt;br /&gt;
&lt;br /&gt;
Finally, the spectrum is averaged over the polarization directions of the emitted photons (&amp;lt;math&amp;gt;\epsilon=x,y,z&amp;lt;/math&amp;gt; representing the respective dipole components).&lt;br /&gt;
&lt;br /&gt;
=== Running the jobs ===&lt;br /&gt;
&lt;br /&gt;
In order to study luminescence in a paradigmatic system, we switch to bulk hexagonal boron nitride and we repeat the workflow. As you can easily see, one can think about automatizing the execution of all these calculations via scripting or more advanced tools. However, in the case of very large simulations (memory-limited or disk-space limited) or for systems whose electronic and lattice properties are fragile with respect to tiny calculation details, one must be very careful and run many basic tests.&lt;br /&gt;
&lt;br /&gt;
Fortunately, we are running a fast underconverged example. We use LDA pseudopotentials from the pseudo-dojo library and the following are the calculations steps.&lt;br /&gt;
&lt;br /&gt;
1. Input &amp;lt;code&amp;gt;hbn.scf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 &amp;amp;control&lt;br /&gt;
     calculation=&#039;scf&#039;,&lt;br /&gt;
     prefix=&#039;hBN&#039;,&lt;br /&gt;
     restart_mode=&#039;from_scratch&#039;&lt;br /&gt;
     pseudo_dir = &#039;$PSEUDO_DIR&#039;,&lt;br /&gt;
     outdir = &#039;./tmp&#039;&lt;br /&gt;
     verbosity = &#039;high&#039;&lt;br /&gt;
     wf_collect=.true.&lt;br /&gt;
 /&lt;br /&gt;
 &amp;amp;system&lt;br /&gt;
     ibrav = 4,&lt;br /&gt;
     celldm(1) = 4.703675849&lt;br /&gt;
     celldm(3) = 2.603711434&lt;br /&gt;
     nat= 4,&lt;br /&gt;
     ntyp= 2,&lt;br /&gt;
     force_symmorphic=.true.&lt;br /&gt;
     ecutwfc = 100,&lt;br /&gt;
 /&lt;br /&gt;
 &amp;amp;electrons&lt;br /&gt;
   diago_david_ndim = 2&lt;br /&gt;
   diago_full_acc=.true.&lt;br /&gt;
   diago_thr_init=5.0e-6&lt;br /&gt;
   mixing_mode = &#039;plain&#039;&lt;br /&gt;
   mixing_beta = 0.7&lt;br /&gt;
   conv_thr =  1.0d-16&lt;br /&gt;
 /&lt;br /&gt;
 ATOMIC_SPECIES&lt;br /&gt;
  B 10.81100  B_LDA_dojo.UPF&lt;br /&gt;
  N 14.00674  N_LDA_dojo.UPF&lt;br /&gt;
 ATOMIC_POSITIONS {crystal}&lt;br /&gt;
 N             0.6666666670        0.3333333330        -0.250000000000&lt;br /&gt;
 B             0.3333333330        0.6666666670        -0.250000000000&lt;br /&gt;
 B             0.6666666670        0.3333333330        0.25000000000&lt;br /&gt;
 N             0.3333333330        0.6666666670        0.25000000000&lt;br /&gt;
 K_POINTS {automatic}&lt;br /&gt;
 6 6 2 0 0 0&lt;br /&gt;
&lt;br /&gt;
 mpirun -np 4 pw.x -inp hbn.scf &amp;gt; scf.out&lt;br /&gt;
&lt;br /&gt;
2. Input &amp;lt;code&amp;gt;hbn.nscf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 &amp;amp;control&lt;br /&gt;
     calculation=&#039;nscf&#039;,&lt;br /&gt;
     prefix=&#039;hBN&#039;,&lt;br /&gt;
     restart_mode=&#039;from_scratch&#039;&lt;br /&gt;
     pseudo_dir = &#039;$PSEUDO_DIR&#039;&lt;br /&gt;
     outdir = &#039;./&#039;&lt;br /&gt;
     verbosity = &#039;high&#039;&lt;br /&gt;
     wf_collect=.true.&lt;br /&gt;
 /&lt;br /&gt;
 &amp;amp;system&lt;br /&gt;
     ibrav = 4,&lt;br /&gt;
     celldm(1) = 4.703675849&lt;br /&gt;
     celldm(3) = 2.603711434&lt;br /&gt;
     nat= 4,&lt;br /&gt;
     ntyp= 2,&lt;br /&gt;
     force_symmorphic=.true.&lt;br /&gt;
     ecutwfc = 100,&lt;br /&gt;
 	nbnd = 120&lt;br /&gt;
 /&lt;br /&gt;
 &amp;amp;electrons&lt;br /&gt;
   diago_david_ndim = 2&lt;br /&gt;
   diago_full_acc=.true.&lt;br /&gt;
   diago_thr_init=5.0e-6&lt;br /&gt;
   mixing_mode = &#039;plain&#039;&lt;br /&gt;
   mixing_beta = 0.7&lt;br /&gt;
   conv_thr =  1.0d-16&lt;br /&gt;
 /&lt;br /&gt;
 ATOMIC_SPECIES&lt;br /&gt;
  B 10.81100  B_LDA_dojo.UPF&lt;br /&gt;
  N 14.00674  N_LDA_dojo.UPF&lt;br /&gt;
 ATOMIC_POSITIONS {crystal}&lt;br /&gt;
 N             0.6666666670        0.3333333330        -0.250000000000&lt;br /&gt;
 B             0.3333333330        0.6666666670        -0.250000000000&lt;br /&gt;
 B             0.6666666670        0.3333333330        0.25000000000&lt;br /&gt;
 N             0.3333333330        0.6666666670        0.25000000000&lt;br /&gt;
 K_POINTS {automatic}&lt;br /&gt;
 6 6 2 0 0 0&lt;br /&gt;
&lt;br /&gt;
 mpirun -np 4 pw.x -inp hbn.nscf &amp;gt; nscf.out&lt;br /&gt;
&lt;br /&gt;
3. Input &amp;lt;code&amp;gt;hbn.dvscf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 hbn_dvscf&lt;br /&gt;
 &amp;amp;inputph&lt;br /&gt;
   tr2_ph=1.0d-12,&lt;br /&gt;
   verbosity=&#039;high&#039;&lt;br /&gt;
   prefix=&#039;hBN&#039;,&lt;br /&gt;
   fildvscf = &#039;hBN-dvscf&#039;,&lt;br /&gt;
   electron_phonon = &#039;dvscf&#039;,&lt;br /&gt;
   fildyn=&#039;hBN.dyn&#039;,&lt;br /&gt;
   epsil=.false.,&lt;br /&gt;
   ldisp=.true.,&lt;br /&gt;
   recover=.true.,&lt;br /&gt;
   nq1=6,&lt;br /&gt;
   nq2=6,&lt;br /&gt;
   nq3=2&lt;br /&gt;
 /&lt;br /&gt;
&lt;br /&gt;
 nohup mpirun -np 8 pw.x -inp hbn.dvscf &amp;gt; dvscf.out &amp;amp;&lt;br /&gt;
&lt;br /&gt;
4. Input &amp;lt;code&amp;gt;bse.in&amp;lt;/code&amp;gt; (we include 2 valence and 2 conduction bands):&lt;br /&gt;
&lt;br /&gt;
 optics                           # [R] Linear Response optical properties&lt;br /&gt;
 bss                              # [R] BSE solver&lt;br /&gt;
 bse                              # [R][BSE] Bethe Salpeter Equation.&lt;br /&gt;
 dipoles                          # [R] Oscillator strenghts (or dipoles)&lt;br /&gt;
 em1s&lt;br /&gt;
 DIP_CPU= &amp;quot;1 8 1&amp;quot;                      # [PARALLEL] CPUs for each role&lt;br /&gt;
 DIP_ROLEs= &amp;quot;k c v&amp;quot;                    # [PARALLEL] CPUs roles (k,c,v)&lt;br /&gt;
 DIP_Threads=0                    # [OPENMP/X] Number of threads for dipoles&lt;br /&gt;
 X_and_IO_CPU= &amp;quot;1 1 1 8 1&amp;quot;                 # [PARALLEL] CPUs for each role&lt;br /&gt;
 X_and_IO_ROLEs= &amp;quot;q g k c v&amp;quot;               # [PARALLEL] CPUs roles (q,g,k,c,v)&lt;br /&gt;
 X_and_IO_nCPU_LinAlg_INV=-1      # [PARALLEL] CPUs for Linear Algebra (if -1 it is automatically set)&lt;br /&gt;
 X_Threads=0                      # [OPENMP/X] Number of threads for response functions&lt;br /&gt;
 BS_CPU= &amp;quot;8 1 1&amp;quot;                       # [PARALLEL] CPUs for each role&lt;br /&gt;
 BS_ROLEs= &amp;quot;k eh t&amp;quot;                     # [PARALLEL] CPUs roles (k,eh,t)&lt;br /&gt;
 BS_nCPU_LinAlg_INV=-1            # [PARALLEL] CPUs for Linear Algebra (if -1 it is automatically set)&lt;br /&gt;
 BS_nCPU_LinAlg_DIAGO=-1          # [PARALLEL] CPUs for Linear Algebra (if -1 it is automatically set)&lt;br /&gt;
 X_Threads=0                      # [OPENMP/X] Number of threads for response functions&lt;br /&gt;
 K_Threads=0                      # [OPENMP/BSK] Number of threads for response functions&lt;br /&gt;
 % QpntsRXs&lt;br /&gt;
    1 | 14 |                         # [Xs] Transferred momenta&lt;br /&gt;
 %&lt;br /&gt;
 % BndsRnXs&lt;br /&gt;
    1 | 120 |                         # [Xs] Polarization function bands&lt;br /&gt;
 %&lt;br /&gt;
 NGsBlkXs= 10                Ry    # [Xs] Response block size&lt;br /&gt;
 % LongDrXs&lt;br /&gt;
  1.000000 | 1.000000 | 1.000000 |        # [Xs] [cc] Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 BSEmod= &amp;quot;resonant&amp;quot;               # [BSE] resonant/retarded/coupling&lt;br /&gt;
 BSKmod= &amp;quot;SEX&amp;quot;                    # [BSE] IP/Hartree/HF/ALDA/SEX/BSfxc&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;Lkind= &amp;quot;Lfull&amp;quot;                    # [BSE] Lbar (default) / full&amp;lt;/span&amp;gt;&lt;br /&gt;
 BSSmod= &amp;quot;d&amp;quot;                      # [BSS] (h)aydock/(d)iagonalization/(s)lepc/(i)nversion/(t)ddft`&lt;br /&gt;
 % DipBands&lt;br /&gt;
    1 | 120 |                         # [DIP] Bands range for dipoles&lt;br /&gt;
 %&lt;br /&gt;
 DipApproach= &amp;quot;G-space v&amp;quot;         # [DIP] [G-space v/R-space x/Covariant/Shifted grids]&lt;br /&gt;
 DipComputed= &amp;quot;R V P&amp;quot;             # [DIP] [default R P V; extra P2 Spin Orb]&lt;br /&gt;
 BSENGexx= 30000            Ry    # [BSK] Exchange components&lt;br /&gt;
 #ALLGexx                       # [BSS] Force the use use all RL vectors for the exchange part&lt;br /&gt;
 BSENGBlk=  9000            Ry    # [BSK] Screened interaction block size [if -1 uses all the G-vectors of W(q,G,Gp)]&lt;br /&gt;
 % KfnQP_E&lt;br /&gt;
  1.25997 | 1.08816 | 1.12683 |        # [EXTQP BSK BSS] E parameters  (c/v) eV|adim|adim&lt;br /&gt;
 %&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;% BSEQptR&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 1 | 14 |                     # [BSK] Transferred momenta range&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;%&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;% BSEBands&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;   7 | 10 |                         # [BSK] Bands range&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;%&amp;lt;/span&amp;gt;&lt;br /&gt;
 % BEnRange&lt;br /&gt;
   0.50000 | 8.00000 |         eV    # [BSS] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 % BDmRange&lt;br /&gt;
  0.050000 | 0.050000 |         eV    # [BSS] Damping range&lt;br /&gt;
 %&lt;br /&gt;
 BEnSteps= 1000                    # [BSS] Energy steps&lt;br /&gt;
 % BLongDir&lt;br /&gt;
  1.000000 | 1.000000 | 0.000000 |        # [BSS] [cc] Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 WRbsWF                        # [BSS] Write to disk excitonic the WFs&lt;br /&gt;
&lt;br /&gt;
 nohup mpirun -np 8 yambo -F bse.in -J bse_Lfull -C bse_Lfull &amp;amp;&lt;br /&gt;
&lt;br /&gt;
Importantly, since we want to describe the phonon-assisted recombination process of an *optical* exciton (i.e., emitting a transverse photon), this time we also run an additional calculation at `Q=0` omitting the nonanalytic long-range Coulomb exchange. Make a second input &amp;lt;code&amp;gt;bse_Lbar.in&amp;lt;/code&amp;gt; with the following changes: &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;Lkind= &amp;quot;Lbar&amp;quot;                    # [BSE] Lbar (default) / full&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;% BSEQptR&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 1 | 1 |                     # [BSK] Transferred momenta range&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;%&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4b. So now we make a second BSE run in a different directory specified by &amp;lt;code&amp;gt;-J&amp;lt;/code&amp;gt;. Here, we also pass to yambo the directory of the previous run as it includes the important screening databases &amp;lt;code&amp;gt;ndb.em1s*&amp;lt;/code&amp;gt; that we do not want to recompute from scratch.&lt;br /&gt;
 &lt;br /&gt;
 mpirun -np 8 yambo -F bse_Lbar.in -J bse_Lbar,bse_Lfull -C bse_Lbar&lt;br /&gt;
&lt;br /&gt;
5. Now we run &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; (with or without yambopy: in the latter case remember the option &amp;lt;code&amp;gt;-D&amp;lt;/code&amp;gt;) to get the el-ph matrix elements, particularly the &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; databases:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph path/of/dvscf/hbn.dvscf -b 7 10 -par 4 2 -D&lt;br /&gt;
&lt;br /&gt;
=== Luminescence calculation ===&lt;br /&gt;
&lt;br /&gt;
6. And finally we calculate exciton-phonon matrix elements and the luminescence spectrum in one go using a python script importing the Yambopy exciton-phonon tools: in order to do this, we need to take a look at all the necessary input variables for the formula written above.&lt;br /&gt;
&lt;br /&gt;
We can start from the script &amp;lt;code&amp;gt;luminescence.py&amp;lt;/code&amp;gt; available in &amp;lt;code&amp;gt;tutorials/exciton-phonon&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
 import numpy as np&lt;br /&gt;
 import matplotlib.pyplot as plt&lt;br /&gt;
 from yambopy.exciton_phonon.excph_luminescence import exc_ph_luminescence&lt;br /&gt;
 from yambopy.exciton_phonon.excph_input_data import exc_ph_get_inputs&lt;br /&gt;
&lt;br /&gt;
We import the necessary tools...&lt;br /&gt;
&lt;br /&gt;
 path = &#039;3D_hBN&#039;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Path to BSE calculation (Lout--&amp;gt; response is Lfull)&amp;lt;/span&amp;gt;&lt;br /&gt;
 bsepath =  f&#039;{path}/bse_Lfull&#039; &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# ndb.BS_diago_Q* databases are needed&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Path to BSE calculation for optically active exciton (Lin --&amp;gt; response is Lbar)&amp;lt;/span&amp;gt;&lt;br /&gt;
 bseBARpath =  f&#039;{path}/bse_Lbar&#039;  &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# ndb.BS_diago_Q1 database is needed&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Path to electron-phonon calculation&amp;lt;/span&amp;gt;&lt;br /&gt;
 elphpath = path &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# ndb.elph is needed&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Path to unprojected dipoles matrix elements (optional)&amp;lt;/span&amp;gt;&lt;br /&gt;
 dipolespath = bsepath &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# ndb.dipoles is needed (optional)&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Path to lattice and k-space info&amp;lt;/span&amp;gt;&lt;br /&gt;
 savepath = f&#039;{path}/SAVE&#039; &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# ns.db1 database is needed&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
... and we specify the paths to the necessary databases. Note that, if we want to perform polarization averaging, we have to recompute the excitonic dipoles in python as seen here.&lt;br /&gt;
&lt;br /&gt;
What about &amp;lt;code&amp;gt;bseBARpath&amp;lt;/code&amp;gt;? This variable points to the directory where the databases for the optical (zero-momentum) excitons &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; (which may be computed with &amp;lt;code&amp;gt;Lkind=&#039;Lbar&#039;&amp;lt;/code&amp;gt;) is located, which can be different from the directory with the full indirect exciton dispersion &amp;lt;math&amp;gt;\beta&amp;lt;/math&amp;gt; (usually computed with &amp;lt;code&amp;gt;Lkind=&#039;Lfull&#039;&amp;lt;/code&amp;gt;, however &amp;lt;code&amp;gt;Lkind=&#039;Ltilde&#039;&amp;lt;/code&amp;gt; can also be used if one is interested in &amp;quot;irreducible&amp;quot; excitons). This makes it possible to compute the coupling between different exciton kinds.&lt;br /&gt;
&lt;br /&gt;
 bands_range=[6,10] &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# 2 valence, 2 conduction bands&amp;lt;/span&amp;gt;&lt;br /&gt;
 phonons_range=[0,12] &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# All phonons&amp;lt;/span&amp;gt;&lt;br /&gt;
 nexc_out = 12 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# 12 excitonic states at each momentum (Lout)&amp;lt;/span&amp;gt;&lt;br /&gt;
 nexc_in  = 12 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# 12 excitonic states at Q=0 (Lin)&amp;lt;/span&amp;gt;&lt;br /&gt;
 T_ph  = 10 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Lattice temperature&amp;lt;/span&amp;gt;&lt;br /&gt;
 T_exc = 10 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Effective excitonic temperature&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 emin=4.4      &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Energy range and plot details (in eV)&amp;lt;/span&amp;gt;&lt;br /&gt;
 emax=4.7&lt;br /&gt;
 estep=0.0002&lt;br /&gt;
 broad = 0.005 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Broadening parameter for peak width (in eV)&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next, we specify the parameters for the calculation. We include valence bands from 7 to 10 (6 to 9 in python index) and the contribution of all 12 phonon modes. We consider 12 excitonic states for the coupling matrix elements.&lt;br /&gt;
&lt;br /&gt;
Here &amp;lt;code&amp;gt;T_ph&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;T_exc&amp;lt;/code&amp;gt; are the lattice and excitonic temperatures, respectively.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# We calculate and load all the inputs:&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# * Exciton-phonon matrix elements&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# * Excitonic dipole matrix elements&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# * Exciton energies&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# * Phonon energies&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# * We specify bse_path2=bseBARpath meaning we use Lbar calculation for Q=0 excitons&amp;lt;/span&amp;gt;&lt;br /&gt;
 input_data = exc_ph_get_inputs(savepath,elphpath,bsepath,\&lt;br /&gt;
                                bse_path2=bseBARpath,dipoles_path=dipolespath,\&lt;br /&gt;
                                nexc_in=12,nexc_out=12,\&lt;br /&gt;
                                bands_range=[6,10],phonons_range=[0,12])&lt;br /&gt;
&lt;br /&gt;
 ph_energies, exc_energies, exc_energies_in, G, exc_dipoles = input_data&lt;br /&gt;
&lt;br /&gt;
The function &amp;lt;code&amp;gt;exc_ph_get_inputs&amp;lt;/code&amp;gt; gives us all the input data for luminescence in the correct format: phonon energies, exciton energies, optical exciton energies (if needed), exciton-phonon matrix elements (calculated on the fly and printed to file), unprojected exciton dipoles (optional, calculated on the fly and printed to file).&lt;br /&gt;
The exc-ph matrix element calculation is just a wrapper of the same tools that we have tested in the above section on MoS2.&lt;br /&gt;
&lt;br /&gt;
Finally, there is the calculation of the luminescence spectrum via the function &amp;lt;code&amp;gt;exc_ph_luminescence&amp;lt;/code&amp;gt;:&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# We calculate the luminescence spectrum including the input data from before&amp;lt;/span&amp;gt;&lt;br /&gt;
 w,PL = exc_ph_luminescence(T_ph,ph_energies,exc_energies,exc_dipoles,G,\&lt;br /&gt;
                            exc_energies_in=exc_energies_in,exc_temp=T_exc,\&lt;br /&gt;
                            nexc_out=nexc_out,nexc_in=nexc_in,emin=emin,emax=emax,\&lt;br /&gt;
                            estep=estep,broad=broad)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you want to print the luminescence data for later plotting, you can also add the following line to the script:&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Save to file&amp;lt;/span&amp;gt;&lt;br /&gt;
 data = np.column_stack((w, PL))&lt;br /&gt;
 np.savetxt(&amp;quot;hBN_luminescence_12x12x1.dat&amp;quot;, data, fmt=&amp;quot;%.8f&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
It is now time to run the whole script:&lt;br /&gt;
&lt;br /&gt;
 python luminescence.py&lt;br /&gt;
 &lt;br /&gt;
NB: By using Yambopy for Step 6, we have limited the use of the Yambo code to just step 4 in the entire workflow. This option is more flexible, as it allows for a greater degree of control by the user. On the other hand the Yambo postprocessing route features a Yambo-style input that doesn&#039;t require python knowledge and the calculation is currently faster in fortran. However, the luminescence expression computed in Yambo is a slightly different than this one: it is more approximated in the description of the satellite oscillator strengths, but it explicitly includes the renormalization of the direct exciton peak. You can check the differences [[Exciton-phonon coupling and luminescence - Yambo postprocessing|here]].&lt;br /&gt;
&lt;br /&gt;
=== Results ===&lt;br /&gt;
We can plot the results of the step 6 calculation. If we do it in the same script we can add something like this:&lt;br /&gt;
 fig = plt.figure()&lt;br /&gt;
 ax = fig.add_subplot(1,1,1)&lt;br /&gt;
 ax.set_xlim(emin,emax)&lt;br /&gt;
 ax.set_ylim(0,np.max(PL)*1.1)&lt;br /&gt;
 ax.get_yaxis().set_visible(False)&lt;br /&gt;
 &lt;br /&gt;
 ax.plot(w, PL, &#039;-&#039;,c=&#039;red&#039;, label=&amp;quot;AA&#039; hBN luminescence&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
 plt.legend()&lt;br /&gt;
 plt.savefig(&#039;hBN_luminescence.png&#039;)&lt;br /&gt;
 plt.show()&lt;br /&gt;
&lt;br /&gt;
[[File:HBN luminescence satellites.png|500px|center]]&lt;br /&gt;
&lt;br /&gt;
Here, the signal corresponds to a finite-momentum exciton that recombines with the help of several different phonon modes, both optical and acoustic. Each phonon mode whose coupling with the exciton is allowed can generate a peak, and the energy shifts of these peaks with respect to the initial exciton energy correspond to the phonon energies. This result is underconverged, but the main features are all there. In the plot, we show a more converged example using a 12x12x4 grid (all the other parameters being equal). These plots can be compared with Fig. 4(a) of reference &amp;lt;ref name=&amp;quot;zanfrognini2023&amp;quot; /&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;toyozawa2003&amp;quot; &amp;gt;Toyozawa, Yutaka, and Chris Oxlade, &#039;&#039;Optical processes in solids&#039;&#039;, [https://m.booksee.org/book/1121964?force_lang=en Cambridge University Press, (2003)]. &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;lechifflart2023&#039;&amp;gt;P. Lechifflart, F. Paleari, D. Sangalli, C. Attaccalite, &#039;&#039;First-principles study of luminescence in hexagonal boron nitride single layer: Exciton-phonon coupling and the role of substrate&#039;&#039;, &lt;br /&gt;
[https://doi.org/10.1103/PhysRevMaterials.7.024006 Phys. Rev. M, &#039;&#039;&#039;7&#039;&#039;&#039; (2), 024006 (2023)]; [https://arxiv.org/abs/2212.10407 arXiv2212.1047]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;cannuccia2019&#039;&amp;gt;E. Cannuccia, B. Monserrat and C. Attaccalite, &#039;&#039;Theory of phonon-assisted luminescence in solids: Application to hexagonal boron nitride&#039;&#039;, [https://doi.org/10.1103/PhysRevB.99.081109 Phys. Rev. B &#039;&#039;&#039;99&#039;&#039;&#039;, 081109(R) (2019)]; [https://arxiv.org/abs/1807.11797 arXiv1807.11797]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;paleari2019&#039;&amp;gt;F. Paleari et al., &#039;&#039;Exciton-Phonon Coupling in the Ultraviolet Absorption and Emission Spectra of Bulk Hexagonal Boron Nitride&#039;&#039;, [https://doi.org/10.1103/PhysRevLett.122.187401 Phys. Rev. Lett. &#039;&#039;&#039;122&#039;&#039;&#039;, 187401 (2019)]; [https://arxiv.org/abs/1810.08976 arXiv1810.089776] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;chen2020&#039;&amp;gt;&#039;&#039;Exciton-Phonon Interaction and Relaxation Times from First Principles&#039;&#039;,&lt;br /&gt;
Hsiao-Yi Chen, Davide Sangalli, and Marco Bernardi, [https://doi.org/10.1103/PhysRevLett.125.107401  Phys. Rev. Lett. &#039;&#039;&#039;125&#039;&#039;&#039;, 107401 (2020)]; [https://arxiv.org/abs/2002.08913 arXiv 2002.08913 (2020)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;lechifflart2023_PhD&amp;quot;&amp;gt;P. Lechifflart, &#039;&#039;Exciton-phonon coupling and phonon-assisted luminescence in hexagonal Boron Nitride nanostructures&#039;&#039;, [https://hal.science/tel-04266805v1 PhD Thesis, University of Marseille (2023)]; [https://www.yambo-code.eu/wiki/images/5/54/These_final.pdf From the yambo website]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;paleari2019_PhD&#039;&amp;gt;F. Paleari, &#039;&#039;First-principles approaches to the description of indirect absorption and luminescence spectroscopy: exciton-phonon coupling in hexagonal boron nitride&#039;&#039;, [https://wwwen.uni.lu/research/fstm/dphyms/people/fulvio_paleari PhD thesis, University of Luxembourg (2019)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;zanfrognini2023&#039;&amp;gt;M. Zanfrognini et al., &#039;&#039;Distinguishing different stackings in layered materials via luminescence spectroscopy&#039;&#039;, [https://doi.org/10.1103/PhysRevLett.131.206902 Phys. Rev. Lett. &#039;&#039;&#039;131&#039;&#039;&#039;, 206902 (2023)]; [https://arxiv.org/abs/2305.17554 arXiv 2305.17554] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;marini2024&#039;&amp;gt;G. Marini, M. Calandra, P. Cudazzo, &#039;&#039;Optical absorption and photoluminescence of single layer boron nitride from a first principles cumulant approach&#039;&#039;, [https://doi.org/10.1021/acs.nanolett.4c00669 Nano Lett., &#039;&#039;&#039;24&#039;&#039;&#039;, 20, 6017 (2024)]; [https://arxiv.org/abs/2402.03826 arXiv 2402.03826 (2024)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;antonius2017&#039;&amp;gt;G. Antonius, S. G. Louie, &#039;&#039;Theory of exciton-phonon coupling&#039;&#039;, [https://doi.org/10.1103/PhysRevB.105.085111 Phys. Rev. B, &#039;&#039;&#039;105&#039;&#039;&#039;, 085111 (2022)]; [https://arxiv.org/abs/1705.04245 arXiv1705.04245 (2017)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;paleari2022&#039;&amp;gt; F. Paleari, and A. Marini, &#039;&#039;Exciton-phonon interaction calls for a revision of the “exciton” concept&#039;&#039;, [https://doi.org/10.1103/PhysRevB.106.125403 Phys. Rev. B, &#039;&#039;&#039;106&#039;&#039;&#039;, 125403 (2022)]; [https://arxiv.org/abs/2205.02783 arXiv 2205.02783]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;cudazzo2020&#039;&amp;gt; P. Cudazzo, &#039;&#039;First-principles description of the exciton-phonon interaction: A cumulant approach&#039;&#039;, [https://doi.org/10.1103/PhysRevB.102.045136 Phys. Rev. B, &#039;&#039;&#039;102&#039;&#039;&#039;, 045136 (2020)]; [https://orbilu.uni.lu/bitstream/10993/44769/1/main.pdf Open access pdf from Luxembourg University]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;chan2023&#039;&amp;gt;Y-h Chan, J. B. Haber, M. H. Naik, J. B. Neaton, D. Y. Qiu, F. H. da Jornada, S. G. Louie, &#039;&#039;Exciton Lifetime and Optical Line Width Profile via Exciton–Phonon Interactions: Theory and First-Principles Calculations for Monolayer MoS2&#039;&#039;, [https://doi.org/10.1021/acs.nanolett.3c00732 Nano Lett., &#039;&#039;&#039;23&#039;&#039;&#039;, 9 (2023)]; [https://arxiv.org/abs/2212.08451 arXiv 2212.08451 (2023)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;murali2025&#039;&amp;gt;M. Nalabothula, S. Reichardt, L. Wirtz, &#039;&#039;Origin of Interlayer Exciton–Phonon Coupling in 2D Heterostructures&#039;&#039;, [https://doi.org/10.1021/acs.nanolett.5c00355 Nano Lett., &#039;&#039;&#039;25&#039;&#039;&#039;, 15 (2025)], [https://arxiv.org/abs/2407.16111 arXiv 2407.16111 (2025)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>FulvioPaleari</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Exciton-phonon_coupling_and_luminescence&amp;diff=9338</id>
		<title>Exciton-phonon coupling and luminescence</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Exciton-phonon_coupling_and_luminescence&amp;diff=9338"/>
		<updated>2026-03-13T14:40:58Z</updated>

		<summary type="html">&lt;p&gt;FulvioPaleari: /* Requirements */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:Tdgw-phonon-usc-01-1024x829.jpg| 400px | right]]&lt;br /&gt;
&lt;br /&gt;
In this advanced tutorial, we will calculate exciton-phonon interactions from first principles by interfacing DFPT (for phonon calculations) and BSE (for exciton calculations).&lt;br /&gt;
&lt;br /&gt;
The DFTP calculations are run with Quantum ESPRESSO, while the many-body GW-BSE calculations are run with Yambo. Finally, the exciton-phonon interaction will be obtained by combining and postprocessing the databases computed in the two previous runs. The great advantage of this workflow is that the calculations can be run in the irreducible Brillouin zones both for the electronic momenta (&#039;&#039;&#039;k&#039;&#039;&#039;) and the transfer momenta (&#039;&#039;&#039;Q&#039;&#039;&#039;, &#039;&#039;&#039;q&#039;&#039;&#039;) of excitons and phonons, thus speeding up considerably the jobs while reducing the IO and memory load.&lt;br /&gt;
&lt;br /&gt;
We will first compute the exciton-phonon coupling matrix elements: these are the building blocks needed to construct experimental observables such as phonon-assisted optical spectra (such as luminescence), Raman spectra and exciton lifetimes. We will do this in the case of monolayer MoS&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;, a 2D system with large spin-orbit interaction.&lt;br /&gt;
&lt;br /&gt;
As an example of application, we will consider the case of phonon-assisted luminescence. We will do this in the case of bulk hBN, a layered indirect insulator with strong electron-phonon coupling.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Note:&#039;&#039;&#039; this tutorial will be updated when new exc-ph tools become available in Yambopy (including full-python postprocessing, Raman spectra, interpolated lifetimes, etc).&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
This is an advanced topic: we assume that you already know something about the theory&amp;lt;ref name=&amp;quot;toyozawa2003&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;antonius2017&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;cudazzo2020&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;paleari2019_PhD&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;paleari2022&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;lechifflart2023_PhD&amp;quot; /&amp;gt; and applications&amp;lt;ref name=&amp;quot;paleari2019&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;cannuccia2019&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;chen2020&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;zanfrognini2023&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;lechifflart2023&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;chan2023&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;marini2024&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;murali2025&amp;quot; /&amp;gt; of exciton-phonon physics. &lt;br /&gt;
&lt;br /&gt;
Also, we assume that you already know how to run both a basic &#039;&#039;&#039;Yambo&#039;&#039;&#039; GW-BSE calculation and a DFPT phonon calculation with &#039;&#039;&#039;Quantum ESPRESSO&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
Besides the QE executables &amp;lt;code&amp;gt;pw.x&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;ph.x&amp;lt;/code&amp;gt;, we also use the yambo phonon-specific executable &amp;lt;code&amp;gt;yambo_ph&amp;lt;/code&amp;gt; and the python utility &#039;&#039;&#039;Yambopy&#039;&#039;&#039;. The auxiliary code &#039;&#039;&#039;LetzElPhC&#039;&#039;&#039; (executable &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt;) will be used to obtain the electron-phonon matrix elements by reading the same electronic wavefunctions used by Yambo (and stored in the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory), while also making full use of crystal symmetries. [https://github.com/yambo-code/LetzElPhC LetzElPhC] will be run by Yambopy, but it must nonetheless be installed. Finally, the exciton-phonon properties can be computed either using &amp;lt;code&amp;gt;yambo_ph&amp;lt;/code&amp;gt; or using Yambopy itself. Both cases will be covered in this tutorial.&lt;br /&gt;
&lt;br /&gt;
[[File:Workflow scheme.png|800px|center]]&lt;br /&gt;
&lt;br /&gt;
== Step 0: Pseudopotentials, equilibrium structure and convergence ==&lt;br /&gt;
&lt;br /&gt;
In a real calculation, it is important to ensure that both the pseudopotential and the lattice parameters that we are using are compatible and perform well for the electronic excited states and for the lattice vibrations simultaneously. Furthermore, you have to make sure that the wave function cutoff &amp;lt;code&amp;gt;ecutwfc&amp;lt;/code&amp;gt; is converged with respect to the DFPT step and not just to the DFT one. This is in addition to the other customary convergence tests for DFT, DFPT, GW and BSE calculations.&lt;br /&gt;
&lt;br /&gt;
This is often the most time-demanding step when starting on a new system.&lt;br /&gt;
&lt;br /&gt;
For the sake of this tutorial, we assume that we have already done all these tests and we are starting the final workflow to get the exciton-phonon properties.&lt;br /&gt;
&lt;br /&gt;
== Step 1: scf calculation ==&lt;br /&gt;
&lt;br /&gt;
First of all, we run a standard scf calculation with &amp;lt;code&amp;gt;pw.x&amp;lt;/code&amp;gt; for Yambo. We stick with non-symmorphic symmetries. At the end, we will have the QE &amp;lt;code&amp;gt;save&amp;lt;/code&amp;gt; directory.&lt;br /&gt;
&lt;br /&gt;
This is the input &amp;lt;code&amp;gt;mos2.scf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 &amp;amp;control&lt;br /&gt;
           wf_collect = .true.,&lt;br /&gt;
          calculation = &amp;quot;scf&amp;quot;,&lt;br /&gt;
            verbosity = &#039;high&#039;,&lt;br /&gt;
           pseudo_dir = &#039;$PSEUDO_DIR&#039;,&lt;br /&gt;
               prefix = &amp;quot;mos2&amp;quot;,&lt;br /&gt;
               outdir = &#039;.&#039;,&lt;br /&gt;
  /&amp;amp;end&lt;br /&gt;
  &amp;amp;system&lt;br /&gt;
              ecutwfc = 100.0,&lt;br /&gt;
          occupations = &#039;fixed&#039;,&lt;br /&gt;
                ibrav = 4,&lt;br /&gt;
            celldm(1) = 5.9000811881,&lt;br /&gt;
            celldm(3) = 6.7795677253,&lt;br /&gt;
                  nat = 3,&lt;br /&gt;
                 ntyp = 2,&lt;br /&gt;
             lspinorb = .true.&lt;br /&gt;
             noncolin = .true.&lt;br /&gt;
             assume_isolated = &#039;2D&#039;&lt;br /&gt;
         force_symmorphic = .true.&lt;br /&gt;
  /&amp;amp;end&lt;br /&gt;
  &amp;amp;electrons&lt;br /&gt;
     electron_maxstep = 200,&lt;br /&gt;
          mixing_beta = 0.7,&lt;br /&gt;
             conv_thr = 1.d-08,&lt;br /&gt;
  /&amp;amp;end&lt;br /&gt;
   ATOMIC_SPECIES&lt;br /&gt;
    Mo  95.940      Mo_ONCV_PBE_FR-1.0.upf&lt;br /&gt;
    S    32.065     S_ONCV_PBE_FR-1.1.upf&lt;br /&gt;
   ATOMIC_POSITIONS { crystal }&lt;br /&gt;
 Mo       0.333333333   0.666666667   0.000000000&lt;br /&gt;
 S        0.666666667   0.333333333   0.073413577&lt;br /&gt;
 S        0.666666667   0.333333333  -0.073413577&lt;br /&gt;
  K_POINTS { automatic }&lt;br /&gt;
 6 6 1 0 0 0&lt;br /&gt;
&lt;br /&gt;
Here we are using full relativistic pseudopotentials from the SG-15 database.&lt;br /&gt;
&lt;br /&gt;
We can run it on our machine (for example using 4 MPI tasks) as:&lt;br /&gt;
&lt;br /&gt;
 mpirun -np 4 pw.x -inp mos2.scf &amp;gt; scf.out&lt;br /&gt;
&lt;br /&gt;
== Step 2: nscf calculation for Yambo ==&lt;br /&gt;
&lt;br /&gt;
Copy the QE &amp;lt;code&amp;gt;save&amp;lt;/code&amp;gt; directory from the scf calculation and run the nscf calculation for any number of empty states, with the correct &amp;lt;code&amp;gt;k&amp;lt;/code&amp;gt;-grid we want to use in Yambo. Here we are using a badly underconverged grid of 6x6x1.&lt;br /&gt;
&lt;br /&gt;
This reciprocal-space grid will also match the momentum transfer &amp;lt;code&amp;gt;q&amp;lt;/code&amp;gt; grid on which excitons and phonons will be defined!&lt;br /&gt;
&lt;br /&gt;
The electronic wavefunctions computed at this step and stored in the new nscf &amp;lt;code&amp;gt;save&amp;lt;/code&amp;gt; directory will be used both by Yambo and by the electron-phonon code: this is important because using different sets of wavefunctions would lead to a phase mismatch issue in the exciton-phonon matrix elements.&lt;br /&gt;
&lt;br /&gt;
The nscf input &amp;lt;code&amp;gt;mos2.nscf&amp;lt;/code&amp;gt; is&lt;br /&gt;
 &amp;amp;control&lt;br /&gt;
           wf_collect = .true.,&lt;br /&gt;
          calculation = &amp;quot;nscf&amp;quot;,&lt;br /&gt;
            verbosity = &#039;high&#039;,&lt;br /&gt;
           pseudo_dir = &#039;$PSEUDO_DIR&#039;,&lt;br /&gt;
               prefix = &amp;quot;mos2&amp;quot;,&lt;br /&gt;
               outdir = &#039;.&#039;,&lt;br /&gt;
  /&amp;amp;end&lt;br /&gt;
  &amp;amp;system&lt;br /&gt;
              ecutwfc = 100.0,&lt;br /&gt;
          occupations = &#039;fixed&#039;,&lt;br /&gt;
                ibrav = 4,&lt;br /&gt;
            celldm(1) = 5.9000811881,&lt;br /&gt;
            celldm(3) = 6.7795677253,&lt;br /&gt;
                  nat = 3,&lt;br /&gt;
                 ntyp = 2,&lt;br /&gt;
             lspinorb = .true.&lt;br /&gt;
             noncolin = .true.&lt;br /&gt;
                nbnd  = 250&lt;br /&gt;
             assume_isolated = &#039;2D&#039;&lt;br /&gt;
         force_symmorphic = .true.&lt;br /&gt;
  /&amp;amp;end&lt;br /&gt;
  &amp;amp;electrons&lt;br /&gt;
     electron_maxstep = 200,&lt;br /&gt;
          mixing_beta = 0.7,&lt;br /&gt;
             conv_thr = 1.d-08,&lt;br /&gt;
  /&amp;amp;end&lt;br /&gt;
   ATOMIC_SPECIES&lt;br /&gt;
    Mo  95.940      Mo_ONCV_PBE_FR-1.0.upf&lt;br /&gt;
    S    32.065     S_ONCV_PBE_FR-1.1.upf&lt;br /&gt;
   ATOMIC_POSITIONS { crystal }&lt;br /&gt;
 Mo       0.333333333   0.666666667   0.000000000&lt;br /&gt;
 S        0.666666667   0.333333333   0.073413577&lt;br /&gt;
 S        0.666666667   0.333333333  -0.073413577&lt;br /&gt;
  K_POINTS { automatic }&lt;br /&gt;
 6 6 1 0 0 0&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Again, we run the calculation&lt;br /&gt;
&lt;br /&gt;
 mpirun -np 4 pw.x -inp mos2.nscf &amp;gt; nscf.out&lt;br /&gt;
&lt;br /&gt;
== Step 3: dvscf phonon calculation ==&lt;br /&gt;
&lt;br /&gt;
Now we run the phonon calculation.&lt;br /&gt;
&lt;br /&gt;
Copy the &amp;lt;code&amp;gt;save&amp;lt;/code&amp;gt; directory from the &#039;&#039;&#039;scf&#039;&#039;&#039; calculation and run &amp;lt;code&amp;gt;ph.x&amp;lt;/code&amp;gt; for a dvscf calculation with a standard &amp;lt;code&amp;gt;q&amp;lt;/code&amp;gt;-grid matching the &amp;lt;code&amp;gt;k&amp;lt;/code&amp;gt;-grid we wanna use in Yambo.&lt;br /&gt;
&lt;br /&gt;
At the end, we will have the &amp;lt;code&amp;gt;_ph0&amp;lt;/code&amp;gt; directory containing the variation of the self-consistent potential, &amp;lt;math&amp;gt;\Delta V_{SCF}(q)&amp;lt;/math&amp;gt;, and the &amp;lt;code&amp;gt;*.dyn&amp;lt;/code&amp;gt; files with the phonon energies and eigenvectors.&lt;br /&gt;
&lt;br /&gt;
NB: one could further refine the phonon energies by enforcing the acoustic sum rule, including non-analytic long-range contributions, interpolating to finer grids... all of this can be done within Quantum ESPRESSO and will not be covered in this version of the tutorial.&lt;br /&gt;
&lt;br /&gt;
The input is &amp;lt;code&amp;gt;mos2.dvscf&amp;lt;/code&amp;gt;:&lt;br /&gt;
 &lt;br /&gt;
 mos2_dvscf&lt;br /&gt;
 &amp;amp;inputph&lt;br /&gt;
   tr2_ph=1.0d-12,&lt;br /&gt;
   verbosity=&#039;high&#039;&lt;br /&gt;
   prefix=&#039;mos2&#039;,&lt;br /&gt;
   fildvscf = &#039;mos2-dvscf&#039;,&lt;br /&gt;
   electron_phonon = &#039;dvscf&#039;,&lt;br /&gt;
   fildyn=&#039;mos2.dyn&#039;,&lt;br /&gt;
   epsil=.false.,&lt;br /&gt;
   ldisp=.true.,&lt;br /&gt;
   recover=.true.,&lt;br /&gt;
   nq1=6,&lt;br /&gt;
   nq2=6,&lt;br /&gt;
   nq3=1&lt;br /&gt;
 /&lt;br /&gt;
&lt;br /&gt;
And now we run as&lt;br /&gt;
&lt;br /&gt;
 nohup mpirun -np 8 ph.x -inp mos2.dvscf &amp;gt; dvscf.out &amp;amp;&lt;br /&gt;
&lt;br /&gt;
This time we use nohup and more processes because this calculation may take some time. It is a good idea to set &amp;lt;code&amp;gt;recover=.true.&amp;lt;/code&amp;gt; as in a real calculation you will easily breach walltime, and in this way you can safely restart.&lt;br /&gt;
&lt;br /&gt;
== Step 4: create Yambo &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory ==&lt;br /&gt;
&lt;br /&gt;
This is just the standard Yambo initialization: run &lt;br /&gt;
 &lt;br /&gt;
 p2y &lt;br /&gt;
&lt;br /&gt;
and then &lt;br /&gt;
&lt;br /&gt;
 yambo &lt;br /&gt;
&lt;br /&gt;
in the &#039;&#039;&#039;nscf&#039;&#039;&#039; &amp;lt;code&amp;gt;save&amp;lt;/code&amp;gt; folder and then move the newly generated &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory to a convenient place.&lt;br /&gt;
&lt;br /&gt;
== Step 5: run a BSE calculation ==&lt;br /&gt;
&lt;br /&gt;
Now we switch from QE to Yambo. Here, we forgo the GW step for simplicity (we can use a scissor operator to open the band gap).&lt;br /&gt;
&lt;br /&gt;
This calculation has a couple of differences with respect to a standard BSE calculation for optical absorption. We can look at the input file &amp;lt;code&amp;gt;bse.in&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Runlevels&amp;lt;/span&amp;gt;&lt;br /&gt;
 optics                       # [R OPT] Optics&lt;br /&gt;
 rim_cut                      # [R RIM CUT] Coulomb potential&lt;br /&gt;
 bss                          # [R BSS] Bethe Salpeter Equation solver&lt;br /&gt;
 em1s                         # [R Xs] Static Inverse Dielectric Matrix&lt;br /&gt;
 bse                          # [R BSE] Bethe Salpeter Equation.&lt;br /&gt;
 bsk                          # [R BSK] Bethe Salpeter Equation kernel&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# RIM and cutoff settings&amp;lt;/span&amp;gt;&lt;br /&gt;
 RandQpts=1000000             # [RIM] Number of random q-points in the BZ&lt;br /&gt;
 RandGvec= 100            RL    # [RIM] Coulomb interaction RS components&lt;br /&gt;
 CUTGeo= &amp;quot;slab z&amp;quot;               # [CUT] Coulomb Cutoff geometry: box/cylinder/sphere X/Y/Z/XY..&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Static screening&amp;lt;/span&amp;gt;&lt;br /&gt;
 X_and_IO_CPU= &amp;quot;1 1 4 2 1&amp;quot;       # [PARALLEL] CPUs for each role&lt;br /&gt;
 X_and_IO_ROLEs= &amp;quot;q g k c v&amp;quot;      # [PARALLEL] CPUs roles (q,g,k,c,v)&lt;br /&gt;
 X_and_IO_nCPU_LinAlg_INV=-1      # [PARALLEL] CPUs for Linear Algebra (if -1 it is automatically set)&lt;br /&gt;
 Chimod= &amp;quot;hartree&amp;quot;            # [X] IP/Hartree/ALDA/LRC/BSfxc&lt;br /&gt;
 % BndsRnXs&lt;br /&gt;
    1 |  200 |                 # [Xs] Polarization function bands&lt;br /&gt;
 %&lt;br /&gt;
 % LongDrXs&lt;br /&gt;
  1.000000 | 1.000000 | 1.000000 |        # [Xs] [cc] Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 NGsBlkXs= 8000            mRy    # [Xs] Response block size&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# BSE&amp;lt;/span&amp;gt;&lt;br /&gt;
 BS_CPU= &amp;quot;4.1.2&amp;quot;                   # [PARALLEL] CPUs for each role&lt;br /&gt;
 BS_ROLEs= &amp;quot;k.eh.t&amp;quot;                 # [PARALLEL] CPUs roles (k,eh,t)&lt;br /&gt;
 BS_nCPU_diago=4              # [PARALLEL] CPUs for matrix diagonalization&lt;br /&gt;
 BSEmod= &amp;quot;causal&amp;quot;             # [BSE] resonant/causal/coupling&lt;br /&gt;
 BSKmod= &amp;quot;SEX&amp;quot;                # [BSE] IP/Hartree/HF/ALDA/SEX/BSfxc&lt;br /&gt;
 BSSmod= &amp;quot;d&amp;quot;                  # [BSS] (h)aydock/(d)iagonalization/(s)lepc/(i)nversion/(t)ddft`&lt;br /&gt;
 BSENGexx=  40000      mRy    # [BSK] Exchange components&lt;br /&gt;
 ALLGexx                      # [BSS] Force the use use all RL vectors for the exchange part&lt;br /&gt;
 BSENGBlk=  8000       mRy    # [BSK] Screened interaction block size&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;Lkind=&amp;quot;full&amp;quot;                  #[BSE,X] bar(default)/full/tilde&amp;lt;/span&amp;gt;&lt;br /&gt;
 % KfnQP_E&lt;br /&gt;
  1.000000 | 1.000000 | 1.000000 |        # [EXTQP BSK BSS] E parameters  (c/v) eV|adim|adim&lt;br /&gt;
 %&lt;br /&gt;
 % BEnRange&lt;br /&gt;
   0.00000 |  4.00000 | eV    # [BSS] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 % BDmRange&lt;br /&gt;
   0.05000 |  0.05000 | eV    # [BSS] Damping range&lt;br /&gt;
 %&lt;br /&gt;
 BEnSteps= 2000               # [BSS] Energy steps&lt;br /&gt;
 % BLongDir&lt;br /&gt;
  1.000000 | 0.000000 | 0.000000 |        # [BSS] [cc] Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;% BSEQptR&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 1 | 7 |                     # [BSK] Transferred momenta range&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;%&amp;lt;/span&amp;gt;&lt;br /&gt;
 % BSEBands&lt;br /&gt;
    25 |  28 |                 # [BSK] Bands range&lt;br /&gt;
 %&lt;br /&gt;
 WRbsWF                      # [BSS] Write to disk excitonic the FWs&lt;br /&gt;
 &lt;br /&gt;
This file was generated using the command: &amp;lt;code&amp;gt; yambo -X s -o b -k sex -y d -r&amp;lt;/code&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
First of all, we compute the excitons for all the momenta in the irreducible Brillouin zone for our discrete grid via the &amp;lt;code&amp;gt;BSEQptR&amp;lt;/code&amp;gt; variable. This will be a &#039;&#039;&#039;finite-momentum&#039;&#039;&#039; BSE calculation, analogous to the phonon one.&lt;br /&gt;
&lt;br /&gt;
Second, we change the variable &amp;lt;code&amp;gt;Lkind&amp;lt;/code&amp;gt; from &amp;lt;code&amp;gt;bar&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;full&amp;lt;/code&amp;gt;. In Yambo, &amp;lt;code&amp;gt;Lkind=&amp;quot;bar&amp;quot;&amp;lt;/code&amp;gt;, which is the default for optical absorption, means that we are computing the excitonic response function without the long-range component of the exchange interaction. This cannot be used when computing the exciton momentum dependence, where the long-range exchange interaction can play a role, therefore we have to include it with &amp;lt;code&amp;gt;Lkind=&amp;quot;full&amp;quot;&amp;lt;/code&amp;gt;. This allows for the calculation of the excitonic longitudinal-transverse splitting (in 3D systems) as well.&lt;br /&gt;
&lt;br /&gt;
We can now run the code:&lt;br /&gt;
&lt;br /&gt;
 nohup mpirun -np 8 yambo -F bse.in -J bse_Lfull -C bse_Lfull &amp;amp;&lt;br /&gt;
&lt;br /&gt;
At the end of the calculation, we have obtained the &amp;lt;code&amp;gt;ndb.BS_diago_Q*&amp;lt;/code&amp;gt; databases inside the directory &amp;lt;code&amp;gt;bse_Lfull&amp;lt;/code&amp;gt;. They contain information on the exciton energies and wavefunctions at each momentum. Do not forget to check the report and logs of your calculation in the same directory to make sure that the code is doing what you want.&lt;br /&gt;
&lt;br /&gt;
== Step 6: obtain the electron-phonon matrix elements ==&lt;br /&gt;
&lt;br /&gt;
We have finished the heavy simulations. Now it&#039;s time for the postprocessing. The first order of business is the reconstruction of the electron-phonon coupling matrix elements from the dvscf results and the electronic wavefunctions.&lt;br /&gt;
&lt;br /&gt;
In order to do this, we will run the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable of the &#039;&#039;&#039;LetzElPhC&#039;&#039;&#039; code. We will run via command line using yambopy, although it will be instructive to have look at the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; input files later.&lt;br /&gt;
&lt;br /&gt;
We run in the same directory where the Yambo &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; is (remember than you can also virtually move it with a symbolic link).&lt;br /&gt;
&lt;br /&gt;
Type:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y&lt;br /&gt;
&lt;br /&gt;
to see the help for the calculation. Have a look at the various flags and their description.&lt;br /&gt;
For example, if we want to do a serial run of LetzElPhC for bands from &amp;lt;math&amp;gt;n_i&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;n_f&amp;lt;/math&amp;gt;, we should type:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph path/of/ph_input.in -b n_i n_f&lt;br /&gt;
&lt;br /&gt;
Here &amp;lt;math&amp;gt;n_i&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;n_f&amp;lt;/math&amp;gt; are integers representing the initial and final band indices. &#039;&#039;&#039;Please note&#039;&#039;&#039;: in this case, the band index starts from 1 and the the interval of bands read by the code is &amp;lt;math&amp;gt;[n_i,n_f]&amp;lt;/math&amp;gt; including the extrema of the interval.&lt;br /&gt;
&lt;br /&gt;
These should coincide with those used for the Bethe-Salpeter kernel, i.e. those specified in the &amp;lt;code&amp;gt;BSEBands&amp;lt;/code&amp;gt; variable of the BSE input file (this is not strictly necessary, but certainly efficient since these calculations use a lot of disk space). &lt;br /&gt;
&lt;br /&gt;
For our system, we want to do a parallel calculation with 4 qpools and 2 kpools. In addition, we want to explicitly specify the path of the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable and avoid automatically deleting the LetzElPhC data. So we type:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph path/of/dvscf/mos2.dvscf -b 25 28 -par 4 2 -lelphc path/to/lelphc_exe&lt;br /&gt;
&lt;br /&gt;
At the end, check your directory: you should find the &amp;lt;code&amp;gt;lelphc.in&amp;lt;/code&amp;gt; input file that was run, let&#039;s inspect it: &lt;br /&gt;
&lt;br /&gt;
 # LetzElPhC input for yambo generated by yambopy&lt;br /&gt;
 nqpool      = 2&lt;br /&gt;
 nkpool      = 4&lt;br /&gt;
 start_bnd   = 25&lt;br /&gt;
 end_bnd     = 28&lt;br /&gt;
 save_dir    = ./SAVE&lt;br /&gt;
 kernel      = dfpt&lt;br /&gt;
 ph_save_dir = dvscf/ph_save&lt;br /&gt;
 convention = yambo&lt;br /&gt;
&lt;br /&gt;
Notice the variable &amp;lt;code&amp;gt;convention=yambo&amp;lt;/code&amp;gt;: what does it mean? At variance with QE and many other codes, Yambo uses the &amp;quot;backward&amp;quot; momentum transfer convention for electronic scatterings. That is, an electronic transition goes from band &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; and momentum &amp;lt;math&amp;gt;k-q&amp;lt;/math&amp;gt; to band &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; and momentum &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;. In the &amp;quot;forward&amp;quot; momentum transfer convention (the more standard one), the transitions go from &amp;lt;math&amp;gt;nk&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;mk+q&amp;lt;/math&amp;gt;. Therefore, this variable ensures that the electron-phonon coupling matrix elements are computed as &amp;lt;math&amp;gt;\langle mk|dV|nk-q\rangle&amp;lt;/math&amp;gt;. This will have consequences also in the formulation of the &#039;&#039;exciton&#039;&#039;-phonon coupling matrix element.&lt;br /&gt;
&lt;br /&gt;
You will also find a &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; database that contains the computed electron-phonon matrix elements, in the output format of &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In addition, if you check the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; folder:&lt;br /&gt;
&lt;br /&gt;
 ls SAVE/ndb.elph_gkkp*&lt;br /&gt;
&lt;br /&gt;
you will see that yambopy has created the Yambo-compatible electron-phonon databases.&lt;br /&gt;
&lt;br /&gt;
If you want to run LetzElPhC directly, without using yambopy, you can refer to its [[https://gitlab.com/lumen-code/LetzElPhC/-/blob/main/docs/main.pdf?ref_type=heads|user guide]].&lt;br /&gt;
Keep in mind that in this case, in order to convert the database to the &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases of Yambo, you will then need a couple of lines of python using the Yambopy class &amp;lt;code&amp;gt;ConvertElectronPhononDB&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;yambopy/letzelph_interface/lelph2y.py&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t need the &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases -- e.g., because you are doing the exc-ph postprocessing with yambopy -- you can run &amp;lt;code&amp;gt;yambopy l2y ...&amp;lt;/code&amp;gt; with the &amp;lt;code&amp;gt;--no_gkkp&amp;lt;/code&amp;gt; option.&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t need the &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; databases -- e.g., because you are using &amp;lt;code&amp;gt;yambo_ph&amp;lt;/code&amp;gt; for the exc-ph part -- you can run &amp;lt;code&amp;gt;yambopy l2y ...&amp;lt;/code&amp;gt; with the &amp;lt;code&amp;gt;--no_lelphc_dbs&amp;lt;/code&amp;gt; option.&lt;br /&gt;
&lt;br /&gt;
== Step 7: Obtain the exciton-phonon coupling ==&lt;br /&gt;
&lt;br /&gt;
Now, we can finally access our basic building block for exciton-phonon physics. This could be done entirely in python (using &#039;&#039;&#039;Yambopy&#039;&#039;&#039;), or by running &#039;&#039;&#039;Yambo&#039;&#039;&#039;. &lt;br /&gt;
&lt;br /&gt;
* For the &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&#039;&#039;&#039;Yambo postprocessing&#039;&#039;&#039;&amp;lt;/span&amp;gt; case (running yambo inputs with the &amp;lt;code&amp;gt;yambo_ph&amp;lt;/code&amp;gt; executable), &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&#039;&#039;&#039;follow the alternative route to Steps 7-8 [[Exciton-phonon coupling and luminescence - Yambo postprocessing|at this link]]&#039;&#039;&#039;&amp;lt;/span&amp;gt;.&lt;br /&gt;
* For the &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&#039;&#039;&#039;Yambopy postprocessing&#039;&#039;&#039;&amp;lt;/span&amp;gt; case (using flexible python scripting), &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&#039;&#039;&#039;keep following Steps 7-8 on this page&#039;&#039;&#039;&amp;lt;/span&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Our objective is obtaining the following quantity: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\mathcal{G}^\mu_{\alpha\lambda}(0,q)=\sum_{vv^\prime c k} A^{\alpha, *}_{cv^\prime} (k, q) g_{vv^\prime}^\mu (k,q) A^{\lambda}_{cv}(k,0) - \sum_{cc^\prime vk} A^{\alpha, *}_{c^\prime v} (k+q, q) g_{c^\prime c}^\mu (k+q,q) A^{\lambda}_{cv}(k, 0)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here, &amp;lt;math&amp;gt;A^{\alpha}_{cv}(k,q)&amp;lt;/math&amp;gt; are the exciton coefficients extracted from the eigenvector of the two-particles Hamiltonian during the BSE calculation in step 5, while &amp;lt;math&amp;gt;g_{nm}^\mu (k,q)&amp;lt;/math&amp;gt; are the electron-phonon coupling matrix elements obtained in step 6. As you can see, the exciton &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; undergoes phonon-mediated scattering to state &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; via phonon mode &amp;lt;math&amp;gt;\mu&amp;lt;/math&amp;gt;. The scattering can happen for the hole (valence, &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt;) or for the electron (conduction, &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
NB: &lt;br /&gt;
&lt;br /&gt;
(1) This is written in the &amp;quot;backward&amp;quot; momentum transfer convention used by Yambo. The momentum dependence is different in the &amp;quot;forward&amp;quot; transfer convention. &lt;br /&gt;
&lt;br /&gt;
(2) For simplicity, this is written for zero initial exciton momentum. This means that one of the two states involved in the phonon-mediated scattering process will be in the optical limit (and possibly an optically generated exciton), while the other state can have any momentum: this momentum will be the same as the phonon one. This matrix element can be used to describe phonon-assisted absorption and emission spectra.&lt;br /&gt;
&lt;br /&gt;
In order to calculate this quantity using python, we need the &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; databases natively generated by the &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; code, as well as the BSE databases &amp;lt;code&amp;gt;ndb.BS_diago_Q*&amp;lt;/code&amp;gt; containing the information on exciton wavefunctions and energies.&lt;br /&gt;
&lt;br /&gt;
Next, we write a python user script importing the yambopy exciton-phonon tools. You can find a version of this script in &amp;lt;code&amp;gt;yambopy/tutorials/exciton-phonon/calculate_excph.py&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
 import numpy as np &lt;br /&gt;
 from yambopy import YamboLatticeDB,YamboWFDB,LetzElphElectronPhononDB &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;#Specific Yambopy dbs loading classes&amp;lt;/span&amp;gt;&lt;br /&gt;
 from yambopy.exciton_phonon.excph_matrix_elements import exciton_phonon_matelem &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;#Specific exc-ph functions&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 path = &#039;1L_MoS2&#039;&lt;br /&gt;
 bands_range=[24,28] &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# 2 valence bands, 2 conduction bands&amp;lt;/span&amp;gt;&lt;br /&gt;
 nexc = 12 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# number of excitonic states&amp;lt;/span&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 bsepath    = f&#039;{path}/bse-allq_full&#039; &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Path to BSE calculation (Lin=Lout)&amp;lt;/span&amp;gt;&lt;br /&gt;
 savepath   = f&#039;{path}/SAVE&#039;     &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Yambo SAVE&amp;lt;/span&amp;gt;&lt;br /&gt;
 ndb_elph   = f&#039;{path}/ndb.elph&#039; &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# LetzElPhC electron-phonon database (any convention)&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Read lattice&amp;lt;/span&amp;gt;&lt;br /&gt;
 lattice = YamboLatticeDB.from_db_file(filename=f&#039;{savepath}/ns.db1&#039;)&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Read electron-phonon&amp;lt;/span&amp;gt;&lt;br /&gt;
 elph    = LetzElphElectronPhononDB(ndb_elph,read_all=False)&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Read wave functions&amp;lt;/span&amp;gt;&lt;br /&gt;
 wfcs    = YamboWFDB(filename=&#039;ns.wf&#039;,save=savepath,latdb=lattice,bands_range=bands_range)&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Calculate exciton-phonon matrix elements&amp;lt;/span&amp;gt;&lt;br /&gt;
 exph = exciton_phonon_matelem(lattice,elph,wfcs,BSE_dir=bsepath,nexc_in=nexc,nexc_out=nexc,dmat_mode=&#039;save&#039;,exph_file=&#039;MoS2_Ex-ph.npy&#039;)&lt;br /&gt;
&lt;br /&gt;
In this script, we can select the number exciton states &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; with &amp;lt;code&amp;gt;nexc&amp;lt;/code&amp;gt;, the single-particle bands range with &amp;lt;code&amp;gt;bands_range&amp;lt;/code&amp;gt;. &#039;&#039;&#039;Please note&#039;&#039;&#039;: in this case, the band index starts from 0 (python indexing) and the the interval of bands read by the code is &amp;lt;math&amp;gt;[n_i,n_f)&amp;lt;/math&amp;gt;, therefore the last value (28 in the example) is excluded. That is, in the example we are selecting the 25th, 26th, 27th and 28th bands. Those bands have to be present in both the electron-phonon and BSE calculations. &lt;br /&gt;
&lt;br /&gt;
Here we calculate the couplings of the first twelve states at each finite-&amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; point including &amp;lt;math&amp;gt;q=0&amp;lt;/math&amp;gt;. We also include all the nine phonon modes of monolayer MoS2. We also need access to the Yambo &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory in order to read the electronic wavefunctions: they are used to compute the electronic representation matrices (&amp;lt;code&amp;gt;dmat&amp;lt;/code&amp;gt; in the code). The argument &amp;lt;code&amp;gt;dmat_mode&amp;lt;/code&amp;gt; can be set to &amp;lt;code&amp;gt;&#039;load&#039;&amp;lt;/code&amp;gt; for subsequent calculations.&lt;br /&gt;
&lt;br /&gt;
When we are satisfied with the input, we run the code:&lt;br /&gt;
&lt;br /&gt;
 python calculate_excph.py&lt;br /&gt;
&lt;br /&gt;
If you check the output, you should find the &amp;lt;code&amp;gt;MoS2_Ex-ph.npy&amp;lt;/code&amp;gt; binary file in the directory where you ran.&lt;br /&gt;
&lt;br /&gt;
=== Analysis of the couplings ===&lt;br /&gt;
&lt;br /&gt;
It is a good idea to have a look at what we computed up to now in order to make sure nothing has gone wrong. &lt;br /&gt;
&lt;br /&gt;
It is not easy to know what to expect (apart from symmetry and gauge compliance of the matrix elements), but one can work out the exciton-phonon selection rules in advance, check that the magnitude is reasonable, etc.&lt;br /&gt;
&lt;br /&gt;
It is also not easy to meaningfully plot this quantity. We have to make sure that we are not breaking degenerate states, otherwise the plots will not be invariant. &lt;br /&gt;
&lt;br /&gt;
First of all, we have to know our system: in monolayer MoS&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt;, the first four excitons are all doubly degenerate. The first exciton responsible for a bright peak in the absorption spectrum (the &#039;&#039;&#039;A&#039;&#039;&#039; peak), is the second state, corresponding to state indices &amp;lt;code&amp;gt;(3,4)&amp;lt;/code&amp;gt; in fortran indexing or &amp;lt;code&amp;gt;(2,3)&amp;lt;/code&amp;gt; in python indexing. &lt;br /&gt;
&lt;br /&gt;
All these information can be obtained by analyzing the BSE results (this stuff is explained in the BSE tutorials) and by knowledge of the system or class of systems from the literature.&lt;br /&gt;
&lt;br /&gt;
Thus, a good quantity to plot may be the norm of the matrix elements, summed over the degenerate subspace of exciton A, for a certain number of scattered final states mediated by certain phonon modes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;F_A(q)= \sqrt{ \sum_{\alpha \in A,\lambda,\mu} |\mathcal{G}_{\alpha\lambda}^\mu (0,q)|^2 }&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In order to do this, we create a python script &amp;lt;code&amp;gt;analyse_excph.py&amp;lt;/code&amp;gt; in which we first load the excph dabatases. &lt;br /&gt;
You can find a version of this script in the yambopy directory, in &amp;lt;code&amp;gt;tutorials/exciton-phonon&amp;lt;/code&amp;gt;. &lt;br /&gt;
First, we select the exciton and phonon states to be included in &amp;lt;code&amp;gt;F_A&amp;lt;/code&amp;gt;, together with the path of databases and plot details:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Exciton &amp;quot;in&amp;quot; states&amp;lt;/span&amp;gt;&lt;br /&gt;
 exc_in  = [2,3]  &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# First bright peak (A: 2,3 -- B: 6,7)&amp;lt;/span&amp;gt;&lt;br /&gt;
 exc_out = [0,1,2,3] &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# first 4 states (dispersion of dark triplet state and A)&amp;lt;/span&amp;gt;&lt;br /&gt;
 ph_in  = &#039;all&#039;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Paths of databases&amp;lt;/span&amp;gt;&lt;br /&gt;
 ns_db1 =f&#039;{path}/SAVE/ns.db1&#039;&lt;br /&gt;
 ns_ypy = &#039;MoS2_Ex-ph.npy&#039;&lt;br /&gt;
 &lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
Then, we load the data:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Read lattice and k-space info&amp;lt;/span&amp;gt;&lt;br /&gt;
 ylat = YamboLatticeDB.from_db_file(filename=ns_db1)&lt;br /&gt;
 print(ylat)&lt;br /&gt;
 &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Load exc-ph database&amp;lt;/span&amp;gt;&lt;br /&gt;
 X_py = np.load(ns_ypy)&lt;br /&gt;
 G_squared = np.abs(X_py)**2.&lt;br /&gt;
&lt;br /&gt;
The quantity &amp;lt;math&amp;gt;F_A(q)&amp;lt;/math&amp;gt; is obtained from a dedicated function as:&lt;br /&gt;
 &lt;br /&gt;
 if exc_in  == &#039;all&#039;: exc_in  = range(G_squared.shape[2])&lt;br /&gt;
 if exc_out == &#039;all&#039;: exc_out = range(G_squared.shape[3])&lt;br /&gt;
 if ph_in   == &#039;all&#039;: ph_in   = range(G_squared.shape[1])&lt;br /&gt;
 &lt;br /&gt;
 G_squared = G_squared[:, ph_in, :, :].sum(axis=(1))&lt;br /&gt;
 G_squared = G_squared[:, exc_in, :].sum(axis=(1))&lt;br /&gt;
 G_squared = G_squared[:, exc_out].sum(axis=(1))&lt;br /&gt;
 &lt;br /&gt;
 F_q = np.sqrt( G_squared )*ha2ev &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Switch from Ha to eV&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And finally, we have to make a plotting function. For this tutorial we will use a custom scatterplot employing some of the plotting tools provided by yambopy (but you can do whatever you want).&lt;br /&gt;
&lt;br /&gt;
 plot_2D_excph(qgrid,G2_to_plot,rlat=ylat.rlat,plt_cbar=True,\&lt;br /&gt;
               marker=&#039;H&#039;,s=700,cmap=&#039;magma&#039;)&lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
You can get more experience on using Yambopy for these kinds of visualization by following the [https://wiki.yambo-code.eu/wiki/index.php?title=First_steps_in_Yambopy Yambopy tutorials]. In fact, remember that these scripts and all the other Yambopy tutorial scripts are just suggestions, not source code written in stone: if you know &amp;lt;code&amp;gt;numpy&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;matplotlib&amp;lt;/code&amp;gt; you can do your own analysis and your own plots, you just need to import the required Yambopy modules to load the data.&lt;br /&gt;
&lt;br /&gt;
In our case, the resulting plot is the following.&lt;br /&gt;
&lt;br /&gt;
[[File:1L MoS2 MoS2 Ex-ph.png|500px|center]]&lt;br /&gt;
&lt;br /&gt;
This can be checked against Fig. 2(d) of reference &amp;lt;ref name=&amp;quot;chan2023&amp;quot; /&amp;gt;, although you have to keep in mind that our results are badly undersampled in terms of the reciprocal-space grid, as can be easily seen, and the quantity plotted is not exactly the same. However, the main features are already there since they are dictated mostly by crystal symmetries.&lt;br /&gt;
&lt;br /&gt;
Now that we have the exciton-phonon matrix elements, we can use them to build several kinds of observables. Below, we give an example related to phonon-assisted luminescence, but we may update this tutorial in the future to include more cases.&lt;br /&gt;
&lt;br /&gt;
== Step 8: Compute phonon-assisted luminescence ==&lt;br /&gt;
&lt;br /&gt;
[[File:Luminescence scheme.png|250px|right]]&lt;br /&gt;
&lt;br /&gt;
We want to compute the experimental optical signature due to the phonon-assisted recombination of an exciton (as sketched in the figure).&lt;br /&gt;
&lt;br /&gt;
The signal from the phonon replicas can be modeled as a second-order scattering process involving one phonon and one photon:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;I^{Sat}(\omega)=\frac{1}{ N_q} \frac{1}{3} \sum_{\epsilon s\beta \mu q} \frac{1}{E_{\beta q}-s\Omega_{\mu q}}\left|\sum_\alpha\frac{ D^{\epsilon}_\alpha \mathcal{G}_{\beta \alpha}^{\mu,*}(q)}{E_\alpha -E_{\beta q} +s\Omega_{\mu q}+\mathrm{i}\eta}\right|^2 \frac{N^{exc}_{\beta q}(T_{exc})[\frac{1+s}{2}+n_{\mu q}(T)]}{\omega -[E_{\beta q}-s\Omega_{\mu q}]+\mathrm{i}\eta}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this equation, the oscillator strength of the peak is given by the exciton-phonon coupling matrix elements &amp;lt;math&amp;gt;\mathcal{G}&amp;lt;/math&amp;gt; multiplied by the exciton dipoles &amp;lt;math&amp;gt;D&amp;lt;/math&amp;gt; (they are called &amp;quot;residuals&amp;quot; in Yambo). Here &amp;lt;math&amp;gt;E_\lambda&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;E_{\alpha q}&amp;lt;/math&amp;gt; are the energies of the optical and finite-momentum excitons, respectively, while &amp;lt;math&amp;gt;\Omega_{\mu q}&amp;lt;/math&amp;gt; are the phonon energies. &lt;br /&gt;
&lt;br /&gt;
Here, &amp;lt;math&amp;gt;n_{\mu q}(T)&amp;lt;/math&amp;gt; is the temperature-dependent phonon Bose-Einstein occupation function. As it can be seen, &amp;lt;math&amp;gt;s=1&amp;lt;/math&amp;gt; corresponds to processes of phonon &#039;&#039;emission&#039;&#039; (&amp;lt;math&amp;gt;\propto n(T)+1&amp;lt;/math&amp;gt;), while &amp;lt;math&amp;gt;s=-1&amp;lt;/math&amp;gt; corresponds to processes of phonon &#039;&#039;absorption&#039;&#039; (&amp;lt;math&amp;gt;\propto n(T)&amp;lt;/math&amp;gt;). Therefore, &amp;lt;math&amp;gt;I^{Sat}_{PL}(\omega;T)&amp;lt;/math&amp;gt; describes &#039;&#039;light&#039;&#039; emission by recombining excitons mediated by either &#039;&#039;phonon&#039;&#039; absorption or emission. &lt;br /&gt;
&lt;br /&gt;
The quantity &amp;lt;math&amp;gt; N_{\alpha q}(T_{exc})&amp;lt;/math&amp;gt; is the exciton occupation function. Luminescence is technically an out-of-equilibrium process, but we can assume that for very low density of excitations and in steady-state conditions, the exciton population can be approximately described by an equilibrium distribution evaluated at an effective temperature. Here, we use the Boltzmann distribution. Experimentally, &amp;lt;math&amp;gt;T_{exc}&amp;lt;/math&amp;gt; tends to coincide with the lattice temperature &amp;lt;math&amp;gt;T&amp;lt;/math&amp;gt; more or less above 100 K, while at very low temperature (&amp;lt; 10 K), &amp;lt;math&amp;gt;T_{exc}&amp;lt;/math&amp;gt; may vary between 10-50 K. It goes without saying that this needs to carefully be checked in your realistic calculations.&lt;br /&gt;
&lt;br /&gt;
Finally, the spectrum is averaged over the polarization directions of the emitted photons (&amp;lt;math&amp;gt;\epsilon=x,y,z&amp;lt;/math&amp;gt; representing the respective dipole components).&lt;br /&gt;
&lt;br /&gt;
=== Running the jobs ===&lt;br /&gt;
&lt;br /&gt;
In order to study luminescence in a paradigmatic system, we switch to bulk hexagonal boron nitride and we repeat the workflow. As you can easily see, one can think about automatizing the execution of all these calculations via scripting or more advanced tools. However, in the case of very large simulations (memory-limited or disk-space limited) or for systems whose electronic and lattice properties are fragile with respect to tiny calculation details, one must be very careful and run many basic tests.&lt;br /&gt;
&lt;br /&gt;
Fortunately, we are running a fast underconverged example. We use LDA pseudopotentials from the pseudo-dojo library and the following are the calculations steps.&lt;br /&gt;
&lt;br /&gt;
1. Input &amp;lt;code&amp;gt;hbn.scf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 &amp;amp;control&lt;br /&gt;
     calculation=&#039;scf&#039;,&lt;br /&gt;
     prefix=&#039;hBN&#039;,&lt;br /&gt;
     restart_mode=&#039;from_scratch&#039;&lt;br /&gt;
     pseudo_dir = &#039;$PSEUDO_DIR&#039;,&lt;br /&gt;
     outdir = &#039;./tmp&#039;&lt;br /&gt;
     verbosity = &#039;high&#039;&lt;br /&gt;
     wf_collect=.true.&lt;br /&gt;
 /&lt;br /&gt;
 &amp;amp;system&lt;br /&gt;
     ibrav = 4,&lt;br /&gt;
     celldm(1) = 4.703675849&lt;br /&gt;
     celldm(3) = 2.603711434&lt;br /&gt;
     nat= 4,&lt;br /&gt;
     ntyp= 2,&lt;br /&gt;
     force_symmorphic=.true.&lt;br /&gt;
     ecutwfc = 100,&lt;br /&gt;
 /&lt;br /&gt;
 &amp;amp;electrons&lt;br /&gt;
   diago_david_ndim = 2&lt;br /&gt;
   diago_full_acc=.true.&lt;br /&gt;
   diago_thr_init=5.0e-6&lt;br /&gt;
   mixing_mode = &#039;plain&#039;&lt;br /&gt;
   mixing_beta = 0.7&lt;br /&gt;
   conv_thr =  1.0d-16&lt;br /&gt;
 /&lt;br /&gt;
 ATOMIC_SPECIES&lt;br /&gt;
  B 10.81100  B_LDA_dojo.UPF&lt;br /&gt;
  N 14.00674  N_LDA_dojo.UPF&lt;br /&gt;
 ATOMIC_POSITIONS {crystal}&lt;br /&gt;
 N             0.6666666670        0.3333333330        -0.250000000000&lt;br /&gt;
 B             0.3333333330        0.6666666670        -0.250000000000&lt;br /&gt;
 B             0.6666666670        0.3333333330        0.25000000000&lt;br /&gt;
 N             0.3333333330        0.6666666670        0.25000000000&lt;br /&gt;
 K_POINTS {automatic}&lt;br /&gt;
 6 6 2 0 0 0&lt;br /&gt;
&lt;br /&gt;
 mpirun -np 4 pw.x -inp hbn.scf &amp;gt; scf.out&lt;br /&gt;
&lt;br /&gt;
2. Input &amp;lt;code&amp;gt;hbn.nscf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 &amp;amp;control&lt;br /&gt;
     calculation=&#039;nscf&#039;,&lt;br /&gt;
     prefix=&#039;hBN&#039;,&lt;br /&gt;
     restart_mode=&#039;from_scratch&#039;&lt;br /&gt;
     pseudo_dir = &#039;$PSEUDO_DIR&#039;&lt;br /&gt;
     outdir = &#039;./&#039;&lt;br /&gt;
     verbosity = &#039;high&#039;&lt;br /&gt;
     wf_collect=.true.&lt;br /&gt;
 /&lt;br /&gt;
 &amp;amp;system&lt;br /&gt;
     ibrav = 4,&lt;br /&gt;
     celldm(1) = 4.703675849&lt;br /&gt;
     celldm(3) = 2.603711434&lt;br /&gt;
     nat= 4,&lt;br /&gt;
     ntyp= 2,&lt;br /&gt;
     force_symmorphic=.true.&lt;br /&gt;
     ecutwfc = 100,&lt;br /&gt;
 	nbnd = 120&lt;br /&gt;
 /&lt;br /&gt;
 &amp;amp;electrons&lt;br /&gt;
   diago_david_ndim = 2&lt;br /&gt;
   diago_full_acc=.true.&lt;br /&gt;
   diago_thr_init=5.0e-6&lt;br /&gt;
   mixing_mode = &#039;plain&#039;&lt;br /&gt;
   mixing_beta = 0.7&lt;br /&gt;
   conv_thr =  1.0d-16&lt;br /&gt;
 /&lt;br /&gt;
 ATOMIC_SPECIES&lt;br /&gt;
  B 10.81100  B_LDA_dojo.UPF&lt;br /&gt;
  N 14.00674  N_LDA_dojo.UPF&lt;br /&gt;
 ATOMIC_POSITIONS {crystal}&lt;br /&gt;
 N             0.6666666670        0.3333333330        -0.250000000000&lt;br /&gt;
 B             0.3333333330        0.6666666670        -0.250000000000&lt;br /&gt;
 B             0.6666666670        0.3333333330        0.25000000000&lt;br /&gt;
 N             0.3333333330        0.6666666670        0.25000000000&lt;br /&gt;
 K_POINTS {automatic}&lt;br /&gt;
 6 6 2 0 0 0&lt;br /&gt;
&lt;br /&gt;
 mpirun -np 4 pw.x -inp hbn.nscf &amp;gt; nscf.out&lt;br /&gt;
&lt;br /&gt;
3. Input &amp;lt;code&amp;gt;hbn.dvscf&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 hbn_dvscf&lt;br /&gt;
 &amp;amp;inputph&lt;br /&gt;
   tr2_ph=1.0d-12,&lt;br /&gt;
   verbosity=&#039;high&#039;&lt;br /&gt;
   prefix=&#039;hBN&#039;,&lt;br /&gt;
   fildvscf = &#039;hBN-dvscf&#039;,&lt;br /&gt;
   electron_phonon = &#039;dvscf&#039;,&lt;br /&gt;
   fildyn=&#039;hBN.dyn&#039;,&lt;br /&gt;
   epsil=.false.,&lt;br /&gt;
   ldisp=.true.,&lt;br /&gt;
   recover=.true.,&lt;br /&gt;
   nq1=6,&lt;br /&gt;
   nq2=6,&lt;br /&gt;
   nq3=2&lt;br /&gt;
 /&lt;br /&gt;
&lt;br /&gt;
 nohup mpirun -np 8 pw.x -inp hbn.dvscf &amp;gt; dvscf.out &amp;amp;&lt;br /&gt;
&lt;br /&gt;
4. Input &amp;lt;code&amp;gt;bse.in&amp;lt;/code&amp;gt; (we include 2 valence and 2 conduction bands):&lt;br /&gt;
&lt;br /&gt;
 optics                           # [R] Linear Response optical properties&lt;br /&gt;
 bss                              # [R] BSE solver&lt;br /&gt;
 bse                              # [R][BSE] Bethe Salpeter Equation.&lt;br /&gt;
 dipoles                          # [R] Oscillator strenghts (or dipoles)&lt;br /&gt;
 em1s&lt;br /&gt;
 DIP_CPU= &amp;quot;1 8 1&amp;quot;                      # [PARALLEL] CPUs for each role&lt;br /&gt;
 DIP_ROLEs= &amp;quot;k c v&amp;quot;                    # [PARALLEL] CPUs roles (k,c,v)&lt;br /&gt;
 DIP_Threads=0                    # [OPENMP/X] Number of threads for dipoles&lt;br /&gt;
 X_and_IO_CPU= &amp;quot;1 1 1 8 1&amp;quot;                 # [PARALLEL] CPUs for each role&lt;br /&gt;
 X_and_IO_ROLEs= &amp;quot;q g k c v&amp;quot;               # [PARALLEL] CPUs roles (q,g,k,c,v)&lt;br /&gt;
 X_and_IO_nCPU_LinAlg_INV=-1      # [PARALLEL] CPUs for Linear Algebra (if -1 it is automatically set)&lt;br /&gt;
 X_Threads=0                      # [OPENMP/X] Number of threads for response functions&lt;br /&gt;
 BS_CPU= &amp;quot;8 1 1&amp;quot;                       # [PARALLEL] CPUs for each role&lt;br /&gt;
 BS_ROLEs= &amp;quot;k eh t&amp;quot;                     # [PARALLEL] CPUs roles (k,eh,t)&lt;br /&gt;
 BS_nCPU_LinAlg_INV=-1            # [PARALLEL] CPUs for Linear Algebra (if -1 it is automatically set)&lt;br /&gt;
 BS_nCPU_LinAlg_DIAGO=-1          # [PARALLEL] CPUs for Linear Algebra (if -1 it is automatically set)&lt;br /&gt;
 X_Threads=0                      # [OPENMP/X] Number of threads for response functions&lt;br /&gt;
 K_Threads=0                      # [OPENMP/BSK] Number of threads for response functions&lt;br /&gt;
 % QpntsRXs&lt;br /&gt;
    1 | 14 |                         # [Xs] Transferred momenta&lt;br /&gt;
 %&lt;br /&gt;
 % BndsRnXs&lt;br /&gt;
    1 | 120 |                         # [Xs] Polarization function bands&lt;br /&gt;
 %&lt;br /&gt;
 NGsBlkXs= 10                Ry    # [Xs] Response block size&lt;br /&gt;
 % LongDrXs&lt;br /&gt;
  1.000000 | 1.000000 | 1.000000 |        # [Xs] [cc] Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 BSEmod= &amp;quot;resonant&amp;quot;               # [BSE] resonant/retarded/coupling&lt;br /&gt;
 BSKmod= &amp;quot;SEX&amp;quot;                    # [BSE] IP/Hartree/HF/ALDA/SEX/BSfxc&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;Lkind= &amp;quot;Lfull&amp;quot;                    # [BSE] Lbar (default) / full&amp;lt;/span&amp;gt;&lt;br /&gt;
 BSSmod= &amp;quot;d&amp;quot;                      # [BSS] (h)aydock/(d)iagonalization/(s)lepc/(i)nversion/(t)ddft`&lt;br /&gt;
 % DipBands&lt;br /&gt;
    1 | 120 |                         # [DIP] Bands range for dipoles&lt;br /&gt;
 %&lt;br /&gt;
 DipApproach= &amp;quot;G-space v&amp;quot;         # [DIP] [G-space v/R-space x/Covariant/Shifted grids]&lt;br /&gt;
 DipComputed= &amp;quot;R V P&amp;quot;             # [DIP] [default R P V; extra P2 Spin Orb]&lt;br /&gt;
 BSENGexx= 30000            Ry    # [BSK] Exchange components&lt;br /&gt;
 #ALLGexx                       # [BSS] Force the use use all RL vectors for the exchange part&lt;br /&gt;
 BSENGBlk=  9000            Ry    # [BSK] Screened interaction block size [if -1 uses all the G-vectors of W(q,G,Gp)]&lt;br /&gt;
 % KfnQP_E&lt;br /&gt;
  1.25997 | 1.08816 | 1.12683 |        # [EXTQP BSK BSS] E parameters  (c/v) eV|adim|adim&lt;br /&gt;
 %&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;% BSEQptR&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 1 | 14 |                     # [BSK] Transferred momenta range&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;%&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;% BSEBands&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;   7 | 10 |                         # [BSK] Bands range&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;%&amp;lt;/span&amp;gt;&lt;br /&gt;
 % BEnRange&lt;br /&gt;
   0.50000 | 8.00000 |         eV    # [BSS] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 % BDmRange&lt;br /&gt;
  0.050000 | 0.050000 |         eV    # [BSS] Damping range&lt;br /&gt;
 %&lt;br /&gt;
 BEnSteps= 1000                    # [BSS] Energy steps&lt;br /&gt;
 % BLongDir&lt;br /&gt;
  1.000000 | 1.000000 | 0.000000 |        # [BSS] [cc] Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 WRbsWF                        # [BSS] Write to disk excitonic the WFs&lt;br /&gt;
&lt;br /&gt;
 nohup mpirun -np 8 yambo -F bse.in -J bse_Lfull -C bse_Lfull &amp;amp;&lt;br /&gt;
&lt;br /&gt;
Importantly, since we want to describe the phonon-assisted recombination process of an *optical* exciton (i.e., emitting a transverse photon), this time we also run an additional calculation at `Q=0` omitting the nonanalytic long-range Coulomb exchange. Make a second input &amp;lt;code&amp;gt;bse_Lbar.in&amp;lt;/code&amp;gt; with the following changes: &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;Lkind= &amp;quot;Lbar&amp;quot;                    # [BSE] Lbar (default) / full&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;% BSEQptR&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 1 | 1 |                     # [BSK] Transferred momenta range&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;%&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
4b. So now we make a second BSE run in a different directory specified by &amp;lt;code&amp;gt;-J&amp;lt;/code&amp;gt;. Here, we also pass to yambo the directory of the previous run as it includes the important screening databases &amp;lt;code&amp;gt;ndb.em1s*&amp;lt;/code&amp;gt; that we do not want to recompute from scratch.&lt;br /&gt;
 &lt;br /&gt;
 mpirun -np 8 yambo -F bse_Lbar.in -J bse_Lbar,bse_Lfull -C bse_Lbar&lt;br /&gt;
&lt;br /&gt;
5. Now we run &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; (with or without yambopy: in the latter case remember the option &amp;lt;code&amp;gt;-D&amp;lt;/code&amp;gt;) to get the el-ph matrix elements, particularly the &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; databases:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph path/of/dvscf/hbn.dvscf -b 7 10 -par 4 2 -D&lt;br /&gt;
&lt;br /&gt;
=== Luminescence calculation ===&lt;br /&gt;
&lt;br /&gt;
6. And finally we calculate exciton-phonon matrix elements and the luminescence spectrum in one go using a python script importing the Yambopy exciton-phonon tools: in order to do this, we need to take a look at all the necessary input variables for the formula written above.&lt;br /&gt;
&lt;br /&gt;
We can start from the script &amp;lt;code&amp;gt;luminescence.py&amp;lt;/code&amp;gt; available in &amp;lt;code&amp;gt;tutorials/exciton-phonon&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
 import numpy as np&lt;br /&gt;
 import matplotlib.pyplot as plt&lt;br /&gt;
 from yambopy.exciton_phonon.excph_luminescence import exc_ph_luminescence&lt;br /&gt;
 from yambopy.exciton_phonon.excph_input_data import exc_ph_get_inputs&lt;br /&gt;
&lt;br /&gt;
We import the necessary tools...&lt;br /&gt;
&lt;br /&gt;
 path = &#039;3D_hBN&#039;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Path to BSE calculation (Lout--&amp;gt; response is Lfull)&amp;lt;/span&amp;gt;&lt;br /&gt;
 bsepath =  f&#039;{path}/bse_Lfull&#039; &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# ndb.BS_diago_Q* databases are needed&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Path to BSE calculation for optically active exciton (Lin --&amp;gt; response is Lbar)&amp;lt;/span&amp;gt;&lt;br /&gt;
 bseBARpath =  f&#039;{path}/bse_Lbar&#039;  &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# ndb.BS_diago_Q1 database is needed&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Path to electron-phonon calculation&amp;lt;/span&amp;gt;&lt;br /&gt;
 elphpath = path &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# ndb.elph is needed&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Path to unprojected dipoles matrix elements (optional)&amp;lt;/span&amp;gt;&lt;br /&gt;
 dipolespath = bsepath &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# ndb.dipoles is needed (optional)&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Path to lattice and k-space info&amp;lt;/span&amp;gt;&lt;br /&gt;
 savepath = f&#039;{path}/SAVE&#039; &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# ns.db1 database is needed&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
... and we specify the paths to the necessary databases. Note that, if we want to perform polarization averaging, we have to recompute the excitonic dipoles in python as seen here.&lt;br /&gt;
&lt;br /&gt;
What about &amp;lt;code&amp;gt;bseBARpath&amp;lt;/code&amp;gt;? This variable points to the directory where the databases for the optical (zero-momentum) excitons &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; (which may be computed with &amp;lt;code&amp;gt;Lkind=&#039;Lbar&#039;&amp;lt;/code&amp;gt;) is located, which can be different from the directory with the full indirect exciton dispersion &amp;lt;math&amp;gt;\beta&amp;lt;/math&amp;gt; (usually computed with &amp;lt;code&amp;gt;Lkind=&#039;Lfull&#039;&amp;lt;/code&amp;gt;, however &amp;lt;code&amp;gt;Lkind=&#039;Ltilde&#039;&amp;lt;/code&amp;gt; can also be used if one is interested in &amp;quot;irreducible&amp;quot; excitons). This makes it possible to compute the coupling between different exciton kinds.&lt;br /&gt;
&lt;br /&gt;
 bands_range=[6,10] &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# 2 valence, 2 conduction bands&amp;lt;/span&amp;gt;&lt;br /&gt;
 phonons_range=[0,12] &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# All phonons&amp;lt;/span&amp;gt;&lt;br /&gt;
 nexc_out = 12 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# 12 excitonic states at each momentum (Lout)&amp;lt;/span&amp;gt;&lt;br /&gt;
 nexc_in  = 12 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# 12 excitonic states at Q=0 (Lin)&amp;lt;/span&amp;gt;&lt;br /&gt;
 T_ph  = 10 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Lattice temperature&amp;lt;/span&amp;gt;&lt;br /&gt;
 T_exc = 10 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Effective excitonic temperature&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 emin=4.4      &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Energy range and plot details (in eV)&amp;lt;/span&amp;gt;&lt;br /&gt;
 emax=4.7&lt;br /&gt;
 estep=0.0002&lt;br /&gt;
 broad = 0.005 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Broadening parameter for peak width (in eV)&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Next, we specify the parameters for the calculation. We include valence bands from 7 to 10 (6 to 9 in python index) and the contribution of all 12 phonon modes. We consider 12 excitonic states for the coupling matrix elements.&lt;br /&gt;
&lt;br /&gt;
Here &amp;lt;code&amp;gt;T_ph&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;T_exc&amp;lt;/code&amp;gt; are the lattice and excitonic temperatures, respectively.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# We calculate and load all the inputs:&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# * Exciton-phonon matrix elements&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# * Excitonic dipole matrix elements&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# * Exciton energies&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# * Phonon energies&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# * We specify bse_path2=bseBARpath meaning we use Lbar calculation for Q=0 excitons&amp;lt;/span&amp;gt;&lt;br /&gt;
 input_data = exc_ph_get_inputs(savepath,elphpath,bsepath,\&lt;br /&gt;
                                bse_path2=bseBARpath,dipoles_path=dipolespath,\&lt;br /&gt;
                                nexc_in=12,nexc_out=12,\&lt;br /&gt;
                                bands_range=[6,10],phonons_range=[0,12])&lt;br /&gt;
&lt;br /&gt;
 ph_energies, exc_energies, exc_energies_in, G, exc_dipoles = input_data&lt;br /&gt;
&lt;br /&gt;
The function &amp;lt;code&amp;gt;exc_ph_get_inputs&amp;lt;/code&amp;gt; gives us all the input data for luminescence in the correct format: phonon energies, exciton energies, optical exciton energies (if needed), exciton-phonon matrix elements (calculated on the fly and printed to file), unprojected exciton dipoles (optional, calculated on the fly and printed to file).&lt;br /&gt;
The exc-ph matrix element calculation is just a wrapper of the same tools that we have tested in the above section on MoS2.&lt;br /&gt;
&lt;br /&gt;
Finally, there is the calculation of the luminescence spectrum via the function &amp;lt;code&amp;gt;exc_ph_luminescence&amp;lt;/code&amp;gt;:&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# We calculate the luminescence spectrum including the input data from before&amp;lt;/span&amp;gt;&lt;br /&gt;
 w,PL = exc_ph_luminescence(T_ph,ph_energies,exc_energies,exc_dipoles,G,\&lt;br /&gt;
                            exc_energies_in=exc_energies_in,exc_temp=T_exc,\&lt;br /&gt;
                            nexc_out=nexc_out,nexc_in=nexc_in,emin=emin,emax=emax,\&lt;br /&gt;
                            estep=estep,broad=broad)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you want to print the luminescence data for later plotting, you can also add the following line to the script:&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# Save to file&amp;lt;/span&amp;gt;&lt;br /&gt;
 data = np.column_stack((w, PL))&lt;br /&gt;
 np.savetxt(&amp;quot;hBN_luminescence_12x12x1.dat&amp;quot;, data, fmt=&amp;quot;%.8f&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
It is now time to run the whole script:&lt;br /&gt;
&lt;br /&gt;
 python luminescence.py&lt;br /&gt;
 &lt;br /&gt;
NB: By using Yambopy for Step 6, we have limited the use of the Yambo code to just step 4 in the entire workflow. This option is more flexible, as it allows for a greater degree of control by the user. On the other hand the Yambo postprocessing route features a Yambo-style input that doesn&#039;t require python knowledge and the calculation is currently faster in fortran. However, the luminescence expression computed in Yambo is a slightly different than this one: it is more approximated in the description of the satellite oscillator strengths, but it explicitly includes the renormalization of the direct exciton peak. You can check the differences [[Exciton-phonon coupling and luminescence - Yambo postprocessing|here]].&lt;br /&gt;
&lt;br /&gt;
=== Results ===&lt;br /&gt;
We can plot the results of the step 6 calculation. If we do it in the same script we can add something like this:&lt;br /&gt;
 fig = plt.figure()&lt;br /&gt;
 ax = fig.add_subplot(1,1,1)&lt;br /&gt;
 ax.set_xlim(emin,emax)&lt;br /&gt;
 ax.set_ylim(0,np.max(PL)*1.1)&lt;br /&gt;
 ax.get_yaxis().set_visible(False)&lt;br /&gt;
 &lt;br /&gt;
 ax.plot(w, PL, &#039;-&#039;,c=&#039;red&#039;, label=&amp;quot;AA&#039; hBN luminescence&amp;quot;)&lt;br /&gt;
 &lt;br /&gt;
 plt.legend()&lt;br /&gt;
 plt.savefig(&#039;hBN_luminescence.png&#039;)&lt;br /&gt;
 plt.show()&lt;br /&gt;
&lt;br /&gt;
[[File:HBN luminescence satellites.png|500px|center]]&lt;br /&gt;
&lt;br /&gt;
Here, the signal corresponds to a finite-momentum exciton that recombines with the help of several different phonon modes, both optical and acoustic. Each phonon mode whose coupling with the exciton is allowed can generate a peak, and the energy shifts of these peaks with respect to the initial exciton energy correspond to the phonon energies. This result is underconverged, but the main features are all there. In the plot, we show a more converged example using a 12x12x4 grid (all the other parameters being equal). These plots can be compared with Fig. 4(a) of reference &amp;lt;ref name=&amp;quot;zanfrognini2023&amp;quot; /&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;references&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;toyozawa2003&amp;quot; &amp;gt;Toyozawa, Yutaka, and Chris Oxlade, &#039;&#039;Optical processes in solids&#039;&#039;, [https://m.booksee.org/book/1121964?force_lang=en Cambridge University Press, (2003)]. &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;lechifflart2023&#039;&amp;gt;P. Lechifflart, F. Paleari, D. Sangalli, C. Attaccalite, &#039;&#039;First-principles study of luminescence in hexagonal boron nitride single layer: Exciton-phonon coupling and the role of substrate&#039;&#039;, &lt;br /&gt;
[https://doi.org/10.1103/PhysRevMaterials.7.024006 Phys. Rev. M, &#039;&#039;&#039;7&#039;&#039;&#039; (2), 024006 (2023)]; [https://arxiv.org/abs/2212.10407 arXiv2212.1047]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;cannuccia2019&#039;&amp;gt;E. Cannuccia, B. Monserrat and C. Attaccalite, &#039;&#039;Theory of phonon-assisted luminescence in solids: Application to hexagonal boron nitride&#039;&#039;, [https://doi.org/10.1103/PhysRevB.99.081109 Phys. Rev. B &#039;&#039;&#039;99&#039;&#039;&#039;, 081109(R) (2019)]; [https://arxiv.org/abs/1807.11797 arXiv1807.11797]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;paleari2019&#039;&amp;gt;F. Paleari et al., &#039;&#039;Exciton-Phonon Coupling in the Ultraviolet Absorption and Emission Spectra of Bulk Hexagonal Boron Nitride&#039;&#039;, [https://doi.org/10.1103/PhysRevLett.122.187401 Phys. Rev. Lett. &#039;&#039;&#039;122&#039;&#039;&#039;, 187401 (2019)]; [https://arxiv.org/abs/1810.08976 arXiv1810.089776] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;chen2020&#039;&amp;gt;&#039;&#039;Exciton-Phonon Interaction and Relaxation Times from First Principles&#039;&#039;,&lt;br /&gt;
Hsiao-Yi Chen, Davide Sangalli, and Marco Bernardi, [https://doi.org/10.1103/PhysRevLett.125.107401  Phys. Rev. Lett. &#039;&#039;&#039;125&#039;&#039;&#039;, 107401 (2020)]; [https://arxiv.org/abs/2002.08913 arXiv 2002.08913 (2020)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&amp;quot;lechifflart2023_PhD&amp;quot;&amp;gt;P. Lechifflart, &#039;&#039;Exciton-phonon coupling and phonon-assisted luminescence in hexagonal Boron Nitride nanostructures&#039;&#039;, [https://hal.science/tel-04266805v1 PhD Thesis, University of Marseille (2023)]; [https://www.yambo-code.eu/wiki/images/5/54/These_final.pdf From the yambo website]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;paleari2019_PhD&#039;&amp;gt;F. Paleari, &#039;&#039;First-principles approaches to the description of indirect absorption and luminescence spectroscopy: exciton-phonon coupling in hexagonal boron nitride&#039;&#039;, [https://wwwen.uni.lu/research/fstm/dphyms/people/fulvio_paleari PhD thesis, University of Luxembourg (2019)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;zanfrognini2023&#039;&amp;gt;M. Zanfrognini et al., &#039;&#039;Distinguishing different stackings in layered materials via luminescence spectroscopy&#039;&#039;, [https://doi.org/10.1103/PhysRevLett.131.206902 Phys. Rev. Lett. &#039;&#039;&#039;131&#039;&#039;&#039;, 206902 (2023)]; [https://arxiv.org/abs/2305.17554 arXiv 2305.17554] &amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;marini2024&#039;&amp;gt;G. Marini, M. Calandra, P. Cudazzo, &#039;&#039;Optical absorption and photoluminescence of single layer boron nitride from a first principles cumulant approach&#039;&#039;, [https://doi.org/10.1021/acs.nanolett.4c00669 Nano Lett., &#039;&#039;&#039;24&#039;&#039;&#039;, 20, 6017 (2024)]; [https://arxiv.org/abs/2402.03826 arXiv 2402.03826 (2024)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;antonius2017&#039;&amp;gt;G. Antonius, S. G. Louie, &#039;&#039;Theory of exciton-phonon coupling&#039;&#039;, [https://doi.org/10.1103/PhysRevB.105.085111 Phys. Rev. B, &#039;&#039;&#039;105&#039;&#039;&#039;, 085111 (2022)]; [https://arxiv.org/abs/1705.04245 arXiv1705.04245 (2017)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;paleari2022&#039;&amp;gt; F. Paleari, and A. Marini, &#039;&#039;Exciton-phonon interaction calls for a revision of the “exciton” concept&#039;&#039;, [https://doi.org/10.1103/PhysRevB.106.125403 Phys. Rev. B, &#039;&#039;&#039;106&#039;&#039;&#039;, 125403 (2022)]; [https://arxiv.org/abs/2205.02783 arXiv 2205.02783]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;cudazzo2020&#039;&amp;gt; P. Cudazzo, &#039;&#039;First-principles description of the exciton-phonon interaction: A cumulant approach&#039;&#039;, [https://doi.org/10.1103/PhysRevB.102.045136 Phys. Rev. B, &#039;&#039;&#039;102&#039;&#039;&#039;, 045136 (2020)]; [https://orbilu.uni.lu/bitstream/10993/44769/1/main.pdf Open access pdf from Luxembourg University]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;chan2023&#039;&amp;gt;Y-h Chan, J. B. Haber, M. H. Naik, J. B. Neaton, D. Y. Qiu, F. H. da Jornada, S. G. Louie, &#039;&#039;Exciton Lifetime and Optical Line Width Profile via Exciton–Phonon Interactions: Theory and First-Principles Calculations for Monolayer MoS2&#039;&#039;, [https://doi.org/10.1021/acs.nanolett.3c00732 Nano Lett., &#039;&#039;&#039;23&#039;&#039;&#039;, 9 (2023)]; [https://arxiv.org/abs/2212.08451 arXiv 2212.08451 (2023)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;ref name=&#039;murali2025&#039;&amp;gt;M. Nalabothula, S. Reichardt, L. Wirtz, &#039;&#039;Origin of Interlayer Exciton–Phonon Coupling in 2D Heterostructures&#039;&#039;, [https://doi.org/10.1021/acs.nanolett.5c00355 Nano Lett., &#039;&#039;&#039;25&#039;&#039;&#039;, 15 (2025)], [https://arxiv.org/abs/2407.16111 arXiv 2407.16111 (2025)]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;/references&amp;gt;&lt;/div&gt;</summary>
		<author><name>FulvioPaleari</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_electron-phonon_coupling&amp;diff=9337</id>
		<title>Yambopy tutorial: electron-phonon coupling</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_electron-phonon_coupling&amp;diff=9337"/>
		<updated>2026-03-11T13:33:50Z</updated>

		<summary type="html">&lt;p&gt;FulvioPaleari: /* Command line: electron-phonon calculation and databases [OPTIONAL] */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial we will cover the handling of electron-phonon coupling matrix elements by Yambopy. The electron-phonon calculation follows two steps:&lt;br /&gt;
&lt;br /&gt;
# Quantum Espresso calculation of phonon energies, eigenmodes and variations of the self-consistent potential via &amp;lt;code&amp;gt;ph.x&amp;lt;/code&amp;gt;.&lt;br /&gt;
# Electron-phonon matrix element calculation, symmetry expansion and conversion by the &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For more information on the &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; code and how you should run step 1., please see the related documentation [https://github.com/yambo-code/LetzElPhC here].&lt;br /&gt;
&lt;br /&gt;
We can use Yambopy to:&lt;br /&gt;
* Run &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; (both preprocessing and main run) without explicitly writing an input file.&lt;br /&gt;
* Convert the resulting databases into &amp;lt;code&amp;gt;Yambo&amp;lt;/code&amp;gt; format.&lt;br /&gt;
* Analyse the electron-phonon coupling both in &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;Yambo&amp;lt;/code&amp;gt; format.&lt;br /&gt;
&lt;br /&gt;
In particular we will take a look at:&lt;br /&gt;
* Lattice geometry data (Yambo database: &amp;lt;code&amp;gt;ns.db1&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
* Electron-phonon matrix elements (Yambo databases: &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt;; LetzElPhC databases: &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;LetzElphElectronPhononDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
The scripts of the tutorial, but not the databases, can be found in the yambopy directory:&lt;br /&gt;
 $cd tutorial/electron_phonon&lt;br /&gt;
&lt;br /&gt;
The full tutorial, including the LetzElPhC and Yambo databases that we will read, can be downloaded and extracted from the yambo website:&lt;br /&gt;
  wget https://media.yambo-code.eu/educational/tutorials/files/yambopy_electron_phonon.tar.gz&lt;br /&gt;
  tar -xvzf yambopy_electron_phonon.tar.gz&lt;br /&gt;
  cd electron_phonon&lt;br /&gt;
&lt;br /&gt;
We will work with monolayer molybdenum disulphide electron-phonon data obtained on a &amp;lt;code&amp;gt;6x6x1&amp;lt;/code&amp;gt; kpoint grid, including spin-orbit interaction (so we deal with electron-phonon coupling and spinorial wavefunctions). Beware that the parameters are most certainly not converged.&lt;br /&gt;
&lt;br /&gt;
=== Command line: electron-phonon calculation and databases [OPTIONAL] ===&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&#039;&#039;&#039;Note&#039;&#039;&#039;: you can run this step only if you have compiled &#039;&#039;&#039;LetzElPhC&#039;&#039;&#039; and &#039;&#039;&#039;Quantum ESPRESSO&#039;&#039;&#039; on your machine. If not, please skip to the following sections of the tutorial, as the electron-phonon coupling databases are already provided in the .tar.gz file and you don&#039;t need to explicitly recalculate them.&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you run this step, please enter the directory&lt;br /&gt;
&lt;br /&gt;
 cd databases&lt;br /&gt;
&lt;br /&gt;
Here you will find:&lt;br /&gt;
* A scf input file for MoS2, &amp;lt;code&amp;gt;scf/mos2.scf&amp;lt;/code&amp;gt;&lt;br /&gt;
* A dvscf input file for MoS2, &amp;lt;code&amp;gt;dvscf/mos2.dvscf&amp;lt;/code&amp;gt;&lt;br /&gt;
* A Yambo &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory corresponding to a nscf calculation (this has been run already).&lt;br /&gt;
* The pseudopotential files to be used for the calculation.&lt;br /&gt;
&lt;br /&gt;
As a first step, you need to run the Quantum ESPRESSO calculations (it is assumed that you are familiar with this). First run the scf calculation inside &amp;lt;code&amp;gt;scf&amp;lt;/code&amp;gt;, then copy the &amp;lt;code&amp;gt;mos2.save&amp;lt;/code&amp;gt; directory into the &amp;lt;code&amp;gt;dvscf&amp;lt;/code&amp;gt; folder and run the dvscf calculation there. When everything is completed correctly, you will have achieved step 1. above.&lt;br /&gt;
&lt;br /&gt;
Now, you will find the phonon results in the &amp;lt;code&amp;gt;dvscf&amp;lt;/code&amp;gt; directory. We also have done a non-self-consistent calculation to be used in Yambo, and created the relative &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory. If you check this directory, you will find the &amp;lt;code&amp;gt;ns.wf&amp;lt;/code&amp;gt; databases containing the electronic wavefunctions.&lt;br /&gt;
 &lt;br /&gt;
Now, we aim to reconstruct the electron-phonon coupling matrix elements from the phonon energies, modes and potential variations (in &amp;lt;code&amp;gt;dvscf&amp;lt;/code&amp;gt;) and the Bloch electronic wavefunctions used by Yambo (in &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
In order to do this, we will run the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable of the &#039;&#039;&#039;LetzElPhC&#039;&#039;&#039; code (this will be step 2. from above). We will run via command line using yambopy, although it will be instructive to have look at the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; input files later.&lt;br /&gt;
&lt;br /&gt;
We run in the same directory where the Yambo &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; is (remember than you can also virtually move it with a symbolic link).&lt;br /&gt;
&lt;br /&gt;
Type:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y&lt;br /&gt;
&lt;br /&gt;
to see the help for the calculation. Have a look at the various flags and their description.&lt;br /&gt;
For example, if we want to do a serial run of LetzElPhC for bands from &amp;lt;math&amp;gt;n_i&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;n_f&amp;lt;/math&amp;gt;, we should type:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph path/of/ph_input.in -b n_i n_f&lt;br /&gt;
&lt;br /&gt;
Here &amp;lt;math&amp;gt;n_i&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;n_f&amp;lt;/math&amp;gt; are integers representing the initial and final band indices. &#039;&#039;&#039;Please note&#039;&#039;&#039;: in this case, the band index starts from 1 and the the interval of bands read by the code is &amp;lt;math&amp;gt;[n_i,n_f]&amp;lt;/math&amp;gt; including the extrema of the interval. &lt;br /&gt;
&lt;br /&gt;
For our system, we want to do a parallel calculation: 4 MPI tasks on q-point loop (phonon momenta) and 2 MPI tasks on the k-point loop (electron momenta). In addition, we want to explicitly specify the path of the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable. &lt;br /&gt;
&lt;br /&gt;
We have a final choice to make. We can ask Yambopy to produce the default LetzElPhC electron-phonon databases, or to convert them in Yambo-compatible format. By the default, both will be printed. &lt;br /&gt;
&lt;br /&gt;
* If you don&#039;t need the Yambo-style &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases you can run &amp;lt;code&amp;gt;yambopy l2y ...&amp;lt;/code&amp;gt; with the &amp;lt;code&amp;gt;--no_gkkp&amp;lt;/code&amp;gt; option.&lt;br /&gt;
* If you don&#039;t need the default &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; databases you can run &amp;lt;code&amp;gt;yambopy l2y ...&amp;lt;/code&amp;gt; with the &amp;lt;code&amp;gt;--no_lelphc_dbs&amp;lt;/code&amp;gt; option.&lt;br /&gt;
&lt;br /&gt;
However, for this tutorial, we will take a look at both databases, so let&#039;s run:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph dvscf/mos2.dvscf -b 25 28 -par 4 2 -lelphc path/to/lelphc_exe&lt;br /&gt;
&lt;br /&gt;
We include the last two valence bands of monolayer MoS2 (25 and 26) and the first two conduction bands (27 and 28). If your &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable is in the &amp;lt;code&amp;gt;PATH&amp;lt;/code&amp;gt;, you do not need to specify the last flag.&lt;br /&gt;
&lt;br /&gt;
At the end, check your directory: you should find the &amp;lt;code&amp;gt;lelphc.in&amp;lt;/code&amp;gt; input file that was run, let&#039;s inspect it: &lt;br /&gt;
&lt;br /&gt;
 # LetzElPhC input for yambo generated by yambopy&lt;br /&gt;
 nqpool      = 2&lt;br /&gt;
 nkpool      = 4&lt;br /&gt;
 start_bnd   = 25&lt;br /&gt;
 end_bnd     = 28&lt;br /&gt;
 save_dir    = ./SAVE&lt;br /&gt;
 kernel      = dfpt&lt;br /&gt;
 ph_save_dir = dvscf/ph_save&lt;br /&gt;
 convention = yambo&lt;br /&gt;
&lt;br /&gt;
Notice the variable &amp;lt;code&amp;gt;convention=yambo&amp;lt;/code&amp;gt;: what does it mean? At variance with QE and many other codes, Yambo uses the &amp;quot;backward&amp;quot; momentum transfer convention for electronic scatterings. That is, an electronic transition goes from band &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; and momentum &amp;lt;math&amp;gt;k-q&amp;lt;/math&amp;gt; to band &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; and momentum &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;. In the &amp;quot;forward&amp;quot; momentum transfer convention (the more standard one), the transitions go from &amp;lt;math&amp;gt;nk&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;mk+q&amp;lt;/math&amp;gt;. Therefore, this variable ensures that the electron-phonon coupling matrix elements are computed as &amp;lt;math&amp;gt;\langle mk|dV|nk-q\rangle&amp;lt;/math&amp;gt;. However, do not worry: Yambopy can automatically switch between the two conventions when loading the LetzElPhC databases.&lt;br /&gt;
&lt;br /&gt;
You will also find a &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; database that contains the computed electron-phonon matrix elements, in the output format of &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In addition, if you check the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; folder:&lt;br /&gt;
&lt;br /&gt;
 ls SAVE/ndb.elph_gkkp*&lt;br /&gt;
&lt;br /&gt;
you will see that yambopy has created the Yambo-compatible electron-phonon databases and placed them inside the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If you want to run LetzElPhC directly, without using yambopy, you can refer to its [[https://gitlab.com/lumen-code/LetzElPhC/-/blob/main/docs/main.pdf?ref_type=heads|user guide]].&lt;br /&gt;
Keep in mind that in this case, in order to convert the database to the &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases of Yambo, you will then need a couple of lines of python using the Yambopy class &amp;lt;code&amp;gt;ConvertElectronPhononDB&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;yambopy/letzelph_interface/lelph2y.py&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
At the end of this section, you should have produced the same databases that you find in the main &amp;lt;code&amp;gt;electron_phonon&amp;lt;/code&amp;gt; folder. You can run the following part either in the directory where you are (by copying the python scripts here), or by going back:&lt;br /&gt;
&lt;br /&gt;
 $cd ..&lt;br /&gt;
&lt;br /&gt;
and using the precomputed ones.&lt;br /&gt;
&lt;br /&gt;
=== Electron-phonon intro: plots of el-ph matrix elements on k-BZ and q-BZ ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; and read the electron-phonon databases that you generated in the previous section.&lt;br /&gt;
&lt;br /&gt;
In order to read the &amp;lt;code&amp;gt;ndb.elph_gkkp_expanded*&amp;lt;/code&amp;gt; databases in python we use the Yambopy class &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
 elph = YamboElectronPhononDB(ylat,folder_gkkp=&#039;path/to/elph/folder&#039;,save=&#039;path/to/SAVE&#039;)&lt;br /&gt;
(notice that it requires a previous instance of &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Instead, in order to read the &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; databases from LetzElPhC, we use a different class:&lt;br /&gt;
 elph = LetzElphElectronPhononDB(&#039;path/to/ndb.elph&#039;)&lt;br /&gt;
&lt;br /&gt;
Now, the &amp;lt;code&amp;gt;elph&amp;lt;/code&amp;gt; objects contain phonon frequencies, phonon eigenvectors, q-point information and, of course, the electron-phonon matrix elements &amp;lt;math&amp;gt;g_{nm\nu}(k,q)&amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; are electron band states, &amp;lt;math&amp;gt;\nu&amp;lt;/math&amp;gt; is a phonon branch, and &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; are the electronic and transfer momenta.&lt;br /&gt;
&lt;br /&gt;
We can print the docstring of the &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt; class with&lt;br /&gt;
 print(yelph.__doc__)&lt;br /&gt;
and of the &amp;lt;code&amp;gt;LetzElphElectronPhononDB&amp;lt;/code&amp;gt; class with&lt;br /&gt;
 print(lelph.__doc__)&lt;br /&gt;
to get an idea of the information stored and of their capabilities.&lt;br /&gt;
&lt;br /&gt;
Now check the &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; script. Besides choosing which database to load, it also performs two plots:&lt;br /&gt;
 &lt;br /&gt;
* Plot of |g(k)| in the k-BZ for selected bands n,m, phonon mode \nu and q [&amp;lt;code&amp;gt;kspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Plot of |g(q)| in the q-BZ for selected bands n,m, phonon mode \nu and k [&amp;lt;code&amp;gt;qspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
You will see that after loading the database, it first postprocesses the electron-phonon data to obtain a plottable quantity. Indeed, it is not necessarily easy to understand what to plot and what to keep fixed, since the matrix element depends on two momenta and three state indices. In addition, bands or phonon states may be degenerate at certain momenta.&lt;br /&gt;
&lt;br /&gt;
In practice, we set a phonon mode (the eighth mode, this is the branch with symmetry &amp;lt;math&amp;gt;A_1^\prime&amp;lt;/math&amp;gt; at zone center) and either a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; point to keep fixed (in each case, we select the high-symmetry &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; point). As for the bands, we consider the top two valence bands. These are mostly degenerate, except around the points &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;K^\prime&amp;lt;/math&amp;gt; where they are split by spin-orbit interaction. We then average over these states before plotting, obtaining the quantity (in k-space below):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; I^{\mu}_{&amp;lt;v&amp;gt;q}(\mathbf{k}) = \sqrt{\sum_{v,v^\prime=24,25}|g^{\mu}_{vv^\prime q}(\mathbf{k})|^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You are invited to play with the electronic, phononic and momentum indices to see what happens! (beware of degenerate states: if not properly accounted for by the sum of the norms, the plots will be phase-dependent and unphysical)&lt;br /&gt;
&lt;br /&gt;
[[File:MoS2 6x6x1 g vv&#039; in kspace.png|yambopy el-ph plot for tutorial|500px]] [[File:MoS2 6x6x1 g vv&#039; in qspace.png|yambopy el-ph plot for tutorial|500px]]&lt;/div&gt;</summary>
		<author><name>FulvioPaleari</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_electron-phonon_coupling&amp;diff=9336</id>
		<title>Yambopy tutorial: electron-phonon coupling</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_electron-phonon_coupling&amp;diff=9336"/>
		<updated>2026-03-11T13:33:36Z</updated>

		<summary type="html">&lt;p&gt;FulvioPaleari: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial we will cover the handling of electron-phonon coupling matrix elements by Yambopy. The electron-phonon calculation follows two steps:&lt;br /&gt;
&lt;br /&gt;
# Quantum Espresso calculation of phonon energies, eigenmodes and variations of the self-consistent potential via &amp;lt;code&amp;gt;ph.x&amp;lt;/code&amp;gt;.&lt;br /&gt;
# Electron-phonon matrix element calculation, symmetry expansion and conversion by the &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For more information on the &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; code and how you should run step 1., please see the related documentation [https://github.com/yambo-code/LetzElPhC here].&lt;br /&gt;
&lt;br /&gt;
We can use Yambopy to:&lt;br /&gt;
* Run &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; (both preprocessing and main run) without explicitly writing an input file.&lt;br /&gt;
* Convert the resulting databases into &amp;lt;code&amp;gt;Yambo&amp;lt;/code&amp;gt; format.&lt;br /&gt;
* Analyse the electron-phonon coupling both in &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;Yambo&amp;lt;/code&amp;gt; format.&lt;br /&gt;
&lt;br /&gt;
In particular we will take a look at:&lt;br /&gt;
* Lattice geometry data (Yambo database: &amp;lt;code&amp;gt;ns.db1&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
* Electron-phonon matrix elements (Yambo databases: &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt;; LetzElPhC databases: &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;LetzElphElectronPhononDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
The scripts of the tutorial, but not the databases, can be found in the yambopy directory:&lt;br /&gt;
 $cd tutorial/electron_phonon&lt;br /&gt;
&lt;br /&gt;
The full tutorial, including the LetzElPhC and Yambo databases that we will read, can be downloaded and extracted from the yambo website:&lt;br /&gt;
  wget https://media.yambo-code.eu/educational/tutorials/files/yambopy_electron_phonon.tar.gz&lt;br /&gt;
  tar -xvzf yambopy_electron_phonon.tar.gz&lt;br /&gt;
  cd electron_phonon&lt;br /&gt;
&lt;br /&gt;
We will work with monolayer molybdenum disulphide electron-phonon data obtained on a &amp;lt;code&amp;gt;6x6x1&amp;lt;/code&amp;gt; kpoint grid, including spin-orbit interaction (so we deal with electron-phonon coupling and spinorial wavefunctions). Beware that the parameters are most certainly not converged.&lt;br /&gt;
&lt;br /&gt;
=== Command line: electron-phonon calculation and databases [OPTIONAL] ===&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&#039;&#039;&#039;Note&#039;&#039;&#039;: you can run this step only if you have compiled &#039;&#039;&#039;LetzElPhC&#039;&#039;&#039; and &#039;&#039;&#039;Quantum ESPRESSO&#039;&#039;&#039; on your machine. If not, please skip to the following sections of the tutorial, as the electron-phonon coupling databases are already provided in the .tar.gz file and you don&#039;t need to explicitly recalculate them.&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you run this step, please enter the directory&lt;br /&gt;
&lt;br /&gt;
 $cd databases&lt;br /&gt;
&lt;br /&gt;
Here you will find:&lt;br /&gt;
* A scf input file for MoS2, &amp;lt;code&amp;gt;scf/mos2.scf&amp;lt;/code&amp;gt;&lt;br /&gt;
* A dvscf input file for MoS2, &amp;lt;code&amp;gt;dvscf/mos2.dvscf&amp;lt;/code&amp;gt;&lt;br /&gt;
* A Yambo &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory corresponding to a nscf calculation (this has been run already).&lt;br /&gt;
* The pseudopotential files to be used for the calculation.&lt;br /&gt;
&lt;br /&gt;
As a first step, you need to run the Quantum ESPRESSO calculations (it is assumed that you are familiar with this). First run the scf calculation inside &amp;lt;code&amp;gt;scf&amp;lt;/code&amp;gt;, then copy the &amp;lt;code&amp;gt;mos2.save&amp;lt;/code&amp;gt; directory into the &amp;lt;code&amp;gt;dvscf&amp;lt;/code&amp;gt; folder and run the dvscf calculation there. When everything is completed correctly, you will have achieved step 1. above.&lt;br /&gt;
&lt;br /&gt;
Now, you will find the phonon results in the &amp;lt;code&amp;gt;dvscf&amp;lt;/code&amp;gt; directory. We also have done a non-self-consistent calculation to be used in Yambo, and created the relative &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory. If you check this directory, you will find the &amp;lt;code&amp;gt;ns.wf&amp;lt;/code&amp;gt; databases containing the electronic wavefunctions.&lt;br /&gt;
 &lt;br /&gt;
Now, we aim to reconstruct the electron-phonon coupling matrix elements from the phonon energies, modes and potential variations (in &amp;lt;code&amp;gt;dvscf&amp;lt;/code&amp;gt;) and the Bloch electronic wavefunctions used by Yambo (in &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
In order to do this, we will run the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable of the &#039;&#039;&#039;LetzElPhC&#039;&#039;&#039; code (this will be step 2. from above). We will run via command line using yambopy, although it will be instructive to have look at the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; input files later.&lt;br /&gt;
&lt;br /&gt;
We run in the same directory where the Yambo &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; is (remember than you can also virtually move it with a symbolic link).&lt;br /&gt;
&lt;br /&gt;
Type:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y&lt;br /&gt;
&lt;br /&gt;
to see the help for the calculation. Have a look at the various flags and their description.&lt;br /&gt;
For example, if we want to do a serial run of LetzElPhC for bands from &amp;lt;math&amp;gt;n_i&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;n_f&amp;lt;/math&amp;gt;, we should type:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph path/of/ph_input.in -b n_i n_f&lt;br /&gt;
&lt;br /&gt;
Here &amp;lt;math&amp;gt;n_i&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;n_f&amp;lt;/math&amp;gt; are integers representing the initial and final band indices. &#039;&#039;&#039;Please note&#039;&#039;&#039;: in this case, the band index starts from 1 and the the interval of bands read by the code is &amp;lt;math&amp;gt;[n_i,n_f]&amp;lt;/math&amp;gt; including the extrema of the interval. &lt;br /&gt;
&lt;br /&gt;
For our system, we want to do a parallel calculation: 4 MPI tasks on q-point loop (phonon momenta) and 2 MPI tasks on the k-point loop (electron momenta). In addition, we want to explicitly specify the path of the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable. &lt;br /&gt;
&lt;br /&gt;
We have a final choice to make. We can ask Yambopy to produce the default LetzElPhC electron-phonon databases, or to convert them in Yambo-compatible format. By the default, both will be printed. &lt;br /&gt;
&lt;br /&gt;
* If you don&#039;t need the Yambo-style &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases you can run &amp;lt;code&amp;gt;yambopy l2y ...&amp;lt;/code&amp;gt; with the &amp;lt;code&amp;gt;--no_gkkp&amp;lt;/code&amp;gt; option.&lt;br /&gt;
* If you don&#039;t need the default &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; databases you can run &amp;lt;code&amp;gt;yambopy l2y ...&amp;lt;/code&amp;gt; with the &amp;lt;code&amp;gt;--no_lelphc_dbs&amp;lt;/code&amp;gt; option.&lt;br /&gt;
&lt;br /&gt;
However, for this tutorial, we will take a look at both databases, so let&#039;s run:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph dvscf/mos2.dvscf -b 25 28 -par 4 2 -lelphc path/to/lelphc_exe&lt;br /&gt;
&lt;br /&gt;
We include the last two valence bands of monolayer MoS2 (25 and 26) and the first two conduction bands (27 and 28). If your &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable is in the &amp;lt;code&amp;gt;PATH&amp;lt;/code&amp;gt;, you do not need to specify the last flag.&lt;br /&gt;
&lt;br /&gt;
At the end, check your directory: you should find the &amp;lt;code&amp;gt;lelphc.in&amp;lt;/code&amp;gt; input file that was run, let&#039;s inspect it: &lt;br /&gt;
&lt;br /&gt;
 # LetzElPhC input for yambo generated by yambopy&lt;br /&gt;
 nqpool      = 2&lt;br /&gt;
 nkpool      = 4&lt;br /&gt;
 start_bnd   = 25&lt;br /&gt;
 end_bnd     = 28&lt;br /&gt;
 save_dir    = ./SAVE&lt;br /&gt;
 kernel      = dfpt&lt;br /&gt;
 ph_save_dir = dvscf/ph_save&lt;br /&gt;
 convention = yambo&lt;br /&gt;
&lt;br /&gt;
Notice the variable &amp;lt;code&amp;gt;convention=yambo&amp;lt;/code&amp;gt;: what does it mean? At variance with QE and many other codes, Yambo uses the &amp;quot;backward&amp;quot; momentum transfer convention for electronic scatterings. That is, an electronic transition goes from band &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; and momentum &amp;lt;math&amp;gt;k-q&amp;lt;/math&amp;gt; to band &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; and momentum &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;. In the &amp;quot;forward&amp;quot; momentum transfer convention (the more standard one), the transitions go from &amp;lt;math&amp;gt;nk&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;mk+q&amp;lt;/math&amp;gt;. Therefore, this variable ensures that the electron-phonon coupling matrix elements are computed as &amp;lt;math&amp;gt;\langle mk|dV|nk-q\rangle&amp;lt;/math&amp;gt;. However, do not worry: Yambopy can automatically switch between the two conventions when loading the LetzElPhC databases.&lt;br /&gt;
&lt;br /&gt;
You will also find a &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; database that contains the computed electron-phonon matrix elements, in the output format of &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In addition, if you check the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; folder:&lt;br /&gt;
&lt;br /&gt;
 ls SAVE/ndb.elph_gkkp*&lt;br /&gt;
&lt;br /&gt;
you will see that yambopy has created the Yambo-compatible electron-phonon databases and placed them inside the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If you want to run LetzElPhC directly, without using yambopy, you can refer to its [[https://gitlab.com/lumen-code/LetzElPhC/-/blob/main/docs/main.pdf?ref_type=heads|user guide]].&lt;br /&gt;
Keep in mind that in this case, in order to convert the database to the &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases of Yambo, you will then need a couple of lines of python using the Yambopy class &amp;lt;code&amp;gt;ConvertElectronPhononDB&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;yambopy/letzelph_interface/lelph2y.py&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
At the end of this section, you should have produced the same databases that you find in the main &amp;lt;code&amp;gt;electron_phonon&amp;lt;/code&amp;gt; folder. You can run the following part either in the directory where you are (by copying the python scripts here), or by going back:&lt;br /&gt;
&lt;br /&gt;
 $cd ..&lt;br /&gt;
&lt;br /&gt;
and using the precomputed ones.&lt;br /&gt;
&lt;br /&gt;
=== Electron-phonon intro: plots of el-ph matrix elements on k-BZ and q-BZ ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; and read the electron-phonon databases that you generated in the previous section.&lt;br /&gt;
&lt;br /&gt;
In order to read the &amp;lt;code&amp;gt;ndb.elph_gkkp_expanded*&amp;lt;/code&amp;gt; databases in python we use the Yambopy class &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
 elph = YamboElectronPhononDB(ylat,folder_gkkp=&#039;path/to/elph/folder&#039;,save=&#039;path/to/SAVE&#039;)&lt;br /&gt;
(notice that it requires a previous instance of &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Instead, in order to read the &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; databases from LetzElPhC, we use a different class:&lt;br /&gt;
 elph = LetzElphElectronPhononDB(&#039;path/to/ndb.elph&#039;)&lt;br /&gt;
&lt;br /&gt;
Now, the &amp;lt;code&amp;gt;elph&amp;lt;/code&amp;gt; objects contain phonon frequencies, phonon eigenvectors, q-point information and, of course, the electron-phonon matrix elements &amp;lt;math&amp;gt;g_{nm\nu}(k,q)&amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; are electron band states, &amp;lt;math&amp;gt;\nu&amp;lt;/math&amp;gt; is a phonon branch, and &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; are the electronic and transfer momenta.&lt;br /&gt;
&lt;br /&gt;
We can print the docstring of the &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt; class with&lt;br /&gt;
 print(yelph.__doc__)&lt;br /&gt;
and of the &amp;lt;code&amp;gt;LetzElphElectronPhononDB&amp;lt;/code&amp;gt; class with&lt;br /&gt;
 print(lelph.__doc__)&lt;br /&gt;
to get an idea of the information stored and of their capabilities.&lt;br /&gt;
&lt;br /&gt;
Now check the &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; script. Besides choosing which database to load, it also performs two plots:&lt;br /&gt;
 &lt;br /&gt;
* Plot of |g(k)| in the k-BZ for selected bands n,m, phonon mode \nu and q [&amp;lt;code&amp;gt;kspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Plot of |g(q)| in the q-BZ for selected bands n,m, phonon mode \nu and k [&amp;lt;code&amp;gt;qspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
You will see that after loading the database, it first postprocesses the electron-phonon data to obtain a plottable quantity. Indeed, it is not necessarily easy to understand what to plot and what to keep fixed, since the matrix element depends on two momenta and three state indices. In addition, bands or phonon states may be degenerate at certain momenta.&lt;br /&gt;
&lt;br /&gt;
In practice, we set a phonon mode (the eighth mode, this is the branch with symmetry &amp;lt;math&amp;gt;A_1^\prime&amp;lt;/math&amp;gt; at zone center) and either a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; point to keep fixed (in each case, we select the high-symmetry &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; point). As for the bands, we consider the top two valence bands. These are mostly degenerate, except around the points &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;K^\prime&amp;lt;/math&amp;gt; where they are split by spin-orbit interaction. We then average over these states before plotting, obtaining the quantity (in k-space below):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; I^{\mu}_{&amp;lt;v&amp;gt;q}(\mathbf{k}) = \sqrt{\sum_{v,v^\prime=24,25}|g^{\mu}_{vv^\prime q}(\mathbf{k})|^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You are invited to play with the electronic, phononic and momentum indices to see what happens! (beware of degenerate states: if not properly accounted for by the sum of the norms, the plots will be phase-dependent and unphysical)&lt;br /&gt;
&lt;br /&gt;
[[File:MoS2 6x6x1 g vv&#039; in kspace.png|yambopy el-ph plot for tutorial|500px]] [[File:MoS2 6x6x1 g vv&#039; in qspace.png|yambopy el-ph plot for tutorial|500px]]&lt;/div&gt;</summary>
		<author><name>FulvioPaleari</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=First_steps_in_Yambopy&amp;diff=9335</id>
		<title>First steps in Yambopy</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=First_steps_in_Yambopy&amp;diff=9335"/>
		<updated>2026-03-11T13:32:46Z</updated>

		<summary type="html">&lt;p&gt;FulvioPaleari: /* Tutorials */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The yambopy project aims to develop python tools to: &lt;br /&gt;
&lt;br /&gt;
* Read and edit yambo and quantum espresso input files&lt;br /&gt;
* Easily perform pre- and post-processing of the simulation data for these two codes - including hard-to-get, database-encoded data beyond standard outputs&lt;br /&gt;
* Provide easy visualization and plotting options &lt;br /&gt;
* Set up simple automatization workflows (e.g., convergence tests)&lt;br /&gt;
&lt;br /&gt;
=== Setup ===&lt;br /&gt;
First of all, make sure that you have a suitable python environment (crated for example with [https://docs.anaconda.com/miniconda/install/ conda] or [https://docs.python.org/3/library/venv.html venv]) with &#039;&#039;&#039;python &amp;gt;=3.8&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
If you are not used with python environments, here two simple commands that you can use&lt;br /&gt;
 python -m venv MYPATH/yamboenv/&lt;br /&gt;
(you can replace `MYPATH` with any path you prefer, e.g. `~/`)&lt;br /&gt;
 source MYPATH/yamboenv/bin/activate&lt;br /&gt;
(for bash users, you can add to your .bashrt the line `. MYPATH/yamboenv/bin/activate`)&lt;br /&gt;
&lt;br /&gt;
Then, you may install yambopy in one of the following ways.&lt;br /&gt;
&lt;br /&gt;
==== Quick installation from PyPI repository ====&lt;br /&gt;
&lt;br /&gt;
* In order to quickly install the officially released version type:&lt;br /&gt;
&lt;br /&gt;
 pip install yambopy&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Installation from tarball ====&lt;br /&gt;
&lt;br /&gt;
* In case you don&#039;t want to download from the pip repository and prefer to install a version of yambopy locally, you may download the appropriate tarball from the [https://github.com/yambo-code/yambopy/releases| yambopy github page]. Extract the tarball, enter the yambopy folder and type &amp;lt;code&amp;gt;pip install .&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Installation of latest patch ====&lt;br /&gt;
&lt;br /&gt;
* In case you want the latest version of the code including new updates and patches that might not be present in the official version, then you can clone the yambopy git repository (a basic knowledge of git may be helpful):&lt;br /&gt;
&lt;br /&gt;
 git clone https://github.com/yambo-code/yambopy.git&lt;br /&gt;
 cd yambopy&lt;br /&gt;
 pip install .&lt;br /&gt;
&lt;br /&gt;
==== Installation for developers ====&lt;br /&gt;
* If you want to install YamboPy in developing mode (to modify or add new functions) you have to download the code from github repository then go in the YamboPy folder and install with the command:&lt;br /&gt;
&lt;br /&gt;
 pip install -e .&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important:&#039;&#039;&#039; if you want your changes to be included into a new patch/version of Yambopy, you need to first create your own personal fork of the git repository, make the changes there, and then create a pull request for the original repository. &lt;br /&gt;
&lt;br /&gt;
==== Dependencies ====&lt;br /&gt;
&lt;br /&gt;
* In principle, &amp;lt;code&amp;gt;pip&amp;lt;/code&amp;gt; should take care of the required python dependencies. They are &amp;lt;code&amp;gt;numpy&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;scipy&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;matplotlib&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;netCDF4&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;h5py&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;lxml&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;PyYAML&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;monty&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;scikit-learn&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;tqdm&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;spglib&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;spgrep&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;pykdtree&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;numba&amp;lt;/code&amp;gt;. In case some dependency-related problem arises, you can install each of them separately beforehand with:&lt;br /&gt;
&lt;br /&gt;
 pip install &amp;lt;code&amp;gt;dependency-name&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* If you experience errors related to &amp;lt;code&amp;gt;NetCDF4&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;hdf5&amp;lt;/code&amp;gt;, these are usually due to incompatibilities between the python modules the library in your environment. In this case, you can force the python installation to match the system library. For example, if you have an &amp;lt;code&amp;gt;hdf5&amp;lt;/code&amp;gt; problem and you are using conda, you could try:&lt;br /&gt;
&lt;br /&gt;
 conda install --force-reinstall h5py hdf5&lt;br /&gt;
&lt;br /&gt;
=== Tutorials ===&lt;br /&gt;
Now yambopy is ready to use! Just go to the tutorials folder and follow the docs!&lt;br /&gt;
&lt;br /&gt;
 cd tutorial/&lt;br /&gt;
&lt;br /&gt;
On this wiki, we provide steps for the following tutorials:&lt;br /&gt;
&lt;br /&gt;
1. Data postprocessing:&lt;br /&gt;
* [[Yambopy tutorial: band structures | Database and plotting tutorial for quantum espresso (qepy) and GW &#039;&#039;&#039;band structures&#039;&#039;&#039;]] (Get the databases: [https://media.yambo-code.eu/educational/tutorials/files/databases_qepy.tar.gz databases_qepy], 46.5MB)&lt;br /&gt;
* [[Yambopy tutorial: Yambo databases | Database and plotting tutorial for yambo (yambopy) and &#039;&#039;&#039;exciton&#039;&#039;&#039; analysis ]] (Get the databases: [https://media.yambo-code.eu/educational/tutorials/files/databases_yambopy.tar.gz databases_yambopy], 99MB)&lt;br /&gt;
2. Manage QE and Yambo runs: [WARNING: these tutorials are currently under maintenance due to updates to the scheduler class]&lt;br /&gt;
* [[GW tutorial. Convergence and approximations (BN)]]&lt;br /&gt;
* [[Bethe-Salpeter equation tutorial. Optical absorption (BN)]]&lt;br /&gt;
3. Advanced topics:&lt;br /&gt;
* [[Yambopy tutorial: electron-phonon coupling|Databases and plotting tutorial for electron-phonon coupling with yambopy]] (Get the databases: [https://media.yambo-code.eu/educational/tutorials/files/yambopy_electron_phonon.tar.gz electron_phonon], 490M)&lt;br /&gt;
* [[Exciton-phonon coupling and luminescence]]&lt;br /&gt;
* [[Phonon-assisted luminescence by finite atomic displacements]]&lt;br /&gt;
&lt;br /&gt;
=== How to cite ===&lt;br /&gt;
If yambopy helped you with your data analysis, workflow management of figure preparation, you can consider citing us.&lt;br /&gt;
&lt;br /&gt;
The way to do so in BibTeX format is the following:&lt;br /&gt;
 @misc{yambopy, &lt;br /&gt;
      author = {Paleari, Fulvio and Molina-Sánchez, Alejandro and Nalabothula, Muralidhar and Reho, Riccardo and Bonacci, Miki and Castelo, José M. and Cervantes-Villanueva, Jorge and Pionteck, Mike and Silvetti, Martino and Attaccalite, Claudio and Pereira Coutada Miranda, Henrique},&lt;br /&gt;
      title = {Yambopy},&lt;br /&gt;
      month = mar,&lt;br /&gt;
      year = 2025,&lt;br /&gt;
      publisher = {Zenodo},&lt;br /&gt;
      version = {0.4.0}, &lt;br /&gt;
      doi = {10.5281/zenodo.15012962},&lt;br /&gt;
      url = {[[https://doi.org/10.5281/zenodo.15012962 https://doi.org/10.5281/zenodo.15012962]]}, }&lt;/div&gt;</summary>
		<author><name>FulvioPaleari</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_band_structures&amp;diff=9334</id>
		<title>Yambopy tutorial: band structures</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_band_structures&amp;diff=9334"/>
		<updated>2026-03-11T12:14:18Z</updated>

		<summary type="html">&lt;p&gt;FulvioPaleari: /* Tutorial 2. Iron. Ferromagnetic metallic material */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
This tutorial will show you how to visualise wave-function and band-structure related information, such as atomic, orbital and spin projections, following a DFT Quantum Espresso calculation using the &amp;quot;qepy&amp;quot; module of Yambopy. It also contains a section about Yambo and GW band structures.&lt;br /&gt;
&lt;br /&gt;
The full tutorial, including the Quantum espresso and Yambo databases that we will read, can be downloaded and extracted from the yambo website:&lt;br /&gt;
 wget https://media.yambo-code.eu/educational/tutorials/files/databases_qepy.tar.gz&lt;br /&gt;
 tar -xvzf databases_qepy.tar.gz&lt;br /&gt;
 cd databases_qepy&lt;br /&gt;
&lt;br /&gt;
==Tutorial 1. BN (semiconductor). Band structure==&lt;br /&gt;
&lt;br /&gt;
First enter in the folder &lt;br /&gt;
 cd databases_qepy/bn-semiconductor&lt;br /&gt;
and have a look to the &lt;br /&gt;
 vim plot-qe-bands.py&lt;br /&gt;
The qepy classes are useful both to execute Quantum Espresso and to analyze the results. Enter in the python environment, by typing &amp;lt;code&amp;gt;python&amp;lt;/code&amp;gt;, then the full qepy library is imported by simply doing:&lt;br /&gt;
&lt;br /&gt;
 from qepy import *&lt;br /&gt;
&lt;br /&gt;
However, for this plot we just need two classes, namely:&lt;br /&gt;
&lt;br /&gt;
 from qepy import Path,PwXML&lt;br /&gt;
&lt;br /&gt;
===Plot Band structure===&lt;br /&gt;
&lt;br /&gt;
The qepy class &#039;&#039;&#039;PwXML&#039;&#039;&#039; reads the data file generated by Quantum Espresso and post-processes the data. The class is instanced by doing:&lt;br /&gt;
&lt;br /&gt;
 xml = PwXML(prefix=&#039;bn&#039;, path=&#039;bands&#039;)&lt;br /&gt;
&lt;br /&gt;
The variable prefix corresponds to the same variable of the QE input. The folder location is indicated by variable path. In order to plot the bands, we also define the k-points path (in crystal coordinates) using the function Path:&lt;br /&gt;
&lt;br /&gt;
 npoints = 50&lt;br /&gt;
 path_kpoints = Path([ [[0.0, 0.0, 0.0],&#039;$\Gamma$&#039;],&lt;br /&gt;
                       [[0.5, 0.0, 0.0],&#039;M&#039;],&lt;br /&gt;
                       [[1./3,1./3,0.0],&#039;K&#039;],&lt;br /&gt;
                       [[0.0, 0.0, 0.0],&#039;$\Gamma$&#039;]], [int(npoints*2),int(npoints),int(sqrt(5)*npoints)])&lt;br /&gt;
&lt;br /&gt;
It is worth to note that the path should coincide with the selected path for the QE band calculations.&lt;br /&gt;
&lt;br /&gt;
In order to show the plot we call the &#039;&#039;&#039;plot_eigen&#039;&#039;&#039; method of the &#039;&#039;&#039;PwXML&#039;&#039;&#039; class:&lt;br /&gt;
&lt;br /&gt;
 xml.plot_eigen(path_kpoints)&lt;br /&gt;
&lt;br /&gt;
This function will automatically plot the bands as shown below running the script:&lt;br /&gt;
&lt;br /&gt;
 python plot-qe-bands.py&lt;br /&gt;
&lt;br /&gt;
[[File:Bands BN 1.png| 400 px | center |Band structure of BN calculated at the level of DFT-LDA]]&lt;br /&gt;
&lt;br /&gt;
Alternatively, we can use the function &#039;&#039;&#039;plot_eigen_ax&#039;&#039;&#039;. This functions requires as input a matplotlib &#039;&#039;&#039;figure&#039;&#039;&#039; object with given axes, as you will see in the next example.&lt;br /&gt;
&lt;br /&gt;
===Plot atomic orbital projected Band structure===&lt;br /&gt;
&lt;br /&gt;
In addition to the band structure, useful information regarding the atomic orbital nature of the electronic wave functions can be displayed using the class &#039;&#039;&#039;ProjwfcXML&#039;&#039;&#039;. &lt;br /&gt;
In order to make quantum espresso calculate the relevant data, we need to use the QE executable &#039;&#039;&#039;projwfc.x&#039;&#039;&#039;, which will create the file &#039;&#039;&#039;atomic_proj.xml&#039;&#039;&#039;. This executable projects the Kohn-Sham wavefunctions onto orthogonalized atomic orbitals, among others functionalities. The orbital indexing  and ordering are explained in the input documentation of the projwfc.x function which you are invited to check (https://www.quantum-espresso.org/Doc/INPUT_PROJWFC.html#idm94). We can run &#039;&#039;&#039;projwf.x&#039;&#039;&#039; directly from the python script using the qepy class &#039;&#039;&#039;ProjwfcIn&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
 proj = ProjwfcIn(prefix=&#039;bn&#039;)&lt;br /&gt;
 proj.run(folder=&#039;bands&#039;)&lt;br /&gt;
&lt;br /&gt;
Be aware that this can take a while in a large system with many k-points. As in the class &#039;&#039;&#039;PwXML&#039;&#039;&#039;, we then define the path_kpoints and also the selected atomic orbitals to project our bands. We have chosen to represent the projection weight onto the nitrogen (1) and boron (2) orbitals, which can be obtained with&lt;br /&gt;
&lt;br /&gt;
 # Automatic selection of the states&lt;br /&gt;
 atom_1 = band.get_states_helper(atom_query=[&#039;N&#039;])&lt;br /&gt;
 atom_2 = band.get_states_helper(atom_query=[&#039;B&#039;])&lt;br /&gt;
&lt;br /&gt;
The full list of orbitals is written in the file &#039;&#039;&#039;bands/prowfc.log&#039;&#039;&#039;. By inspecting it, you may also construct custom lists of states.&lt;br /&gt;
&lt;br /&gt;
We have also defined the figure box&lt;br /&gt;
&lt;br /&gt;
 import matplotlib.pyplot as plt&lt;br /&gt;
 fig = plt.figure(figsize=(5,7))&lt;br /&gt;
 ax  = fig.add_axes( [ 0.12, 0.10, 0.70, 0.80 ])&lt;br /&gt;
&lt;br /&gt;
The class &#039;&#039;&#039;ProjwfcXML&#039;&#039;&#039; then runs as in this example:&lt;br /&gt;
&lt;br /&gt;
 band = ProjwfcXML(prefix=&#039;bn&#039;,path=&#039;bands&#039;,qe_version=&#039;7.0&#039;)&lt;br /&gt;
 band.plot_eigen(ax,path_kpoints=path_kpoints,cmap=&#039;viridis&#039;,selected_orbitals=atom_1,selected_orbitals_2=atom_2)&lt;br /&gt;
&lt;br /&gt;
We can run now the file:&lt;br /&gt;
&lt;br /&gt;
 python plot-qe-orbitals.py&lt;br /&gt;
&lt;br /&gt;
[[File:Bands AOP BN 1.png| 400 px | center | Atomic orbital projected band structure of monolayer BN]]&lt;br /&gt;
&lt;br /&gt;
We have chosen the colormap &#039;viridis&#039; (variable cmap). You see that the colormap goes from maximum &#039;&#039;&#039;selected_orbitals&#039;&#039;&#039; content (in this case nitrogen) to the maximum &#039;&#039;&#039;selected_orbitals_2&#039;&#039;&#039; content (in this case boron). &lt;br /&gt;
The colormap can be represented in many ways and qepy does not include a particular function for this. An example is:&lt;br /&gt;
&lt;br /&gt;
 import matplotlib as mpl&lt;br /&gt;
 cmap=plt.get_cmap(&#039;viridis&#039;)&lt;br /&gt;
 bx  = fig.add_axes( [ 0.88, 0.10, 0.05, 0.80 ])&lt;br /&gt;
 norm = mpl.colors.Normalize(vmin=0.,vmax=1.)&lt;br /&gt;
 cb1 = mpl.colorbar.ColorbarBase(bx, cmap=cmap, norm=norm,orientation=&#039;vertical&#039;,ticks=[0,1])&lt;br /&gt;
 cb1.set_ticklabels([&#039;B&#039;, &#039;N&#039;])&lt;br /&gt;
&lt;br /&gt;
Suppose now that we have run the G0W0 calculation from the last tutorial, and we want to represent the atomic weights on top of the quasiparticle band structure instead of the Kohn-Sham one. However, we do not have the same kpoint grid between the G0W0 calculation and the quantum espresso &amp;quot;band&amp;quot; calculation along a path. We can then extract the parameters for a scissor operator (this is done below) and feed them to the &#039;&#039;&#039;ProjwfcXML&#039;&#039;&#039; class together with the number of valence bands. Try uncommenting the following lines in the tutorial script:&lt;br /&gt;
&lt;br /&gt;
 # Add scissor operator to the bands from a G0W0 calculation&lt;br /&gt;
 scissor= [1.8985195950522469, 1.0265240811345133, 1.051588659878575]&lt;br /&gt;
 n_val = 4&lt;br /&gt;
 band.add_scissor(n_val,scissor)&lt;br /&gt;
  &lt;br /&gt;
Finally, we can also plot the band orbital character with size variation instead of a color scale. In this case we have to pass only the variable selected_orbitals (see the next tutorial).&lt;br /&gt;
&lt;br /&gt;
==Tutorial 2. Iron. Ferromagnetic metallic material==&lt;br /&gt;
&lt;br /&gt;
In the case of spin-polarized calculations we can plot the spin up and down band structures. &lt;br /&gt;
&lt;br /&gt;
After running a band structure calculation for iron (the results are in the &amp;lt;code&amp;gt;bands&amp;lt;/code&amp;gt; folder), we can load the data from the QE xml output files and make the band plot by running the script:&lt;br /&gt;
&lt;br /&gt;
 python plot-qe-bands.py&lt;br /&gt;
&lt;br /&gt;
The class &amp;lt;code&amp;gt;PwXML&amp;lt;/code&amp;gt; automatically detects the spin polarized case (nspin=2 in the QE input file). The spin up channel is displayed with red and the spin down channel with blue. In the case of iron we have selected this k-point path:&lt;br /&gt;
&lt;br /&gt;
 npoints = 50&lt;br /&gt;
 path_kpoints = Path([ [[0.0, 0.0, 0.0 ],&#039;G&#039;],&lt;br /&gt;
                       [[0.0, 0.0, 1.0 ],&#039;H&#039;],&lt;br /&gt;
                       [[1./2,0.0,1./2.],&#039;N&#039;],&lt;br /&gt;
                       [[0.0, 0.0, 0.0 ],&#039;G&#039;],&lt;br /&gt;
                       [[1./2, 1./2, 1./2 ],&#039;P&#039;],&lt;br /&gt;
                       [[1./2,0.0,1./2. ],&#039;N&#039;]], [npoints,npoints,npoints,npoints,npoints])&lt;br /&gt;
&lt;br /&gt;
 xml = PwXML(prefix=&#039;pw&#039;,path=&#039;bands/t0&#039;)&lt;br /&gt;
 xml.plot_eigen(path_kpoints)&lt;br /&gt;
&lt;br /&gt;
[[File:Figure 3-iron-bands.png| 600 px | center |Spin polarized band structure of iron calculated by DFT]]&lt;br /&gt;
&lt;br /&gt;
The analysis of the projected atomic orbitals is also implemented. In this case the results are more cumbersome because the projection is separated in spin up and down channels.&amp;lt;br&amp;gt; &lt;br /&gt;
Let us look first at the file &#039;&#039;&#039;plot-qe-orbitals-size&#039;&#039;&#039;. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NB: If you generated your own qe band structure instead of relying on the precomputed databases, you can run the quantum espresso executable projwfc.x to compute the orbital projections using yambopy. In this case, please uncomment the following lines in the script&#039;&#039;&#039; (plot-qe-orbitals-size.py) :&lt;br /&gt;
 #proj = ProjwfcIn(prefix=&#039;pw&#039;)&lt;br /&gt;
 #proj.run(folder=&#039;bands&#039;)&lt;br /&gt;
&lt;br /&gt;
Now, we can use the dot size as a function of the weight of the orbitals&lt;br /&gt;
 # Automatic selection of the states&lt;br /&gt;
 s = band.get_states_helper(orbital_query=[&#039;s&#039;])&lt;br /&gt;
 p = band.get_states_helper(orbital_query=[&#039;p&#039;])&lt;br /&gt;
 d = band.get_states_helper(orbital_query=[&#039;d&#039;])&lt;br /&gt;
&lt;br /&gt;
and the plots are done with&lt;br /&gt;
 band = ProjwfcXML(prefix=&#039;pw&#039;,path=&#039;bands&#039;,qe_version=&#039;7.0&#039;)&lt;br /&gt;
 band.plot_eigen(ax,path_kpoints=path_kpoints,&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;selected_orbitals=s,&amp;lt;/span&amp;gt;color=&#039;pink&#039;,color_2=&#039;black&#039;)&lt;br /&gt;
 band.plot_eigen(ax,path_kpoints=path_kpoints,&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;selected_orbitals=p,&amp;lt;/span&amp;gt;color=&#039;green&#039;,color_2=&#039;orange&#039;)&lt;br /&gt;
 band.plot_eigen(ax,path_kpoints=path_kpoints,&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;selected_orbitals=d,&amp;lt;/span&amp;gt;color=&#039;red&#039;,color_2=&#039;blue&#039;)&lt;br /&gt;
&lt;br /&gt;
As an example, we can select just the &#039;&#039;d&#039;&#039; orbitals by commenting the first two plots and then running the file:&lt;br /&gt;
&lt;br /&gt;
 plot-qe-orbitals-size.py&lt;br /&gt;
&lt;br /&gt;
[[File:Figure 4-iron-bands-size-d-orbitals.png|400px|center|Iron band structure. Size is proportional to the weights of the projection on atomic d-orbitals. Red (blue) is up (down) spin polarization.]]&lt;br /&gt;
&lt;br /&gt;
From the plot is clear that &#039;&#039;d&#039;&#039; orbitals are mainly localized around the Fermi energy. The plot above is in red and blue, while the default choice in your script should be pink and black. You can experiment with the colors and other &#039;&#039;matplotlib&#039;&#039; plot options and also plot the other orbital types.&lt;br /&gt;
&lt;br /&gt;
Another option is to plot the orbital composition as a colormap running the file:&lt;br /&gt;
&lt;br /&gt;
 plot-qe-orbitals-colormap.py&lt;br /&gt;
&lt;br /&gt;
[[File:Figure 5-iron-bands-colormap.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
Here we have added the p and d orbitals in the analysis:&lt;br /&gt;
&lt;br /&gt;
 p = band.get_states_helper(orbital_query=[&#039;p&#039;])&lt;br /&gt;
 d = band.get_states_helper(orbital_query=[&#039;d&#039;])&lt;br /&gt;
 band = ProjwfcXML(prefix=&#039;pw&#039;,path=&#039;bands&#039;,qe_version=&#039;7.0&#039;)&lt;br /&gt;
 band.plot_eigen(ax,path_kpoints=path_kpoints,cmap=&#039;viridis&#039;,cmap2=&#039;rainbow&#039;,selected_orbitals=p,selected_orbitals_2=d)&lt;br /&gt;
&lt;br /&gt;
The colormap bar is added in the same way as in Tutorial 1 (see script), but this time we have a different colormap for each spin polarisation.&lt;br /&gt;
&lt;br /&gt;
==Tutorial 3: GW bands==&lt;br /&gt;
&lt;br /&gt;
Yambopy can be used either to run Yambo and QE calculations, or to analyse the results of QE and Yambo by dealing with their generated databases. This is done with a variety of classes included in the qepy (for QE) or yambopy (for Yambo) modules. &lt;br /&gt;
In the case of Yambo GW quasi-particle calculations, we can use the yambopy class &#039;&#039;&#039;YamboQPDB&#039;&#039;&#039; to read the database produced by the simulation.&lt;br /&gt;
Enter in the folder&lt;br /&gt;
 cd ../gw-bands&lt;br /&gt;
We can use this to find the scissor operator, plot the GW bands and to interpolate the GW bands on a smoother k-path. The example runs by typing:&lt;br /&gt;
&lt;br /&gt;
 python plot-qp.py&lt;br /&gt;
&lt;br /&gt;
See below for an explanation of the tutorial. As usual, we can import the qepy and yambopy libraries (in addition to the standard modules we will need):&lt;br /&gt;
&lt;br /&gt;
  from yambopy import YamboLatticeDB,YamboQPDB # Load yambo netcdf databases&lt;br /&gt;
  from qepy import Path                        # Define path in k-space&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
  from math import sqrt&lt;br /&gt;
&lt;br /&gt;
We define the k-points path.&lt;br /&gt;
  npoints = 10&lt;br /&gt;
  path = Path([ [[  0.0,  0.0,  0.0],&#039;$\Gamma$&#039;],&lt;br /&gt;
                [[  0.5,  0.0,  0.0],&#039;M&#039;],&lt;br /&gt;
                [[1./3.,1./3.,  0.0],&#039;K&#039;],&lt;br /&gt;
                [[  0.0,  0.0,  0.0],&#039;$\Gamma$&#039;]], [int(npoints*2),int(npoints),int(sqrt(5)*npoints)] )&lt;br /&gt;
&lt;br /&gt;
Importantly, the number of points is a free choice. We can increase the variable npoints as we wish, it just means that the interpolation step will take more time. In order to analyse GW results we need to have the file related to the basic data of our Yambo calculation (&#039;&#039;&#039;SAVE/ns.db1&#039;&#039;&#039;) and the netcdf file with the quasi-particle results (&#039;&#039;&#039;ndb.QP&#039;&#039;&#039;). We load the data calling the respective classes:&lt;br /&gt;
&lt;br /&gt;
 # Read Lattice information from SAVE&lt;br /&gt;
 ## Note: we do not expand the kpts because QP database is in the IBZ&lt;br /&gt;
 lat  = YamboLatticeDB.from_db_file(filename=&#039;SAVE/ns.db1&#039;,Expand=False)&lt;br /&gt;
 # Read QP database&lt;br /&gt;
 ydb  = YamboQPDB.from_db(filename=&#039;ndb.QP&#039;,folder=&#039;qp-gw&#039;)&lt;br /&gt;
&lt;br /&gt;
The first option is to plot the energies and calculate the ideal Kohn-Sham to GW scissor operator. We need to select the index of the top valence band:&lt;br /&gt;
&lt;br /&gt;
 n_top_vb = 4&lt;br /&gt;
 ydb.plot_scissor_ax(ax,n_top_vb)&lt;br /&gt;
&lt;br /&gt;
Yambopy displays the fitting and also the data of the slope of each fitting. Notice that this is also a test if the GW calculations are running well. &#039;&#039;&#039;If the dependence is not linear you should double-check your results!&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[[File:Figure 6-slope-scissor.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
In this case the slope is:&lt;br /&gt;
&lt;br /&gt;
 valence bands:&lt;br /&gt;
 slope:     1.0515886598785766&lt;br /&gt;
 conduction bands:&lt;br /&gt;
 slope:     1.026524081134514&lt;br /&gt;
 scissor list (shift,c,v) [eV,adim,adim]: [1.8985204833551723, 1.026524081134514, 1.0515886598785766]&lt;br /&gt;
&lt;br /&gt;
In addition to the scissor operator, we can plot the GW (and DFT) band structure along the path. The first choice would be to plot the actual GW calculations, without interpolation, to check that the results are meaningful (or not). This plot is independent of the number of k-points (&#039;&#039;&#039;npoints&#039;&#039;&#039;) that we want to put in the interpolation. The class YamboQPDB finds the calculated points that belong to the path and plots them. Be aware that if we use coarse grids the class would not find any point and the function will not work.&lt;br /&gt;
&lt;br /&gt;
 ks_bs_0, qp_bs_0 = ydb.get_bs_path(lat,path)&lt;br /&gt;
 ks_bs_0.plot_ax(ax,legend=True,c_bands=&#039;r&#039;,label=&#039;KS&#039;)&lt;br /&gt;
 qp_bs_0.plot_ax(ax,legend=True,c_bands=&#039;b&#039;,label=&#039;QP-GW&#039;)&lt;br /&gt;
&lt;br /&gt;
[[File:Figure 7-GW-band-structure-non-interpolated.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
The interpolation of the DFT and GW band structures looks similar:&lt;br /&gt;
&lt;br /&gt;
 ks_bs, qp_bs = ydb.interpolate(lat,path,what=&#039;QP+KS&#039;,lpratio=20)&lt;br /&gt;
 ks_bs.plot_ax(ax,legend=True,c_bands=&#039;r&#039;,label=&#039;KS&#039;)&lt;br /&gt;
 qp_bs.plot_ax(ax,legend=True,c_bands=&#039;b&#039;,label=&#039;QP-GW&#039;)&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;lpratio&#039;&#039;&#039; can be increased if the interpolation does not work as well as intended. The SKW interpolation scheme is the same on implemented in Abipy.&lt;br /&gt;
&lt;br /&gt;
[[File:Figure 8-GW-band-structure-interpolated.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
Finally, we can compare the calculated GW eigenvalues with the interpolation.&lt;br /&gt;
&lt;br /&gt;
[[File:Figure 8-GW-band-structure-comparison.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
As always, remember that you can do your own script, the one provided is just an example. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What to do if the interpolation does not seem to work well&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* First of all, you can try to modify the &#039;&#039;&#039;lpratio&#039;&#039;&#039; parameter and see if it improves.&lt;br /&gt;
&lt;br /&gt;
* If it does not, often you can obtain better results by just interpolating the &#039;&#039;&#039;differences&#039;&#039;&#039; between QP and DFT energies. This can be done by first subtracting the DFT value from the QP energies, then interpolate, and finally re-add the DFT interpolated values. You can also run a separate band structure calculation in DFT on a dense grid (so that you don&#039;t need to interpolate the DFT energies) and read it into your script either with &amp;lt;code&amp;gt;qepy&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;YamboElectronsDB&amp;lt;/code&amp;gt; after creating a SAVE directory. If you have (i) a QP calculation and SAVE on the original grid and (ii) a DFT SAVE on a denser grid, you could do this directly via the &amp;lt;code&amp;gt;interpolate_QP_corrections&amp;lt;/code&amp;gt; method in &amp;lt;code&amp;gt;YamboQPDB&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
* If this also does not improve anything, consider that the quality of the interpolation improves the denser your actual calculated kmesh is. Thus, as a last resort, you can try to run an &#039;&#039;&#039;additional&#039;&#039;&#039; GW calculation on a &#039;&#039;&#039;shifted k-point grid&#039;&#039;&#039;. For example, you shift it by (0.5,0.5,0.5) in fractional coordinates. Yambo is able to calculate the self-energy corrections on this grid without recalculating the screening. Now, you have effectively doubled the k-density of your QP corrections. In this case, you have to do a bit of yambopy scripting yourself to merge the two databases and obtain the band plot: this is an advanced application but you can do everything with the tools yambopy makes available.&lt;br /&gt;
&lt;br /&gt;
==Links==&lt;br /&gt;
* Back to [[Rome 2023#Tutorials]]&lt;br /&gt;
* Back to [[ICTP 2022#Tutorials]]&lt;/div&gt;</summary>
		<author><name>FulvioPaleari</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_electron-phonon_coupling&amp;diff=9333</id>
		<title>Yambopy tutorial: electron-phonon coupling</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_electron-phonon_coupling&amp;diff=9333"/>
		<updated>2026-03-11T10:37:29Z</updated>

		<summary type="html">&lt;p&gt;FulvioPaleari: /* Electron-phonon intro: plots of el-ph matrix elements on k-BZ and q-BZ */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial we will cover the handling of electron-phonon coupling matrix elements by Yambopy. The electron-phonon calculation follows two steps:&lt;br /&gt;
&lt;br /&gt;
# Quantum Espresso calculation of phonon energies, eigenmodes and variations of the self-consistent potential via &amp;lt;code&amp;gt;ph.x&amp;lt;/code&amp;gt;.&lt;br /&gt;
# Electron-phonon matrix element calculation, symmetry expansion and conversion by the &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For more information on the &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; code and how you should run step 1., please see the related documentation [https://github.com/yambo-code/LetzElPhC here].&lt;br /&gt;
&lt;br /&gt;
We can use Yambopy to:&lt;br /&gt;
* Run &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; (both preprocessing and main run) without explicitly writing an input file.&lt;br /&gt;
* Convert the resulting databases into &amp;lt;code&amp;gt;Yambo&amp;lt;/code&amp;gt; format.&lt;br /&gt;
* Analyse the electron-phonon coupling both in &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;Yambo&amp;lt;/code&amp;gt; format.&lt;br /&gt;
&lt;br /&gt;
In particular we will take a look at:&lt;br /&gt;
* Lattice geometry data (Yambo database: &amp;lt;code&amp;gt;ns.db1&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
* Electron-phonon matrix elements (Yambo databases: &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt;; LetzElPhC databases: &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;LetzElphElectronPhononDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
The scripts of the tutorial, but not the databases, can be found in the yambopy directory:&lt;br /&gt;
 $cd tutorial/electron_phonon&lt;br /&gt;
&lt;br /&gt;
The full tutorial, including the LetzElPhC and Yambo databases that we will read, can be downloaded and extracted from the yambo website:&lt;br /&gt;
 $wget https://media.yambo-code.eu/educational/tutorials/files/electron_phonon.tar.gz&lt;br /&gt;
 $tar -xvzf electron_phonon.tar.gz&lt;br /&gt;
 $cd electron_phonon&lt;br /&gt;
&lt;br /&gt;
We will work with monolayer molybdenum disulphide electron-phonon data obtained on a &amp;lt;code&amp;gt;6x6x1&amp;lt;/code&amp;gt; kpoint grid, including spin-orbit interaction (so we deal with electron-phonon coupling and spinorial wavefunctions). Beware that the parameters are most certainly not converged.&lt;br /&gt;
&lt;br /&gt;
=== Command line: electron-phonon calculation and databases [OPTIONAL] ===&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&#039;&#039;&#039;Note&#039;&#039;&#039;: you can run this step only if you have compiled &#039;&#039;&#039;LetzElPhC&#039;&#039;&#039; and &#039;&#039;&#039;Quantum ESPRESSO&#039;&#039;&#039; on your machine. If not, please skip to the following sections of the tutorial, as the electron-phonon coupling databases are already provided in the .tar.gz file and you don&#039;t need to explicitly recalculate them.&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you run this step, please enter the directory&lt;br /&gt;
&lt;br /&gt;
 $cd databases&lt;br /&gt;
&lt;br /&gt;
Here you will find:&lt;br /&gt;
* A scf input file for MoS2, &amp;lt;code&amp;gt;scf/mos2.scf&amp;lt;/code&amp;gt;&lt;br /&gt;
* A dvscf input file for MoS2, &amp;lt;code&amp;gt;dvscf/mos2.dvscf&amp;lt;/code&amp;gt;&lt;br /&gt;
* A Yambo &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory corresponding to a nscf calculation (this has been run already).&lt;br /&gt;
* The pseudopotential files to be used for the calculation.&lt;br /&gt;
&lt;br /&gt;
As a first step, you need to run the Quantum ESPRESSO calculations (it is assumed that you are familiar with this). First run the scf calculation inside &amp;lt;code&amp;gt;scf&amp;lt;/code&amp;gt;, then copy the &amp;lt;code&amp;gt;mos2.save&amp;lt;/code&amp;gt; directory into the &amp;lt;code&amp;gt;dvscf&amp;lt;/code&amp;gt; folder and run the dvscf calculation there. When everything is completed correctly, you will have achieved step 1. above.&lt;br /&gt;
&lt;br /&gt;
Now, you will find the phonon results in the &amp;lt;code&amp;gt;dvscf&amp;lt;/code&amp;gt; directory. We also have done a non-self-consistent calculation to be used in Yambo, and created the relative &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory. If you check this directory, you will find the &amp;lt;code&amp;gt;ns.wf&amp;lt;/code&amp;gt; databases containing the electronic wavefunctions.&lt;br /&gt;
 &lt;br /&gt;
Now, we aim to reconstruct the electron-phonon coupling matrix elements from the phonon energies, modes and potential variations (in &amp;lt;code&amp;gt;dvscf&amp;lt;/code&amp;gt;) and the Bloch electronic wavefunctions used by Yambo (in &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
In order to do this, we will run the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable of the &#039;&#039;&#039;LetzElPhC&#039;&#039;&#039; code (this will be step 2. from above). We will run via command line using yambopy, although it will be instructive to have look at the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; input files later.&lt;br /&gt;
&lt;br /&gt;
We run in the same directory where the Yambo &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; is (remember than you can also virtually move it with a symbolic link).&lt;br /&gt;
&lt;br /&gt;
Type:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y&lt;br /&gt;
&lt;br /&gt;
to see the help for the calculation. Have a look at the various flags and their description.&lt;br /&gt;
For example, if we want to do a serial run of LetzElPhC for bands from &amp;lt;math&amp;gt;n_i&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;n_f&amp;lt;/math&amp;gt;, we should type:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph path/of/ph_input.in -b n_i n_f&lt;br /&gt;
&lt;br /&gt;
Here &amp;lt;math&amp;gt;n_i&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;n_f&amp;lt;/math&amp;gt; are integers representing the initial and final band indices. &#039;&#039;&#039;Please note&#039;&#039;&#039;: in this case, the band index starts from 1 and the the interval of bands read by the code is &amp;lt;math&amp;gt;[n_i,n_f]&amp;lt;/math&amp;gt; including the extrema of the interval. &lt;br /&gt;
&lt;br /&gt;
For our system, we want to do a parallel calculation: 4 MPI tasks on q-point loop (phonon momenta) and 2 MPI tasks on the k-point loop (electron momenta). In addition, we want to explicitly specify the path of the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable. &lt;br /&gt;
&lt;br /&gt;
We have a final choice to make. We can ask Yambopy to produce the default LetzElPhC electron-phonon databases, or to convert them in Yambo-compatible format. By the default, both will be printed. &lt;br /&gt;
&lt;br /&gt;
* If you don&#039;t need the Yambo-style &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases you can run &amp;lt;code&amp;gt;yambopy l2y ...&amp;lt;/code&amp;gt; with the &amp;lt;code&amp;gt;--no_gkkp&amp;lt;/code&amp;gt; option.&lt;br /&gt;
* If you don&#039;t need the default &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; databases you can run &amp;lt;code&amp;gt;yambopy l2y ...&amp;lt;/code&amp;gt; with the &amp;lt;code&amp;gt;--no_lelphc_dbs&amp;lt;/code&amp;gt; option.&lt;br /&gt;
&lt;br /&gt;
However, for this tutorial, we will take a look at both databases, so let&#039;s run:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph dvscf/mos2.dvscf -b 25 28 -par 4 2 -lelphc path/to/lelphc_exe&lt;br /&gt;
&lt;br /&gt;
We include the last two valence bands of monolayer MoS2 (25 and 26) and the first two conduction bands (27 and 28). If your &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable is in the &amp;lt;code&amp;gt;PATH&amp;lt;/code&amp;gt;, you do not need to specify the last flag.&lt;br /&gt;
&lt;br /&gt;
At the end, check your directory: you should find the &amp;lt;code&amp;gt;lelphc.in&amp;lt;/code&amp;gt; input file that was run, let&#039;s inspect it: &lt;br /&gt;
&lt;br /&gt;
 # LetzElPhC input for yambo generated by yambopy&lt;br /&gt;
 nqpool      = 2&lt;br /&gt;
 nkpool      = 4&lt;br /&gt;
 start_bnd   = 25&lt;br /&gt;
 end_bnd     = 28&lt;br /&gt;
 save_dir    = ./SAVE&lt;br /&gt;
 kernel      = dfpt&lt;br /&gt;
 ph_save_dir = dvscf/ph_save&lt;br /&gt;
 convention = yambo&lt;br /&gt;
&lt;br /&gt;
Notice the variable &amp;lt;code&amp;gt;convention=yambo&amp;lt;/code&amp;gt;: what does it mean? At variance with QE and many other codes, Yambo uses the &amp;quot;backward&amp;quot; momentum transfer convention for electronic scatterings. That is, an electronic transition goes from band &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; and momentum &amp;lt;math&amp;gt;k-q&amp;lt;/math&amp;gt; to band &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; and momentum &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;. In the &amp;quot;forward&amp;quot; momentum transfer convention (the more standard one), the transitions go from &amp;lt;math&amp;gt;nk&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;mk+q&amp;lt;/math&amp;gt;. Therefore, this variable ensures that the electron-phonon coupling matrix elements are computed as &amp;lt;math&amp;gt;\langle mk|dV|nk-q\rangle&amp;lt;/math&amp;gt;. However, do not worry: Yambopy can automatically switch between the two conventions when loading the LetzElPhC databases.&lt;br /&gt;
&lt;br /&gt;
You will also find a &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; database that contains the computed electron-phonon matrix elements, in the output format of &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In addition, if you check the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; folder:&lt;br /&gt;
&lt;br /&gt;
 ls SAVE/ndb.elph_gkkp*&lt;br /&gt;
&lt;br /&gt;
you will see that yambopy has created the Yambo-compatible electron-phonon databases and placed them inside the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If you want to run LetzElPhC directly, without using yambopy, you can refer to its [[https://gitlab.com/lumen-code/LetzElPhC/-/blob/main/docs/main.pdf?ref_type=heads|user guide]].&lt;br /&gt;
Keep in mind that in this case, in order to convert the database to the &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases of Yambo, you will then need a couple of lines of python using the Yambopy class &amp;lt;code&amp;gt;ConvertElectronPhononDB&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;yambopy/letzelph_interface/lelph2y.py&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
At the end of this section, you should have produced the same databases that you find in the main &amp;lt;code&amp;gt;electron_phonon&amp;lt;/code&amp;gt; folder. You can run the following part either in the directory where you are (by copying the python scripts here), or by going back:&lt;br /&gt;
&lt;br /&gt;
 $cd ..&lt;br /&gt;
&lt;br /&gt;
and using the precomputed ones.&lt;br /&gt;
&lt;br /&gt;
=== Electron-phonon intro: plots of el-ph matrix elements on k-BZ and q-BZ ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; and read the electron-phonon databases that you generated in the previous section.&lt;br /&gt;
&lt;br /&gt;
In order to read the &amp;lt;code&amp;gt;ndb.elph_gkkp_expanded*&amp;lt;/code&amp;gt; databases in python we use the Yambopy class &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
 elph = YamboElectronPhononDB(ylat,folder_gkkp=&#039;path/to/elph/folder&#039;,save=&#039;path/to/SAVE&#039;)&lt;br /&gt;
(notice that it requires a previous instance of &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Instead, in order to read the &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; databases from LetzElPhC, we use a different class:&lt;br /&gt;
 elph = LetzElphElectronPhononDB(&#039;path/to/ndb.elph&#039;)&lt;br /&gt;
&lt;br /&gt;
Now, the &amp;lt;code&amp;gt;elph&amp;lt;/code&amp;gt; objects contain phonon frequencies, phonon eigenvectors, q-point information and, of course, the electron-phonon matrix elements &amp;lt;math&amp;gt;g_{nm\nu}(k,q)&amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; are electron band states, &amp;lt;math&amp;gt;\nu&amp;lt;/math&amp;gt; is a phonon branch, and &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; are the electronic and transfer momenta.&lt;br /&gt;
&lt;br /&gt;
We can print the docstring of the &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt; class with&lt;br /&gt;
 print(yelph.__doc__)&lt;br /&gt;
and of the &amp;lt;code&amp;gt;LetzElphElectronPhononDB&amp;lt;/code&amp;gt; class with&lt;br /&gt;
 print(lelph.__doc__)&lt;br /&gt;
to get an idea of the information stored and of their capabilities.&lt;br /&gt;
&lt;br /&gt;
Now check the &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; script. Besides choosing which database to load, it also performs two plots:&lt;br /&gt;
 &lt;br /&gt;
* Plot of |g(k)| in the k-BZ for selected bands n,m, phonon mode \nu and q [&amp;lt;code&amp;gt;kspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Plot of |g(q)| in the q-BZ for selected bands n,m, phonon mode \nu and k [&amp;lt;code&amp;gt;qspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
You will see that after loading the database, it first postprocesses the electron-phonon data to obtain a plottable quantity. Indeed, it is not necessarily easy to understand what to plot and what to keep fixed, since the matrix element depends on two momenta and three state indices. In addition, bands or phonon states may be degenerate at certain momenta.&lt;br /&gt;
&lt;br /&gt;
In practice, we set a phonon mode (the eighth mode, this is the branch with symmetry &amp;lt;math&amp;gt;A_1^\prime&amp;lt;/math&amp;gt; at zone center) and either a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; point to keep fixed (in each case, we select the high-symmetry &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; point). As for the bands, we consider the top two valence bands. These are mostly degenerate, except around the points &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;K^\prime&amp;lt;/math&amp;gt; where they are split by spin-orbit interaction. We then average over these states before plotting, obtaining the quantity (in k-space below):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; I^{\mu}_{&amp;lt;v&amp;gt;q}(\mathbf{k}) = \sqrt{\sum_{v,v^\prime=24,25}|g^{\mu}_{vv^\prime q}(\mathbf{k})|^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You are invited to play with the electronic, phononic and momentum indices to see what happens! (beware of degenerate states: if not properly accounted for by the sum of the norms, the plots will be phase-dependent and unphysical)&lt;br /&gt;
&lt;br /&gt;
[[File:MoS2 6x6x1 g vv&#039; in kspace.png|yambopy el-ph plot for tutorial|500px]] [[File:MoS2 6x6x1 g vv&#039; in qspace.png|yambopy el-ph plot for tutorial|500px]]&lt;/div&gt;</summary>
		<author><name>FulvioPaleari</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_electron-phonon_coupling&amp;diff=9332</id>
		<title>Yambopy tutorial: electron-phonon coupling</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_electron-phonon_coupling&amp;diff=9332"/>
		<updated>2026-03-11T10:36:55Z</updated>

		<summary type="html">&lt;p&gt;FulvioPaleari: /* Electron-phonon intro: plots of el-ph matrix elements on k-BZ and q-BZ */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial we will cover the handling of electron-phonon coupling matrix elements by Yambopy. The electron-phonon calculation follows two steps:&lt;br /&gt;
&lt;br /&gt;
# Quantum Espresso calculation of phonon energies, eigenmodes and variations of the self-consistent potential via &amp;lt;code&amp;gt;ph.x&amp;lt;/code&amp;gt;.&lt;br /&gt;
# Electron-phonon matrix element calculation, symmetry expansion and conversion by the &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For more information on the &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; code and how you should run step 1., please see the related documentation [https://github.com/yambo-code/LetzElPhC here].&lt;br /&gt;
&lt;br /&gt;
We can use Yambopy to:&lt;br /&gt;
* Run &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; (both preprocessing and main run) without explicitly writing an input file.&lt;br /&gt;
* Convert the resulting databases into &amp;lt;code&amp;gt;Yambo&amp;lt;/code&amp;gt; format.&lt;br /&gt;
* Analyse the electron-phonon coupling both in &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;Yambo&amp;lt;/code&amp;gt; format.&lt;br /&gt;
&lt;br /&gt;
In particular we will take a look at:&lt;br /&gt;
* Lattice geometry data (Yambo database: &amp;lt;code&amp;gt;ns.db1&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
* Electron-phonon matrix elements (Yambo databases: &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt;; LetzElPhC databases: &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;LetzElphElectronPhononDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
The scripts of the tutorial, but not the databases, can be found in the yambopy directory:&lt;br /&gt;
 $cd tutorial/electron_phonon&lt;br /&gt;
&lt;br /&gt;
The full tutorial, including the LetzElPhC and Yambo databases that we will read, can be downloaded and extracted from the yambo website:&lt;br /&gt;
 $wget https://media.yambo-code.eu/educational/tutorials/files/electron_phonon.tar.gz&lt;br /&gt;
 $tar -xvzf electron_phonon.tar.gz&lt;br /&gt;
 $cd electron_phonon&lt;br /&gt;
&lt;br /&gt;
We will work with monolayer molybdenum disulphide electron-phonon data obtained on a &amp;lt;code&amp;gt;6x6x1&amp;lt;/code&amp;gt; kpoint grid, including spin-orbit interaction (so we deal with electron-phonon coupling and spinorial wavefunctions). Beware that the parameters are most certainly not converged.&lt;br /&gt;
&lt;br /&gt;
=== Command line: electron-phonon calculation and databases [OPTIONAL] ===&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&#039;&#039;&#039;Note&#039;&#039;&#039;: you can run this step only if you have compiled &#039;&#039;&#039;LetzElPhC&#039;&#039;&#039; and &#039;&#039;&#039;Quantum ESPRESSO&#039;&#039;&#039; on your machine. If not, please skip to the following sections of the tutorial, as the electron-phonon coupling databases are already provided in the .tar.gz file and you don&#039;t need to explicitly recalculate them.&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you run this step, please enter the directory&lt;br /&gt;
&lt;br /&gt;
 $cd databases&lt;br /&gt;
&lt;br /&gt;
Here you will find:&lt;br /&gt;
* A scf input file for MoS2, &amp;lt;code&amp;gt;scf/mos2.scf&amp;lt;/code&amp;gt;&lt;br /&gt;
* A dvscf input file for MoS2, &amp;lt;code&amp;gt;dvscf/mos2.dvscf&amp;lt;/code&amp;gt;&lt;br /&gt;
* A Yambo &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory corresponding to a nscf calculation (this has been run already).&lt;br /&gt;
* The pseudopotential files to be used for the calculation.&lt;br /&gt;
&lt;br /&gt;
As a first step, you need to run the Quantum ESPRESSO calculations (it is assumed that you are familiar with this). First run the scf calculation inside &amp;lt;code&amp;gt;scf&amp;lt;/code&amp;gt;, then copy the &amp;lt;code&amp;gt;mos2.save&amp;lt;/code&amp;gt; directory into the &amp;lt;code&amp;gt;dvscf&amp;lt;/code&amp;gt; folder and run the dvscf calculation there. When everything is completed correctly, you will have achieved step 1. above.&lt;br /&gt;
&lt;br /&gt;
Now, you will find the phonon results in the &amp;lt;code&amp;gt;dvscf&amp;lt;/code&amp;gt; directory. We also have done a non-self-consistent calculation to be used in Yambo, and created the relative &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory. If you check this directory, you will find the &amp;lt;code&amp;gt;ns.wf&amp;lt;/code&amp;gt; databases containing the electronic wavefunctions.&lt;br /&gt;
 &lt;br /&gt;
Now, we aim to reconstruct the electron-phonon coupling matrix elements from the phonon energies, modes and potential variations (in &amp;lt;code&amp;gt;dvscf&amp;lt;/code&amp;gt;) and the Bloch electronic wavefunctions used by Yambo (in &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
In order to do this, we will run the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable of the &#039;&#039;&#039;LetzElPhC&#039;&#039;&#039; code (this will be step 2. from above). We will run via command line using yambopy, although it will be instructive to have look at the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; input files later.&lt;br /&gt;
&lt;br /&gt;
We run in the same directory where the Yambo &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; is (remember than you can also virtually move it with a symbolic link).&lt;br /&gt;
&lt;br /&gt;
Type:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y&lt;br /&gt;
&lt;br /&gt;
to see the help for the calculation. Have a look at the various flags and their description.&lt;br /&gt;
For example, if we want to do a serial run of LetzElPhC for bands from &amp;lt;math&amp;gt;n_i&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;n_f&amp;lt;/math&amp;gt;, we should type:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph path/of/ph_input.in -b n_i n_f&lt;br /&gt;
&lt;br /&gt;
Here &amp;lt;math&amp;gt;n_i&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;n_f&amp;lt;/math&amp;gt; are integers representing the initial and final band indices. &#039;&#039;&#039;Please note&#039;&#039;&#039;: in this case, the band index starts from 1 and the the interval of bands read by the code is &amp;lt;math&amp;gt;[n_i,n_f]&amp;lt;/math&amp;gt; including the extrema of the interval. &lt;br /&gt;
&lt;br /&gt;
For our system, we want to do a parallel calculation: 4 MPI tasks on q-point loop (phonon momenta) and 2 MPI tasks on the k-point loop (electron momenta). In addition, we want to explicitly specify the path of the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable. &lt;br /&gt;
&lt;br /&gt;
We have a final choice to make. We can ask Yambopy to produce the default LetzElPhC electron-phonon databases, or to convert them in Yambo-compatible format. By the default, both will be printed. &lt;br /&gt;
&lt;br /&gt;
* If you don&#039;t need the Yambo-style &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases you can run &amp;lt;code&amp;gt;yambopy l2y ...&amp;lt;/code&amp;gt; with the &amp;lt;code&amp;gt;--no_gkkp&amp;lt;/code&amp;gt; option.&lt;br /&gt;
* If you don&#039;t need the default &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; databases you can run &amp;lt;code&amp;gt;yambopy l2y ...&amp;lt;/code&amp;gt; with the &amp;lt;code&amp;gt;--no_lelphc_dbs&amp;lt;/code&amp;gt; option.&lt;br /&gt;
&lt;br /&gt;
However, for this tutorial, we will take a look at both databases, so let&#039;s run:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph dvscf/mos2.dvscf -b 25 28 -par 4 2 -lelphc path/to/lelphc_exe&lt;br /&gt;
&lt;br /&gt;
We include the last two valence bands of monolayer MoS2 (25 and 26) and the first two conduction bands (27 and 28). If your &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable is in the &amp;lt;code&amp;gt;PATH&amp;lt;/code&amp;gt;, you do not need to specify the last flag.&lt;br /&gt;
&lt;br /&gt;
At the end, check your directory: you should find the &amp;lt;code&amp;gt;lelphc.in&amp;lt;/code&amp;gt; input file that was run, let&#039;s inspect it: &lt;br /&gt;
&lt;br /&gt;
 # LetzElPhC input for yambo generated by yambopy&lt;br /&gt;
 nqpool      = 2&lt;br /&gt;
 nkpool      = 4&lt;br /&gt;
 start_bnd   = 25&lt;br /&gt;
 end_bnd     = 28&lt;br /&gt;
 save_dir    = ./SAVE&lt;br /&gt;
 kernel      = dfpt&lt;br /&gt;
 ph_save_dir = dvscf/ph_save&lt;br /&gt;
 convention = yambo&lt;br /&gt;
&lt;br /&gt;
Notice the variable &amp;lt;code&amp;gt;convention=yambo&amp;lt;/code&amp;gt;: what does it mean? At variance with QE and many other codes, Yambo uses the &amp;quot;backward&amp;quot; momentum transfer convention for electronic scatterings. That is, an electronic transition goes from band &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; and momentum &amp;lt;math&amp;gt;k-q&amp;lt;/math&amp;gt; to band &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; and momentum &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;. In the &amp;quot;forward&amp;quot; momentum transfer convention (the more standard one), the transitions go from &amp;lt;math&amp;gt;nk&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;mk+q&amp;lt;/math&amp;gt;. Therefore, this variable ensures that the electron-phonon coupling matrix elements are computed as &amp;lt;math&amp;gt;\langle mk|dV|nk-q\rangle&amp;lt;/math&amp;gt;. However, do not worry: Yambopy can automatically switch between the two conventions when loading the LetzElPhC databases.&lt;br /&gt;
&lt;br /&gt;
You will also find a &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; database that contains the computed electron-phonon matrix elements, in the output format of &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In addition, if you check the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; folder:&lt;br /&gt;
&lt;br /&gt;
 ls SAVE/ndb.elph_gkkp*&lt;br /&gt;
&lt;br /&gt;
you will see that yambopy has created the Yambo-compatible electron-phonon databases and placed them inside the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If you want to run LetzElPhC directly, without using yambopy, you can refer to its [[https://gitlab.com/lumen-code/LetzElPhC/-/blob/main/docs/main.pdf?ref_type=heads|user guide]].&lt;br /&gt;
Keep in mind that in this case, in order to convert the database to the &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases of Yambo, you will then need a couple of lines of python using the Yambopy class &amp;lt;code&amp;gt;ConvertElectronPhononDB&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;yambopy/letzelph_interface/lelph2y.py&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
At the end of this section, you should have produced the same databases that you find in the main &amp;lt;code&amp;gt;electron_phonon&amp;lt;/code&amp;gt; folder. You can run the following part either in the directory where you are (by copying the python scripts here), or by going back:&lt;br /&gt;
&lt;br /&gt;
 $cd ..&lt;br /&gt;
&lt;br /&gt;
and using the precomputed ones.&lt;br /&gt;
&lt;br /&gt;
=== Electron-phonon intro: plots of el-ph matrix elements on k-BZ and q-BZ ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; and read the electron-phonon databases that you generated in the previous section.&lt;br /&gt;
&lt;br /&gt;
In order to read the &amp;lt;code&amp;gt;ndb.elph_gkkp_expanded*&amp;lt;/code&amp;gt; databases in python we use the Yambopy class &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
 elph = YamboElectronPhononDB(ylat,folder_gkkp=&#039;path/to/elph/folder&#039;,save=&#039;path/to/SAVE&#039;)&lt;br /&gt;
(notice that it requires a previous instance of &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Instead, in order to read the &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; databases from LetzElPhC, we use a different class:&lt;br /&gt;
 elph = LetzElphElectronPhononDB(&#039;path/to/ndb.elph&#039;)&lt;br /&gt;
&lt;br /&gt;
Now, the &amp;lt;code&amp;gt;elph&amp;lt;/code&amp;gt; objects contain phonon frequencies, phonon eigenvectors, q-point information and, of course, the electron-phonon matrix elements &amp;lt;math&amp;gt;g_{nm\nu}(k,q)&amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; are electron band states, &amp;lt;math&amp;gt;\nu&amp;lt;/math&amp;gt; is a phonon branch, and &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; are the electronic and transfer momenta.&lt;br /&gt;
&lt;br /&gt;
We can print the docstring of the &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt; class with&lt;br /&gt;
 print(yelph.__doc__)&lt;br /&gt;
and of the &amp;lt;code&amp;gt;LetzElphElectronPhononDB&amp;lt;/code&amp;gt; class with&lt;br /&gt;
 print(lelph.__doc__)&lt;br /&gt;
to get an idea of the information stored and of their capabilities.&lt;br /&gt;
&lt;br /&gt;
Now check the &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; script. Besides choosing which database to load, it also performs two plots:&lt;br /&gt;
 &lt;br /&gt;
* Plot of |g(k)| in the k-BZ for selected bands n,m, phonon mode \nu and q [&amp;lt;code&amp;gt;kspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Plot of |g(q)| in the q-BZ for selected bands n,m, phonon mode \nu and k [&amp;lt;code&amp;gt;qspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
You will see that after loading the database, it first postprocesses the electron-phonon data to obtain a plottable quantity. Indeed, it is not necessarily easy to understand what to plot and what to keep fixed, since the matrix element depends on two momenta and three state indices. In addition, bands or phonon states may be degenerate at certain momenta.&lt;br /&gt;
&lt;br /&gt;
In practice, we set a phonon mode (the eighth mode, this is the branch with symmetry &amp;lt;math&amp;gt;A_1^\prime&amp;lt;/math&amp;gt; at zone center) and either a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; point to keep fixed (in each case, we select the high-symmetry &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; point). As for the bands, we consider the top two valence bands. These are mostly degenerate, except around the points &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;K^\prime&amp;lt;/math&amp;gt; where they are split by spin-orbit interaction. We then average over these states before plotting, obtaining the quantity (in k-space below):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; I^{\mu}_{&amp;lt;v&amp;gt;q}(\mathbf{k}) = \sqrt{\sum_{v,v^\prime=24,25}|g^{\mu}_{vv^\prime q}(\mathbf{k})|^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You are invited to play with the electronic, phononic and momentum indices to see what happens! (beware of degenerate states: if not properly accounted for by the sum of the norms, the plots will be phase-dependent and unphysical)&lt;br /&gt;
&lt;br /&gt;
[[File:MoS2 6x6x1 g vv&#039; in kspace.png|yambopy el-ph plot for tutorial|400px]] [[File:MoS2 6x6x1 g vv&#039; in qspace.png|yambopy el-ph plot for tutorial|400px]]&lt;/div&gt;</summary>
		<author><name>FulvioPaleari</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=File:MoS2_6x6x1_g_vv%27_in_qspace.png&amp;diff=9331</id>
		<title>File:MoS2 6x6x1 g vv&#039; in qspace.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=File:MoS2_6x6x1_g_vv%27_in_qspace.png&amp;diff=9331"/>
		<updated>2026-03-11T10:35:14Z</updated>

		<summary type="html">&lt;p&gt;FulvioPaleari: Uploaded own work with UploadWizard&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=={{int:filedesc}}==&lt;br /&gt;
{{Information&lt;br /&gt;
|description={{en|1=Yambo tutorial image}}&lt;br /&gt;
|date=2026-03-10&lt;br /&gt;
|source={{own}}&lt;br /&gt;
|author=[[User:FulvioPaleari|FulvioPaleari]]&lt;br /&gt;
|permission=&lt;br /&gt;
|other versions=&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=={{int:license-header}}==&lt;br /&gt;
{{self|cc-by-sa-4.0}}&lt;br /&gt;
&lt;br /&gt;
This file was uploaded with the UploadWizard extension.&lt;br /&gt;
&lt;br /&gt;
[[Category:Uploaded with UploadWizard]]&lt;/div&gt;</summary>
		<author><name>FulvioPaleari</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=File:MoS2_6x6x1_g_vv%27_in_kspace.png&amp;diff=9330</id>
		<title>File:MoS2 6x6x1 g vv&#039; in kspace.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=File:MoS2_6x6x1_g_vv%27_in_kspace.png&amp;diff=9330"/>
		<updated>2026-03-11T10:35:14Z</updated>

		<summary type="html">&lt;p&gt;FulvioPaleari: Uploaded own work with UploadWizard&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=={{int:filedesc}}==&lt;br /&gt;
{{Information&lt;br /&gt;
|description={{en|1=Yambo tutorial image}}&lt;br /&gt;
|date=2026-03-10&lt;br /&gt;
|source={{own}}&lt;br /&gt;
|author=[[User:FulvioPaleari|FulvioPaleari]]&lt;br /&gt;
|permission=&lt;br /&gt;
|other versions=&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
=={{int:license-header}}==&lt;br /&gt;
{{self|cc-by-sa-4.0}}&lt;br /&gt;
&lt;br /&gt;
This file was uploaded with the UploadWizard extension.&lt;br /&gt;
&lt;br /&gt;
[[Category:Uploaded with UploadWizard]]&lt;/div&gt;</summary>
		<author><name>FulvioPaleari</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_electron-phonon_coupling&amp;diff=9329</id>
		<title>Yambopy tutorial: electron-phonon coupling</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_electron-phonon_coupling&amp;diff=9329"/>
		<updated>2026-03-10T14:37:47Z</updated>

		<summary type="html">&lt;p&gt;FulvioPaleari: /* Electron-phonon intro: plots of el-ph matrix elements on k-BZ and q-BZ */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial we will cover the handling of electron-phonon coupling matrix elements by Yambopy. The electron-phonon calculation follows two steps:&lt;br /&gt;
&lt;br /&gt;
# Quantum Espresso calculation of phonon energies, eigenmodes and variations of the self-consistent potential via &amp;lt;code&amp;gt;ph.x&amp;lt;/code&amp;gt;.&lt;br /&gt;
# Electron-phonon matrix element calculation, symmetry expansion and conversion by the &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For more information on the &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; code and how you should run step 1., please see the related documentation [https://github.com/yambo-code/LetzElPhC here].&lt;br /&gt;
&lt;br /&gt;
We can use Yambopy to:&lt;br /&gt;
* Run &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; (both preprocessing and main run) without explicitly writing an input file.&lt;br /&gt;
* Convert the resulting databases into &amp;lt;code&amp;gt;Yambo&amp;lt;/code&amp;gt; format.&lt;br /&gt;
* Analyse the electron-phonon coupling both in &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;Yambo&amp;lt;/code&amp;gt; format.&lt;br /&gt;
&lt;br /&gt;
In particular we will take a look at:&lt;br /&gt;
* Lattice geometry data (Yambo database: &amp;lt;code&amp;gt;ns.db1&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
* Electron-phonon matrix elements (Yambo databases: &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt;; LetzElPhC databases: &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;LetzElphElectronPhononDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
The scripts of the tutorial, but not the databases, can be found in the yambopy directory:&lt;br /&gt;
 $cd tutorial/electron_phonon&lt;br /&gt;
&lt;br /&gt;
The full tutorial, including the LetzElPhC and Yambo databases that we will read, can be downloaded and extracted from the yambo website:&lt;br /&gt;
 $wget https://media.yambo-code.eu/educational/tutorials/files/electron_phonon.tar.gz&lt;br /&gt;
 $tar -xvzf electron_phonon.tar.gz&lt;br /&gt;
 $cd electron_phonon&lt;br /&gt;
&lt;br /&gt;
We will work with monolayer molybdenum disulphide electron-phonon data obtained on a &amp;lt;code&amp;gt;6x6x1&amp;lt;/code&amp;gt; kpoint grid, including spin-orbit interaction (so we deal with electron-phonon coupling and spinorial wavefunctions). Beware that the parameters are most certainly not converged.&lt;br /&gt;
&lt;br /&gt;
=== Command line: electron-phonon calculation and databases [OPTIONAL] ===&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&#039;&#039;&#039;Note&#039;&#039;&#039;: you can run this step only if you have compiled &#039;&#039;&#039;LetzElPhC&#039;&#039;&#039; and &#039;&#039;&#039;Quantum ESPRESSO&#039;&#039;&#039; on your machine. If not, please skip to the following sections of the tutorial, as the electron-phonon coupling databases are already provided in the .tar.gz file and you don&#039;t need to explicitly recalculate them.&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you run this step, please enter the directory&lt;br /&gt;
&lt;br /&gt;
 $cd databases&lt;br /&gt;
&lt;br /&gt;
Here you will find:&lt;br /&gt;
* A scf input file for MoS2, &amp;lt;code&amp;gt;scf/mos2.scf&amp;lt;/code&amp;gt;&lt;br /&gt;
* A dvscf input file for MoS2, &amp;lt;code&amp;gt;dvscf/mos2.dvscf&amp;lt;/code&amp;gt;&lt;br /&gt;
* A Yambo &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory corresponding to a nscf calculation (this has been run already).&lt;br /&gt;
* The pseudopotential files to be used for the calculation.&lt;br /&gt;
&lt;br /&gt;
As a first step, you need to run the Quantum ESPRESSO calculations (it is assumed that you are familiar with this). First run the scf calculation inside &amp;lt;code&amp;gt;scf&amp;lt;/code&amp;gt;, then copy the &amp;lt;code&amp;gt;mos2.save&amp;lt;/code&amp;gt; directory into the &amp;lt;code&amp;gt;dvscf&amp;lt;/code&amp;gt; folder and run the dvscf calculation there. When everything is completed correctly, you will have achieved step 1. above.&lt;br /&gt;
&lt;br /&gt;
Now, you will find the phonon results in the &amp;lt;code&amp;gt;dvscf&amp;lt;/code&amp;gt; directory. We also have done a non-self-consistent calculation to be used in Yambo, and created the relative &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory. If you check this directory, you will find the &amp;lt;code&amp;gt;ns.wf&amp;lt;/code&amp;gt; databases containing the electronic wavefunctions.&lt;br /&gt;
 &lt;br /&gt;
Now, we aim to reconstruct the electron-phonon coupling matrix elements from the phonon energies, modes and potential variations (in &amp;lt;code&amp;gt;dvscf&amp;lt;/code&amp;gt;) and the Bloch electronic wavefunctions used by Yambo (in &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
In order to do this, we will run the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable of the &#039;&#039;&#039;LetzElPhC&#039;&#039;&#039; code (this will be step 2. from above). We will run via command line using yambopy, although it will be instructive to have look at the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; input files later.&lt;br /&gt;
&lt;br /&gt;
We run in the same directory where the Yambo &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; is (remember than you can also virtually move it with a symbolic link).&lt;br /&gt;
&lt;br /&gt;
Type:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y&lt;br /&gt;
&lt;br /&gt;
to see the help for the calculation. Have a look at the various flags and their description.&lt;br /&gt;
For example, if we want to do a serial run of LetzElPhC for bands from &amp;lt;math&amp;gt;n_i&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;n_f&amp;lt;/math&amp;gt;, we should type:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph path/of/ph_input.in -b n_i n_f&lt;br /&gt;
&lt;br /&gt;
Here &amp;lt;math&amp;gt;n_i&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;n_f&amp;lt;/math&amp;gt; are integers representing the initial and final band indices. &#039;&#039;&#039;Please note&#039;&#039;&#039;: in this case, the band index starts from 1 and the the interval of bands read by the code is &amp;lt;math&amp;gt;[n_i,n_f]&amp;lt;/math&amp;gt; including the extrema of the interval. &lt;br /&gt;
&lt;br /&gt;
For our system, we want to do a parallel calculation: 4 MPI tasks on q-point loop (phonon momenta) and 2 MPI tasks on the k-point loop (electron momenta). In addition, we want to explicitly specify the path of the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable. &lt;br /&gt;
&lt;br /&gt;
We have a final choice to make. We can ask Yambopy to produce the default LetzElPhC electron-phonon databases, or to convert them in Yambo-compatible format. By the default, both will be printed. &lt;br /&gt;
&lt;br /&gt;
* If you don&#039;t need the Yambo-style &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases you can run &amp;lt;code&amp;gt;yambopy l2y ...&amp;lt;/code&amp;gt; with the &amp;lt;code&amp;gt;--no_gkkp&amp;lt;/code&amp;gt; option.&lt;br /&gt;
* If you don&#039;t need the default &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; databases you can run &amp;lt;code&amp;gt;yambopy l2y ...&amp;lt;/code&amp;gt; with the &amp;lt;code&amp;gt;--no_lelphc_dbs&amp;lt;/code&amp;gt; option.&lt;br /&gt;
&lt;br /&gt;
However, for this tutorial, we will take a look at both databases, so let&#039;s run:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph dvscf/mos2.dvscf -b 25 28 -par 4 2 -lelphc path/to/lelphc_exe&lt;br /&gt;
&lt;br /&gt;
We include the last two valence bands of monolayer MoS2 (25 and 26) and the first two conduction bands (27 and 28). If your &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable is in the &amp;lt;code&amp;gt;PATH&amp;lt;/code&amp;gt;, you do not need to specify the last flag.&lt;br /&gt;
&lt;br /&gt;
At the end, check your directory: you should find the &amp;lt;code&amp;gt;lelphc.in&amp;lt;/code&amp;gt; input file that was run, let&#039;s inspect it: &lt;br /&gt;
&lt;br /&gt;
 # LetzElPhC input for yambo generated by yambopy&lt;br /&gt;
 nqpool      = 2&lt;br /&gt;
 nkpool      = 4&lt;br /&gt;
 start_bnd   = 25&lt;br /&gt;
 end_bnd     = 28&lt;br /&gt;
 save_dir    = ./SAVE&lt;br /&gt;
 kernel      = dfpt&lt;br /&gt;
 ph_save_dir = dvscf/ph_save&lt;br /&gt;
 convention = yambo&lt;br /&gt;
&lt;br /&gt;
Notice the variable &amp;lt;code&amp;gt;convention=yambo&amp;lt;/code&amp;gt;: what does it mean? At variance with QE and many other codes, Yambo uses the &amp;quot;backward&amp;quot; momentum transfer convention for electronic scatterings. That is, an electronic transition goes from band &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; and momentum &amp;lt;math&amp;gt;k-q&amp;lt;/math&amp;gt; to band &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; and momentum &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;. In the &amp;quot;forward&amp;quot; momentum transfer convention (the more standard one), the transitions go from &amp;lt;math&amp;gt;nk&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;mk+q&amp;lt;/math&amp;gt;. Therefore, this variable ensures that the electron-phonon coupling matrix elements are computed as &amp;lt;math&amp;gt;\langle mk|dV|nk-q\rangle&amp;lt;/math&amp;gt;. However, do not worry: Yambopy can automatically switch between the two conventions when loading the LetzElPhC databases.&lt;br /&gt;
&lt;br /&gt;
You will also find a &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; database that contains the computed electron-phonon matrix elements, in the output format of &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In addition, if you check the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; folder:&lt;br /&gt;
&lt;br /&gt;
 ls SAVE/ndb.elph_gkkp*&lt;br /&gt;
&lt;br /&gt;
you will see that yambopy has created the Yambo-compatible electron-phonon databases and placed them inside the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If you want to run LetzElPhC directly, without using yambopy, you can refer to its [[https://gitlab.com/lumen-code/LetzElPhC/-/blob/main/docs/main.pdf?ref_type=heads|user guide]].&lt;br /&gt;
Keep in mind that in this case, in order to convert the database to the &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases of Yambo, you will then need a couple of lines of python using the Yambopy class &amp;lt;code&amp;gt;ConvertElectronPhononDB&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;yambopy/letzelph_interface/lelph2y.py&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
At the end of this section, you should have produced the same databases that you find in the main &amp;lt;code&amp;gt;electron_phonon&amp;lt;/code&amp;gt; folder. You can run the following part either in the directory where you are (by copying the python scripts here), or by going back:&lt;br /&gt;
&lt;br /&gt;
 $cd ..&lt;br /&gt;
&lt;br /&gt;
and using the precomputed ones.&lt;br /&gt;
&lt;br /&gt;
=== Electron-phonon intro: plots of el-ph matrix elements on k-BZ and q-BZ ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; and read the electron-phonon databases that you generated in the previous section.&lt;br /&gt;
&lt;br /&gt;
In order to read the &amp;lt;code&amp;gt;ndb.elph_gkkp_expanded*&amp;lt;/code&amp;gt; databases in python we use the Yambopy class &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
 elph = YamboElectronPhononDB(ylat,folder_gkkp=&#039;path/to/elph/folder&#039;,save=&#039;path/to/SAVE&#039;)&lt;br /&gt;
(notice that it requires a previous instance of &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Instead, in order to read the &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; databases from LetzElPhC, we use a different class:&lt;br /&gt;
 elph = LetzElphElectronPhononDB(&#039;path/to/ndb.elph&#039;)&lt;br /&gt;
&lt;br /&gt;
Now, the &amp;lt;code&amp;gt;elph&amp;lt;/code&amp;gt; objects contain phonon frequencies, phonon eigenvectors, q-point information and, of course, the electron-phonon matrix elements &amp;lt;math&amp;gt;g_{nm\nu}(k,q)&amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; are electron band states, &amp;lt;math&amp;gt;\nu&amp;lt;/math&amp;gt; is a phonon branch, and &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; are the electronic and transfer momenta.&lt;br /&gt;
&lt;br /&gt;
We can print the docstring of the &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt; class with&lt;br /&gt;
 print(yelph.__doc__)&lt;br /&gt;
and of the &amp;lt;code&amp;gt;LetzElphElectronPhononDB&amp;lt;/code&amp;gt; class with&lt;br /&gt;
 print(lelph.__doc__)&lt;br /&gt;
to get an idea of the information stored and of their capabilities.&lt;br /&gt;
&lt;br /&gt;
Now check the &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; script. Besides choosing which database to load, it also performs two plots:&lt;br /&gt;
 &lt;br /&gt;
* Plot of |g(k)| in the k-BZ for selected bands n,m, phonon mode \nu and q [&amp;lt;code&amp;gt;kspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Plot of |g(q)| in the q-BZ for selected bands n,m, phonon mode \nu and k [&amp;lt;code&amp;gt;qspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
You will see that after loading the database, it first postprocesses the electron-phonon data to obtain a plottable quantity. Indeed, it is not necessarily easy to understand what to plot and what to keep fixed, since the matrix element depends on two momenta and three state indices. In addition, bands or phonon states may be degenerate at certain momenta.&lt;br /&gt;
&lt;br /&gt;
In practice, we set a phonon mode (the eighth mode, this is the branch with symmetry &amp;lt;math&amp;gt;A_1^\prime&amp;lt;/math&amp;gt; at zone center) and either a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; point to keep fixed (in each case, we select the high-symmetry &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; point). As for the bands, we consider the top two valence bands. These are mostly degenerate, except around the points &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;K^\prime&amp;lt;/math&amp;gt; where they are split by spin-orbit interaction. We then average over these states before plotting, obtaining the quantity (in k-space below):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; I^{\mu}_{&amp;lt;v&amp;gt;q}(\mathbf{k}) = \sqrt{\sum_{v,v^\prime=24,25}|g^{\mu}_{vv^\prime q}(\mathbf{k})|^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
You are invited to play with the electronic, phononic and momentum indices to see what happens! (beware of degenerate states: if not properly accounted for by the sum of the norms, the plots will be phase-dependent and unphysical)&lt;br /&gt;
&lt;br /&gt;
[[File:Elph hbn.jpg|YamboElectronPhononDB plot from yambopy tutorial|500px]]&lt;/div&gt;</summary>
		<author><name>FulvioPaleari</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_electron-phonon_coupling&amp;diff=9328</id>
		<title>Yambopy tutorial: electron-phonon coupling</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_electron-phonon_coupling&amp;diff=9328"/>
		<updated>2026-03-10T14:32:45Z</updated>

		<summary type="html">&lt;p&gt;FulvioPaleari: /* Electron-phonon intro: plots of el-ph matrix elements on k-BZ and q-BZ */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial we will cover the handling of electron-phonon coupling matrix elements by Yambopy. The electron-phonon calculation follows two steps:&lt;br /&gt;
&lt;br /&gt;
# Quantum Espresso calculation of phonon energies, eigenmodes and variations of the self-consistent potential via &amp;lt;code&amp;gt;ph.x&amp;lt;/code&amp;gt;.&lt;br /&gt;
# Electron-phonon matrix element calculation, symmetry expansion and conversion by the &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For more information on the &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; code and how you should run step 1., please see the related documentation [https://github.com/yambo-code/LetzElPhC here].&lt;br /&gt;
&lt;br /&gt;
We can use Yambopy to:&lt;br /&gt;
* Run &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; (both preprocessing and main run) without explicitly writing an input file.&lt;br /&gt;
* Convert the resulting databases into &amp;lt;code&amp;gt;Yambo&amp;lt;/code&amp;gt; format.&lt;br /&gt;
* Analyse the electron-phonon coupling both in &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;Yambo&amp;lt;/code&amp;gt; format.&lt;br /&gt;
&lt;br /&gt;
In particular we will take a look at:&lt;br /&gt;
* Lattice geometry data (Yambo database: &amp;lt;code&amp;gt;ns.db1&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
* Electron-phonon matrix elements (Yambo databases: &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt;; LetzElPhC databases: &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;LetzElphElectronPhononDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
The scripts of the tutorial, but not the databases, can be found in the yambopy directory:&lt;br /&gt;
 $cd tutorial/electron_phonon&lt;br /&gt;
&lt;br /&gt;
The full tutorial, including the LetzElPhC and Yambo databases that we will read, can be downloaded and extracted from the yambo website:&lt;br /&gt;
 $wget https://media.yambo-code.eu/educational/tutorials/files/electron_phonon.tar.gz&lt;br /&gt;
 $tar -xvzf electron_phonon.tar.gz&lt;br /&gt;
 $cd electron_phonon&lt;br /&gt;
&lt;br /&gt;
We will work with monolayer molybdenum disulphide electron-phonon data obtained on a &amp;lt;code&amp;gt;6x6x1&amp;lt;/code&amp;gt; kpoint grid, including spin-orbit interaction (so we deal with electron-phonon coupling and spinorial wavefunctions). Beware that the parameters are most certainly not converged.&lt;br /&gt;
&lt;br /&gt;
=== Command line: electron-phonon calculation and databases [OPTIONAL] ===&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&#039;&#039;&#039;Note&#039;&#039;&#039;: you can run this step only if you have compiled &#039;&#039;&#039;LetzElPhC&#039;&#039;&#039; and &#039;&#039;&#039;Quantum ESPRESSO&#039;&#039;&#039; on your machine. If not, please skip to the following sections of the tutorial, as the electron-phonon coupling databases are already provided in the .tar.gz file and you don&#039;t need to explicitly recalculate them.&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you run this step, please enter the directory&lt;br /&gt;
&lt;br /&gt;
 $cd databases&lt;br /&gt;
&lt;br /&gt;
Here you will find:&lt;br /&gt;
* A scf input file for MoS2, &amp;lt;code&amp;gt;scf/mos2.scf&amp;lt;/code&amp;gt;&lt;br /&gt;
* A dvscf input file for MoS2, &amp;lt;code&amp;gt;dvscf/mos2.dvscf&amp;lt;/code&amp;gt;&lt;br /&gt;
* A Yambo &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory corresponding to a nscf calculation (this has been run already).&lt;br /&gt;
* The pseudopotential files to be used for the calculation.&lt;br /&gt;
&lt;br /&gt;
As a first step, you need to run the Quantum ESPRESSO calculations (it is assumed that you are familiar with this). First run the scf calculation inside &amp;lt;code&amp;gt;scf&amp;lt;/code&amp;gt;, then copy the &amp;lt;code&amp;gt;mos2.save&amp;lt;/code&amp;gt; directory into the &amp;lt;code&amp;gt;dvscf&amp;lt;/code&amp;gt; folder and run the dvscf calculation there. When everything is completed correctly, you will have achieved step 1. above.&lt;br /&gt;
&lt;br /&gt;
Now, you will find the phonon results in the &amp;lt;code&amp;gt;dvscf&amp;lt;/code&amp;gt; directory. We also have done a non-self-consistent calculation to be used in Yambo, and created the relative &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory. If you check this directory, you will find the &amp;lt;code&amp;gt;ns.wf&amp;lt;/code&amp;gt; databases containing the electronic wavefunctions.&lt;br /&gt;
 &lt;br /&gt;
Now, we aim to reconstruct the electron-phonon coupling matrix elements from the phonon energies, modes and potential variations (in &amp;lt;code&amp;gt;dvscf&amp;lt;/code&amp;gt;) and the Bloch electronic wavefunctions used by Yambo (in &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
In order to do this, we will run the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable of the &#039;&#039;&#039;LetzElPhC&#039;&#039;&#039; code (this will be step 2. from above). We will run via command line using yambopy, although it will be instructive to have look at the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; input files later.&lt;br /&gt;
&lt;br /&gt;
We run in the same directory where the Yambo &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; is (remember than you can also virtually move it with a symbolic link).&lt;br /&gt;
&lt;br /&gt;
Type:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y&lt;br /&gt;
&lt;br /&gt;
to see the help for the calculation. Have a look at the various flags and their description.&lt;br /&gt;
For example, if we want to do a serial run of LetzElPhC for bands from &amp;lt;math&amp;gt;n_i&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;n_f&amp;lt;/math&amp;gt;, we should type:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph path/of/ph_input.in -b n_i n_f&lt;br /&gt;
&lt;br /&gt;
Here &amp;lt;math&amp;gt;n_i&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;n_f&amp;lt;/math&amp;gt; are integers representing the initial and final band indices. &#039;&#039;&#039;Please note&#039;&#039;&#039;: in this case, the band index starts from 1 and the the interval of bands read by the code is &amp;lt;math&amp;gt;[n_i,n_f]&amp;lt;/math&amp;gt; including the extrema of the interval. &lt;br /&gt;
&lt;br /&gt;
For our system, we want to do a parallel calculation: 4 MPI tasks on q-point loop (phonon momenta) and 2 MPI tasks on the k-point loop (electron momenta). In addition, we want to explicitly specify the path of the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable. &lt;br /&gt;
&lt;br /&gt;
We have a final choice to make. We can ask Yambopy to produce the default LetzElPhC electron-phonon databases, or to convert them in Yambo-compatible format. By the default, both will be printed. &lt;br /&gt;
&lt;br /&gt;
* If you don&#039;t need the Yambo-style &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases you can run &amp;lt;code&amp;gt;yambopy l2y ...&amp;lt;/code&amp;gt; with the &amp;lt;code&amp;gt;--no_gkkp&amp;lt;/code&amp;gt; option.&lt;br /&gt;
* If you don&#039;t need the default &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; databases you can run &amp;lt;code&amp;gt;yambopy l2y ...&amp;lt;/code&amp;gt; with the &amp;lt;code&amp;gt;--no_lelphc_dbs&amp;lt;/code&amp;gt; option.&lt;br /&gt;
&lt;br /&gt;
However, for this tutorial, we will take a look at both databases, so let&#039;s run:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph dvscf/mos2.dvscf -b 25 28 -par 4 2 -lelphc path/to/lelphc_exe&lt;br /&gt;
&lt;br /&gt;
We include the last two valence bands of monolayer MoS2 (25 and 26) and the first two conduction bands (27 and 28). If your &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable is in the &amp;lt;code&amp;gt;PATH&amp;lt;/code&amp;gt;, you do not need to specify the last flag.&lt;br /&gt;
&lt;br /&gt;
At the end, check your directory: you should find the &amp;lt;code&amp;gt;lelphc.in&amp;lt;/code&amp;gt; input file that was run, let&#039;s inspect it: &lt;br /&gt;
&lt;br /&gt;
 # LetzElPhC input for yambo generated by yambopy&lt;br /&gt;
 nqpool      = 2&lt;br /&gt;
 nkpool      = 4&lt;br /&gt;
 start_bnd   = 25&lt;br /&gt;
 end_bnd     = 28&lt;br /&gt;
 save_dir    = ./SAVE&lt;br /&gt;
 kernel      = dfpt&lt;br /&gt;
 ph_save_dir = dvscf/ph_save&lt;br /&gt;
 convention = yambo&lt;br /&gt;
&lt;br /&gt;
Notice the variable &amp;lt;code&amp;gt;convention=yambo&amp;lt;/code&amp;gt;: what does it mean? At variance with QE and many other codes, Yambo uses the &amp;quot;backward&amp;quot; momentum transfer convention for electronic scatterings. That is, an electronic transition goes from band &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; and momentum &amp;lt;math&amp;gt;k-q&amp;lt;/math&amp;gt; to band &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; and momentum &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;. In the &amp;quot;forward&amp;quot; momentum transfer convention (the more standard one), the transitions go from &amp;lt;math&amp;gt;nk&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;mk+q&amp;lt;/math&amp;gt;. Therefore, this variable ensures that the electron-phonon coupling matrix elements are computed as &amp;lt;math&amp;gt;\langle mk|dV|nk-q\rangle&amp;lt;/math&amp;gt;. However, do not worry: Yambopy can automatically switch between the two conventions when loading the LetzElPhC databases.&lt;br /&gt;
&lt;br /&gt;
You will also find a &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; database that contains the computed electron-phonon matrix elements, in the output format of &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In addition, if you check the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; folder:&lt;br /&gt;
&lt;br /&gt;
 ls SAVE/ndb.elph_gkkp*&lt;br /&gt;
&lt;br /&gt;
you will see that yambopy has created the Yambo-compatible electron-phonon databases and placed them inside the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If you want to run LetzElPhC directly, without using yambopy, you can refer to its [[https://gitlab.com/lumen-code/LetzElPhC/-/blob/main/docs/main.pdf?ref_type=heads|user guide]].&lt;br /&gt;
Keep in mind that in this case, in order to convert the database to the &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases of Yambo, you will then need a couple of lines of python using the Yambopy class &amp;lt;code&amp;gt;ConvertElectronPhononDB&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;yambopy/letzelph_interface/lelph2y.py&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
At the end of this section, you should have produced the same databases that you find in the main &amp;lt;code&amp;gt;electron_phonon&amp;lt;/code&amp;gt; folder. You can run the following part either in the directory where you are (by copying the python scripts here), or by going back:&lt;br /&gt;
&lt;br /&gt;
 $cd ..&lt;br /&gt;
&lt;br /&gt;
and using the precomputed ones.&lt;br /&gt;
&lt;br /&gt;
=== Electron-phonon intro: plots of el-ph matrix elements on k-BZ and q-BZ ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; and read the electron-phonon databases that you generated in the previous section.&lt;br /&gt;
&lt;br /&gt;
In order to read the &amp;lt;code&amp;gt;ndb.elph_gkkp_expanded*&amp;lt;/code&amp;gt; databases in python we use the Yambopy class &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
 elph = YamboElectronPhononDB(ylat,folder_gkkp=&#039;path/to/elph/folder&#039;,save=&#039;path/to/SAVE&#039;)&lt;br /&gt;
(notice that it requires a previous instance of &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Instead, in order to read the &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; databases from LetzElPhC, we use a different class:&lt;br /&gt;
 elph = LetzElphElectronPhononDB(&#039;path/to/ndb.elph&#039;)&lt;br /&gt;
&lt;br /&gt;
Now, the &amp;lt;code&amp;gt;elph&amp;lt;/code&amp;gt; objects contain phonon frequencies, phonon eigenvectors, q-point information and, of course, the electron-phonon matrix elements &amp;lt;math&amp;gt;g_{nm\nu}(k,q)&amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; are electron band states, &amp;lt;math&amp;gt;\nu&amp;lt;/math&amp;gt; is a phonon branch, and &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; are the electronic and transfer momenta.&lt;br /&gt;
&lt;br /&gt;
We can print the docstring of the &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt; class with&lt;br /&gt;
 print(yelph.__doc__)&lt;br /&gt;
and of the &amp;lt;code&amp;gt;LetzElphElectronPhononDB&amp;lt;/code&amp;gt; class with&lt;br /&gt;
 print(lelph.__doc__)&lt;br /&gt;
to get an idea of the information stored and of their capabilities.&lt;br /&gt;
&lt;br /&gt;
Now check the &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; script. You will see that after loading the database, it first postprocesses the electron-phonon data to obtain a plottable quantity.&lt;br /&gt;
In practice, we set a phonon mode (the eighth mode, this is the branch with symmetry &amp;lt;math&amp;gt;A_1^\prime&amp;lt;/math&amp;gt; at zone center) and either a &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; point to keep fixed (in each case, we select the high-symmetry &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; point). As for the bands, we consider the top two valence bands. These are mostly degenerate, except around the points &amp;lt;math&amp;gt;K&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;K^\prime&amp;lt;/math&amp;gt; where they are split by spin-orbit interaction. We then average over these states before plotting, obtaining the quantity:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; I^{\mu}_{&amp;lt;v&amp;gt;q}(\mathbf{k}) = \sqrt{\sum_{v,v^\prime=24,25}|g^{\mu}_{vv^\prime q}(\mathbf{k})|^2}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 performs two plots: &lt;br /&gt;
* Plot of |g(k)| in the k-BZ for selected n,m,\nu and q [&amp;lt;code&amp;gt;Kspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Plot of |g(q)| in the q-BZ for selected n,m,\nu and k [&amp;lt;code&amp;gt;Qspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
You can change the electronic, phononic and momentum indices to see what happens.&lt;br /&gt;
&lt;br /&gt;
[[File:Elph hbn.jpg|YamboElectronPhononDB plot from yambopy tutorial|500px]]&lt;/div&gt;</summary>
		<author><name>FulvioPaleari</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_electron-phonon_coupling&amp;diff=9327</id>
		<title>Yambopy tutorial: electron-phonon coupling</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_electron-phonon_coupling&amp;diff=9327"/>
		<updated>2026-03-10T13:30:59Z</updated>

		<summary type="html">&lt;p&gt;FulvioPaleari: /* Electron-phonon intro: plots of el-ph matrix elements on k-BZ and q-BZ */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial we will cover the handling of electron-phonon coupling matrix elements by Yambopy. The electron-phonon calculation follows two steps:&lt;br /&gt;
&lt;br /&gt;
# Quantum Espresso calculation of phonon energies, eigenmodes and variations of the self-consistent potential via &amp;lt;code&amp;gt;ph.x&amp;lt;/code&amp;gt;.&lt;br /&gt;
# Electron-phonon matrix element calculation, symmetry expansion and conversion by the &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For more information on the &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; code and how you should run step 1., please see the related documentation [https://github.com/yambo-code/LetzElPhC here].&lt;br /&gt;
&lt;br /&gt;
We can use Yambopy to:&lt;br /&gt;
* Run &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; (both preprocessing and main run) without explicitly writing an input file.&lt;br /&gt;
* Convert the resulting databases into &amp;lt;code&amp;gt;Yambo&amp;lt;/code&amp;gt; format.&lt;br /&gt;
* Analyse the electron-phonon coupling both in &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;Yambo&amp;lt;/code&amp;gt; format.&lt;br /&gt;
&lt;br /&gt;
In particular we will take a look at:&lt;br /&gt;
* Lattice geometry data (Yambo database: &amp;lt;code&amp;gt;ns.db1&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
* Electron-phonon matrix elements (Yambo databases: &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt;; LetzElPhC databases: &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;LetzElphElectronPhononDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
The scripts of the tutorial, but not the databases, can be found in the yambopy directory:&lt;br /&gt;
 $cd tutorial/electron_phonon&lt;br /&gt;
&lt;br /&gt;
The full tutorial, including the LetzElPhC and Yambo databases that we will read, can be downloaded and extracted from the yambo website:&lt;br /&gt;
 $wget https://media.yambo-code.eu/educational/tutorials/files/electron_phonon.tar.gz&lt;br /&gt;
 $tar -xvzf electron_phonon.tar.gz&lt;br /&gt;
 $cd electron_phonon&lt;br /&gt;
&lt;br /&gt;
We will work with monolayer molybdenum disulphide electron-phonon data obtained on a &amp;lt;code&amp;gt;6x6x1&amp;lt;/code&amp;gt; kpoint grid, including spin-orbit interaction (so we deal with electron-phonon coupling and spinorial wavefunctions). Beware that the parameters are most certainly not converged.&lt;br /&gt;
&lt;br /&gt;
=== Command line: electron-phonon calculation and databases [OPTIONAL] ===&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&#039;&#039;&#039;Note&#039;&#039;&#039;: you can run this step only if you have compiled &#039;&#039;&#039;LetzElPhC&#039;&#039;&#039; and &#039;&#039;&#039;Quantum ESPRESSO&#039;&#039;&#039; on your machine. If not, please skip to the following sections of the tutorial, as the electron-phonon coupling databases are already provided in the .tar.gz file and you don&#039;t need to explicitly recalculate them.&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you run this step, please enter the directory&lt;br /&gt;
&lt;br /&gt;
 $cd databases&lt;br /&gt;
&lt;br /&gt;
Here you will find:&lt;br /&gt;
* A scf input file for MoS2, &amp;lt;code&amp;gt;scf/mos2.scf&amp;lt;/code&amp;gt;&lt;br /&gt;
* A dvscf input file for MoS2, &amp;lt;code&amp;gt;dvscf/mos2.dvscf&amp;lt;/code&amp;gt;&lt;br /&gt;
* A Yambo &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory corresponding to a nscf calculation (this has been run already).&lt;br /&gt;
* The pseudopotential files to be used for the calculation.&lt;br /&gt;
&lt;br /&gt;
As a first step, you need to run the Quantum ESPRESSO calculations (it is assumed that you are familiar with this). First run the scf calculation inside &amp;lt;code&amp;gt;scf&amp;lt;/code&amp;gt;, then copy the &amp;lt;code&amp;gt;mos2.save&amp;lt;/code&amp;gt; directory into the &amp;lt;code&amp;gt;dvscf&amp;lt;/code&amp;gt; folder and run the dvscf calculation there. When everything is completed correctly, you will have achieved step 1. above.&lt;br /&gt;
&lt;br /&gt;
Now, you will find the phonon results in the &amp;lt;code&amp;gt;dvscf&amp;lt;/code&amp;gt; directory. We also have done a non-self-consistent calculation to be used in Yambo, and created the relative &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory. If you check this directory, you will find the &amp;lt;code&amp;gt;ns.wf&amp;lt;/code&amp;gt; databases containing the electronic wavefunctions.&lt;br /&gt;
 &lt;br /&gt;
Now, we aim to reconstruct the electron-phonon coupling matrix elements from the phonon energies, modes and potential variations (in &amp;lt;code&amp;gt;dvscf&amp;lt;/code&amp;gt;) and the Bloch electronic wavefunctions used by Yambo (in &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
In order to do this, we will run the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable of the &#039;&#039;&#039;LetzElPhC&#039;&#039;&#039; code (this will be step 2. from above). We will run via command line using yambopy, although it will be instructive to have look at the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; input files later.&lt;br /&gt;
&lt;br /&gt;
We run in the same directory where the Yambo &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; is (remember than you can also virtually move it with a symbolic link).&lt;br /&gt;
&lt;br /&gt;
Type:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y&lt;br /&gt;
&lt;br /&gt;
to see the help for the calculation. Have a look at the various flags and their description.&lt;br /&gt;
For example, if we want to do a serial run of LetzElPhC for bands from &amp;lt;math&amp;gt;n_i&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;n_f&amp;lt;/math&amp;gt;, we should type:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph path/of/ph_input.in -b n_i n_f&lt;br /&gt;
&lt;br /&gt;
Here &amp;lt;math&amp;gt;n_i&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;n_f&amp;lt;/math&amp;gt; are integers representing the initial and final band indices. &#039;&#039;&#039;Please note&#039;&#039;&#039;: in this case, the band index starts from 1 and the the interval of bands read by the code is &amp;lt;math&amp;gt;[n_i,n_f]&amp;lt;/math&amp;gt; including the extrema of the interval. &lt;br /&gt;
&lt;br /&gt;
For our system, we want to do a parallel calculation: 4 MPI tasks on q-point loop (phonon momenta) and 2 MPI tasks on the k-point loop (electron momenta). In addition, we want to explicitly specify the path of the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable. &lt;br /&gt;
&lt;br /&gt;
We have a final choice to make. We can ask Yambopy to produce the default LetzElPhC electron-phonon databases, or to convert them in Yambo-compatible format. By the default, both will be printed. &lt;br /&gt;
&lt;br /&gt;
* If you don&#039;t need the Yambo-style &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases you can run &amp;lt;code&amp;gt;yambopy l2y ...&amp;lt;/code&amp;gt; with the &amp;lt;code&amp;gt;--no_gkkp&amp;lt;/code&amp;gt; option.&lt;br /&gt;
* If you don&#039;t need the default &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; databases you can run &amp;lt;code&amp;gt;yambopy l2y ...&amp;lt;/code&amp;gt; with the &amp;lt;code&amp;gt;--no_lelphc_dbs&amp;lt;/code&amp;gt; option.&lt;br /&gt;
&lt;br /&gt;
However, for this tutorial, we will take a look at both databases, so let&#039;s run:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph dvscf/mos2.dvscf -b 25 28 -par 4 2 -lelphc path/to/lelphc_exe&lt;br /&gt;
&lt;br /&gt;
We include the last two valence bands of monolayer MoS2 (25 and 26) and the first two conduction bands (27 and 28). If your &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable is in the &amp;lt;code&amp;gt;PATH&amp;lt;/code&amp;gt;, you do not need to specify the last flag.&lt;br /&gt;
&lt;br /&gt;
At the end, check your directory: you should find the &amp;lt;code&amp;gt;lelphc.in&amp;lt;/code&amp;gt; input file that was run, let&#039;s inspect it: &lt;br /&gt;
&lt;br /&gt;
 # LetzElPhC input for yambo generated by yambopy&lt;br /&gt;
 nqpool      = 2&lt;br /&gt;
 nkpool      = 4&lt;br /&gt;
 start_bnd   = 25&lt;br /&gt;
 end_bnd     = 28&lt;br /&gt;
 save_dir    = ./SAVE&lt;br /&gt;
 kernel      = dfpt&lt;br /&gt;
 ph_save_dir = dvscf/ph_save&lt;br /&gt;
 convention = yambo&lt;br /&gt;
&lt;br /&gt;
Notice the variable &amp;lt;code&amp;gt;convention=yambo&amp;lt;/code&amp;gt;: what does it mean? At variance with QE and many other codes, Yambo uses the &amp;quot;backward&amp;quot; momentum transfer convention for electronic scatterings. That is, an electronic transition goes from band &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; and momentum &amp;lt;math&amp;gt;k-q&amp;lt;/math&amp;gt; to band &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; and momentum &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;. In the &amp;quot;forward&amp;quot; momentum transfer convention (the more standard one), the transitions go from &amp;lt;math&amp;gt;nk&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;mk+q&amp;lt;/math&amp;gt;. Therefore, this variable ensures that the electron-phonon coupling matrix elements are computed as &amp;lt;math&amp;gt;\langle mk|dV|nk-q\rangle&amp;lt;/math&amp;gt;. However, do not worry: Yambopy can automatically switch between the two conventions when loading the LetzElPhC databases.&lt;br /&gt;
&lt;br /&gt;
You will also find a &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; database that contains the computed electron-phonon matrix elements, in the output format of &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In addition, if you check the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; folder:&lt;br /&gt;
&lt;br /&gt;
 ls SAVE/ndb.elph_gkkp*&lt;br /&gt;
&lt;br /&gt;
you will see that yambopy has created the Yambo-compatible electron-phonon databases and placed them inside the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If you want to run LetzElPhC directly, without using yambopy, you can refer to its [[https://gitlab.com/lumen-code/LetzElPhC/-/blob/main/docs/main.pdf?ref_type=heads|user guide]].&lt;br /&gt;
Keep in mind that in this case, in order to convert the database to the &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases of Yambo, you will then need a couple of lines of python using the Yambopy class &amp;lt;code&amp;gt;ConvertElectronPhononDB&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;yambopy/letzelph_interface/lelph2y.py&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
At the end of this section, you should have produced the same databases that you find in the main &amp;lt;code&amp;gt;electron_phonon&amp;lt;/code&amp;gt; folder. You can run the following part either in the directory where you are (by copying the python scripts here), or by going back:&lt;br /&gt;
&lt;br /&gt;
 $cd ..&lt;br /&gt;
&lt;br /&gt;
and using the precomputed ones.&lt;br /&gt;
&lt;br /&gt;
=== Electron-phonon intro: plots of el-ph matrix elements on k-BZ and q-BZ ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; and read the electron-phonon databases that you generated in the previous section.&lt;br /&gt;
&lt;br /&gt;
In order to read the &amp;lt;code&amp;gt;ndb.elph_gkkp_expanded*&amp;lt;/code&amp;gt; databases in python we use the Yambopy class &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
 elph = YamboElectronPhononDB(ylat,folder_gkkp=&#039;path/to/elph/folder&#039;,save=&#039;path/to/SAVE&#039;)&lt;br /&gt;
(notice that it requires a previous instance of &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Instead, in order to read the &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; databases from LetzElPhC, we use a different class:&lt;br /&gt;
 elph = LetzElphElectronPhononDB(&#039;path/to/ndb.elph&#039;)&lt;br /&gt;
&lt;br /&gt;
Now, the &amp;lt;code&amp;gt;elph&amp;lt;/code&amp;gt; objects contain phonon frequencies, phonon eigenvectors, q-point information and, of course, the electron-phonon matrix elements &amp;lt;math&amp;gt;g_{nm\nu}(k,q)&amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; are electron band states, &amp;lt;math&amp;gt;\nu&amp;lt;/math&amp;gt; is a phonon branch, and &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; are the electronic and transfer momenta.&lt;br /&gt;
&lt;br /&gt;
We can print the docstring of the &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt; class with&lt;br /&gt;
 print(yelph.__doc__)&lt;br /&gt;
and of the &amp;lt;code&amp;gt;LetzElphElectronPhononDB&amp;lt;/code&amp;gt; class with&lt;br /&gt;
 print(lelph.__doc__)&lt;br /&gt;
to get an idea of the information stored and of their capabilities.&lt;br /&gt;
&lt;br /&gt;
Now check the &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; script. You will see that it performs two plots: &lt;br /&gt;
* Plot of |g(k)| in the k-BZ for selected n,m,\nu and q [&amp;lt;code&amp;gt;Kspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Plot of |g(q)| in the q-BZ for selected n,m,\nu and k [&amp;lt;code&amp;gt;Qspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
You can change the electronic, phononic and momentum indices to see what happens.&lt;br /&gt;
&lt;br /&gt;
[[File:Elph hbn.jpg|YamboElectronPhononDB plot from yambopy tutorial|500px]]&lt;/div&gt;</summary>
		<author><name>FulvioPaleari</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_electron-phonon_coupling&amp;diff=9326</id>
		<title>Yambopy tutorial: electron-phonon coupling</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_electron-phonon_coupling&amp;diff=9326"/>
		<updated>2026-03-10T13:15:33Z</updated>

		<summary type="html">&lt;p&gt;FulvioPaleari: /* Command line: electron-phonon calculation and databases [OPTIONAL] */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial we will cover the handling of electron-phonon coupling matrix elements by Yambopy. The electron-phonon calculation follows two steps:&lt;br /&gt;
&lt;br /&gt;
# Quantum Espresso calculation of phonon energies, eigenmodes and variations of the self-consistent potential via &amp;lt;code&amp;gt;ph.x&amp;lt;/code&amp;gt;.&lt;br /&gt;
# Electron-phonon matrix element calculation, symmetry expansion and conversion by the &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For more information on the &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; code and how you should run step 1., please see the related documentation [https://github.com/yambo-code/LetzElPhC here].&lt;br /&gt;
&lt;br /&gt;
We can use Yambopy to:&lt;br /&gt;
* Run &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; (both preprocessing and main run) without explicitly writing an input file.&lt;br /&gt;
* Convert the resulting databases into &amp;lt;code&amp;gt;Yambo&amp;lt;/code&amp;gt; format.&lt;br /&gt;
* Analyse the electron-phonon coupling both in &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;Yambo&amp;lt;/code&amp;gt; format.&lt;br /&gt;
&lt;br /&gt;
In particular we will take a look at:&lt;br /&gt;
* Lattice geometry data (Yambo database: &amp;lt;code&amp;gt;ns.db1&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
* Electron-phonon matrix elements (Yambo databases: &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt;; LetzElPhC databases: &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;LetzElphElectronPhononDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
The scripts of the tutorial, but not the databases, can be found in the yambopy directory:&lt;br /&gt;
 $cd tutorial/electron_phonon&lt;br /&gt;
&lt;br /&gt;
The full tutorial, including the LetzElPhC and Yambo databases that we will read, can be downloaded and extracted from the yambo website:&lt;br /&gt;
 $wget https://media.yambo-code.eu/educational/tutorials/files/electron_phonon.tar.gz&lt;br /&gt;
 $tar -xvzf electron_phonon.tar.gz&lt;br /&gt;
 $cd electron_phonon&lt;br /&gt;
&lt;br /&gt;
We will work with monolayer molybdenum disulphide electron-phonon data obtained on a &amp;lt;code&amp;gt;6x6x1&amp;lt;/code&amp;gt; kpoint grid, including spin-orbit interaction (so we deal with electron-phonon coupling and spinorial wavefunctions). Beware that the parameters are most certainly not converged.&lt;br /&gt;
&lt;br /&gt;
=== Command line: electron-phonon calculation and databases [OPTIONAL] ===&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&#039;&#039;&#039;Note&#039;&#039;&#039;: you can run this step only if you have compiled &#039;&#039;&#039;LetzElPhC&#039;&#039;&#039; and &#039;&#039;&#039;Quantum ESPRESSO&#039;&#039;&#039; on your machine. If not, please skip to the following sections of the tutorial, as the electron-phonon coupling databases are already provided in the .tar.gz file and you don&#039;t need to explicitly recalculate them.&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you run this step, please enter the directory&lt;br /&gt;
&lt;br /&gt;
 $cd databases&lt;br /&gt;
&lt;br /&gt;
Here you will find:&lt;br /&gt;
* A scf input file for MoS2, &amp;lt;code&amp;gt;scf/mos2.scf&amp;lt;/code&amp;gt;&lt;br /&gt;
* A dvscf input file for MoS2, &amp;lt;code&amp;gt;dvscf/mos2.dvscf&amp;lt;/code&amp;gt;&lt;br /&gt;
* A Yambo &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory corresponding to a nscf calculation (this has been run already).&lt;br /&gt;
* The pseudopotential files to be used for the calculation.&lt;br /&gt;
&lt;br /&gt;
As a first step, you need to run the Quantum ESPRESSO calculations (it is assumed that you are familiar with this). First run the scf calculation inside &amp;lt;code&amp;gt;scf&amp;lt;/code&amp;gt;, then copy the &amp;lt;code&amp;gt;mos2.save&amp;lt;/code&amp;gt; directory into the &amp;lt;code&amp;gt;dvscf&amp;lt;/code&amp;gt; folder and run the dvscf calculation there. When everything is completed correctly, you will have achieved step 1. above.&lt;br /&gt;
&lt;br /&gt;
Now, you will find the phonon results in the &amp;lt;code&amp;gt;dvscf&amp;lt;/code&amp;gt; directory. We also have done a non-self-consistent calculation to be used in Yambo, and created the relative &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory. If you check this directory, you will find the &amp;lt;code&amp;gt;ns.wf&amp;lt;/code&amp;gt; databases containing the electronic wavefunctions.&lt;br /&gt;
 &lt;br /&gt;
Now, we aim to reconstruct the electron-phonon coupling matrix elements from the phonon energies, modes and potential variations (in &amp;lt;code&amp;gt;dvscf&amp;lt;/code&amp;gt;) and the Bloch electronic wavefunctions used by Yambo (in &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
In order to do this, we will run the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable of the &#039;&#039;&#039;LetzElPhC&#039;&#039;&#039; code (this will be step 2. from above). We will run via command line using yambopy, although it will be instructive to have look at the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; input files later.&lt;br /&gt;
&lt;br /&gt;
We run in the same directory where the Yambo &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; is (remember than you can also virtually move it with a symbolic link).&lt;br /&gt;
&lt;br /&gt;
Type:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y&lt;br /&gt;
&lt;br /&gt;
to see the help for the calculation. Have a look at the various flags and their description.&lt;br /&gt;
For example, if we want to do a serial run of LetzElPhC for bands from &amp;lt;math&amp;gt;n_i&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;n_f&amp;lt;/math&amp;gt;, we should type:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph path/of/ph_input.in -b n_i n_f&lt;br /&gt;
&lt;br /&gt;
Here &amp;lt;math&amp;gt;n_i&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;n_f&amp;lt;/math&amp;gt; are integers representing the initial and final band indices. &#039;&#039;&#039;Please note&#039;&#039;&#039;: in this case, the band index starts from 1 and the the interval of bands read by the code is &amp;lt;math&amp;gt;[n_i,n_f]&amp;lt;/math&amp;gt; including the extrema of the interval. &lt;br /&gt;
&lt;br /&gt;
For our system, we want to do a parallel calculation: 4 MPI tasks on q-point loop (phonon momenta) and 2 MPI tasks on the k-point loop (electron momenta). In addition, we want to explicitly specify the path of the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable. &lt;br /&gt;
&lt;br /&gt;
We have a final choice to make. We can ask Yambopy to produce the default LetzElPhC electron-phonon databases, or to convert them in Yambo-compatible format. By the default, both will be printed. &lt;br /&gt;
&lt;br /&gt;
* If you don&#039;t need the Yambo-style &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases you can run &amp;lt;code&amp;gt;yambopy l2y ...&amp;lt;/code&amp;gt; with the &amp;lt;code&amp;gt;--no_gkkp&amp;lt;/code&amp;gt; option.&lt;br /&gt;
* If you don&#039;t need the default &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; databases you can run &amp;lt;code&amp;gt;yambopy l2y ...&amp;lt;/code&amp;gt; with the &amp;lt;code&amp;gt;--no_lelphc_dbs&amp;lt;/code&amp;gt; option.&lt;br /&gt;
&lt;br /&gt;
However, for this tutorial, we will take a look at both databases, so let&#039;s run:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph dvscf/mos2.dvscf -b 25 28 -par 4 2 -lelphc path/to/lelphc_exe&lt;br /&gt;
&lt;br /&gt;
We include the last two valence bands of monolayer MoS2 (25 and 26) and the first two conduction bands (27 and 28). If your &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable is in the &amp;lt;code&amp;gt;PATH&amp;lt;/code&amp;gt;, you do not need to specify the last flag.&lt;br /&gt;
&lt;br /&gt;
At the end, check your directory: you should find the &amp;lt;code&amp;gt;lelphc.in&amp;lt;/code&amp;gt; input file that was run, let&#039;s inspect it: &lt;br /&gt;
&lt;br /&gt;
 # LetzElPhC input for yambo generated by yambopy&lt;br /&gt;
 nqpool      = 2&lt;br /&gt;
 nkpool      = 4&lt;br /&gt;
 start_bnd   = 25&lt;br /&gt;
 end_bnd     = 28&lt;br /&gt;
 save_dir    = ./SAVE&lt;br /&gt;
 kernel      = dfpt&lt;br /&gt;
 ph_save_dir = dvscf/ph_save&lt;br /&gt;
 convention = yambo&lt;br /&gt;
&lt;br /&gt;
Notice the variable &amp;lt;code&amp;gt;convention=yambo&amp;lt;/code&amp;gt;: what does it mean? At variance with QE and many other codes, Yambo uses the &amp;quot;backward&amp;quot; momentum transfer convention for electronic scatterings. That is, an electronic transition goes from band &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; and momentum &amp;lt;math&amp;gt;k-q&amp;lt;/math&amp;gt; to band &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; and momentum &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;. In the &amp;quot;forward&amp;quot; momentum transfer convention (the more standard one), the transitions go from &amp;lt;math&amp;gt;nk&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;mk+q&amp;lt;/math&amp;gt;. Therefore, this variable ensures that the electron-phonon coupling matrix elements are computed as &amp;lt;math&amp;gt;\langle mk|dV|nk-q\rangle&amp;lt;/math&amp;gt;. However, do not worry: Yambopy can automatically switch between the two conventions when loading the LetzElPhC databases.&lt;br /&gt;
&lt;br /&gt;
You will also find a &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; database that contains the computed electron-phonon matrix elements, in the output format of &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In addition, if you check the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; folder:&lt;br /&gt;
&lt;br /&gt;
 ls SAVE/ndb.elph_gkkp*&lt;br /&gt;
&lt;br /&gt;
you will see that yambopy has created the Yambo-compatible electron-phonon databases and placed them inside the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If you want to run LetzElPhC directly, without using yambopy, you can refer to its [[https://gitlab.com/lumen-code/LetzElPhC/-/blob/main/docs/main.pdf?ref_type=heads|user guide]].&lt;br /&gt;
Keep in mind that in this case, in order to convert the database to the &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases of Yambo, you will then need a couple of lines of python using the Yambopy class &amp;lt;code&amp;gt;ConvertElectronPhononDB&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;yambopy/letzelph_interface/lelph2y.py&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
At the end of this section, you should have produced the same databases that you find in the main &amp;lt;code&amp;gt;electron_phonon&amp;lt;/code&amp;gt; folder. You can run the following part either in the directory where you are (by copying the python scripts here), or by going back:&lt;br /&gt;
&lt;br /&gt;
 $cd ..&lt;br /&gt;
&lt;br /&gt;
and using the precomputed ones.&lt;br /&gt;
&lt;br /&gt;
=== Electron-phonon intro: plots of el-ph matrix elements on k-BZ and q-BZ ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; and read the electron-phonon databases that you generated in the previous section.&lt;br /&gt;
&lt;br /&gt;
In order to read the &amp;lt;code&amp;gt;ndb.elph_gkkp_expanded*&amp;lt;/code&amp;gt; databases in python we use the Yambopy class &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
 yelph = YamboElectronPhononDB(ylat,folder_gkkp=&#039;path/to/elph/folder&#039;,save=&#039;path/to/SAVE&#039;)&lt;br /&gt;
(notice that it requires a previous instance of &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Instead, in order to read the &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; databases from LetzElPhC, we use a different class:&lt;br /&gt;
 lelph = LetzElphElectronPhononDB(&#039;path/to/ndb.elph&#039;)&lt;br /&gt;
&lt;br /&gt;
Now, the &amp;lt;code&amp;gt;*elph&amp;lt;/code&amp;gt; objects contain phonon frequencies, phonon eigenvectors, q-point information and, of course, the electron-phonon matrix elements &amp;lt;math&amp;gt;g_{nm\nu}(k,q)&amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; are electron band states, &amp;lt;math&amp;gt;\nu&amp;lt;/math&amp;gt; is a phonon branch, and &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; are the electronic and transfer momenta.&lt;br /&gt;
&lt;br /&gt;
We can print the docstring of the &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt; class with&lt;br /&gt;
 print(yelph.__doc__)&lt;br /&gt;
and of the &amp;lt;code&amp;gt;LetzElphElectronPhononDB&amp;lt;/code&amp;gt; class with&lt;br /&gt;
 print(lelph.__doc__)&lt;br /&gt;
to get an idea of the information stored and of their capabilities.&lt;br /&gt;
&lt;br /&gt;
Now check the &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; script. You will see that it performs two plots: &lt;br /&gt;
* Plot of |g(k)| in the k-BZ for selected n,m,\nu and q [&amp;lt;code&amp;gt;Kspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Plot of |g(q)| in the q-BZ for selected n,m,\nu and k [&amp;lt;code&amp;gt;Qspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
You can change the electronic, phononic and momentum indices to see what happens.&lt;br /&gt;
&lt;br /&gt;
[[File:Elph hbn.jpg|YamboElectronPhononDB plot from yambopy tutorial|500px]]&lt;/div&gt;</summary>
		<author><name>FulvioPaleari</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_electron-phonon_coupling&amp;diff=9325</id>
		<title>Yambopy tutorial: electron-phonon coupling</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_electron-phonon_coupling&amp;diff=9325"/>
		<updated>2026-03-10T13:14:05Z</updated>

		<summary type="html">&lt;p&gt;FulvioPaleari: /* Command line: electron-phonon calculation and databases [OPTIONAL] */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial we will cover the handling of electron-phonon coupling matrix elements by Yambopy. The electron-phonon calculation follows two steps:&lt;br /&gt;
&lt;br /&gt;
# Quantum Espresso calculation of phonon energies, eigenmodes and variations of the self-consistent potential via &amp;lt;code&amp;gt;ph.x&amp;lt;/code&amp;gt;.&lt;br /&gt;
# Electron-phonon matrix element calculation, symmetry expansion and conversion by the &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For more information on the &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; code and how you should run step 1., please see the related documentation [https://github.com/yambo-code/LetzElPhC here].&lt;br /&gt;
&lt;br /&gt;
We can use Yambopy to:&lt;br /&gt;
* Run &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; (both preprocessing and main run) without explicitly writing an input file.&lt;br /&gt;
* Convert the resulting databases into &amp;lt;code&amp;gt;Yambo&amp;lt;/code&amp;gt; format.&lt;br /&gt;
* Analyse the electron-phonon coupling both in &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;Yambo&amp;lt;/code&amp;gt; format.&lt;br /&gt;
&lt;br /&gt;
In particular we will take a look at:&lt;br /&gt;
* Lattice geometry data (Yambo database: &amp;lt;code&amp;gt;ns.db1&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
* Electron-phonon matrix elements (Yambo databases: &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt;; LetzElPhC databases: &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;LetzElphElectronPhononDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
The scripts of the tutorial, but not the databases, can be found in the yambopy directory:&lt;br /&gt;
 $cd tutorial/electron_phonon&lt;br /&gt;
&lt;br /&gt;
The full tutorial, including the LetzElPhC and Yambo databases that we will read, can be downloaded and extracted from the yambo website:&lt;br /&gt;
 $wget https://media.yambo-code.eu/educational/tutorials/files/electron_phonon.tar.gz&lt;br /&gt;
 $tar -xvzf electron_phonon.tar.gz&lt;br /&gt;
 $cd electron_phonon&lt;br /&gt;
&lt;br /&gt;
We will work with monolayer molybdenum disulphide electron-phonon data obtained on a &amp;lt;code&amp;gt;6x6x1&amp;lt;/code&amp;gt; kpoint grid, including spin-orbit interaction (so we deal with electron-phonon coupling and spinorial wavefunctions). Beware that the parameters are most certainly not converged.&lt;br /&gt;
&lt;br /&gt;
=== Command line: electron-phonon calculation and databases [OPTIONAL] ===&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&#039;&#039;&#039;Note&#039;&#039;&#039;: you can run this step only if you have compiled &#039;&#039;&#039;LetzElPhC&#039;&#039;&#039; and &#039;&#039;&#039;Quantum ESPRESSO&#039;&#039;&#039; on your machine. If not, please skip to the following sections of the tutorial, as the electron-phonon coupling databases are already provided in the .tar.gz file and you don&#039;t need to explicitly recalculate them.&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you run this step, please enter the directory&lt;br /&gt;
&lt;br /&gt;
 $cd databases&lt;br /&gt;
&lt;br /&gt;
Here you will find:&lt;br /&gt;
* A scf input file for MoS2, &amp;lt;code&amp;gt;scf/mos2.scf&amp;lt;/code&amp;gt;&lt;br /&gt;
* A dvscf input file for MoS2, &amp;lt;code&amp;gt;dvscf/mos2.dvscf&amp;lt;/code&amp;gt;&lt;br /&gt;
* A Yambo &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory corresponding to a nscf calculation (this has been run already).&lt;br /&gt;
* The pseudopotential files to be used for the calculation.&lt;br /&gt;
&lt;br /&gt;
As a first step, you need to run the Quantum ESPRESSO calculations (it is assumed that you are familiar with this). First run the scf calculation inside &amp;lt;code&amp;gt;scf&amp;lt;/code&amp;gt;, then copy the &amp;lt;code&amp;gt;mos2.save&amp;lt;/code&amp;gt; directory into the &amp;lt;code&amp;gt;dvscf&amp;lt;/code&amp;gt; folder and run the dvscf calculation there. When everything is completed correctly, you will have achieved step 1. above.&lt;br /&gt;
&lt;br /&gt;
Now, you will find the phonon results in the &amp;lt;code&amp;gt;dvscf&amp;lt;/code&amp;gt; directory. We also have done a non-self-consistent calculation to be used in Yambo, and created the relative &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory. If you check this directory, you will find the &amp;lt;code&amp;gt;ns.wf&amp;lt;/code&amp;gt; databases containing the electronic wavefunctions.&lt;br /&gt;
 &lt;br /&gt;
Now, we aim to reconstruct the electron-phonon coupling matrix elements from the phonon energies, modes and potential variations (in &amp;lt;code&amp;gt;dvscf&amp;lt;/code&amp;gt;) and the Bloch electronic wavefunctions used by Yambo (in &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
In order to do this, we will run the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable of the &#039;&#039;&#039;LetzElPhC&#039;&#039;&#039; code (this will be step 2. from above). We will run via command line using yambopy, although it will be instructive to have look at the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; input files later.&lt;br /&gt;
&lt;br /&gt;
We run in the same directory where the Yambo &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; is (remember than you can also virtually move it with a symbolic link).&lt;br /&gt;
&lt;br /&gt;
Type:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y&lt;br /&gt;
&lt;br /&gt;
to see the help for the calculation. Have a look at the various flags and their description.&lt;br /&gt;
For example, if we want to do a serial run of LetzElPhC for bands from &amp;lt;math&amp;gt;n_i&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;n_f&amp;lt;/math&amp;gt;, we should type:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph path/of/ph_input.in -b n_i n_f&lt;br /&gt;
&lt;br /&gt;
Here &amp;lt;math&amp;gt;n_i&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;n_f&amp;lt;/math&amp;gt; are integers representing the initial and final band indices. &#039;&#039;&#039;Please note&#039;&#039;&#039;: in this case, the band index starts from 1 and the the interval of bands read by the code is &amp;lt;math&amp;gt;[n_i,n_f]&amp;lt;/math&amp;gt; including the extrema of the interval. &lt;br /&gt;
&lt;br /&gt;
For our system, we want to do a parallel calculation: 4 MPI tasks on q-point loop (phonon momenta) and 2 MPI tasks on the k-point loop (electron momenta). In addition, we want to explicitly specify the path of the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable. &lt;br /&gt;
&lt;br /&gt;
We have a final choice to make. We can ask Yambopy to produce the default LetzElPhC electron-phonon databases, or to convert them in Yambo-compatible format. By the default, both will be printed. &lt;br /&gt;
&lt;br /&gt;
* If you don&#039;t need the Yambo-style &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases you can run &amp;lt;code&amp;gt;yambopy l2y ...&amp;lt;/code&amp;gt; with the &amp;lt;code&amp;gt;--no_gkkp&amp;lt;/code&amp;gt; option.&lt;br /&gt;
* If you don&#039;t need the default &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; databases you can run &amp;lt;code&amp;gt;yambopy l2y ...&amp;lt;/code&amp;gt; with the &amp;lt;code&amp;gt;--no_lelphc_dbs&amp;lt;/code&amp;gt; option.&lt;br /&gt;
&lt;br /&gt;
However, for this tutorial, we will take a look at both databases, so let&#039;s run:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph dvscf/mos2.dvscf -b 25 28 -par 4 2 -lelphc path/to/lelphc_exe&lt;br /&gt;
&lt;br /&gt;
We include the last two valence bands of monolayer MoS2 (25 and 26) and the first two conduction bands (27 and 28). If your &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable is in the &amp;lt;code&amp;gt;PATH&amp;lt;/code&amp;gt;, you do not need to specify the last flag.&lt;br /&gt;
&lt;br /&gt;
At the end, check your directory: you should find the &amp;lt;code&amp;gt;lelphc.in&amp;lt;/code&amp;gt; input file that was run, let&#039;s inspect it: &lt;br /&gt;
&lt;br /&gt;
 # LetzElPhC input for yambo generated by yambopy&lt;br /&gt;
 nqpool      = 2&lt;br /&gt;
 nkpool      = 4&lt;br /&gt;
 start_bnd   = 25&lt;br /&gt;
 end_bnd     = 28&lt;br /&gt;
 save_dir    = ./SAVE&lt;br /&gt;
 kernel      = dfpt&lt;br /&gt;
 ph_save_dir = dvscf/ph_save&lt;br /&gt;
 convention = yambo&lt;br /&gt;
&lt;br /&gt;
Notice the variable &amp;lt;code&amp;gt;convention=yambo&amp;lt;/code&amp;gt;: what does it mean? At variance with QE and many other codes, Yambo uses the &amp;quot;backward&amp;quot; momentum transfer convention for electronic scatterings. That is, an electronic transition goes from band &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; and momentum &amp;lt;math&amp;gt;k-q&amp;lt;/math&amp;gt; to band &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; and momentum &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;. In the &amp;quot;forward&amp;quot; momentum transfer convention (the more standard one), the transitions go from &amp;lt;math&amp;gt;nk&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;mk+q&amp;lt;/math&amp;gt;. Therefore, this variable ensures that the electron-phonon coupling matrix elements are computed as &amp;lt;math&amp;gt;\langle mk|dV|nk-q\rangle&amp;lt;/math&amp;gt;. However, do not worry: Yambopy can automatically switch between the two conventions when loading the LetzElPhC databases.&lt;br /&gt;
&lt;br /&gt;
You will also find a &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; database that contains the computed electron-phonon matrix elements, in the output format of &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In addition, if you check the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; folder:&lt;br /&gt;
&lt;br /&gt;
 ls SAVE/ndb.elph_gkkp*&lt;br /&gt;
&lt;br /&gt;
you will see that yambopy has created the Yambo-compatible electron-phonon databases and placed them inside the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If you want to run LetzElPhC directly, without using yambopy, you can refer to its [[https://gitlab.com/lumen-code/LetzElPhC/-/blob/main/docs/main.pdf?ref_type=heads|user guide]].&lt;br /&gt;
Keep in mind that in this case, in order to convert the database to the &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases of Yambo, you will then need a couple of lines of python using the Yambopy class &amp;lt;code&amp;gt;ConvertElectronPhononDB&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;yambopy/letzelph_interface/lelph2y.py&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
At the end of this section, you should have produced the same databases that you find in the main &amp;lt;code&amp;gt;electron_phonon&amp;lt;/code&amp;gt; folder. You can run the following part either in the directory where you are (by copying the python scripts here), or by going back:&lt;br /&gt;
&lt;br /&gt;
 $cd ..&lt;br /&gt;
&lt;br /&gt;
and using the original ones.&lt;br /&gt;
&lt;br /&gt;
=== Electron-phonon intro: plots of el-ph matrix elements on k-BZ and q-BZ ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; and read the electron-phonon databases that you generated in the previous section.&lt;br /&gt;
&lt;br /&gt;
In order to read the &amp;lt;code&amp;gt;ndb.elph_gkkp_expanded*&amp;lt;/code&amp;gt; databases in python we use the Yambopy class &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
 yelph = YamboElectronPhononDB(ylat,folder_gkkp=&#039;path/to/elph/folder&#039;,save=&#039;path/to/SAVE&#039;)&lt;br /&gt;
(notice that it requires a previous instance of &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Instead, in order to read the &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; databases from LetzElPhC, we use a different class:&lt;br /&gt;
 lelph = LetzElphElectronPhononDB(&#039;path/to/ndb.elph&#039;)&lt;br /&gt;
&lt;br /&gt;
Now, the &amp;lt;code&amp;gt;*elph&amp;lt;/code&amp;gt; objects contain phonon frequencies, phonon eigenvectors, q-point information and, of course, the electron-phonon matrix elements &amp;lt;math&amp;gt;g_{nm\nu}(k,q)&amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; are electron band states, &amp;lt;math&amp;gt;\nu&amp;lt;/math&amp;gt; is a phonon branch, and &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; are the electronic and transfer momenta.&lt;br /&gt;
&lt;br /&gt;
We can print the docstring of the &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt; class with&lt;br /&gt;
 print(yelph.__doc__)&lt;br /&gt;
and of the &amp;lt;code&amp;gt;LetzElphElectronPhononDB&amp;lt;/code&amp;gt; class with&lt;br /&gt;
 print(lelph.__doc__)&lt;br /&gt;
to get an idea of the information stored and of their capabilities.&lt;br /&gt;
&lt;br /&gt;
Now check the &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; script. You will see that it performs two plots: &lt;br /&gt;
* Plot of |g(k)| in the k-BZ for selected n,m,\nu and q [&amp;lt;code&amp;gt;Kspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Plot of |g(q)| in the q-BZ for selected n,m,\nu and k [&amp;lt;code&amp;gt;Qspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
You can change the electronic, phononic and momentum indices to see what happens.&lt;br /&gt;
&lt;br /&gt;
[[File:Elph hbn.jpg|YamboElectronPhononDB plot from yambopy tutorial|500px]]&lt;/div&gt;</summary>
		<author><name>FulvioPaleari</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_electron-phonon_coupling&amp;diff=9324</id>
		<title>Yambopy tutorial: electron-phonon coupling</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_electron-phonon_coupling&amp;diff=9324"/>
		<updated>2026-03-10T13:13:23Z</updated>

		<summary type="html">&lt;p&gt;FulvioPaleari: /* Command line: electron-phonon calculation and databases [OPTIONAL] */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial we will cover the handling of electron-phonon coupling matrix elements by Yambopy. The electron-phonon calculation follows two steps:&lt;br /&gt;
&lt;br /&gt;
# Quantum Espresso calculation of phonon energies, eigenmodes and variations of the self-consistent potential via &amp;lt;code&amp;gt;ph.x&amp;lt;/code&amp;gt;.&lt;br /&gt;
# Electron-phonon matrix element calculation, symmetry expansion and conversion by the &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For more information on the &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; code and how you should run step 1., please see the related documentation [https://github.com/yambo-code/LetzElPhC here].&lt;br /&gt;
&lt;br /&gt;
We can use Yambopy to:&lt;br /&gt;
* Run &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; (both preprocessing and main run) without explicitly writing an input file.&lt;br /&gt;
* Convert the resulting databases into &amp;lt;code&amp;gt;Yambo&amp;lt;/code&amp;gt; format.&lt;br /&gt;
* Analyse the electron-phonon coupling both in &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;Yambo&amp;lt;/code&amp;gt; format.&lt;br /&gt;
&lt;br /&gt;
In particular we will take a look at:&lt;br /&gt;
* Lattice geometry data (Yambo database: &amp;lt;code&amp;gt;ns.db1&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
* Electron-phonon matrix elements (Yambo databases: &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt;; LetzElPhC databases: &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;LetzElphElectronPhononDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
The scripts of the tutorial, but not the databases, can be found in the yambopy directory:&lt;br /&gt;
 $cd tutorial/electron_phonon&lt;br /&gt;
&lt;br /&gt;
The full tutorial, including the LetzElPhC and Yambo databases that we will read, can be downloaded and extracted from the yambo website:&lt;br /&gt;
 $wget https://media.yambo-code.eu/educational/tutorials/files/electron_phonon.tar.gz&lt;br /&gt;
 $tar -xvzf electron_phonon.tar.gz&lt;br /&gt;
 $cd electron_phonon&lt;br /&gt;
&lt;br /&gt;
We will work with monolayer molybdenum disulphide electron-phonon data obtained on a &amp;lt;code&amp;gt;6x6x1&amp;lt;/code&amp;gt; kpoint grid, including spin-orbit interaction (so we deal with electron-phonon coupling and spinorial wavefunctions). Beware that the parameters are most certainly not converged.&lt;br /&gt;
&lt;br /&gt;
=== Command line: electron-phonon calculation and databases [OPTIONAL] ===&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&#039;&#039;&#039;Note&#039;&#039;&#039;: you can run this step only if you have compiled &#039;&#039;&#039;LetzElPhC&#039;&#039;&#039; and &#039;&#039;&#039;Quantum ESPRESSO&#039;&#039;&#039; on your machine. If not, please skip to the following sections of the tutorial, as the electron-phonon coupling databases are already provided in the .tar.gz file and you don&#039;t need to explicitly recalculate them.&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you run this step, please enter the directory&lt;br /&gt;
&lt;br /&gt;
 $cd databases&lt;br /&gt;
&lt;br /&gt;
Here you will find:&lt;br /&gt;
* A scf input file for MoS2, &amp;lt;code&amp;gt;scf/mos2.scf&amp;lt;/code&amp;gt;&lt;br /&gt;
* A dvscf input file for MoS2, &amp;lt;code&amp;gt;dvscf/mos2.dvscf&amp;lt;/code&amp;gt;&lt;br /&gt;
* A Yambo &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory corresponding to a nscf calculation (this has been run already).&lt;br /&gt;
* The pseudopotential files to be used for the calculation.&lt;br /&gt;
&lt;br /&gt;
As a first step, you need to run the Quantum ESPRESSO calculations (it is assumed that you are familiar with this). First run the scf calculation inside &amp;lt;code&amp;gt;scf&amp;lt;/code&amp;gt;, then copy the &amp;lt;code&amp;gt;mos2.save&amp;lt;/code&amp;gt; directory into the &amp;lt;code&amp;gt;dvscf&amp;lt;/code&amp;gt; folder and run the dvscf calculation there. When everything is completed correctly, you will have achieved step 1. above.&lt;br /&gt;
&lt;br /&gt;
Now, you will find the phonon results in the &amp;lt;code&amp;gt;dvscf&amp;lt;/code&amp;gt; directory. We also have done a non-self-consistent calculation to be used in Yambo, and created the relative &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory. If you check this directory, you will find the &amp;lt;code&amp;gt;ns.wf&amp;lt;/code&amp;gt; containing the electronic wavefunctions.&lt;br /&gt;
 &lt;br /&gt;
Now, we aim to reconstruct the electron-phonon coupling matrix elements from the phonon energies, modes and potential variations (in &amp;lt;code&amp;gt;dvscf&amp;lt;/code&amp;gt;) and the Bloch electronic wavefunctions used by Yambo (in &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
In order to do this, we will run the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable of the &#039;&#039;&#039;LetzElPhC&#039;&#039;&#039; code (this will be step 2. from above). We will run via command line using yambopy, although it will be instructive to have look at the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; input files later.&lt;br /&gt;
&lt;br /&gt;
We run in the same directory where the Yambo &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; is (remember than you can also virtually move it with a symbolic link).&lt;br /&gt;
&lt;br /&gt;
Type:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y&lt;br /&gt;
&lt;br /&gt;
to see the help for the calculation. Have a look at the various flags and their description.&lt;br /&gt;
For example, if we want to do a serial run of LetzElPhC for bands from &amp;lt;math&amp;gt;n_i&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;n_f&amp;lt;/math&amp;gt;, we should type:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph path/of/ph_input.in -b n_i n_f&lt;br /&gt;
&lt;br /&gt;
Here &amp;lt;math&amp;gt;n_i&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;n_f&amp;lt;/math&amp;gt; are integers representing the initial and final band indices. &#039;&#039;&#039;Please note&#039;&#039;&#039;: in this case, the band index starts from 1 and the the interval of bands read by the code is &amp;lt;math&amp;gt;[n_i,n_f]&amp;lt;/math&amp;gt; including the extrema of the interval. &lt;br /&gt;
&lt;br /&gt;
For our system, we want to do a parallel calculation: 4 MPI tasks on q-point loop (phonon momenta) and 2 MPI tasks on the k-point loop (electron momenta). In addition, we want to explicitly specify the path of the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable. &lt;br /&gt;
&lt;br /&gt;
We have a final choice to make. We can ask Yambopy to produce the default LetzElPhC electron-phonon databases, or to convert them in Yambo-compatible format. By the default, both will be printed. &lt;br /&gt;
&lt;br /&gt;
* If you don&#039;t need the Yambo-style &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases you can run &amp;lt;code&amp;gt;yambopy l2y ...&amp;lt;/code&amp;gt; with the &amp;lt;code&amp;gt;--no_gkkp&amp;lt;/code&amp;gt; option.&lt;br /&gt;
* If you don&#039;t need the default &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; databases you can run &amp;lt;code&amp;gt;yambopy l2y ...&amp;lt;/code&amp;gt; with the &amp;lt;code&amp;gt;--no_lelphc_dbs&amp;lt;/code&amp;gt; option.&lt;br /&gt;
&lt;br /&gt;
However, for this tutorial, we will take a look at both databases, so let&#039;s run:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph dvscf/mos2.dvscf -b 25 28 -par 4 2 -lelphc path/to/lelphc_exe&lt;br /&gt;
&lt;br /&gt;
We include the last two valence bands of monolayer MoS2 (25 and 26) and the first two conduction bands (27 and 28). If your &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable is in the &amp;lt;code&amp;gt;PATH&amp;lt;/code&amp;gt;, you do not need to specify the last flag.&lt;br /&gt;
&lt;br /&gt;
At the end, check your directory: you should find the &amp;lt;code&amp;gt;lelphc.in&amp;lt;/code&amp;gt; input file that was run, let&#039;s inspect it: &lt;br /&gt;
&lt;br /&gt;
 # LetzElPhC input for yambo generated by yambopy&lt;br /&gt;
 nqpool      = 2&lt;br /&gt;
 nkpool      = 4&lt;br /&gt;
 start_bnd   = 25&lt;br /&gt;
 end_bnd     = 28&lt;br /&gt;
 save_dir    = ./SAVE&lt;br /&gt;
 kernel      = dfpt&lt;br /&gt;
 ph_save_dir = dvscf/ph_save&lt;br /&gt;
 convention = yambo&lt;br /&gt;
&lt;br /&gt;
Notice the variable &amp;lt;code&amp;gt;convention=yambo&amp;lt;/code&amp;gt;: what does it mean? At variance with QE and many other codes, Yambo uses the &amp;quot;backward&amp;quot; momentum transfer convention for electronic scatterings. That is, an electronic transition goes from band &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; and momentum &amp;lt;math&amp;gt;k-q&amp;lt;/math&amp;gt; to band &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; and momentum &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;. In the &amp;quot;forward&amp;quot; momentum transfer convention (the more standard one), the transitions go from &amp;lt;math&amp;gt;nk&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;mk+q&amp;lt;/math&amp;gt;. Therefore, this variable ensures that the electron-phonon coupling matrix elements are computed as &amp;lt;math&amp;gt;\langle mk|dV|nk-q\rangle&amp;lt;/math&amp;gt;. However, do not worry: Yambopy can automatically switch between the two conventions when loading the LetzElPhC databases.&lt;br /&gt;
&lt;br /&gt;
You will also find a &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; database that contains the computed electron-phonon matrix elements, in the output format of &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In addition, if you check the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; folder:&lt;br /&gt;
&lt;br /&gt;
 ls SAVE/ndb.elph_gkkp*&lt;br /&gt;
&lt;br /&gt;
you will see that yambopy has created the Yambo-compatible electron-phonon databases and placed them inside the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If you want to run LetzElPhC directly, without using yambopy, you can refer to its [[https://gitlab.com/lumen-code/LetzElPhC/-/blob/main/docs/main.pdf?ref_type=heads|user guide]].&lt;br /&gt;
Keep in mind that in this case, in order to convert the database to the &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases of Yambo, you will then need a couple of lines of python using the Yambopy class &amp;lt;code&amp;gt;ConvertElectronPhononDB&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;yambopy/letzelph_interface/lelph2y.py&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
At the end of this section, you should have produced the same databases that you find in the main &amp;lt;code&amp;gt;electron_phonon&amp;lt;/code&amp;gt; folder. You can run the following part either in the directory where you are (by copying the python scripts here), or by going back:&lt;br /&gt;
&lt;br /&gt;
 $cd ..&lt;br /&gt;
&lt;br /&gt;
and using the original ones.&lt;br /&gt;
&lt;br /&gt;
=== Electron-phonon intro: plots of el-ph matrix elements on k-BZ and q-BZ ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; and read the electron-phonon databases that you generated in the previous section.&lt;br /&gt;
&lt;br /&gt;
In order to read the &amp;lt;code&amp;gt;ndb.elph_gkkp_expanded*&amp;lt;/code&amp;gt; databases in python we use the Yambopy class &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
 yelph = YamboElectronPhononDB(ylat,folder_gkkp=&#039;path/to/elph/folder&#039;,save=&#039;path/to/SAVE&#039;)&lt;br /&gt;
(notice that it requires a previous instance of &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Instead, in order to read the &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; databases from LetzElPhC, we use a different class:&lt;br /&gt;
 lelph = LetzElphElectronPhononDB(&#039;path/to/ndb.elph&#039;)&lt;br /&gt;
&lt;br /&gt;
Now, the &amp;lt;code&amp;gt;*elph&amp;lt;/code&amp;gt; objects contain phonon frequencies, phonon eigenvectors, q-point information and, of course, the electron-phonon matrix elements &amp;lt;math&amp;gt;g_{nm\nu}(k,q)&amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; are electron band states, &amp;lt;math&amp;gt;\nu&amp;lt;/math&amp;gt; is a phonon branch, and &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; are the electronic and transfer momenta.&lt;br /&gt;
&lt;br /&gt;
We can print the docstring of the &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt; class with&lt;br /&gt;
 print(yelph.__doc__)&lt;br /&gt;
and of the &amp;lt;code&amp;gt;LetzElphElectronPhononDB&amp;lt;/code&amp;gt; class with&lt;br /&gt;
 print(lelph.__doc__)&lt;br /&gt;
to get an idea of the information stored and of their capabilities.&lt;br /&gt;
&lt;br /&gt;
Now check the &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; script. You will see that it performs two plots: &lt;br /&gt;
* Plot of |g(k)| in the k-BZ for selected n,m,\nu and q [&amp;lt;code&amp;gt;Kspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Plot of |g(q)| in the q-BZ for selected n,m,\nu and k [&amp;lt;code&amp;gt;Qspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
You can change the electronic, phononic and momentum indices to see what happens.&lt;br /&gt;
&lt;br /&gt;
[[File:Elph hbn.jpg|YamboElectronPhononDB plot from yambopy tutorial|500px]]&lt;/div&gt;</summary>
		<author><name>FulvioPaleari</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_electron-phonon_coupling&amp;diff=9323</id>
		<title>Yambopy tutorial: electron-phonon coupling</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_electron-phonon_coupling&amp;diff=9323"/>
		<updated>2026-03-10T11:27:43Z</updated>

		<summary type="html">&lt;p&gt;FulvioPaleari: /* Electron-phonon intro: plots of el-ph matrix elements on k-BZ and q-BZ */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial we will cover the handling of electron-phonon coupling matrix elements by Yambopy. The electron-phonon calculation follows two steps:&lt;br /&gt;
&lt;br /&gt;
# Quantum Espresso calculation of phonon energies, eigenmodes and variations of the self-consistent potential via &amp;lt;code&amp;gt;ph.x&amp;lt;/code&amp;gt;.&lt;br /&gt;
# Electron-phonon matrix element calculation, symmetry expansion and conversion by the &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For more information on the &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; code and how you should run step 1., please see the related documentation [https://github.com/yambo-code/LetzElPhC here].&lt;br /&gt;
&lt;br /&gt;
We can use Yambopy to:&lt;br /&gt;
* Run &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; (both preprocessing and main run) without explicitly writing an input file.&lt;br /&gt;
* Convert the resulting databases into &amp;lt;code&amp;gt;Yambo&amp;lt;/code&amp;gt; format.&lt;br /&gt;
* Analyse the electron-phonon coupling both in &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;Yambo&amp;lt;/code&amp;gt; format.&lt;br /&gt;
&lt;br /&gt;
In particular we will take a look at:&lt;br /&gt;
* Lattice geometry data (Yambo database: &amp;lt;code&amp;gt;ns.db1&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
* Electron-phonon matrix elements (Yambo databases: &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt;; LetzElPhC databases: &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;LetzElphElectronPhononDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
The scripts of the tutorial, but not the databases, can be found in the yambopy directory:&lt;br /&gt;
 $cd tutorial/electron_phonon&lt;br /&gt;
&lt;br /&gt;
The full tutorial, including the LetzElPhC and Yambo databases that we will read, can be downloaded and extracted from the yambo website:&lt;br /&gt;
 $wget https://media.yambo-code.eu/educational/tutorials/files/electron_phonon.tar.gz&lt;br /&gt;
 $tar -xvzf electron_phonon.tar.gz&lt;br /&gt;
 $cd electron_phonon&lt;br /&gt;
&lt;br /&gt;
We will work with monolayer molybdenum disulphide electron-phonon data obtained on a &amp;lt;code&amp;gt;6x6x1&amp;lt;/code&amp;gt; kpoint grid, including spin-orbit interaction (so we deal with electron-phonon coupling and spinorial wavefunctions). Beware that the parameters are most certainly not converged.&lt;br /&gt;
&lt;br /&gt;
=== Command line: electron-phonon calculation and databases [OPTIONAL] ===&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&#039;&#039;&#039;Note&#039;&#039;&#039;: you can run this step only if you have compiled &#039;&#039;&#039;LetzElPhC&#039;&#039;&#039; on your machine. If not, please skip to the following sections of the tutorial, as the electron-phonon coupling databases are already provided in the .tar.gz file and you don&#039;t need to explicitly recalculate them.&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you run this step, please enter the directory&lt;br /&gt;
&lt;br /&gt;
 $cd databases&lt;br /&gt;
&lt;br /&gt;
Let us assume that we have run a quantum espresso phonon calculation as per step 1. above. You will find the results in the &amp;lt;code&amp;gt;dvscf&amp;lt;/code&amp;gt; directory. We also have done a non-self-consistent calculation to be used in Yambo, and created the relative &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory.&lt;br /&gt;
 &lt;br /&gt;
Now, we aim to reconstruct the electron-phonon coupling matrix elements from the phonon energies, modes and potential variations (in &amp;lt;code&amp;gt;dvscf&amp;lt;/code&amp;gt;) and the Bloch electronic wavefunctions used by Yambo (in &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
In order to do this, we will run the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable of the &#039;&#039;&#039;LetzElPhC&#039;&#039;&#039; code. We will run via command line using yambopy, although it will be instructive to have look at the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; input files later.&lt;br /&gt;
&lt;br /&gt;
We run in the same directory where the Yambo &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; is (remember than you can also virtually move it with a symbolic link).&lt;br /&gt;
&lt;br /&gt;
Type:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y&lt;br /&gt;
&lt;br /&gt;
to see the help for the calculation. Have a look at the various flags and their description.&lt;br /&gt;
For example, if we want to do a serial run of LetzElPhC for bands from &amp;lt;math&amp;gt;n_i&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;n_f&amp;lt;/math&amp;gt;, we should type:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph path/of/ph_input.in -b n_i n_f&lt;br /&gt;
&lt;br /&gt;
Here &amp;lt;math&amp;gt;n_i&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;n_f&amp;lt;/math&amp;gt; are integers representing the initial and final band indices. &#039;&#039;&#039;Please note&#039;&#039;&#039;: in this case, the band index starts from 1 and the the interval of bands read by the code is &amp;lt;math&amp;gt;[n_i,n_f]&amp;lt;/math&amp;gt; including the extrema of the interval. &lt;br /&gt;
&lt;br /&gt;
For our system, we want to do a parallel calculation: 4 MPI tasks on q-point loop (phonon momenta) and 2 MPI tasks on the k-point loop (electron momenta). In addition, we want to explicitly specify the path of the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable. &lt;br /&gt;
&lt;br /&gt;
We have a final choice to make. We can ask Yambopy to produce the default LetzElPhC electron-phonon databases, or to convert them in Yambo-compatible format. By the default, both will be printed. &lt;br /&gt;
&lt;br /&gt;
* If you don&#039;t need the Yambo-style &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases you can run &amp;lt;code&amp;gt;yambopy l2y ...&amp;lt;/code&amp;gt; with the &amp;lt;code&amp;gt;--no_gkkp&amp;lt;/code&amp;gt; option.&lt;br /&gt;
* If you don&#039;t need the default &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; databases you can run &amp;lt;code&amp;gt;yambopy l2y ...&amp;lt;/code&amp;gt; with the &amp;lt;code&amp;gt;--no_lelphc_dbs&amp;lt;/code&amp;gt; option.&lt;br /&gt;
&lt;br /&gt;
However, for this tutorial, we will take a look at both databases, so let&#039;s run:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph dvscf/mos2.dvscf -b 25 28 -par 4 2 -lelphc path/to/lelphc_exe&lt;br /&gt;
&lt;br /&gt;
We include the last two valence bands of monolayer MoS2 (25 and 26) and the first two conduction bands (27 and 28). If your &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable is in the &amp;lt;code&amp;gt;PATH&amp;lt;/code&amp;gt;, you do not need to specify the last flag.&lt;br /&gt;
&lt;br /&gt;
At the end, check your directory: you should find the &amp;lt;code&amp;gt;lelphc.in&amp;lt;/code&amp;gt; input file that was run, let&#039;s inspect it: &lt;br /&gt;
&lt;br /&gt;
 # LetzElPhC input for yambo generated by yambopy&lt;br /&gt;
 nqpool      = 2&lt;br /&gt;
 nkpool      = 4&lt;br /&gt;
 start_bnd   = 25&lt;br /&gt;
 end_bnd     = 28&lt;br /&gt;
 save_dir    = ./SAVE&lt;br /&gt;
 kernel      = dfpt&lt;br /&gt;
 ph_save_dir = dvscf/ph_save&lt;br /&gt;
 convention = yambo&lt;br /&gt;
&lt;br /&gt;
Notice the variable &amp;lt;code&amp;gt;convention=yambo&amp;lt;/code&amp;gt;: what does it mean? At variance with QE and many other codes, Yambo uses the &amp;quot;backward&amp;quot; momentum transfer convention for electronic scatterings. That is, an electronic transition goes from band &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; and momentum &amp;lt;math&amp;gt;k-q&amp;lt;/math&amp;gt; to band &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; and momentum &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;. In the &amp;quot;forward&amp;quot; momentum transfer convention (the more standard one), the transitions go from &amp;lt;math&amp;gt;nk&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;mk+q&amp;lt;/math&amp;gt;. Therefore, this variable ensures that the electron-phonon coupling matrix elements are computed as &amp;lt;math&amp;gt;\langle mk|dV|nk-q\rangle&amp;lt;/math&amp;gt;. However, do not worry: Yambopy can automatically switch between the two conventions when loading the LetzElPhC databases.&lt;br /&gt;
&lt;br /&gt;
You will also find a &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; database that contains the computed electron-phonon matrix elements, in the output format of &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In addition, if you check the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; folder:&lt;br /&gt;
&lt;br /&gt;
 ls SAVE/ndb.elph_gkkp*&lt;br /&gt;
&lt;br /&gt;
you will see that yambopy has created the Yambo-compatible electron-phonon databases and placed them inside the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If you want to run LetzElPhC directly, without using yambopy, you can refer to its [[https://gitlab.com/lumen-code/LetzElPhC/-/blob/main/docs/main.pdf?ref_type=heads|user guide]].&lt;br /&gt;
Keep in mind that in this case, in order to convert the database to the &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases of Yambo, you will then need a couple of lines of python using the Yambopy class &amp;lt;code&amp;gt;ConvertElectronPhononDB&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;yambopy/letzelph_interface/lelph2y.py&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
At the end of this section, you should have produced the same databases that you find in the main &amp;lt;code&amp;gt;electron_phonon&amp;lt;/code&amp;gt; folder. You can run the following part either in the directory where you are (by copying the python scripts here), or by going back:&lt;br /&gt;
&lt;br /&gt;
 $cd ..&lt;br /&gt;
&lt;br /&gt;
and using the original ones.&lt;br /&gt;
&lt;br /&gt;
=== Electron-phonon intro: plots of el-ph matrix elements on k-BZ and q-BZ ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; and read the electron-phonon databases that you generated in the previous section.&lt;br /&gt;
&lt;br /&gt;
In order to read the &amp;lt;code&amp;gt;ndb.elph_gkkp_expanded*&amp;lt;/code&amp;gt; databases in python we use the Yambopy class &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
 yelph = YamboElectronPhononDB(ylat,folder_gkkp=&#039;path/to/elph/folder&#039;,save=&#039;path/to/SAVE&#039;)&lt;br /&gt;
(notice that it requires a previous instance of &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Instead, in order to read the &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; databases from LetzElPhC, we use a different class:&lt;br /&gt;
 lelph = LetzElphElectronPhononDB(&#039;path/to/ndb.elph&#039;)&lt;br /&gt;
&lt;br /&gt;
Now, the &amp;lt;code&amp;gt;*elph&amp;lt;/code&amp;gt; objects contain phonon frequencies, phonon eigenvectors, q-point information and, of course, the electron-phonon matrix elements &amp;lt;math&amp;gt;g_{nm\nu}(k,q)&amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; are electron band states, &amp;lt;math&amp;gt;\nu&amp;lt;/math&amp;gt; is a phonon branch, and &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; are the electronic and transfer momenta.&lt;br /&gt;
&lt;br /&gt;
We can print the docstring of the &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt; class with&lt;br /&gt;
 print(yelph.__doc__)&lt;br /&gt;
and of the &amp;lt;code&amp;gt;LetzElphElectronPhononDB&amp;lt;/code&amp;gt; class with&lt;br /&gt;
 print(lelph.__doc__)&lt;br /&gt;
to get an idea of the information stored and of their capabilities.&lt;br /&gt;
&lt;br /&gt;
Now check the &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; script. You will see that it performs two plots: &lt;br /&gt;
* Plot of |g(k)| in the k-BZ for selected n,m,\nu and q [&amp;lt;code&amp;gt;Kspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Plot of |g(q)| in the q-BZ for selected n,m,\nu and k [&amp;lt;code&amp;gt;Qspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
You can change the electronic, phononic and momentum indices to see what happens.&lt;br /&gt;
&lt;br /&gt;
[[File:Elph hbn.jpg|YamboElectronPhononDB plot from yambopy tutorial|500px]]&lt;/div&gt;</summary>
		<author><name>FulvioPaleari</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_electron-phonon_coupling&amp;diff=9322</id>
		<title>Yambopy tutorial: electron-phonon coupling</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_electron-phonon_coupling&amp;diff=9322"/>
		<updated>2026-03-10T11:04:58Z</updated>

		<summary type="html">&lt;p&gt;FulvioPaleari: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial we will cover the handling of electron-phonon coupling matrix elements by Yambopy. The electron-phonon calculation follows two steps:&lt;br /&gt;
&lt;br /&gt;
# Quantum Espresso calculation of phonon energies, eigenmodes and variations of the self-consistent potential via &amp;lt;code&amp;gt;ph.x&amp;lt;/code&amp;gt;.&lt;br /&gt;
# Electron-phonon matrix element calculation, symmetry expansion and conversion by the &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For more information on the &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; code and how you should run step 1., please see the related documentation [https://github.com/yambo-code/LetzElPhC here].&lt;br /&gt;
&lt;br /&gt;
We can use Yambopy to:&lt;br /&gt;
* Run &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; (both preprocessing and main run) without explicitly writing an input file.&lt;br /&gt;
* Convert the resulting databases into &amp;lt;code&amp;gt;Yambo&amp;lt;/code&amp;gt; format.&lt;br /&gt;
* Analyse the electron-phonon coupling both in &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;Yambo&amp;lt;/code&amp;gt; format.&lt;br /&gt;
&lt;br /&gt;
In particular we will take a look at:&lt;br /&gt;
* Lattice geometry data (Yambo database: &amp;lt;code&amp;gt;ns.db1&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
* Electron-phonon matrix elements (Yambo databases: &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt;; LetzElPhC databases: &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;LetzElphElectronPhononDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
The scripts of the tutorial, but not the databases, can be found in the yambopy directory:&lt;br /&gt;
 $cd tutorial/electron_phonon&lt;br /&gt;
&lt;br /&gt;
The full tutorial, including the LetzElPhC and Yambo databases that we will read, can be downloaded and extracted from the yambo website:&lt;br /&gt;
 $wget https://media.yambo-code.eu/educational/tutorials/files/electron_phonon.tar.gz&lt;br /&gt;
 $tar -xvzf electron_phonon.tar.gz&lt;br /&gt;
 $cd electron_phonon&lt;br /&gt;
&lt;br /&gt;
We will work with monolayer molybdenum disulphide electron-phonon data obtained on a &amp;lt;code&amp;gt;6x6x1&amp;lt;/code&amp;gt; kpoint grid, including spin-orbit interaction (so we deal with electron-phonon coupling and spinorial wavefunctions). Beware that the parameters are most certainly not converged.&lt;br /&gt;
&lt;br /&gt;
=== Command line: electron-phonon calculation and databases [OPTIONAL] ===&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&#039;&#039;&#039;Note&#039;&#039;&#039;: you can run this step only if you have compiled &#039;&#039;&#039;LetzElPhC&#039;&#039;&#039; on your machine. If not, please skip to the following sections of the tutorial, as the electron-phonon coupling databases are already provided in the .tar.gz file and you don&#039;t need to explicitly recalculate them.&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you run this step, please enter the directory&lt;br /&gt;
&lt;br /&gt;
 $cd databases&lt;br /&gt;
&lt;br /&gt;
Let us assume that we have run a quantum espresso phonon calculation as per step 1. above. You will find the results in the &amp;lt;code&amp;gt;dvscf&amp;lt;/code&amp;gt; directory. We also have done a non-self-consistent calculation to be used in Yambo, and created the relative &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory.&lt;br /&gt;
 &lt;br /&gt;
Now, we aim to reconstruct the electron-phonon coupling matrix elements from the phonon energies, modes and potential variations (in &amp;lt;code&amp;gt;dvscf&amp;lt;/code&amp;gt;) and the Bloch electronic wavefunctions used by Yambo (in &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
In order to do this, we will run the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable of the &#039;&#039;&#039;LetzElPhC&#039;&#039;&#039; code. We will run via command line using yambopy, although it will be instructive to have look at the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; input files later.&lt;br /&gt;
&lt;br /&gt;
We run in the same directory where the Yambo &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; is (remember than you can also virtually move it with a symbolic link).&lt;br /&gt;
&lt;br /&gt;
Type:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y&lt;br /&gt;
&lt;br /&gt;
to see the help for the calculation. Have a look at the various flags and their description.&lt;br /&gt;
For example, if we want to do a serial run of LetzElPhC for bands from &amp;lt;math&amp;gt;n_i&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;n_f&amp;lt;/math&amp;gt;, we should type:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph path/of/ph_input.in -b n_i n_f&lt;br /&gt;
&lt;br /&gt;
Here &amp;lt;math&amp;gt;n_i&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;n_f&amp;lt;/math&amp;gt; are integers representing the initial and final band indices. &#039;&#039;&#039;Please note&#039;&#039;&#039;: in this case, the band index starts from 1 and the the interval of bands read by the code is &amp;lt;math&amp;gt;[n_i,n_f]&amp;lt;/math&amp;gt; including the extrema of the interval. &lt;br /&gt;
&lt;br /&gt;
For our system, we want to do a parallel calculation: 4 MPI tasks on q-point loop (phonon momenta) and 2 MPI tasks on the k-point loop (electron momenta). In addition, we want to explicitly specify the path of the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable. &lt;br /&gt;
&lt;br /&gt;
We have a final choice to make. We can ask Yambopy to produce the default LetzElPhC electron-phonon databases, or to convert them in Yambo-compatible format. By the default, both will be printed. &lt;br /&gt;
&lt;br /&gt;
* If you don&#039;t need the Yambo-style &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases you can run &amp;lt;code&amp;gt;yambopy l2y ...&amp;lt;/code&amp;gt; with the &amp;lt;code&amp;gt;--no_gkkp&amp;lt;/code&amp;gt; option.&lt;br /&gt;
* If you don&#039;t need the default &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; databases you can run &amp;lt;code&amp;gt;yambopy l2y ...&amp;lt;/code&amp;gt; with the &amp;lt;code&amp;gt;--no_lelphc_dbs&amp;lt;/code&amp;gt; option.&lt;br /&gt;
&lt;br /&gt;
However, for this tutorial, we will take a look at both databases, so let&#039;s run:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph dvscf/mos2.dvscf -b 25 28 -par 4 2 -lelphc path/to/lelphc_exe&lt;br /&gt;
&lt;br /&gt;
We include the last two valence bands of monolayer MoS2 (25 and 26) and the first two conduction bands (27 and 28). If your &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable is in the &amp;lt;code&amp;gt;PATH&amp;lt;/code&amp;gt;, you do not need to specify the last flag.&lt;br /&gt;
&lt;br /&gt;
At the end, check your directory: you should find the &amp;lt;code&amp;gt;lelphc.in&amp;lt;/code&amp;gt; input file that was run, let&#039;s inspect it: &lt;br /&gt;
&lt;br /&gt;
 # LetzElPhC input for yambo generated by yambopy&lt;br /&gt;
 nqpool      = 2&lt;br /&gt;
 nkpool      = 4&lt;br /&gt;
 start_bnd   = 25&lt;br /&gt;
 end_bnd     = 28&lt;br /&gt;
 save_dir    = ./SAVE&lt;br /&gt;
 kernel      = dfpt&lt;br /&gt;
 ph_save_dir = dvscf/ph_save&lt;br /&gt;
 convention = yambo&lt;br /&gt;
&lt;br /&gt;
Notice the variable &amp;lt;code&amp;gt;convention=yambo&amp;lt;/code&amp;gt;: what does it mean? At variance with QE and many other codes, Yambo uses the &amp;quot;backward&amp;quot; momentum transfer convention for electronic scatterings. That is, an electronic transition goes from band &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; and momentum &amp;lt;math&amp;gt;k-q&amp;lt;/math&amp;gt; to band &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; and momentum &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;. In the &amp;quot;forward&amp;quot; momentum transfer convention (the more standard one), the transitions go from &amp;lt;math&amp;gt;nk&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;mk+q&amp;lt;/math&amp;gt;. Therefore, this variable ensures that the electron-phonon coupling matrix elements are computed as &amp;lt;math&amp;gt;\langle mk|dV|nk-q\rangle&amp;lt;/math&amp;gt;. However, do not worry: Yambopy can automatically switch between the two conventions when loading the LetzElPhC databases.&lt;br /&gt;
&lt;br /&gt;
You will also find a &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; database that contains the computed electron-phonon matrix elements, in the output format of &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In addition, if you check the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; folder:&lt;br /&gt;
&lt;br /&gt;
 ls SAVE/ndb.elph_gkkp*&lt;br /&gt;
&lt;br /&gt;
you will see that yambopy has created the Yambo-compatible electron-phonon databases and placed them inside the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If you want to run LetzElPhC directly, without using yambopy, you can refer to its [[https://gitlab.com/lumen-code/LetzElPhC/-/blob/main/docs/main.pdf?ref_type=heads|user guide]].&lt;br /&gt;
Keep in mind that in this case, in order to convert the database to the &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases of Yambo, you will then need a couple of lines of python using the Yambopy class &amp;lt;code&amp;gt;ConvertElectronPhononDB&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;yambopy/letzelph_interface/lelph2y.py&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
At the end of this section, you should have produced the same databases that you find in the main &amp;lt;code&amp;gt;electron_phonon&amp;lt;/code&amp;gt; folder. You can run the following part either in the directory where you are (by copying the python scripts here), or by going back:&lt;br /&gt;
&lt;br /&gt;
 $cd ..&lt;br /&gt;
&lt;br /&gt;
and using the original ones.&lt;br /&gt;
&lt;br /&gt;
=== Electron-phonon intro: plots of el-ph matrix elements on k-BZ and q-BZ ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; and read the electron-phonon databases that you generated in the previous section.&lt;br /&gt;
&lt;br /&gt;
In order to read the &amp;lt;code&amp;gt;ndb.elph_gkkp_expanded*&amp;lt;/code&amp;gt; databases in python we use the Yambopy class &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
 yelph = YamboElectronPhononDB(ylat,folder_gkkp=&#039;path/to/elph/folder&#039;,save=&#039;path/to/SAVE&#039;)&lt;br /&gt;
(notice that it requires a previous instance of &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Now, the &amp;lt;code&amp;gt;yelph&amp;lt;/code&amp;gt; object contains phonon frequencies, phonon eigenvectors, qpoint information and, of course, the electron-phonon matrix elements g_{nm\nu}(k,q) where n, m are electron band states, \nu is a phonon branch, and k and q are the electronic and transfer momenta.&lt;br /&gt;
&lt;br /&gt;
We can print the docstring of the &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt; class with&lt;br /&gt;
 print(yelph.__doc__)&lt;br /&gt;
to get an idea of the information stored and of its capabilities.&lt;br /&gt;
&lt;br /&gt;
Now check the &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; script. You will see that it performs two plots: &lt;br /&gt;
* Plot of |g(k)| in the k-BZ for selected n,m,\nu and q [&amp;lt;code&amp;gt;Kspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Plot of |g(q)| in the q-BZ for selected n,m,\nu and k [&amp;lt;code&amp;gt;Qspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
You can change the electronic, phononic and momentum indices to see what happens.&lt;br /&gt;
&lt;br /&gt;
[[File:Elph hbn.jpg|YamboElectronPhononDB plot from yambopy tutorial|500px]]&lt;/div&gt;</summary>
		<author><name>FulvioPaleari</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_electron-phonon_coupling&amp;diff=9321</id>
		<title>Yambopy tutorial: electron-phonon coupling</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_electron-phonon_coupling&amp;diff=9321"/>
		<updated>2026-03-10T10:49:26Z</updated>

		<summary type="html">&lt;p&gt;FulvioPaleari: /* Command line: electron-phonon calculation and databases */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial we will cover the handling of electron-phonon coupling matrix elements by Yambopy. The electron-phonon calculation follows two steps:&lt;br /&gt;
&lt;br /&gt;
# Quantum Espresso calculation of phonon energies, eigenmodes and variations of the self-consistent potential via &amp;lt;code&amp;gt;ph.x&amp;lt;/code&amp;gt;.&lt;br /&gt;
# Electron-phonon matrix element calculation, symmetry expansion and conversion by the &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For more information on the &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; code and how you should run step 1., please see the related documentation [https://github.com/yambo-code/LetzElPhC here].&lt;br /&gt;
&lt;br /&gt;
We can use Yambopy to:&lt;br /&gt;
* Run &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; (both preprocessing and main run) without explicitly writing an input file.&lt;br /&gt;
* Convert the resulting databases into &amp;lt;code&amp;gt;Yambo&amp;lt;/code&amp;gt; format.&lt;br /&gt;
* Analyse the electron-phonon coupling both in &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;Yambo&amp;lt;/code&amp;gt; format.&lt;br /&gt;
&lt;br /&gt;
The scripts of the tutorial, but not the databases, can be found in the yambopy directory:&lt;br /&gt;
 $cd tutorial/electron_phonon&lt;br /&gt;
&lt;br /&gt;
The full tutorial, including the LetzElPhC and Yambo databases that we will read, can be downloaded and extracted from the yambo website:&lt;br /&gt;
 $wget https://media.yambo-code.eu/educational/tutorials/files/electron_phonon.tar.gz&lt;br /&gt;
 $tar -xvzf electron_phonon.tar.gz&lt;br /&gt;
 $cd electron_phonon&lt;br /&gt;
&lt;br /&gt;
We will work with monolayer molybdenum disulphide electron-phonon data obtained on a &amp;lt;code&amp;gt;6x6x1&amp;lt;/code&amp;gt; kpoint grid, including spin-orbit interaction (so we deal with electron-phonon coupling and spinorial wavefunctions). Beware that the parameters are most certainly not converged.&lt;br /&gt;
&lt;br /&gt;
=== Command line: electron-phonon calculation and databases [OPTIONAL] ===&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&#039;&#039;&#039;Note&#039;&#039;&#039;: you can run this step only if you have compiled &#039;&#039;&#039;LetzElPhC&#039;&#039;&#039; on your machine. If not, please skip to the following sections of the tutorial, as the electron-phonon coupling databases are already provided in the .tar.gz file and you don&#039;t need to explicitly recalculate them.&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you run this step, please enter the directory&lt;br /&gt;
&lt;br /&gt;
 $cd databases&lt;br /&gt;
&lt;br /&gt;
Let us assume that we have run a quantum espresso phonon calculation as per step 1. above. You will find the results in the &amp;lt;code&amp;gt;dvscf&amp;lt;/code&amp;gt; directory. We also have done a non-self-consistent calculation to be used in Yambo, and created the relative &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory.&lt;br /&gt;
 &lt;br /&gt;
Now, we aim to reconstruct the electron-phonon coupling matrix elements from the phonon energies, modes and potential variations (in &amp;lt;code&amp;gt;dvscf&amp;lt;/code&amp;gt;) and the Bloch electronic wavefunctions used by Yambo (in &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
In order to do this, we will run the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable of the &#039;&#039;&#039;LetzElPhC&#039;&#039;&#039; code. We will run via command line using yambopy, although it will be instructive to have look at the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; input files later.&lt;br /&gt;
&lt;br /&gt;
We run in the same directory where the Yambo &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; is (remember than you can also virtually move it with a symbolic link).&lt;br /&gt;
&lt;br /&gt;
Type:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y&lt;br /&gt;
&lt;br /&gt;
to see the help for the calculation. Have a look at the various flags and their description.&lt;br /&gt;
For example, if we want to do a serial run of LetzElPhC for bands from &amp;lt;math&amp;gt;n_i&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;n_f&amp;lt;/math&amp;gt;, we should type:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph path/of/ph_input.in -b n_i n_f&lt;br /&gt;
&lt;br /&gt;
Here &amp;lt;math&amp;gt;n_i&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;n_f&amp;lt;/math&amp;gt; are integers representing the initial and final band indices. &#039;&#039;&#039;Please note&#039;&#039;&#039;: in this case, the band index starts from 1 and the the interval of bands read by the code is &amp;lt;math&amp;gt;[n_i,n_f]&amp;lt;/math&amp;gt; including the extrema of the interval. &lt;br /&gt;
&lt;br /&gt;
For our system, we want to do a parallel calculation: 4 MPI tasks on q-point loop (phonon momenta) and 2 MPI tasks on the k-point loop (electron momenta). In addition, we want to explicitly specify the path of the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable. &lt;br /&gt;
&lt;br /&gt;
We have a final choice to make. We can ask Yambopy to produce the default LetzElPhC electron-phonon databases, or to convert them in Yambo-compatible format. By the default, both will be printed. &lt;br /&gt;
&lt;br /&gt;
* If you don&#039;t need the Yambo-style &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases you can run &amp;lt;code&amp;gt;yambopy l2y ...&amp;lt;/code&amp;gt; with the &amp;lt;code&amp;gt;--no_gkkp&amp;lt;/code&amp;gt; option.&lt;br /&gt;
* If you don&#039;t need the default &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; databases you can run &amp;lt;code&amp;gt;yambopy l2y ...&amp;lt;/code&amp;gt; with the &amp;lt;code&amp;gt;--no_lelphc_dbs&amp;lt;/code&amp;gt; option.&lt;br /&gt;
&lt;br /&gt;
However, for this tutorial, we will take a look at both databases, so let&#039;s run:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph dvscf/mos2.dvscf -b 25 28 -par 4 2 -lelphc path/to/lelphc_exe&lt;br /&gt;
&lt;br /&gt;
We include the last two valence bands of monolayer MoS2 (25 and 26) and the first two conduction bands (27 and 28). If your &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable is in the &amp;lt;code&amp;gt;PATH&amp;lt;/code&amp;gt;, you do not need to specify the last flag.&lt;br /&gt;
&lt;br /&gt;
At the end, check your directory: you should find the &amp;lt;code&amp;gt;lelphc.in&amp;lt;/code&amp;gt; input file that was run, let&#039;s inspect it: &lt;br /&gt;
&lt;br /&gt;
 # LetzElPhC input for yambo generated by yambopy&lt;br /&gt;
 nqpool      = 2&lt;br /&gt;
 nkpool      = 4&lt;br /&gt;
 start_bnd   = 25&lt;br /&gt;
 end_bnd     = 28&lt;br /&gt;
 save_dir    = ./SAVE&lt;br /&gt;
 kernel      = dfpt&lt;br /&gt;
 ph_save_dir = dvscf/ph_save&lt;br /&gt;
 convention = yambo&lt;br /&gt;
&lt;br /&gt;
Notice the variable &amp;lt;code&amp;gt;convention=yambo&amp;lt;/code&amp;gt;: what does it mean? At variance with QE and many other codes, Yambo uses the &amp;quot;backward&amp;quot; momentum transfer convention for electronic scatterings. That is, an electronic transition goes from band &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; and momentum &amp;lt;math&amp;gt;k-q&amp;lt;/math&amp;gt; to band &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; and momentum &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;. In the &amp;quot;forward&amp;quot; momentum transfer convention (the more standard one), the transitions go from &amp;lt;math&amp;gt;nk&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;mk+q&amp;lt;/math&amp;gt;. Therefore, this variable ensures that the electron-phonon coupling matrix elements are computed as &amp;lt;math&amp;gt;\langle mk|dV|nk-q\rangle&amp;lt;/math&amp;gt;. However, do not worry: Yambopy can automatically switch between the two conventions when loading the LetzElPhC databases.&lt;br /&gt;
&lt;br /&gt;
You will also find a &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; database that contains the computed electron-phonon matrix elements, in the output format of &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In addition, if you check the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; folder:&lt;br /&gt;
&lt;br /&gt;
 ls SAVE/ndb.elph_gkkp*&lt;br /&gt;
&lt;br /&gt;
you will see that yambopy has created the Yambo-compatible electron-phonon databases and placed them inside the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If you want to run LetzElPhC directly, without using yambopy, you can refer to its [[https://gitlab.com/lumen-code/LetzElPhC/-/blob/main/docs/main.pdf?ref_type=heads|user guide]].&lt;br /&gt;
Keep in mind that in this case, in order to convert the database to the &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases of Yambo, you will then need a couple of lines of python using the Yambopy class &amp;lt;code&amp;gt;ConvertElectronPhononDB&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;yambopy/letzelph_interface/lelph2y.py&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
At the end of this section, you should have produced the same databases that you find in the main &amp;lt;code&amp;gt;electron_phonon&amp;lt;/code&amp;gt; folder. You can run the following part either in the directory where you are (by copying the python scripts here), or by going back:&lt;br /&gt;
&lt;br /&gt;
 $cd ..&lt;br /&gt;
&lt;br /&gt;
and using the original ones.&lt;br /&gt;
&lt;br /&gt;
=== Electron-phonon intro: plots of el-ph matrix elements on k-BZ and q-BZ ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Loading electron-phonon matrix elements: Yambo ===&lt;br /&gt;
You may have seen how to calculate and import electron-phonon matrix elements in yambo in the [[Electron Phonon Coupling|electron-phonon tutorial]].&lt;br /&gt;
&lt;br /&gt;
With Yambopy, we can generate a yambo SAVE folder and import the matrix elements with a single command.&lt;br /&gt;
Typing &lt;br /&gt;
 $yambopy gkkp&lt;br /&gt;
will print the necessary documentation:&lt;br /&gt;
 Produce a SAVE folder including elph_gkkp databases&lt;br /&gt;
 &lt;br /&gt;
 Arguments are:&lt;br /&gt;
   -nscf, --nscf_dir  -&amp;gt; &amp;lt;Optional&amp;gt; Path to nscf save folder&lt;br /&gt;
   -elph, --elph_dir  -&amp;gt; Path to elph_dir folder&lt;br /&gt;
   -y, --yambo_dir    -&amp;gt; &amp;lt;Optional&amp;gt; Path to yambo executables&lt;br /&gt;
   -e, --expand       -&amp;gt; &amp;lt;Optional&amp;gt; Expand gkkp databases&lt;br /&gt;
&lt;br /&gt;
The necessary quantum espresso databases are stored in &amp;lt;code&amp;gt;ELPH_SAVES/QE_SAVES/hBN.save&amp;lt;/code&amp;gt; (nscf calculation) and &amp;lt;code&amp;gt;ELPH_SAVES/QE_SAVES/elph_dir&amp;lt;/code&amp;gt; (matrix elements from the dfpt calculation). For this tutorial we also need to expand the electron-phonon matrix elements to the full Brillouin zone. Since this is a different calculation with respect to the previous section, please generate this SAVE in a different directory than the one you used for the previous SAVE, which should be the current directory.&lt;br /&gt;
For example:&lt;br /&gt;
 $mkdir yambo-with-elph&lt;br /&gt;
 $cd yambo-with-elph&lt;br /&gt;
&lt;br /&gt;
Now we can run yambopy as in the instructions:&lt;br /&gt;
 $yambopy gkkp -nscf ../ELPH_saves/QE_saves/hBN.save -elph ../ELPH_saves/QE_saves/elph_dir --expand&lt;br /&gt;
This should generate a yambo SAVE folder which contains the &amp;lt;code&amp;gt;ndb.elph_gkkp_expanded*&amp;lt;/code&amp;gt; databases.&lt;br /&gt;
&lt;br /&gt;
=== Electron-phonon intro old: plots of el-ph matrix elements on k-BZ and q-BZ ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; and read the electron-phonon databases that you generated in the previous section.&lt;br /&gt;
&lt;br /&gt;
In order to read the &amp;lt;code&amp;gt;ndb.elph_gkkp_expanded*&amp;lt;/code&amp;gt; databases in python we use the Yambopy class &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
 yelph = YamboElectronPhononDB(ylat,folder_gkkp=&#039;path/to/elph/folder&#039;,save=&#039;path/to/SAVE&#039;)&lt;br /&gt;
(notice that it requires a previous instance of &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Now, the &amp;lt;code&amp;gt;yelph&amp;lt;/code&amp;gt; object contains phonon frequencies, phonon eigenvectors, qpoint information and, of course, the electron-phonon matrix elements g_{nm\nu}(k,q) where n, m are electron band states, \nu is a phonon branch, and k and q are the electronic and transfer momenta.&lt;br /&gt;
&lt;br /&gt;
We can print the docstring of the &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt; class with&lt;br /&gt;
 print(yelph.__doc__)&lt;br /&gt;
to get an idea of the information stored and of its capabilities.&lt;br /&gt;
&lt;br /&gt;
Now check the &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; script. You will see that it performs two plots: &lt;br /&gt;
* Plot of |g(k)| in the k-BZ for selected n,m,\nu and q [&amp;lt;code&amp;gt;Kspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Plot of |g(q)| in the q-BZ for selected n,m,\nu and k [&amp;lt;code&amp;gt;Qspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
You can change the electronic, phononic and momentum indices to see what happens.&lt;br /&gt;
&lt;br /&gt;
[[File:Elph hbn.jpg|YamboElectronPhononDB plot from yambopy tutorial|500px]]&lt;/div&gt;</summary>
		<author><name>FulvioPaleari</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_electron-phonon_coupling&amp;diff=9320</id>
		<title>Yambopy tutorial: electron-phonon coupling</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_electron-phonon_coupling&amp;diff=9320"/>
		<updated>2026-03-10T10:48:58Z</updated>

		<summary type="html">&lt;p&gt;FulvioPaleari: /* Command line: electron-phonon calculation and databases */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial we will cover the handling of electron-phonon coupling matrix elements by Yambopy. The electron-phonon calculation follows two steps:&lt;br /&gt;
&lt;br /&gt;
# Quantum Espresso calculation of phonon energies, eigenmodes and variations of the self-consistent potential via &amp;lt;code&amp;gt;ph.x&amp;lt;/code&amp;gt;.&lt;br /&gt;
# Electron-phonon matrix element calculation, symmetry expansion and conversion by the &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For more information on the &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; code and how you should run step 1., please see the related documentation [https://github.com/yambo-code/LetzElPhC here].&lt;br /&gt;
&lt;br /&gt;
We can use Yambopy to:&lt;br /&gt;
* Run &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; (both preprocessing and main run) without explicitly writing an input file.&lt;br /&gt;
* Convert the resulting databases into &amp;lt;code&amp;gt;Yambo&amp;lt;/code&amp;gt; format.&lt;br /&gt;
* Analyse the electron-phonon coupling both in &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;Yambo&amp;lt;/code&amp;gt; format.&lt;br /&gt;
&lt;br /&gt;
The scripts of the tutorial, but not the databases, can be found in the yambopy directory:&lt;br /&gt;
 $cd tutorial/electron_phonon&lt;br /&gt;
&lt;br /&gt;
The full tutorial, including the LetzElPhC and Yambo databases that we will read, can be downloaded and extracted from the yambo website:&lt;br /&gt;
 $wget https://media.yambo-code.eu/educational/tutorials/files/electron_phonon.tar.gz&lt;br /&gt;
 $tar -xvzf electron_phonon.tar.gz&lt;br /&gt;
 $cd electron_phonon&lt;br /&gt;
&lt;br /&gt;
We will work with monolayer molybdenum disulphide electron-phonon data obtained on a &amp;lt;code&amp;gt;6x6x1&amp;lt;/code&amp;gt; kpoint grid, including spin-orbit interaction (so we deal with electron-phonon coupling and spinorial wavefunctions). Beware that the parameters are most certainly not converged.&lt;br /&gt;
&lt;br /&gt;
=== Command line: electron-phonon calculation and databases ===&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&#039;&#039;&#039;Note&#039;&#039;&#039;: you can run this step only if you have compiled &#039;&#039;&#039;LetzElPhC&#039;&#039;&#039; on your machine. If not, please skip to the following sections of the tutorial, as the electron-phonon coupling databases are already provided in the .tar.gz file and you don&#039;t need to explicitly recalculate them.&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you run this step, please enter the directory&lt;br /&gt;
&lt;br /&gt;
 $cd databases&lt;br /&gt;
&lt;br /&gt;
Let us assume that we have run a quantum espresso phonon calculation as per step 1. above. You will find the results in the &amp;lt;code&amp;gt;dvscf&amp;lt;/code&amp;gt; directory. We also have done a non-self-consistent calculation to be used in Yambo, and created the relative &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory.&lt;br /&gt;
 &lt;br /&gt;
Now, we aim to reconstruct the electron-phonon coupling matrix elements from the phonon energies, modes and potential variations (in &amp;lt;code&amp;gt;dvscf&amp;lt;/code&amp;gt;) and the Bloch electronic wavefunctions used by Yambo (in &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
In order to do this, we will run the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable of the &#039;&#039;&#039;LetzElPhC&#039;&#039;&#039; code. We will run via command line using yambopy, although it will be instructive to have look at the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; input files later.&lt;br /&gt;
&lt;br /&gt;
We run in the same directory where the Yambo &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; is (remember than you can also virtually move it with a symbolic link).&lt;br /&gt;
&lt;br /&gt;
Type:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y&lt;br /&gt;
&lt;br /&gt;
to see the help for the calculation. Have a look at the various flags and their description.&lt;br /&gt;
For example, if we want to do a serial run of LetzElPhC for bands from &amp;lt;math&amp;gt;n_i&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;n_f&amp;lt;/math&amp;gt;, we should type:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph path/of/ph_input.in -b n_i n_f&lt;br /&gt;
&lt;br /&gt;
Here &amp;lt;math&amp;gt;n_i&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;n_f&amp;lt;/math&amp;gt; are integers representing the initial and final band indices. &#039;&#039;&#039;Please note&#039;&#039;&#039;: in this case, the band index starts from 1 and the the interval of bands read by the code is &amp;lt;math&amp;gt;[n_i,n_f]&amp;lt;/math&amp;gt; including the extrema of the interval. &lt;br /&gt;
&lt;br /&gt;
For our system, we want to do a parallel calculation: 4 MPI tasks on q-point loop (phonon momenta) and 2 MPI tasks on the k-point loop (electron momenta). In addition, we want to explicitly specify the path of the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable. &lt;br /&gt;
&lt;br /&gt;
We have a final choice to make. We can ask Yambopy to produce the default LetzElPhC electron-phonon databases, or to convert them in Yambo-compatible format. By the default, both will be printed. &lt;br /&gt;
&lt;br /&gt;
* If you don&#039;t need the Yambo-style &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases you can run &amp;lt;code&amp;gt;yambopy l2y ...&amp;lt;/code&amp;gt; with the &amp;lt;code&amp;gt;--no_gkkp&amp;lt;/code&amp;gt; option.&lt;br /&gt;
* If you don&#039;t need the default &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; databases you can run &amp;lt;code&amp;gt;yambopy l2y ...&amp;lt;/code&amp;gt; with the &amp;lt;code&amp;gt;--no_lelphc_dbs&amp;lt;/code&amp;gt; option.&lt;br /&gt;
&lt;br /&gt;
However, for this tutorial, we will take a look at both databases, so let&#039;s run:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph dvscf/mos2.dvscf -b 25 28 -par 4 2 -lelphc path/to/lelphc_exe&lt;br /&gt;
&lt;br /&gt;
We include the last two valence bands of monolayer MoS2 (25 and 26) and the first two conduction bands (27 and 28). If your &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable is in the &amp;lt;code&amp;gt;PATH&amp;lt;/code&amp;gt;, you do not need to specify the last flag.&lt;br /&gt;
&lt;br /&gt;
At the end, check your directory: you should find the &amp;lt;code&amp;gt;lelphc.in&amp;lt;/code&amp;gt; input file that was run, let&#039;s inspect it: &lt;br /&gt;
&lt;br /&gt;
 # LetzElPhC input for yambo generated by yambopy&lt;br /&gt;
 nqpool      = 2&lt;br /&gt;
 nkpool      = 4&lt;br /&gt;
 start_bnd   = 25&lt;br /&gt;
 end_bnd     = 28&lt;br /&gt;
 save_dir    = ./SAVE&lt;br /&gt;
 kernel      = dfpt&lt;br /&gt;
 ph_save_dir = dvscf/ph_save&lt;br /&gt;
 convention = yambo&lt;br /&gt;
&lt;br /&gt;
Notice the variable &amp;lt;code&amp;gt;convention=yambo&amp;lt;/code&amp;gt;: what does it mean? At variance with QE and many other codes, Yambo uses the &amp;quot;backward&amp;quot; momentum transfer convention for electronic scatterings. That is, an electronic transition goes from band &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; and momentum &amp;lt;math&amp;gt;k-q&amp;lt;/math&amp;gt; to band &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; and momentum &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;. In the &amp;quot;forward&amp;quot; momentum transfer convention (the more standard one), the transitions go from &amp;lt;math&amp;gt;nk&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;mk+q&amp;lt;/math&amp;gt;. Therefore, this variable ensures that the electron-phonon coupling matrix elements are computed as &amp;lt;math&amp;gt;\langle mk|dV|nk-q\rangle&amp;lt;/math&amp;gt;. However, do not worry: Yambopy can automatically switch between the two conventions when loading the LetzElPhC databases.&lt;br /&gt;
&lt;br /&gt;
You will also find a &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; database that contains the computed electron-phonon matrix elements, in the output format of &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In addition, if you check the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; folder:&lt;br /&gt;
&lt;br /&gt;
 ls SAVE/ndb.elph_gkkp*&lt;br /&gt;
&lt;br /&gt;
you will see that yambopy has created the Yambo-compatible electron-phonon databases and placed them inside the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If you want to run LetzElPhC directly, without using yambopy, you can refer to its [[https://gitlab.com/lumen-code/LetzElPhC/-/blob/main/docs/main.pdf?ref_type=heads|user guide]].&lt;br /&gt;
Keep in mind that in this case, in order to convert the database to the &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases of Yambo, you will then need a couple of lines of python using the Yambopy class &amp;lt;code&amp;gt;ConvertElectronPhononDB&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;yambopy/letzelph_interface/lelph2y.py&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
At the end of this section, you should have produced the same databases that you find in the main &amp;lt;code&amp;gt;electron_phonon&amp;lt;/code&amp;gt; folder. You can run the following part either in the directory where you are (by copying the python scripts here), or by going back:&lt;br /&gt;
&lt;br /&gt;
 $cd ..&lt;br /&gt;
&lt;br /&gt;
and using the original ones.&lt;br /&gt;
&lt;br /&gt;
=== Electron-phonon intro: plots of el-ph matrix elements on k-BZ and q-BZ ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Loading electron-phonon matrix elements: Yambo ===&lt;br /&gt;
You may have seen how to calculate and import electron-phonon matrix elements in yambo in the [[Electron Phonon Coupling|electron-phonon tutorial]].&lt;br /&gt;
&lt;br /&gt;
With Yambopy, we can generate a yambo SAVE folder and import the matrix elements with a single command.&lt;br /&gt;
Typing &lt;br /&gt;
 $yambopy gkkp&lt;br /&gt;
will print the necessary documentation:&lt;br /&gt;
 Produce a SAVE folder including elph_gkkp databases&lt;br /&gt;
 &lt;br /&gt;
 Arguments are:&lt;br /&gt;
   -nscf, --nscf_dir  -&amp;gt; &amp;lt;Optional&amp;gt; Path to nscf save folder&lt;br /&gt;
   -elph, --elph_dir  -&amp;gt; Path to elph_dir folder&lt;br /&gt;
   -y, --yambo_dir    -&amp;gt; &amp;lt;Optional&amp;gt; Path to yambo executables&lt;br /&gt;
   -e, --expand       -&amp;gt; &amp;lt;Optional&amp;gt; Expand gkkp databases&lt;br /&gt;
&lt;br /&gt;
The necessary quantum espresso databases are stored in &amp;lt;code&amp;gt;ELPH_SAVES/QE_SAVES/hBN.save&amp;lt;/code&amp;gt; (nscf calculation) and &amp;lt;code&amp;gt;ELPH_SAVES/QE_SAVES/elph_dir&amp;lt;/code&amp;gt; (matrix elements from the dfpt calculation). For this tutorial we also need to expand the electron-phonon matrix elements to the full Brillouin zone. Since this is a different calculation with respect to the previous section, please generate this SAVE in a different directory than the one you used for the previous SAVE, which should be the current directory.&lt;br /&gt;
For example:&lt;br /&gt;
 $mkdir yambo-with-elph&lt;br /&gt;
 $cd yambo-with-elph&lt;br /&gt;
&lt;br /&gt;
Now we can run yambopy as in the instructions:&lt;br /&gt;
 $yambopy gkkp -nscf ../ELPH_saves/QE_saves/hBN.save -elph ../ELPH_saves/QE_saves/elph_dir --expand&lt;br /&gt;
This should generate a yambo SAVE folder which contains the &amp;lt;code&amp;gt;ndb.elph_gkkp_expanded*&amp;lt;/code&amp;gt; databases.&lt;br /&gt;
&lt;br /&gt;
=== Electron-phonon intro old: plots of el-ph matrix elements on k-BZ and q-BZ ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; and read the electron-phonon databases that you generated in the previous section.&lt;br /&gt;
&lt;br /&gt;
In order to read the &amp;lt;code&amp;gt;ndb.elph_gkkp_expanded*&amp;lt;/code&amp;gt; databases in python we use the Yambopy class &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
 yelph = YamboElectronPhononDB(ylat,folder_gkkp=&#039;path/to/elph/folder&#039;,save=&#039;path/to/SAVE&#039;)&lt;br /&gt;
(notice that it requires a previous instance of &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Now, the &amp;lt;code&amp;gt;yelph&amp;lt;/code&amp;gt; object contains phonon frequencies, phonon eigenvectors, qpoint information and, of course, the electron-phonon matrix elements g_{nm\nu}(k,q) where n, m are electron band states, \nu is a phonon branch, and k and q are the electronic and transfer momenta.&lt;br /&gt;
&lt;br /&gt;
We can print the docstring of the &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt; class with&lt;br /&gt;
 print(yelph.__doc__)&lt;br /&gt;
to get an idea of the information stored and of its capabilities.&lt;br /&gt;
&lt;br /&gt;
Now check the &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; script. You will see that it performs two plots: &lt;br /&gt;
* Plot of |g(k)| in the k-BZ for selected n,m,\nu and q [&amp;lt;code&amp;gt;Kspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Plot of |g(q)| in the q-BZ for selected n,m,\nu and k [&amp;lt;code&amp;gt;Qspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
You can change the electronic, phononic and momentum indices to see what happens.&lt;br /&gt;
&lt;br /&gt;
[[File:Elph hbn.jpg|YamboElectronPhononDB plot from yambopy tutorial|500px]]&lt;/div&gt;</summary>
		<author><name>FulvioPaleari</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_electron-phonon_coupling&amp;diff=9319</id>
		<title>Yambopy tutorial: electron-phonon coupling</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_electron-phonon_coupling&amp;diff=9319"/>
		<updated>2026-03-10T10:43:16Z</updated>

		<summary type="html">&lt;p&gt;FulvioPaleari: /* Command line: electron-phonon calculation and databases */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial we will cover the handling of electron-phonon coupling matrix elements by Yambopy. The electron-phonon calculation follows two steps:&lt;br /&gt;
&lt;br /&gt;
# Quantum Espresso calculation of phonon energies, eigenmodes and variations of the self-consistent potential via &amp;lt;code&amp;gt;ph.x&amp;lt;/code&amp;gt;.&lt;br /&gt;
# Electron-phonon matrix element calculation, symmetry expansion and conversion by the &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For more information on the &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; code and how you should run step 1., please see the related documentation [https://github.com/yambo-code/LetzElPhC here].&lt;br /&gt;
&lt;br /&gt;
We can use Yambopy to:&lt;br /&gt;
* Run &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; (both preprocessing and main run) without explicitly writing an input file.&lt;br /&gt;
* Convert the resulting databases into &amp;lt;code&amp;gt;Yambo&amp;lt;/code&amp;gt; format.&lt;br /&gt;
* Analyse the electron-phonon coupling both in &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;Yambo&amp;lt;/code&amp;gt; format.&lt;br /&gt;
&lt;br /&gt;
The scripts of the tutorial, but not the databases, can be found in the yambopy directory:&lt;br /&gt;
 $cd tutorial/electron_phonon&lt;br /&gt;
&lt;br /&gt;
The full tutorial, including the LetzElPhC and Yambo databases that we will read, can be downloaded and extracted from the yambo website:&lt;br /&gt;
 $wget https://media.yambo-code.eu/educational/tutorials/files/electron_phonon.tar.gz&lt;br /&gt;
 $tar -xvzf electron_phonon.tar.gz&lt;br /&gt;
 $cd electron_phonon&lt;br /&gt;
&lt;br /&gt;
We will work with monolayer molybdenum disulphide electron-phonon data obtained on a &amp;lt;code&amp;gt;6x6x1&amp;lt;/code&amp;gt; kpoint grid, including spin-orbit interaction (so we deal with electron-phonon coupling and spinorial wavefunctions). Beware that the parameters are most certainly not converged.&lt;br /&gt;
&lt;br /&gt;
=== Command line: electron-phonon calculation and databases ===&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&#039;&#039;&#039;Note&#039;&#039;&#039;: you can run this step only if you have compiled &#039;&#039;&#039;LetzElPhC&#039;&#039;&#039; on your machine. If not, please skip to the following sections of the tutorial, as the electron-phonon coupling databases are already provided in the .tar.gz file and you don&#039;t need to explicitly recalculate them.&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let us assume that we have run a quantum espresso phonon calculation as per step 1. above. You will find the results in the &amp;lt;code&amp;gt;dvscf&amp;lt;/code&amp;gt; directory. We also have done a non-self-consistent calculation to be used in Yambo, and created the relative &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory.&lt;br /&gt;
 &lt;br /&gt;
Now, we aim to reconstruct the electron-phonon coupling matrix elements from the phonon energies, modes and potential variations (in &amp;lt;code&amp;gt;dvscf&amp;lt;/code&amp;gt;) and the Bloch electronic wavefunctions used by Yambo (in &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
In order to do this, we will run the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable of the &#039;&#039;&#039;LetzElPhC&#039;&#039;&#039; code. We will run via command line using yambopy, although it will be instructive to have look at the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; input files later.&lt;br /&gt;
&lt;br /&gt;
We run in the same directory where the Yambo &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; is (remember than you can also virtually move it with a symbolic link).&lt;br /&gt;
&lt;br /&gt;
Type:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y&lt;br /&gt;
&lt;br /&gt;
to see the help for the calculation. Have a look at the various flags and their description.&lt;br /&gt;
For example, if we want to do a serial run of LetzElPhC for bands from &amp;lt;math&amp;gt;n_i&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;n_f&amp;lt;/math&amp;gt;, we should type:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph path/of/ph_input.in -b n_i n_f&lt;br /&gt;
&lt;br /&gt;
Here &amp;lt;math&amp;gt;n_i&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;n_f&amp;lt;/math&amp;gt; are integers representing the initial and final band indices. &#039;&#039;&#039;Please note&#039;&#039;&#039;: in this case, the band index starts from 1 and the the interval of bands read by the code is &amp;lt;math&amp;gt;[n_i,n_f]&amp;lt;/math&amp;gt; including the extrema of the interval. &lt;br /&gt;
&lt;br /&gt;
For our system, we want to do a parallel calculation: 4 MPI tasks on q-point loop (phonon momenta) and 2 MPI tasks on the k-point loop (electron momenta). In addition, we want to explicitly specify the path of the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable. &lt;br /&gt;
&lt;br /&gt;
We have a final choice to make. We can ask Yambopy to produce the default LetzElPhC electron-phonon databases, or to convert them in Yambo-compatible format. By the default, both will be printed. &lt;br /&gt;
&lt;br /&gt;
* If you don&#039;t need the Yambo-style &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases you can run &amp;lt;code&amp;gt;yambopy l2y ...&amp;lt;/code&amp;gt; with the &amp;lt;code&amp;gt;--no_gkkp&amp;lt;/code&amp;gt; option.&lt;br /&gt;
* If you don&#039;t need the default &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; databases you can run &amp;lt;code&amp;gt;yambopy l2y ...&amp;lt;/code&amp;gt; with the &amp;lt;code&amp;gt;--no_lelphc_dbs&amp;lt;/code&amp;gt; option.&lt;br /&gt;
&lt;br /&gt;
However, for this tutorial, we will take a look at both databases, so let&#039;s run:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph dvscf/mos2.dvscf -b 25 28 -par 4 2 -lelphc path/to/lelphc_exe&lt;br /&gt;
&lt;br /&gt;
We include the last two valence bands of monolayer MoS2 (25 and 26) and the first two conduction bands (27 and 28). If your &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable is in the &amp;lt;code&amp;gt;PATH&amp;lt;/code&amp;gt;, you do not need to specify the last flag.&lt;br /&gt;
&lt;br /&gt;
At the end, check your directory: you should find the &amp;lt;code&amp;gt;lelphc.in&amp;lt;/code&amp;gt; input file that was run, let&#039;s inspect it: &lt;br /&gt;
&lt;br /&gt;
 # LetzElPhC input for yambo generated by yambopy&lt;br /&gt;
 nqpool      = 2&lt;br /&gt;
 nkpool      = 4&lt;br /&gt;
 start_bnd   = 25&lt;br /&gt;
 end_bnd     = 28&lt;br /&gt;
 save_dir    = ./SAVE&lt;br /&gt;
 kernel      = dfpt&lt;br /&gt;
 ph_save_dir = dvscf/ph_save&lt;br /&gt;
 convention = yambo&lt;br /&gt;
&lt;br /&gt;
Notice the variable &amp;lt;code&amp;gt;convention=yambo&amp;lt;/code&amp;gt;: what does it mean? At variance with QE and many other codes, Yambo uses the &amp;quot;backward&amp;quot; momentum transfer convention for electronic scatterings. That is, an electronic transition goes from band &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; and momentum &amp;lt;math&amp;gt;k-q&amp;lt;/math&amp;gt; to band &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; and momentum &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;. In the &amp;quot;forward&amp;quot; momentum transfer convention (the more standard one), the transitions go from &amp;lt;math&amp;gt;nk&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;mk+q&amp;lt;/math&amp;gt;. Therefore, this variable ensures that the electron-phonon coupling matrix elements are computed as &amp;lt;math&amp;gt;\langle mk|dV|nk-q\rangle&amp;lt;/math&amp;gt;. However, do not worry: Yambopy can automatically switch between the two conventions when loading the LetzElPhC databases.&lt;br /&gt;
&lt;br /&gt;
You will also find a &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; database that contains the computed electron-phonon matrix elements, in the output format of &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In addition, if you check the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; folder:&lt;br /&gt;
&lt;br /&gt;
 ls SAVE/ndb.elph_gkkp*&lt;br /&gt;
&lt;br /&gt;
you will see that yambopy has created the Yambo-compatible electron-phonon databases and placed them inside the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If you want to run LetzElPhC directly, without using yambopy, you can refer to its [[https://gitlab.com/lumen-code/LetzElPhC/-/blob/main/docs/main.pdf?ref_type=heads|user guide]].&lt;br /&gt;
Keep in mind that in this case, in order to convert the database to the &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases of Yambo, you will then need a couple of lines of python using the Yambopy class &amp;lt;code&amp;gt;ConvertElectronPhononDB&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;yambopy/letzelph_interface/lelph2y.py&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Electron-phonon intro: plots of el-ph matrix elements on k-BZ and q-BZ ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Loading electron-phonon matrix elements: Yambo ===&lt;br /&gt;
You may have seen how to calculate and import electron-phonon matrix elements in yambo in the [[Electron Phonon Coupling|electron-phonon tutorial]].&lt;br /&gt;
&lt;br /&gt;
With Yambopy, we can generate a yambo SAVE folder and import the matrix elements with a single command.&lt;br /&gt;
Typing &lt;br /&gt;
 $yambopy gkkp&lt;br /&gt;
will print the necessary documentation:&lt;br /&gt;
 Produce a SAVE folder including elph_gkkp databases&lt;br /&gt;
 &lt;br /&gt;
 Arguments are:&lt;br /&gt;
   -nscf, --nscf_dir  -&amp;gt; &amp;lt;Optional&amp;gt; Path to nscf save folder&lt;br /&gt;
   -elph, --elph_dir  -&amp;gt; Path to elph_dir folder&lt;br /&gt;
   -y, --yambo_dir    -&amp;gt; &amp;lt;Optional&amp;gt; Path to yambo executables&lt;br /&gt;
   -e, --expand       -&amp;gt; &amp;lt;Optional&amp;gt; Expand gkkp databases&lt;br /&gt;
&lt;br /&gt;
The necessary quantum espresso databases are stored in &amp;lt;code&amp;gt;ELPH_SAVES/QE_SAVES/hBN.save&amp;lt;/code&amp;gt; (nscf calculation) and &amp;lt;code&amp;gt;ELPH_SAVES/QE_SAVES/elph_dir&amp;lt;/code&amp;gt; (matrix elements from the dfpt calculation). For this tutorial we also need to expand the electron-phonon matrix elements to the full Brillouin zone. Since this is a different calculation with respect to the previous section, please generate this SAVE in a different directory than the one you used for the previous SAVE, which should be the current directory.&lt;br /&gt;
For example:&lt;br /&gt;
 $mkdir yambo-with-elph&lt;br /&gt;
 $cd yambo-with-elph&lt;br /&gt;
&lt;br /&gt;
Now we can run yambopy as in the instructions:&lt;br /&gt;
 $yambopy gkkp -nscf ../ELPH_saves/QE_saves/hBN.save -elph ../ELPH_saves/QE_saves/elph_dir --expand&lt;br /&gt;
This should generate a yambo SAVE folder which contains the &amp;lt;code&amp;gt;ndb.elph_gkkp_expanded*&amp;lt;/code&amp;gt; databases.&lt;br /&gt;
&lt;br /&gt;
=== Electron-phonon intro old: plots of el-ph matrix elements on k-BZ and q-BZ ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; and read the electron-phonon databases that you generated in the previous section.&lt;br /&gt;
&lt;br /&gt;
In order to read the &amp;lt;code&amp;gt;ndb.elph_gkkp_expanded*&amp;lt;/code&amp;gt; databases in python we use the Yambopy class &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
 yelph = YamboElectronPhononDB(ylat,folder_gkkp=&#039;path/to/elph/folder&#039;,save=&#039;path/to/SAVE&#039;)&lt;br /&gt;
(notice that it requires a previous instance of &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Now, the &amp;lt;code&amp;gt;yelph&amp;lt;/code&amp;gt; object contains phonon frequencies, phonon eigenvectors, qpoint information and, of course, the electron-phonon matrix elements g_{nm\nu}(k,q) where n, m are electron band states, \nu is a phonon branch, and k and q are the electronic and transfer momenta.&lt;br /&gt;
&lt;br /&gt;
We can print the docstring of the &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt; class with&lt;br /&gt;
 print(yelph.__doc__)&lt;br /&gt;
to get an idea of the information stored and of its capabilities.&lt;br /&gt;
&lt;br /&gt;
Now check the &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; script. You will see that it performs two plots: &lt;br /&gt;
* Plot of |g(k)| in the k-BZ for selected n,m,\nu and q [&amp;lt;code&amp;gt;Kspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Plot of |g(q)| in the q-BZ for selected n,m,\nu and k [&amp;lt;code&amp;gt;Qspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
You can change the electronic, phononic and momentum indices to see what happens.&lt;br /&gt;
&lt;br /&gt;
[[File:Elph hbn.jpg|YamboElectronPhononDB plot from yambopy tutorial|500px]]&lt;/div&gt;</summary>
		<author><name>FulvioPaleari</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_electron-phonon_coupling&amp;diff=9318</id>
		<title>Yambopy tutorial: electron-phonon coupling</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_electron-phonon_coupling&amp;diff=9318"/>
		<updated>2026-03-10T10:42:50Z</updated>

		<summary type="html">&lt;p&gt;FulvioPaleari: /* Command line: electron-phonon calculation and databases */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial we will cover the handling of electron-phonon coupling matrix elements by Yambopy. The electron-phonon calculation follows two steps:&lt;br /&gt;
&lt;br /&gt;
# Quantum Espresso calculation of phonon energies, eigenmodes and variations of the self-consistent potential via &amp;lt;code&amp;gt;ph.x&amp;lt;/code&amp;gt;.&lt;br /&gt;
# Electron-phonon matrix element calculation, symmetry expansion and conversion by the &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For more information on the &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; code and how you should run step 1., please see the related documentation [https://github.com/yambo-code/LetzElPhC here].&lt;br /&gt;
&lt;br /&gt;
We can use Yambopy to:&lt;br /&gt;
* Run &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; (both preprocessing and main run) without explicitly writing an input file.&lt;br /&gt;
* Convert the resulting databases into &amp;lt;code&amp;gt;Yambo&amp;lt;/code&amp;gt; format.&lt;br /&gt;
* Analyse the electron-phonon coupling both in &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;Yambo&amp;lt;/code&amp;gt; format.&lt;br /&gt;
&lt;br /&gt;
The scripts of the tutorial, but not the databases, can be found in the yambopy directory:&lt;br /&gt;
 $cd tutorial/electron_phonon&lt;br /&gt;
&lt;br /&gt;
The full tutorial, including the LetzElPhC and Yambo databases that we will read, can be downloaded and extracted from the yambo website:&lt;br /&gt;
 $wget https://media.yambo-code.eu/educational/tutorials/files/electron_phonon.tar.gz&lt;br /&gt;
 $tar -xvzf electron_phonon.tar.gz&lt;br /&gt;
 $cd electron_phonon&lt;br /&gt;
&lt;br /&gt;
We will work with monolayer molybdenum disulphide electron-phonon data obtained on a &amp;lt;code&amp;gt;6x6x1&amp;lt;/code&amp;gt; kpoint grid, including spin-orbit interaction (so we deal with electron-phonon coupling and spinorial wavefunctions). Beware that the parameters are most certainly not converged.&lt;br /&gt;
&lt;br /&gt;
=== Command line: electron-phonon calculation and databases ===&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&#039;&#039;&#039;Note&#039;&#039;&#039;: you can run this step only if you have compiled &#039;&#039;&#039;LetzElPhC&#039;&#039;&#039; on your machine. If not, please skip to the following sections of the tutorial, as the electron-phonon coupling databases are already provided in the .tar.gz file.&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let us assume that we have run a quantum espresso phonon calculation as per step 1. above. You will find the results in the &amp;lt;code&amp;gt;dvscf&amp;lt;/code&amp;gt; directory. We also have done a non-self-consistent calculation to be used in Yambo, and created the relative &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory.&lt;br /&gt;
 &lt;br /&gt;
Now, we aim to reconstruct the electron-phonon coupling matrix elements from the phonon energies, modes and potential variations (in &amp;lt;code&amp;gt;dvscf&amp;lt;/code&amp;gt;) and the Bloch electronic wavefunctions used by Yambo (in &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
In order to do this, we will run the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable of the &#039;&#039;&#039;LetzElPhC&#039;&#039;&#039; code. We will run via command line using yambopy, although it will be instructive to have look at the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; input files later.&lt;br /&gt;
&lt;br /&gt;
We run in the same directory where the Yambo &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; is (remember than you can also virtually move it with a symbolic link).&lt;br /&gt;
&lt;br /&gt;
Type:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y&lt;br /&gt;
&lt;br /&gt;
to see the help for the calculation. Have a look at the various flags and their description.&lt;br /&gt;
For example, if we want to do a serial run of LetzElPhC for bands from &amp;lt;math&amp;gt;n_i&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;n_f&amp;lt;/math&amp;gt;, we should type:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph path/of/ph_input.in -b n_i n_f&lt;br /&gt;
&lt;br /&gt;
Here &amp;lt;math&amp;gt;n_i&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;n_f&amp;lt;/math&amp;gt; are integers representing the initial and final band indices. &#039;&#039;&#039;Please note&#039;&#039;&#039;: in this case, the band index starts from 1 and the the interval of bands read by the code is &amp;lt;math&amp;gt;[n_i,n_f]&amp;lt;/math&amp;gt; including the extrema of the interval. &lt;br /&gt;
&lt;br /&gt;
For our system, we want to do a parallel calculation: 4 MPI tasks on q-point loop (phonon momenta) and 2 MPI tasks on the k-point loop (electron momenta). In addition, we want to explicitly specify the path of the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable. &lt;br /&gt;
&lt;br /&gt;
We have a final choice to make. We can ask Yambopy to produce the default LetzElPhC electron-phonon databases, or to convert them in Yambo-compatible format. By the default, both will be printed. &lt;br /&gt;
&lt;br /&gt;
* If you don&#039;t need the Yambo-style &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases you can run &amp;lt;code&amp;gt;yambopy l2y ...&amp;lt;/code&amp;gt; with the &amp;lt;code&amp;gt;--no_gkkp&amp;lt;/code&amp;gt; option.&lt;br /&gt;
* If you don&#039;t need the default &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; databases you can run &amp;lt;code&amp;gt;yambopy l2y ...&amp;lt;/code&amp;gt; with the &amp;lt;code&amp;gt;--no_lelphc_dbs&amp;lt;/code&amp;gt; option.&lt;br /&gt;
&lt;br /&gt;
However, for this tutorial, we will take a look at both databases, so let&#039;s run:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph dvscf/mos2.dvscf -b 25 28 -par 4 2 -lelphc path/to/lelphc_exe&lt;br /&gt;
&lt;br /&gt;
We include the last two valence bands of monolayer MoS2 (25 and 26) and the first two conduction bands (27 and 28). If your &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable is in the &amp;lt;code&amp;gt;PATH&amp;lt;/code&amp;gt;, you do not need to specify the last flag.&lt;br /&gt;
&lt;br /&gt;
At the end, check your directory: you should find the &amp;lt;code&amp;gt;lelphc.in&amp;lt;/code&amp;gt; input file that was run, let&#039;s inspect it: &lt;br /&gt;
&lt;br /&gt;
 # LetzElPhC input for yambo generated by yambopy&lt;br /&gt;
 nqpool      = 2&lt;br /&gt;
 nkpool      = 4&lt;br /&gt;
 start_bnd   = 25&lt;br /&gt;
 end_bnd     = 28&lt;br /&gt;
 save_dir    = ./SAVE&lt;br /&gt;
 kernel      = dfpt&lt;br /&gt;
 ph_save_dir = dvscf/ph_save&lt;br /&gt;
 convention = yambo&lt;br /&gt;
&lt;br /&gt;
Notice the variable &amp;lt;code&amp;gt;convention=yambo&amp;lt;/code&amp;gt;: what does it mean? At variance with QE and many other codes, Yambo uses the &amp;quot;backward&amp;quot; momentum transfer convention for electronic scatterings. That is, an electronic transition goes from band &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; and momentum &amp;lt;math&amp;gt;k-q&amp;lt;/math&amp;gt; to band &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; and momentum &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;. In the &amp;quot;forward&amp;quot; momentum transfer convention (the more standard one), the transitions go from &amp;lt;math&amp;gt;nk&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;mk+q&amp;lt;/math&amp;gt;. Therefore, this variable ensures that the electron-phonon coupling matrix elements are computed as &amp;lt;math&amp;gt;\langle mk|dV|nk-q\rangle&amp;lt;/math&amp;gt;. However, do not worry: Yambopy can automatically switch between the two conventions when loading the LetzElPhC databases.&lt;br /&gt;
&lt;br /&gt;
You will also find a &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; database that contains the computed electron-phonon matrix elements, in the output format of &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In addition, if you check the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; folder:&lt;br /&gt;
&lt;br /&gt;
 ls SAVE/ndb.elph_gkkp*&lt;br /&gt;
&lt;br /&gt;
you will see that yambopy has created the Yambo-compatible electron-phonon databases and placed them inside the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If you want to run LetzElPhC directly, without using yambopy, you can refer to its [[https://gitlab.com/lumen-code/LetzElPhC/-/blob/main/docs/main.pdf?ref_type=heads|user guide]].&lt;br /&gt;
Keep in mind that in this case, in order to convert the database to the &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases of Yambo, you will then need a couple of lines of python using the Yambopy class &amp;lt;code&amp;gt;ConvertElectronPhononDB&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;yambopy/letzelph_interface/lelph2y.py&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Electron-phonon intro: plots of el-ph matrix elements on k-BZ and q-BZ ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Loading electron-phonon matrix elements: Yambo ===&lt;br /&gt;
You may have seen how to calculate and import electron-phonon matrix elements in yambo in the [[Electron Phonon Coupling|electron-phonon tutorial]].&lt;br /&gt;
&lt;br /&gt;
With Yambopy, we can generate a yambo SAVE folder and import the matrix elements with a single command.&lt;br /&gt;
Typing &lt;br /&gt;
 $yambopy gkkp&lt;br /&gt;
will print the necessary documentation:&lt;br /&gt;
 Produce a SAVE folder including elph_gkkp databases&lt;br /&gt;
 &lt;br /&gt;
 Arguments are:&lt;br /&gt;
   -nscf, --nscf_dir  -&amp;gt; &amp;lt;Optional&amp;gt; Path to nscf save folder&lt;br /&gt;
   -elph, --elph_dir  -&amp;gt; Path to elph_dir folder&lt;br /&gt;
   -y, --yambo_dir    -&amp;gt; &amp;lt;Optional&amp;gt; Path to yambo executables&lt;br /&gt;
   -e, --expand       -&amp;gt; &amp;lt;Optional&amp;gt; Expand gkkp databases&lt;br /&gt;
&lt;br /&gt;
The necessary quantum espresso databases are stored in &amp;lt;code&amp;gt;ELPH_SAVES/QE_SAVES/hBN.save&amp;lt;/code&amp;gt; (nscf calculation) and &amp;lt;code&amp;gt;ELPH_SAVES/QE_SAVES/elph_dir&amp;lt;/code&amp;gt; (matrix elements from the dfpt calculation). For this tutorial we also need to expand the electron-phonon matrix elements to the full Brillouin zone. Since this is a different calculation with respect to the previous section, please generate this SAVE in a different directory than the one you used for the previous SAVE, which should be the current directory.&lt;br /&gt;
For example:&lt;br /&gt;
 $mkdir yambo-with-elph&lt;br /&gt;
 $cd yambo-with-elph&lt;br /&gt;
&lt;br /&gt;
Now we can run yambopy as in the instructions:&lt;br /&gt;
 $yambopy gkkp -nscf ../ELPH_saves/QE_saves/hBN.save -elph ../ELPH_saves/QE_saves/elph_dir --expand&lt;br /&gt;
This should generate a yambo SAVE folder which contains the &amp;lt;code&amp;gt;ndb.elph_gkkp_expanded*&amp;lt;/code&amp;gt; databases.&lt;br /&gt;
&lt;br /&gt;
=== Electron-phonon intro old: plots of el-ph matrix elements on k-BZ and q-BZ ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; and read the electron-phonon databases that you generated in the previous section.&lt;br /&gt;
&lt;br /&gt;
In order to read the &amp;lt;code&amp;gt;ndb.elph_gkkp_expanded*&amp;lt;/code&amp;gt; databases in python we use the Yambopy class &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
 yelph = YamboElectronPhononDB(ylat,folder_gkkp=&#039;path/to/elph/folder&#039;,save=&#039;path/to/SAVE&#039;)&lt;br /&gt;
(notice that it requires a previous instance of &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Now, the &amp;lt;code&amp;gt;yelph&amp;lt;/code&amp;gt; object contains phonon frequencies, phonon eigenvectors, qpoint information and, of course, the electron-phonon matrix elements g_{nm\nu}(k,q) where n, m are electron band states, \nu is a phonon branch, and k and q are the electronic and transfer momenta.&lt;br /&gt;
&lt;br /&gt;
We can print the docstring of the &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt; class with&lt;br /&gt;
 print(yelph.__doc__)&lt;br /&gt;
to get an idea of the information stored and of its capabilities.&lt;br /&gt;
&lt;br /&gt;
Now check the &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; script. You will see that it performs two plots: &lt;br /&gt;
* Plot of |g(k)| in the k-BZ for selected n,m,\nu and q [&amp;lt;code&amp;gt;Kspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Plot of |g(q)| in the q-BZ for selected n,m,\nu and k [&amp;lt;code&amp;gt;Qspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
You can change the electronic, phononic and momentum indices to see what happens.&lt;br /&gt;
&lt;br /&gt;
[[File:Elph hbn.jpg|YamboElectronPhononDB plot from yambopy tutorial|500px]]&lt;/div&gt;</summary>
		<author><name>FulvioPaleari</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_electron-phonon_coupling&amp;diff=9317</id>
		<title>Yambopy tutorial: electron-phonon coupling</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_electron-phonon_coupling&amp;diff=9317"/>
		<updated>2026-03-10T10:42:28Z</updated>

		<summary type="html">&lt;p&gt;FulvioPaleari: /* Command line: electron-phonon calculation and databases */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial we will cover the handling of electron-phonon coupling matrix elements by Yambopy. The electron-phonon calculation follows two steps:&lt;br /&gt;
&lt;br /&gt;
# Quantum Espresso calculation of phonon energies, eigenmodes and variations of the self-consistent potential via &amp;lt;code&amp;gt;ph.x&amp;lt;/code&amp;gt;.&lt;br /&gt;
# Electron-phonon matrix element calculation, symmetry expansion and conversion by the &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For more information on the &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; code and how you should run step 1., please see the related documentation [https://github.com/yambo-code/LetzElPhC here].&lt;br /&gt;
&lt;br /&gt;
We can use Yambopy to:&lt;br /&gt;
* Run &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; (both preprocessing and main run) without explicitly writing an input file.&lt;br /&gt;
* Convert the resulting databases into &amp;lt;code&amp;gt;Yambo&amp;lt;/code&amp;gt; format.&lt;br /&gt;
* Analyse the electron-phonon coupling both in &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;Yambo&amp;lt;/code&amp;gt; format.&lt;br /&gt;
&lt;br /&gt;
The scripts of the tutorial, but not the databases, can be found in the yambopy directory:&lt;br /&gt;
 $cd tutorial/electron_phonon&lt;br /&gt;
&lt;br /&gt;
The full tutorial, including the LetzElPhC and Yambo databases that we will read, can be downloaded and extracted from the yambo website:&lt;br /&gt;
 $wget https://media.yambo-code.eu/educational/tutorials/files/electron_phonon.tar.gz&lt;br /&gt;
 $tar -xvzf electron_phonon.tar.gz&lt;br /&gt;
 $cd electron_phonon&lt;br /&gt;
&lt;br /&gt;
We will work with monolayer molybdenum disulphide electron-phonon data obtained on a &amp;lt;code&amp;gt;6x6x1&amp;lt;/code&amp;gt; kpoint grid, including spin-orbit interaction (so we deal with electron-phonon coupling and spinorial wavefunctions). Beware that the parameters are most certainly not converged.&lt;br /&gt;
&lt;br /&gt;
=== Command line: electron-phonon calculation and databases ===&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&#039;&#039;&#039;Note&#039;&#039;&#039;: you can run this step only if you have compiled &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; on your machine. If not, please skip to the following sections of the tutorial, as the electron-phonon coupling databases are already provided in the .tar.gz file.&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let us assume that we have run a quantum espresso phonon calculation as per step 1. above. You will find the results in the &amp;lt;code&amp;gt;dvscf&amp;lt;/code&amp;gt; directory. We also have done a non-self-consistent calculation to be used in Yambo, and created the relative &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory.&lt;br /&gt;
 &lt;br /&gt;
Now, we aim to reconstruct the electron-phonon coupling matrix elements from the phonon energies, modes and potential variations (in &amp;lt;code&amp;gt;dvscf&amp;lt;/code&amp;gt;) and the Bloch electronic wavefunctions used by Yambo (in &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
In order to do this, we will run the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable of the &#039;&#039;&#039;LetzElPhC&#039;&#039;&#039; code. We will run via command line using yambopy, although it will be instructive to have look at the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; input files later.&lt;br /&gt;
&lt;br /&gt;
We run in the same directory where the Yambo &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; is (remember than you can also virtually move it with a symbolic link).&lt;br /&gt;
&lt;br /&gt;
Type:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y&lt;br /&gt;
&lt;br /&gt;
to see the help for the calculation. Have a look at the various flags and their description.&lt;br /&gt;
For example, if we want to do a serial run of LetzElPhC for bands from &amp;lt;math&amp;gt;n_i&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;n_f&amp;lt;/math&amp;gt;, we should type:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph path/of/ph_input.in -b n_i n_f&lt;br /&gt;
&lt;br /&gt;
Here &amp;lt;math&amp;gt;n_i&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;n_f&amp;lt;/math&amp;gt; are integers representing the initial and final band indices. &#039;&#039;&#039;Please note&#039;&#039;&#039;: in this case, the band index starts from 1 and the the interval of bands read by the code is &amp;lt;math&amp;gt;[n_i,n_f]&amp;lt;/math&amp;gt; including the extrema of the interval. &lt;br /&gt;
&lt;br /&gt;
For our system, we want to do a parallel calculation: 4 MPI tasks on q-point loop (phonon momenta) and 2 MPI tasks on the k-point loop (electron momenta). In addition, we want to explicitly specify the path of the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable. &lt;br /&gt;
&lt;br /&gt;
We have a final choice to make. We can ask Yambopy to produce the default LetzElPhC electron-phonon databases, or to convert them in Yambo-compatible format. By the default, both will be printed. &lt;br /&gt;
&lt;br /&gt;
* If you don&#039;t need the Yambo-style &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases you can run &amp;lt;code&amp;gt;yambopy l2y ...&amp;lt;/code&amp;gt; with the &amp;lt;code&amp;gt;--no_gkkp&amp;lt;/code&amp;gt; option.&lt;br /&gt;
* If you don&#039;t need the default &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; databases you can run &amp;lt;code&amp;gt;yambopy l2y ...&amp;lt;/code&amp;gt; with the &amp;lt;code&amp;gt;--no_lelphc_dbs&amp;lt;/code&amp;gt; option.&lt;br /&gt;
&lt;br /&gt;
However, for this tutorial, we will take a look at both databases, so let&#039;s run:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph dvscf/mos2.dvscf -b 25 28 -par 4 2 -lelphc path/to/lelphc_exe&lt;br /&gt;
&lt;br /&gt;
We include the last two valence bands of monolayer MoS2 (25 and 26) and the first two conduction bands (27 and 28). If your &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable is in the &amp;lt;code&amp;gt;PATH&amp;lt;/code&amp;gt;, you do not need to specify the last flag.&lt;br /&gt;
&lt;br /&gt;
At the end, check your directory: you should find the &amp;lt;code&amp;gt;lelphc.in&amp;lt;/code&amp;gt; input file that was run, let&#039;s inspect it: &lt;br /&gt;
&lt;br /&gt;
 # LetzElPhC input for yambo generated by yambopy&lt;br /&gt;
 nqpool      = 2&lt;br /&gt;
 nkpool      = 4&lt;br /&gt;
 start_bnd   = 25&lt;br /&gt;
 end_bnd     = 28&lt;br /&gt;
 save_dir    = ./SAVE&lt;br /&gt;
 kernel      = dfpt&lt;br /&gt;
 ph_save_dir = dvscf/ph_save&lt;br /&gt;
 convention = yambo&lt;br /&gt;
&lt;br /&gt;
Notice the variable &amp;lt;code&amp;gt;convention=yambo&amp;lt;/code&amp;gt;: what does it mean? At variance with QE and many other codes, Yambo uses the &amp;quot;backward&amp;quot; momentum transfer convention for electronic scatterings. That is, an electronic transition goes from band &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; and momentum &amp;lt;math&amp;gt;k-q&amp;lt;/math&amp;gt; to band &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; and momentum &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;. In the &amp;quot;forward&amp;quot; momentum transfer convention (the more standard one), the transitions go from &amp;lt;math&amp;gt;nk&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;mk+q&amp;lt;/math&amp;gt;. Therefore, this variable ensures that the electron-phonon coupling matrix elements are computed as &amp;lt;math&amp;gt;\langle mk|dV|nk-q\rangle&amp;lt;/math&amp;gt;. However, do not worry: Yambopy can automatically switch between the two conventions when loading the LetzElPhC databases.&lt;br /&gt;
&lt;br /&gt;
You will also find a &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; database that contains the computed electron-phonon matrix elements, in the output format of &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In addition, if you check the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; folder:&lt;br /&gt;
&lt;br /&gt;
 ls SAVE/ndb.elph_gkkp*&lt;br /&gt;
&lt;br /&gt;
you will see that yambopy has created the Yambo-compatible electron-phonon databases and placed them inside the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If you want to run LetzElPhC directly, without using yambopy, you can refer to its [[https://gitlab.com/lumen-code/LetzElPhC/-/blob/main/docs/main.pdf?ref_type=heads|user guide]].&lt;br /&gt;
Keep in mind that in this case, in order to convert the database to the &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases of Yambo, you will then need a couple of lines of python using the Yambopy class &amp;lt;code&amp;gt;ConvertElectronPhononDB&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;yambopy/letzelph_interface/lelph2y.py&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Electron-phonon intro: plots of el-ph matrix elements on k-BZ and q-BZ ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Loading electron-phonon matrix elements: Yambo ===&lt;br /&gt;
You may have seen how to calculate and import electron-phonon matrix elements in yambo in the [[Electron Phonon Coupling|electron-phonon tutorial]].&lt;br /&gt;
&lt;br /&gt;
With Yambopy, we can generate a yambo SAVE folder and import the matrix elements with a single command.&lt;br /&gt;
Typing &lt;br /&gt;
 $yambopy gkkp&lt;br /&gt;
will print the necessary documentation:&lt;br /&gt;
 Produce a SAVE folder including elph_gkkp databases&lt;br /&gt;
 &lt;br /&gt;
 Arguments are:&lt;br /&gt;
   -nscf, --nscf_dir  -&amp;gt; &amp;lt;Optional&amp;gt; Path to nscf save folder&lt;br /&gt;
   -elph, --elph_dir  -&amp;gt; Path to elph_dir folder&lt;br /&gt;
   -y, --yambo_dir    -&amp;gt; &amp;lt;Optional&amp;gt; Path to yambo executables&lt;br /&gt;
   -e, --expand       -&amp;gt; &amp;lt;Optional&amp;gt; Expand gkkp databases&lt;br /&gt;
&lt;br /&gt;
The necessary quantum espresso databases are stored in &amp;lt;code&amp;gt;ELPH_SAVES/QE_SAVES/hBN.save&amp;lt;/code&amp;gt; (nscf calculation) and &amp;lt;code&amp;gt;ELPH_SAVES/QE_SAVES/elph_dir&amp;lt;/code&amp;gt; (matrix elements from the dfpt calculation). For this tutorial we also need to expand the electron-phonon matrix elements to the full Brillouin zone. Since this is a different calculation with respect to the previous section, please generate this SAVE in a different directory than the one you used for the previous SAVE, which should be the current directory.&lt;br /&gt;
For example:&lt;br /&gt;
 $mkdir yambo-with-elph&lt;br /&gt;
 $cd yambo-with-elph&lt;br /&gt;
&lt;br /&gt;
Now we can run yambopy as in the instructions:&lt;br /&gt;
 $yambopy gkkp -nscf ../ELPH_saves/QE_saves/hBN.save -elph ../ELPH_saves/QE_saves/elph_dir --expand&lt;br /&gt;
This should generate a yambo SAVE folder which contains the &amp;lt;code&amp;gt;ndb.elph_gkkp_expanded*&amp;lt;/code&amp;gt; databases.&lt;br /&gt;
&lt;br /&gt;
=== Electron-phonon intro old: plots of el-ph matrix elements on k-BZ and q-BZ ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; and read the electron-phonon databases that you generated in the previous section.&lt;br /&gt;
&lt;br /&gt;
In order to read the &amp;lt;code&amp;gt;ndb.elph_gkkp_expanded*&amp;lt;/code&amp;gt; databases in python we use the Yambopy class &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
 yelph = YamboElectronPhononDB(ylat,folder_gkkp=&#039;path/to/elph/folder&#039;,save=&#039;path/to/SAVE&#039;)&lt;br /&gt;
(notice that it requires a previous instance of &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Now, the &amp;lt;code&amp;gt;yelph&amp;lt;/code&amp;gt; object contains phonon frequencies, phonon eigenvectors, qpoint information and, of course, the electron-phonon matrix elements g_{nm\nu}(k,q) where n, m are electron band states, \nu is a phonon branch, and k and q are the electronic and transfer momenta.&lt;br /&gt;
&lt;br /&gt;
We can print the docstring of the &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt; class with&lt;br /&gt;
 print(yelph.__doc__)&lt;br /&gt;
to get an idea of the information stored and of its capabilities.&lt;br /&gt;
&lt;br /&gt;
Now check the &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; script. You will see that it performs two plots: &lt;br /&gt;
* Plot of |g(k)| in the k-BZ for selected n,m,\nu and q [&amp;lt;code&amp;gt;Kspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Plot of |g(q)| in the q-BZ for selected n,m,\nu and k [&amp;lt;code&amp;gt;Qspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
You can change the electronic, phononic and momentum indices to see what happens.&lt;br /&gt;
&lt;br /&gt;
[[File:Elph hbn.jpg|YamboElectronPhononDB plot from yambopy tutorial|500px]]&lt;/div&gt;</summary>
		<author><name>FulvioPaleari</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_electron-phonon_coupling&amp;diff=9316</id>
		<title>Yambopy tutorial: electron-phonon coupling</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_electron-phonon_coupling&amp;diff=9316"/>
		<updated>2026-03-10T10:41:41Z</updated>

		<summary type="html">&lt;p&gt;FulvioPaleari: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial we will cover the handling of electron-phonon coupling matrix elements by Yambopy. The electron-phonon calculation follows two steps:&lt;br /&gt;
&lt;br /&gt;
# Quantum Espresso calculation of phonon energies, eigenmodes and variations of the self-consistent potential via &amp;lt;code&amp;gt;ph.x&amp;lt;/code&amp;gt;.&lt;br /&gt;
# Electron-phonon matrix element calculation, symmetry expansion and conversion by the &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For more information on the &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; code and how you should run step 1., please see the related documentation [https://github.com/yambo-code/LetzElPhC here].&lt;br /&gt;
&lt;br /&gt;
We can use Yambopy to:&lt;br /&gt;
* Run &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; (both preprocessing and main run) without explicitly writing an input file.&lt;br /&gt;
* Convert the resulting databases into &amp;lt;code&amp;gt;Yambo&amp;lt;/code&amp;gt; format.&lt;br /&gt;
* Analyse the electron-phonon coupling both in &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;Yambo&amp;lt;/code&amp;gt; format.&lt;br /&gt;
&lt;br /&gt;
The scripts of the tutorial, but not the databases, can be found in the yambopy directory:&lt;br /&gt;
 $cd tutorial/electron_phonon&lt;br /&gt;
&lt;br /&gt;
The full tutorial, including the LetzElPhC and Yambo databases that we will read, can be downloaded and extracted from the yambo website:&lt;br /&gt;
 $wget https://media.yambo-code.eu/educational/tutorials/files/electron_phonon.tar.gz&lt;br /&gt;
 $tar -xvzf electron_phonon.tar.gz&lt;br /&gt;
 $cd electron_phonon&lt;br /&gt;
&lt;br /&gt;
We will work with monolayer molybdenum disulphide electron-phonon data obtained on a &amp;lt;code&amp;gt;6x6x1&amp;lt;/code&amp;gt; kpoint grid, including spin-orbit interaction (so we deal with electron-phonon coupling and spinorial wavefunctions). Beware that the parameters are most certainly not converged.&lt;br /&gt;
&lt;br /&gt;
=== Command line: electron-phonon calculation and databases ===&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: you can run this step only if you have compiled &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; on your machine. If not, please skip to the following sections of the tutorial, as the electron-phonon coupling databases are already provided in the .tar.gz file.&lt;br /&gt;
&lt;br /&gt;
Let us assume that we have run a quantum espresso phonon calculation as per step 1. above. You will find the results in the &amp;lt;code&amp;gt;dvscf&amp;lt;/code&amp;gt; directory. We also have done a non-self-consistent calculation to be used in Yambo, and created the relative &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory.&lt;br /&gt;
 &lt;br /&gt;
Now, we aim to reconstruct the electron-phonon coupling matrix elements from the phonon energies, modes and potential variations (in &amp;lt;code&amp;gt;dvscf&amp;lt;/code&amp;gt;) and the Bloch electronic wavefunctions used by Yambo (in &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
In order to do this, we will run the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable of the &#039;&#039;&#039;LetzElPhC&#039;&#039;&#039; code. We will run via command line using yambopy, although it will be instructive to have look at the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; input files later.&lt;br /&gt;
&lt;br /&gt;
We run in the same directory where the Yambo &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; is (remember than you can also virtually move it with a symbolic link).&lt;br /&gt;
&lt;br /&gt;
Type:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y&lt;br /&gt;
&lt;br /&gt;
to see the help for the calculation. Have a look at the various flags and their description.&lt;br /&gt;
For example, if we want to do a serial run of LetzElPhC for bands from &amp;lt;math&amp;gt;n_i&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;n_f&amp;lt;/math&amp;gt;, we should type:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph path/of/ph_input.in -b n_i n_f&lt;br /&gt;
&lt;br /&gt;
Here &amp;lt;math&amp;gt;n_i&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;n_f&amp;lt;/math&amp;gt; are integers representing the initial and final band indices. &#039;&#039;&#039;Please note&#039;&#039;&#039;: in this case, the band index starts from 1 and the the interval of bands read by the code is &amp;lt;math&amp;gt;[n_i,n_f]&amp;lt;/math&amp;gt; including the extrema of the interval. &lt;br /&gt;
&lt;br /&gt;
For our system, we want to do a parallel calculation: 4 MPI tasks on q-point loop (phonon momenta) and 2 MPI tasks on the k-point loop (electron momenta). In addition, we want to explicitly specify the path of the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable. &lt;br /&gt;
&lt;br /&gt;
We have a final choice to make. We can ask Yambopy to produce the default LetzElPhC electron-phonon databases, or to convert them in Yambo-compatible format. By the default, both will be printed. &lt;br /&gt;
&lt;br /&gt;
* If you don&#039;t need the Yambo-style &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases you can run &amp;lt;code&amp;gt;yambopy l2y ...&amp;lt;/code&amp;gt; with the &amp;lt;code&amp;gt;--no_gkkp&amp;lt;/code&amp;gt; option.&lt;br /&gt;
* If you don&#039;t need the default &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; databases you can run &amp;lt;code&amp;gt;yambopy l2y ...&amp;lt;/code&amp;gt; with the &amp;lt;code&amp;gt;--no_lelphc_dbs&amp;lt;/code&amp;gt; option.&lt;br /&gt;
&lt;br /&gt;
However, for this tutorial, we will take a look at both databases, so let&#039;s run:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph dvscf/mos2.dvscf -b 25 28 -par 4 2 -lelphc path/to/lelphc_exe&lt;br /&gt;
&lt;br /&gt;
We include the last two valence bands of monolayer MoS2 (25 and 26) and the first two conduction bands (27 and 28). If your &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable is in the &amp;lt;code&amp;gt;PATH&amp;lt;/code&amp;gt;, you do not need to specify the last flag.&lt;br /&gt;
&lt;br /&gt;
At the end, check your directory: you should find the &amp;lt;code&amp;gt;lelphc.in&amp;lt;/code&amp;gt; input file that was run, let&#039;s inspect it: &lt;br /&gt;
&lt;br /&gt;
 # LetzElPhC input for yambo generated by yambopy&lt;br /&gt;
 nqpool      = 2&lt;br /&gt;
 nkpool      = 4&lt;br /&gt;
 start_bnd   = 25&lt;br /&gt;
 end_bnd     = 28&lt;br /&gt;
 save_dir    = ./SAVE&lt;br /&gt;
 kernel      = dfpt&lt;br /&gt;
 ph_save_dir = dvscf/ph_save&lt;br /&gt;
 convention = yambo&lt;br /&gt;
&lt;br /&gt;
Notice the variable &amp;lt;code&amp;gt;convention=yambo&amp;lt;/code&amp;gt;: what does it mean? At variance with QE and many other codes, Yambo uses the &amp;quot;backward&amp;quot; momentum transfer convention for electronic scatterings. That is, an electronic transition goes from band &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; and momentum &amp;lt;math&amp;gt;k-q&amp;lt;/math&amp;gt; to band &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; and momentum &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;. In the &amp;quot;forward&amp;quot; momentum transfer convention (the more standard one), the transitions go from &amp;lt;math&amp;gt;nk&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;mk+q&amp;lt;/math&amp;gt;. Therefore, this variable ensures that the electron-phonon coupling matrix elements are computed as &amp;lt;math&amp;gt;\langle mk|dV|nk-q\rangle&amp;lt;/math&amp;gt;. However, do not worry: Yambopy can automatically switch between the two conventions when loading the LetzElPhC databases.&lt;br /&gt;
&lt;br /&gt;
You will also find a &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; database that contains the computed electron-phonon matrix elements, in the output format of &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In addition, if you check the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; folder:&lt;br /&gt;
&lt;br /&gt;
 ls SAVE/ndb.elph_gkkp*&lt;br /&gt;
&lt;br /&gt;
you will see that yambopy has created the Yambo-compatible electron-phonon databases and placed them inside the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If you want to run LetzElPhC directly, without using yambopy, you can refer to its [[https://gitlab.com/lumen-code/LetzElPhC/-/blob/main/docs/main.pdf?ref_type=heads|user guide]].&lt;br /&gt;
Keep in mind that in this case, in order to convert the database to the &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases of Yambo, you will then need a couple of lines of python using the Yambopy class &amp;lt;code&amp;gt;ConvertElectronPhononDB&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;yambopy/letzelph_interface/lelph2y.py&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Electron-phonon intro: plots of el-ph matrix elements on k-BZ and q-BZ ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Loading electron-phonon matrix elements: Yambo ===&lt;br /&gt;
You may have seen how to calculate and import electron-phonon matrix elements in yambo in the [[Electron Phonon Coupling|electron-phonon tutorial]].&lt;br /&gt;
&lt;br /&gt;
With Yambopy, we can generate a yambo SAVE folder and import the matrix elements with a single command.&lt;br /&gt;
Typing &lt;br /&gt;
 $yambopy gkkp&lt;br /&gt;
will print the necessary documentation:&lt;br /&gt;
 Produce a SAVE folder including elph_gkkp databases&lt;br /&gt;
 &lt;br /&gt;
 Arguments are:&lt;br /&gt;
   -nscf, --nscf_dir  -&amp;gt; &amp;lt;Optional&amp;gt; Path to nscf save folder&lt;br /&gt;
   -elph, --elph_dir  -&amp;gt; Path to elph_dir folder&lt;br /&gt;
   -y, --yambo_dir    -&amp;gt; &amp;lt;Optional&amp;gt; Path to yambo executables&lt;br /&gt;
   -e, --expand       -&amp;gt; &amp;lt;Optional&amp;gt; Expand gkkp databases&lt;br /&gt;
&lt;br /&gt;
The necessary quantum espresso databases are stored in &amp;lt;code&amp;gt;ELPH_SAVES/QE_SAVES/hBN.save&amp;lt;/code&amp;gt; (nscf calculation) and &amp;lt;code&amp;gt;ELPH_SAVES/QE_SAVES/elph_dir&amp;lt;/code&amp;gt; (matrix elements from the dfpt calculation). For this tutorial we also need to expand the electron-phonon matrix elements to the full Brillouin zone. Since this is a different calculation with respect to the previous section, please generate this SAVE in a different directory than the one you used for the previous SAVE, which should be the current directory.&lt;br /&gt;
For example:&lt;br /&gt;
 $mkdir yambo-with-elph&lt;br /&gt;
 $cd yambo-with-elph&lt;br /&gt;
&lt;br /&gt;
Now we can run yambopy as in the instructions:&lt;br /&gt;
 $yambopy gkkp -nscf ../ELPH_saves/QE_saves/hBN.save -elph ../ELPH_saves/QE_saves/elph_dir --expand&lt;br /&gt;
This should generate a yambo SAVE folder which contains the &amp;lt;code&amp;gt;ndb.elph_gkkp_expanded*&amp;lt;/code&amp;gt; databases.&lt;br /&gt;
&lt;br /&gt;
=== Electron-phonon intro old: plots of el-ph matrix elements on k-BZ and q-BZ ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; and read the electron-phonon databases that you generated in the previous section.&lt;br /&gt;
&lt;br /&gt;
In order to read the &amp;lt;code&amp;gt;ndb.elph_gkkp_expanded*&amp;lt;/code&amp;gt; databases in python we use the Yambopy class &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
 yelph = YamboElectronPhononDB(ylat,folder_gkkp=&#039;path/to/elph/folder&#039;,save=&#039;path/to/SAVE&#039;)&lt;br /&gt;
(notice that it requires a previous instance of &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Now, the &amp;lt;code&amp;gt;yelph&amp;lt;/code&amp;gt; object contains phonon frequencies, phonon eigenvectors, qpoint information and, of course, the electron-phonon matrix elements g_{nm\nu}(k,q) where n, m are electron band states, \nu is a phonon branch, and k and q are the electronic and transfer momenta.&lt;br /&gt;
&lt;br /&gt;
We can print the docstring of the &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt; class with&lt;br /&gt;
 print(yelph.__doc__)&lt;br /&gt;
to get an idea of the information stored and of its capabilities.&lt;br /&gt;
&lt;br /&gt;
Now check the &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; script. You will see that it performs two plots: &lt;br /&gt;
* Plot of |g(k)| in the k-BZ for selected n,m,\nu and q [&amp;lt;code&amp;gt;Kspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Plot of |g(q)| in the q-BZ for selected n,m,\nu and k [&amp;lt;code&amp;gt;Qspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
You can change the electronic, phononic and momentum indices to see what happens.&lt;br /&gt;
&lt;br /&gt;
[[File:Elph hbn.jpg|YamboElectronPhononDB plot from yambopy tutorial|500px]]&lt;/div&gt;</summary>
		<author><name>FulvioPaleari</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_electron-phonon_coupling&amp;diff=9315</id>
		<title>Yambopy tutorial: electron-phonon coupling</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_electron-phonon_coupling&amp;diff=9315"/>
		<updated>2026-03-10T10:40:34Z</updated>

		<summary type="html">&lt;p&gt;FulvioPaleari: /* Command line: electron-phonon calculation and databases */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial we will cover the handling of electron-phonon coupling matrix elements by Yambopy. The electron-phonon calculation follows two steps:&lt;br /&gt;
&lt;br /&gt;
# Quantum Espresso calculation of phonon energies, eigenmodes and variations of the self-consistent potential via &amp;lt;code&amp;gt;ph.x&amp;lt;/code&amp;gt;.&lt;br /&gt;
# Electron-phonon matrix element calculation, symmetry expansion and conversion by the &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For more information on the &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; code and how you should run step 1., please see the related documentation [https://github.com/yambo-code/LetzElPhC here].&lt;br /&gt;
&lt;br /&gt;
We can use Yambopy to:&lt;br /&gt;
* Run &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; (both preprocessing and main run) without explicitly writing an input file.&lt;br /&gt;
* Convert the resulting databases into &amp;lt;code&amp;gt;Yambo&amp;lt;/code&amp;gt; format.&lt;br /&gt;
* Analyse the electron-phonon coupling both in &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;Yambo&amp;lt;/code&amp;gt; format.&lt;br /&gt;
&lt;br /&gt;
The scripts of the tutorial, but not the databases, can be found in the yambopy directory:&lt;br /&gt;
 $cd tutorial/electron_phonon&lt;br /&gt;
&lt;br /&gt;
The full tutorial, including the LetzElPhC and Yambo databases that we will read, can be downloaded and extracted from the yambo website:&lt;br /&gt;
 $wget https://media.yambo-code.eu/educational/tutorials/files/electron_phonon.tar.gz&lt;br /&gt;
 $tar -xvzf electron_phonon.tar.gz&lt;br /&gt;
 $cd electron_phonon&lt;br /&gt;
&lt;br /&gt;
We will work with monolayer molybdenum disulfide electron-phonon data obtained on a &amp;lt;code&amp;gt;6x6x1&amp;lt;/code&amp;gt; kpoint grid. Beware that these are most certainly not converged.&lt;br /&gt;
&lt;br /&gt;
=== Command line: electron-phonon calculation and databases ===&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: you can run this step only if you have compiled &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; on your machine. If not, please skip to the following sections of the tutorial, as the electron-phonon coupling databases are already provided in the .tar.gz file.&lt;br /&gt;
&lt;br /&gt;
Let us assume that we have run a quantum espresso phonon calculation as per step 1. above. You will find the results in the &amp;lt;code&amp;gt;dvscf&amp;lt;/code&amp;gt; directory. We also have done a non-self-consistent calculation to be used in Yambo, and created the relative &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory.&lt;br /&gt;
 &lt;br /&gt;
Now, we aim to reconstruct the electron-phonon coupling matrix elements from the phonon energies, modes and potential variations (in &amp;lt;code&amp;gt;dvscf&amp;lt;/code&amp;gt;) and the Bloch electronic wavefunctions used by Yambo (in &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
In order to do this, we will run the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable of the &#039;&#039;&#039;LetzElPhC&#039;&#039;&#039; code. We will run via command line using yambopy, although it will be instructive to have look at the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; input files later.&lt;br /&gt;
&lt;br /&gt;
We run in the same directory where the Yambo &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; is (remember than you can also virtually move it with a symbolic link).&lt;br /&gt;
&lt;br /&gt;
Type:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y&lt;br /&gt;
&lt;br /&gt;
to see the help for the calculation. Have a look at the various flags and their description.&lt;br /&gt;
For example, if we want to do a serial run of LetzElPhC for bands from &amp;lt;math&amp;gt;n_i&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;n_f&amp;lt;/math&amp;gt;, we should type:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph path/of/ph_input.in -b n_i n_f&lt;br /&gt;
&lt;br /&gt;
Here &amp;lt;math&amp;gt;n_i&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;n_f&amp;lt;/math&amp;gt; are integers representing the initial and final band indices. &#039;&#039;&#039;Please note&#039;&#039;&#039;: in this case, the band index starts from 1 and the the interval of bands read by the code is &amp;lt;math&amp;gt;[n_i,n_f]&amp;lt;/math&amp;gt; including the extrema of the interval. &lt;br /&gt;
&lt;br /&gt;
For our system, we want to do a parallel calculation: 4 MPI tasks on q-point loop (phonon momenta) and 2 MPI tasks on the k-point loop (electron momenta). In addition, we want to explicitly specify the path of the &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable. &lt;br /&gt;
&lt;br /&gt;
We have a final choice to make. We can ask Yambopy to produce the default LetzElPhC electron-phonon databases, or to convert them in Yambo-compatible format. By the default, both will be printed. &lt;br /&gt;
&lt;br /&gt;
* If you don&#039;t need the Yambo-style &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases you can run &amp;lt;code&amp;gt;yambopy l2y ...&amp;lt;/code&amp;gt; with the &amp;lt;code&amp;gt;--no_gkkp&amp;lt;/code&amp;gt; option.&lt;br /&gt;
* If you don&#039;t need the default &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; databases you can run &amp;lt;code&amp;gt;yambopy l2y ...&amp;lt;/code&amp;gt; with the &amp;lt;code&amp;gt;--no_lelphc_dbs&amp;lt;/code&amp;gt; option.&lt;br /&gt;
&lt;br /&gt;
However, for this tutorial, we will take a look at both databases, so let&#039;s run:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph dvscf/mos2.dvscf -b 25 28 -par 4 2 -lelphc path/to/lelphc_exe&lt;br /&gt;
&lt;br /&gt;
We include the last two valence bands of monolayer MoS2 (25 and 26) and the first two conduction bands (27 and 28). If your &amp;lt;code&amp;gt;lelphc&amp;lt;/code&amp;gt; executable is in the &amp;lt;code&amp;gt;PATH&amp;lt;/code&amp;gt;, you do not need to specify the last flag.&lt;br /&gt;
&lt;br /&gt;
At the end, check your directory: you should find the &amp;lt;code&amp;gt;lelphc.in&amp;lt;/code&amp;gt; input file that was run, let&#039;s inspect it: &lt;br /&gt;
&lt;br /&gt;
 # LetzElPhC input for yambo generated by yambopy&lt;br /&gt;
 nqpool      = 2&lt;br /&gt;
 nkpool      = 4&lt;br /&gt;
 start_bnd   = 25&lt;br /&gt;
 end_bnd     = 28&lt;br /&gt;
 save_dir    = ./SAVE&lt;br /&gt;
 kernel      = dfpt&lt;br /&gt;
 ph_save_dir = dvscf/ph_save&lt;br /&gt;
 convention = yambo&lt;br /&gt;
&lt;br /&gt;
Notice the variable &amp;lt;code&amp;gt;convention=yambo&amp;lt;/code&amp;gt;: what does it mean? At variance with QE and many other codes, Yambo uses the &amp;quot;backward&amp;quot; momentum transfer convention for electronic scatterings. That is, an electronic transition goes from band &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; and momentum &amp;lt;math&amp;gt;k-q&amp;lt;/math&amp;gt; to band &amp;lt;math&amp;gt;m&amp;lt;/math&amp;gt; and momentum &amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;. In the &amp;quot;forward&amp;quot; momentum transfer convention (the more standard one), the transitions go from &amp;lt;math&amp;gt;nk&amp;lt;/math&amp;gt; to &amp;lt;math&amp;gt;mk+q&amp;lt;/math&amp;gt;. Therefore, this variable ensures that the electron-phonon coupling matrix elements are computed as &amp;lt;math&amp;gt;\langle mk|dV|nk-q\rangle&amp;lt;/math&amp;gt;. However, do not worry: Yambopy can automatically switch between the two conventions when loading the LetzElPhC databases.&lt;br /&gt;
&lt;br /&gt;
You will also find a &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; database that contains the computed electron-phonon matrix elements, in the output format of &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In addition, if you check the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; folder:&lt;br /&gt;
&lt;br /&gt;
 ls SAVE/ndb.elph_gkkp*&lt;br /&gt;
&lt;br /&gt;
you will see that yambopy has created the Yambo-compatible electron-phonon databases and placed them inside the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If you want to run LetzElPhC directly, without using yambopy, you can refer to its [[https://gitlab.com/lumen-code/LetzElPhC/-/blob/main/docs/main.pdf?ref_type=heads|user guide]].&lt;br /&gt;
Keep in mind that in this case, in order to convert the database to the &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases of Yambo, you will then need a couple of lines of python using the Yambopy class &amp;lt;code&amp;gt;ConvertElectronPhononDB&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;yambopy/letzelph_interface/lelph2y.py&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Electron-phonon intro: plots of el-ph matrix elements on k-BZ and q-BZ ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Loading electron-phonon matrix elements: Yambo ===&lt;br /&gt;
You may have seen how to calculate and import electron-phonon matrix elements in yambo in the [[Electron Phonon Coupling|electron-phonon tutorial]].&lt;br /&gt;
&lt;br /&gt;
With Yambopy, we can generate a yambo SAVE folder and import the matrix elements with a single command.&lt;br /&gt;
Typing &lt;br /&gt;
 $yambopy gkkp&lt;br /&gt;
will print the necessary documentation:&lt;br /&gt;
 Produce a SAVE folder including elph_gkkp databases&lt;br /&gt;
 &lt;br /&gt;
 Arguments are:&lt;br /&gt;
   -nscf, --nscf_dir  -&amp;gt; &amp;lt;Optional&amp;gt; Path to nscf save folder&lt;br /&gt;
   -elph, --elph_dir  -&amp;gt; Path to elph_dir folder&lt;br /&gt;
   -y, --yambo_dir    -&amp;gt; &amp;lt;Optional&amp;gt; Path to yambo executables&lt;br /&gt;
   -e, --expand       -&amp;gt; &amp;lt;Optional&amp;gt; Expand gkkp databases&lt;br /&gt;
&lt;br /&gt;
The necessary quantum espresso databases are stored in &amp;lt;code&amp;gt;ELPH_SAVES/QE_SAVES/hBN.save&amp;lt;/code&amp;gt; (nscf calculation) and &amp;lt;code&amp;gt;ELPH_SAVES/QE_SAVES/elph_dir&amp;lt;/code&amp;gt; (matrix elements from the dfpt calculation). For this tutorial we also need to expand the electron-phonon matrix elements to the full Brillouin zone. Since this is a different calculation with respect to the previous section, please generate this SAVE in a different directory than the one you used for the previous SAVE, which should be the current directory.&lt;br /&gt;
For example:&lt;br /&gt;
 $mkdir yambo-with-elph&lt;br /&gt;
 $cd yambo-with-elph&lt;br /&gt;
&lt;br /&gt;
Now we can run yambopy as in the instructions:&lt;br /&gt;
 $yambopy gkkp -nscf ../ELPH_saves/QE_saves/hBN.save -elph ../ELPH_saves/QE_saves/elph_dir --expand&lt;br /&gt;
This should generate a yambo SAVE folder which contains the &amp;lt;code&amp;gt;ndb.elph_gkkp_expanded*&amp;lt;/code&amp;gt; databases.&lt;br /&gt;
&lt;br /&gt;
=== Electron-phonon intro old: plots of el-ph matrix elements on k-BZ and q-BZ ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; and read the electron-phonon databases that you generated in the previous section.&lt;br /&gt;
&lt;br /&gt;
In order to read the &amp;lt;code&amp;gt;ndb.elph_gkkp_expanded*&amp;lt;/code&amp;gt; databases in python we use the Yambopy class &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
 yelph = YamboElectronPhononDB(ylat,folder_gkkp=&#039;path/to/elph/folder&#039;,save=&#039;path/to/SAVE&#039;)&lt;br /&gt;
(notice that it requires a previous instance of &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Now, the &amp;lt;code&amp;gt;yelph&amp;lt;/code&amp;gt; object contains phonon frequencies, phonon eigenvectors, qpoint information and, of course, the electron-phonon matrix elements g_{nm\nu}(k,q) where n, m are electron band states, \nu is a phonon branch, and k and q are the electronic and transfer momenta.&lt;br /&gt;
&lt;br /&gt;
We can print the docstring of the &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt; class with&lt;br /&gt;
 print(yelph.__doc__)&lt;br /&gt;
to get an idea of the information stored and of its capabilities.&lt;br /&gt;
&lt;br /&gt;
Now check the &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; script. You will see that it performs two plots: &lt;br /&gt;
* Plot of |g(k)| in the k-BZ for selected n,m,\nu and q [&amp;lt;code&amp;gt;Kspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Plot of |g(q)| in the q-BZ for selected n,m,\nu and k [&amp;lt;code&amp;gt;Qspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
You can change the electronic, phononic and momentum indices to see what happens.&lt;br /&gt;
&lt;br /&gt;
[[File:Elph hbn.jpg|YamboElectronPhononDB plot from yambopy tutorial|500px]]&lt;/div&gt;</summary>
		<author><name>FulvioPaleari</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_electron-phonon_coupling&amp;diff=9314</id>
		<title>Yambopy tutorial: electron-phonon coupling</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_electron-phonon_coupling&amp;diff=9314"/>
		<updated>2026-03-10T09:56:10Z</updated>

		<summary type="html">&lt;p&gt;FulvioPaleari: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial we will cover the handling of electron-phonon coupling matrix elements by Yambopy. The electron-phonon calculation follows two steps:&lt;br /&gt;
&lt;br /&gt;
# Quantum Espresso calculation of phonon energies, eigenmodes and variations of the self-consistent potential via &amp;lt;code&amp;gt;ph.x&amp;lt;/code&amp;gt;.&lt;br /&gt;
# Electron-phonon matrix element calculation, symmetry expansion and conversion by the &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For more information on the &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; code and how you should run step 1., please see the related documentation [https://github.com/yambo-code/LetzElPhC here].&lt;br /&gt;
&lt;br /&gt;
We can use Yambopy to:&lt;br /&gt;
* Run &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; (both preprocessing and main run) without explicitly writing an input file.&lt;br /&gt;
* Convert the resulting databases into &amp;lt;code&amp;gt;Yambo&amp;lt;/code&amp;gt; format.&lt;br /&gt;
* Analyse the electron-phonon coupling both in &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;Yambo&amp;lt;/code&amp;gt; format.&lt;br /&gt;
&lt;br /&gt;
The scripts of the tutorial, but not the databases, can be found in the yambopy directory:&lt;br /&gt;
 $cd tutorial/electron_phonon&lt;br /&gt;
&lt;br /&gt;
The full tutorial, including the LetzElPhC and Yambo databases that we will read, can be downloaded and extracted from the yambo website:&lt;br /&gt;
 $wget https://media.yambo-code.eu/educational/tutorials/files/electron_phonon.tar.gz&lt;br /&gt;
 $tar -xvzf electron_phonon.tar.gz&lt;br /&gt;
 $cd electron_phonon&lt;br /&gt;
&lt;br /&gt;
We will work with monolayer molybdenum disulfide electron-phonon data obtained on a &amp;lt;code&amp;gt;6x6x1&amp;lt;/code&amp;gt; kpoint grid. Beware that these are most certainly not converged.&lt;br /&gt;
&lt;br /&gt;
=== Command line: electron-phonon calculation and databases ===&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: you can run this step only if you have compiled &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; on your machine. If not, please skip to the following sections of the tutorial, as the electron-phonon coupling databases are already provided in the .tar.gz file.&lt;br /&gt;
&lt;br /&gt;
* Electron-phonon matrix elements (Yambo databases: &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=== Electron-phonon intro: plots of el-ph matrix elements on k-BZ and q-BZ ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Loading electron-phonon matrix elements: Yambo ===&lt;br /&gt;
You may have seen how to calculate and import electron-phonon matrix elements in yambo in the [[Electron Phonon Coupling|electron-phonon tutorial]].&lt;br /&gt;
&lt;br /&gt;
With Yambopy, we can generate a yambo SAVE folder and import the matrix elements with a single command.&lt;br /&gt;
Typing &lt;br /&gt;
 $yambopy gkkp&lt;br /&gt;
will print the necessary documentation:&lt;br /&gt;
 Produce a SAVE folder including elph_gkkp databases&lt;br /&gt;
 &lt;br /&gt;
 Arguments are:&lt;br /&gt;
   -nscf, --nscf_dir  -&amp;gt; &amp;lt;Optional&amp;gt; Path to nscf save folder&lt;br /&gt;
   -elph, --elph_dir  -&amp;gt; Path to elph_dir folder&lt;br /&gt;
   -y, --yambo_dir    -&amp;gt; &amp;lt;Optional&amp;gt; Path to yambo executables&lt;br /&gt;
   -e, --expand       -&amp;gt; &amp;lt;Optional&amp;gt; Expand gkkp databases&lt;br /&gt;
&lt;br /&gt;
The necessary quantum espresso databases are stored in &amp;lt;code&amp;gt;ELPH_SAVES/QE_SAVES/hBN.save&amp;lt;/code&amp;gt; (nscf calculation) and &amp;lt;code&amp;gt;ELPH_SAVES/QE_SAVES/elph_dir&amp;lt;/code&amp;gt; (matrix elements from the dfpt calculation). For this tutorial we also need to expand the electron-phonon matrix elements to the full Brillouin zone. Since this is a different calculation with respect to the previous section, please generate this SAVE in a different directory than the one you used for the previous SAVE, which should be the current directory.&lt;br /&gt;
For example:&lt;br /&gt;
 $mkdir yambo-with-elph&lt;br /&gt;
 $cd yambo-with-elph&lt;br /&gt;
&lt;br /&gt;
Now we can run yambopy as in the instructions:&lt;br /&gt;
 $yambopy gkkp -nscf ../ELPH_saves/QE_saves/hBN.save -elph ../ELPH_saves/QE_saves/elph_dir --expand&lt;br /&gt;
This should generate a yambo SAVE folder which contains the &amp;lt;code&amp;gt;ndb.elph_gkkp_expanded*&amp;lt;/code&amp;gt; databases.&lt;br /&gt;
&lt;br /&gt;
=== Electron-phonon intro old: plots of el-ph matrix elements on k-BZ and q-BZ ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; and read the electron-phonon databases that you generated in the previous section.&lt;br /&gt;
&lt;br /&gt;
In order to read the &amp;lt;code&amp;gt;ndb.elph_gkkp_expanded*&amp;lt;/code&amp;gt; databases in python we use the Yambopy class &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
 yelph = YamboElectronPhononDB(ylat,folder_gkkp=&#039;path/to/elph/folder&#039;,save=&#039;path/to/SAVE&#039;)&lt;br /&gt;
(notice that it requires a previous instance of &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Now, the &amp;lt;code&amp;gt;yelph&amp;lt;/code&amp;gt; object contains phonon frequencies, phonon eigenvectors, qpoint information and, of course, the electron-phonon matrix elements g_{nm\nu}(k,q) where n, m are electron band states, \nu is a phonon branch, and k and q are the electronic and transfer momenta.&lt;br /&gt;
&lt;br /&gt;
We can print the docstring of the &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt; class with&lt;br /&gt;
 print(yelph.__doc__)&lt;br /&gt;
to get an idea of the information stored and of its capabilities.&lt;br /&gt;
&lt;br /&gt;
Now check the &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; script. You will see that it performs two plots: &lt;br /&gt;
* Plot of |g(k)| in the k-BZ for selected n,m,\nu and q [&amp;lt;code&amp;gt;Kspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Plot of |g(q)| in the q-BZ for selected n,m,\nu and k [&amp;lt;code&amp;gt;Qspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
You can change the electronic, phononic and momentum indices to see what happens.&lt;br /&gt;
&lt;br /&gt;
[[File:Elph hbn.jpg|YamboElectronPhononDB plot from yambopy tutorial|500px]]&lt;/div&gt;</summary>
		<author><name>FulvioPaleari</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_electron-phonon_coupling&amp;diff=9313</id>
		<title>Yambopy tutorial: electron-phonon coupling</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_electron-phonon_coupling&amp;diff=9313"/>
		<updated>2026-03-10T09:55:20Z</updated>

		<summary type="html">&lt;p&gt;FulvioPaleari: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial we will cover the handling of electron-phonon coupling matrix elements by Yambopy. The electron-phonon calculation follows two steps:&lt;br /&gt;
&lt;br /&gt;
# Quantum Espresso calculation of phonon energies, eigenmodes and variations of the self-consistent potential via &amp;lt;code&amp;gt;ph.x&amp;lt;/code&amp;gt;.&lt;br /&gt;
# Electron-phonon matrix element calculation, symmetry expansion and conversion by the &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For more information on the &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; code and how you should run step 1., please see the related documentation [https://github.com/yambo-code/LetzElPhC here].&lt;br /&gt;
&lt;br /&gt;
We can use Yambopy to:&lt;br /&gt;
* Run &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; (both preprocessing and main run) without explicitly writing an input file.&lt;br /&gt;
* Convert the resulting databases into &amp;lt;code&amp;gt;Yambo&amp;lt;/code&amp;gt; format.&lt;br /&gt;
* Analyse the electron-phonon coupling both in &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;Yambo&amp;lt;/code&amp;gt; format.&lt;br /&gt;
&lt;br /&gt;
The scripts of the tutorial, but not the databases, can be found in the yambopy directory:&lt;br /&gt;
 $cd tutorial/electron_phonon&lt;br /&gt;
&lt;br /&gt;
The full tutorial, including the LetzElPhC and Yambo databases that we will read, can be downloaded and extracted from the yambo website:&lt;br /&gt;
 $wget https://media.yambo-code.eu/educational/tutorials/files/electron_phonon.tar.gz&lt;br /&gt;
 $tar -xvzf electron_phonon.tar.gz&lt;br /&gt;
 $cd electron_phonon&lt;br /&gt;
&lt;br /&gt;
We will work with monolayer molybdenum disulfide electron-phonon data obtained on a &amp;lt;code&amp;gt;6x6x1&amp;lt;/code&amp;gt; kpoint grid. Beware that these are most certainly not converged.&lt;br /&gt;
&lt;br /&gt;
=== Command line: electron-phonon calculation and databases ===&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: you can run this step only if you have compiled &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; on your machine. If not, please skip to the following sections of the tutorial, as the electron-phonon coupling databases are already provided in the .tar.gz file.&lt;br /&gt;
&lt;br /&gt;
* Electron-phonon matrix elements (Yambo databases: &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=== Loading electron-phonon matrix elements: LetzElPhC ===&lt;br /&gt;
&lt;br /&gt;
=== Loading electron-phonon matrix elements: Yambo ===&lt;br /&gt;
You may have seen how to calculate and import electron-phonon matrix elements in yambo in the [[Electron Phonon Coupling|electron-phonon tutorial]].&lt;br /&gt;
&lt;br /&gt;
With Yambopy, we can generate a yambo SAVE folder and import the matrix elements with a single command.&lt;br /&gt;
Typing &lt;br /&gt;
 $yambopy gkkp&lt;br /&gt;
will print the necessary documentation:&lt;br /&gt;
 Produce a SAVE folder including elph_gkkp databases&lt;br /&gt;
 &lt;br /&gt;
 Arguments are:&lt;br /&gt;
   -nscf, --nscf_dir  -&amp;gt; &amp;lt;Optional&amp;gt; Path to nscf save folder&lt;br /&gt;
   -elph, --elph_dir  -&amp;gt; Path to elph_dir folder&lt;br /&gt;
   -y, --yambo_dir    -&amp;gt; &amp;lt;Optional&amp;gt; Path to yambo executables&lt;br /&gt;
   -e, --expand       -&amp;gt; &amp;lt;Optional&amp;gt; Expand gkkp databases&lt;br /&gt;
&lt;br /&gt;
The necessary quantum espresso databases are stored in &amp;lt;code&amp;gt;ELPH_SAVES/QE_SAVES/hBN.save&amp;lt;/code&amp;gt; (nscf calculation) and &amp;lt;code&amp;gt;ELPH_SAVES/QE_SAVES/elph_dir&amp;lt;/code&amp;gt; (matrix elements from the dfpt calculation). For this tutorial we also need to expand the electron-phonon matrix elements to the full Brillouin zone. Since this is a different calculation with respect to the previous section, please generate this SAVE in a different directory than the one you used for the previous SAVE, which should be the current directory.&lt;br /&gt;
For example:&lt;br /&gt;
 $mkdir yambo-with-elph&lt;br /&gt;
 $cd yambo-with-elph&lt;br /&gt;
&lt;br /&gt;
Now we can run yambopy as in the instructions:&lt;br /&gt;
 $yambopy gkkp -nscf ../ELPH_saves/QE_saves/hBN.save -elph ../ELPH_saves/QE_saves/elph_dir --expand&lt;br /&gt;
This should generate a yambo SAVE folder which contains the &amp;lt;code&amp;gt;ndb.elph_gkkp_expanded*&amp;lt;/code&amp;gt; databases.&lt;br /&gt;
&lt;br /&gt;
=== Electron-phonon intro: plots of el-ph matrix elements on k-BZ and q-BZ ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; and read the electron-phonon databases that you generated in the previous section.&lt;br /&gt;
&lt;br /&gt;
In order to read the &amp;lt;code&amp;gt;ndb.elph_gkkp_expanded*&amp;lt;/code&amp;gt; databases in python we use the Yambopy class &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
 yelph = YamboElectronPhononDB(ylat,folder_gkkp=&#039;path/to/elph/folder&#039;,save=&#039;path/to/SAVE&#039;)&lt;br /&gt;
(notice that it requires a previous instance of &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Now, the &amp;lt;code&amp;gt;yelph&amp;lt;/code&amp;gt; object contains phonon frequencies, phonon eigenvectors, qpoint information and, of course, the electron-phonon matrix elements g_{nm\nu}(k,q) where n, m are electron band states, \nu is a phonon branch, and k and q are the electronic and transfer momenta.&lt;br /&gt;
&lt;br /&gt;
We can print the docstring of the &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt; class with&lt;br /&gt;
 print(yelph.__doc__)&lt;br /&gt;
to get an idea of the information stored and of its capabilities.&lt;br /&gt;
&lt;br /&gt;
Now check the &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; script. You will see that it performs two plots: &lt;br /&gt;
* Plot of |g(k)| in the k-BZ for selected n,m,\nu and q [&amp;lt;code&amp;gt;Kspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Plot of |g(q)| in the q-BZ for selected n,m,\nu and k [&amp;lt;code&amp;gt;Qspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
You can change the electronic, phononic and momentum indices to see what happens.&lt;br /&gt;
&lt;br /&gt;
[[File:Elph hbn.jpg|YamboElectronPhononDB plot from yambopy tutorial|500px]]&lt;/div&gt;</summary>
		<author><name>FulvioPaleari</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_electron-phonon_coupling&amp;diff=9312</id>
		<title>Yambopy tutorial: electron-phonon coupling</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_electron-phonon_coupling&amp;diff=9312"/>
		<updated>2026-03-10T09:53:27Z</updated>

		<summary type="html">&lt;p&gt;FulvioPaleari: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial we will cover the handling of electron-phonon coupling matrix elements by Yambopy. The electron-phonon calculation follows two steps:&lt;br /&gt;
&lt;br /&gt;
# Quantum Espresso calculation of phonon energies, eigenmodes and variations of the self-consistent potential via &amp;lt;code&amp;gt;ph.x&amp;lt;/code&amp;gt;.&lt;br /&gt;
# Electron-phonon matrix element calculation, symmetry expansion and conversion by the &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For more information on the &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; code and how you should run step 1., please see the related documentation [https://github.com/yambo-code/LetzElPhC here].&lt;br /&gt;
&lt;br /&gt;
We can use Yambopy to:&lt;br /&gt;
* Run &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; (both preprocessing and main run) without explicitly writing an input file.&lt;br /&gt;
* Convert the resulting databases into &amp;lt;code&amp;gt;Yambo&amp;lt;/code&amp;gt; format.&lt;br /&gt;
* Analyse the electron-phonon coupling both in &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;Yambo&amp;lt;/code&amp;gt; format.&lt;br /&gt;
&lt;br /&gt;
The scripts of the tutorial, but not the databases, can be found in the yambopy directory:&lt;br /&gt;
 $cd tutorial/electron_phonon&lt;br /&gt;
&lt;br /&gt;
The full tutorial, including the LetzElPhC and Yambo databases that we will read, can be downloaded and extracted from the yambo website:&lt;br /&gt;
 $wget https://media.yambo-code.eu/educational/tutorials/files/electron_phonon.tar.gz&lt;br /&gt;
 $tar -xvzf electron_phonon.tar.gz&lt;br /&gt;
 $cd electron_phonon&lt;br /&gt;
&lt;br /&gt;
We will work with monolayer molybdenum disulfide electron-phonon data obtained on a &amp;lt;code&amp;gt;6x6x1&amp;lt;/code&amp;gt; kpoint grid. Beware that these are most certainly not converged.&lt;br /&gt;
&lt;br /&gt;
=== Command line: electron-phonon calculation ===&lt;br /&gt;
&#039;&#039;&#039;Note&#039;&#039;&#039;: you can run this step only if you have compiled &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; on your machine. If not, please skip to the following sections of the tutorial, as the electron-phonon coupling databases are already provided in the .tar.gz file.&lt;br /&gt;
&lt;br /&gt;
* Electron-phonon matrix elements (Yambo databases: &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=== Command line: importing electron-phonon matrix elements ===&lt;br /&gt;
You may have seen how to calculate and import electron-phonon matrix elements in yambo in the [[Electron Phonon Coupling|electron-phonon tutorial]].&lt;br /&gt;
&lt;br /&gt;
With Yambopy, we can generate a yambo SAVE folder and import the matrix elements with a single command.&lt;br /&gt;
Typing &lt;br /&gt;
 $yambopy gkkp&lt;br /&gt;
will print the necessary documentation:&lt;br /&gt;
 Produce a SAVE folder including elph_gkkp databases&lt;br /&gt;
 &lt;br /&gt;
 Arguments are:&lt;br /&gt;
   -nscf, --nscf_dir  -&amp;gt; &amp;lt;Optional&amp;gt; Path to nscf save folder&lt;br /&gt;
   -elph, --elph_dir  -&amp;gt; Path to elph_dir folder&lt;br /&gt;
   -y, --yambo_dir    -&amp;gt; &amp;lt;Optional&amp;gt; Path to yambo executables&lt;br /&gt;
   -e, --expand       -&amp;gt; &amp;lt;Optional&amp;gt; Expand gkkp databases&lt;br /&gt;
&lt;br /&gt;
The necessary quantum espresso databases are stored in &amp;lt;code&amp;gt;ELPH_SAVES/QE_SAVES/hBN.save&amp;lt;/code&amp;gt; (nscf calculation) and &amp;lt;code&amp;gt;ELPH_SAVES/QE_SAVES/elph_dir&amp;lt;/code&amp;gt; (matrix elements from the dfpt calculation). For this tutorial we also need to expand the electron-phonon matrix elements to the full Brillouin zone. Since this is a different calculation with respect to the previous section, please generate this SAVE in a different directory than the one you used for the previous SAVE, which should be the current directory.&lt;br /&gt;
For example:&lt;br /&gt;
 $mkdir yambo-with-elph&lt;br /&gt;
 $cd yambo-with-elph&lt;br /&gt;
&lt;br /&gt;
Now we can run yambopy as in the instructions:&lt;br /&gt;
 $yambopy gkkp -nscf ../ELPH_saves/QE_saves/hBN.save -elph ../ELPH_saves/QE_saves/elph_dir --expand&lt;br /&gt;
This should generate a yambo SAVE folder which contains the &amp;lt;code&amp;gt;ndb.elph_gkkp_expanded*&amp;lt;/code&amp;gt; databases.&lt;br /&gt;
&lt;br /&gt;
=== Electron-phonon intro: plots of el-ph matrix elements on k-BZ and q-BZ ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; and read the electron-phonon databases that you generated in the previous section.&lt;br /&gt;
&lt;br /&gt;
In order to read the &amp;lt;code&amp;gt;ndb.elph_gkkp_expanded*&amp;lt;/code&amp;gt; databases in python we use the Yambopy class &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
 yelph = YamboElectronPhononDB(ylat,folder_gkkp=&#039;path/to/elph/folder&#039;,save=&#039;path/to/SAVE&#039;)&lt;br /&gt;
(notice that it requires a previous instance of &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Now, the &amp;lt;code&amp;gt;yelph&amp;lt;/code&amp;gt; object contains phonon frequencies, phonon eigenvectors, qpoint information and, of course, the electron-phonon matrix elements g_{nm\nu}(k,q) where n, m are electron band states, \nu is a phonon branch, and k and q are the electronic and transfer momenta.&lt;br /&gt;
&lt;br /&gt;
We can print the docstring of the &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt; class with&lt;br /&gt;
 print(yelph.__doc__)&lt;br /&gt;
to get an idea of the information stored and of its capabilities.&lt;br /&gt;
&lt;br /&gt;
Now check the &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; script. You will see that it performs two plots: &lt;br /&gt;
* Plot of |g(k)| in the k-BZ for selected n,m,\nu and q [&amp;lt;code&amp;gt;Kspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Plot of |g(q)| in the q-BZ for selected n,m,\nu and k [&amp;lt;code&amp;gt;Qspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
You can change the electronic, phononic and momentum indices to see what happens.&lt;br /&gt;
&lt;br /&gt;
[[File:Elph hbn.jpg|YamboElectronPhononDB plot from yambopy tutorial|500px]]&lt;/div&gt;</summary>
		<author><name>FulvioPaleari</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_electron-phonon_coupling&amp;diff=9311</id>
		<title>Yambopy tutorial: electron-phonon coupling</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_electron-phonon_coupling&amp;diff=9311"/>
		<updated>2026-03-10T09:41:36Z</updated>

		<summary type="html">&lt;p&gt;FulvioPaleari: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial we will cover the handling of electron-phonon coupling matrix elements by Yambopy. The electron-phonon calculation follows two steps:&lt;br /&gt;
&lt;br /&gt;
# Quantum Espresso calculation of phonon energies, eigenmodes and variations of the self-consistent potential via &amp;lt;code&amp;gt;ph.x&amp;lt;/code&amp;gt;.&lt;br /&gt;
# Electron-phonon matrix element calculation, symmetry expansion and conversion by the &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For more information on the &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; and how you should run step 1., please see the related documentation [https://github.com/yambo-code/LetzElPhC here].&lt;br /&gt;
&lt;br /&gt;
* Electron-phonon matrix elements (Yambo databases: &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=== Command line: importing electron-phonon matrix elements ===&lt;br /&gt;
You may have seen how to calculate and import electron-phonon matrix elements in yambo in the [[Electron Phonon Coupling|electron-phonon tutorial]].&lt;br /&gt;
&lt;br /&gt;
With Yambopy, we can generate a yambo SAVE folder and import the matrix elements with a single command.&lt;br /&gt;
Typing &lt;br /&gt;
 $yambopy gkkp&lt;br /&gt;
will print the necessary documentation:&lt;br /&gt;
 Produce a SAVE folder including elph_gkkp databases&lt;br /&gt;
 &lt;br /&gt;
 Arguments are:&lt;br /&gt;
   -nscf, --nscf_dir  -&amp;gt; &amp;lt;Optional&amp;gt; Path to nscf save folder&lt;br /&gt;
   -elph, --elph_dir  -&amp;gt; Path to elph_dir folder&lt;br /&gt;
   -y, --yambo_dir    -&amp;gt; &amp;lt;Optional&amp;gt; Path to yambo executables&lt;br /&gt;
   -e, --expand       -&amp;gt; &amp;lt;Optional&amp;gt; Expand gkkp databases&lt;br /&gt;
&lt;br /&gt;
The necessary quantum espresso databases are stored in &amp;lt;code&amp;gt;ELPH_SAVES/QE_SAVES/hBN.save&amp;lt;/code&amp;gt; (nscf calculation) and &amp;lt;code&amp;gt;ELPH_SAVES/QE_SAVES/elph_dir&amp;lt;/code&amp;gt; (matrix elements from the dfpt calculation). For this tutorial we also need to expand the electron-phonon matrix elements to the full Brillouin zone. Since this is a different calculation with respect to the previous section, please generate this SAVE in a different directory than the one you used for the previous SAVE, which should be the current directory.&lt;br /&gt;
For example:&lt;br /&gt;
 $mkdir yambo-with-elph&lt;br /&gt;
 $cd yambo-with-elph&lt;br /&gt;
&lt;br /&gt;
Now we can run yambopy as in the instructions:&lt;br /&gt;
 $yambopy gkkp -nscf ../ELPH_saves/QE_saves/hBN.save -elph ../ELPH_saves/QE_saves/elph_dir --expand&lt;br /&gt;
This should generate a yambo SAVE folder which contains the &amp;lt;code&amp;gt;ndb.elph_gkkp_expanded*&amp;lt;/code&amp;gt; databases.&lt;br /&gt;
&lt;br /&gt;
=== Electron-phonon intro: plots of el-ph matrix elements on k-BZ and q-BZ ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; and read the electron-phonon databases that you generated in the previous section.&lt;br /&gt;
&lt;br /&gt;
In order to read the &amp;lt;code&amp;gt;ndb.elph_gkkp_expanded*&amp;lt;/code&amp;gt; databases in python we use the Yambopy class &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
 yelph = YamboElectronPhononDB(ylat,folder_gkkp=&#039;path/to/elph/folder&#039;,save=&#039;path/to/SAVE&#039;)&lt;br /&gt;
(notice that it requires a previous instance of &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Now, the &amp;lt;code&amp;gt;yelph&amp;lt;/code&amp;gt; object contains phonon frequencies, phonon eigenvectors, qpoint information and, of course, the electron-phonon matrix elements g_{nm\nu}(k,q) where n, m are electron band states, \nu is a phonon branch, and k and q are the electronic and transfer momenta.&lt;br /&gt;
&lt;br /&gt;
We can print the docstring of the &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt; class with&lt;br /&gt;
 print(yelph.__doc__)&lt;br /&gt;
to get an idea of the information stored and of its capabilities.&lt;br /&gt;
&lt;br /&gt;
Now check the &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; script. You will see that it performs two plots: &lt;br /&gt;
* Plot of |g(k)| in the k-BZ for selected n,m,\nu and q [&amp;lt;code&amp;gt;Kspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Plot of |g(q)| in the q-BZ for selected n,m,\nu and k [&amp;lt;code&amp;gt;Qspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
You can change the electronic, phononic and momentum indices to see what happens.&lt;br /&gt;
&lt;br /&gt;
[[File:Elph hbn.jpg|YamboElectronPhononDB plot from yambopy tutorial|500px]]&lt;/div&gt;</summary>
		<author><name>FulvioPaleari</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_electron-phonon_coupling&amp;diff=9310</id>
		<title>Yambopy tutorial: electron-phonon coupling</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_electron-phonon_coupling&amp;diff=9310"/>
		<updated>2026-03-10T09:41:01Z</updated>

		<summary type="html">&lt;p&gt;FulvioPaleari: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial we will cover the handling of electron-phonon coupling matrix elements by Yambopy. The electron-phonon calculation follows two steps:&lt;br /&gt;
1. Quantum Espresso calculation of phonon energies, eigenmodes and variations of the self-consistent potential via &amp;lt;code&amp;gt;ph.x&amp;lt;/code&amp;gt;.&lt;br /&gt;
2. Electron-phonon matrix element calculation, symmetry expansion and conversion by the &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For more information on the &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; and how you should run step 1., please see the related documentation [https://github.com/yambo-code/LetzElPhC here].&lt;br /&gt;
&lt;br /&gt;
* Electron-phonon matrix elements (Yambo databases: &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=== Command line: importing electron-phonon matrix elements ===&lt;br /&gt;
You may have seen how to calculate and import electron-phonon matrix elements in yambo in the [[Electron Phonon Coupling|electron-phonon tutorial]].&lt;br /&gt;
&lt;br /&gt;
With Yambopy, we can generate a yambo SAVE folder and import the matrix elements with a single command.&lt;br /&gt;
Typing &lt;br /&gt;
 $yambopy gkkp&lt;br /&gt;
will print the necessary documentation:&lt;br /&gt;
 Produce a SAVE folder including elph_gkkp databases&lt;br /&gt;
 &lt;br /&gt;
 Arguments are:&lt;br /&gt;
   -nscf, --nscf_dir  -&amp;gt; &amp;lt;Optional&amp;gt; Path to nscf save folder&lt;br /&gt;
   -elph, --elph_dir  -&amp;gt; Path to elph_dir folder&lt;br /&gt;
   -y, --yambo_dir    -&amp;gt; &amp;lt;Optional&amp;gt; Path to yambo executables&lt;br /&gt;
   -e, --expand       -&amp;gt; &amp;lt;Optional&amp;gt; Expand gkkp databases&lt;br /&gt;
&lt;br /&gt;
The necessary quantum espresso databases are stored in &amp;lt;code&amp;gt;ELPH_SAVES/QE_SAVES/hBN.save&amp;lt;/code&amp;gt; (nscf calculation) and &amp;lt;code&amp;gt;ELPH_SAVES/QE_SAVES/elph_dir&amp;lt;/code&amp;gt; (matrix elements from the dfpt calculation). For this tutorial we also need to expand the electron-phonon matrix elements to the full Brillouin zone. Since this is a different calculation with respect to the previous section, please generate this SAVE in a different directory than the one you used for the previous SAVE, which should be the current directory.&lt;br /&gt;
For example:&lt;br /&gt;
 $mkdir yambo-with-elph&lt;br /&gt;
 $cd yambo-with-elph&lt;br /&gt;
&lt;br /&gt;
Now we can run yambopy as in the instructions:&lt;br /&gt;
 $yambopy gkkp -nscf ../ELPH_saves/QE_saves/hBN.save -elph ../ELPH_saves/QE_saves/elph_dir --expand&lt;br /&gt;
This should generate a yambo SAVE folder which contains the &amp;lt;code&amp;gt;ndb.elph_gkkp_expanded*&amp;lt;/code&amp;gt; databases.&lt;br /&gt;
&lt;br /&gt;
=== Electron-phonon intro: plots of el-ph matrix elements on k-BZ and q-BZ ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; and read the electron-phonon databases that you generated in the previous section.&lt;br /&gt;
&lt;br /&gt;
In order to read the &amp;lt;code&amp;gt;ndb.elph_gkkp_expanded*&amp;lt;/code&amp;gt; databases in python we use the Yambopy class &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
 yelph = YamboElectronPhononDB(ylat,folder_gkkp=&#039;path/to/elph/folder&#039;,save=&#039;path/to/SAVE&#039;)&lt;br /&gt;
(notice that it requires a previous instance of &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Now, the &amp;lt;code&amp;gt;yelph&amp;lt;/code&amp;gt; object contains phonon frequencies, phonon eigenvectors, qpoint information and, of course, the electron-phonon matrix elements g_{nm\nu}(k,q) where n, m are electron band states, \nu is a phonon branch, and k and q are the electronic and transfer momenta.&lt;br /&gt;
&lt;br /&gt;
We can print the docstring of the &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt; class with&lt;br /&gt;
 print(yelph.__doc__)&lt;br /&gt;
to get an idea of the information stored and of its capabilities.&lt;br /&gt;
&lt;br /&gt;
Now check the &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; script. You will see that it performs two plots: &lt;br /&gt;
* Plot of |g(k)| in the k-BZ for selected n,m,\nu and q [&amp;lt;code&amp;gt;Kspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Plot of |g(q)| in the q-BZ for selected n,m,\nu and k [&amp;lt;code&amp;gt;Qspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
You can change the electronic, phononic and momentum indices to see what happens.&lt;br /&gt;
&lt;br /&gt;
[[File:Elph hbn.jpg|YamboElectronPhononDB plot from yambopy tutorial|500px]]&lt;/div&gt;</summary>
		<author><name>FulvioPaleari</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_electron-phonon_coupling&amp;diff=9309</id>
		<title>Yambopy tutorial: electron-phonon coupling</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_electron-phonon_coupling&amp;diff=9309"/>
		<updated>2026-03-10T09:40:46Z</updated>

		<summary type="html">&lt;p&gt;FulvioPaleari: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial we will cover the handling of electron-phonon coupling matrix elements by Yambopy. The electron-phonon calculation follows two steps:&lt;br /&gt;
1. Quantum Espresso calculation of phonon energies, eigenmodes and variations of the self-consistent potential via &amp;lt;code&amp;gt;ph.x&amp;lt;/code&amp;gt;.&lt;br /&gt;
2. Electron-phonon matrix element calculation, symmetry expansion and conversion by the &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For more information on the &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; and how you should run step 1., please see the related documentation [https://github.com/yambo-code/LetzElPhC | here].&lt;br /&gt;
&lt;br /&gt;
* Electron-phonon matrix elements (Yambo databases: &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=== Command line: importing electron-phonon matrix elements ===&lt;br /&gt;
You may have seen how to calculate and import electron-phonon matrix elements in yambo in the [[Electron Phonon Coupling|electron-phonon tutorial]].&lt;br /&gt;
&lt;br /&gt;
With Yambopy, we can generate a yambo SAVE folder and import the matrix elements with a single command.&lt;br /&gt;
Typing &lt;br /&gt;
 $yambopy gkkp&lt;br /&gt;
will print the necessary documentation:&lt;br /&gt;
 Produce a SAVE folder including elph_gkkp databases&lt;br /&gt;
 &lt;br /&gt;
 Arguments are:&lt;br /&gt;
   -nscf, --nscf_dir  -&amp;gt; &amp;lt;Optional&amp;gt; Path to nscf save folder&lt;br /&gt;
   -elph, --elph_dir  -&amp;gt; Path to elph_dir folder&lt;br /&gt;
   -y, --yambo_dir    -&amp;gt; &amp;lt;Optional&amp;gt; Path to yambo executables&lt;br /&gt;
   -e, --expand       -&amp;gt; &amp;lt;Optional&amp;gt; Expand gkkp databases&lt;br /&gt;
&lt;br /&gt;
The necessary quantum espresso databases are stored in &amp;lt;code&amp;gt;ELPH_SAVES/QE_SAVES/hBN.save&amp;lt;/code&amp;gt; (nscf calculation) and &amp;lt;code&amp;gt;ELPH_SAVES/QE_SAVES/elph_dir&amp;lt;/code&amp;gt; (matrix elements from the dfpt calculation). For this tutorial we also need to expand the electron-phonon matrix elements to the full Brillouin zone. Since this is a different calculation with respect to the previous section, please generate this SAVE in a different directory than the one you used for the previous SAVE, which should be the current directory.&lt;br /&gt;
For example:&lt;br /&gt;
 $mkdir yambo-with-elph&lt;br /&gt;
 $cd yambo-with-elph&lt;br /&gt;
&lt;br /&gt;
Now we can run yambopy as in the instructions:&lt;br /&gt;
 $yambopy gkkp -nscf ../ELPH_saves/QE_saves/hBN.save -elph ../ELPH_saves/QE_saves/elph_dir --expand&lt;br /&gt;
This should generate a yambo SAVE folder which contains the &amp;lt;code&amp;gt;ndb.elph_gkkp_expanded*&amp;lt;/code&amp;gt; databases.&lt;br /&gt;
&lt;br /&gt;
=== Electron-phonon intro: plots of el-ph matrix elements on k-BZ and q-BZ ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; and read the electron-phonon databases that you generated in the previous section.&lt;br /&gt;
&lt;br /&gt;
In order to read the &amp;lt;code&amp;gt;ndb.elph_gkkp_expanded*&amp;lt;/code&amp;gt; databases in python we use the Yambopy class &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
 yelph = YamboElectronPhononDB(ylat,folder_gkkp=&#039;path/to/elph/folder&#039;,save=&#039;path/to/SAVE&#039;)&lt;br /&gt;
(notice that it requires a previous instance of &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Now, the &amp;lt;code&amp;gt;yelph&amp;lt;/code&amp;gt; object contains phonon frequencies, phonon eigenvectors, qpoint information and, of course, the electron-phonon matrix elements g_{nm\nu}(k,q) where n, m are electron band states, \nu is a phonon branch, and k and q are the electronic and transfer momenta.&lt;br /&gt;
&lt;br /&gt;
We can print the docstring of the &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt; class with&lt;br /&gt;
 print(yelph.__doc__)&lt;br /&gt;
to get an idea of the information stored and of its capabilities.&lt;br /&gt;
&lt;br /&gt;
Now check the &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; script. You will see that it performs two plots: &lt;br /&gt;
* Plot of |g(k)| in the k-BZ for selected n,m,\nu and q [&amp;lt;code&amp;gt;Kspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Plot of |g(q)| in the q-BZ for selected n,m,\nu and k [&amp;lt;code&amp;gt;Qspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
You can change the electronic, phononic and momentum indices to see what happens.&lt;br /&gt;
&lt;br /&gt;
[[File:Elph hbn.jpg|YamboElectronPhononDB plot from yambopy tutorial|500px]]&lt;/div&gt;</summary>
		<author><name>FulvioPaleari</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_electron-phonon_coupling&amp;diff=9308</id>
		<title>Yambopy tutorial: electron-phonon coupling</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_electron-phonon_coupling&amp;diff=9308"/>
		<updated>2026-03-10T09:40:16Z</updated>

		<summary type="html">&lt;p&gt;FulvioPaleari: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial we will cover the handling of electron-phonon coupling matrix elements by Yambopy. The electron-phonon calculation follows two steps:&lt;br /&gt;
1. Quantum Espresso calculation of phonon energies, eigenmodes and variations of the self-consistent potential via &amp;lt;code&amp;gt;ph.x&amp;lt;/code&amp;gt;.&lt;br /&gt;
2. Electron-phonon matrix element calculation, symmetry expansion and conversion by the &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
For more information on the &amp;lt;code&amp;gt;LetzElPhC&amp;lt;/code&amp;gt; and how you should run step 1., please see the related documentation [[https://github.com/yambo-code/LetzElPhC | here]].&lt;br /&gt;
&lt;br /&gt;
* Electron-phonon matrix elements (Yambo databases: &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=== Command line: importing electron-phonon matrix elements ===&lt;br /&gt;
You may have seen how to calculate and import electron-phonon matrix elements in yambo in the [[Electron Phonon Coupling|electron-phonon tutorial]].&lt;br /&gt;
&lt;br /&gt;
With Yambopy, we can generate a yambo SAVE folder and import the matrix elements with a single command.&lt;br /&gt;
Typing &lt;br /&gt;
 $yambopy gkkp&lt;br /&gt;
will print the necessary documentation:&lt;br /&gt;
 Produce a SAVE folder including elph_gkkp databases&lt;br /&gt;
 &lt;br /&gt;
 Arguments are:&lt;br /&gt;
   -nscf, --nscf_dir  -&amp;gt; &amp;lt;Optional&amp;gt; Path to nscf save folder&lt;br /&gt;
   -elph, --elph_dir  -&amp;gt; Path to elph_dir folder&lt;br /&gt;
   -y, --yambo_dir    -&amp;gt; &amp;lt;Optional&amp;gt; Path to yambo executables&lt;br /&gt;
   -e, --expand       -&amp;gt; &amp;lt;Optional&amp;gt; Expand gkkp databases&lt;br /&gt;
&lt;br /&gt;
The necessary quantum espresso databases are stored in &amp;lt;code&amp;gt;ELPH_SAVES/QE_SAVES/hBN.save&amp;lt;/code&amp;gt; (nscf calculation) and &amp;lt;code&amp;gt;ELPH_SAVES/QE_SAVES/elph_dir&amp;lt;/code&amp;gt; (matrix elements from the dfpt calculation). For this tutorial we also need to expand the electron-phonon matrix elements to the full Brillouin zone. Since this is a different calculation with respect to the previous section, please generate this SAVE in a different directory than the one you used for the previous SAVE, which should be the current directory.&lt;br /&gt;
For example:&lt;br /&gt;
 $mkdir yambo-with-elph&lt;br /&gt;
 $cd yambo-with-elph&lt;br /&gt;
&lt;br /&gt;
Now we can run yambopy as in the instructions:&lt;br /&gt;
 $yambopy gkkp -nscf ../ELPH_saves/QE_saves/hBN.save -elph ../ELPH_saves/QE_saves/elph_dir --expand&lt;br /&gt;
This should generate a yambo SAVE folder which contains the &amp;lt;code&amp;gt;ndb.elph_gkkp_expanded*&amp;lt;/code&amp;gt; databases.&lt;br /&gt;
&lt;br /&gt;
=== Electron-phonon intro: plots of el-ph matrix elements on k-BZ and q-BZ ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; and read the electron-phonon databases that you generated in the previous section.&lt;br /&gt;
&lt;br /&gt;
In order to read the &amp;lt;code&amp;gt;ndb.elph_gkkp_expanded*&amp;lt;/code&amp;gt; databases in python we use the Yambopy class &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
 yelph = YamboElectronPhononDB(ylat,folder_gkkp=&#039;path/to/elph/folder&#039;,save=&#039;path/to/SAVE&#039;)&lt;br /&gt;
(notice that it requires a previous instance of &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Now, the &amp;lt;code&amp;gt;yelph&amp;lt;/code&amp;gt; object contains phonon frequencies, phonon eigenvectors, qpoint information and, of course, the electron-phonon matrix elements g_{nm\nu}(k,q) where n, m are electron band states, \nu is a phonon branch, and k and q are the electronic and transfer momenta.&lt;br /&gt;
&lt;br /&gt;
We can print the docstring of the &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt; class with&lt;br /&gt;
 print(yelph.__doc__)&lt;br /&gt;
to get an idea of the information stored and of its capabilities.&lt;br /&gt;
&lt;br /&gt;
Now check the &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; script. You will see that it performs two plots: &lt;br /&gt;
* Plot of |g(k)| in the k-BZ for selected n,m,\nu and q [&amp;lt;code&amp;gt;Kspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Plot of |g(q)| in the q-BZ for selected n,m,\nu and k [&amp;lt;code&amp;gt;Qspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
You can change the electronic, phononic and momentum indices to see what happens.&lt;br /&gt;
&lt;br /&gt;
[[File:Elph hbn.jpg|YamboElectronPhononDB plot from yambopy tutorial|500px]]&lt;/div&gt;</summary>
		<author><name>FulvioPaleari</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_electron-phonon_coupling&amp;diff=9307</id>
		<title>Yambopy tutorial: electron-phonon coupling</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_electron-phonon_coupling&amp;diff=9307"/>
		<updated>2026-03-10T09:34:25Z</updated>

		<summary type="html">&lt;p&gt;FulvioPaleari: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial we will see some examples on how to read and analyse the data contained in the Yambo netCDF databases, which are not readily available as human readable outputs.&lt;br /&gt;
&lt;br /&gt;
* Electron-phonon matrix elements (Yambo databases: &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=== Command line: importing electron-phonon matrix elements ===&lt;br /&gt;
You may have seen how to calculate and import electron-phonon matrix elements in yambo in the [[Electron Phonon Coupling|electron-phonon tutorial]].&lt;br /&gt;
&lt;br /&gt;
With Yambopy, we can generate a yambo SAVE folder and import the matrix elements with a single command.&lt;br /&gt;
Typing &lt;br /&gt;
 $yambopy gkkp&lt;br /&gt;
will print the necessary documentation:&lt;br /&gt;
 Produce a SAVE folder including elph_gkkp databases&lt;br /&gt;
 &lt;br /&gt;
 Arguments are:&lt;br /&gt;
   -nscf, --nscf_dir  -&amp;gt; &amp;lt;Optional&amp;gt; Path to nscf save folder&lt;br /&gt;
   -elph, --elph_dir  -&amp;gt; Path to elph_dir folder&lt;br /&gt;
   -y, --yambo_dir    -&amp;gt; &amp;lt;Optional&amp;gt; Path to yambo executables&lt;br /&gt;
   -e, --expand       -&amp;gt; &amp;lt;Optional&amp;gt; Expand gkkp databases&lt;br /&gt;
&lt;br /&gt;
The necessary quantum espresso databases are stored in &amp;lt;code&amp;gt;ELPH_SAVES/QE_SAVES/hBN.save&amp;lt;/code&amp;gt; (nscf calculation) and &amp;lt;code&amp;gt;ELPH_SAVES/QE_SAVES/elph_dir&amp;lt;/code&amp;gt; (matrix elements from the dfpt calculation). For this tutorial we also need to expand the electron-phonon matrix elements to the full Brillouin zone. Since this is a different calculation with respect to the previous section, please generate this SAVE in a different directory than the one you used for the previous SAVE, which should be the current directory.&lt;br /&gt;
For example:&lt;br /&gt;
 $mkdir yambo-with-elph&lt;br /&gt;
 $cd yambo-with-elph&lt;br /&gt;
&lt;br /&gt;
Now we can run yambopy as in the instructions:&lt;br /&gt;
 $yambopy gkkp -nscf ../ELPH_saves/QE_saves/hBN.save -elph ../ELPH_saves/QE_saves/elph_dir --expand&lt;br /&gt;
This should generate a yambo SAVE folder which contains the &amp;lt;code&amp;gt;ndb.elph_gkkp_expanded*&amp;lt;/code&amp;gt; databases.&lt;br /&gt;
&lt;br /&gt;
=== Electron-phonon intro: plots of el-ph matrix elements on k-BZ and q-BZ ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; and read the electron-phonon databases that you generated in the previous section.&lt;br /&gt;
&lt;br /&gt;
In order to read the &amp;lt;code&amp;gt;ndb.elph_gkkp_expanded*&amp;lt;/code&amp;gt; databases in python we use the Yambopy class &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
 yelph = YamboElectronPhononDB(ylat,folder_gkkp=&#039;path/to/elph/folder&#039;,save=&#039;path/to/SAVE&#039;)&lt;br /&gt;
(notice that it requires a previous instance of &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Now, the &amp;lt;code&amp;gt;yelph&amp;lt;/code&amp;gt; object contains phonon frequencies, phonon eigenvectors, qpoint information and, of course, the electron-phonon matrix elements g_{nm\nu}(k,q) where n, m are electron band states, \nu is a phonon branch, and k and q are the electronic and transfer momenta.&lt;br /&gt;
&lt;br /&gt;
We can print the docstring of the &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt; class with&lt;br /&gt;
 print(yelph.__doc__)&lt;br /&gt;
to get an idea of the information stored and of its capabilities.&lt;br /&gt;
&lt;br /&gt;
Now check the &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; script. You will see that it performs two plots: &lt;br /&gt;
* Plot of |g(k)| in the k-BZ for selected n,m,\nu and q [&amp;lt;code&amp;gt;Kspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Plot of |g(q)| in the q-BZ for selected n,m,\nu and k [&amp;lt;code&amp;gt;Qspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
You can change the electronic, phononic and momentum indices to see what happens.&lt;br /&gt;
&lt;br /&gt;
[[File:Elph hbn.jpg|YamboElectronPhononDB plot from yambopy tutorial|500px]]&lt;/div&gt;</summary>
		<author><name>FulvioPaleari</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_Yambo_databases&amp;diff=9306</id>
		<title>Yambopy tutorial: Yambo databases</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_Yambo_databases&amp;diff=9306"/>
		<updated>2026-03-10T09:34:12Z</updated>

		<summary type="html">&lt;p&gt;FulvioPaleari: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial we will see some examples on how to read and analyse the data contained in the Yambo netCDF databases, which are not readily available as human readable outputs.&lt;br /&gt;
&lt;br /&gt;
In particular we will take a look at:&lt;br /&gt;
* Lattice geometry data (Yambo database: &amp;lt;code&amp;gt;ns.db1&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
* Dipole matrix elements (Yambo databases: &amp;lt;code&amp;gt;ndb.dipoles&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboDipolesDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
* Exciton energies, symmetries, wavefunctions and spectra (Yambo databases: &amp;lt;code&amp;gt;ndb.BS_diago_Q*&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboExcitonDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
We will also check the command line instructions to quickly generate yambo SAVE folders.&lt;br /&gt;
&lt;br /&gt;
The scripts of the tutorial, but not the databases, can be found in the yambopy directory:&lt;br /&gt;
 $cd tutorial/databases_yambopy&lt;br /&gt;
&lt;br /&gt;
The full tutorial, including the Quantum espresso and Yambo databases that we will read, can be downloaded and extracted from the yambo website:&lt;br /&gt;
 $wget https://media.yambo-code.eu/educational/tutorials/files/databases_yambopy.tar.gz&lt;br /&gt;
 $tar -xvzf databases_yambopy.tar.gz&lt;br /&gt;
 $cd databases_yambopy&lt;br /&gt;
&lt;br /&gt;
We will work with monolayer hexagonal boron nitride electron-phonon and exciton data obtained on a &amp;lt;code&amp;gt;12x12x1&amp;lt;/code&amp;gt; kpoint grid. Beware that these are certainly not converged.&lt;br /&gt;
&lt;br /&gt;
=== Command line: generating the Yambo SAVE ===&lt;br /&gt;
Yambopy offers a set of command line options. In order to review them, you can type&lt;br /&gt;
 $yambopy&lt;br /&gt;
which will print the output&lt;br /&gt;
 yambopy v0.7&lt;br /&gt;
 Available commands are:&lt;br /&gt;
 &lt;br /&gt;
       plotem1s -&amp;gt;     Plot em1s calculation.&lt;br /&gt;
     analysebse -&amp;gt;     Study the convergence of BSE calculations.&lt;br /&gt;
      analysegw -&amp;gt;     Study the convergence of GW calculations by looking at the change in band-gap value.&lt;br /&gt;
   plotexcitons -&amp;gt;     Plot excitons calculation.&lt;br /&gt;
          addqp -&amp;gt;     Add corrections from QP databases.&lt;br /&gt;
        mergeqp -&amp;gt;     Merge QP databases.&lt;br /&gt;
           save -&amp;gt;     Produce a SAVE folder.&lt;br /&gt;
           gkkp -&amp;gt;     Produce a SAVE folder including elph_gkkp databases.&lt;br /&gt;
          bands -&amp;gt;     Script to produce band structure data and visualization from QE.&lt;br /&gt;
         serial -&amp;gt;     Script to update serial numbers of yambo ndb.* databases in order to import them to new calculations.&lt;br /&gt;
     gwsubspace -&amp;gt;     Script to calculate off-diago corrections of yambo ndb.QP databases in order to plot band structure.&lt;br /&gt;
          phinp -&amp;gt;     Script to update the explicit list of q-points in a ph input file (ldisp=.false., qplot=.true.).&lt;br /&gt;
        convert -&amp;gt;     Script to convert RL number in Ry energy units using ndb.gops.&lt;br /&gt;
        bsesize -&amp;gt;     Script to calculate the expected BSE kernel size, in GB, to be loaded by each MPI task.&lt;br /&gt;
            l2y -&amp;gt;     Calculate gauge-invariant electron-phonon matrix elements with LetzElPhC and convert them into Yambo format.&lt;br /&gt;
      exc-irrep -&amp;gt;     Script to get the irreducible representation labels for excitonic states. [-h for help]&lt;br /&gt;
         exc-wf -&amp;gt;     Real space exciton wf for either fixed hole/electron. [-h for help]&lt;br /&gt;
       exc-sort -&amp;gt;     Script to sort excitonic states according to energies and intensities. [-h for help]&lt;br /&gt;
&lt;br /&gt;
For this tutorial, we will need the &amp;lt;code&amp;gt;save&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;gkkp&amp;lt;/code&amp;gt; options.&lt;br /&gt;
By typing in one of these, additional information about how to run the commands will be printed, e.g.:&lt;br /&gt;
 $yambopy save&lt;br /&gt;
 &lt;br /&gt;
 Produce a SAVE folder&lt;br /&gt;
 &lt;br /&gt;
 Arguments are:&lt;br /&gt;
   -nscf, --nscf_dir  -&amp;gt; Path to nscf save folder&lt;br /&gt;
   -y, --yambo_dir    -&amp;gt; &amp;lt;Optional&amp;gt; Path to yambo executables&lt;br /&gt;
&lt;br /&gt;
The quantum espresso save for hBN is provided in the directory &amp;lt;code&amp;gt;BSE_saves/QE_saves/hBN.save&amp;lt;/code&amp;gt; (you can check the contents of the various folders). &lt;br /&gt;
Then, following the instructions printed on screen, we can generate a yambo SAVE from the hBN.save by typing&lt;br /&gt;
&lt;br /&gt;
 $yambopy save -nscf BSE_saves/QE_saves/hBN.save&lt;br /&gt;
&lt;br /&gt;
This should produce a SAVE folder in the current directory.&lt;br /&gt;
&lt;br /&gt;
=== Lattice intro: plot k-point coordinates in IBZ/BZ ===&lt;br /&gt;
For this section we will use the script &amp;lt;code&amp;gt;bz_plot.py&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
By inspecting the SAVE folder we have just generated, we will find the &amp;lt;code&amp;gt;ns.db1&amp;lt;/code&amp;gt; database which contains all the geometry and lattice information.&lt;br /&gt;
We are now going to read it in python by using the Yambopy class &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
&lt;br /&gt;
 from yambopy import YamboLatticeDB&lt;br /&gt;
 ylat = YamboLatticeDB.from_db_file(filename=&amp;quot;PATH/TO/SAVE/ns.db1&amp;quot;)&lt;br /&gt;
(remember to edit the variable &amp;lt;code&amp;gt;save_path&amp;lt;/code&amp;gt; in order to point at your yambo SAVE).&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;ylat&amp;lt;/code&amp;gt; object now contains many useful information as attributes, such as the k-points in Cartesian or crystal coordinates, the system symmetries, lattice constants and basis vectors in real and reciprocal space, etc.&lt;br /&gt;
The k-points are also automatically expanded in the full Brillouin zone from the irreducible one (you can turn this off with the option &amp;lt;code&amp;gt;Expand=False&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Directly printing the object with&lt;br /&gt;
 print(ylat)&lt;br /&gt;
will also give us some general parameters related to the database. &lt;br /&gt;
&lt;br /&gt;
Now check the &amp;lt;code&amp;gt;bz_plot.py&amp;lt;/code&amp;gt; script. You will see that it performs three plots: &lt;br /&gt;
* Scatterplot of the k-points in Cartesian coordinates with both expanded and unexpanded grids, with annotated indices [&amp;lt;code&amp;gt;Cartesian_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Scatterplot of the k-points in crystal coordinates [&amp;lt;code&amp;gt;Crystal_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Manual transformation of a chosen k-point from irreducible to full Brillouin zone (you can change the index &amp;lt;code&amp;gt;i_k&amp;lt;/code&amp;gt; in the script to check different cases) [&amp;lt;code&amp;gt;Symmetry_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
Below, the result of the first plot.&lt;br /&gt;
&lt;br /&gt;
[[File:Car kpoints hbn.jpg|YamboLatticeDB plot from yambopy tutorial| 500px]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What about the units?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Below we report the relation between units used in Yambo, Quantum Espresso, and Yambopy.&lt;br /&gt;
&lt;br /&gt;
* bohr^-1 (atomic units):                                     &amp;lt;code&amp;gt;YamboLatticeDB.car_kpoints*2.*pi&amp;lt;/code&amp;gt;. Divide by the bohr-to-angstrom conversion factor to obtain angs^-1 &lt;br /&gt;
* Yambo cartesian units (&amp;lt;code&amp;gt;[cc]&amp;lt;/code&amp;gt; in Yambo outputs): &amp;lt;code&amp;gt;YamboLatticeDB.car_kpoints*2.*pi&amp;lt;/code&amp;gt; (same as above).&lt;br /&gt;
* QE cartesian units (&amp;lt;code&amp;gt;[cart. coord. in units 2pi/alat]&amp;lt;/code&amp;gt; in QE outputs): &amp;lt;code&amp;gt;YamboLatticeDB.car_kpoints*YamboLatticeDB.alat[0]&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Internal yambo units (&amp;lt;code&amp;gt;[iku]&amp;lt;/code&amp;gt; in yambo outputs): &amp;lt;code&amp;gt;YamboLatticeDB.iku_kpoints&amp;lt;/code&amp;gt;&lt;br /&gt;
* Fractional coordinates (&amp;lt;code&amp;gt;[rlu]&amp;lt;/code&amp;gt; in yambo, &amp;lt;code&amp;gt;cryst. coord.&amp;lt;/code&amp;gt; in QE): &amp;lt;code&amp;gt;YamboLatticeDB.red_kpoints&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Dipoles intro: plots of dipoles on BZ, plot of IP absorption ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;dipoles_plot.py&amp;lt;/code&amp;gt; and read the dipole databases generated in an optical absorption calculation by yambo. Keep in mind that from now on we will use the &amp;quot;BSE&amp;quot; yambo SAVE generated in the [[#Command line: generating the Yambo SAVE|first section]].&lt;br /&gt;
&lt;br /&gt;
The databases written after a calculation of optical properties with yambo (dipoles, static screening, excitons) are in the directory &amp;lt;code&amp;gt;BSE_saves/BSE_databases&amp;lt;/code&amp;gt;. Here we will also find &amp;lt;code&amp;gt;ndb.dipoles&amp;lt;/code&amp;gt; which is needed now, since it contains the matrix elements d_{vck}(\alpha) where vk and ck are the valence and electron states involved in the transition and \alpha the polarisation direction of the external electric field.&lt;br /&gt;
&lt;br /&gt;
In order to read it in python we use the Yambopy class &amp;lt;code&amp;gt;YamboDipolesDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
 ydip = YamboDipolesDB(ylat,save=&#039;path/to/BSE/databases&#039;,filename=&#039;ndb.dipoles&#039;)&lt;br /&gt;
(notice that it requires a previous instance of &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
In addition, in order to read the Kohn-Sham energies, we can also instance the &amp;lt;code&amp;gt;YamboElectronsDB&amp;lt;/code&amp;gt; as&lt;br /&gt;
 yel = YamboElectronsDB.from_db_file(folder=&#039;path/to/SAVE&#039;) &lt;br /&gt;
&lt;br /&gt;
The object &amp;lt;code&amp;gt;ydip&amp;lt;/code&amp;gt; now has a method that permits to retrieve the independent-particle absorption spectrum with customly chosen energy range, steps, and broadening:&lt;br /&gt;
 w, eps2 = ydip.ip_eps2(yel)&lt;br /&gt;
&lt;br /&gt;
In order to see all this in action, take a look at the &amp;lt;code&amp;gt;dipoles_plot.py&amp;lt;/code&amp;gt; script. You will see that it performs two plots:&lt;br /&gt;
* Plot of |d(k)| in the BZ for selected v,c and \alpha (we choose the layer plane &#039;xy&#039;) [&amp;lt;code&amp;gt;Kspace_Plot=True&amp;lt;/code&amp;gt;]. From this plot you can appreciate which sections of the BZ contribute the most to the absorption rate.&lt;br /&gt;
* Plot of the independent-particles absorption spectrum [&amp;lt;code&amp;gt;Absorption_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
You can play with the indices and the plot parameters to check what happens.&lt;br /&gt;
&lt;br /&gt;
[[File:Dipoles hbn2.png|YamboDipolesDB plot from yambopy tutorial|500px]]&lt;br /&gt;
&lt;br /&gt;
=== Exciton intro 1: read and sort data ===&lt;br /&gt;
In this section we will use both the script &amp;lt;code&amp;gt;exc_read.py&amp;lt;/code&amp;gt; and the command line in order to read the exciton data resulting from a BSE calculation to familiarise with their structure. This time we are going to read the &amp;lt;code&amp;gt;ndb.BS_diago_Q*&amp;lt;/code&amp;gt; databases which correspond to BSE calculations at various momenta Q (Q=1 being the zero-momentum optical absorption limit - notice that python indexing starts from 0, while the databases are counted starting from 1).&lt;br /&gt;
&lt;br /&gt;
In order to read them in python we use the Yambopy class &amp;lt;code&amp;gt;YamboExcitonDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
 yexc = YamboExcitonDB.from_db_file(ylat,filename=f&#039;path/to/BSE/databases/ndb.BS_diago_Q{i}&#039;)&lt;br /&gt;
(where i is the number of BS_diago_Qi file. Notice that it requires a previous instance of &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Now the &amp;lt;code&amp;gt;yexc&amp;lt;/code&amp;gt; object contains information about the exciton energies (&amp;lt;code&amp;gt;yexc.eigenvalues&amp;lt;/code&amp;gt;), wave functions (&amp;lt;code&amp;gt;yexc.eigenvectors&amp;lt;/code&amp;gt;) and intensities (&amp;lt;code&amp;gt;yexc.l_residuals&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yexc.r_residuals&amp;lt;/code&amp;gt;) for Qpoint i_Q. You can start by keeping &amp;lt;code&amp;gt;Q1&amp;lt;/code&amp;gt; which is the optical limit and then check other momenta.&lt;br /&gt;
&lt;br /&gt;
The exciton wave function components A_{vck}^{\lambda Q} (\lambda being the exciton index) are stored as A_{t}^{\lambda} in each Q-dependent database, with t being the transition index grouping the single-particle indices vck. Therefore, &amp;lt;code&amp;gt;yexc.eigenvectors&amp;lt;/code&amp;gt; is an array with (N_excitons,N_transitions) dimension. In order to make the connection t-&amp;gt;kcv, the table &amp;lt;code&amp;gt;yexc.table&amp;lt;/code&amp;gt; provides k,v,c and spin indices corresponding to each transition.&lt;br /&gt;
&lt;br /&gt;
In order to get a clearer picture, take a look at the script &amp;lt;code&amp;gt;exc_read.py&amp;lt;/code&amp;gt;. Run it and try to understand the outputs.&lt;br /&gt;
  $ python exc_read.py&lt;br /&gt;
&lt;br /&gt;
Actually, we can produce output files with the sorted exciton energies in a much more convenient way by using the command line instruction &amp;lt;code&amp;gt;exc-sort&amp;lt;/code&amp;gt;. Check its syntax via:&lt;br /&gt;
 $ yambopy exc-sort -h&lt;br /&gt;
&lt;br /&gt;
Then, we run it for our specific calculation with:&lt;br /&gt;
 $ yambopy exc-sort --save BSE_saves/YAMBO_saves/SAVE -J BSE_saves/BSE_databases --iqpt 1&lt;br /&gt;
&lt;br /&gt;
This should produce the &amp;lt;code&amp;gt;o-BSE_databases.exc_qpt1_sorted_E.dat&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;o-BSE_databases.exc_qpt1_sorted_I.dat&amp;lt;/code&amp;gt; output files for you to inspect. These are very useful as they allow for identification of degenerate states and degree of optical activity. You will see that in our system most states are doubly degenerate, a byproduct of crystal symmetry. This is an updated version of the ypp exciton analysis that you can find [[How to analyse excitons#Sort the excitonic eigenvalues|here]].&lt;br /&gt;
&lt;br /&gt;
=== Exciton intro 2: symmetry analysis and wavefunction plot in real space ===&lt;br /&gt;
&lt;br /&gt;
==== Symmetries of excitons====&lt;br /&gt;
We can analyse the symmetries of the excitonic wavefunctions in terms of irreducible representation of the point group of the system (if at Q=0) or the Q little group. For more information, the methodology is explained in Ref. &amp;lt;ref&amp;gt;Symmetries of excitons, M. Nalabothula et al., [https://arxiv.org/abs/2511.21540 preprint arXiv]&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
We use the &amp;lt;code&amp;gt;exc-irrep&amp;lt;/code&amp;gt; command line option, check the arguments with:&lt;br /&gt;
 $ yambopy exc-irrep -h&lt;br /&gt;
&lt;br /&gt;
We know from the previous section (by inspecting the sorted energies) that the first four BSE eigenvalues correspond to two doubly-degenerate bright states. Let us analyse their symmetry by running&lt;br /&gt;
 $ yambopy exc-irrep --path BSE_saves/YAMBO_saves -J BSE_saves/BSE_databases --iqpt 1 --nstates 4&lt;br /&gt;
&lt;br /&gt;
This command first loads the electronic wave functions and calculated the electronic representation matrices (called &amp;lt;code&amp;gt;Dmats&amp;lt;/code&amp;gt; in the code). As a second step, they are used to compute the &#039;&#039;&#039;excitonic&#039;&#039;&#039; representation matrices. &lt;br /&gt;
&lt;br /&gt;
We obtain the following output:&lt;br /&gt;
&lt;br /&gt;
 ========================================&lt;br /&gt;
 Group theory analysis for Q point : (0.000000, 0.000000, 0.000000)&lt;br /&gt;
 ****************************************&lt;br /&gt;
 Little group :  D3h&lt;br /&gt;
 Little group symmetries :  [ 1  2  3  4  5  6  7  8  9 10 11 12]&lt;br /&gt;
 Classes (symmetry indices in each class):&lt;br /&gt;
                E    :  [1]&lt;br /&gt;
             2S_3    :  [2 6]&lt;br /&gt;
             2C_3    :  [3 5]&lt;br /&gt;
          sigma_h    :  [4]&lt;br /&gt;
             3C_2    :  [ 7  9 11]&lt;br /&gt;
         3sigma_v    :  [ 8 10 12]&lt;br /&gt;
 &lt;br /&gt;
 ====== Exciton representations ======&lt;br /&gt;
 Energy (eV),  degeneracy  : representation&lt;br /&gt;
 ----------------------------------------&lt;br /&gt;
 1.9139                2  :  E&#039;&lt;br /&gt;
 2.5988                2  :  E&#039;&lt;br /&gt;
 ****************************************&lt;br /&gt;
&lt;br /&gt;
This is similar to the group theory analysis done by Quantum Espresso on the electronic states, and is actually analogous to the one performed for the phonon modes of crystals. We see that the first two states transform as the E&#039; representation of the D3h point group of the crystal. By optical selection rules, only states with this symmetry can form absorption peaks in monolayer BN when light is polarized along the layer plane.&lt;br /&gt;
&lt;br /&gt;
We could go further and calculate the total crystal angular momentum of these states, while also rotate the degenerate exciton states so that they are both eigenvectors of the BSE Hamiltonian and the total crystal angular momentum operator. This is very useful for analyses involving selection rules, exciton-boson couplings, chirality, etc. This is an advanced topic and will not be covered, nonetheless an example script is provided in the tutorial folder called &amp;lt;code&amp;gt;total_crystal_angular_momentum_exciton.py&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; What to do when symmetry analysis does not seem to work well &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Check for warnings during execution. If the BSE calculation was done with a response function that breaks the symmetries (such as the longitudinal response in place of the transverse one at q=0), that may explain the issues.&lt;br /&gt;
&lt;br /&gt;
* If the exciton density of states is very high (such as for a bulk 3D system or for a 2D system at higher energies in the optical spectrum), the analyser may fail to resolve degenerate states, and incorporate a bunch of states together. The symmetry analysis will still be performed but the representation labels will appear as summed. In severe cases, the code may crash. You can try to get a better result by carefully selecting the degeneracy tolerance with &amp;lt;code&amp;gt;degen_tol&amp;lt;/code&amp;gt; and restricting the number of states with &amp;lt;code&amp;gt;nstates&amp;lt;/code&amp;gt; in the command line options.&lt;br /&gt;
&lt;br /&gt;
====Exciton wave functions in real space====&lt;br /&gt;
We can also plot the wave functions of the exciton states on the crystal lattice. In practice, what we do is set the position of the hole at a &amp;quot;physical&amp;quot; point, and then visualize the resulting electronic distribution:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;I^{e}_{\lambda \mathbf{Q}}(\mathbf{r}_e)= |\Psi_{\alpha \mathbf{Q}}(\mathbf{r}_e,\mathbf{r}_h=\mathbf{r}_0)|^2&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let us focus on the lowest exciton state, which gives rise to the largest peak in absorption (see the last part of the tutorial). We will set the hole position on top of a nitrogen atom, since that&#039;s where the &amp;lt;math&amp;gt;p_z&amp;lt;/math&amp;gt; orbitals where the hole comes from are mostly localized.&lt;br /&gt;
&lt;br /&gt;
If we don&#039;t know the correct coordinates, we can modify the &amp;lt;code&amp;gt;bz_plot.py&amp;lt;/code&amp;gt; script by adding (after instancing the lattice object):&lt;br /&gt;
 for iat in range(len(ylat.atomic_numbers)): print(ylat.atomic_numbers[iat],ylat.red_atomic_positions[iat])&lt;br /&gt;
which will print&lt;br /&gt;
 5 [0.6666667 0.3333333 0.       ]&lt;br /&gt;
 7 [-0.6666667 -0.3333333  0.       ]&lt;br /&gt;
&lt;br /&gt;
In order to make the plot, we have to give yambopy the same inputs that are used in the equivalent [[How to analyse excitons#Plot the exciton spatial distribution| ypp calculation]]. First, let&#039;s check all the options via&lt;br /&gt;
 $ yambopy exc-wf -h&lt;br /&gt;
&lt;br /&gt;
Then, we can run our calculation (by selecting a 9x9x1 supercell and a 30 Ry cutoff) as &lt;br /&gt;
 $ yambopy exc-wf --path BSE_saves/YAMBO_saves -J BSE_saves/BSE_databases --iqpt 1 --iexe 1 --supercell 9 9 1 --wfc_cutoff 30 --hole 0.33333333 0.66666667 0.03&lt;br /&gt;
&lt;br /&gt;
Yambopy will produce a *.cube file that can be visualized with VESTA, xcrysden or the like, producing a figure similar to the one below.&lt;br /&gt;
&lt;br /&gt;
The example script &amp;lt;code&amp;gt;exc_real_wf.py&amp;lt;/code&amp;gt;, which runs the same calculation by explicitly calling the necessary functions, will give you more info about what is happening behind the scenes.&lt;br /&gt;
&lt;br /&gt;
[[File:Exc BN yambopy.png|YamboExcitonDB exciton wave function|400px]]&lt;br /&gt;
&lt;br /&gt;
We see that electron is localised in &amp;lt;math&amp;gt;p_z&amp;lt;/math&amp;gt;-like distributions on top of boron atoms around the nitrogen where the hole is set.&lt;br /&gt;
&lt;br /&gt;
=== Exciton intro 3: plot exciton weights on k-BZ and (interpolated) band structure ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;exc_kspace_plot.py&amp;lt;/code&amp;gt; and work with the quantities defined in the previous section.&lt;br /&gt;
&lt;br /&gt;
For now, only the i_Q=0 case is implemented in this section.&lt;br /&gt;
We want to check the relative importance of the various (vk-&amp;gt;ck) electronic transitions in forming a certain excitonic state. &lt;br /&gt;
&lt;br /&gt;
Since many excitonic states are degenerate, we first need to tell Yambopy which states we want to check. For example, in monolayer hexagonal boron nitride, the lowest-bound exciton - forming the main peak in the BSE absorption spectrum - is doubly degenerate. In order to analyse it, in the &amp;lt;code&amp;gt;exc_kspace_plot.py&amp;lt;/code&amp;gt; script we set&lt;br /&gt;
 states = [1,2]&lt;br /&gt;
(we can also set [3,4] to check the second excitonic state, and then [5] for the non-degenerate third state, and so on; we can check degeneracies by printing the energies using the script &amp;lt;code&amp;gt;exc_read.py&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
In order to make a band structure plot, it is necessary to read the band energies, for example with the &amp;lt;code&amp;gt;YamboSaveDB&amp;lt;/code&amp;gt; class&lt;br /&gt;
 yel = YamboSaveDB.from_db_file(folder=&#039;path/to/SAVE&#039;)&lt;br /&gt;
and specify the path in the BZ using crystal coordinates via the &amp;lt;code&amp;gt;Path&amp;lt;/code&amp;gt; function:   &lt;br /&gt;
 npoints = 20&lt;br /&gt;
 path = Path([ [[  0.0,  0.0,  0.0],&#039;$\Gamma$&#039;],&lt;br /&gt;
               [[  0.5,  0.0,  0.0],&#039;M&#039;],&lt;br /&gt;
               [[1./3.,1./3.,  0.0],&#039;K&#039;],&lt;br /&gt;
               [[  0.0,  0.0,  0.0],&#039;$\Gamma$&#039;]],&lt;br /&gt;
               [int(npoints*2),int(npoints),int(sqrt(5)*npoints)] )&lt;br /&gt;
&lt;br /&gt;
Now let&#039;s take a closer look at the &amp;lt;code&amp;gt;exc_kspace_plot.py&amp;lt;/code&amp;gt; script. You will see that it performs three plots:&lt;br /&gt;
* Plot of |A(k)| in the k-BZ for the selected exciton state. You can see how most contributions come from the area around K and the MK direction [&amp;lt;code&amp;gt;Kspace_Plot=True&amp;lt;/code&amp;gt;]. &lt;br /&gt;
* Plot of |A(v,c,k)| on the electronic band structure for the selected exciton state. Here you can better see how the top valence and bottom conduction around MK are mostly involved [&amp;lt;code&amp;gt;Bands_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Plot of interpolated |A(v,c,k)| on the interpolated electronic band structure for the selected exciton state [&amp;lt;code&amp;gt;Bands_Plot_Interpolated=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
As always, try to play with the parameters, for example by changing the excitonic states to analyse.&lt;br /&gt;
&lt;br /&gt;
[[File:Exc bands1 hbn.jpg|YamboExcitonDB plot from yambopy tutorial|300px| Uninterpolated exciton weights on top of band structure]][[File:Exc bands2 hbn.jpg|YamboExcitonDB plot from yambopy tutorial|300px]]&lt;br /&gt;
&lt;br /&gt;
=== Exciton intro 4: plot BSE optical absorption with custom options ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;exc_abs_plot.py&amp;lt;/code&amp;gt; and work with the quantities defined in the previous sections.&lt;br /&gt;
&lt;br /&gt;
The class &amp;lt;code&amp;gt;YamboExcitonDB&amp;lt;/code&amp;gt; also enables us, of course, to read the dielectric function eps(w) and print absorption and related spectra in python.&lt;br /&gt;
&lt;br /&gt;
The advantages over using the standard human-readable yambo outputs are mainly two:&lt;br /&gt;
# We can freely select energy ranges, energy steps, peak broadenings and number of excitonic states included without having to rerun the &amp;lt;code&amp;gt;yambo&amp;lt;/code&amp;gt; executable every time. This reduces the chance of mistakenly editing the yambo input and allows for greater freedom since these plots can now be done in your local machine without having to transfer the output data from a remote cluster.&lt;br /&gt;
# The dielectric function constructed from netCDF database variables has a much higher precision (number of significant digits) than the human readable output, which may be important if you want to perform additional operations in python (e.g., computing refractive index, reflectivity and other optical spectra from it, performing finite-difference derivatives, etc).&lt;br /&gt;
&lt;br /&gt;
We can read eps(w) as a &amp;lt;code&amp;gt;numpy&amp;lt;/code&amp;gt; array with the specified options as (energy values are in eV):&lt;br /&gt;
 w, eps = yexc.get_chi(nexcitons=&#039;all&#039;,emin=0,emax=7,estep=0.005,broad=0.04)&lt;br /&gt;
Or, you can directly prepare a plot of its imaginary part with&lt;br /&gt;
 w, chi = yexc.plot_chi_ax(ax,nexcitons=&#039;all&#039;,emin=0,emax=7,estep=0.005,broad=0.04)&lt;br /&gt;
where &amp;lt;code&amp;gt;ax&amp;lt;/code&amp;gt; is a previously defined &amp;lt;code&amp;gt;Axes&amp;lt;/code&amp;gt; object from &amp;lt;code&amp;gt;matplotlib&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In order to see how this works, let&#039;s take a look at the &amp;lt;code&amp;gt;exc_abs_plot.py&amp;lt;/code&amp;gt; script.&lt;br /&gt;
You will see that it performs the two operations described above:&lt;br /&gt;
* Plotting the BSE absorption spectrum [&amp;lt;code&amp;gt;Absorption_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Reading the complex dielectric function.&lt;br /&gt;
&lt;br /&gt;
Try to customise the plots by changing the &amp;lt;code&amp;gt;nexcitons&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;emin&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;emax&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;estep&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;broad&amp;lt;/code&amp;gt; parameters.&lt;br /&gt;
&lt;br /&gt;
[[File:Absalpha.png|Yambo alpha_2D tutorial plot|700px]]&lt;br /&gt;
&lt;br /&gt;
==Links==&lt;br /&gt;
* Back to [[Rome 2023#Tutorials]]&lt;br /&gt;
* Back to [[ICTP 2022#Tutorials]]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;/div&gt;</summary>
		<author><name>FulvioPaleari</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_electron-phonon_coupling&amp;diff=9305</id>
		<title>Yambopy tutorial: electron-phonon coupling</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_electron-phonon_coupling&amp;diff=9305"/>
		<updated>2026-03-10T09:33:32Z</updated>

		<summary type="html">&lt;p&gt;FulvioPaleari: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial we will see some examples on how to read and analyse the data contained in the Yambo netCDF databases, which are not readily available as human readable outputs.&lt;br /&gt;
&lt;br /&gt;
* Electron-phonon matrix elements (Yambo databases: &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=== Electron-phonon intro: plots of el-ph matrix elements on k-BZ and q-BZ ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; and read the electron-phonon databases that you generated in the previous section.&lt;br /&gt;
&lt;br /&gt;
In order to read the &amp;lt;code&amp;gt;ndb.elph_gkkp_expanded*&amp;lt;/code&amp;gt; databases in python we use the Yambopy class &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
 yelph = YamboElectronPhononDB(ylat,folder_gkkp=&#039;path/to/elph/folder&#039;,save=&#039;path/to/SAVE&#039;)&lt;br /&gt;
(notice that it requires a previous instance of &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Now, the &amp;lt;code&amp;gt;yelph&amp;lt;/code&amp;gt; object contains phonon frequencies, phonon eigenvectors, qpoint information and, of course, the electron-phonon matrix elements g_{nm\nu}(k,q) where n, m are electron band states, \nu is a phonon branch, and k and q are the electronic and transfer momenta.&lt;br /&gt;
&lt;br /&gt;
We can print the docstring of the &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt; class with&lt;br /&gt;
 print(yelph.__doc__)&lt;br /&gt;
to get an idea of the information stored and of its capabilities.&lt;br /&gt;
&lt;br /&gt;
Now check the &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; script. You will see that it performs two plots: &lt;br /&gt;
* Plot of |g(k)| in the k-BZ for selected n,m,\nu and q [&amp;lt;code&amp;gt;Kspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Plot of |g(q)| in the q-BZ for selected n,m,\nu and k [&amp;lt;code&amp;gt;Qspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
You can change the electronic, phononic and momentum indices to see what happens.&lt;br /&gt;
&lt;br /&gt;
[[File:Elph hbn.jpg|YamboElectronPhononDB plot from yambopy tutorial|500px]]&lt;/div&gt;</summary>
		<author><name>FulvioPaleari</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=First_steps_in_Yambopy&amp;diff=9304</id>
		<title>First steps in Yambopy</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=First_steps_in_Yambopy&amp;diff=9304"/>
		<updated>2026-03-10T09:32:49Z</updated>

		<summary type="html">&lt;p&gt;FulvioPaleari: /* Tutorials */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The yambopy project aims to develop python tools to: &lt;br /&gt;
&lt;br /&gt;
* Read and edit yambo and quantum espresso input files&lt;br /&gt;
* Easily perform pre- and post-processing of the simulation data for these two codes - including hard-to-get, database-encoded data beyond standard outputs&lt;br /&gt;
* Provide easy visualization and plotting options &lt;br /&gt;
* Set up simple automatization workflows (e.g., convergence tests)&lt;br /&gt;
&lt;br /&gt;
=== Setup ===&lt;br /&gt;
First of all, make sure that you have a suitable python environment (crated for example with [https://docs.anaconda.com/miniconda/install/ conda] or [https://docs.python.org/3/library/venv.html venv]) with &#039;&#039;&#039;python &amp;gt;=3.8&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
If you are not used with python environments, here two simple commands that you can use&lt;br /&gt;
 python -m venv MYPATH/yamboenv/&lt;br /&gt;
(you can replace `MYPATH` with any path you prefer, e.g. `~/`)&lt;br /&gt;
 source MYPATH/yamboenv/bin/activate&lt;br /&gt;
(for bash users, you can add to your .bashrt the line `. MYPATH/yamboenv/bin/activate`)&lt;br /&gt;
&lt;br /&gt;
Then, you may install yambopy in one of the following ways.&lt;br /&gt;
&lt;br /&gt;
==== Quick installation from PyPI repository ====&lt;br /&gt;
&lt;br /&gt;
* In order to quickly install the officially released version type:&lt;br /&gt;
&lt;br /&gt;
 pip install yambopy&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Installation from tarball ====&lt;br /&gt;
&lt;br /&gt;
* In case you don&#039;t want to download from the pip repository and prefer to install a version of yambopy locally, you may download the appropriate tarball from the [https://github.com/yambo-code/yambopy/releases| yambopy github page]. Extract the tarball, enter the yambopy folder and type &amp;lt;code&amp;gt;pip install .&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Installation of latest patch ====&lt;br /&gt;
&lt;br /&gt;
* In case you want the latest version of the code including new updates and patches that might not be present in the official version, then you can clone the yambopy git repository (a basic knowledge of git may be helpful):&lt;br /&gt;
&lt;br /&gt;
 git clone https://github.com/yambo-code/yambopy.git&lt;br /&gt;
 cd yambopy&lt;br /&gt;
 pip install .&lt;br /&gt;
&lt;br /&gt;
==== Installation for developers ====&lt;br /&gt;
* If you want to install YamboPy in developing mode (to modify or add new functions) you have to download the code from github repository then go in the YamboPy folder and install with the command:&lt;br /&gt;
&lt;br /&gt;
 pip install -e .&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important:&#039;&#039;&#039; if you want your changes to be included into a new patch/version of Yambopy, you need to first create your own personal fork of the git repository, make the changes there, and then create a pull request for the original repository. &lt;br /&gt;
&lt;br /&gt;
==== Dependencies ====&lt;br /&gt;
&lt;br /&gt;
* In principle, &amp;lt;code&amp;gt;pip&amp;lt;/code&amp;gt; should take care of the required python dependencies. They are &amp;lt;code&amp;gt;numpy&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;scipy&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;matplotlib&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;netCDF4&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;h5py&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;lxml&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;PyYAML&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;monty&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;scikit-learn&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;tqdm&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;spglib&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;spgrep&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;pykdtree&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;numba&amp;lt;/code&amp;gt;. In case some dependency-related problem arises, you can install each of them separately beforehand with:&lt;br /&gt;
&lt;br /&gt;
 pip install &amp;lt;code&amp;gt;dependency-name&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* If you experience errors related to &amp;lt;code&amp;gt;NetCDF4&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;hdf5&amp;lt;/code&amp;gt;, these are usually due to incompatibilities between the python modules the library in your environment. In this case, you can force the python installation to match the system library. For example, if you have an &amp;lt;code&amp;gt;hdf5&amp;lt;/code&amp;gt; problem and you are using conda, you could try:&lt;br /&gt;
&lt;br /&gt;
 conda install --force-reinstall h5py hdf5&lt;br /&gt;
&lt;br /&gt;
=== Tutorials ===&lt;br /&gt;
Now yambopy is ready to use! Just go to the tutorials folder and follow the docs!&lt;br /&gt;
&lt;br /&gt;
 cd tutorial/&lt;br /&gt;
&lt;br /&gt;
On this wiki, we provide steps for the following tutorials:&lt;br /&gt;
&lt;br /&gt;
1. Data postprocessing:&lt;br /&gt;
* [[Yambopy tutorial: band structures | Database and plotting tutorial for quantum espresso (qepy) and GW &#039;&#039;&#039;band structures&#039;&#039;&#039;]] (Get the databases: [https://media.yambo-code.eu/educational/tutorials/files/databases_qepy.tar.gz databases_qepy], 46.5MB)&lt;br /&gt;
* [[Yambopy tutorial: Yambo databases | Database and plotting tutorial for yambo (yambopy) and &#039;&#039;&#039;exciton&#039;&#039;&#039; analysis ]] (Get the databases: [https://media.yambo-code.eu/educational/tutorials/files/databases_yambopy.tar.gz databases_yambopy], 129MB)&lt;br /&gt;
2. Manage QE and Yambo runs: [WARNING: these tutorials are currently under maintenance due to updates to the scheduler class]&lt;br /&gt;
* [[GW tutorial. Convergence and approximations (BN)]]&lt;br /&gt;
* [[Bethe-Salpeter equation tutorial. Optical absorption (BN)]]&lt;br /&gt;
3. Advanced topics:&lt;br /&gt;
* [[Yambopy tutorial: electron-phonon coupling|Databases and plotting tutorial for electron-phonon coupling with yambopy]] (Get the databases: )&lt;br /&gt;
* [[Exciton-phonon coupling and luminescence]]&lt;br /&gt;
* [[Phonon-assisted luminescence by finite atomic displacements]]&lt;br /&gt;
&lt;br /&gt;
=== How to cite ===&lt;br /&gt;
If yambopy helped you with your data analysis, workflow management of figure preparation, you can consider citing us.&lt;br /&gt;
&lt;br /&gt;
The way to do so in BibTeX format is the following:&lt;br /&gt;
 @misc{yambopy, &lt;br /&gt;
      author = {Paleari, Fulvio and Molina-Sánchez, Alejandro and Nalabothula, Muralidhar and Reho, Riccardo and Bonacci, Miki and Castelo, José M. and Cervantes-Villanueva, Jorge and Pionteck, Mike and Silvetti, Martino and Attaccalite, Claudio and Pereira Coutada Miranda, Henrique},&lt;br /&gt;
      title = {Yambopy},&lt;br /&gt;
      month = mar,&lt;br /&gt;
      year = 2025,&lt;br /&gt;
      publisher = {Zenodo},&lt;br /&gt;
      version = {0.4.0}, &lt;br /&gt;
      doi = {10.5281/zenodo.15012962},&lt;br /&gt;
      url = {[[https://doi.org/10.5281/zenodo.15012962 https://doi.org/10.5281/zenodo.15012962]]}, }&lt;/div&gt;</summary>
		<author><name>FulvioPaleari</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_Yambo_databases&amp;diff=9303</id>
		<title>Yambopy tutorial: Yambo databases</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_Yambo_databases&amp;diff=9303"/>
		<updated>2026-03-09T19:12:58Z</updated>

		<summary type="html">&lt;p&gt;FulvioPaleari: /* Command line: generating the Yambo SAVE */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial we will see some examples on how to read and analyse the data contained in the Yambo netCDF databases, which are not readily available as human readable outputs.&lt;br /&gt;
&lt;br /&gt;
In particular we will take a look at:&lt;br /&gt;
* Lattice geometry data (Yambo database: &amp;lt;code&amp;gt;ns.db1&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
* Dipole matrix elements (Yambo databases: &amp;lt;code&amp;gt;ndb.dipoles&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboDipolesDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
* Exciton energies, symmetries, wavefunctions and spectra (Yambo databases: &amp;lt;code&amp;gt;ndb.BS_diago_Q*&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboExcitonDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
We will also check the command line instructions to quickly generate yambo SAVE folders.&lt;br /&gt;
&lt;br /&gt;
The scripts of the tutorial, but not the databases, can be found in the yambopy directory:&lt;br /&gt;
 $cd tutorial/databases_yambopy&lt;br /&gt;
&lt;br /&gt;
The full tutorial, including the Quantum espresso and Yambo databases that we will read, can be downloaded and extracted from the yambo website:&lt;br /&gt;
 $wget https://media.yambo-code.eu/educational/tutorials/files/databases_yambopy.tar.gz&lt;br /&gt;
 $tar -xvzf databases_yambopy.tar.gz&lt;br /&gt;
 $cd databases_yambopy&lt;br /&gt;
&lt;br /&gt;
We will work with monolayer hexagonal boron nitride electron-phonon and exciton data obtained on a &amp;lt;code&amp;gt;12x12x1&amp;lt;/code&amp;gt; kpoint grid. Beware that these are certainly not converged.&lt;br /&gt;
&lt;br /&gt;
=== Command line: generating the Yambo SAVE ===&lt;br /&gt;
Yambopy offers a set of command line options. In order to review them, you can type&lt;br /&gt;
 $yambopy&lt;br /&gt;
which will print the output&lt;br /&gt;
 yambopy v0.7&lt;br /&gt;
 Available commands are:&lt;br /&gt;
 &lt;br /&gt;
       plotem1s -&amp;gt;     Plot em1s calculation.&lt;br /&gt;
     analysebse -&amp;gt;     Study the convergence of BSE calculations.&lt;br /&gt;
      analysegw -&amp;gt;     Study the convergence of GW calculations by looking at the change in band-gap value.&lt;br /&gt;
   plotexcitons -&amp;gt;     Plot excitons calculation.&lt;br /&gt;
          addqp -&amp;gt;     Add corrections from QP databases.&lt;br /&gt;
        mergeqp -&amp;gt;     Merge QP databases.&lt;br /&gt;
           save -&amp;gt;     Produce a SAVE folder.&lt;br /&gt;
           gkkp -&amp;gt;     Produce a SAVE folder including elph_gkkp databases.&lt;br /&gt;
          bands -&amp;gt;     Script to produce band structure data and visualization from QE.&lt;br /&gt;
         serial -&amp;gt;     Script to update serial numbers of yambo ndb.* databases in order to import them to new calculations.&lt;br /&gt;
     gwsubspace -&amp;gt;     Script to calculate off-diago corrections of yambo ndb.QP databases in order to plot band structure.&lt;br /&gt;
          phinp -&amp;gt;     Script to update the explicit list of q-points in a ph input file (ldisp=.false., qplot=.true.).&lt;br /&gt;
        convert -&amp;gt;     Script to convert RL number in Ry energy units using ndb.gops.&lt;br /&gt;
        bsesize -&amp;gt;     Script to calculate the expected BSE kernel size, in GB, to be loaded by each MPI task.&lt;br /&gt;
            l2y -&amp;gt;     Calculate gauge-invariant electron-phonon matrix elements with LetzElPhC and convert them into Yambo format.&lt;br /&gt;
      exc-irrep -&amp;gt;     Script to get the irreducible representation labels for excitonic states. [-h for help]&lt;br /&gt;
         exc-wf -&amp;gt;     Real space exciton wf for either fixed hole/electron. [-h for help]&lt;br /&gt;
       exc-sort -&amp;gt;     Script to sort excitonic states according to energies and intensities. [-h for help]&lt;br /&gt;
&lt;br /&gt;
For this tutorial, we will need the &amp;lt;code&amp;gt;save&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;gkkp&amp;lt;/code&amp;gt; options.&lt;br /&gt;
By typing in one of these, additional information about how to run the commands will be printed, e.g.:&lt;br /&gt;
 $yambopy save&lt;br /&gt;
 &lt;br /&gt;
 Produce a SAVE folder&lt;br /&gt;
 &lt;br /&gt;
 Arguments are:&lt;br /&gt;
   -nscf, --nscf_dir  -&amp;gt; Path to nscf save folder&lt;br /&gt;
   -y, --yambo_dir    -&amp;gt; &amp;lt;Optional&amp;gt; Path to yambo executables&lt;br /&gt;
&lt;br /&gt;
The quantum espresso save for hBN is provided in the directory &amp;lt;code&amp;gt;BSE_saves/QE_saves/hBN.save&amp;lt;/code&amp;gt; (you can check the contents of the various folders). &lt;br /&gt;
Then, following the instructions printed on screen, we can generate a yambo SAVE from the hBN.save by typing&lt;br /&gt;
&lt;br /&gt;
 $yambopy save -nscf BSE_saves/QE_saves/hBN.save&lt;br /&gt;
&lt;br /&gt;
This should produce a SAVE folder in the current directory.&lt;br /&gt;
&lt;br /&gt;
=== Lattice intro: plot k-point coordinates in IBZ/BZ ===&lt;br /&gt;
For this section we will use the script &amp;lt;code&amp;gt;bz_plot.py&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
By inspecting the SAVE folder we have just generated, we will find the &amp;lt;code&amp;gt;ns.db1&amp;lt;/code&amp;gt; database which contains all the geometry and lattice information.&lt;br /&gt;
We are now going to read it in python by using the Yambopy class &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
&lt;br /&gt;
 from yambopy import YamboLatticeDB&lt;br /&gt;
 ylat = YamboLatticeDB.from_db_file(filename=&amp;quot;PATH/TO/SAVE/ns.db1&amp;quot;)&lt;br /&gt;
(remember to edit the variable &amp;lt;code&amp;gt;save_path&amp;lt;/code&amp;gt; in order to point at your yambo SAVE).&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;ylat&amp;lt;/code&amp;gt; object now contains many useful information as attributes, such as the k-points in Cartesian or crystal coordinates, the system symmetries, lattice constants and basis vectors in real and reciprocal space, etc.&lt;br /&gt;
The k-points are also automatically expanded in the full Brillouin zone from the irreducible one (you can turn this off with the option &amp;lt;code&amp;gt;Expand=False&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Directly printing the object with&lt;br /&gt;
 print(ylat)&lt;br /&gt;
will also give us some general parameters related to the database. &lt;br /&gt;
&lt;br /&gt;
Now check the &amp;lt;code&amp;gt;bz_plot.py&amp;lt;/code&amp;gt; script. You will see that it performs three plots: &lt;br /&gt;
* Scatterplot of the k-points in Cartesian coordinates with both expanded and unexpanded grids, with annotated indices [&amp;lt;code&amp;gt;Cartesian_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Scatterplot of the k-points in crystal coordinates [&amp;lt;code&amp;gt;Crystal_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Manual transformation of a chosen k-point from irreducible to full Brillouin zone (you can change the index &amp;lt;code&amp;gt;i_k&amp;lt;/code&amp;gt; in the script to check different cases) [&amp;lt;code&amp;gt;Symmetry_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
Below, the result of the first plot.&lt;br /&gt;
&lt;br /&gt;
[[File:Car kpoints hbn.jpg|YamboLatticeDB plot from yambopy tutorial| 500px]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What about the units?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Below we report the relation between units used in Yambo, Quantum Espresso, and Yambopy.&lt;br /&gt;
&lt;br /&gt;
* bohr^-1 (atomic units):                                     &amp;lt;code&amp;gt;YamboLatticeDB.car_kpoints*2.*pi&amp;lt;/code&amp;gt;. Divide by the bohr-to-angstrom conversion factor to obtain angs^-1 &lt;br /&gt;
* Yambo cartesian units (&amp;lt;code&amp;gt;[cc]&amp;lt;/code&amp;gt; in Yambo outputs): &amp;lt;code&amp;gt;YamboLatticeDB.car_kpoints*2.*pi&amp;lt;/code&amp;gt; (same as above).&lt;br /&gt;
* QE cartesian units (&amp;lt;code&amp;gt;[cart. coord. in units 2pi/alat]&amp;lt;/code&amp;gt; in QE outputs): &amp;lt;code&amp;gt;YamboLatticeDB.car_kpoints*YamboLatticeDB.alat[0]&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Internal yambo units (&amp;lt;code&amp;gt;[iku]&amp;lt;/code&amp;gt; in yambo outputs): &amp;lt;code&amp;gt;YamboLatticeDB.iku_kpoints&amp;lt;/code&amp;gt;&lt;br /&gt;
* Fractional coordinates (&amp;lt;code&amp;gt;[rlu]&amp;lt;/code&amp;gt; in yambo, &amp;lt;code&amp;gt;cryst. coord.&amp;lt;/code&amp;gt; in QE): &amp;lt;code&amp;gt;YamboLatticeDB.red_kpoints&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Dipoles intro: plots of dipoles on BZ, plot of IP absorption ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;dipoles_plot.py&amp;lt;/code&amp;gt; and read the dipole databases generated in an optical absorption calculation by yambo. Keep in mind that from now on we will use the &amp;quot;BSE&amp;quot; yambo SAVE generated in the [[#Command line: generating the Yambo SAVE|first section]].&lt;br /&gt;
&lt;br /&gt;
The databases written after a calculation of optical properties with yambo (dipoles, static screening, excitons) are in the directory &amp;lt;code&amp;gt;BSE_saves/BSE_databases&amp;lt;/code&amp;gt;. Here we will also find &amp;lt;code&amp;gt;ndb.dipoles&amp;lt;/code&amp;gt; which is needed now, since it contains the matrix elements d_{vck}(\alpha) where vk and ck are the valence and electron states involved in the transition and \alpha the polarisation direction of the external electric field.&lt;br /&gt;
&lt;br /&gt;
In order to read it in python we use the Yambopy class &amp;lt;code&amp;gt;YamboDipolesDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
 ydip = YamboDipolesDB(ylat,save=&#039;path/to/BSE/databases&#039;,filename=&#039;ndb.dipoles&#039;)&lt;br /&gt;
(notice that it requires a previous instance of &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
In addition, in order to read the Kohn-Sham energies, we can also instance the &amp;lt;code&amp;gt;YamboElectronsDB&amp;lt;/code&amp;gt; as&lt;br /&gt;
 yel = YamboElectronsDB.from_db_file(folder=&#039;path/to/SAVE&#039;) &lt;br /&gt;
&lt;br /&gt;
The object &amp;lt;code&amp;gt;ydip&amp;lt;/code&amp;gt; now has a method that permits to retrieve the independent-particle absorption spectrum with customly chosen energy range, steps, and broadening:&lt;br /&gt;
 w, eps2 = ydip.ip_eps2(yel)&lt;br /&gt;
&lt;br /&gt;
In order to see all this in action, take a look at the &amp;lt;code&amp;gt;dipoles_plot.py&amp;lt;/code&amp;gt; script. You will see that it performs two plots:&lt;br /&gt;
* Plot of |d(k)| in the BZ for selected v,c and \alpha (we choose the layer plane &#039;xy&#039;) [&amp;lt;code&amp;gt;Kspace_Plot=True&amp;lt;/code&amp;gt;]. From this plot you can appreciate which sections of the BZ contribute the most to the absorption rate.&lt;br /&gt;
* Plot of the independent-particles absorption spectrum [&amp;lt;code&amp;gt;Absorption_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
You can play with the indices and the plot parameters to check what happens.&lt;br /&gt;
&lt;br /&gt;
[[File:Dipoles hbn2.png|YamboDipolesDB plot from yambopy tutorial|500px]]&lt;br /&gt;
&lt;br /&gt;
=== Exciton intro 1: read and sort data ===&lt;br /&gt;
In this section we will use both the script &amp;lt;code&amp;gt;exc_read.py&amp;lt;/code&amp;gt; and the command line in order to read the exciton data resulting from a BSE calculation to familiarise with their structure. This time we are going to read the &amp;lt;code&amp;gt;ndb.BS_diago_Q*&amp;lt;/code&amp;gt; databases which correspond to BSE calculations at various momenta Q (Q=1 being the zero-momentum optical absorption limit - notice that python indexing starts from 0, while the databases are counted starting from 1).&lt;br /&gt;
&lt;br /&gt;
In order to read them in python we use the Yambopy class &amp;lt;code&amp;gt;YamboExcitonDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
 yexc = YamboExcitonDB.from_db_file(ylat,filename=f&#039;path/to/BSE/databases/ndb.BS_diago_Q{i}&#039;)&lt;br /&gt;
(where i is the number of BS_diago_Qi file. Notice that it requires a previous instance of &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Now the &amp;lt;code&amp;gt;yexc&amp;lt;/code&amp;gt; object contains information about the exciton energies (&amp;lt;code&amp;gt;yexc.eigenvalues&amp;lt;/code&amp;gt;), wave functions (&amp;lt;code&amp;gt;yexc.eigenvectors&amp;lt;/code&amp;gt;) and intensities (&amp;lt;code&amp;gt;yexc.l_residuals&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yexc.r_residuals&amp;lt;/code&amp;gt;) for Qpoint i_Q. You can start by keeping &amp;lt;code&amp;gt;Q1&amp;lt;/code&amp;gt; which is the optical limit and then check other momenta.&lt;br /&gt;
&lt;br /&gt;
The exciton wave function components A_{vck}^{\lambda Q} (\lambda being the exciton index) are stored as A_{t}^{\lambda} in each Q-dependent database, with t being the transition index grouping the single-particle indices vck. Therefore, &amp;lt;code&amp;gt;yexc.eigenvectors&amp;lt;/code&amp;gt; is an array with (N_excitons,N_transitions) dimension. In order to make the connection t-&amp;gt;kcv, the table &amp;lt;code&amp;gt;yexc.table&amp;lt;/code&amp;gt; provides k,v,c and spin indices corresponding to each transition.&lt;br /&gt;
&lt;br /&gt;
In order to get a clearer picture, take a look at the script &amp;lt;code&amp;gt;exc_read.py&amp;lt;/code&amp;gt;. Run it and try to understand the outputs.&lt;br /&gt;
  $ python exc_read.py&lt;br /&gt;
&lt;br /&gt;
Actually, we can produce output files with the sorted exciton energies in a much more convenient way by using the command line instruction &amp;lt;code&amp;gt;exc-sort&amp;lt;/code&amp;gt;. Check its syntax via:&lt;br /&gt;
 $ yambopy exc-sort -h&lt;br /&gt;
&lt;br /&gt;
Then, we run it for our specific calculation with:&lt;br /&gt;
 $ yambopy exc-sort --save BSE_saves/YAMBO_saves/SAVE -J BSE_saves/BSE_databases --iqpt 1&lt;br /&gt;
&lt;br /&gt;
This should produce the &amp;lt;code&amp;gt;o-BSE_databases.exc_qpt1_sorted_E.dat&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;o-BSE_databases.exc_qpt1_sorted_I.dat&amp;lt;/code&amp;gt; output files for you to inspect. These are very useful as they allow for identification of degenerate states and degree of optical activity. You will see that in our system most states are doubly degenerate, a byproduct of crystal symmetry. This is an updated version of the ypp exciton analysis that you can find [[How to analyse excitons#Sort the excitonic eigenvalues|here]].&lt;br /&gt;
&lt;br /&gt;
=== Exciton intro 2: symmetry analysis and wavefunction plot in real space ===&lt;br /&gt;
&lt;br /&gt;
==== Symmetries of excitons====&lt;br /&gt;
We can analyse the symmetries of the excitonic wavefunctions in terms of irreducible representation of the point group of the system (if at Q=0) or the Q little group. For more information, the methodology is explained in Ref. &amp;lt;ref&amp;gt;Symmetries of excitons, M. Nalabothula et al., [https://arxiv.org/abs/2511.21540 preprint arXiv]&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
We use the &amp;lt;code&amp;gt;exc-irrep&amp;lt;/code&amp;gt; command line option, check the arguments with:&lt;br /&gt;
 $ yambopy exc-irrep -h&lt;br /&gt;
&lt;br /&gt;
We know from the previous section (by inspecting the sorted energies) that the first four BSE eigenvalues correspond to two doubly-degenerate bright states. Let us analyse their symmetry by running&lt;br /&gt;
 $ yambopy exc-irrep --path BSE_saves/YAMBO_saves -J BSE_saves/BSE_databases --iqpt 1 --nstates 4&lt;br /&gt;
&lt;br /&gt;
This command first loads the electronic wave functions and calculated the electronic representation matrices (called &amp;lt;code&amp;gt;Dmats&amp;lt;/code&amp;gt; in the code). As a second step, they are used to compute the &#039;&#039;&#039;excitonic&#039;&#039;&#039; representation matrices. &lt;br /&gt;
&lt;br /&gt;
We obtain the following output:&lt;br /&gt;
&lt;br /&gt;
 ========================================&lt;br /&gt;
 Group theory analysis for Q point : (0.000000, 0.000000, 0.000000)&lt;br /&gt;
 ****************************************&lt;br /&gt;
 Little group :  D3h&lt;br /&gt;
 Little group symmetries :  [ 1  2  3  4  5  6  7  8  9 10 11 12]&lt;br /&gt;
 Classes (symmetry indices in each class):&lt;br /&gt;
                E    :  [1]&lt;br /&gt;
             2S_3    :  [2 6]&lt;br /&gt;
             2C_3    :  [3 5]&lt;br /&gt;
          sigma_h    :  [4]&lt;br /&gt;
             3C_2    :  [ 7  9 11]&lt;br /&gt;
         3sigma_v    :  [ 8 10 12]&lt;br /&gt;
 &lt;br /&gt;
 ====== Exciton representations ======&lt;br /&gt;
 Energy (eV),  degeneracy  : representation&lt;br /&gt;
 ----------------------------------------&lt;br /&gt;
 1.9139                2  :  E&#039;&lt;br /&gt;
 2.5988                2  :  E&#039;&lt;br /&gt;
 ****************************************&lt;br /&gt;
&lt;br /&gt;
This is similar to the group theory analysis done by Quantum Espresso on the electronic states, and is actually analogous to the one performed for the phonon modes of crystals. We see that the first two states transform as the E&#039; representation of the D3h point group of the crystal. By optical selection rules, only states with this symmetry can form absorption peaks in monolayer BN when light is polarized along the layer plane.&lt;br /&gt;
&lt;br /&gt;
We could go further and calculate the total crystal angular momentum of these states, while also rotate the degenerate exciton states so that they are both eigenvectors of the BSE Hamiltonian and the total crystal angular momentum operator. This is very useful for analyses involving selection rules, exciton-boson couplings, chirality, etc. This is an advanced topic and will not be covered, nonetheless an example script is provided in the tutorial folder called &amp;lt;code&amp;gt;total_crystal_angular_momentum_exciton.py&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; What to do when symmetry analysis does not seem to work well &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Check for warnings during execution. If the BSE calculation was done with a response function that breaks the symmetries (such as the longitudinal response in place of the transverse one at q=0), that may explain the issues.&lt;br /&gt;
&lt;br /&gt;
* If the exciton density of states is very high (such as for a bulk 3D system or for a 2D system at higher energies in the optical spectrum), the analyser may fail to resolve degenerate states, and incorporate a bunch of states together. The symmetry analysis will still be performed but the representation labels will appear as summed. In severe cases, the code may crash. You can try to get a better result by carefully selecting the degeneracy tolerance with &amp;lt;code&amp;gt;degen_tol&amp;lt;/code&amp;gt; and restricting the number of states with &amp;lt;code&amp;gt;nstates&amp;lt;/code&amp;gt; in the command line options.&lt;br /&gt;
&lt;br /&gt;
====Exciton wave functions in real space====&lt;br /&gt;
We can also plot the wave functions of the exciton states on the crystal lattice. In practice, what we do is set the position of the hole at a &amp;quot;physical&amp;quot; point, and then visualize the resulting electronic distribution:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;I^{e}_{\lambda \mathbf{Q}}(\mathbf{r}_e)= |\Psi_{\alpha \mathbf{Q}}(\mathbf{r}_e,\mathbf{r}_h=\mathbf{r}_0)|^2&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let us focus on the lowest exciton state, which gives rise to the largest peak in absorption (see the last part of the tutorial). We will set the hole position on top of a nitrogen atom, since that&#039;s where the &amp;lt;math&amp;gt;p_z&amp;lt;/math&amp;gt; orbitals where the hole comes from are mostly localized.&lt;br /&gt;
&lt;br /&gt;
If we don&#039;t know the correct coordinates, we can modify the &amp;lt;code&amp;gt;bz_plot.py&amp;lt;/code&amp;gt; script by adding (after instancing the lattice object):&lt;br /&gt;
 for iat in range(len(ylat.atomic_numbers)): print(ylat.atomic_numbers[iat],ylat.red_atomic_positions[iat])&lt;br /&gt;
which will print&lt;br /&gt;
 5 [0.6666667 0.3333333 0.       ]&lt;br /&gt;
 7 [-0.6666667 -0.3333333  0.       ]&lt;br /&gt;
&lt;br /&gt;
In order to make the plot, we have to give yambopy the same inputs that are used in the equivalent [[How to analyse excitons#Plot the exciton spatial distribution| ypp calculation]]. First, let&#039;s check all the options via&lt;br /&gt;
 $ yambopy exc-wf -h&lt;br /&gt;
&lt;br /&gt;
Then, we can run our calculation (by selecting a 9x9x1 supercell and a 30 Ry cutoff) as &lt;br /&gt;
 $ yambopy exc-wf --path BSE_saves/YAMBO_saves -J BSE_saves/BSE_databases --iqpt 1 --iexe 1 --supercell 9 9 1 --wfc_cutoff 30 --hole 0.33333333 0.66666667 0.03&lt;br /&gt;
&lt;br /&gt;
Yambopy will produce a *.cube file that can be visualized with VESTA, xcrysden or the like, producing a figure similar to the one below.&lt;br /&gt;
&lt;br /&gt;
The example script &amp;lt;code&amp;gt;exc_real_wf.py&amp;lt;/code&amp;gt;, which runs the same calculation by explicitly calling the necessary functions, will give you more info about what is happening behind the scenes.&lt;br /&gt;
&lt;br /&gt;
[[File:Exc BN yambopy.png|YamboExcitonDB exciton wave function|400px]]&lt;br /&gt;
&lt;br /&gt;
We see that electron is localised in &amp;lt;math&amp;gt;p_z&amp;lt;/math&amp;gt;-like distributions on top of boron atoms around the nitrogen where the hole is set.&lt;br /&gt;
&lt;br /&gt;
=== Exciton intro 3: plot exciton weights on k-BZ and (interpolated) band structure ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;exc_kspace_plot.py&amp;lt;/code&amp;gt; and work with the quantities defined in the previous section.&lt;br /&gt;
&lt;br /&gt;
For now, only the i_Q=0 case is implemented in this section.&lt;br /&gt;
We want to check the relative importance of the various (vk-&amp;gt;ck) electronic transitions in forming a certain excitonic state. &lt;br /&gt;
&lt;br /&gt;
Since many excitonic states are degenerate, we first need to tell Yambopy which states we want to check. For example, in monolayer hexagonal boron nitride, the lowest-bound exciton - forming the main peak in the BSE absorption spectrum - is doubly degenerate. In order to analyse it, in the &amp;lt;code&amp;gt;exc_kspace_plot.py&amp;lt;/code&amp;gt; script we set&lt;br /&gt;
 states = [1,2]&lt;br /&gt;
(we can also set [3,4] to check the second excitonic state, and then [5] for the non-degenerate third state, and so on; we can check degeneracies by printing the energies using the script &amp;lt;code&amp;gt;exc_read.py&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
In order to make a band structure plot, it is necessary to read the band energies, for example with the &amp;lt;code&amp;gt;YamboSaveDB&amp;lt;/code&amp;gt; class&lt;br /&gt;
 yel = YamboSaveDB.from_db_file(folder=&#039;path/to/SAVE&#039;)&lt;br /&gt;
and specify the path in the BZ using crystal coordinates via the &amp;lt;code&amp;gt;Path&amp;lt;/code&amp;gt; function:   &lt;br /&gt;
 npoints = 20&lt;br /&gt;
 path = Path([ [[  0.0,  0.0,  0.0],&#039;$\Gamma$&#039;],&lt;br /&gt;
               [[  0.5,  0.0,  0.0],&#039;M&#039;],&lt;br /&gt;
               [[1./3.,1./3.,  0.0],&#039;K&#039;],&lt;br /&gt;
               [[  0.0,  0.0,  0.0],&#039;$\Gamma$&#039;]],&lt;br /&gt;
               [int(npoints*2),int(npoints),int(sqrt(5)*npoints)] )&lt;br /&gt;
&lt;br /&gt;
Now let&#039;s take a closer look at the &amp;lt;code&amp;gt;exc_kspace_plot.py&amp;lt;/code&amp;gt; script. You will see that it performs three plots:&lt;br /&gt;
* Plot of |A(k)| in the k-BZ for the selected exciton state. You can see how most contributions come from the area around K and the MK direction [&amp;lt;code&amp;gt;Kspace_Plot=True&amp;lt;/code&amp;gt;]. &lt;br /&gt;
* Plot of |A(v,c,k)| on the electronic band structure for the selected exciton state. Here you can better see how the top valence and bottom conduction around MK are mostly involved [&amp;lt;code&amp;gt;Bands_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Plot of interpolated |A(v,c,k)| on the interpolated electronic band structure for the selected exciton state [&amp;lt;code&amp;gt;Bands_Plot_Interpolated=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
As always, try to play with the parameters, for example by changing the excitonic states to analyse.&lt;br /&gt;
&lt;br /&gt;
[[File:Exc bands1 hbn.jpg|YamboExcitonDB plot from yambopy tutorial|300px| Uninterpolated exciton weights on top of band structure]][[File:Exc bands2 hbn.jpg|YamboExcitonDB plot from yambopy tutorial|300px]]&lt;br /&gt;
&lt;br /&gt;
=== Exciton intro 4: plot BSE optical absorption with custom options ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;exc_abs_plot.py&amp;lt;/code&amp;gt; and work with the quantities defined in the previous sections.&lt;br /&gt;
&lt;br /&gt;
The class &amp;lt;code&amp;gt;YamboExcitonDB&amp;lt;/code&amp;gt; also enables us, of course, to read the dielectric function eps(w) and print absorption and related spectra in python.&lt;br /&gt;
&lt;br /&gt;
The advantages over using the standard human-readable yambo outputs are mainly two:&lt;br /&gt;
# We can freely select energy ranges, energy steps, peak broadenings and number of excitonic states included without having to rerun the &amp;lt;code&amp;gt;yambo&amp;lt;/code&amp;gt; executable every time. This reduces the chance of mistakenly editing the yambo input and allows for greater freedom since these plots can now be done in your local machine without having to transfer the output data from a remote cluster.&lt;br /&gt;
# The dielectric function constructed from netCDF database variables has a much higher precision (number of significant digits) than the human readable output, which may be important if you want to perform additional operations in python (e.g., computing refractive index, reflectivity and other optical spectra from it, performing finite-difference derivatives, etc).&lt;br /&gt;
&lt;br /&gt;
We can read eps(w) as a &amp;lt;code&amp;gt;numpy&amp;lt;/code&amp;gt; array with the specified options as (energy values are in eV):&lt;br /&gt;
 w, eps = yexc.get_chi(nexcitons=&#039;all&#039;,emin=0,emax=7,estep=0.005,broad=0.04)&lt;br /&gt;
Or, you can directly prepare a plot of its imaginary part with&lt;br /&gt;
 w, chi = yexc.plot_chi_ax(ax,nexcitons=&#039;all&#039;,emin=0,emax=7,estep=0.005,broad=0.04)&lt;br /&gt;
where &amp;lt;code&amp;gt;ax&amp;lt;/code&amp;gt; is a previously defined &amp;lt;code&amp;gt;Axes&amp;lt;/code&amp;gt; object from &amp;lt;code&amp;gt;matplotlib&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In order to see how this works, let&#039;s take a look at the &amp;lt;code&amp;gt;exc_abs_plot.py&amp;lt;/code&amp;gt; script.&lt;br /&gt;
You will see that it performs the two operations described above:&lt;br /&gt;
* Plotting the BSE absorption spectrum [&amp;lt;code&amp;gt;Absorption_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Reading the complex dielectric function.&lt;br /&gt;
&lt;br /&gt;
Try to customise the plots by changing the &amp;lt;code&amp;gt;nexcitons&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;emin&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;emax&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;estep&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;broad&amp;lt;/code&amp;gt; parameters.&lt;br /&gt;
&lt;br /&gt;
[[File:Absalpha.png|Yambo alpha_2D tutorial plot|700px]]&lt;br /&gt;
&lt;br /&gt;
=== Command line: importing electron-phonon matrix elements ===&lt;br /&gt;
You may have seen how to calculate and import electron-phonon matrix elements in yambo in the [[Electron Phonon Coupling|electron-phonon tutorial]].&lt;br /&gt;
&lt;br /&gt;
With Yambopy, we can generate a yambo SAVE folder and import the matrix elements with a single command.&lt;br /&gt;
Typing &lt;br /&gt;
 $yambopy gkkp&lt;br /&gt;
will print the necessary documentation:&lt;br /&gt;
 Produce a SAVE folder including elph_gkkp databases&lt;br /&gt;
 &lt;br /&gt;
 Arguments are:&lt;br /&gt;
   -nscf, --nscf_dir  -&amp;gt; &amp;lt;Optional&amp;gt; Path to nscf save folder&lt;br /&gt;
   -elph, --elph_dir  -&amp;gt; Path to elph_dir folder&lt;br /&gt;
   -y, --yambo_dir    -&amp;gt; &amp;lt;Optional&amp;gt; Path to yambo executables&lt;br /&gt;
   -e, --expand       -&amp;gt; &amp;lt;Optional&amp;gt; Expand gkkp databases&lt;br /&gt;
&lt;br /&gt;
The necessary quantum espresso databases are stored in &amp;lt;code&amp;gt;ELPH_SAVES/QE_SAVES/hBN.save&amp;lt;/code&amp;gt; (nscf calculation) and &amp;lt;code&amp;gt;ELPH_SAVES/QE_SAVES/elph_dir&amp;lt;/code&amp;gt; (matrix elements from the dfpt calculation). For this tutorial we also need to expand the electron-phonon matrix elements to the full Brillouin zone. Since this is a different calculation with respect to the previous section, please generate this SAVE in a different directory than the one you used for the previous SAVE, which should be the current directory.&lt;br /&gt;
For example:&lt;br /&gt;
 $mkdir yambo-with-elph&lt;br /&gt;
 $cd yambo-with-elph&lt;br /&gt;
&lt;br /&gt;
Now we can run yambopy as in the instructions:&lt;br /&gt;
 $yambopy gkkp -nscf ../ELPH_saves/QE_saves/hBN.save -elph ../ELPH_saves/QE_saves/elph_dir --expand&lt;br /&gt;
This should generate a yambo SAVE folder which contains the &amp;lt;code&amp;gt;ndb.elph_gkkp_expanded*&amp;lt;/code&amp;gt; databases.&lt;br /&gt;
&lt;br /&gt;
=== Electron-phonon intro: plots of el-ph matrix elements on k-BZ and q-BZ ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; and read the electron-phonon databases that you generated in the previous section.&lt;br /&gt;
&lt;br /&gt;
In order to read the &amp;lt;code&amp;gt;ndb.elph_gkkp_expanded*&amp;lt;/code&amp;gt; databases in python we use the Yambopy class &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
 yelph = YamboElectronPhononDB(ylat,folder_gkkp=&#039;path/to/elph/folder&#039;,save=&#039;path/to/SAVE&#039;)&lt;br /&gt;
(notice that it requires a previous instance of &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Now, the &amp;lt;code&amp;gt;yelph&amp;lt;/code&amp;gt; object contains phonon frequencies, phonon eigenvectors, qpoint information and, of course, the electron-phonon matrix elements g_{nm\nu}(k,q) where n, m are electron band states, \nu is a phonon branch, and k and q are the electronic and transfer momenta.&lt;br /&gt;
&lt;br /&gt;
We can print the docstring of the &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt; class with&lt;br /&gt;
 print(yelph.__doc__)&lt;br /&gt;
to get an idea of the information stored and of its capabilities.&lt;br /&gt;
&lt;br /&gt;
Now check the &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; script. You will see that it performs two plots: &lt;br /&gt;
* Plot of |g(k)| in the k-BZ for selected n,m,\nu and q [&amp;lt;code&amp;gt;Kspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Plot of |g(q)| in the q-BZ for selected n,m,\nu and k [&amp;lt;code&amp;gt;Qspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
You can change the electronic, phononic and momentum indices to see what happens.&lt;br /&gt;
&lt;br /&gt;
[[File:Elph hbn.jpg|YamboElectronPhononDB plot from yambopy tutorial|500px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Links==&lt;br /&gt;
* Back to [[Rome 2023#Tutorials]]&lt;br /&gt;
* Back to [[ICTP 2022#Tutorials]]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;/div&gt;</summary>
		<author><name>FulvioPaleari</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_Yambo_databases&amp;diff=9302</id>
		<title>Yambopy tutorial: Yambo databases</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_Yambo_databases&amp;diff=9302"/>
		<updated>2026-03-09T19:09:35Z</updated>

		<summary type="html">&lt;p&gt;FulvioPaleari: /* Lattice intro: plot k-point coordinates in IBZ/BZ */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial we will see some examples on how to read and analyse the data contained in the Yambo netCDF databases, which are not readily available as human readable outputs.&lt;br /&gt;
&lt;br /&gt;
In particular we will take a look at:&lt;br /&gt;
* Lattice geometry data (Yambo database: &amp;lt;code&amp;gt;ns.db1&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
* Dipole matrix elements (Yambo databases: &amp;lt;code&amp;gt;ndb.dipoles&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboDipolesDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
* Exciton energies, symmetries, wavefunctions and spectra (Yambo databases: &amp;lt;code&amp;gt;ndb.BS_diago_Q*&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboExcitonDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
We will also check the command line instructions to quickly generate yambo SAVE folders.&lt;br /&gt;
&lt;br /&gt;
The scripts of the tutorial, but not the databases, can be found in the yambopy directory:&lt;br /&gt;
 $cd tutorial/databases_yambopy&lt;br /&gt;
&lt;br /&gt;
The full tutorial, including the Quantum espresso and Yambo databases that we will read, can be downloaded and extracted from the yambo website:&lt;br /&gt;
 $wget https://media.yambo-code.eu/educational/tutorials/files/databases_yambopy.tar.gz&lt;br /&gt;
 $tar -xvzf databases_yambopy.tar.gz&lt;br /&gt;
 $cd databases_yambopy&lt;br /&gt;
&lt;br /&gt;
We will work with monolayer hexagonal boron nitride electron-phonon and exciton data obtained on a &amp;lt;code&amp;gt;12x12x1&amp;lt;/code&amp;gt; kpoint grid. Beware that these are certainly not converged.&lt;br /&gt;
&lt;br /&gt;
=== Command line: generating the Yambo SAVE ===&lt;br /&gt;
Yambopy offers a set of command line options. In order to review them, you can type&lt;br /&gt;
 $yambopy&lt;br /&gt;
which will print the output&lt;br /&gt;
 yambopy v0.7&lt;br /&gt;
 Available commands are:&lt;br /&gt;
 &lt;br /&gt;
       plotem1s -&amp;gt;     Plot em1s calculation.&lt;br /&gt;
     analysebse -&amp;gt;     Study the convergence of BSE calculations.&lt;br /&gt;
      analysegw -&amp;gt;     Study the convergence of GW calculations by looking at the change in band-gap value.&lt;br /&gt;
   plotexcitons -&amp;gt;     Plot excitons calculation&lt;br /&gt;
          addqp -&amp;gt;     Add corrections from QP databases.&lt;br /&gt;
        mergeqp -&amp;gt;     Merge QP databases&lt;br /&gt;
           save -&amp;gt;     Produce a SAVE folder&lt;br /&gt;
           gkkp -&amp;gt;     Produce a SAVE folder including elph_gkkp databases&lt;br /&gt;
          bands -&amp;gt;     Script to produce band structure data and visualization from QE.&lt;br /&gt;
         serial -&amp;gt;     Script to update serial numbers of yambo ndb.* databases in order to import them to new calculations.&lt;br /&gt;
     gwsubspace -&amp;gt;     Script to calculate off-diago corrections of yambo ndb.QP databases in order to plot band structure.&lt;br /&gt;
          phinp -&amp;gt;     Script to update the explicit list of q-points in a ph input file (ldisp=.false., qplot=.true.).&lt;br /&gt;
        convert -&amp;gt;     Script to convert RL number in Ry energy units using ndb.gops.&lt;br /&gt;
        bsesize -&amp;gt;     Script to calculate the expected BSE kernel size, in GB, to be loaded by each MPI task.&lt;br /&gt;
            l2y -&amp;gt;     Calculate gauge-invariant electron-phonon matrix elements with LetzElPhC and convert them into Yambo format.&lt;br /&gt;
      exc-irrep -&amp;gt;     Script to get the irreducible representation labels for excitonic states. [-h for help]&lt;br /&gt;
         exc-wf -&amp;gt;     Real space exciton wf for either fixed hole/electron. [-h for help]&lt;br /&gt;
       exc-sort -&amp;gt;     Script to sort excitonic states according to energies and intensities. [-h for help]&lt;br /&gt;
&lt;br /&gt;
For this tutorial, we will need the &amp;lt;code&amp;gt;save&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;gkkp&amp;lt;/code&amp;gt; options.&lt;br /&gt;
By typing in one of these, additional information about how to run the commands will be printed, e.g.:&lt;br /&gt;
 $yambopy save&lt;br /&gt;
 &lt;br /&gt;
 Produce a SAVE folder&lt;br /&gt;
 &lt;br /&gt;
 Arguments are:&lt;br /&gt;
   -nscf, --nscf_dir  -&amp;gt; Path to nscf save folder&lt;br /&gt;
   -y, --yambo_dir    -&amp;gt; &amp;lt;Optional&amp;gt; Path to yambo executables&lt;br /&gt;
&lt;br /&gt;
The quantum espresso save for hBN is provided in the directory &amp;lt;code&amp;gt;BSE_saves/QE_saves/hBN.save&amp;lt;/code&amp;gt; (you can check the contents of the various folders). &lt;br /&gt;
Then, following the instructions printed on screen, we can generate a yambo SAVE from the hBN.save by typing&lt;br /&gt;
&lt;br /&gt;
 $yambopy save -nscf BSE_saves/QE_saves/hBN.save&lt;br /&gt;
&lt;br /&gt;
This should produce a SAVE folder in the current directory.&lt;br /&gt;
&lt;br /&gt;
=== Lattice intro: plot k-point coordinates in IBZ/BZ ===&lt;br /&gt;
For this section we will use the script &amp;lt;code&amp;gt;bz_plot.py&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
By inspecting the SAVE folder we have just generated, we will find the &amp;lt;code&amp;gt;ns.db1&amp;lt;/code&amp;gt; database which contains all the geometry and lattice information.&lt;br /&gt;
We are now going to read it in python by using the Yambopy class &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
&lt;br /&gt;
 from yambopy import YamboLatticeDB&lt;br /&gt;
 ylat = YamboLatticeDB.from_db_file(filename=&amp;quot;PATH/TO/SAVE/ns.db1&amp;quot;)&lt;br /&gt;
(remember to edit the variable &amp;lt;code&amp;gt;save_path&amp;lt;/code&amp;gt; in order to point at your yambo SAVE).&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;ylat&amp;lt;/code&amp;gt; object now contains many useful information as attributes, such as the k-points in Cartesian or crystal coordinates, the system symmetries, lattice constants and basis vectors in real and reciprocal space, etc.&lt;br /&gt;
The k-points are also automatically expanded in the full Brillouin zone from the irreducible one (you can turn this off with the option &amp;lt;code&amp;gt;Expand=False&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Directly printing the object with&lt;br /&gt;
 print(ylat)&lt;br /&gt;
will also give us some general parameters related to the database. &lt;br /&gt;
&lt;br /&gt;
Now check the &amp;lt;code&amp;gt;bz_plot.py&amp;lt;/code&amp;gt; script. You will see that it performs three plots: &lt;br /&gt;
* Scatterplot of the k-points in Cartesian coordinates with both expanded and unexpanded grids, with annotated indices [&amp;lt;code&amp;gt;Cartesian_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Scatterplot of the k-points in crystal coordinates [&amp;lt;code&amp;gt;Crystal_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Manual transformation of a chosen k-point from irreducible to full Brillouin zone (you can change the index &amp;lt;code&amp;gt;i_k&amp;lt;/code&amp;gt; in the script to check different cases) [&amp;lt;code&amp;gt;Symmetry_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
Below, the result of the first plot.&lt;br /&gt;
&lt;br /&gt;
[[File:Car kpoints hbn.jpg|YamboLatticeDB plot from yambopy tutorial| 500px]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What about the units?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Below we report the relation between units used in Yambo, Quantum Espresso, and Yambopy.&lt;br /&gt;
&lt;br /&gt;
* bohr^-1 (atomic units):                                     &amp;lt;code&amp;gt;YamboLatticeDB.car_kpoints*2.*pi&amp;lt;/code&amp;gt;. Divide by the bohr-to-angstrom conversion factor to obtain angs^-1 &lt;br /&gt;
* Yambo cartesian units (&amp;lt;code&amp;gt;[cc]&amp;lt;/code&amp;gt; in Yambo outputs): &amp;lt;code&amp;gt;YamboLatticeDB.car_kpoints*2.*pi&amp;lt;/code&amp;gt; (same as above).&lt;br /&gt;
* QE cartesian units (&amp;lt;code&amp;gt;[cart. coord. in units 2pi/alat]&amp;lt;/code&amp;gt; in QE outputs): &amp;lt;code&amp;gt;YamboLatticeDB.car_kpoints*YamboLatticeDB.alat[0]&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Internal yambo units (&amp;lt;code&amp;gt;[iku]&amp;lt;/code&amp;gt; in yambo outputs): &amp;lt;code&amp;gt;YamboLatticeDB.iku_kpoints&amp;lt;/code&amp;gt;&lt;br /&gt;
* Fractional coordinates (&amp;lt;code&amp;gt;[rlu]&amp;lt;/code&amp;gt; in yambo, &amp;lt;code&amp;gt;cryst. coord.&amp;lt;/code&amp;gt; in QE): &amp;lt;code&amp;gt;YamboLatticeDB.red_kpoints&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Dipoles intro: plots of dipoles on BZ, plot of IP absorption ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;dipoles_plot.py&amp;lt;/code&amp;gt; and read the dipole databases generated in an optical absorption calculation by yambo. Keep in mind that from now on we will use the &amp;quot;BSE&amp;quot; yambo SAVE generated in the [[#Command line: generating the Yambo SAVE|first section]].&lt;br /&gt;
&lt;br /&gt;
The databases written after a calculation of optical properties with yambo (dipoles, static screening, excitons) are in the directory &amp;lt;code&amp;gt;BSE_saves/BSE_databases&amp;lt;/code&amp;gt;. Here we will also find &amp;lt;code&amp;gt;ndb.dipoles&amp;lt;/code&amp;gt; which is needed now, since it contains the matrix elements d_{vck}(\alpha) where vk and ck are the valence and electron states involved in the transition and \alpha the polarisation direction of the external electric field.&lt;br /&gt;
&lt;br /&gt;
In order to read it in python we use the Yambopy class &amp;lt;code&amp;gt;YamboDipolesDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
 ydip = YamboDipolesDB(ylat,save=&#039;path/to/BSE/databases&#039;,filename=&#039;ndb.dipoles&#039;)&lt;br /&gt;
(notice that it requires a previous instance of &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
In addition, in order to read the Kohn-Sham energies, we can also instance the &amp;lt;code&amp;gt;YamboElectronsDB&amp;lt;/code&amp;gt; as&lt;br /&gt;
 yel = YamboElectronsDB.from_db_file(folder=&#039;path/to/SAVE&#039;) &lt;br /&gt;
&lt;br /&gt;
The object &amp;lt;code&amp;gt;ydip&amp;lt;/code&amp;gt; now has a method that permits to retrieve the independent-particle absorption spectrum with customly chosen energy range, steps, and broadening:&lt;br /&gt;
 w, eps2 = ydip.ip_eps2(yel)&lt;br /&gt;
&lt;br /&gt;
In order to see all this in action, take a look at the &amp;lt;code&amp;gt;dipoles_plot.py&amp;lt;/code&amp;gt; script. You will see that it performs two plots:&lt;br /&gt;
* Plot of |d(k)| in the BZ for selected v,c and \alpha (we choose the layer plane &#039;xy&#039;) [&amp;lt;code&amp;gt;Kspace_Plot=True&amp;lt;/code&amp;gt;]. From this plot you can appreciate which sections of the BZ contribute the most to the absorption rate.&lt;br /&gt;
* Plot of the independent-particles absorption spectrum [&amp;lt;code&amp;gt;Absorption_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
You can play with the indices and the plot parameters to check what happens.&lt;br /&gt;
&lt;br /&gt;
[[File:Dipoles hbn2.png|YamboDipolesDB plot from yambopy tutorial|500px]]&lt;br /&gt;
&lt;br /&gt;
=== Exciton intro 1: read and sort data ===&lt;br /&gt;
In this section we will use both the script &amp;lt;code&amp;gt;exc_read.py&amp;lt;/code&amp;gt; and the command line in order to read the exciton data resulting from a BSE calculation to familiarise with their structure. This time we are going to read the &amp;lt;code&amp;gt;ndb.BS_diago_Q*&amp;lt;/code&amp;gt; databases which correspond to BSE calculations at various momenta Q (Q=1 being the zero-momentum optical absorption limit - notice that python indexing starts from 0, while the databases are counted starting from 1).&lt;br /&gt;
&lt;br /&gt;
In order to read them in python we use the Yambopy class &amp;lt;code&amp;gt;YamboExcitonDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
 yexc = YamboExcitonDB.from_db_file(ylat,filename=f&#039;path/to/BSE/databases/ndb.BS_diago_Q{i}&#039;)&lt;br /&gt;
(where i is the number of BS_diago_Qi file. Notice that it requires a previous instance of &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Now the &amp;lt;code&amp;gt;yexc&amp;lt;/code&amp;gt; object contains information about the exciton energies (&amp;lt;code&amp;gt;yexc.eigenvalues&amp;lt;/code&amp;gt;), wave functions (&amp;lt;code&amp;gt;yexc.eigenvectors&amp;lt;/code&amp;gt;) and intensities (&amp;lt;code&amp;gt;yexc.l_residuals&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yexc.r_residuals&amp;lt;/code&amp;gt;) for Qpoint i_Q. You can start by keeping &amp;lt;code&amp;gt;Q1&amp;lt;/code&amp;gt; which is the optical limit and then check other momenta.&lt;br /&gt;
&lt;br /&gt;
The exciton wave function components A_{vck}^{\lambda Q} (\lambda being the exciton index) are stored as A_{t}^{\lambda} in each Q-dependent database, with t being the transition index grouping the single-particle indices vck. Therefore, &amp;lt;code&amp;gt;yexc.eigenvectors&amp;lt;/code&amp;gt; is an array with (N_excitons,N_transitions) dimension. In order to make the connection t-&amp;gt;kcv, the table &amp;lt;code&amp;gt;yexc.table&amp;lt;/code&amp;gt; provides k,v,c and spin indices corresponding to each transition.&lt;br /&gt;
&lt;br /&gt;
In order to get a clearer picture, take a look at the script &amp;lt;code&amp;gt;exc_read.py&amp;lt;/code&amp;gt;. Run it and try to understand the outputs.&lt;br /&gt;
  $ python exc_read.py&lt;br /&gt;
&lt;br /&gt;
Actually, we can produce output files with the sorted exciton energies in a much more convenient way by using the command line instruction &amp;lt;code&amp;gt;exc-sort&amp;lt;/code&amp;gt;. Check its syntax via:&lt;br /&gt;
 $ yambopy exc-sort -h&lt;br /&gt;
&lt;br /&gt;
Then, we run it for our specific calculation with:&lt;br /&gt;
 $ yambopy exc-sort --save BSE_saves/YAMBO_saves/SAVE -J BSE_saves/BSE_databases --iqpt 1&lt;br /&gt;
&lt;br /&gt;
This should produce the &amp;lt;code&amp;gt;o-BSE_databases.exc_qpt1_sorted_E.dat&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;o-BSE_databases.exc_qpt1_sorted_I.dat&amp;lt;/code&amp;gt; output files for you to inspect. These are very useful as they allow for identification of degenerate states and degree of optical activity. You will see that in our system most states are doubly degenerate, a byproduct of crystal symmetry. This is an updated version of the ypp exciton analysis that you can find [[How to analyse excitons#Sort the excitonic eigenvalues|here]].&lt;br /&gt;
&lt;br /&gt;
=== Exciton intro 2: symmetry analysis and wavefunction plot in real space ===&lt;br /&gt;
&lt;br /&gt;
==== Symmetries of excitons====&lt;br /&gt;
We can analyse the symmetries of the excitonic wavefunctions in terms of irreducible representation of the point group of the system (if at Q=0) or the Q little group. For more information, the methodology is explained in Ref. &amp;lt;ref&amp;gt;Symmetries of excitons, M. Nalabothula et al., [https://arxiv.org/abs/2511.21540 preprint arXiv]&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
We use the &amp;lt;code&amp;gt;exc-irrep&amp;lt;/code&amp;gt; command line option, check the arguments with:&lt;br /&gt;
 $ yambopy exc-irrep -h&lt;br /&gt;
&lt;br /&gt;
We know from the previous section (by inspecting the sorted energies) that the first four BSE eigenvalues correspond to two doubly-degenerate bright states. Let us analyse their symmetry by running&lt;br /&gt;
 $ yambopy exc-irrep --path BSE_saves/YAMBO_saves -J BSE_saves/BSE_databases --iqpt 1 --nstates 4&lt;br /&gt;
&lt;br /&gt;
This command first loads the electronic wave functions and calculated the electronic representation matrices (called &amp;lt;code&amp;gt;Dmats&amp;lt;/code&amp;gt; in the code). As a second step, they are used to compute the &#039;&#039;&#039;excitonic&#039;&#039;&#039; representation matrices. &lt;br /&gt;
&lt;br /&gt;
We obtain the following output:&lt;br /&gt;
&lt;br /&gt;
 ========================================&lt;br /&gt;
 Group theory analysis for Q point : (0.000000, 0.000000, 0.000000)&lt;br /&gt;
 ****************************************&lt;br /&gt;
 Little group :  D3h&lt;br /&gt;
 Little group symmetries :  [ 1  2  3  4  5  6  7  8  9 10 11 12]&lt;br /&gt;
 Classes (symmetry indices in each class):&lt;br /&gt;
                E    :  [1]&lt;br /&gt;
             2S_3    :  [2 6]&lt;br /&gt;
             2C_3    :  [3 5]&lt;br /&gt;
          sigma_h    :  [4]&lt;br /&gt;
             3C_2    :  [ 7  9 11]&lt;br /&gt;
         3sigma_v    :  [ 8 10 12]&lt;br /&gt;
 &lt;br /&gt;
 ====== Exciton representations ======&lt;br /&gt;
 Energy (eV),  degeneracy  : representation&lt;br /&gt;
 ----------------------------------------&lt;br /&gt;
 1.9139                2  :  E&#039;&lt;br /&gt;
 2.5988                2  :  E&#039;&lt;br /&gt;
 ****************************************&lt;br /&gt;
&lt;br /&gt;
This is similar to the group theory analysis done by Quantum Espresso on the electronic states, and is actually analogous to the one performed for the phonon modes of crystals. We see that the first two states transform as the E&#039; representation of the D3h point group of the crystal. By optical selection rules, only states with this symmetry can form absorption peaks in monolayer BN when light is polarized along the layer plane.&lt;br /&gt;
&lt;br /&gt;
We could go further and calculate the total crystal angular momentum of these states, while also rotate the degenerate exciton states so that they are both eigenvectors of the BSE Hamiltonian and the total crystal angular momentum operator. This is very useful for analyses involving selection rules, exciton-boson couplings, chirality, etc. This is an advanced topic and will not be covered, nonetheless an example script is provided in the tutorial folder called &amp;lt;code&amp;gt;total_crystal_angular_momentum_exciton.py&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; What to do when symmetry analysis does not seem to work well &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Check for warnings during execution. If the BSE calculation was done with a response function that breaks the symmetries (such as the longitudinal response in place of the transverse one at q=0), that may explain the issues.&lt;br /&gt;
&lt;br /&gt;
* If the exciton density of states is very high (such as for a bulk 3D system or for a 2D system at higher energies in the optical spectrum), the analyser may fail to resolve degenerate states, and incorporate a bunch of states together. The symmetry analysis will still be performed but the representation labels will appear as summed. In severe cases, the code may crash. You can try to get a better result by carefully selecting the degeneracy tolerance with &amp;lt;code&amp;gt;degen_tol&amp;lt;/code&amp;gt; and restricting the number of states with &amp;lt;code&amp;gt;nstates&amp;lt;/code&amp;gt; in the command line options.&lt;br /&gt;
&lt;br /&gt;
====Exciton wave functions in real space====&lt;br /&gt;
We can also plot the wave functions of the exciton states on the crystal lattice. In practice, what we do is set the position of the hole at a &amp;quot;physical&amp;quot; point, and then visualize the resulting electronic distribution:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;I^{e}_{\lambda \mathbf{Q}}(\mathbf{r}_e)= |\Psi_{\alpha \mathbf{Q}}(\mathbf{r}_e,\mathbf{r}_h=\mathbf{r}_0)|^2&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let us focus on the lowest exciton state, which gives rise to the largest peak in absorption (see the last part of the tutorial). We will set the hole position on top of a nitrogen atom, since that&#039;s where the &amp;lt;math&amp;gt;p_z&amp;lt;/math&amp;gt; orbitals where the hole comes from are mostly localized.&lt;br /&gt;
&lt;br /&gt;
If we don&#039;t know the correct coordinates, we can modify the &amp;lt;code&amp;gt;bz_plot.py&amp;lt;/code&amp;gt; script by adding (after instancing the lattice object):&lt;br /&gt;
 for iat in range(len(ylat.atomic_numbers)): print(ylat.atomic_numbers[iat],ylat.red_atomic_positions[iat])&lt;br /&gt;
which will print&lt;br /&gt;
 5 [0.6666667 0.3333333 0.       ]&lt;br /&gt;
 7 [-0.6666667 -0.3333333  0.       ]&lt;br /&gt;
&lt;br /&gt;
In order to make the plot, we have to give yambopy the same inputs that are used in the equivalent [[How to analyse excitons#Plot the exciton spatial distribution| ypp calculation]]. First, let&#039;s check all the options via&lt;br /&gt;
 $ yambopy exc-wf -h&lt;br /&gt;
&lt;br /&gt;
Then, we can run our calculation (by selecting a 9x9x1 supercell and a 30 Ry cutoff) as &lt;br /&gt;
 $ yambopy exc-wf --path BSE_saves/YAMBO_saves -J BSE_saves/BSE_databases --iqpt 1 --iexe 1 --supercell 9 9 1 --wfc_cutoff 30 --hole 0.33333333 0.66666667 0.03&lt;br /&gt;
&lt;br /&gt;
Yambopy will produce a *.cube file that can be visualized with VESTA, xcrysden or the like, producing a figure similar to the one below.&lt;br /&gt;
&lt;br /&gt;
The example script &amp;lt;code&amp;gt;exc_real_wf.py&amp;lt;/code&amp;gt;, which runs the same calculation by explicitly calling the necessary functions, will give you more info about what is happening behind the scenes.&lt;br /&gt;
&lt;br /&gt;
[[File:Exc BN yambopy.png|YamboExcitonDB exciton wave function|400px]]&lt;br /&gt;
&lt;br /&gt;
We see that electron is localised in &amp;lt;math&amp;gt;p_z&amp;lt;/math&amp;gt;-like distributions on top of boron atoms around the nitrogen where the hole is set.&lt;br /&gt;
&lt;br /&gt;
=== Exciton intro 3: plot exciton weights on k-BZ and (interpolated) band structure ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;exc_kspace_plot.py&amp;lt;/code&amp;gt; and work with the quantities defined in the previous section.&lt;br /&gt;
&lt;br /&gt;
For now, only the i_Q=0 case is implemented in this section.&lt;br /&gt;
We want to check the relative importance of the various (vk-&amp;gt;ck) electronic transitions in forming a certain excitonic state. &lt;br /&gt;
&lt;br /&gt;
Since many excitonic states are degenerate, we first need to tell Yambopy which states we want to check. For example, in monolayer hexagonal boron nitride, the lowest-bound exciton - forming the main peak in the BSE absorption spectrum - is doubly degenerate. In order to analyse it, in the &amp;lt;code&amp;gt;exc_kspace_plot.py&amp;lt;/code&amp;gt; script we set&lt;br /&gt;
 states = [1,2]&lt;br /&gt;
(we can also set [3,4] to check the second excitonic state, and then [5] for the non-degenerate third state, and so on; we can check degeneracies by printing the energies using the script &amp;lt;code&amp;gt;exc_read.py&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
In order to make a band structure plot, it is necessary to read the band energies, for example with the &amp;lt;code&amp;gt;YamboSaveDB&amp;lt;/code&amp;gt; class&lt;br /&gt;
 yel = YamboSaveDB.from_db_file(folder=&#039;path/to/SAVE&#039;)&lt;br /&gt;
and specify the path in the BZ using crystal coordinates via the &amp;lt;code&amp;gt;Path&amp;lt;/code&amp;gt; function:   &lt;br /&gt;
 npoints = 20&lt;br /&gt;
 path = Path([ [[  0.0,  0.0,  0.0],&#039;$\Gamma$&#039;],&lt;br /&gt;
               [[  0.5,  0.0,  0.0],&#039;M&#039;],&lt;br /&gt;
               [[1./3.,1./3.,  0.0],&#039;K&#039;],&lt;br /&gt;
               [[  0.0,  0.0,  0.0],&#039;$\Gamma$&#039;]],&lt;br /&gt;
               [int(npoints*2),int(npoints),int(sqrt(5)*npoints)] )&lt;br /&gt;
&lt;br /&gt;
Now let&#039;s take a closer look at the &amp;lt;code&amp;gt;exc_kspace_plot.py&amp;lt;/code&amp;gt; script. You will see that it performs three plots:&lt;br /&gt;
* Plot of |A(k)| in the k-BZ for the selected exciton state. You can see how most contributions come from the area around K and the MK direction [&amp;lt;code&amp;gt;Kspace_Plot=True&amp;lt;/code&amp;gt;]. &lt;br /&gt;
* Plot of |A(v,c,k)| on the electronic band structure for the selected exciton state. Here you can better see how the top valence and bottom conduction around MK are mostly involved [&amp;lt;code&amp;gt;Bands_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Plot of interpolated |A(v,c,k)| on the interpolated electronic band structure for the selected exciton state [&amp;lt;code&amp;gt;Bands_Plot_Interpolated=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
As always, try to play with the parameters, for example by changing the excitonic states to analyse.&lt;br /&gt;
&lt;br /&gt;
[[File:Exc bands1 hbn.jpg|YamboExcitonDB plot from yambopy tutorial|300px| Uninterpolated exciton weights on top of band structure]][[File:Exc bands2 hbn.jpg|YamboExcitonDB plot from yambopy tutorial|300px]]&lt;br /&gt;
&lt;br /&gt;
=== Exciton intro 4: plot BSE optical absorption with custom options ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;exc_abs_plot.py&amp;lt;/code&amp;gt; and work with the quantities defined in the previous sections.&lt;br /&gt;
&lt;br /&gt;
The class &amp;lt;code&amp;gt;YamboExcitonDB&amp;lt;/code&amp;gt; also enables us, of course, to read the dielectric function eps(w) and print absorption and related spectra in python.&lt;br /&gt;
&lt;br /&gt;
The advantages over using the standard human-readable yambo outputs are mainly two:&lt;br /&gt;
# We can freely select energy ranges, energy steps, peak broadenings and number of excitonic states included without having to rerun the &amp;lt;code&amp;gt;yambo&amp;lt;/code&amp;gt; executable every time. This reduces the chance of mistakenly editing the yambo input and allows for greater freedom since these plots can now be done in your local machine without having to transfer the output data from a remote cluster.&lt;br /&gt;
# The dielectric function constructed from netCDF database variables has a much higher precision (number of significant digits) than the human readable output, which may be important if you want to perform additional operations in python (e.g., computing refractive index, reflectivity and other optical spectra from it, performing finite-difference derivatives, etc).&lt;br /&gt;
&lt;br /&gt;
We can read eps(w) as a &amp;lt;code&amp;gt;numpy&amp;lt;/code&amp;gt; array with the specified options as (energy values are in eV):&lt;br /&gt;
 w, eps = yexc.get_chi(nexcitons=&#039;all&#039;,emin=0,emax=7,estep=0.005,broad=0.04)&lt;br /&gt;
Or, you can directly prepare a plot of its imaginary part with&lt;br /&gt;
 w, chi = yexc.plot_chi_ax(ax,nexcitons=&#039;all&#039;,emin=0,emax=7,estep=0.005,broad=0.04)&lt;br /&gt;
where &amp;lt;code&amp;gt;ax&amp;lt;/code&amp;gt; is a previously defined &amp;lt;code&amp;gt;Axes&amp;lt;/code&amp;gt; object from &amp;lt;code&amp;gt;matplotlib&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In order to see how this works, let&#039;s take a look at the &amp;lt;code&amp;gt;exc_abs_plot.py&amp;lt;/code&amp;gt; script.&lt;br /&gt;
You will see that it performs the two operations described above:&lt;br /&gt;
* Plotting the BSE absorption spectrum [&amp;lt;code&amp;gt;Absorption_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Reading the complex dielectric function.&lt;br /&gt;
&lt;br /&gt;
Try to customise the plots by changing the &amp;lt;code&amp;gt;nexcitons&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;emin&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;emax&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;estep&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;broad&amp;lt;/code&amp;gt; parameters.&lt;br /&gt;
&lt;br /&gt;
[[File:Absalpha.png|Yambo alpha_2D tutorial plot|700px]]&lt;br /&gt;
&lt;br /&gt;
=== Command line: importing electron-phonon matrix elements ===&lt;br /&gt;
You may have seen how to calculate and import electron-phonon matrix elements in yambo in the [[Electron Phonon Coupling|electron-phonon tutorial]].&lt;br /&gt;
&lt;br /&gt;
With Yambopy, we can generate a yambo SAVE folder and import the matrix elements with a single command.&lt;br /&gt;
Typing &lt;br /&gt;
 $yambopy gkkp&lt;br /&gt;
will print the necessary documentation:&lt;br /&gt;
 Produce a SAVE folder including elph_gkkp databases&lt;br /&gt;
 &lt;br /&gt;
 Arguments are:&lt;br /&gt;
   -nscf, --nscf_dir  -&amp;gt; &amp;lt;Optional&amp;gt; Path to nscf save folder&lt;br /&gt;
   -elph, --elph_dir  -&amp;gt; Path to elph_dir folder&lt;br /&gt;
   -y, --yambo_dir    -&amp;gt; &amp;lt;Optional&amp;gt; Path to yambo executables&lt;br /&gt;
   -e, --expand       -&amp;gt; &amp;lt;Optional&amp;gt; Expand gkkp databases&lt;br /&gt;
&lt;br /&gt;
The necessary quantum espresso databases are stored in &amp;lt;code&amp;gt;ELPH_SAVES/QE_SAVES/hBN.save&amp;lt;/code&amp;gt; (nscf calculation) and &amp;lt;code&amp;gt;ELPH_SAVES/QE_SAVES/elph_dir&amp;lt;/code&amp;gt; (matrix elements from the dfpt calculation). For this tutorial we also need to expand the electron-phonon matrix elements to the full Brillouin zone. Since this is a different calculation with respect to the previous section, please generate this SAVE in a different directory than the one you used for the previous SAVE, which should be the current directory.&lt;br /&gt;
For example:&lt;br /&gt;
 $mkdir yambo-with-elph&lt;br /&gt;
 $cd yambo-with-elph&lt;br /&gt;
&lt;br /&gt;
Now we can run yambopy as in the instructions:&lt;br /&gt;
 $yambopy gkkp -nscf ../ELPH_saves/QE_saves/hBN.save -elph ../ELPH_saves/QE_saves/elph_dir --expand&lt;br /&gt;
This should generate a yambo SAVE folder which contains the &amp;lt;code&amp;gt;ndb.elph_gkkp_expanded*&amp;lt;/code&amp;gt; databases.&lt;br /&gt;
&lt;br /&gt;
=== Electron-phonon intro: plots of el-ph matrix elements on k-BZ and q-BZ ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; and read the electron-phonon databases that you generated in the previous section.&lt;br /&gt;
&lt;br /&gt;
In order to read the &amp;lt;code&amp;gt;ndb.elph_gkkp_expanded*&amp;lt;/code&amp;gt; databases in python we use the Yambopy class &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
 yelph = YamboElectronPhononDB(ylat,folder_gkkp=&#039;path/to/elph/folder&#039;,save=&#039;path/to/SAVE&#039;)&lt;br /&gt;
(notice that it requires a previous instance of &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Now, the &amp;lt;code&amp;gt;yelph&amp;lt;/code&amp;gt; object contains phonon frequencies, phonon eigenvectors, qpoint information and, of course, the electron-phonon matrix elements g_{nm\nu}(k,q) where n, m are electron band states, \nu is a phonon branch, and k and q are the electronic and transfer momenta.&lt;br /&gt;
&lt;br /&gt;
We can print the docstring of the &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt; class with&lt;br /&gt;
 print(yelph.__doc__)&lt;br /&gt;
to get an idea of the information stored and of its capabilities.&lt;br /&gt;
&lt;br /&gt;
Now check the &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; script. You will see that it performs two plots: &lt;br /&gt;
* Plot of |g(k)| in the k-BZ for selected n,m,\nu and q [&amp;lt;code&amp;gt;Kspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Plot of |g(q)| in the q-BZ for selected n,m,\nu and k [&amp;lt;code&amp;gt;Qspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
You can change the electronic, phononic and momentum indices to see what happens.&lt;br /&gt;
&lt;br /&gt;
[[File:Elph hbn.jpg|YamboElectronPhononDB plot from yambopy tutorial|500px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Links==&lt;br /&gt;
* Back to [[Rome 2023#Tutorials]]&lt;br /&gt;
* Back to [[ICTP 2022#Tutorials]]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;/div&gt;</summary>
		<author><name>FulvioPaleari</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_Yambo_databases&amp;diff=9301</id>
		<title>Yambopy tutorial: Yambo databases</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_Yambo_databases&amp;diff=9301"/>
		<updated>2026-03-09T19:09:00Z</updated>

		<summary type="html">&lt;p&gt;FulvioPaleari: /* Command line: generating the Yambo SAVE */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial we will see some examples on how to read and analyse the data contained in the Yambo netCDF databases, which are not readily available as human readable outputs.&lt;br /&gt;
&lt;br /&gt;
In particular we will take a look at:&lt;br /&gt;
* Lattice geometry data (Yambo database: &amp;lt;code&amp;gt;ns.db1&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
* Dipole matrix elements (Yambo databases: &amp;lt;code&amp;gt;ndb.dipoles&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboDipolesDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
* Exciton energies, symmetries, wavefunctions and spectra (Yambo databases: &amp;lt;code&amp;gt;ndb.BS_diago_Q*&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboExcitonDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
We will also check the command line instructions to quickly generate yambo SAVE folders.&lt;br /&gt;
&lt;br /&gt;
The scripts of the tutorial, but not the databases, can be found in the yambopy directory:&lt;br /&gt;
 $cd tutorial/databases_yambopy&lt;br /&gt;
&lt;br /&gt;
The full tutorial, including the Quantum espresso and Yambo databases that we will read, can be downloaded and extracted from the yambo website:&lt;br /&gt;
 $wget https://media.yambo-code.eu/educational/tutorials/files/databases_yambopy.tar.gz&lt;br /&gt;
 $tar -xvzf databases_yambopy.tar.gz&lt;br /&gt;
 $cd databases_yambopy&lt;br /&gt;
&lt;br /&gt;
We will work with monolayer hexagonal boron nitride electron-phonon and exciton data obtained on a &amp;lt;code&amp;gt;12x12x1&amp;lt;/code&amp;gt; kpoint grid. Beware that these are certainly not converged.&lt;br /&gt;
&lt;br /&gt;
=== Command line: generating the Yambo SAVE ===&lt;br /&gt;
Yambopy offers a set of command line options. In order to review them, you can type&lt;br /&gt;
 $yambopy&lt;br /&gt;
which will print the output&lt;br /&gt;
 yambopy v0.7&lt;br /&gt;
 Available commands are:&lt;br /&gt;
 &lt;br /&gt;
       plotem1s -&amp;gt;     Plot em1s calculation.&lt;br /&gt;
     analysebse -&amp;gt;     Study the convergence of BSE calculations.&lt;br /&gt;
      analysegw -&amp;gt;     Study the convergence of GW calculations by looking at the change in band-gap value.&lt;br /&gt;
   plotexcitons -&amp;gt;     Plot excitons calculation&lt;br /&gt;
          addqp -&amp;gt;     Add corrections from QP databases.&lt;br /&gt;
        mergeqp -&amp;gt;     Merge QP databases&lt;br /&gt;
           save -&amp;gt;     Produce a SAVE folder&lt;br /&gt;
           gkkp -&amp;gt;     Produce a SAVE folder including elph_gkkp databases&lt;br /&gt;
          bands -&amp;gt;     Script to produce band structure data and visualization from QE.&lt;br /&gt;
         serial -&amp;gt;     Script to update serial numbers of yambo ndb.* databases in order to import them to new calculations.&lt;br /&gt;
     gwsubspace -&amp;gt;     Script to calculate off-diago corrections of yambo ndb.QP databases in order to plot band structure.&lt;br /&gt;
          phinp -&amp;gt;     Script to update the explicit list of q-points in a ph input file (ldisp=.false., qplot=.true.).&lt;br /&gt;
        convert -&amp;gt;     Script to convert RL number in Ry energy units using ndb.gops.&lt;br /&gt;
        bsesize -&amp;gt;     Script to calculate the expected BSE kernel size, in GB, to be loaded by each MPI task.&lt;br /&gt;
            l2y -&amp;gt;     Calculate gauge-invariant electron-phonon matrix elements with LetzElPhC and convert them into Yambo format.&lt;br /&gt;
      exc-irrep -&amp;gt;     Script to get the irreducible representation labels for excitonic states. [-h for help]&lt;br /&gt;
         exc-wf -&amp;gt;     Real space exciton wf for either fixed hole/electron. [-h for help]&lt;br /&gt;
       exc-sort -&amp;gt;     Script to sort excitonic states according to energies and intensities. [-h for help]&lt;br /&gt;
&lt;br /&gt;
For this tutorial, we will need the &amp;lt;code&amp;gt;save&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;gkkp&amp;lt;/code&amp;gt; options.&lt;br /&gt;
By typing in one of these, additional information about how to run the commands will be printed, e.g.:&lt;br /&gt;
 $yambopy save&lt;br /&gt;
 &lt;br /&gt;
 Produce a SAVE folder&lt;br /&gt;
 &lt;br /&gt;
 Arguments are:&lt;br /&gt;
   -nscf, --nscf_dir  -&amp;gt; Path to nscf save folder&lt;br /&gt;
   -y, --yambo_dir    -&amp;gt; &amp;lt;Optional&amp;gt; Path to yambo executables&lt;br /&gt;
&lt;br /&gt;
The quantum espresso save for hBN is provided in the directory &amp;lt;code&amp;gt;BSE_saves/QE_saves/hBN.save&amp;lt;/code&amp;gt; (you can check the contents of the various folders). &lt;br /&gt;
Then, following the instructions printed on screen, we can generate a yambo SAVE from the hBN.save by typing&lt;br /&gt;
&lt;br /&gt;
 $yambopy save -nscf BSE_saves/QE_saves/hBN.save&lt;br /&gt;
&lt;br /&gt;
This should produce a SAVE folder in the current directory.&lt;br /&gt;
&lt;br /&gt;
=== Lattice intro: plot k-point coordinates in IBZ/BZ ===&lt;br /&gt;
For this section we will use the script &amp;lt;code&amp;gt;bz_plot.py&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
By inspecting the SAVE folder we have just generated, we will find the &amp;lt;code&amp;gt;ns.db1&amp;lt;/code&amp;gt; database which contains all the geometry and lattice information.&lt;br /&gt;
We are now going to read it in python by using the Yambopy class &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
&lt;br /&gt;
 from yambopy import *&lt;br /&gt;
 ylat = YamboLatticeDB.from_db_file(filename=&amp;quot;PATH/TO/SAVE/ns.db1&amp;quot;)&lt;br /&gt;
(remember to edit the variable &amp;lt;code&amp;gt;save_path&amp;lt;/code&amp;gt; in order to point at your yambo SAVE).&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;ylat&amp;lt;/code&amp;gt; object now contains many useful information as attributes, such as the k-points in Cartesian or crystal coordinates, the system symmetries, lattice constants and basis vectors in real and reciprocal space, etc.&lt;br /&gt;
The k-points are also automatically expanded in the full Brillouin zone from the irreducible one (you can turn this off with the option &amp;lt;code&amp;gt;Expand=False&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Directly printing the object with&lt;br /&gt;
 print(ylat)&lt;br /&gt;
will also give us some general parameters related to the database. &lt;br /&gt;
&lt;br /&gt;
Now check the &amp;lt;code&amp;gt;bz_plot.py&amp;lt;/code&amp;gt; script. You will see that it performs three plots: &lt;br /&gt;
* Scatterplot of the k-points in Cartesian coordinates with both expanded and unexpanded grids, with annotated indices [&amp;lt;code&amp;gt;Cartesian_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Scatterplot of the k-points in crystal coordinates [&amp;lt;code&amp;gt;Crystal_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Manual transformation of a chosen k-point from irreducible to full Brillouin zone (you can change the index &amp;lt;code&amp;gt;i_k&amp;lt;/code&amp;gt; in the script to check different cases) [&amp;lt;code&amp;gt;Symmetry_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
Below, the result of the first plot.&lt;br /&gt;
&lt;br /&gt;
[[File:Car kpoints hbn.jpg|YamboLatticeDB plot from yambopy tutorial| 500px]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What about the units?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Below we report the relation between units used in Yambo, Quantum Espresso, and Yambopy.&lt;br /&gt;
&lt;br /&gt;
* bohr^-1 (atomic units):                                     &amp;lt;code&amp;gt;YamboLatticeDB.car_kpoints*2.*pi&amp;lt;/code&amp;gt;. Divide by the bohr-to-angstrom conversion factor to obtain angs^-1 &lt;br /&gt;
* Yambo cartesian units (&amp;lt;code&amp;gt;[cc]&amp;lt;/code&amp;gt; in Yambo outputs): &amp;lt;code&amp;gt;YamboLatticeDB.car_kpoints*2.*pi&amp;lt;/code&amp;gt; (same as above).&lt;br /&gt;
* QE cartesian units (&amp;lt;code&amp;gt;[cart. coord. in units 2pi/alat]&amp;lt;/code&amp;gt; in QE outputs): &amp;lt;code&amp;gt;YamboLatticeDB.car_kpoints*YamboLatticeDB.alat[0]&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Internal yambo units (&amp;lt;code&amp;gt;[iku]&amp;lt;/code&amp;gt; in yambo outputs): &amp;lt;code&amp;gt;YamboLatticeDB.iku_kpoints&amp;lt;/code&amp;gt;&lt;br /&gt;
* Fractional coordinates (&amp;lt;code&amp;gt;[rlu]&amp;lt;/code&amp;gt; in yambo, &amp;lt;code&amp;gt;cryst. coord.&amp;lt;/code&amp;gt; in QE): &amp;lt;code&amp;gt;YamboLatticeDB.red_kpoints&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Dipoles intro: plots of dipoles on BZ, plot of IP absorption ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;dipoles_plot.py&amp;lt;/code&amp;gt; and read the dipole databases generated in an optical absorption calculation by yambo. Keep in mind that from now on we will use the &amp;quot;BSE&amp;quot; yambo SAVE generated in the [[#Command line: generating the Yambo SAVE|first section]].&lt;br /&gt;
&lt;br /&gt;
The databases written after a calculation of optical properties with yambo (dipoles, static screening, excitons) are in the directory &amp;lt;code&amp;gt;BSE_saves/BSE_databases&amp;lt;/code&amp;gt;. Here we will also find &amp;lt;code&amp;gt;ndb.dipoles&amp;lt;/code&amp;gt; which is needed now, since it contains the matrix elements d_{vck}(\alpha) where vk and ck are the valence and electron states involved in the transition and \alpha the polarisation direction of the external electric field.&lt;br /&gt;
&lt;br /&gt;
In order to read it in python we use the Yambopy class &amp;lt;code&amp;gt;YamboDipolesDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
 ydip = YamboDipolesDB(ylat,save=&#039;path/to/BSE/databases&#039;,filename=&#039;ndb.dipoles&#039;)&lt;br /&gt;
(notice that it requires a previous instance of &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
In addition, in order to read the Kohn-Sham energies, we can also instance the &amp;lt;code&amp;gt;YamboElectronsDB&amp;lt;/code&amp;gt; as&lt;br /&gt;
 yel = YamboElectronsDB.from_db_file(folder=&#039;path/to/SAVE&#039;) &lt;br /&gt;
&lt;br /&gt;
The object &amp;lt;code&amp;gt;ydip&amp;lt;/code&amp;gt; now has a method that permits to retrieve the independent-particle absorption spectrum with customly chosen energy range, steps, and broadening:&lt;br /&gt;
 w, eps2 = ydip.ip_eps2(yel)&lt;br /&gt;
&lt;br /&gt;
In order to see all this in action, take a look at the &amp;lt;code&amp;gt;dipoles_plot.py&amp;lt;/code&amp;gt; script. You will see that it performs two plots:&lt;br /&gt;
* Plot of |d(k)| in the BZ for selected v,c and \alpha (we choose the layer plane &#039;xy&#039;) [&amp;lt;code&amp;gt;Kspace_Plot=True&amp;lt;/code&amp;gt;]. From this plot you can appreciate which sections of the BZ contribute the most to the absorption rate.&lt;br /&gt;
* Plot of the independent-particles absorption spectrum [&amp;lt;code&amp;gt;Absorption_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
You can play with the indices and the plot parameters to check what happens.&lt;br /&gt;
&lt;br /&gt;
[[File:Dipoles hbn2.png|YamboDipolesDB plot from yambopy tutorial|500px]]&lt;br /&gt;
&lt;br /&gt;
=== Exciton intro 1: read and sort data ===&lt;br /&gt;
In this section we will use both the script &amp;lt;code&amp;gt;exc_read.py&amp;lt;/code&amp;gt; and the command line in order to read the exciton data resulting from a BSE calculation to familiarise with their structure. This time we are going to read the &amp;lt;code&amp;gt;ndb.BS_diago_Q*&amp;lt;/code&amp;gt; databases which correspond to BSE calculations at various momenta Q (Q=1 being the zero-momentum optical absorption limit - notice that python indexing starts from 0, while the databases are counted starting from 1).&lt;br /&gt;
&lt;br /&gt;
In order to read them in python we use the Yambopy class &amp;lt;code&amp;gt;YamboExcitonDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
 yexc = YamboExcitonDB.from_db_file(ylat,filename=f&#039;path/to/BSE/databases/ndb.BS_diago_Q{i}&#039;)&lt;br /&gt;
(where i is the number of BS_diago_Qi file. Notice that it requires a previous instance of &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Now the &amp;lt;code&amp;gt;yexc&amp;lt;/code&amp;gt; object contains information about the exciton energies (&amp;lt;code&amp;gt;yexc.eigenvalues&amp;lt;/code&amp;gt;), wave functions (&amp;lt;code&amp;gt;yexc.eigenvectors&amp;lt;/code&amp;gt;) and intensities (&amp;lt;code&amp;gt;yexc.l_residuals&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yexc.r_residuals&amp;lt;/code&amp;gt;) for Qpoint i_Q. You can start by keeping &amp;lt;code&amp;gt;Q1&amp;lt;/code&amp;gt; which is the optical limit and then check other momenta.&lt;br /&gt;
&lt;br /&gt;
The exciton wave function components A_{vck}^{\lambda Q} (\lambda being the exciton index) are stored as A_{t}^{\lambda} in each Q-dependent database, with t being the transition index grouping the single-particle indices vck. Therefore, &amp;lt;code&amp;gt;yexc.eigenvectors&amp;lt;/code&amp;gt; is an array with (N_excitons,N_transitions) dimension. In order to make the connection t-&amp;gt;kcv, the table &amp;lt;code&amp;gt;yexc.table&amp;lt;/code&amp;gt; provides k,v,c and spin indices corresponding to each transition.&lt;br /&gt;
&lt;br /&gt;
In order to get a clearer picture, take a look at the script &amp;lt;code&amp;gt;exc_read.py&amp;lt;/code&amp;gt;. Run it and try to understand the outputs.&lt;br /&gt;
  $ python exc_read.py&lt;br /&gt;
&lt;br /&gt;
Actually, we can produce output files with the sorted exciton energies in a much more convenient way by using the command line instruction &amp;lt;code&amp;gt;exc-sort&amp;lt;/code&amp;gt;. Check its syntax via:&lt;br /&gt;
 $ yambopy exc-sort -h&lt;br /&gt;
&lt;br /&gt;
Then, we run it for our specific calculation with:&lt;br /&gt;
 $ yambopy exc-sort --save BSE_saves/YAMBO_saves/SAVE -J BSE_saves/BSE_databases --iqpt 1&lt;br /&gt;
&lt;br /&gt;
This should produce the &amp;lt;code&amp;gt;o-BSE_databases.exc_qpt1_sorted_E.dat&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;o-BSE_databases.exc_qpt1_sorted_I.dat&amp;lt;/code&amp;gt; output files for you to inspect. These are very useful as they allow for identification of degenerate states and degree of optical activity. You will see that in our system most states are doubly degenerate, a byproduct of crystal symmetry. This is an updated version of the ypp exciton analysis that you can find [[How to analyse excitons#Sort the excitonic eigenvalues|here]].&lt;br /&gt;
&lt;br /&gt;
=== Exciton intro 2: symmetry analysis and wavefunction plot in real space ===&lt;br /&gt;
&lt;br /&gt;
==== Symmetries of excitons====&lt;br /&gt;
We can analyse the symmetries of the excitonic wavefunctions in terms of irreducible representation of the point group of the system (if at Q=0) or the Q little group. For more information, the methodology is explained in Ref. &amp;lt;ref&amp;gt;Symmetries of excitons, M. Nalabothula et al., [https://arxiv.org/abs/2511.21540 preprint arXiv]&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
We use the &amp;lt;code&amp;gt;exc-irrep&amp;lt;/code&amp;gt; command line option, check the arguments with:&lt;br /&gt;
 $ yambopy exc-irrep -h&lt;br /&gt;
&lt;br /&gt;
We know from the previous section (by inspecting the sorted energies) that the first four BSE eigenvalues correspond to two doubly-degenerate bright states. Let us analyse their symmetry by running&lt;br /&gt;
 $ yambopy exc-irrep --path BSE_saves/YAMBO_saves -J BSE_saves/BSE_databases --iqpt 1 --nstates 4&lt;br /&gt;
&lt;br /&gt;
This command first loads the electronic wave functions and calculated the electronic representation matrices (called &amp;lt;code&amp;gt;Dmats&amp;lt;/code&amp;gt; in the code). As a second step, they are used to compute the &#039;&#039;&#039;excitonic&#039;&#039;&#039; representation matrices. &lt;br /&gt;
&lt;br /&gt;
We obtain the following output:&lt;br /&gt;
&lt;br /&gt;
 ========================================&lt;br /&gt;
 Group theory analysis for Q point : (0.000000, 0.000000, 0.000000)&lt;br /&gt;
 ****************************************&lt;br /&gt;
 Little group :  D3h&lt;br /&gt;
 Little group symmetries :  [ 1  2  3  4  5  6  7  8  9 10 11 12]&lt;br /&gt;
 Classes (symmetry indices in each class):&lt;br /&gt;
                E    :  [1]&lt;br /&gt;
             2S_3    :  [2 6]&lt;br /&gt;
             2C_3    :  [3 5]&lt;br /&gt;
          sigma_h    :  [4]&lt;br /&gt;
             3C_2    :  [ 7  9 11]&lt;br /&gt;
         3sigma_v    :  [ 8 10 12]&lt;br /&gt;
 &lt;br /&gt;
 ====== Exciton representations ======&lt;br /&gt;
 Energy (eV),  degeneracy  : representation&lt;br /&gt;
 ----------------------------------------&lt;br /&gt;
 1.9139                2  :  E&#039;&lt;br /&gt;
 2.5988                2  :  E&#039;&lt;br /&gt;
 ****************************************&lt;br /&gt;
&lt;br /&gt;
This is similar to the group theory analysis done by Quantum Espresso on the electronic states, and is actually analogous to the one performed for the phonon modes of crystals. We see that the first two states transform as the E&#039; representation of the D3h point group of the crystal. By optical selection rules, only states with this symmetry can form absorption peaks in monolayer BN when light is polarized along the layer plane.&lt;br /&gt;
&lt;br /&gt;
We could go further and calculate the total crystal angular momentum of these states, while also rotate the degenerate exciton states so that they are both eigenvectors of the BSE Hamiltonian and the total crystal angular momentum operator. This is very useful for analyses involving selection rules, exciton-boson couplings, chirality, etc. This is an advanced topic and will not be covered, nonetheless an example script is provided in the tutorial folder called &amp;lt;code&amp;gt;total_crystal_angular_momentum_exciton.py&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; What to do when symmetry analysis does not seem to work well &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Check for warnings during execution. If the BSE calculation was done with a response function that breaks the symmetries (such as the longitudinal response in place of the transverse one at q=0), that may explain the issues.&lt;br /&gt;
&lt;br /&gt;
* If the exciton density of states is very high (such as for a bulk 3D system or for a 2D system at higher energies in the optical spectrum), the analyser may fail to resolve degenerate states, and incorporate a bunch of states together. The symmetry analysis will still be performed but the representation labels will appear as summed. In severe cases, the code may crash. You can try to get a better result by carefully selecting the degeneracy tolerance with &amp;lt;code&amp;gt;degen_tol&amp;lt;/code&amp;gt; and restricting the number of states with &amp;lt;code&amp;gt;nstates&amp;lt;/code&amp;gt; in the command line options.&lt;br /&gt;
&lt;br /&gt;
====Exciton wave functions in real space====&lt;br /&gt;
We can also plot the wave functions of the exciton states on the crystal lattice. In practice, what we do is set the position of the hole at a &amp;quot;physical&amp;quot; point, and then visualize the resulting electronic distribution:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;I^{e}_{\lambda \mathbf{Q}}(\mathbf{r}_e)= |\Psi_{\alpha \mathbf{Q}}(\mathbf{r}_e,\mathbf{r}_h=\mathbf{r}_0)|^2&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let us focus on the lowest exciton state, which gives rise to the largest peak in absorption (see the last part of the tutorial). We will set the hole position on top of a nitrogen atom, since that&#039;s where the &amp;lt;math&amp;gt;p_z&amp;lt;/math&amp;gt; orbitals where the hole comes from are mostly localized.&lt;br /&gt;
&lt;br /&gt;
If we don&#039;t know the correct coordinates, we can modify the &amp;lt;code&amp;gt;bz_plot.py&amp;lt;/code&amp;gt; script by adding (after instancing the lattice object):&lt;br /&gt;
 for iat in range(len(ylat.atomic_numbers)): print(ylat.atomic_numbers[iat],ylat.red_atomic_positions[iat])&lt;br /&gt;
which will print&lt;br /&gt;
 5 [0.6666667 0.3333333 0.       ]&lt;br /&gt;
 7 [-0.6666667 -0.3333333  0.       ]&lt;br /&gt;
&lt;br /&gt;
In order to make the plot, we have to give yambopy the same inputs that are used in the equivalent [[How to analyse excitons#Plot the exciton spatial distribution| ypp calculation]]. First, let&#039;s check all the options via&lt;br /&gt;
 $ yambopy exc-wf -h&lt;br /&gt;
&lt;br /&gt;
Then, we can run our calculation (by selecting a 9x9x1 supercell and a 30 Ry cutoff) as &lt;br /&gt;
 $ yambopy exc-wf --path BSE_saves/YAMBO_saves -J BSE_saves/BSE_databases --iqpt 1 --iexe 1 --supercell 9 9 1 --wfc_cutoff 30 --hole 0.33333333 0.66666667 0.03&lt;br /&gt;
&lt;br /&gt;
Yambopy will produce a *.cube file that can be visualized with VESTA, xcrysden or the like, producing a figure similar to the one below.&lt;br /&gt;
&lt;br /&gt;
The example script &amp;lt;code&amp;gt;exc_real_wf.py&amp;lt;/code&amp;gt;, which runs the same calculation by explicitly calling the necessary functions, will give you more info about what is happening behind the scenes.&lt;br /&gt;
&lt;br /&gt;
[[File:Exc BN yambopy.png|YamboExcitonDB exciton wave function|400px]]&lt;br /&gt;
&lt;br /&gt;
We see that electron is localised in &amp;lt;math&amp;gt;p_z&amp;lt;/math&amp;gt;-like distributions on top of boron atoms around the nitrogen where the hole is set.&lt;br /&gt;
&lt;br /&gt;
=== Exciton intro 3: plot exciton weights on k-BZ and (interpolated) band structure ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;exc_kspace_plot.py&amp;lt;/code&amp;gt; and work with the quantities defined in the previous section.&lt;br /&gt;
&lt;br /&gt;
For now, only the i_Q=0 case is implemented in this section.&lt;br /&gt;
We want to check the relative importance of the various (vk-&amp;gt;ck) electronic transitions in forming a certain excitonic state. &lt;br /&gt;
&lt;br /&gt;
Since many excitonic states are degenerate, we first need to tell Yambopy which states we want to check. For example, in monolayer hexagonal boron nitride, the lowest-bound exciton - forming the main peak in the BSE absorption spectrum - is doubly degenerate. In order to analyse it, in the &amp;lt;code&amp;gt;exc_kspace_plot.py&amp;lt;/code&amp;gt; script we set&lt;br /&gt;
 states = [1,2]&lt;br /&gt;
(we can also set [3,4] to check the second excitonic state, and then [5] for the non-degenerate third state, and so on; we can check degeneracies by printing the energies using the script &amp;lt;code&amp;gt;exc_read.py&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
In order to make a band structure plot, it is necessary to read the band energies, for example with the &amp;lt;code&amp;gt;YamboSaveDB&amp;lt;/code&amp;gt; class&lt;br /&gt;
 yel = YamboSaveDB.from_db_file(folder=&#039;path/to/SAVE&#039;)&lt;br /&gt;
and specify the path in the BZ using crystal coordinates via the &amp;lt;code&amp;gt;Path&amp;lt;/code&amp;gt; function:   &lt;br /&gt;
 npoints = 20&lt;br /&gt;
 path = Path([ [[  0.0,  0.0,  0.0],&#039;$\Gamma$&#039;],&lt;br /&gt;
               [[  0.5,  0.0,  0.0],&#039;M&#039;],&lt;br /&gt;
               [[1./3.,1./3.,  0.0],&#039;K&#039;],&lt;br /&gt;
               [[  0.0,  0.0,  0.0],&#039;$\Gamma$&#039;]],&lt;br /&gt;
               [int(npoints*2),int(npoints),int(sqrt(5)*npoints)] )&lt;br /&gt;
&lt;br /&gt;
Now let&#039;s take a closer look at the &amp;lt;code&amp;gt;exc_kspace_plot.py&amp;lt;/code&amp;gt; script. You will see that it performs three plots:&lt;br /&gt;
* Plot of |A(k)| in the k-BZ for the selected exciton state. You can see how most contributions come from the area around K and the MK direction [&amp;lt;code&amp;gt;Kspace_Plot=True&amp;lt;/code&amp;gt;]. &lt;br /&gt;
* Plot of |A(v,c,k)| on the electronic band structure for the selected exciton state. Here you can better see how the top valence and bottom conduction around MK are mostly involved [&amp;lt;code&amp;gt;Bands_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Plot of interpolated |A(v,c,k)| on the interpolated electronic band structure for the selected exciton state [&amp;lt;code&amp;gt;Bands_Plot_Interpolated=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
As always, try to play with the parameters, for example by changing the excitonic states to analyse.&lt;br /&gt;
&lt;br /&gt;
[[File:Exc bands1 hbn.jpg|YamboExcitonDB plot from yambopy tutorial|300px| Uninterpolated exciton weights on top of band structure]][[File:Exc bands2 hbn.jpg|YamboExcitonDB plot from yambopy tutorial|300px]]&lt;br /&gt;
&lt;br /&gt;
=== Exciton intro 4: plot BSE optical absorption with custom options ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;exc_abs_plot.py&amp;lt;/code&amp;gt; and work with the quantities defined in the previous sections.&lt;br /&gt;
&lt;br /&gt;
The class &amp;lt;code&amp;gt;YamboExcitonDB&amp;lt;/code&amp;gt; also enables us, of course, to read the dielectric function eps(w) and print absorption and related spectra in python.&lt;br /&gt;
&lt;br /&gt;
The advantages over using the standard human-readable yambo outputs are mainly two:&lt;br /&gt;
# We can freely select energy ranges, energy steps, peak broadenings and number of excitonic states included without having to rerun the &amp;lt;code&amp;gt;yambo&amp;lt;/code&amp;gt; executable every time. This reduces the chance of mistakenly editing the yambo input and allows for greater freedom since these plots can now be done in your local machine without having to transfer the output data from a remote cluster.&lt;br /&gt;
# The dielectric function constructed from netCDF database variables has a much higher precision (number of significant digits) than the human readable output, which may be important if you want to perform additional operations in python (e.g., computing refractive index, reflectivity and other optical spectra from it, performing finite-difference derivatives, etc).&lt;br /&gt;
&lt;br /&gt;
We can read eps(w) as a &amp;lt;code&amp;gt;numpy&amp;lt;/code&amp;gt; array with the specified options as (energy values are in eV):&lt;br /&gt;
 w, eps = yexc.get_chi(nexcitons=&#039;all&#039;,emin=0,emax=7,estep=0.005,broad=0.04)&lt;br /&gt;
Or, you can directly prepare a plot of its imaginary part with&lt;br /&gt;
 w, chi = yexc.plot_chi_ax(ax,nexcitons=&#039;all&#039;,emin=0,emax=7,estep=0.005,broad=0.04)&lt;br /&gt;
where &amp;lt;code&amp;gt;ax&amp;lt;/code&amp;gt; is a previously defined &amp;lt;code&amp;gt;Axes&amp;lt;/code&amp;gt; object from &amp;lt;code&amp;gt;matplotlib&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In order to see how this works, let&#039;s take a look at the &amp;lt;code&amp;gt;exc_abs_plot.py&amp;lt;/code&amp;gt; script.&lt;br /&gt;
You will see that it performs the two operations described above:&lt;br /&gt;
* Plotting the BSE absorption spectrum [&amp;lt;code&amp;gt;Absorption_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Reading the complex dielectric function.&lt;br /&gt;
&lt;br /&gt;
Try to customise the plots by changing the &amp;lt;code&amp;gt;nexcitons&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;emin&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;emax&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;estep&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;broad&amp;lt;/code&amp;gt; parameters.&lt;br /&gt;
&lt;br /&gt;
[[File:Absalpha.png|Yambo alpha_2D tutorial plot|700px]]&lt;br /&gt;
&lt;br /&gt;
=== Command line: importing electron-phonon matrix elements ===&lt;br /&gt;
You may have seen how to calculate and import electron-phonon matrix elements in yambo in the [[Electron Phonon Coupling|electron-phonon tutorial]].&lt;br /&gt;
&lt;br /&gt;
With Yambopy, we can generate a yambo SAVE folder and import the matrix elements with a single command.&lt;br /&gt;
Typing &lt;br /&gt;
 $yambopy gkkp&lt;br /&gt;
will print the necessary documentation:&lt;br /&gt;
 Produce a SAVE folder including elph_gkkp databases&lt;br /&gt;
 &lt;br /&gt;
 Arguments are:&lt;br /&gt;
   -nscf, --nscf_dir  -&amp;gt; &amp;lt;Optional&amp;gt; Path to nscf save folder&lt;br /&gt;
   -elph, --elph_dir  -&amp;gt; Path to elph_dir folder&lt;br /&gt;
   -y, --yambo_dir    -&amp;gt; &amp;lt;Optional&amp;gt; Path to yambo executables&lt;br /&gt;
   -e, --expand       -&amp;gt; &amp;lt;Optional&amp;gt; Expand gkkp databases&lt;br /&gt;
&lt;br /&gt;
The necessary quantum espresso databases are stored in &amp;lt;code&amp;gt;ELPH_SAVES/QE_SAVES/hBN.save&amp;lt;/code&amp;gt; (nscf calculation) and &amp;lt;code&amp;gt;ELPH_SAVES/QE_SAVES/elph_dir&amp;lt;/code&amp;gt; (matrix elements from the dfpt calculation). For this tutorial we also need to expand the electron-phonon matrix elements to the full Brillouin zone. Since this is a different calculation with respect to the previous section, please generate this SAVE in a different directory than the one you used for the previous SAVE, which should be the current directory.&lt;br /&gt;
For example:&lt;br /&gt;
 $mkdir yambo-with-elph&lt;br /&gt;
 $cd yambo-with-elph&lt;br /&gt;
&lt;br /&gt;
Now we can run yambopy as in the instructions:&lt;br /&gt;
 $yambopy gkkp -nscf ../ELPH_saves/QE_saves/hBN.save -elph ../ELPH_saves/QE_saves/elph_dir --expand&lt;br /&gt;
This should generate a yambo SAVE folder which contains the &amp;lt;code&amp;gt;ndb.elph_gkkp_expanded*&amp;lt;/code&amp;gt; databases.&lt;br /&gt;
&lt;br /&gt;
=== Electron-phonon intro: plots of el-ph matrix elements on k-BZ and q-BZ ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; and read the electron-phonon databases that you generated in the previous section.&lt;br /&gt;
&lt;br /&gt;
In order to read the &amp;lt;code&amp;gt;ndb.elph_gkkp_expanded*&amp;lt;/code&amp;gt; databases in python we use the Yambopy class &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
 yelph = YamboElectronPhononDB(ylat,folder_gkkp=&#039;path/to/elph/folder&#039;,save=&#039;path/to/SAVE&#039;)&lt;br /&gt;
(notice that it requires a previous instance of &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Now, the &amp;lt;code&amp;gt;yelph&amp;lt;/code&amp;gt; object contains phonon frequencies, phonon eigenvectors, qpoint information and, of course, the electron-phonon matrix elements g_{nm\nu}(k,q) where n, m are electron band states, \nu is a phonon branch, and k and q are the electronic and transfer momenta.&lt;br /&gt;
&lt;br /&gt;
We can print the docstring of the &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt; class with&lt;br /&gt;
 print(yelph.__doc__)&lt;br /&gt;
to get an idea of the information stored and of its capabilities.&lt;br /&gt;
&lt;br /&gt;
Now check the &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; script. You will see that it performs two plots: &lt;br /&gt;
* Plot of |g(k)| in the k-BZ for selected n,m,\nu and q [&amp;lt;code&amp;gt;Kspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Plot of |g(q)| in the q-BZ for selected n,m,\nu and k [&amp;lt;code&amp;gt;Qspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
You can change the electronic, phononic and momentum indices to see what happens.&lt;br /&gt;
&lt;br /&gt;
[[File:Elph hbn.jpg|YamboElectronPhononDB plot from yambopy tutorial|500px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Links==&lt;br /&gt;
* Back to [[Rome 2023#Tutorials]]&lt;br /&gt;
* Back to [[ICTP 2022#Tutorials]]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;/div&gt;</summary>
		<author><name>FulvioPaleari</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_Yambo_databases&amp;diff=9300</id>
		<title>Yambopy tutorial: Yambo databases</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_Yambo_databases&amp;diff=9300"/>
		<updated>2026-03-09T19:08:25Z</updated>

		<summary type="html">&lt;p&gt;FulvioPaleari: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial we will see some examples on how to read and analyse the data contained in the Yambo netCDF databases, which are not readily available as human readable outputs.&lt;br /&gt;
&lt;br /&gt;
In particular we will take a look at:&lt;br /&gt;
* Lattice geometry data (Yambo database: &amp;lt;code&amp;gt;ns.db1&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
* Dipole matrix elements (Yambo databases: &amp;lt;code&amp;gt;ndb.dipoles&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboDipolesDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
* Exciton energies, symmetries, wavefunctions and spectra (Yambo databases: &amp;lt;code&amp;gt;ndb.BS_diago_Q*&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboExcitonDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
We will also check the command line instructions to quickly generate yambo SAVE folders.&lt;br /&gt;
&lt;br /&gt;
The scripts of the tutorial, but not the databases, can be found in the yambopy directory:&lt;br /&gt;
 $cd tutorial/databases_yambopy&lt;br /&gt;
&lt;br /&gt;
The full tutorial, including the Quantum espresso and Yambo databases that we will read, can be downloaded and extracted from the yambo website:&lt;br /&gt;
 $wget https://media.yambo-code.eu/educational/tutorials/files/databases_yambopy.tar.gz&lt;br /&gt;
 $tar -xvzf databases_yambopy.tar.gz&lt;br /&gt;
 $cd databases_yambopy&lt;br /&gt;
&lt;br /&gt;
We will work with monolayer hexagonal boron nitride electron-phonon and exciton data obtained on a &amp;lt;code&amp;gt;12x12x1&amp;lt;/code&amp;gt; kpoint grid. Beware that these are certainly not converged.&lt;br /&gt;
&lt;br /&gt;
=== Command line: generating the Yambo SAVE ===&lt;br /&gt;
Yambopy offers a set of command line options. In order to review them, you can type&lt;br /&gt;
 $yambopy&lt;br /&gt;
which will print the output&lt;br /&gt;
 yambopy v0.7&lt;br /&gt;
 Available commands are:&lt;br /&gt;
&lt;br /&gt;
       plotem1s -&amp;gt;     Plot em1s calculation.&lt;br /&gt;
     analysebse -&amp;gt;     Study the convergence of BSE calculations.&lt;br /&gt;
      analysegw -&amp;gt;     Study the convergence of GW calculations by looking at the change in band-gap value.&lt;br /&gt;
   plotexcitons -&amp;gt;     Plot excitons calculation&lt;br /&gt;
          addqp -&amp;gt;     Add corrections from QP databases.&lt;br /&gt;
        mergeqp -&amp;gt;     Merge QP databases&lt;br /&gt;
           save -&amp;gt;     Produce a SAVE folder&lt;br /&gt;
           gkkp -&amp;gt;     Produce a SAVE folder including elph_gkkp databases&lt;br /&gt;
          bands -&amp;gt;     Script to produce band structure data and visualization from QE.&lt;br /&gt;
         serial -&amp;gt;     Script to update serial numbers of yambo ndb.* databases in order to import them to new calculations.&lt;br /&gt;
     gwsubspace -&amp;gt;     Script to calculate off-diago corrections of yambo ndb.QP databases in order to plot band structure.&lt;br /&gt;
          phinp -&amp;gt;     Script to update the explicit list of q-points in a ph input file (ldisp=.false., qplot=.true.).&lt;br /&gt;
        convert -&amp;gt;     Script to convert RL number in Ry energy units using ndb.gops.&lt;br /&gt;
        bsesize -&amp;gt;     Script to calculate the expected BSE kernel size, in GB, to be loaded by each MPI task.&lt;br /&gt;
            l2y -&amp;gt;     Calculate gauge-invariant electron-phonon matrix elements with LetzElPhC and convert them into Yambo format.&lt;br /&gt;
      exc-irrep -&amp;gt;     Script to get the irreducible representation labels for excitonic states. [-h for help]&lt;br /&gt;
         exc-wf -&amp;gt;     Real space exciton wf for either fixed hole/electron. [-h for help]&lt;br /&gt;
       exc-sort -&amp;gt;     Script to sort excitonic states according to energies and intensities. [-h for help]&lt;br /&gt;
&lt;br /&gt;
For this tutorial, we will need the &amp;lt;code&amp;gt;save&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;gkkp&amp;lt;/code&amp;gt; options.&lt;br /&gt;
By typing in one of these, additional information about how to run the commands will be printed, e.g.:&lt;br /&gt;
 $yambopy save&lt;br /&gt;
&lt;br /&gt;
 Produce a SAVE folder&lt;br /&gt;
 &lt;br /&gt;
 Arguments are:&lt;br /&gt;
   -nscf, --nscf_dir  -&amp;gt; Path to nscf save folder&lt;br /&gt;
   -y, --yambo_dir    -&amp;gt; &amp;lt;Optional&amp;gt; Path to yambo executables&lt;br /&gt;
&lt;br /&gt;
The quantum espresso save for hBN is provided in the directory &amp;lt;code&amp;gt;BSE_saves/QE_saves/hBN.save&amp;lt;/code&amp;gt; (you can check the contents of the various folders). &lt;br /&gt;
Then, following the instructions printed on screen, we can generate a yambo SAVE from the hBN.save by typing&lt;br /&gt;
&lt;br /&gt;
 $yambopy save -nscf BSE_saves/QE_saves/hBN.save&lt;br /&gt;
&lt;br /&gt;
This should produce a SAVE folder in the current directory.&lt;br /&gt;
&lt;br /&gt;
=== Lattice intro: plot k-point coordinates in IBZ/BZ ===&lt;br /&gt;
For this section we will use the script &amp;lt;code&amp;gt;bz_plot.py&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
By inspecting the SAVE folder we have just generated, we will find the &amp;lt;code&amp;gt;ns.db1&amp;lt;/code&amp;gt; database which contains all the geometry and lattice information.&lt;br /&gt;
We are now going to read it in python by using the Yambopy class &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
&lt;br /&gt;
 from yambopy import *&lt;br /&gt;
 ylat = YamboLatticeDB.from_db_file(filename=&amp;quot;PATH/TO/SAVE/ns.db1&amp;quot;)&lt;br /&gt;
(remember to edit the variable &amp;lt;code&amp;gt;save_path&amp;lt;/code&amp;gt; in order to point at your yambo SAVE).&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;ylat&amp;lt;/code&amp;gt; object now contains many useful information as attributes, such as the k-points in Cartesian or crystal coordinates, the system symmetries, lattice constants and basis vectors in real and reciprocal space, etc.&lt;br /&gt;
The k-points are also automatically expanded in the full Brillouin zone from the irreducible one (you can turn this off with the option &amp;lt;code&amp;gt;Expand=False&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Directly printing the object with&lt;br /&gt;
 print(ylat)&lt;br /&gt;
will also give us some general parameters related to the database. &lt;br /&gt;
&lt;br /&gt;
Now check the &amp;lt;code&amp;gt;bz_plot.py&amp;lt;/code&amp;gt; script. You will see that it performs three plots: &lt;br /&gt;
* Scatterplot of the k-points in Cartesian coordinates with both expanded and unexpanded grids, with annotated indices [&amp;lt;code&amp;gt;Cartesian_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Scatterplot of the k-points in crystal coordinates [&amp;lt;code&amp;gt;Crystal_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Manual transformation of a chosen k-point from irreducible to full Brillouin zone (you can change the index &amp;lt;code&amp;gt;i_k&amp;lt;/code&amp;gt; in the script to check different cases) [&amp;lt;code&amp;gt;Symmetry_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
Below, the result of the first plot.&lt;br /&gt;
&lt;br /&gt;
[[File:Car kpoints hbn.jpg|YamboLatticeDB plot from yambopy tutorial| 500px]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;What about the units?&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Below we report the relation between units used in Yambo, Quantum Espresso, and Yambopy.&lt;br /&gt;
&lt;br /&gt;
* bohr^-1 (atomic units):                                     &amp;lt;code&amp;gt;YamboLatticeDB.car_kpoints*2.*pi&amp;lt;/code&amp;gt;. Divide by the bohr-to-angstrom conversion factor to obtain angs^-1 &lt;br /&gt;
* Yambo cartesian units (&amp;lt;code&amp;gt;[cc]&amp;lt;/code&amp;gt; in Yambo outputs): &amp;lt;code&amp;gt;YamboLatticeDB.car_kpoints*2.*pi&amp;lt;/code&amp;gt; (same as above).&lt;br /&gt;
* QE cartesian units (&amp;lt;code&amp;gt;[cart. coord. in units 2pi/alat]&amp;lt;/code&amp;gt; in QE outputs): &amp;lt;code&amp;gt;YamboLatticeDB.car_kpoints*YamboLatticeDB.alat[0]&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Internal yambo units (&amp;lt;code&amp;gt;[iku]&amp;lt;/code&amp;gt; in yambo outputs): &amp;lt;code&amp;gt;YamboLatticeDB.iku_kpoints&amp;lt;/code&amp;gt;&lt;br /&gt;
* Fractional coordinates (&amp;lt;code&amp;gt;[rlu]&amp;lt;/code&amp;gt; in yambo, &amp;lt;code&amp;gt;cryst. coord.&amp;lt;/code&amp;gt; in QE): &amp;lt;code&amp;gt;YamboLatticeDB.red_kpoints&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Dipoles intro: plots of dipoles on BZ, plot of IP absorption ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;dipoles_plot.py&amp;lt;/code&amp;gt; and read the dipole databases generated in an optical absorption calculation by yambo. Keep in mind that from now on we will use the &amp;quot;BSE&amp;quot; yambo SAVE generated in the [[#Command line: generating the Yambo SAVE|first section]].&lt;br /&gt;
&lt;br /&gt;
The databases written after a calculation of optical properties with yambo (dipoles, static screening, excitons) are in the directory &amp;lt;code&amp;gt;BSE_saves/BSE_databases&amp;lt;/code&amp;gt;. Here we will also find &amp;lt;code&amp;gt;ndb.dipoles&amp;lt;/code&amp;gt; which is needed now, since it contains the matrix elements d_{vck}(\alpha) where vk and ck are the valence and electron states involved in the transition and \alpha the polarisation direction of the external electric field.&lt;br /&gt;
&lt;br /&gt;
In order to read it in python we use the Yambopy class &amp;lt;code&amp;gt;YamboDipolesDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
 ydip = YamboDipolesDB(ylat,save=&#039;path/to/BSE/databases&#039;,filename=&#039;ndb.dipoles&#039;)&lt;br /&gt;
(notice that it requires a previous instance of &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
In addition, in order to read the Kohn-Sham energies, we can also instance the &amp;lt;code&amp;gt;YamboElectronsDB&amp;lt;/code&amp;gt; as&lt;br /&gt;
 yel = YamboElectronsDB.from_db_file(folder=&#039;path/to/SAVE&#039;) &lt;br /&gt;
&lt;br /&gt;
The object &amp;lt;code&amp;gt;ydip&amp;lt;/code&amp;gt; now has a method that permits to retrieve the independent-particle absorption spectrum with customly chosen energy range, steps, and broadening:&lt;br /&gt;
 w, eps2 = ydip.ip_eps2(yel)&lt;br /&gt;
&lt;br /&gt;
In order to see all this in action, take a look at the &amp;lt;code&amp;gt;dipoles_plot.py&amp;lt;/code&amp;gt; script. You will see that it performs two plots:&lt;br /&gt;
* Plot of |d(k)| in the BZ for selected v,c and \alpha (we choose the layer plane &#039;xy&#039;) [&amp;lt;code&amp;gt;Kspace_Plot=True&amp;lt;/code&amp;gt;]. From this plot you can appreciate which sections of the BZ contribute the most to the absorption rate.&lt;br /&gt;
* Plot of the independent-particles absorption spectrum [&amp;lt;code&amp;gt;Absorption_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
You can play with the indices and the plot parameters to check what happens.&lt;br /&gt;
&lt;br /&gt;
[[File:Dipoles hbn2.png|YamboDipolesDB plot from yambopy tutorial|500px]]&lt;br /&gt;
&lt;br /&gt;
=== Exciton intro 1: read and sort data ===&lt;br /&gt;
In this section we will use both the script &amp;lt;code&amp;gt;exc_read.py&amp;lt;/code&amp;gt; and the command line in order to read the exciton data resulting from a BSE calculation to familiarise with their structure. This time we are going to read the &amp;lt;code&amp;gt;ndb.BS_diago_Q*&amp;lt;/code&amp;gt; databases which correspond to BSE calculations at various momenta Q (Q=1 being the zero-momentum optical absorption limit - notice that python indexing starts from 0, while the databases are counted starting from 1).&lt;br /&gt;
&lt;br /&gt;
In order to read them in python we use the Yambopy class &amp;lt;code&amp;gt;YamboExcitonDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
 yexc = YamboExcitonDB.from_db_file(ylat,filename=f&#039;path/to/BSE/databases/ndb.BS_diago_Q{i}&#039;)&lt;br /&gt;
(where i is the number of BS_diago_Qi file. Notice that it requires a previous instance of &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Now the &amp;lt;code&amp;gt;yexc&amp;lt;/code&amp;gt; object contains information about the exciton energies (&amp;lt;code&amp;gt;yexc.eigenvalues&amp;lt;/code&amp;gt;), wave functions (&amp;lt;code&amp;gt;yexc.eigenvectors&amp;lt;/code&amp;gt;) and intensities (&amp;lt;code&amp;gt;yexc.l_residuals&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yexc.r_residuals&amp;lt;/code&amp;gt;) for Qpoint i_Q. You can start by keeping &amp;lt;code&amp;gt;Q1&amp;lt;/code&amp;gt; which is the optical limit and then check other momenta.&lt;br /&gt;
&lt;br /&gt;
The exciton wave function components A_{vck}^{\lambda Q} (\lambda being the exciton index) are stored as A_{t}^{\lambda} in each Q-dependent database, with t being the transition index grouping the single-particle indices vck. Therefore, &amp;lt;code&amp;gt;yexc.eigenvectors&amp;lt;/code&amp;gt; is an array with (N_excitons,N_transitions) dimension. In order to make the connection t-&amp;gt;kcv, the table &amp;lt;code&amp;gt;yexc.table&amp;lt;/code&amp;gt; provides k,v,c and spin indices corresponding to each transition.&lt;br /&gt;
&lt;br /&gt;
In order to get a clearer picture, take a look at the script &amp;lt;code&amp;gt;exc_read.py&amp;lt;/code&amp;gt;. Run it and try to understand the outputs.&lt;br /&gt;
  $ python exc_read.py&lt;br /&gt;
&lt;br /&gt;
Actually, we can produce output files with the sorted exciton energies in a much more convenient way by using the command line instruction &amp;lt;code&amp;gt;exc-sort&amp;lt;/code&amp;gt;. Check its syntax via:&lt;br /&gt;
 $ yambopy exc-sort -h&lt;br /&gt;
&lt;br /&gt;
Then, we run it for our specific calculation with:&lt;br /&gt;
 $ yambopy exc-sort --save BSE_saves/YAMBO_saves/SAVE -J BSE_saves/BSE_databases --iqpt 1&lt;br /&gt;
&lt;br /&gt;
This should produce the &amp;lt;code&amp;gt;o-BSE_databases.exc_qpt1_sorted_E.dat&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;o-BSE_databases.exc_qpt1_sorted_I.dat&amp;lt;/code&amp;gt; output files for you to inspect. These are very useful as they allow for identification of degenerate states and degree of optical activity. You will see that in our system most states are doubly degenerate, a byproduct of crystal symmetry. This is an updated version of the ypp exciton analysis that you can find [[How to analyse excitons#Sort the excitonic eigenvalues|here]].&lt;br /&gt;
&lt;br /&gt;
=== Exciton intro 2: symmetry analysis and wavefunction plot in real space ===&lt;br /&gt;
&lt;br /&gt;
==== Symmetries of excitons====&lt;br /&gt;
We can analyse the symmetries of the excitonic wavefunctions in terms of irreducible representation of the point group of the system (if at Q=0) or the Q little group. For more information, the methodology is explained in Ref. &amp;lt;ref&amp;gt;Symmetries of excitons, M. Nalabothula et al., [https://arxiv.org/abs/2511.21540 preprint arXiv]&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
We use the &amp;lt;code&amp;gt;exc-irrep&amp;lt;/code&amp;gt; command line option, check the arguments with:&lt;br /&gt;
 $ yambopy exc-irrep -h&lt;br /&gt;
&lt;br /&gt;
We know from the previous section (by inspecting the sorted energies) that the first four BSE eigenvalues correspond to two doubly-degenerate bright states. Let us analyse their symmetry by running&lt;br /&gt;
 $ yambopy exc-irrep --path BSE_saves/YAMBO_saves -J BSE_saves/BSE_databases --iqpt 1 --nstates 4&lt;br /&gt;
&lt;br /&gt;
This command first loads the electronic wave functions and calculated the electronic representation matrices (called &amp;lt;code&amp;gt;Dmats&amp;lt;/code&amp;gt; in the code). As a second step, they are used to compute the &#039;&#039;&#039;excitonic&#039;&#039;&#039; representation matrices. &lt;br /&gt;
&lt;br /&gt;
We obtain the following output:&lt;br /&gt;
&lt;br /&gt;
 ========================================&lt;br /&gt;
 Group theory analysis for Q point : (0.000000, 0.000000, 0.000000)&lt;br /&gt;
 ****************************************&lt;br /&gt;
 Little group :  D3h&lt;br /&gt;
 Little group symmetries :  [ 1  2  3  4  5  6  7  8  9 10 11 12]&lt;br /&gt;
 Classes (symmetry indices in each class):&lt;br /&gt;
                E    :  [1]&lt;br /&gt;
             2S_3    :  [2 6]&lt;br /&gt;
             2C_3    :  [3 5]&lt;br /&gt;
          sigma_h    :  [4]&lt;br /&gt;
             3C_2    :  [ 7  9 11]&lt;br /&gt;
         3sigma_v    :  [ 8 10 12]&lt;br /&gt;
 &lt;br /&gt;
 ====== Exciton representations ======&lt;br /&gt;
 Energy (eV),  degeneracy  : representation&lt;br /&gt;
 ----------------------------------------&lt;br /&gt;
 1.9139                2  :  E&#039;&lt;br /&gt;
 2.5988                2  :  E&#039;&lt;br /&gt;
 ****************************************&lt;br /&gt;
&lt;br /&gt;
This is similar to the group theory analysis done by Quantum Espresso on the electronic states, and is actually analogous to the one performed for the phonon modes of crystals. We see that the first two states transform as the E&#039; representation of the D3h point group of the crystal. By optical selection rules, only states with this symmetry can form absorption peaks in monolayer BN when light is polarized along the layer plane.&lt;br /&gt;
&lt;br /&gt;
We could go further and calculate the total crystal angular momentum of these states, while also rotate the degenerate exciton states so that they are both eigenvectors of the BSE Hamiltonian and the total crystal angular momentum operator. This is very useful for analyses involving selection rules, exciton-boson couplings, chirality, etc. This is an advanced topic and will not be covered, nonetheless an example script is provided in the tutorial folder called &amp;lt;code&amp;gt;total_crystal_angular_momentum_exciton.py&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; What to do when symmetry analysis does not seem to work well &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Check for warnings during execution. If the BSE calculation was done with a response function that breaks the symmetries (such as the longitudinal response in place of the transverse one at q=0), that may explain the issues.&lt;br /&gt;
&lt;br /&gt;
* If the exciton density of states is very high (such as for a bulk 3D system or for a 2D system at higher energies in the optical spectrum), the analyser may fail to resolve degenerate states, and incorporate a bunch of states together. The symmetry analysis will still be performed but the representation labels will appear as summed. In severe cases, the code may crash. You can try to get a better result by carefully selecting the degeneracy tolerance with &amp;lt;code&amp;gt;degen_tol&amp;lt;/code&amp;gt; and restricting the number of states with &amp;lt;code&amp;gt;nstates&amp;lt;/code&amp;gt; in the command line options.&lt;br /&gt;
&lt;br /&gt;
====Exciton wave functions in real space====&lt;br /&gt;
We can also plot the wave functions of the exciton states on the crystal lattice. In practice, what we do is set the position of the hole at a &amp;quot;physical&amp;quot; point, and then visualize the resulting electronic distribution:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;I^{e}_{\lambda \mathbf{Q}}(\mathbf{r}_e)= |\Psi_{\alpha \mathbf{Q}}(\mathbf{r}_e,\mathbf{r}_h=\mathbf{r}_0)|^2&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Let us focus on the lowest exciton state, which gives rise to the largest peak in absorption (see the last part of the tutorial). We will set the hole position on top of a nitrogen atom, since that&#039;s where the &amp;lt;math&amp;gt;p_z&amp;lt;/math&amp;gt; orbitals where the hole comes from are mostly localized.&lt;br /&gt;
&lt;br /&gt;
If we don&#039;t know the correct coordinates, we can modify the &amp;lt;code&amp;gt;bz_plot.py&amp;lt;/code&amp;gt; script by adding (after instancing the lattice object):&lt;br /&gt;
 for iat in range(len(ylat.atomic_numbers)): print(ylat.atomic_numbers[iat],ylat.red_atomic_positions[iat])&lt;br /&gt;
which will print&lt;br /&gt;
 5 [0.6666667 0.3333333 0.       ]&lt;br /&gt;
 7 [-0.6666667 -0.3333333  0.       ]&lt;br /&gt;
&lt;br /&gt;
In order to make the plot, we have to give yambopy the same inputs that are used in the equivalent [[How to analyse excitons#Plot the exciton spatial distribution| ypp calculation]]. First, let&#039;s check all the options via&lt;br /&gt;
 $ yambopy exc-wf -h&lt;br /&gt;
&lt;br /&gt;
Then, we can run our calculation (by selecting a 9x9x1 supercell and a 30 Ry cutoff) as &lt;br /&gt;
 $ yambopy exc-wf --path BSE_saves/YAMBO_saves -J BSE_saves/BSE_databases --iqpt 1 --iexe 1 --supercell 9 9 1 --wfc_cutoff 30 --hole 0.33333333 0.66666667 0.03&lt;br /&gt;
&lt;br /&gt;
Yambopy will produce a *.cube file that can be visualized with VESTA, xcrysden or the like, producing a figure similar to the one below.&lt;br /&gt;
&lt;br /&gt;
The example script &amp;lt;code&amp;gt;exc_real_wf.py&amp;lt;/code&amp;gt;, which runs the same calculation by explicitly calling the necessary functions, will give you more info about what is happening behind the scenes.&lt;br /&gt;
&lt;br /&gt;
[[File:Exc BN yambopy.png|YamboExcitonDB exciton wave function|400px]]&lt;br /&gt;
&lt;br /&gt;
We see that electron is localised in &amp;lt;math&amp;gt;p_z&amp;lt;/math&amp;gt;-like distributions on top of boron atoms around the nitrogen where the hole is set.&lt;br /&gt;
&lt;br /&gt;
=== Exciton intro 3: plot exciton weights on k-BZ and (interpolated) band structure ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;exc_kspace_plot.py&amp;lt;/code&amp;gt; and work with the quantities defined in the previous section.&lt;br /&gt;
&lt;br /&gt;
For now, only the i_Q=0 case is implemented in this section.&lt;br /&gt;
We want to check the relative importance of the various (vk-&amp;gt;ck) electronic transitions in forming a certain excitonic state. &lt;br /&gt;
&lt;br /&gt;
Since many excitonic states are degenerate, we first need to tell Yambopy which states we want to check. For example, in monolayer hexagonal boron nitride, the lowest-bound exciton - forming the main peak in the BSE absorption spectrum - is doubly degenerate. In order to analyse it, in the &amp;lt;code&amp;gt;exc_kspace_plot.py&amp;lt;/code&amp;gt; script we set&lt;br /&gt;
 states = [1,2]&lt;br /&gt;
(we can also set [3,4] to check the second excitonic state, and then [5] for the non-degenerate third state, and so on; we can check degeneracies by printing the energies using the script &amp;lt;code&amp;gt;exc_read.py&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
In order to make a band structure plot, it is necessary to read the band energies, for example with the &amp;lt;code&amp;gt;YamboSaveDB&amp;lt;/code&amp;gt; class&lt;br /&gt;
 yel = YamboSaveDB.from_db_file(folder=&#039;path/to/SAVE&#039;)&lt;br /&gt;
and specify the path in the BZ using crystal coordinates via the &amp;lt;code&amp;gt;Path&amp;lt;/code&amp;gt; function:   &lt;br /&gt;
 npoints = 20&lt;br /&gt;
 path = Path([ [[  0.0,  0.0,  0.0],&#039;$\Gamma$&#039;],&lt;br /&gt;
               [[  0.5,  0.0,  0.0],&#039;M&#039;],&lt;br /&gt;
               [[1./3.,1./3.,  0.0],&#039;K&#039;],&lt;br /&gt;
               [[  0.0,  0.0,  0.0],&#039;$\Gamma$&#039;]],&lt;br /&gt;
               [int(npoints*2),int(npoints),int(sqrt(5)*npoints)] )&lt;br /&gt;
&lt;br /&gt;
Now let&#039;s take a closer look at the &amp;lt;code&amp;gt;exc_kspace_plot.py&amp;lt;/code&amp;gt; script. You will see that it performs three plots:&lt;br /&gt;
* Plot of |A(k)| in the k-BZ for the selected exciton state. You can see how most contributions come from the area around K and the MK direction [&amp;lt;code&amp;gt;Kspace_Plot=True&amp;lt;/code&amp;gt;]. &lt;br /&gt;
* Plot of |A(v,c,k)| on the electronic band structure for the selected exciton state. Here you can better see how the top valence and bottom conduction around MK are mostly involved [&amp;lt;code&amp;gt;Bands_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Plot of interpolated |A(v,c,k)| on the interpolated electronic band structure for the selected exciton state [&amp;lt;code&amp;gt;Bands_Plot_Interpolated=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
As always, try to play with the parameters, for example by changing the excitonic states to analyse.&lt;br /&gt;
&lt;br /&gt;
[[File:Exc bands1 hbn.jpg|YamboExcitonDB plot from yambopy tutorial|300px| Uninterpolated exciton weights on top of band structure]][[File:Exc bands2 hbn.jpg|YamboExcitonDB plot from yambopy tutorial|300px]]&lt;br /&gt;
&lt;br /&gt;
=== Exciton intro 4: plot BSE optical absorption with custom options ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;exc_abs_plot.py&amp;lt;/code&amp;gt; and work with the quantities defined in the previous sections.&lt;br /&gt;
&lt;br /&gt;
The class &amp;lt;code&amp;gt;YamboExcitonDB&amp;lt;/code&amp;gt; also enables us, of course, to read the dielectric function eps(w) and print absorption and related spectra in python.&lt;br /&gt;
&lt;br /&gt;
The advantages over using the standard human-readable yambo outputs are mainly two:&lt;br /&gt;
# We can freely select energy ranges, energy steps, peak broadenings and number of excitonic states included without having to rerun the &amp;lt;code&amp;gt;yambo&amp;lt;/code&amp;gt; executable every time. This reduces the chance of mistakenly editing the yambo input and allows for greater freedom since these plots can now be done in your local machine without having to transfer the output data from a remote cluster.&lt;br /&gt;
# The dielectric function constructed from netCDF database variables has a much higher precision (number of significant digits) than the human readable output, which may be important if you want to perform additional operations in python (e.g., computing refractive index, reflectivity and other optical spectra from it, performing finite-difference derivatives, etc).&lt;br /&gt;
&lt;br /&gt;
We can read eps(w) as a &amp;lt;code&amp;gt;numpy&amp;lt;/code&amp;gt; array with the specified options as (energy values are in eV):&lt;br /&gt;
 w, eps = yexc.get_chi(nexcitons=&#039;all&#039;,emin=0,emax=7,estep=0.005,broad=0.04)&lt;br /&gt;
Or, you can directly prepare a plot of its imaginary part with&lt;br /&gt;
 w, chi = yexc.plot_chi_ax(ax,nexcitons=&#039;all&#039;,emin=0,emax=7,estep=0.005,broad=0.04)&lt;br /&gt;
where &amp;lt;code&amp;gt;ax&amp;lt;/code&amp;gt; is a previously defined &amp;lt;code&amp;gt;Axes&amp;lt;/code&amp;gt; object from &amp;lt;code&amp;gt;matplotlib&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In order to see how this works, let&#039;s take a look at the &amp;lt;code&amp;gt;exc_abs_plot.py&amp;lt;/code&amp;gt; script.&lt;br /&gt;
You will see that it performs the two operations described above:&lt;br /&gt;
* Plotting the BSE absorption spectrum [&amp;lt;code&amp;gt;Absorption_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Reading the complex dielectric function.&lt;br /&gt;
&lt;br /&gt;
Try to customise the plots by changing the &amp;lt;code&amp;gt;nexcitons&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;emin&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;emax&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;estep&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;broad&amp;lt;/code&amp;gt; parameters.&lt;br /&gt;
&lt;br /&gt;
[[File:Absalpha.png|Yambo alpha_2D tutorial plot|700px]]&lt;br /&gt;
&lt;br /&gt;
=== Command line: importing electron-phonon matrix elements ===&lt;br /&gt;
You may have seen how to calculate and import electron-phonon matrix elements in yambo in the [[Electron Phonon Coupling|electron-phonon tutorial]].&lt;br /&gt;
&lt;br /&gt;
With Yambopy, we can generate a yambo SAVE folder and import the matrix elements with a single command.&lt;br /&gt;
Typing &lt;br /&gt;
 $yambopy gkkp&lt;br /&gt;
will print the necessary documentation:&lt;br /&gt;
 Produce a SAVE folder including elph_gkkp databases&lt;br /&gt;
 &lt;br /&gt;
 Arguments are:&lt;br /&gt;
   -nscf, --nscf_dir  -&amp;gt; &amp;lt;Optional&amp;gt; Path to nscf save folder&lt;br /&gt;
   -elph, --elph_dir  -&amp;gt; Path to elph_dir folder&lt;br /&gt;
   -y, --yambo_dir    -&amp;gt; &amp;lt;Optional&amp;gt; Path to yambo executables&lt;br /&gt;
   -e, --expand       -&amp;gt; &amp;lt;Optional&amp;gt; Expand gkkp databases&lt;br /&gt;
&lt;br /&gt;
The necessary quantum espresso databases are stored in &amp;lt;code&amp;gt;ELPH_SAVES/QE_SAVES/hBN.save&amp;lt;/code&amp;gt; (nscf calculation) and &amp;lt;code&amp;gt;ELPH_SAVES/QE_SAVES/elph_dir&amp;lt;/code&amp;gt; (matrix elements from the dfpt calculation). For this tutorial we also need to expand the electron-phonon matrix elements to the full Brillouin zone. Since this is a different calculation with respect to the previous section, please generate this SAVE in a different directory than the one you used for the previous SAVE, which should be the current directory.&lt;br /&gt;
For example:&lt;br /&gt;
 $mkdir yambo-with-elph&lt;br /&gt;
 $cd yambo-with-elph&lt;br /&gt;
&lt;br /&gt;
Now we can run yambopy as in the instructions:&lt;br /&gt;
 $yambopy gkkp -nscf ../ELPH_saves/QE_saves/hBN.save -elph ../ELPH_saves/QE_saves/elph_dir --expand&lt;br /&gt;
This should generate a yambo SAVE folder which contains the &amp;lt;code&amp;gt;ndb.elph_gkkp_expanded*&amp;lt;/code&amp;gt; databases.&lt;br /&gt;
&lt;br /&gt;
=== Electron-phonon intro: plots of el-ph matrix elements on k-BZ and q-BZ ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; and read the electron-phonon databases that you generated in the previous section.&lt;br /&gt;
&lt;br /&gt;
In order to read the &amp;lt;code&amp;gt;ndb.elph_gkkp_expanded*&amp;lt;/code&amp;gt; databases in python we use the Yambopy class &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
 yelph = YamboElectronPhononDB(ylat,folder_gkkp=&#039;path/to/elph/folder&#039;,save=&#039;path/to/SAVE&#039;)&lt;br /&gt;
(notice that it requires a previous instance of &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Now, the &amp;lt;code&amp;gt;yelph&amp;lt;/code&amp;gt; object contains phonon frequencies, phonon eigenvectors, qpoint information and, of course, the electron-phonon matrix elements g_{nm\nu}(k,q) where n, m are electron band states, \nu is a phonon branch, and k and q are the electronic and transfer momenta.&lt;br /&gt;
&lt;br /&gt;
We can print the docstring of the &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt; class with&lt;br /&gt;
 print(yelph.__doc__)&lt;br /&gt;
to get an idea of the information stored and of its capabilities.&lt;br /&gt;
&lt;br /&gt;
Now check the &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; script. You will see that it performs two plots: &lt;br /&gt;
* Plot of |g(k)| in the k-BZ for selected n,m,\nu and q [&amp;lt;code&amp;gt;Kspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Plot of |g(q)| in the q-BZ for selected n,m,\nu and k [&amp;lt;code&amp;gt;Qspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
You can change the electronic, phononic and momentum indices to see what happens.&lt;br /&gt;
&lt;br /&gt;
[[File:Elph hbn.jpg|YamboElectronPhononDB plot from yambopy tutorial|500px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Links==&lt;br /&gt;
* Back to [[Rome 2023#Tutorials]]&lt;br /&gt;
* Back to [[ICTP 2022#Tutorials]]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;/div&gt;</summary>
		<author><name>FulvioPaleari</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=First_steps_in_Yambopy&amp;diff=9299</id>
		<title>First steps in Yambopy</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=First_steps_in_Yambopy&amp;diff=9299"/>
		<updated>2026-03-09T19:05:32Z</updated>

		<summary type="html">&lt;p&gt;FulvioPaleari: /* Tutorials */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The yambopy project aims to develop python tools to: &lt;br /&gt;
&lt;br /&gt;
* Read and edit yambo and quantum espresso input files&lt;br /&gt;
* Easily perform pre- and post-processing of the simulation data for these two codes - including hard-to-get, database-encoded data beyond standard outputs&lt;br /&gt;
* Provide easy visualization and plotting options &lt;br /&gt;
* Set up simple automatization workflows (e.g., convergence tests)&lt;br /&gt;
&lt;br /&gt;
=== Setup ===&lt;br /&gt;
First of all, make sure that you have a suitable python environment (crated for example with [https://docs.anaconda.com/miniconda/install/ conda] or [https://docs.python.org/3/library/venv.html venv]) with &#039;&#039;&#039;python &amp;gt;=3.8&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
If you are not used with python environments, here two simple commands that you can use&lt;br /&gt;
 python -m venv MYPATH/yamboenv/&lt;br /&gt;
(you can replace `MYPATH` with any path you prefer, e.g. `~/`)&lt;br /&gt;
 source MYPATH/yamboenv/bin/activate&lt;br /&gt;
(for bash users, you can add to your .bashrt the line `. MYPATH/yamboenv/bin/activate`)&lt;br /&gt;
&lt;br /&gt;
Then, you may install yambopy in one of the following ways.&lt;br /&gt;
&lt;br /&gt;
==== Quick installation from PyPI repository ====&lt;br /&gt;
&lt;br /&gt;
* In order to quickly install the officially released version type:&lt;br /&gt;
&lt;br /&gt;
 pip install yambopy&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Installation from tarball ====&lt;br /&gt;
&lt;br /&gt;
* In case you don&#039;t want to download from the pip repository and prefer to install a version of yambopy locally, you may download the appropriate tarball from the [https://github.com/yambo-code/yambopy/releases| yambopy github page]. Extract the tarball, enter the yambopy folder and type &amp;lt;code&amp;gt;pip install .&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Installation of latest patch ====&lt;br /&gt;
&lt;br /&gt;
* In case you want the latest version of the code including new updates and patches that might not be present in the official version, then you can clone the yambopy git repository (a basic knowledge of git may be helpful):&lt;br /&gt;
&lt;br /&gt;
 git clone https://github.com/yambo-code/yambopy.git&lt;br /&gt;
 cd yambopy&lt;br /&gt;
 pip install .&lt;br /&gt;
&lt;br /&gt;
==== Installation for developers ====&lt;br /&gt;
* If you want to install YamboPy in developing mode (to modify or add new functions) you have to download the code from github repository then go in the YamboPy folder and install with the command:&lt;br /&gt;
&lt;br /&gt;
 pip install -e .&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Important:&#039;&#039;&#039; if you want your changes to be included into a new patch/version of Yambopy, you need to first create your own personal fork of the git repository, make the changes there, and then create a pull request for the original repository. &lt;br /&gt;
&lt;br /&gt;
==== Dependencies ====&lt;br /&gt;
&lt;br /&gt;
* In principle, &amp;lt;code&amp;gt;pip&amp;lt;/code&amp;gt; should take care of the required python dependencies. They are &amp;lt;code&amp;gt;numpy&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;scipy&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;matplotlib&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;netCDF4&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;h5py&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;lxml&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;PyYAML&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;monty&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;scikit-learn&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;tqdm&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;spglib&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;spgrep&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;pykdtree&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;numba&amp;lt;/code&amp;gt;. In case some dependency-related problem arises, you can install each of them separately beforehand with:&lt;br /&gt;
&lt;br /&gt;
 pip install &amp;lt;code&amp;gt;dependency-name&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* If you experience errors related to &amp;lt;code&amp;gt;NetCDF4&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;hdf5&amp;lt;/code&amp;gt;, these are usually due to incompatibilities between the python modules the library in your environment. In this case, you can force the python installation to match the system library. For example, if you have an &amp;lt;code&amp;gt;hdf5&amp;lt;/code&amp;gt; problem and you are using conda, you could try:&lt;br /&gt;
&lt;br /&gt;
 conda install --force-reinstall h5py hdf5&lt;br /&gt;
&lt;br /&gt;
=== Tutorials ===&lt;br /&gt;
Now yambopy is ready to use! Just go to the tutorials folder and follow the docs!&lt;br /&gt;
&lt;br /&gt;
 cd tutorial/&lt;br /&gt;
&lt;br /&gt;
On this wiki, we provide steps for the following tutorials:&lt;br /&gt;
&lt;br /&gt;
1. Data postprocessing:&lt;br /&gt;
* [[Yambopy tutorial: band structures | Database and plotting tutorial for quantum espresso (qepy) and GW band structures]] (Get the databases: [https://media.yambo-code.eu/educational/tutorials/files/databases_qepy.tar.gz databases_qepy], 46.5MB)&lt;br /&gt;
* [[Yambopy tutorial: Yambo databases | Database and plotting tutorial for yambo (yambopy) and exciton analysis ]] (Get the databases: [https://media.yambo-code.eu/educational/tutorials/files/databases_yambopy.tar.gz databases_yambopy], 129MB)&lt;br /&gt;
2. Manage QE and Yambo runs: [WARNING: these tutorials are currently under maintenance due to updates to the scheduler class]&lt;br /&gt;
* [[GW tutorial. Convergence and approximations (BN)]]&lt;br /&gt;
* [[Bethe-Salpeter equation tutorial. Optical absorption (BN)]]&lt;br /&gt;
3. Advanced topics:&lt;br /&gt;
* [[Yambopy tutorial: electron-phonon coupling|Databases and plotting tutorial for electron-phonon coupling with yambopy]] (Get the databases: )&lt;br /&gt;
* [[Exciton-phonon coupling and luminescence]]&lt;br /&gt;
* [[Phonon-assisted luminescence by finite atomic displacements]]&lt;br /&gt;
&lt;br /&gt;
=== How to cite ===&lt;br /&gt;
If yambopy helped you with your data analysis, workflow management of figure preparation, you can consider citing us.&lt;br /&gt;
&lt;br /&gt;
The way to do so in BibTeX format is the following:&lt;br /&gt;
 @misc{yambopy, &lt;br /&gt;
      author = {Paleari, Fulvio and Molina-Sánchez, Alejandro and Nalabothula, Muralidhar and Reho, Riccardo and Bonacci, Miki and Castelo, José M. and Cervantes-Villanueva, Jorge and Pionteck, Mike and Silvetti, Martino and Attaccalite, Claudio and Pereira Coutada Miranda, Henrique},&lt;br /&gt;
      title = {Yambopy},&lt;br /&gt;
      month = mar,&lt;br /&gt;
      year = 2025,&lt;br /&gt;
      publisher = {Zenodo},&lt;br /&gt;
      version = {0.4.0}, &lt;br /&gt;
      doi = {10.5281/zenodo.15012962},&lt;br /&gt;
      url = {[[https://doi.org/10.5281/zenodo.15012962 https://doi.org/10.5281/zenodo.15012962]]}, }&lt;/div&gt;</summary>
		<author><name>FulvioPaleari</name></author>
	</entry>
</feed>