<?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=Attacc</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=Attacc"/>
	<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Special:Contributions/Attacc"/>
	<updated>2026-05-17T14:33:03Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.8</generator>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Pump_and_Probe&amp;diff=9259</id>
		<title>Pump and Probe</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Pump_and_Probe&amp;diff=9259"/>
		<updated>2025-12-01T10:25:54Z</updated>

		<summary type="html">&lt;p&gt;Attacc: /* Analysis of the results using YamboPy */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
In this tutorial we will show you how to setup two external fields in &#039;&#039;&#039;yambo_nl&#039;&#039;&#039;, to perform pump and probe simulation. &amp;lt;ref name=&amp;quot;pnp&amp;quot;&amp;gt;[https://arxiv.org/abs/2211.12241 Exciton - Exciton transitions involving strongly bound excitons: an ab-initio approach], D. Sangalli, M. D&#039;Alessandro and C. Attaccalite, Physical Review B &#039;&#039;&#039;107&#039;&#039;&#039; (20), 205203 (2023) &amp;lt;/ref&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
This tutorial is at independent particle level, but the same kind of simulation can be repeated including local field effects, &lt;br /&gt;
quasi-particle correction or electron-hole interaction, see for example the tutorials:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[Correlation effects in the non-linear response]] &amp;lt;br&amp;gt;&lt;br /&gt;
[[Real time Bethe-Salpeter Equation (TDSE)]]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
This tutorial supposes that you are already familiar with real-time simulation with Yambo&amp;lt;ref name=&amp;quot;dberry&amp;quot;&amp;gt;[https://arxiv.org/abs/1609.09639 Non-linear response in extended systems: a real-time approach], C. Attaccalite &amp;lt;/ref&amp;gt;&lt;br /&gt;
if it is not the case please check these tutorials: [[Tutorials#Non_linear_response]]&lt;br /&gt;
&lt;br /&gt;
We start from the h-BN monolayer with an in place lattice constant a=2.5 Å and a box large 33 a.u. in the z-direction.&lt;br /&gt;
Standard DFT input for hBN monolayer for ABINIT or QuantumEspresso can be found here [[Tutorials]]. &amp;lt;br&amp;gt;&lt;br /&gt;
We used  a 9x9x1 k-points grid and 8 bands in the non-self consistent calculation and 40 Ry cutoff for the wave-function.&lt;br /&gt;
&lt;br /&gt;
In our example we choose direction [0,1,0] for the pump and [1,0,0] for the probe. &lt;br /&gt;
We generate the ypp.in to remove symmetries with the command &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;ypp -y&amp;lt;/span&amp;gt; and we modify it as:&lt;br /&gt;
&lt;br /&gt;
 fixsyms                          # [R] Remove symmetries not consistent with an external perturbation&lt;br /&gt;
 % Efield1&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;0.000000 | 1.000000 | 0.000000 |  &amp;lt;/span&amp;gt;      # First external Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 % Efield2&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 1.000000 | 0.000000 | 0.000000 | &amp;lt;/span&amp;gt;       # Additional external Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 BField= 0.000000           T     # [MAG] Magnetic field modulus&lt;br /&gt;
 Bpsi= 0.000000             deg   # [MAG] Magnetic field psi angle [degree]&lt;br /&gt;
 Btheta= 0.000000           deg   # [MAG] Magnetic field theta angle [degree]&lt;br /&gt;
 #RmAllSymm                     # Remove all symmetries &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;RmTimeRev&amp;lt;/span&amp;gt;                     # Remove Time Reversal&lt;br /&gt;
 #RmSpaceInv                    # Remove Spatial Inversion&lt;br /&gt;
&lt;br /&gt;
then we go in the FixSymm directory and run again the setup. &amp;lt;br&amp;gt;&lt;br /&gt;
We will perform three different real-time calculations: &amp;lt;br&amp;gt;&lt;br /&gt;
* the probe field alone; &lt;br /&gt;
* the pump field alone; &lt;br /&gt;
* the pump and probe configuration.&lt;br /&gt;
&lt;br /&gt;
== Probe only ==&lt;br /&gt;
&lt;br /&gt;
We can generate the input file for a generic Pump and Probe calculations with the command: &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;yambo_nl -u p -F yambo.in_probe&amp;lt;/span&amp;gt;:&lt;br /&gt;
 &lt;br /&gt;
 nloptics                         # [R] Non-linear spectroscopy&lt;br /&gt;
 DIP_Threads=0                    # [OPENMP/X] Number of threads for dipoles&lt;br /&gt;
 NL_Threads=0                     # [OPENMP/NL] Number of threads for nl-optics&lt;br /&gt;
 % NLBands&lt;br /&gt;
   &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;  3 |  6 |    &amp;lt;/span&amp;gt;                       # [NL] Bands range&lt;br /&gt;
 %&lt;br /&gt;
 NLverbosity= &amp;quot;high&amp;quot;              # [NL] Verbosity level (low | high)&lt;br /&gt;
 NLtime= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 80.000000&amp;lt;/span&amp;gt;           fs    # [NL] Simulation Time&lt;br /&gt;
 NLintegrator= &amp;quot; &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; CRANKNIC&amp;lt;/span&amp;gt;&amp;quot;           # [NL] Integrator (&amp;quot;EULEREXP/RK2/RK4/RK2EXP/HEUN/INVINT/CRANKNIC&amp;quot;)&lt;br /&gt;
 NLCorrelation= &amp;quot;IPA&amp;quot;             # [NL] Correlation (&amp;quot;IPA/HARTREE/TDDFT/LRC/LRW/JGM/SEX&amp;quot;)&lt;br /&gt;
 NLLrcAlpha= 0.000000             # [NL] Long Range Correction&lt;br /&gt;
 NLDamping= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;0.000000 &amp;lt;/span&amp;gt;       eV    # [NL] Damping (or dephasing)&lt;br /&gt;
 RADLifeTime=-1.000000      fs    # [RT] Radiative life-time (if negative Yambo sets it equal to Phase_LifeTime in NL)&lt;br /&gt;
 #EvalCurrent                   # [NL] Evaluate the current&lt;br /&gt;
 #FrPolPerdic                   # [DIP] Force periodicity of polarization respect to the external field&lt;br /&gt;
 HARRLvcs= 21817            RL    # [HA] Hartree     RL components&lt;br /&gt;
 EXXRLvcs= 21817            RL    # [XX] Exchange    RL components&lt;br /&gt;
 % Field1_Freq&lt;br /&gt;
  0.100000 | 0.100000 |         eV    # [RT Field1] Frequency&lt;br /&gt;
 %&lt;br /&gt;
 Field1_NFreqs= 1                 # [RT Field1] Frequency&lt;br /&gt;
 Field1_Int=  1000.00       kWLm2 # [RT Field1] Intensity&lt;br /&gt;
 Field1_Width= 0.000000     fs    # [RT Field1] Width&lt;br /&gt;
 Field1_kind= &amp;quot; &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; DELTA&amp;lt;/span&amp;gt;&amp;quot;           # [RT Field1] Kind(SIN|COS|RES|ANTIRES|GAUSS|DELTA|QSSIN)&lt;br /&gt;
 Field1_pol= &amp;quot;linear&amp;quot;             # [RT Field1] Pol(linear|circular)&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
   &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 1.000000 | 0.000000 | 0.000000 |  &amp;lt;/span&amp;gt;      # [RT Field1] Versor&lt;br /&gt;
 %&lt;br /&gt;
 Field1_Tstart=  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 5.00000  &amp;lt;/span&amp;gt;  fs    # [RT Field1] Initial Time&lt;br /&gt;
 [......]&lt;br /&gt;
&lt;br /&gt;
In this input we set only the first field that is the probe, we use a DELTA function as field in such a way to probe all the frequencies, and set the starting point of the delta at t=5 fs. &amp;lt;br&amp;gt;Run this job in a separate folder with the command  &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;yambo_nl -F yambo.in_probe -J PROBE&amp;lt;/span&amp;gt;. Then we can analyze the spectra with &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;ypp -u -J PROBE &amp;lt;/span&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 nonlinear                        # [R] Non-linear response analysis&lt;br /&gt;
 Xorder= 1                        # Max order of the response/exc functions&lt;br /&gt;
 % TimeRange&lt;br /&gt;
 -1.000000 |-1.000000 |         fs    # Time-window where processing is done&lt;br /&gt;
 %&lt;br /&gt;
 ETStpsRt= 200                    # Total Energy steps&lt;br /&gt;
 % EnRngeRt&lt;br /&gt;
   0.00000 | 20.00000 |         eV    # Energy range&lt;br /&gt;
 %&lt;br /&gt;
 DampMode= &amp;quot;&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;LORENTZIAN&amp;lt;/span&amp;gt;&amp;quot;           # Damping type ( NONE | LORENTZIAN | GAUSSIAN )&lt;br /&gt;
 DampFactor= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;0.100000&amp;lt;/span&amp;gt;       eV    # Damping parameter&lt;br /&gt;
 PumpPATH= &amp;quot;none&amp;quot;           # Path of the simulation with the Pump only&lt;br /&gt;
&lt;br /&gt;
and get the dielectric response. Notice that we introduce a Lorentzian broadening the post-processing. &amp;lt;br&amp;gt;&lt;br /&gt;
Hereafter we plot the damped polarization along the y-direction and the corresponding dielectric constant:&lt;br /&gt;
&lt;br /&gt;
[[File:Eps probe.png|800px|center | Probe only]]&lt;br /&gt;
&lt;br /&gt;
the arrow indicates the position where we will put the Pump in the next simulation.&lt;br /&gt;
&lt;br /&gt;
==Pump only==&lt;br /&gt;
&lt;br /&gt;
Now we run a simulation with the pump field only. We generate the input in the same way &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;yambo_nl -u p -F yambo.in_pump&amp;lt;/span&amp;gt;. &amp;lt;br&amp;gt;&lt;br /&gt;
These result will be our reference field in the final analysis. Here the input file for the pump:&lt;br /&gt;
 &lt;br /&gt;
 nloptics                         # [R] Non-linear spectroscopy&lt;br /&gt;
 DIP_Threads=0                    # [OPENMP/X] Number of threads for dipoles&lt;br /&gt;
 NL_Threads=0                     # [OPENMP/NL] Number of threads for nl-optics&lt;br /&gt;
 % NLBands&lt;br /&gt;
    &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;3 |  6 |&amp;lt;/span&amp;gt;                           # [NL] Bands range&lt;br /&gt;
 %&lt;br /&gt;
 NLverbosity= &amp;quot;high&amp;quot;              # [NL] Verbosity level (low | high)&lt;br /&gt;
 NLtime=  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;150.0000&amp;lt;/span&amp;gt;           fs    # [NL] Simulation Time&lt;br /&gt;
 NLintegrator= &amp;quot;CRANKNIC&amp;quot;         # [NL] Integrator (&amp;quot;EULEREXP/RK2/RK4/RK2EXP/HEUN/INVINT/CRANKNIC&amp;quot;)&lt;br /&gt;
 NLCorrelation= &amp;quot;IPA&amp;quot;             # [NL] Correlation (&amp;quot;IPA/HARTREE/TDDFT/LRC/LRW/JGM/SEX&amp;quot;)&lt;br /&gt;
 NLLrcAlpha= 0.000000             # [NL] Long Range Correction&lt;br /&gt;
 NLDamping=  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;0.000000&amp;lt;/span&amp;gt;        eV    # [NL] Damping (or dephasing)&lt;br /&gt;
 RADLifeTime=-1.000000      fs    # [RT] Radiative life-time (if negative Yambo sets it equal to Phase_LifeTime in NL)&lt;br /&gt;
 #EvalCurrent                   # [NL] Evaluate the current&lt;br /&gt;
 #FrPolPerdic                   # [DIP] Force periodicity of polarization respect to the external field&lt;br /&gt;
 HARRLvcs= 21817            RL    # [HA] Hartree     RL components&lt;br /&gt;
 EXXRLvcs= 21817            RL    # [XX] Exchange    RL components&lt;br /&gt;
 % Field1_Freq&lt;br /&gt;
  0.100000 | 0.100000 |         eV    # [RT Field1] Frequency&lt;br /&gt;
 %&lt;br /&gt;
 Field1_NFreqs= 1                 # [RT Field1] Frequency&lt;br /&gt;
 Field1_Int=  10000.00       kWLm2 # [RT Field1] Intensity&lt;br /&gt;
 Field1_Width= 0.000000     fs    # [RT Field1] Width&lt;br /&gt;
 Field1_kind= &amp;quot;SOFTSIN&amp;quot;           # [RT Field1] Kind(SIN|COS|RES|ANTIRES|GAUSS|DELTA|QSSIN)&lt;br /&gt;
 Field1_pol= &amp;quot;linear&amp;quot;             # [RT Field1] Pol(linear|circular)&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
  0.000000 | 0.000000 | 0.000000 |        # [RT Field1] Versor&lt;br /&gt;
 %&lt;br /&gt;
 Field1_Tstart= 0.010000    fs    # [RT Field1] Initial Time &lt;br /&gt;
 % Field2_Freq&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 5.42 | 5.42 &amp;lt;/span&amp;gt;|         eV    # [RT Field2] Frequency&lt;br /&gt;
 %&lt;br /&gt;
 Field2_NFreqs= 1                 # [RT Field2] Frequency&lt;br /&gt;
 Field2_Int=  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;1000.00 &amp;lt;/span&amp;gt;      kWLm2 # [RT Field2] Intensity&lt;br /&gt;
 Field2_Width= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;10.00000&amp;lt;/span&amp;gt;     fs    # [RT Field2] Width&lt;br /&gt;
 Field2_kind= &amp;quot;&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;QSSIN&amp;lt;/span&amp;gt;&amp;quot;             # [RT Field2] Kind(SIN|COS|RES|ANTIRES|GAUSS|DELTA|QSSIN)&lt;br /&gt;
 Field2_pol= &amp;quot;linear&amp;quot;             # [RT Field2] Pol(linear|circular)&lt;br /&gt;
 % Field2_Dir&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 0.000000 | 1.000000 | 0.000000 |   &amp;lt;/span&amp;gt;     # [RT Field2] Versor&lt;br /&gt;
 %&lt;br /&gt;
 Field2_Tstart= 0.010000    fs    # [RT Field2] Initial Time&lt;br /&gt;
 [...]&lt;br /&gt;
In this simulation we used as Pump field QSSIN that is sinus with a Guassian envelope[https://demonstrations.wolfram.com/SineGaussianSignals/ sine-Gaussian wave]. For a list of all possible field in Yambo see the file  &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt; src/modules/mod_fields.F&amp;lt;/span&amp;gt;. We centred the field frequency at 5.42 eV that is the energy of the highest peak in the previous figure, see arrow there. &lt;br /&gt;
Run the simulation with the command &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;yambo_nl -F yambo.in_pump -J PUMP &amp;lt;/span&amp;gt;.&lt;br /&gt;
The pump field, column 6th of the file &amp;lt;code&amp;gt;o-PUMP.external_potential_F1&amp;lt;/code&amp;gt;, is shown in the figure below:&lt;br /&gt;
&lt;br /&gt;
[[File:Pump only.png|800px|center|Pump field]]&lt;br /&gt;
&lt;br /&gt;
== Pump and probe==&lt;br /&gt;
&lt;br /&gt;
Now we copy the pump in file in a new file &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt; cp yambo.in_pump yambo.in_pump_and_probe&amp;lt;/span&amp;gt; and turn on  the probe field:&lt;br /&gt;
&lt;br /&gt;
 nloptics                         # [R] Non-linear spectroscopy&lt;br /&gt;
 DIP_Threads=0                    # [OPENMP/X] Number of threads for dipoles&lt;br /&gt;
 NL_Threads=0                     # [OPENMP/NL] Number of threads for nl-optics&lt;br /&gt;
 % NLBands&lt;br /&gt;
   3 |  6 |                           # [NL] Bands range&lt;br /&gt;
 %&lt;br /&gt;
 NLverbosity= &amp;quot;high&amp;quot;              # [NL] Verbosity level (low | high)&lt;br /&gt;
 NLtime=  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;150.0000 &amp;lt;/span&amp;gt;          fs    # [NL] Simulation Time&lt;br /&gt;
 NLintegrator= &amp;quot;CRANKNIC&amp;quot;         # [NL] Integrator (&amp;quot;EULEREXP/RK2/RK4/RK2EXP/HEUN/INVINT/CRANKNIC&amp;quot;)&lt;br /&gt;
 NLCorrelation= &amp;quot;IPA&amp;quot;             # [NL] Correlation (&amp;quot;IPA/HARTREE/TDDFT/LRC/LRW/JGM/SEX&amp;quot;)&lt;br /&gt;
 NLLrcAlpha= 0.000000             # [NL] Long Range Correction&lt;br /&gt;
 NLDamping=  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;0.000000 &amp;lt;/span&amp;gt;       eV    # [NL] Damping (or dephasing)&lt;br /&gt;
 RADLifeTime=-1.000000      fs    # [RT] Radiative life-time (if negative Yambo sets it equal to Phase_LifeTime in NL)&lt;br /&gt;
 #EvalCurrent                   # [NL] Evaluate the current&lt;br /&gt;
 #FrPolPerdic                   # [DIP] Force periodicity of polarization respect to the external field&lt;br /&gt;
 HARRLvcs= 21817            RL    # [HA] Hartree     RL components&lt;br /&gt;
 EXXRLvcs= 21817            RL    # [XX] Exchange    RL components&lt;br /&gt;
 % Field1_Freq&lt;br /&gt;
  0.100000 | 0.100000 |         eV    # [RT Field1] Frequency&lt;br /&gt;
 %&lt;br /&gt;
 Field1_NFreqs= 1                 # [RT Field1] Frequency&lt;br /&gt;
 Field1_Int=  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;1.00  &amp;lt;/span&amp;gt;     kWLm2 # [RT Field1] Intensity&lt;br /&gt;
 Field1_Width= 0.000000     fs    # [RT Field1] Width&lt;br /&gt;
 Field1_kind= &amp;quot;&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;DELTA&amp;lt;/span&amp;gt;&amp;quot;           # [RT Field1] Kind(SIN|COS|RES|ANTIRES|GAUSS|DELTA|QSSIN)&lt;br /&gt;
 Field1_pol= &amp;quot;linear&amp;quot;             # [RT Field1] Pol(linear|circular)&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 1.000000 | 0.000000 | 0.000000 | &amp;lt;/span&amp;gt;       # [RT Field1] Versor&lt;br /&gt;
 %&lt;br /&gt;
 Field1_Tstart= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;90.0000  &amp;lt;/span&amp;gt;  fs    # [RT Field1] Initial Time&lt;br /&gt;
 % Field2_Freq&lt;br /&gt;
   &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;5.42 | 5.42 |  &amp;lt;/span&amp;gt;       eV    # [RT Field2] Frequency&lt;br /&gt;
 %&lt;br /&gt;
 Field2_NFreqs= 1                 # [RT Field2] Frequency&lt;br /&gt;
 Field2_Int=  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;1000.00&amp;lt;/span&amp;gt;       kWLm2 # [RT Field2] Intensity&lt;br /&gt;
 Field2_Width=  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;10.00000  &amp;lt;/span&amp;gt;   fs    # [RT Field2] Width&lt;br /&gt;
 Field2_kind= &amp;quot;&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;QSSIN&amp;lt;/span&amp;gt;&amp;quot;             # [RT Field2] Kind(SIN|COS|RES|ANTIRES|GAUSS|DELTA|QSSIN)&lt;br /&gt;
 Field2_pol= &amp;quot;linear&amp;quot;             # [RT Field2] Pol(linear|circular)&lt;br /&gt;
 % Field2_Dir&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;0.000000 | 1.000000 | 0.000000 |&amp;lt;/span&amp;gt;        # [RT Field2] Versor&lt;br /&gt;
 %&lt;br /&gt;
 Field2_Tstart= 0.010000    fs    # [RT Field2] Initial Time&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Please note:&#039;&#039;&#039;  by convention in Yambo we consider the first field the probe and the second the pump. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
you run the simulation with the command &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;yambo_nl -F yambo.in_pump_and_probe -J PUMP_AND_PROBE &amp;lt;/span&amp;gt; and then we analyze the result using ypp with the command: &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;ypp_nl -u -J PUMP_AND_PROBE &amp;lt;/span&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 nonlinear                        # [R] Non-linear response analysis &lt;br /&gt;
 Xorder= 1                        # Max order of the response/exc functions&lt;br /&gt;
 % TimeRange&lt;br /&gt;
 -1.000000 |-1.000000 |         fs    # Time-window where processing is done&lt;br /&gt;
 %&lt;br /&gt;
 ETStpsRt= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;500 &amp;lt;/span&amp;gt;                   # Total Energy steps&lt;br /&gt;
 % EnRngeRt&lt;br /&gt;
   &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;0.00000 | 3.9000 &amp;lt;/span&amp;gt;|         eV    # Energy range&lt;br /&gt;
 %&lt;br /&gt;
 DampMode= &amp;quot;&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;GAUSSIAN&amp;lt;/span&amp;gt;&amp;quot;                 # Damping type ( NONE | LORENTZIAN | GAUSSIAN )&lt;br /&gt;
 DampFactor= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;0.085000  &amp;lt;/span&amp;gt;     eV    # Damping parameter&lt;br /&gt;
 PumpPATH= &amp;quot;&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;./PUMP/&amp;lt;/span&amp;gt;&amp;quot;                 # Path of the simulation with the Pump only&lt;br /&gt;
&lt;br /&gt;
Notice that in this case we are interested in the spectra below the 4 eV, that is was zero without the presence of the pump. We put in the input the pump path in such way to calculate polarization of the pump&amp;amp;probe minus the one of generate by the pump only &amp;lt;math&amp;gt;\Delta P(t) = P_{PnP}(t) - P_{pump}(t)&amp;lt;/math&amp;gt;. Then we analyze the &amp;lt;math&amp;gt;\Delta P(t)&amp;lt;/math&amp;gt; and get the new spectra:&lt;br /&gt;
&lt;br /&gt;
[[File:P and p spectrum.png|800px | center|Pump and probe spectrum]]&lt;br /&gt;
&lt;br /&gt;
The peak that you see in this spectrum, that were not present in when the pump was zero, correspond to the transition between the different excited states. The pump field populates the state at 5.42 eV and then the probe excites electrons from this state to higher states. The energy difference between the higher excited states and the peak at 5.42 define the position of the peaks in the pump and probe spectrum, while their intensity is dictated by the dipole matrix elements between the different excited states, see Ref. &amp;lt;ref name=&amp;quot;pnp&amp;quot;&amp;gt;&amp;lt;/ref&amp;gt;.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Additional comments on pump and probe calculations &#039;&#039;&#039;&lt;br /&gt;
* We used a Gaussian damping factor, this choice is motivated by various tests we have done, and it seems to us that in pump and probe this broadening gives better results.&amp;lt;br&amp;gt;&lt;br /&gt;
* If you plot all spectrum you will notice that the &amp;quot;equilibrium part&amp;quot; is much stronger than the one induced by the pump, this is normal because only a small fraction of electron are promoted in the excited state by the pump.&lt;br /&gt;
* All previous simulation can be run also in presence of excitons, see  Ref. &amp;lt;ref name=&amp;quot;pnp&amp;quot;&amp;gt;&amp;lt;/ref&amp;gt; and group theory can be used to predict dark/bright transition in the pump and probe spectroscopy.&amp;lt;ref&amp;gt;[https://link.springer.com/book/10.1007/978-3-540-32899-5  Group Theory, Application to the Physics of Condensed Matter],   Mildred S. S. Dresselhaus, Gene Dresselhaus, Ado Jorio, Springer Editor&amp;lt;/ref&amp;gt;&lt;br /&gt;
* In principle is it possible to include damping and radiative life-time in the simulation to study retardation effect between the pump and probe. This  approach  exact in the independent particle case, but introduces an error when correlation effects are present, see Refs.&amp;lt;ref&amp;gt;[https://arxiv.org/abs/2106.03592 Excitons and carriers in transient absorption and time-resolved ARPES spectroscopy: an abinitio approach], D. Sangalli, Phys. Rev. Materials &#039;&#039;&#039;5&#039;&#039;&#039;, 083803 (2021)&amp;lt;/ref&amp;gt; and &amp;lt;ref&amp;gt;[https://arxiv.org/abs/1705.04245 Theory of exciton-phonon coupling], Gabriel Antonius and Steven G. Louie Phys. Rev. B &#039;&#039;&#039;105&#039;&#039;&#039;, 085111 (2022)&amp;lt;/ref&amp;gt;for a discussion.&lt;br /&gt;
* Non-linear response (SHG, THG, ...) induced by the pump is not implemented yet... if you have a good idea how to do it, please let us know&lt;br /&gt;
&lt;br /&gt;
== Analysis of the results using YamboPy ==&lt;br /&gt;
&#039;&#039;&#039;This part works only with Yamboo 5.3 or the last version available on Github&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Results can be analyzed using YamboPy with the following script:&lt;br /&gt;
&lt;br /&gt;
 from yambopy import *&lt;br /&gt;
 from yambopy.plot  import *&lt;br /&gt;
 &lt;br /&gt;
 NLDB_P_and_P=YamboNLDB(calc=&#039;P_and_P&#039;)&lt;br /&gt;
 NLDB_Pump   =YamboNLDB(calc=&#039;PUMP&#039;)&lt;br /&gt;
  &lt;br /&gt;
 pol_pump   =NLDB_Pump.Polarization[0]&lt;br /&gt;
 pol_p_and_p=NLDB_P_and_P.Polarization[0]&lt;br /&gt;
 &lt;br /&gt;
 time=NLDB_P_and_P.IO_TIME_points&lt;br /&gt;
 t_initial=NLDB_P_and_P.Efield[0][&amp;quot;initial_time&amp;quot;]&lt;br /&gt;
 &lt;br /&gt;
 pol_damped=np.empty_like(pol_pump)&lt;br /&gt;
 &lt;br /&gt;
 for i_d in range(3):&lt;br /&gt;
     pol_damped[i_d,:]=damp_it(pol_p_and_p[i_d,:]-pol_pump[i_d,:],time,t_initial,damp_type=&#039;GAUSSIAN&#039;,damp_factor=0.085/ha2ev)&lt;br /&gt;
 &lt;br /&gt;
 Plot_Pol(time=time, pol=pol_damped, xlim=[0,55], save_file=&#039;polarization.pdf&#039;)&lt;br /&gt;
 &lt;br /&gt;
 Linear_Response(time=time,pol=pol_damped,efield=NLDB_P_and_P.Efield[0],plot=False,plot_file=&#039;delta_eps.pdf&#039;,e_range=[0.0,3.7],n_freqs=500)&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;/div&gt;</summary>
		<author><name>Attacc</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Pump_and_Probe&amp;diff=9258</id>
		<title>Pump and Probe</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Pump_and_Probe&amp;diff=9258"/>
		<updated>2025-12-01T10:24:12Z</updated>

		<summary type="html">&lt;p&gt;Attacc: /* Analysis of the results using YamboPy */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
In this tutorial we will show you how to setup two external fields in &#039;&#039;&#039;yambo_nl&#039;&#039;&#039;, to perform pump and probe simulation. &amp;lt;ref name=&amp;quot;pnp&amp;quot;&amp;gt;[https://arxiv.org/abs/2211.12241 Exciton - Exciton transitions involving strongly bound excitons: an ab-initio approach], D. Sangalli, M. D&#039;Alessandro and C. Attaccalite, Physical Review B &#039;&#039;&#039;107&#039;&#039;&#039; (20), 205203 (2023) &amp;lt;/ref&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
This tutorial is at independent particle level, but the same kind of simulation can be repeated including local field effects, &lt;br /&gt;
quasi-particle correction or electron-hole interaction, see for example the tutorials:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[Correlation effects in the non-linear response]] &amp;lt;br&amp;gt;&lt;br /&gt;
[[Real time Bethe-Salpeter Equation (TDSE)]]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
This tutorial supposes that you are already familiar with real-time simulation with Yambo&amp;lt;ref name=&amp;quot;dberry&amp;quot;&amp;gt;[https://arxiv.org/abs/1609.09639 Non-linear response in extended systems: a real-time approach], C. Attaccalite &amp;lt;/ref&amp;gt;&lt;br /&gt;
if it is not the case please check these tutorials: [[Tutorials#Non_linear_response]]&lt;br /&gt;
&lt;br /&gt;
We start from the h-BN monolayer with an in place lattice constant a=2.5 Å and a box large 33 a.u. in the z-direction.&lt;br /&gt;
Standard DFT input for hBN monolayer for ABINIT or QuantumEspresso can be found here [[Tutorials]]. &amp;lt;br&amp;gt;&lt;br /&gt;
We used  a 9x9x1 k-points grid and 8 bands in the non-self consistent calculation and 40 Ry cutoff for the wave-function.&lt;br /&gt;
&lt;br /&gt;
In our example we choose direction [0,1,0] for the pump and [1,0,0] for the probe. &lt;br /&gt;
We generate the ypp.in to remove symmetries with the command &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;ypp -y&amp;lt;/span&amp;gt; and we modify it as:&lt;br /&gt;
&lt;br /&gt;
 fixsyms                          # [R] Remove symmetries not consistent with an external perturbation&lt;br /&gt;
 % Efield1&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;0.000000 | 1.000000 | 0.000000 |  &amp;lt;/span&amp;gt;      # First external Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 % Efield2&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 1.000000 | 0.000000 | 0.000000 | &amp;lt;/span&amp;gt;       # Additional external Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 BField= 0.000000           T     # [MAG] Magnetic field modulus&lt;br /&gt;
 Bpsi= 0.000000             deg   # [MAG] Magnetic field psi angle [degree]&lt;br /&gt;
 Btheta= 0.000000           deg   # [MAG] Magnetic field theta angle [degree]&lt;br /&gt;
 #RmAllSymm                     # Remove all symmetries &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;RmTimeRev&amp;lt;/span&amp;gt;                     # Remove Time Reversal&lt;br /&gt;
 #RmSpaceInv                    # Remove Spatial Inversion&lt;br /&gt;
&lt;br /&gt;
then we go in the FixSymm directory and run again the setup. &amp;lt;br&amp;gt;&lt;br /&gt;
We will perform three different real-time calculations: &amp;lt;br&amp;gt;&lt;br /&gt;
* the probe field alone; &lt;br /&gt;
* the pump field alone; &lt;br /&gt;
* the pump and probe configuration.&lt;br /&gt;
&lt;br /&gt;
== Probe only ==&lt;br /&gt;
&lt;br /&gt;
We can generate the input file for a generic Pump and Probe calculations with the command: &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;yambo_nl -u p -F yambo.in_probe&amp;lt;/span&amp;gt;:&lt;br /&gt;
 &lt;br /&gt;
 nloptics                         # [R] Non-linear spectroscopy&lt;br /&gt;
 DIP_Threads=0                    # [OPENMP/X] Number of threads for dipoles&lt;br /&gt;
 NL_Threads=0                     # [OPENMP/NL] Number of threads for nl-optics&lt;br /&gt;
 % NLBands&lt;br /&gt;
   &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;  3 |  6 |    &amp;lt;/span&amp;gt;                       # [NL] Bands range&lt;br /&gt;
 %&lt;br /&gt;
 NLverbosity= &amp;quot;high&amp;quot;              # [NL] Verbosity level (low | high)&lt;br /&gt;
 NLtime= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 80.000000&amp;lt;/span&amp;gt;           fs    # [NL] Simulation Time&lt;br /&gt;
 NLintegrator= &amp;quot; &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; CRANKNIC&amp;lt;/span&amp;gt;&amp;quot;           # [NL] Integrator (&amp;quot;EULEREXP/RK2/RK4/RK2EXP/HEUN/INVINT/CRANKNIC&amp;quot;)&lt;br /&gt;
 NLCorrelation= &amp;quot;IPA&amp;quot;             # [NL] Correlation (&amp;quot;IPA/HARTREE/TDDFT/LRC/LRW/JGM/SEX&amp;quot;)&lt;br /&gt;
 NLLrcAlpha= 0.000000             # [NL] Long Range Correction&lt;br /&gt;
 NLDamping= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;0.000000 &amp;lt;/span&amp;gt;       eV    # [NL] Damping (or dephasing)&lt;br /&gt;
 RADLifeTime=-1.000000      fs    # [RT] Radiative life-time (if negative Yambo sets it equal to Phase_LifeTime in NL)&lt;br /&gt;
 #EvalCurrent                   # [NL] Evaluate the current&lt;br /&gt;
 #FrPolPerdic                   # [DIP] Force periodicity of polarization respect to the external field&lt;br /&gt;
 HARRLvcs= 21817            RL    # [HA] Hartree     RL components&lt;br /&gt;
 EXXRLvcs= 21817            RL    # [XX] Exchange    RL components&lt;br /&gt;
 % Field1_Freq&lt;br /&gt;
  0.100000 | 0.100000 |         eV    # [RT Field1] Frequency&lt;br /&gt;
 %&lt;br /&gt;
 Field1_NFreqs= 1                 # [RT Field1] Frequency&lt;br /&gt;
 Field1_Int=  1000.00       kWLm2 # [RT Field1] Intensity&lt;br /&gt;
 Field1_Width= 0.000000     fs    # [RT Field1] Width&lt;br /&gt;
 Field1_kind= &amp;quot; &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; DELTA&amp;lt;/span&amp;gt;&amp;quot;           # [RT Field1] Kind(SIN|COS|RES|ANTIRES|GAUSS|DELTA|QSSIN)&lt;br /&gt;
 Field1_pol= &amp;quot;linear&amp;quot;             # [RT Field1] Pol(linear|circular)&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
   &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 1.000000 | 0.000000 | 0.000000 |  &amp;lt;/span&amp;gt;      # [RT Field1] Versor&lt;br /&gt;
 %&lt;br /&gt;
 Field1_Tstart=  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 5.00000  &amp;lt;/span&amp;gt;  fs    # [RT Field1] Initial Time&lt;br /&gt;
 [......]&lt;br /&gt;
&lt;br /&gt;
In this input we set only the first field that is the probe, we use a DELTA function as field in such a way to probe all the frequencies, and set the starting point of the delta at t=5 fs. &amp;lt;br&amp;gt;Run this job in a separate folder with the command  &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;yambo_nl -F yambo.in_probe -J PROBE&amp;lt;/span&amp;gt;. Then we can analyze the spectra with &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;ypp -u -J PROBE &amp;lt;/span&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 nonlinear                        # [R] Non-linear response analysis&lt;br /&gt;
 Xorder= 1                        # Max order of the response/exc functions&lt;br /&gt;
 % TimeRange&lt;br /&gt;
 -1.000000 |-1.000000 |         fs    # Time-window where processing is done&lt;br /&gt;
 %&lt;br /&gt;
 ETStpsRt= 200                    # Total Energy steps&lt;br /&gt;
 % EnRngeRt&lt;br /&gt;
   0.00000 | 20.00000 |         eV    # Energy range&lt;br /&gt;
 %&lt;br /&gt;
 DampMode= &amp;quot;&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;LORENTZIAN&amp;lt;/span&amp;gt;&amp;quot;           # Damping type ( NONE | LORENTZIAN | GAUSSIAN )&lt;br /&gt;
 DampFactor= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;0.100000&amp;lt;/span&amp;gt;       eV    # Damping parameter&lt;br /&gt;
 PumpPATH= &amp;quot;none&amp;quot;           # Path of the simulation with the Pump only&lt;br /&gt;
&lt;br /&gt;
and get the dielectric response. Notice that we introduce a Lorentzian broadening the post-processing. &amp;lt;br&amp;gt;&lt;br /&gt;
Hereafter we plot the damped polarization along the y-direction and the corresponding dielectric constant:&lt;br /&gt;
&lt;br /&gt;
[[File:Eps probe.png|800px|center | Probe only]]&lt;br /&gt;
&lt;br /&gt;
the arrow indicates the position where we will put the Pump in the next simulation.&lt;br /&gt;
&lt;br /&gt;
==Pump only==&lt;br /&gt;
&lt;br /&gt;
Now we run a simulation with the pump field only. We generate the input in the same way &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;yambo_nl -u p -F yambo.in_pump&amp;lt;/span&amp;gt;. &amp;lt;br&amp;gt;&lt;br /&gt;
These result will be our reference field in the final analysis. Here the input file for the pump:&lt;br /&gt;
 &lt;br /&gt;
 nloptics                         # [R] Non-linear spectroscopy&lt;br /&gt;
 DIP_Threads=0                    # [OPENMP/X] Number of threads for dipoles&lt;br /&gt;
 NL_Threads=0                     # [OPENMP/NL] Number of threads for nl-optics&lt;br /&gt;
 % NLBands&lt;br /&gt;
    &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;3 |  6 |&amp;lt;/span&amp;gt;                           # [NL] Bands range&lt;br /&gt;
 %&lt;br /&gt;
 NLverbosity= &amp;quot;high&amp;quot;              # [NL] Verbosity level (low | high)&lt;br /&gt;
 NLtime=  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;150.0000&amp;lt;/span&amp;gt;           fs    # [NL] Simulation Time&lt;br /&gt;
 NLintegrator= &amp;quot;CRANKNIC&amp;quot;         # [NL] Integrator (&amp;quot;EULEREXP/RK2/RK4/RK2EXP/HEUN/INVINT/CRANKNIC&amp;quot;)&lt;br /&gt;
 NLCorrelation= &amp;quot;IPA&amp;quot;             # [NL] Correlation (&amp;quot;IPA/HARTREE/TDDFT/LRC/LRW/JGM/SEX&amp;quot;)&lt;br /&gt;
 NLLrcAlpha= 0.000000             # [NL] Long Range Correction&lt;br /&gt;
 NLDamping=  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;0.000000&amp;lt;/span&amp;gt;        eV    # [NL] Damping (or dephasing)&lt;br /&gt;
 RADLifeTime=-1.000000      fs    # [RT] Radiative life-time (if negative Yambo sets it equal to Phase_LifeTime in NL)&lt;br /&gt;
 #EvalCurrent                   # [NL] Evaluate the current&lt;br /&gt;
 #FrPolPerdic                   # [DIP] Force periodicity of polarization respect to the external field&lt;br /&gt;
 HARRLvcs= 21817            RL    # [HA] Hartree     RL components&lt;br /&gt;
 EXXRLvcs= 21817            RL    # [XX] Exchange    RL components&lt;br /&gt;
 % Field1_Freq&lt;br /&gt;
  0.100000 | 0.100000 |         eV    # [RT Field1] Frequency&lt;br /&gt;
 %&lt;br /&gt;
 Field1_NFreqs= 1                 # [RT Field1] Frequency&lt;br /&gt;
 Field1_Int=  10000.00       kWLm2 # [RT Field1] Intensity&lt;br /&gt;
 Field1_Width= 0.000000     fs    # [RT Field1] Width&lt;br /&gt;
 Field1_kind= &amp;quot;SOFTSIN&amp;quot;           # [RT Field1] Kind(SIN|COS|RES|ANTIRES|GAUSS|DELTA|QSSIN)&lt;br /&gt;
 Field1_pol= &amp;quot;linear&amp;quot;             # [RT Field1] Pol(linear|circular)&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
  0.000000 | 0.000000 | 0.000000 |        # [RT Field1] Versor&lt;br /&gt;
 %&lt;br /&gt;
 Field1_Tstart= 0.010000    fs    # [RT Field1] Initial Time &lt;br /&gt;
 % Field2_Freq&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 5.42 | 5.42 &amp;lt;/span&amp;gt;|         eV    # [RT Field2] Frequency&lt;br /&gt;
 %&lt;br /&gt;
 Field2_NFreqs= 1                 # [RT Field2] Frequency&lt;br /&gt;
 Field2_Int=  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;1000.00 &amp;lt;/span&amp;gt;      kWLm2 # [RT Field2] Intensity&lt;br /&gt;
 Field2_Width= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;10.00000&amp;lt;/span&amp;gt;     fs    # [RT Field2] Width&lt;br /&gt;
 Field2_kind= &amp;quot;&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;QSSIN&amp;lt;/span&amp;gt;&amp;quot;             # [RT Field2] Kind(SIN|COS|RES|ANTIRES|GAUSS|DELTA|QSSIN)&lt;br /&gt;
 Field2_pol= &amp;quot;linear&amp;quot;             # [RT Field2] Pol(linear|circular)&lt;br /&gt;
 % Field2_Dir&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 0.000000 | 1.000000 | 0.000000 |   &amp;lt;/span&amp;gt;     # [RT Field2] Versor&lt;br /&gt;
 %&lt;br /&gt;
 Field2_Tstart= 0.010000    fs    # [RT Field2] Initial Time&lt;br /&gt;
 [...]&lt;br /&gt;
In this simulation we used as Pump field QSSIN that is sinus with a Guassian envelope[https://demonstrations.wolfram.com/SineGaussianSignals/ sine-Gaussian wave]. For a list of all possible field in Yambo see the file  &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt; src/modules/mod_fields.F&amp;lt;/span&amp;gt;. We centred the field frequency at 5.42 eV that is the energy of the highest peak in the previous figure, see arrow there. &lt;br /&gt;
Run the simulation with the command &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;yambo_nl -F yambo.in_pump -J PUMP &amp;lt;/span&amp;gt;.&lt;br /&gt;
The pump field, column 6th of the file &amp;lt;code&amp;gt;o-PUMP.external_potential_F1&amp;lt;/code&amp;gt;, is shown in the figure below:&lt;br /&gt;
&lt;br /&gt;
[[File:Pump only.png|800px|center|Pump field]]&lt;br /&gt;
&lt;br /&gt;
== Pump and probe==&lt;br /&gt;
&lt;br /&gt;
Now we copy the pump in file in a new file &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt; cp yambo.in_pump yambo.in_pump_and_probe&amp;lt;/span&amp;gt; and turn on  the probe field:&lt;br /&gt;
&lt;br /&gt;
 nloptics                         # [R] Non-linear spectroscopy&lt;br /&gt;
 DIP_Threads=0                    # [OPENMP/X] Number of threads for dipoles&lt;br /&gt;
 NL_Threads=0                     # [OPENMP/NL] Number of threads for nl-optics&lt;br /&gt;
 % NLBands&lt;br /&gt;
   3 |  6 |                           # [NL] Bands range&lt;br /&gt;
 %&lt;br /&gt;
 NLverbosity= &amp;quot;high&amp;quot;              # [NL] Verbosity level (low | high)&lt;br /&gt;
 NLtime=  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;150.0000 &amp;lt;/span&amp;gt;          fs    # [NL] Simulation Time&lt;br /&gt;
 NLintegrator= &amp;quot;CRANKNIC&amp;quot;         # [NL] Integrator (&amp;quot;EULEREXP/RK2/RK4/RK2EXP/HEUN/INVINT/CRANKNIC&amp;quot;)&lt;br /&gt;
 NLCorrelation= &amp;quot;IPA&amp;quot;             # [NL] Correlation (&amp;quot;IPA/HARTREE/TDDFT/LRC/LRW/JGM/SEX&amp;quot;)&lt;br /&gt;
 NLLrcAlpha= 0.000000             # [NL] Long Range Correction&lt;br /&gt;
 NLDamping=  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;0.000000 &amp;lt;/span&amp;gt;       eV    # [NL] Damping (or dephasing)&lt;br /&gt;
 RADLifeTime=-1.000000      fs    # [RT] Radiative life-time (if negative Yambo sets it equal to Phase_LifeTime in NL)&lt;br /&gt;
 #EvalCurrent                   # [NL] Evaluate the current&lt;br /&gt;
 #FrPolPerdic                   # [DIP] Force periodicity of polarization respect to the external field&lt;br /&gt;
 HARRLvcs= 21817            RL    # [HA] Hartree     RL components&lt;br /&gt;
 EXXRLvcs= 21817            RL    # [XX] Exchange    RL components&lt;br /&gt;
 % Field1_Freq&lt;br /&gt;
  0.100000 | 0.100000 |         eV    # [RT Field1] Frequency&lt;br /&gt;
 %&lt;br /&gt;
 Field1_NFreqs= 1                 # [RT Field1] Frequency&lt;br /&gt;
 Field1_Int=  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;1.00  &amp;lt;/span&amp;gt;     kWLm2 # [RT Field1] Intensity&lt;br /&gt;
 Field1_Width= 0.000000     fs    # [RT Field1] Width&lt;br /&gt;
 Field1_kind= &amp;quot;&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;DELTA&amp;lt;/span&amp;gt;&amp;quot;           # [RT Field1] Kind(SIN|COS|RES|ANTIRES|GAUSS|DELTA|QSSIN)&lt;br /&gt;
 Field1_pol= &amp;quot;linear&amp;quot;             # [RT Field1] Pol(linear|circular)&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 1.000000 | 0.000000 | 0.000000 | &amp;lt;/span&amp;gt;       # [RT Field1] Versor&lt;br /&gt;
 %&lt;br /&gt;
 Field1_Tstart= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;90.0000  &amp;lt;/span&amp;gt;  fs    # [RT Field1] Initial Time&lt;br /&gt;
 % Field2_Freq&lt;br /&gt;
   &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;5.42 | 5.42 |  &amp;lt;/span&amp;gt;       eV    # [RT Field2] Frequency&lt;br /&gt;
 %&lt;br /&gt;
 Field2_NFreqs= 1                 # [RT Field2] Frequency&lt;br /&gt;
 Field2_Int=  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;1000.00&amp;lt;/span&amp;gt;       kWLm2 # [RT Field2] Intensity&lt;br /&gt;
 Field2_Width=  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;10.00000  &amp;lt;/span&amp;gt;   fs    # [RT Field2] Width&lt;br /&gt;
 Field2_kind= &amp;quot;&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;QSSIN&amp;lt;/span&amp;gt;&amp;quot;             # [RT Field2] Kind(SIN|COS|RES|ANTIRES|GAUSS|DELTA|QSSIN)&lt;br /&gt;
 Field2_pol= &amp;quot;linear&amp;quot;             # [RT Field2] Pol(linear|circular)&lt;br /&gt;
 % Field2_Dir&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;0.000000 | 1.000000 | 0.000000 |&amp;lt;/span&amp;gt;        # [RT Field2] Versor&lt;br /&gt;
 %&lt;br /&gt;
 Field2_Tstart= 0.010000    fs    # [RT Field2] Initial Time&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Please note:&#039;&#039;&#039;  by convention in Yambo we consider the first field the probe and the second the pump. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
you run the simulation with the command &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;yambo_nl -F yambo.in_pump_and_probe -J PUMP_AND_PROBE &amp;lt;/span&amp;gt; and then we analyze the result using ypp with the command: &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;ypp_nl -u -J PUMP_AND_PROBE &amp;lt;/span&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 nonlinear                        # [R] Non-linear response analysis &lt;br /&gt;
 Xorder= 1                        # Max order of the response/exc functions&lt;br /&gt;
 % TimeRange&lt;br /&gt;
 -1.000000 |-1.000000 |         fs    # Time-window where processing is done&lt;br /&gt;
 %&lt;br /&gt;
 ETStpsRt= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;500 &amp;lt;/span&amp;gt;                   # Total Energy steps&lt;br /&gt;
 % EnRngeRt&lt;br /&gt;
   &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;0.00000 | 3.9000 &amp;lt;/span&amp;gt;|         eV    # Energy range&lt;br /&gt;
 %&lt;br /&gt;
 DampMode= &amp;quot;&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;GAUSSIAN&amp;lt;/span&amp;gt;&amp;quot;                 # Damping type ( NONE | LORENTZIAN | GAUSSIAN )&lt;br /&gt;
 DampFactor= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;0.085000  &amp;lt;/span&amp;gt;     eV    # Damping parameter&lt;br /&gt;
 PumpPATH= &amp;quot;&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;./PUMP/&amp;lt;/span&amp;gt;&amp;quot;                 # Path of the simulation with the Pump only&lt;br /&gt;
&lt;br /&gt;
Notice that in this case we are interested in the spectra below the 4 eV, that is was zero without the presence of the pump. We put in the input the pump path in such way to calculate polarization of the pump&amp;amp;probe minus the one of generate by the pump only &amp;lt;math&amp;gt;\Delta P(t) = P_{PnP}(t) - P_{pump}(t)&amp;lt;/math&amp;gt;. Then we analyze the &amp;lt;math&amp;gt;\Delta P(t)&amp;lt;/math&amp;gt; and get the new spectra:&lt;br /&gt;
&lt;br /&gt;
[[File:P and p spectrum.png|800px | center|Pump and probe spectrum]]&lt;br /&gt;
&lt;br /&gt;
The peak that you see in this spectrum, that were not present in when the pump was zero, correspond to the transition between the different excited states. The pump field populates the state at 5.42 eV and then the probe excites electrons from this state to higher states. The energy difference between the higher excited states and the peak at 5.42 define the position of the peaks in the pump and probe spectrum, while their intensity is dictated by the dipole matrix elements between the different excited states, see Ref. &amp;lt;ref name=&amp;quot;pnp&amp;quot;&amp;gt;&amp;lt;/ref&amp;gt;.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Additional comments on pump and probe calculations &#039;&#039;&#039;&lt;br /&gt;
* We used a Gaussian damping factor, this choice is motivated by various tests we have done, and it seems to us that in pump and probe this broadening gives better results.&amp;lt;br&amp;gt;&lt;br /&gt;
* If you plot all spectrum you will notice that the &amp;quot;equilibrium part&amp;quot; is much stronger than the one induced by the pump, this is normal because only a small fraction of electron are promoted in the excited state by the pump.&lt;br /&gt;
* All previous simulation can be run also in presence of excitons, see  Ref. &amp;lt;ref name=&amp;quot;pnp&amp;quot;&amp;gt;&amp;lt;/ref&amp;gt; and group theory can be used to predict dark/bright transition in the pump and probe spectroscopy.&amp;lt;ref&amp;gt;[https://link.springer.com/book/10.1007/978-3-540-32899-5  Group Theory, Application to the Physics of Condensed Matter],   Mildred S. S. Dresselhaus, Gene Dresselhaus, Ado Jorio, Springer Editor&amp;lt;/ref&amp;gt;&lt;br /&gt;
* In principle is it possible to include damping and radiative life-time in the simulation to study retardation effect between the pump and probe. This  approach  exact in the independent particle case, but introduces an error when correlation effects are present, see Refs.&amp;lt;ref&amp;gt;[https://arxiv.org/abs/2106.03592 Excitons and carriers in transient absorption and time-resolved ARPES spectroscopy: an abinitio approach], D. Sangalli, Phys. Rev. Materials &#039;&#039;&#039;5&#039;&#039;&#039;, 083803 (2021)&amp;lt;/ref&amp;gt; and &amp;lt;ref&amp;gt;[https://arxiv.org/abs/1705.04245 Theory of exciton-phonon coupling], Gabriel Antonius and Steven G. Louie Phys. Rev. B &#039;&#039;&#039;105&#039;&#039;&#039;, 085111 (2022)&amp;lt;/ref&amp;gt;for a discussion.&lt;br /&gt;
* Non-linear response (SHG, THG, ...) induced by the pump is not implemented yet... if you have a good idea how to do it, please let us know&lt;br /&gt;
&lt;br /&gt;
== Analysis of the results using YamboPy ==&lt;br /&gt;
&#039;&#039;&#039;This part works only with Lumen 2.0 or the last version available on GitLab:&#039;&#039;&#039; [https://gitlab.com/lumen-code https://gitlab.com/lumen-code]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Results can be analyzed using YamboPy with the following script:&lt;br /&gt;
&lt;br /&gt;
 from yambopy import *&lt;br /&gt;
 from yambopy.plot  import *&lt;br /&gt;
 &lt;br /&gt;
 NLDB_P_and_P=YamboNLDB(calc=&#039;P_and_P&#039;)&lt;br /&gt;
 NLDB_Pump   =YamboNLDB(calc=&#039;PUMP&#039;)&lt;br /&gt;
  &lt;br /&gt;
 pol_pump   =NLDB_Pump.Polarization[0]&lt;br /&gt;
 pol_p_and_p=NLDB_P_and_P.Polarization[0]&lt;br /&gt;
 &lt;br /&gt;
 time=NLDB_P_and_P.IO_TIME_points&lt;br /&gt;
 t_initial=NLDB_P_and_P.Efield[0][&amp;quot;initial_time&amp;quot;]&lt;br /&gt;
 &lt;br /&gt;
 pol_damped=np.empty_like(pol_pump)&lt;br /&gt;
 &lt;br /&gt;
 for i_d in range(3):&lt;br /&gt;
     pol_damped[i_d,:]=damp_it(pol_p_and_p[i_d,:]-pol_pump[i_d,:],time,t_initial,damp_type=&#039;GAUSSIAN&#039;,damp_factor=0.085/ha2ev)&lt;br /&gt;
 &lt;br /&gt;
 Plot_Pol(time=time, pol=pol_damped, xlim=[0,55], save_file=&#039;polarization.pdf&#039;)&lt;br /&gt;
 &lt;br /&gt;
 Linear_Response(time=time,pol=pol_damped,efield=NLDB_P_and_P.Efield[0],plot=False,plot_file=&#039;delta_eps.pdf&#039;,e_range=[0.0,3.7],n_freqs=500)&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;/div&gt;</summary>
		<author><name>Attacc</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Pump_and_Probe&amp;diff=9257</id>
		<title>Pump and Probe</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Pump_and_Probe&amp;diff=9257"/>
		<updated>2025-12-01T10:23:58Z</updated>

		<summary type="html">&lt;p&gt;Attacc: /* Analysis of the results using YamboPy */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
In this tutorial we will show you how to setup two external fields in &#039;&#039;&#039;yambo_nl&#039;&#039;&#039;, to perform pump and probe simulation. &amp;lt;ref name=&amp;quot;pnp&amp;quot;&amp;gt;[https://arxiv.org/abs/2211.12241 Exciton - Exciton transitions involving strongly bound excitons: an ab-initio approach], D. Sangalli, M. D&#039;Alessandro and C. Attaccalite, Physical Review B &#039;&#039;&#039;107&#039;&#039;&#039; (20), 205203 (2023) &amp;lt;/ref&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
This tutorial is at independent particle level, but the same kind of simulation can be repeated including local field effects, &lt;br /&gt;
quasi-particle correction or electron-hole interaction, see for example the tutorials:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
[[Correlation effects in the non-linear response]] &amp;lt;br&amp;gt;&lt;br /&gt;
[[Real time Bethe-Salpeter Equation (TDSE)]]&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
This tutorial supposes that you are already familiar with real-time simulation with Yambo&amp;lt;ref name=&amp;quot;dberry&amp;quot;&amp;gt;[https://arxiv.org/abs/1609.09639 Non-linear response in extended systems: a real-time approach], C. Attaccalite &amp;lt;/ref&amp;gt;&lt;br /&gt;
if it is not the case please check these tutorials: [[Tutorials#Non_linear_response]]&lt;br /&gt;
&lt;br /&gt;
We start from the h-BN monolayer with an in place lattice constant a=2.5 Å and a box large 33 a.u. in the z-direction.&lt;br /&gt;
Standard DFT input for hBN monolayer for ABINIT or QuantumEspresso can be found here [[Tutorials]]. &amp;lt;br&amp;gt;&lt;br /&gt;
We used  a 9x9x1 k-points grid and 8 bands in the non-self consistent calculation and 40 Ry cutoff for the wave-function.&lt;br /&gt;
&lt;br /&gt;
In our example we choose direction [0,1,0] for the pump and [1,0,0] for the probe. &lt;br /&gt;
We generate the ypp.in to remove symmetries with the command &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;ypp -y&amp;lt;/span&amp;gt; and we modify it as:&lt;br /&gt;
&lt;br /&gt;
 fixsyms                          # [R] Remove symmetries not consistent with an external perturbation&lt;br /&gt;
 % Efield1&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;0.000000 | 1.000000 | 0.000000 |  &amp;lt;/span&amp;gt;      # First external Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 % Efield2&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 1.000000 | 0.000000 | 0.000000 | &amp;lt;/span&amp;gt;       # Additional external Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 BField= 0.000000           T     # [MAG] Magnetic field modulus&lt;br /&gt;
 Bpsi= 0.000000             deg   # [MAG] Magnetic field psi angle [degree]&lt;br /&gt;
 Btheta= 0.000000           deg   # [MAG] Magnetic field theta angle [degree]&lt;br /&gt;
 #RmAllSymm                     # Remove all symmetries &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;RmTimeRev&amp;lt;/span&amp;gt;                     # Remove Time Reversal&lt;br /&gt;
 #RmSpaceInv                    # Remove Spatial Inversion&lt;br /&gt;
&lt;br /&gt;
then we go in the FixSymm directory and run again the setup. &amp;lt;br&amp;gt;&lt;br /&gt;
We will perform three different real-time calculations: &amp;lt;br&amp;gt;&lt;br /&gt;
* the probe field alone; &lt;br /&gt;
* the pump field alone; &lt;br /&gt;
* the pump and probe configuration.&lt;br /&gt;
&lt;br /&gt;
== Probe only ==&lt;br /&gt;
&lt;br /&gt;
We can generate the input file for a generic Pump and Probe calculations with the command: &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;yambo_nl -u p -F yambo.in_probe&amp;lt;/span&amp;gt;:&lt;br /&gt;
 &lt;br /&gt;
 nloptics                         # [R] Non-linear spectroscopy&lt;br /&gt;
 DIP_Threads=0                    # [OPENMP/X] Number of threads for dipoles&lt;br /&gt;
 NL_Threads=0                     # [OPENMP/NL] Number of threads for nl-optics&lt;br /&gt;
 % NLBands&lt;br /&gt;
   &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;  3 |  6 |    &amp;lt;/span&amp;gt;                       # [NL] Bands range&lt;br /&gt;
 %&lt;br /&gt;
 NLverbosity= &amp;quot;high&amp;quot;              # [NL] Verbosity level (low | high)&lt;br /&gt;
 NLtime= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 80.000000&amp;lt;/span&amp;gt;           fs    # [NL] Simulation Time&lt;br /&gt;
 NLintegrator= &amp;quot; &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; CRANKNIC&amp;lt;/span&amp;gt;&amp;quot;           # [NL] Integrator (&amp;quot;EULEREXP/RK2/RK4/RK2EXP/HEUN/INVINT/CRANKNIC&amp;quot;)&lt;br /&gt;
 NLCorrelation= &amp;quot;IPA&amp;quot;             # [NL] Correlation (&amp;quot;IPA/HARTREE/TDDFT/LRC/LRW/JGM/SEX&amp;quot;)&lt;br /&gt;
 NLLrcAlpha= 0.000000             # [NL] Long Range Correction&lt;br /&gt;
 NLDamping= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;0.000000 &amp;lt;/span&amp;gt;       eV    # [NL] Damping (or dephasing)&lt;br /&gt;
 RADLifeTime=-1.000000      fs    # [RT] Radiative life-time (if negative Yambo sets it equal to Phase_LifeTime in NL)&lt;br /&gt;
 #EvalCurrent                   # [NL] Evaluate the current&lt;br /&gt;
 #FrPolPerdic                   # [DIP] Force periodicity of polarization respect to the external field&lt;br /&gt;
 HARRLvcs= 21817            RL    # [HA] Hartree     RL components&lt;br /&gt;
 EXXRLvcs= 21817            RL    # [XX] Exchange    RL components&lt;br /&gt;
 % Field1_Freq&lt;br /&gt;
  0.100000 | 0.100000 |         eV    # [RT Field1] Frequency&lt;br /&gt;
 %&lt;br /&gt;
 Field1_NFreqs= 1                 # [RT Field1] Frequency&lt;br /&gt;
 Field1_Int=  1000.00       kWLm2 # [RT Field1] Intensity&lt;br /&gt;
 Field1_Width= 0.000000     fs    # [RT Field1] Width&lt;br /&gt;
 Field1_kind= &amp;quot; &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; DELTA&amp;lt;/span&amp;gt;&amp;quot;           # [RT Field1] Kind(SIN|COS|RES|ANTIRES|GAUSS|DELTA|QSSIN)&lt;br /&gt;
 Field1_pol= &amp;quot;linear&amp;quot;             # [RT Field1] Pol(linear|circular)&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
   &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 1.000000 | 0.000000 | 0.000000 |  &amp;lt;/span&amp;gt;      # [RT Field1] Versor&lt;br /&gt;
 %&lt;br /&gt;
 Field1_Tstart=  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 5.00000  &amp;lt;/span&amp;gt;  fs    # [RT Field1] Initial Time&lt;br /&gt;
 [......]&lt;br /&gt;
&lt;br /&gt;
In this input we set only the first field that is the probe, we use a DELTA function as field in such a way to probe all the frequencies, and set the starting point of the delta at t=5 fs. &amp;lt;br&amp;gt;Run this job in a separate folder with the command  &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;yambo_nl -F yambo.in_probe -J PROBE&amp;lt;/span&amp;gt;. Then we can analyze the spectra with &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;ypp -u -J PROBE &amp;lt;/span&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 nonlinear                        # [R] Non-linear response analysis&lt;br /&gt;
 Xorder= 1                        # Max order of the response/exc functions&lt;br /&gt;
 % TimeRange&lt;br /&gt;
 -1.000000 |-1.000000 |         fs    # Time-window where processing is done&lt;br /&gt;
 %&lt;br /&gt;
 ETStpsRt= 200                    # Total Energy steps&lt;br /&gt;
 % EnRngeRt&lt;br /&gt;
   0.00000 | 20.00000 |         eV    # Energy range&lt;br /&gt;
 %&lt;br /&gt;
 DampMode= &amp;quot;&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;LORENTZIAN&amp;lt;/span&amp;gt;&amp;quot;           # Damping type ( NONE | LORENTZIAN | GAUSSIAN )&lt;br /&gt;
 DampFactor= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;0.100000&amp;lt;/span&amp;gt;       eV    # Damping parameter&lt;br /&gt;
 PumpPATH= &amp;quot;none&amp;quot;           # Path of the simulation with the Pump only&lt;br /&gt;
&lt;br /&gt;
and get the dielectric response. Notice that we introduce a Lorentzian broadening the post-processing. &amp;lt;br&amp;gt;&lt;br /&gt;
Hereafter we plot the damped polarization along the y-direction and the corresponding dielectric constant:&lt;br /&gt;
&lt;br /&gt;
[[File:Eps probe.png|800px|center | Probe only]]&lt;br /&gt;
&lt;br /&gt;
the arrow indicates the position where we will put the Pump in the next simulation.&lt;br /&gt;
&lt;br /&gt;
==Pump only==&lt;br /&gt;
&lt;br /&gt;
Now we run a simulation with the pump field only. We generate the input in the same way &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;yambo_nl -u p -F yambo.in_pump&amp;lt;/span&amp;gt;. &amp;lt;br&amp;gt;&lt;br /&gt;
These result will be our reference field in the final analysis. Here the input file for the pump:&lt;br /&gt;
 &lt;br /&gt;
 nloptics                         # [R] Non-linear spectroscopy&lt;br /&gt;
 DIP_Threads=0                    # [OPENMP/X] Number of threads for dipoles&lt;br /&gt;
 NL_Threads=0                     # [OPENMP/NL] Number of threads for nl-optics&lt;br /&gt;
 % NLBands&lt;br /&gt;
    &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;3 |  6 |&amp;lt;/span&amp;gt;                           # [NL] Bands range&lt;br /&gt;
 %&lt;br /&gt;
 NLverbosity= &amp;quot;high&amp;quot;              # [NL] Verbosity level (low | high)&lt;br /&gt;
 NLtime=  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;150.0000&amp;lt;/span&amp;gt;           fs    # [NL] Simulation Time&lt;br /&gt;
 NLintegrator= &amp;quot;CRANKNIC&amp;quot;         # [NL] Integrator (&amp;quot;EULEREXP/RK2/RK4/RK2EXP/HEUN/INVINT/CRANKNIC&amp;quot;)&lt;br /&gt;
 NLCorrelation= &amp;quot;IPA&amp;quot;             # [NL] Correlation (&amp;quot;IPA/HARTREE/TDDFT/LRC/LRW/JGM/SEX&amp;quot;)&lt;br /&gt;
 NLLrcAlpha= 0.000000             # [NL] Long Range Correction&lt;br /&gt;
 NLDamping=  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;0.000000&amp;lt;/span&amp;gt;        eV    # [NL] Damping (or dephasing)&lt;br /&gt;
 RADLifeTime=-1.000000      fs    # [RT] Radiative life-time (if negative Yambo sets it equal to Phase_LifeTime in NL)&lt;br /&gt;
 #EvalCurrent                   # [NL] Evaluate the current&lt;br /&gt;
 #FrPolPerdic                   # [DIP] Force periodicity of polarization respect to the external field&lt;br /&gt;
 HARRLvcs= 21817            RL    # [HA] Hartree     RL components&lt;br /&gt;
 EXXRLvcs= 21817            RL    # [XX] Exchange    RL components&lt;br /&gt;
 % Field1_Freq&lt;br /&gt;
  0.100000 | 0.100000 |         eV    # [RT Field1] Frequency&lt;br /&gt;
 %&lt;br /&gt;
 Field1_NFreqs= 1                 # [RT Field1] Frequency&lt;br /&gt;
 Field1_Int=  10000.00       kWLm2 # [RT Field1] Intensity&lt;br /&gt;
 Field1_Width= 0.000000     fs    # [RT Field1] Width&lt;br /&gt;
 Field1_kind= &amp;quot;SOFTSIN&amp;quot;           # [RT Field1] Kind(SIN|COS|RES|ANTIRES|GAUSS|DELTA|QSSIN)&lt;br /&gt;
 Field1_pol= &amp;quot;linear&amp;quot;             # [RT Field1] Pol(linear|circular)&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
  0.000000 | 0.000000 | 0.000000 |        # [RT Field1] Versor&lt;br /&gt;
 %&lt;br /&gt;
 Field1_Tstart= 0.010000    fs    # [RT Field1] Initial Time &lt;br /&gt;
 % Field2_Freq&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 5.42 | 5.42 &amp;lt;/span&amp;gt;|         eV    # [RT Field2] Frequency&lt;br /&gt;
 %&lt;br /&gt;
 Field2_NFreqs= 1                 # [RT Field2] Frequency&lt;br /&gt;
 Field2_Int=  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;1000.00 &amp;lt;/span&amp;gt;      kWLm2 # [RT Field2] Intensity&lt;br /&gt;
 Field2_Width= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;10.00000&amp;lt;/span&amp;gt;     fs    # [RT Field2] Width&lt;br /&gt;
 Field2_kind= &amp;quot;&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;QSSIN&amp;lt;/span&amp;gt;&amp;quot;             # [RT Field2] Kind(SIN|COS|RES|ANTIRES|GAUSS|DELTA|QSSIN)&lt;br /&gt;
 Field2_pol= &amp;quot;linear&amp;quot;             # [RT Field2] Pol(linear|circular)&lt;br /&gt;
 % Field2_Dir&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 0.000000 | 1.000000 | 0.000000 |   &amp;lt;/span&amp;gt;     # [RT Field2] Versor&lt;br /&gt;
 %&lt;br /&gt;
 Field2_Tstart= 0.010000    fs    # [RT Field2] Initial Time&lt;br /&gt;
 [...]&lt;br /&gt;
In this simulation we used as Pump field QSSIN that is sinus with a Guassian envelope[https://demonstrations.wolfram.com/SineGaussianSignals/ sine-Gaussian wave]. For a list of all possible field in Yambo see the file  &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt; src/modules/mod_fields.F&amp;lt;/span&amp;gt;. We centred the field frequency at 5.42 eV that is the energy of the highest peak in the previous figure, see arrow there. &lt;br /&gt;
Run the simulation with the command &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;yambo_nl -F yambo.in_pump -J PUMP &amp;lt;/span&amp;gt;.&lt;br /&gt;
The pump field, column 6th of the file &amp;lt;code&amp;gt;o-PUMP.external_potential_F1&amp;lt;/code&amp;gt;, is shown in the figure below:&lt;br /&gt;
&lt;br /&gt;
[[File:Pump only.png|800px|center|Pump field]]&lt;br /&gt;
&lt;br /&gt;
== Pump and probe==&lt;br /&gt;
&lt;br /&gt;
Now we copy the pump in file in a new file &amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt; cp yambo.in_pump yambo.in_pump_and_probe&amp;lt;/span&amp;gt; and turn on  the probe field:&lt;br /&gt;
&lt;br /&gt;
 nloptics                         # [R] Non-linear spectroscopy&lt;br /&gt;
 DIP_Threads=0                    # [OPENMP/X] Number of threads for dipoles&lt;br /&gt;
 NL_Threads=0                     # [OPENMP/NL] Number of threads for nl-optics&lt;br /&gt;
 % NLBands&lt;br /&gt;
   3 |  6 |                           # [NL] Bands range&lt;br /&gt;
 %&lt;br /&gt;
 NLverbosity= &amp;quot;high&amp;quot;              # [NL] Verbosity level (low | high)&lt;br /&gt;
 NLtime=  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;150.0000 &amp;lt;/span&amp;gt;          fs    # [NL] Simulation Time&lt;br /&gt;
 NLintegrator= &amp;quot;CRANKNIC&amp;quot;         # [NL] Integrator (&amp;quot;EULEREXP/RK2/RK4/RK2EXP/HEUN/INVINT/CRANKNIC&amp;quot;)&lt;br /&gt;
 NLCorrelation= &amp;quot;IPA&amp;quot;             # [NL] Correlation (&amp;quot;IPA/HARTREE/TDDFT/LRC/LRW/JGM/SEX&amp;quot;)&lt;br /&gt;
 NLLrcAlpha= 0.000000             # [NL] Long Range Correction&lt;br /&gt;
 NLDamping=  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;0.000000 &amp;lt;/span&amp;gt;       eV    # [NL] Damping (or dephasing)&lt;br /&gt;
 RADLifeTime=-1.000000      fs    # [RT] Radiative life-time (if negative Yambo sets it equal to Phase_LifeTime in NL)&lt;br /&gt;
 #EvalCurrent                   # [NL] Evaluate the current&lt;br /&gt;
 #FrPolPerdic                   # [DIP] Force periodicity of polarization respect to the external field&lt;br /&gt;
 HARRLvcs= 21817            RL    # [HA] Hartree     RL components&lt;br /&gt;
 EXXRLvcs= 21817            RL    # [XX] Exchange    RL components&lt;br /&gt;
 % Field1_Freq&lt;br /&gt;
  0.100000 | 0.100000 |         eV    # [RT Field1] Frequency&lt;br /&gt;
 %&lt;br /&gt;
 Field1_NFreqs= 1                 # [RT Field1] Frequency&lt;br /&gt;
 Field1_Int=  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;1.00  &amp;lt;/span&amp;gt;     kWLm2 # [RT Field1] Intensity&lt;br /&gt;
 Field1_Width= 0.000000     fs    # [RT Field1] Width&lt;br /&gt;
 Field1_kind= &amp;quot;&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;DELTA&amp;lt;/span&amp;gt;&amp;quot;           # [RT Field1] Kind(SIN|COS|RES|ANTIRES|GAUSS|DELTA|QSSIN)&lt;br /&gt;
 Field1_pol= &amp;quot;linear&amp;quot;             # [RT Field1] Pol(linear|circular)&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 1.000000 | 0.000000 | 0.000000 | &amp;lt;/span&amp;gt;       # [RT Field1] Versor&lt;br /&gt;
 %&lt;br /&gt;
 Field1_Tstart= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;90.0000  &amp;lt;/span&amp;gt;  fs    # [RT Field1] Initial Time&lt;br /&gt;
 % Field2_Freq&lt;br /&gt;
   &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;5.42 | 5.42 |  &amp;lt;/span&amp;gt;       eV    # [RT Field2] Frequency&lt;br /&gt;
 %&lt;br /&gt;
 Field2_NFreqs= 1                 # [RT Field2] Frequency&lt;br /&gt;
 Field2_Int=  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;1000.00&amp;lt;/span&amp;gt;       kWLm2 # [RT Field2] Intensity&lt;br /&gt;
 Field2_Width=  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;10.00000  &amp;lt;/span&amp;gt;   fs    # [RT Field2] Width&lt;br /&gt;
 Field2_kind= &amp;quot;&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;QSSIN&amp;lt;/span&amp;gt;&amp;quot;             # [RT Field2] Kind(SIN|COS|RES|ANTIRES|GAUSS|DELTA|QSSIN)&lt;br /&gt;
 Field2_pol= &amp;quot;linear&amp;quot;             # [RT Field2] Pol(linear|circular)&lt;br /&gt;
 % Field2_Dir&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;0.000000 | 1.000000 | 0.000000 |&amp;lt;/span&amp;gt;        # [RT Field2] Versor&lt;br /&gt;
 %&lt;br /&gt;
 Field2_Tstart= 0.010000    fs    # [RT Field2] Initial Time&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Please note:&#039;&#039;&#039;  by convention in Yambo we consider the first field the probe and the second the pump. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
you run the simulation with the command &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;yambo_nl -F yambo.in_pump_and_probe -J PUMP_AND_PROBE &amp;lt;/span&amp;gt; and then we analyze the result using ypp with the command: &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;ypp_nl -u -J PUMP_AND_PROBE &amp;lt;/span&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 nonlinear                        # [R] Non-linear response analysis &lt;br /&gt;
 Xorder= 1                        # Max order of the response/exc functions&lt;br /&gt;
 % TimeRange&lt;br /&gt;
 -1.000000 |-1.000000 |         fs    # Time-window where processing is done&lt;br /&gt;
 %&lt;br /&gt;
 ETStpsRt= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;500 &amp;lt;/span&amp;gt;                   # Total Energy steps&lt;br /&gt;
 % EnRngeRt&lt;br /&gt;
   &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;0.00000 | 3.9000 &amp;lt;/span&amp;gt;|         eV    # Energy range&lt;br /&gt;
 %&lt;br /&gt;
 DampMode= &amp;quot;&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;GAUSSIAN&amp;lt;/span&amp;gt;&amp;quot;                 # Damping type ( NONE | LORENTZIAN | GAUSSIAN )&lt;br /&gt;
 DampFactor= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;0.085000  &amp;lt;/span&amp;gt;     eV    # Damping parameter&lt;br /&gt;
 PumpPATH= &amp;quot;&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;./PUMP/&amp;lt;/span&amp;gt;&amp;quot;                 # Path of the simulation with the Pump only&lt;br /&gt;
&lt;br /&gt;
Notice that in this case we are interested in the spectra below the 4 eV, that is was zero without the presence of the pump. We put in the input the pump path in such way to calculate polarization of the pump&amp;amp;probe minus the one of generate by the pump only &amp;lt;math&amp;gt;\Delta P(t) = P_{PnP}(t) - P_{pump}(t)&amp;lt;/math&amp;gt;. Then we analyze the &amp;lt;math&amp;gt;\Delta P(t)&amp;lt;/math&amp;gt; and get the new spectra:&lt;br /&gt;
&lt;br /&gt;
[[File:P and p spectrum.png|800px | center|Pump and probe spectrum]]&lt;br /&gt;
&lt;br /&gt;
The peak that you see in this spectrum, that were not present in when the pump was zero, correspond to the transition between the different excited states. The pump field populates the state at 5.42 eV and then the probe excites electrons from this state to higher states. The energy difference between the higher excited states and the peak at 5.42 define the position of the peaks in the pump and probe spectrum, while their intensity is dictated by the dipole matrix elements between the different excited states, see Ref. &amp;lt;ref name=&amp;quot;pnp&amp;quot;&amp;gt;&amp;lt;/ref&amp;gt;.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Additional comments on pump and probe calculations &#039;&#039;&#039;&lt;br /&gt;
* We used a Gaussian damping factor, this choice is motivated by various tests we have done, and it seems to us that in pump and probe this broadening gives better results.&amp;lt;br&amp;gt;&lt;br /&gt;
* If you plot all spectrum you will notice that the &amp;quot;equilibrium part&amp;quot; is much stronger than the one induced by the pump, this is normal because only a small fraction of electron are promoted in the excited state by the pump.&lt;br /&gt;
* All previous simulation can be run also in presence of excitons, see  Ref. &amp;lt;ref name=&amp;quot;pnp&amp;quot;&amp;gt;&amp;lt;/ref&amp;gt; and group theory can be used to predict dark/bright transition in the pump and probe spectroscopy.&amp;lt;ref&amp;gt;[https://link.springer.com/book/10.1007/978-3-540-32899-5  Group Theory, Application to the Physics of Condensed Matter],   Mildred S. S. Dresselhaus, Gene Dresselhaus, Ado Jorio, Springer Editor&amp;lt;/ref&amp;gt;&lt;br /&gt;
* In principle is it possible to include damping and radiative life-time in the simulation to study retardation effect between the pump and probe. This  approach  exact in the independent particle case, but introduces an error when correlation effects are present, see Refs.&amp;lt;ref&amp;gt;[https://arxiv.org/abs/2106.03592 Excitons and carriers in transient absorption and time-resolved ARPES spectroscopy: an abinitio approach], D. Sangalli, Phys. Rev. Materials &#039;&#039;&#039;5&#039;&#039;&#039;, 083803 (2021)&amp;lt;/ref&amp;gt; and &amp;lt;ref&amp;gt;[https://arxiv.org/abs/1705.04245 Theory of exciton-phonon coupling], Gabriel Antonius and Steven G. Louie Phys. Rev. B &#039;&#039;&#039;105&#039;&#039;&#039;, 085111 (2022)&amp;lt;/ref&amp;gt;for a discussion.&lt;br /&gt;
* Non-linear response (SHG, THG, ...) induced by the pump is not implemented yet... if you have a good idea how to do it, please let us know&lt;br /&gt;
&lt;br /&gt;
== Analysis of the results using YamboPy ==&lt;br /&gt;
&#039;&#039;&#039;This part works only with Lumen 2.0 or the last version available on Github:&#039;&#039;&#039; [https://gitlab.com/lumen-code https://gitlab.com/lumen-code]&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Results can be analyzed using YamboPy with the following script:&lt;br /&gt;
&lt;br /&gt;
 from yambopy import *&lt;br /&gt;
 from yambopy.plot  import *&lt;br /&gt;
 &lt;br /&gt;
 NLDB_P_and_P=YamboNLDB(calc=&#039;P_and_P&#039;)&lt;br /&gt;
 NLDB_Pump   =YamboNLDB(calc=&#039;PUMP&#039;)&lt;br /&gt;
  &lt;br /&gt;
 pol_pump   =NLDB_Pump.Polarization[0]&lt;br /&gt;
 pol_p_and_p=NLDB_P_and_P.Polarization[0]&lt;br /&gt;
 &lt;br /&gt;
 time=NLDB_P_and_P.IO_TIME_points&lt;br /&gt;
 t_initial=NLDB_P_and_P.Efield[0][&amp;quot;initial_time&amp;quot;]&lt;br /&gt;
 &lt;br /&gt;
 pol_damped=np.empty_like(pol_pump)&lt;br /&gt;
 &lt;br /&gt;
 for i_d in range(3):&lt;br /&gt;
     pol_damped[i_d,:]=damp_it(pol_p_and_p[i_d,:]-pol_pump[i_d,:],time,t_initial,damp_type=&#039;GAUSSIAN&#039;,damp_factor=0.085/ha2ev)&lt;br /&gt;
 &lt;br /&gt;
 Plot_Pol(time=time, pol=pol_damped, xlim=[0,55], save_file=&#039;polarization.pdf&#039;)&lt;br /&gt;
 &lt;br /&gt;
 Linear_Response(time=time,pol=pol_damped,efield=NLDB_P_and_P.Efield[0],plot=False,plot_file=&#039;delta_eps.pdf&#039;,e_range=[0.0,3.7],n_freqs=500)&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;/div&gt;</summary>
		<author><name>Attacc</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Exciton-phonon_coupling_and_luminescence&amp;diff=9240</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=9240"/>
		<updated>2025-11-16T21:49:17Z</updated>

		<summary type="html">&lt;p&gt;Attacc: Undo revision 9239 by Attacc (talk)&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://gitlab.com/lumen-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. 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. &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 --debug&lt;br /&gt;
&lt;br /&gt;
At the end, check the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 ls SAVE/ndb.elph_gkkp*&lt;br /&gt;
&lt;br /&gt;
to see that it has created the Yambo-compatible electron-phonon databases.&lt;br /&gt;
&lt;br /&gt;
If you saved the &amp;lt;code&amp;gt;lelphc.in&amp;lt;/code&amp;gt; input file, you can 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;
If you want to run LetzElPhC directly, without using yambopy - for example if you just need the native database &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; - you can refer to its [[https://gitlab.com/lumen-code/LetzElPhC/-/blob/main/docs/main.pdf?ref_type=heads|user guide]].&lt;br /&gt;
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;
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;
== 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,q) - \sum_{cc^\prime vk} A^{\alpha, *}_{c^\prime v} (k+q, q) g_{c^\prime c}^\mu (k+q,q) A^{\lambda}_{cv}(k,q)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here, &amp;lt;math&amp;gt;A^{\lambda}_{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&lt;br /&gt;
 from yambopy.exciton_phonon.excph_matrix_elements import exciton_phonon_matelem&lt;br /&gt;
&lt;br /&gt;
 path = &#039;1L_MoS2&#039;&lt;br /&gt;
 bands_range=[24,28] # 2 valence bands, 2 conduction bands&lt;br /&gt;
 nexc = 12 # number of excitonic states&lt;br /&gt;
 &lt;br /&gt;
 bsepath    = f&#039;{path}/bse-allq_full&#039; # Path to BSE calculation (Lin=Lout)&lt;br /&gt;
 savepath   = f&#039;{path}/SAVE&#039;     # Yambo SAVE&lt;br /&gt;
 ndb_elph   = f&#039;{path}/ndb.elph&#039; # LetzElPhC electron-phonon database (any convention)&lt;br /&gt;
&lt;br /&gt;
 # Read lattice&lt;br /&gt;
 lattice = YamboLatticeDB.from_db_file(filename=f&#039;{savepath}/ns.db1&#039;)&lt;br /&gt;
 # Read electron-phonon&lt;br /&gt;
 elph    = LetzElphElectronPhononDB(ndb_elph,read_all=False)&lt;br /&gt;
 # Read wave functions&lt;br /&gt;
 wfcs    = YamboWFDB(filename=&#039;ns.wf&#039;,save=savepath,latdb=lattice,bands_range=bands_range)&lt;br /&gt;
 # Calculate exciton-phonon matrix elements&lt;br /&gt;
 exph = exciton_phonon_matelem(lattice,elph,wfcs,BSE_dir=bsepath,neigs=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; (python indexing and last value is excluded). 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;
 # Exciton in states&lt;br /&gt;
 exc_in  = [2,3]  # First bright peak (A: 2,3 -- B: 6,7)&lt;br /&gt;
 exc_out = [0,1,2,3] # first 4 states (dispersion of dark triplet state and A)&lt;br /&gt;
 ph_in  = &#039;all&#039;&lt;br /&gt;
 # Paths of databases&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;
 # Read lattice and k-space info&lt;br /&gt;
 ylat = YamboLatticeDB.from_db_file(filename=ns_db1)&lt;br /&gt;
 print(ylat)&lt;br /&gt;
&lt;br /&gt;
 # Load exc-ph database&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 # Switch from Ha to eV&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>Attacc</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Exciton-phonon_coupling_and_luminescence&amp;diff=9239</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=9239"/>
		<updated>2025-11-16T21:48:41Z</updated>

		<summary type="html">&lt;p&gt;Attacc: &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;
This tutorial is based on the following references: theory[1][2][3][4][5][6] and applications[7][8][9][10][11][12][13][14] of exciton-phonon physics. &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://gitlab.com/lumen-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. 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. &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 --debug&lt;br /&gt;
&lt;br /&gt;
At the end, check the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 ls SAVE/ndb.elph_gkkp*&lt;br /&gt;
&lt;br /&gt;
to see that it has created the Yambo-compatible electron-phonon databases.&lt;br /&gt;
&lt;br /&gt;
If you saved the &amp;lt;code&amp;gt;lelphc.in&amp;lt;/code&amp;gt; input file, you can 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;
If you want to run LetzElPhC directly, without using yambopy - for example if you just need the native database &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt; - you can refer to its [[https://gitlab.com/lumen-code/LetzElPhC/-/blob/main/docs/main.pdf?ref_type=heads|user guide]].&lt;br /&gt;
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;
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;
== 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,q) - \sum_{cc^\prime vk} A^{\alpha, *}_{c^\prime v} (k+q, q) g_{c^\prime c}^\mu (k+q,q) A^{\lambda}_{cv}(k,q)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here, &amp;lt;math&amp;gt;A^{\lambda}_{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&lt;br /&gt;
 from yambopy.exciton_phonon.excph_matrix_elements import exciton_phonon_matelem&lt;br /&gt;
&lt;br /&gt;
 path = &#039;1L_MoS2&#039;&lt;br /&gt;
 bands_range=[24,28] # 2 valence bands, 2 conduction bands&lt;br /&gt;
 nexc = 12 # number of excitonic states&lt;br /&gt;
 &lt;br /&gt;
 bsepath    = f&#039;{path}/bse-allq_full&#039; # Path to BSE calculation (Lin=Lout)&lt;br /&gt;
 savepath   = f&#039;{path}/SAVE&#039;     # Yambo SAVE&lt;br /&gt;
 ndb_elph   = f&#039;{path}/ndb.elph&#039; # LetzElPhC electron-phonon database (any convention)&lt;br /&gt;
&lt;br /&gt;
 # Read lattice&lt;br /&gt;
 lattice = YamboLatticeDB.from_db_file(filename=f&#039;{savepath}/ns.db1&#039;)&lt;br /&gt;
 # Read electron-phonon&lt;br /&gt;
 elph    = LetzElphElectronPhononDB(ndb_elph,read_all=False)&lt;br /&gt;
 # Read wave functions&lt;br /&gt;
 wfcs    = YamboWFDB(filename=&#039;ns.wf&#039;,save=savepath,latdb=lattice,bands_range=bands_range)&lt;br /&gt;
 # Calculate exciton-phonon matrix elements&lt;br /&gt;
 exph = exciton_phonon_matelem(lattice,elph,wfcs,BSE_dir=bsepath,neigs=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; (python indexing and last value is excluded). 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;
 # Exciton in states&lt;br /&gt;
 exc_in  = [2,3]  # First bright peak (A: 2,3 -- B: 6,7)&lt;br /&gt;
 exc_out = [0,1,2,3] # first 4 states (dispersion of dark triplet state and A)&lt;br /&gt;
 ph_in  = &#039;all&#039;&lt;br /&gt;
 # Paths of databases&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;
 # Read lattice and k-space info&lt;br /&gt;
 ylat = YamboLatticeDB.from_db_file(filename=ns_db1)&lt;br /&gt;
 print(ylat)&lt;br /&gt;
&lt;br /&gt;
 # Load exc-ph database&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 # Switch from Ha to eV&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>Attacc</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Tutorials_all&amp;diff=9193</id>
		<title>Tutorials all</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Tutorials_all&amp;diff=9193"/>
		<updated>2025-10-30T11:37:40Z</updated>

		<summary type="html">&lt;p&gt;Attacc: /* Non-Linear response */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page contains the full list of available tutorials. These cover a variety of mixed topics, both physical and methodological. Some of these are om &amp;quot;Standalone mode&amp;quot; and are designed to be followed from start to finish in one page. Others have been ported in &amp;quot;Modular form&amp;quot;. These are also available under the link [[Tutorials modular]]. The tutorials do not require previous knowledge of yambo, unless explicitly specified. Each tutorial requires download of a specific core database, and typically they cover a specific physical system (like bulk GaSb or a hydrogen chain). Ground state input files and pseudopotentials are provided. Output files are also provided for reference.&lt;br /&gt;
&lt;br /&gt;
These tutorials can be accessed directly from this page of from the side bar. They include different kind of subjects:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Warning&#039;&#039;&#039;: These tutorials were prepared using previous version of the Yambo code: some command lines, variables, reports and outputs can be  slightly different from the last version of the code.  Scripts for parsing output cannot work anymore and should be edited to work with the new outputs. New command lines can be accessed typing &amp;lt;code&amp;gt;yambo -h &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic ==&lt;br /&gt;
* [[First steps: a walk through from DFT to optical properties]] (modular tutorial)&lt;br /&gt;
* [[Silicon|GW on bulk silicon]]&lt;br /&gt;
* [[GW on h-BN (standalone)|GW on h-BN]] (standalone version);  [[How to obtain the quasi-particle band structure of a bulk material: h-BN|GW on h-BN]] (modular version)&lt;br /&gt;
* [[LiF|BSE in lithium-floride]]&lt;br /&gt;
* [[BSE tutorial on hBN]]&lt;br /&gt;
* [[How to analyse excitons]]&lt;br /&gt;
&lt;br /&gt;
== More on GW and Quasi-particles ==&lt;br /&gt;
* [[Real_Axis_and_Lifetimes|Real Axis and Lifetimes]]&lt;br /&gt;
* [[Self-consistent GW on eigenvalues only]]&lt;br /&gt;
* [[GW parallel strategies|GW parallel strategies v1]]; [[GW parallel strategies CECAM|GW parallel strategies v2]];  [[Pushing convergence in parallel|GW convergence in parallel]] (modular tutorials)&lt;br /&gt;
* [[GW tutorial on HPC]] (external tutorial on HackMD)&lt;br /&gt;
* [[Quasi-particles and Self-energy within the Multipole Approximation (MPA)]]&lt;br /&gt;
* [http://www.attaccalite.com/gw-correction-on-an-arbitrary-point-of-the-brillouin-zone GW on arbitrary k point] (external tutorial on www.attaccalite.com)&lt;br /&gt;
&lt;br /&gt;
== More on Linear response and BSE ==&lt;br /&gt;
* [[Hydrogen chain|TDDFT Failure and long range correlations]]&lt;br /&gt;
* [[SOC|Spin-orbit coupling in GaSb]]&lt;br /&gt;
* [[The magneto-optical Kerr effect|The magneto-optical Kerr effect in bulk iron, RPA]]&lt;br /&gt;
* [[The magneto-optical Kerr effect including excitonic effects|The magneto-optical Kerr effect in XXX, excitonic effects]] (todo)&lt;br /&gt;
* [[Dichroism in molecules]]&lt;br /&gt;
* [[Surface spectroscopy]] (to restore from older version)&lt;br /&gt;
* [[Si_Surface|Linear Response of a silicon surface (2D)]]&lt;br /&gt;
* [http://www.attaccalite.com/speed-up-dielectric-constant-calculations-using-the-double-grid-method-with-yambo/ Speed up dielectric constant calculations using the double-grid method] (to be imported)&lt;br /&gt;
* [[Si_wire|Linear Response from a silicon wire (1D)]] (to restore from old version)&lt;br /&gt;
* [[H2|H2 molecule: Linear Response &amp;amp; TDDFT (0D)]] (to restore from old version)&lt;br /&gt;
* [[SiH4|SiH4: isolated molecule TDDFT &amp;amp; BSE (0D)]] (restored from old version, still to be finalized)&lt;br /&gt;
&lt;br /&gt;
== Post Processing with ypp ==&lt;br /&gt;
* [[Yambo Post Processing (ypp)]]&lt;br /&gt;
&lt;br /&gt;
== Electron phonon coupling ==&lt;br /&gt;
* [[Electron Phonon Coupling|Electron Phonon Coupling]]&lt;br /&gt;
* [[Optical properties at finite temperature]]&lt;br /&gt;
* [[Phonon-assisted luminescence by finite atomic displacements]]&lt;br /&gt;
* [[Exciton-phonon coupling and luminescence]]&lt;br /&gt;
&lt;br /&gt;
== Real time &amp;amp; Non linear response ==&lt;br /&gt;
=== Linear response ===&lt;br /&gt;
* [[Linear response from real time simulations (density matrix only)|Linear response using the density matrix (IP)]]&lt;br /&gt;
* [[Linear response using Dynamical Berry Phase|Linear response using wave-functions and Dynamical Berry Phase (IP)]]&lt;br /&gt;
* [[Linear response in velocity gauge|Linear response using wave-functions in velocity gauge (IP)]]&lt;br /&gt;
* [[Real time Bethe-Salpeter Equation (density_matrix_only)|Linear response using the density matrix (TD-HSEX)]]&lt;br /&gt;
* [[Linear response from real time simulations|Linear response from real time simulations (IP &amp;amp; TD-HSEX)]] (modular tutorial)&lt;br /&gt;
&lt;br /&gt;
=== Non-Linear response ===&lt;br /&gt;
* [[Real time approach to non-linear response (SHG)]]&lt;br /&gt;
* [[Correlation effects in the non-linear response]]&lt;br /&gt;
* [[SHG within the TD-HSEX level (also called TD-aGW or TD-BSE)]]&lt;br /&gt;
&lt;br /&gt;
=== Pump and Probe experiments ===&lt;br /&gt;
* [[Nonequilibrium absorption in bulk silicon|Pump and Probe: Transient Absorption from BSE with NEQ occupations]]&lt;br /&gt;
* [[Pump and Probe|Pump and Probe: Transient Absorption from real time propagation with pump and probe]]&lt;br /&gt;
* [[Pump and Probe: Time resolved ARPES|Pump and Probe: Time resolved ARPES from real time propagation with pump]]&lt;br /&gt;
&lt;br /&gt;
== Developing Yambo ==&lt;br /&gt;
* [[How to create a new project in Yambo]]&lt;br /&gt;
* [[How to create a new ypp interface]]&lt;br /&gt;
* [[Some hints on github]]&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
* [[SOC|Spin-Orbit Coupling MBPT]]&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- For each TUTORIAL (Solid_LiF, Solid_Al, ...) , therefore, you can download the ground state files (zip archive named TUTORIAL_ground_state.zip) and generate the Yambo databases from your own by running abinit/PWscf and a2y/p2y. In this case the Yambo input and reference files are contained in the zip file (TUTORIAL_reference_files.zip). Alternatively, if (and only if) you have compiled yambo with the NetCDF support you can directly download the zip files containing the Yambo core databases (TUTORIAL_NETCDF_databases_and_reference_files.zip). These are generated using the NetCDF interface in order to be readable in any platform.&lt;br /&gt;
After you have downloaded the tutorial zip files and unziped them you should have now a tutorial tree:&lt;br /&gt;
localhost:&amp;gt; ls &lt;br /&gt;
YAMBO_TUTORIALS/&lt;br /&gt;
localhost:&amp;gt; ls  YAMBO_TUTORIALS/&lt;br /&gt;
COPYING  Fantastic_Dimensions/  Hydrogen_Chain/  README  Solid_LiF/ Solid_Al/ SiH4/ ...&lt;br /&gt;
In each folder you will find an Abinit or Pwscf subfolder in case you have downloaded the ground state zip files and the YAMBO subfolder. The tutorials start by entering the YAMBO subfolder and followinf the informations provided in the tutorial documentation.  --&amp;gt;&lt;/div&gt;</summary>
		<author><name>Attacc</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Tutorials_all&amp;diff=9192</id>
		<title>Tutorials all</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Tutorials_all&amp;diff=9192"/>
		<updated>2025-10-30T11:29:08Z</updated>

		<summary type="html">&lt;p&gt;Attacc: /* Pump and Probe experiments */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page contains the full list of available tutorials. These cover a variety of mixed topics, both physical and methodological. Some of these are om &amp;quot;Standalone mode&amp;quot; and are designed to be followed from start to finish in one page. Others have been ported in &amp;quot;Modular form&amp;quot;. These are also available under the link [[Tutorials modular]]. The tutorials do not require previous knowledge of yambo, unless explicitly specified. Each tutorial requires download of a specific core database, and typically they cover a specific physical system (like bulk GaSb or a hydrogen chain). Ground state input files and pseudopotentials are provided. Output files are also provided for reference.&lt;br /&gt;
&lt;br /&gt;
These tutorials can be accessed directly from this page of from the side bar. They include different kind of subjects:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Warning&#039;&#039;&#039;: These tutorials were prepared using previous version of the Yambo code: some command lines, variables, reports and outputs can be  slightly different from the last version of the code.  Scripts for parsing output cannot work anymore and should be edited to work with the new outputs. New command lines can be accessed typing &amp;lt;code&amp;gt;yambo -h &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic ==&lt;br /&gt;
* [[First steps: a walk through from DFT to optical properties]] (modular tutorial)&lt;br /&gt;
* [[Silicon|GW on bulk silicon]]&lt;br /&gt;
* [[GW on h-BN (standalone)|GW on h-BN]] (standalone version);  [[How to obtain the quasi-particle band structure of a bulk material: h-BN|GW on h-BN]] (modular version)&lt;br /&gt;
* [[LiF|BSE in lithium-floride]]&lt;br /&gt;
* [[BSE tutorial on hBN]]&lt;br /&gt;
* [[How to analyse excitons]]&lt;br /&gt;
&lt;br /&gt;
== More on GW and Quasi-particles ==&lt;br /&gt;
* [[Real_Axis_and_Lifetimes|Real Axis and Lifetimes]]&lt;br /&gt;
* [[Self-consistent GW on eigenvalues only]]&lt;br /&gt;
* [[GW parallel strategies|GW parallel strategies v1]]; [[GW parallel strategies CECAM|GW parallel strategies v2]];  [[Pushing convergence in parallel|GW convergence in parallel]] (modular tutorials)&lt;br /&gt;
* [[GW tutorial on HPC]] (external tutorial on HackMD)&lt;br /&gt;
* [[Quasi-particles and Self-energy within the Multipole Approximation (MPA)]]&lt;br /&gt;
* [http://www.attaccalite.com/gw-correction-on-an-arbitrary-point-of-the-brillouin-zone GW on arbitrary k point] (external tutorial on www.attaccalite.com)&lt;br /&gt;
&lt;br /&gt;
== More on Linear response and BSE ==&lt;br /&gt;
* [[Hydrogen chain|TDDFT Failure and long range correlations]]&lt;br /&gt;
* [[SOC|Spin-orbit coupling in GaSb]]&lt;br /&gt;
* [[The magneto-optical Kerr effect|The magneto-optical Kerr effect in bulk iron, RPA]]&lt;br /&gt;
* [[The magneto-optical Kerr effect including excitonic effects|The magneto-optical Kerr effect in XXX, excitonic effects]] (todo)&lt;br /&gt;
* [[Dichroism in molecules]]&lt;br /&gt;
* [[Surface spectroscopy]] (to restore from older version)&lt;br /&gt;
* [[Si_Surface|Linear Response of a silicon surface (2D)]]&lt;br /&gt;
* [http://www.attaccalite.com/speed-up-dielectric-constant-calculations-using-the-double-grid-method-with-yambo/ Speed up dielectric constant calculations using the double-grid method] (to be imported)&lt;br /&gt;
* [[Si_wire|Linear Response from a silicon wire (1D)]] (to restore from old version)&lt;br /&gt;
* [[H2|H2 molecule: Linear Response &amp;amp; TDDFT (0D)]] (to restore from old version)&lt;br /&gt;
* [[SiH4|SiH4: isolated molecule TDDFT &amp;amp; BSE (0D)]] (restored from old version, still to be finalized)&lt;br /&gt;
&lt;br /&gt;
== Post Processing with ypp ==&lt;br /&gt;
* [[Yambo Post Processing (ypp)]]&lt;br /&gt;
&lt;br /&gt;
== Electron phonon coupling ==&lt;br /&gt;
* [[Electron Phonon Coupling|Electron Phonon Coupling]]&lt;br /&gt;
* [[Optical properties at finite temperature]]&lt;br /&gt;
* [[Phonon-assisted luminescence by finite atomic displacements]]&lt;br /&gt;
* [[Exciton-phonon coupling and luminescence]]&lt;br /&gt;
&lt;br /&gt;
== Real time &amp;amp; Non linear response ==&lt;br /&gt;
=== Linear response ===&lt;br /&gt;
* [[Linear response from real time simulations (density matrix only)|Linear response using the density matrix (IP)]]&lt;br /&gt;
* [[Linear response using Dynamical Berry Phase|Linear response using wave-functions and Dynamical Berry Phase (IP)]]&lt;br /&gt;
* [[Linear response in velocity gauge|Linear response using wave-functions in velocity gauge (IP)]]&lt;br /&gt;
* [[Real time Bethe-Salpeter Equation (density_matrix_only)|Linear response using the density matrix (TD-HSEX)]]&lt;br /&gt;
* [[Linear response from real time simulations|Linear response from real time simulations (IP &amp;amp; TD-HSEX)]] (modular tutorial)&lt;br /&gt;
&lt;br /&gt;
=== Non-Linear response ===&lt;br /&gt;
* [[Real time approach to non-linear response (SHG)]]&lt;br /&gt;
* [[Correlation effects in the non-linear response]]&lt;br /&gt;
* [[SHG within the TD-HSEX level (also called TD-aGW or TD-BSE)]]&lt;br /&gt;
* [[A fast approach to excitonic effects in linear/non-linear response]]&lt;br /&gt;
* [[Angular dependence of non-linear response]]&lt;br /&gt;
* [[Third Harmonic Generation (THG)]]&lt;br /&gt;
* [[Two-photon absorption]]&lt;br /&gt;
* [[Parallelization for non-linear response calculations]]&lt;br /&gt;
&lt;br /&gt;
=== Pump and Probe experiments ===&lt;br /&gt;
* [[Nonequilibrium absorption in bulk silicon|Pump and Probe: Transient Absorption from BSE with NEQ occupations]]&lt;br /&gt;
* [[Pump and Probe|Pump and Probe: Transient Absorption from real time propagation with pump and probe]]&lt;br /&gt;
* [[Pump and Probe: Time resolved ARPES|Pump and Probe: Time resolved ARPES from real time propagation with pump]]&lt;br /&gt;
&lt;br /&gt;
== Developing Yambo ==&lt;br /&gt;
* [[How to create a new project in Yambo]]&lt;br /&gt;
* [[How to create a new ypp interface]]&lt;br /&gt;
* [[Some hints on github]]&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
* [[SOC|Spin-Orbit Coupling MBPT]]&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- For each TUTORIAL (Solid_LiF, Solid_Al, ...) , therefore, you can download the ground state files (zip archive named TUTORIAL_ground_state.zip) and generate the Yambo databases from your own by running abinit/PWscf and a2y/p2y. In this case the Yambo input and reference files are contained in the zip file (TUTORIAL_reference_files.zip). Alternatively, if (and only if) you have compiled yambo with the NetCDF support you can directly download the zip files containing the Yambo core databases (TUTORIAL_NETCDF_databases_and_reference_files.zip). These are generated using the NetCDF interface in order to be readable in any platform.&lt;br /&gt;
After you have downloaded the tutorial zip files and unziped them you should have now a tutorial tree:&lt;br /&gt;
localhost:&amp;gt; ls &lt;br /&gt;
YAMBO_TUTORIALS/&lt;br /&gt;
localhost:&amp;gt; ls  YAMBO_TUTORIALS/&lt;br /&gt;
COPYING  Fantastic_Dimensions/  Hydrogen_Chain/  README  Solid_LiF/ Solid_Al/ SiH4/ ...&lt;br /&gt;
In each folder you will find an Abinit or Pwscf subfolder in case you have downloaded the ground state zip files and the YAMBO subfolder. The tutorials start by entering the YAMBO subfolder and followinf the informations provided in the tutorial documentation.  --&amp;gt;&lt;/div&gt;</summary>
		<author><name>Attacc</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Tutorials_all&amp;diff=9191</id>
		<title>Tutorials all</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Tutorials_all&amp;diff=9191"/>
		<updated>2025-10-30T11:25:19Z</updated>

		<summary type="html">&lt;p&gt;Attacc: /* Non-Linear response */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page contains the full list of available tutorials. These cover a variety of mixed topics, both physical and methodological. Some of these are om &amp;quot;Standalone mode&amp;quot; and are designed to be followed from start to finish in one page. Others have been ported in &amp;quot;Modular form&amp;quot;. These are also available under the link [[Tutorials modular]]. The tutorials do not require previous knowledge of yambo, unless explicitly specified. Each tutorial requires download of a specific core database, and typically they cover a specific physical system (like bulk GaSb or a hydrogen chain). Ground state input files and pseudopotentials are provided. Output files are also provided for reference.&lt;br /&gt;
&lt;br /&gt;
These tutorials can be accessed directly from this page of from the side bar. They include different kind of subjects:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Warning&#039;&#039;&#039;: These tutorials were prepared using previous version of the Yambo code: some command lines, variables, reports and outputs can be  slightly different from the last version of the code.  Scripts for parsing output cannot work anymore and should be edited to work with the new outputs. New command lines can be accessed typing &amp;lt;code&amp;gt;yambo -h &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic ==&lt;br /&gt;
* [[First steps: a walk through from DFT to optical properties]] (modular tutorial)&lt;br /&gt;
* [[Silicon|GW on bulk silicon]]&lt;br /&gt;
* [[GW on h-BN (standalone)|GW on h-BN]] (standalone version);  [[How to obtain the quasi-particle band structure of a bulk material: h-BN|GW on h-BN]] (modular version)&lt;br /&gt;
* [[LiF|BSE in lithium-floride]]&lt;br /&gt;
* [[BSE tutorial on hBN]]&lt;br /&gt;
* [[How to analyse excitons]]&lt;br /&gt;
&lt;br /&gt;
== More on GW and Quasi-particles ==&lt;br /&gt;
* [[Real_Axis_and_Lifetimes|Real Axis and Lifetimes]]&lt;br /&gt;
* [[Self-consistent GW on eigenvalues only]]&lt;br /&gt;
* [[GW parallel strategies|GW parallel strategies v1]]; [[GW parallel strategies CECAM|GW parallel strategies v2]];  [[Pushing convergence in parallel|GW convergence in parallel]] (modular tutorials)&lt;br /&gt;
* [[GW tutorial on HPC]] (external tutorial on HackMD)&lt;br /&gt;
* [[Quasi-particles and Self-energy within the Multipole Approximation (MPA)]]&lt;br /&gt;
* [http://www.attaccalite.com/gw-correction-on-an-arbitrary-point-of-the-brillouin-zone GW on arbitrary k point] (external tutorial on www.attaccalite.com)&lt;br /&gt;
&lt;br /&gt;
== More on Linear response and BSE ==&lt;br /&gt;
* [[Hydrogen chain|TDDFT Failure and long range correlations]]&lt;br /&gt;
* [[SOC|Spin-orbit coupling in GaSb]]&lt;br /&gt;
* [[The magneto-optical Kerr effect|The magneto-optical Kerr effect in bulk iron, RPA]]&lt;br /&gt;
* [[The magneto-optical Kerr effect including excitonic effects|The magneto-optical Kerr effect in XXX, excitonic effects]] (todo)&lt;br /&gt;
* [[Dichroism in molecules]]&lt;br /&gt;
* [[Surface spectroscopy]] (to restore from older version)&lt;br /&gt;
* [[Si_Surface|Linear Response of a silicon surface (2D)]]&lt;br /&gt;
* [http://www.attaccalite.com/speed-up-dielectric-constant-calculations-using-the-double-grid-method-with-yambo/ Speed up dielectric constant calculations using the double-grid method] (to be imported)&lt;br /&gt;
* [[Si_wire|Linear Response from a silicon wire (1D)]] (to restore from old version)&lt;br /&gt;
* [[H2|H2 molecule: Linear Response &amp;amp; TDDFT (0D)]] (to restore from old version)&lt;br /&gt;
* [[SiH4|SiH4: isolated molecule TDDFT &amp;amp; BSE (0D)]] (restored from old version, still to be finalized)&lt;br /&gt;
&lt;br /&gt;
== Post Processing with ypp ==&lt;br /&gt;
* [[Yambo Post Processing (ypp)]]&lt;br /&gt;
&lt;br /&gt;
== Electron phonon coupling ==&lt;br /&gt;
* [[Electron Phonon Coupling|Electron Phonon Coupling]]&lt;br /&gt;
* [[Optical properties at finite temperature]]&lt;br /&gt;
* [[Phonon-assisted luminescence by finite atomic displacements]]&lt;br /&gt;
* [[Exciton-phonon coupling and luminescence]]&lt;br /&gt;
&lt;br /&gt;
== Real time &amp;amp; Non linear response ==&lt;br /&gt;
=== Linear response ===&lt;br /&gt;
* [[Linear response from real time simulations (density matrix only)|Linear response using the density matrix (IP)]]&lt;br /&gt;
* [[Linear response using Dynamical Berry Phase|Linear response using wave-functions and Dynamical Berry Phase (IP)]]&lt;br /&gt;
* [[Linear response in velocity gauge|Linear response using wave-functions in velocity gauge (IP)]]&lt;br /&gt;
* [[Real time Bethe-Salpeter Equation (density_matrix_only)|Linear response using the density matrix (TD-HSEX)]]&lt;br /&gt;
* [[Linear response from real time simulations|Linear response from real time simulations (IP &amp;amp; TD-HSEX)]] (modular tutorial)&lt;br /&gt;
&lt;br /&gt;
=== Non-Linear response ===&lt;br /&gt;
* [[Real time approach to non-linear response (SHG)]]&lt;br /&gt;
* [[Correlation effects in the non-linear response]]&lt;br /&gt;
* [[SHG within the TD-HSEX level (also called TD-aGW or TD-BSE)]]&lt;br /&gt;
* [[A fast approach to excitonic effects in linear/non-linear response]]&lt;br /&gt;
* [[Angular dependence of non-linear response]]&lt;br /&gt;
* [[Third Harmonic Generation (THG)]]&lt;br /&gt;
* [[Two-photon absorption]]&lt;br /&gt;
* [[Parallelization for non-linear response calculations]]&lt;br /&gt;
&lt;br /&gt;
=== Pump and Probe experiments ===&lt;br /&gt;
* [[Nonequilibrium absorption in bulk silicon|Pump and Probe: Transient Absorption from BSE with NEQ occupations]]&lt;br /&gt;
* [[Pump and Probe|Pump and Probe: Transient Absorption from real time propagation with pump and probe]]&lt;br /&gt;
* [[Pump and Probe: Time resolved ARPES|Pump and Probe: Time resolved ARPES from real time propagation with pump]]&lt;br /&gt;
* [[Pump and Probe: reading electronic occuations from Perturbo code]]&lt;br /&gt;
&lt;br /&gt;
== Developing Yambo ==&lt;br /&gt;
* [[How to create a new project in Yambo]]&lt;br /&gt;
* [[How to create a new ypp interface]]&lt;br /&gt;
* [[Some hints on github]]&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
* [[SOC|Spin-Orbit Coupling MBPT]]&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- For each TUTORIAL (Solid_LiF, Solid_Al, ...) , therefore, you can download the ground state files (zip archive named TUTORIAL_ground_state.zip) and generate the Yambo databases from your own by running abinit/PWscf and a2y/p2y. In this case the Yambo input and reference files are contained in the zip file (TUTORIAL_reference_files.zip). Alternatively, if (and only if) you have compiled yambo with the NetCDF support you can directly download the zip files containing the Yambo core databases (TUTORIAL_NETCDF_databases_and_reference_files.zip). These are generated using the NetCDF interface in order to be readable in any platform.&lt;br /&gt;
After you have downloaded the tutorial zip files and unziped them you should have now a tutorial tree:&lt;br /&gt;
localhost:&amp;gt; ls &lt;br /&gt;
YAMBO_TUTORIALS/&lt;br /&gt;
localhost:&amp;gt; ls  YAMBO_TUTORIALS/&lt;br /&gt;
COPYING  Fantastic_Dimensions/  Hydrogen_Chain/  README  Solid_LiF/ Solid_Al/ SiH4/ ...&lt;br /&gt;
In each folder you will find an Abinit or Pwscf subfolder in case you have downloaded the ground state zip files and the YAMBO subfolder. The tutorials start by entering the YAMBO subfolder and followinf the informations provided in the tutorial documentation.  --&amp;gt;&lt;/div&gt;</summary>
		<author><name>Attacc</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Tutorials_all&amp;diff=9190</id>
		<title>Tutorials all</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Tutorials_all&amp;diff=9190"/>
		<updated>2025-10-28T08:37:10Z</updated>

		<summary type="html">&lt;p&gt;Attacc: /* Non-Linear response */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page contains the full list of available tutorials. These cover a variety of mixed topics, both physical and methodological. Some of these are om &amp;quot;Standalone mode&amp;quot; and are designed to be followed from start to finish in one page. Others have been ported in &amp;quot;Modular form&amp;quot;. These are also available under the link [[Tutorials modular]]. The tutorials do not require previous knowledge of yambo, unless explicitly specified. Each tutorial requires download of a specific core database, and typically they cover a specific physical system (like bulk GaSb or a hydrogen chain). Ground state input files and pseudopotentials are provided. Output files are also provided for reference.&lt;br /&gt;
&lt;br /&gt;
These tutorials can be accessed directly from this page of from the side bar. They include different kind of subjects:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Warning&#039;&#039;&#039;: These tutorials were prepared using previous version of the Yambo code: some command lines, variables, reports and outputs can be  slightly different from the last version of the code.  Scripts for parsing output cannot work anymore and should be edited to work with the new outputs. New command lines can be accessed typing &amp;lt;code&amp;gt;yambo -h &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic ==&lt;br /&gt;
* [[First steps: a walk through from DFT to optical properties]] (modular tutorial)&lt;br /&gt;
* [[Silicon|GW on bulk silicon]]&lt;br /&gt;
* [[GW on h-BN (standalone)|GW on h-BN]] (standalone version);  [[How to obtain the quasi-particle band structure of a bulk material: h-BN|GW on h-BN]] (modular version)&lt;br /&gt;
* [[LiF|BSE in lithium-floride]]&lt;br /&gt;
* [[BSE tutorial on hBN]]&lt;br /&gt;
* [[How to analyse excitons]]&lt;br /&gt;
&lt;br /&gt;
== More on GW and Quasi-particles ==&lt;br /&gt;
* [[Real_Axis_and_Lifetimes|Real Axis and Lifetimes]]&lt;br /&gt;
* [[Self-consistent GW on eigenvalues only]]&lt;br /&gt;
* [[GW parallel strategies|GW parallel strategies v1]]; [[GW parallel strategies CECAM|GW parallel strategies v2]];  [[Pushing convergence in parallel|GW convergence in parallel]] (modular tutorials)&lt;br /&gt;
* [[GW tutorial on HPC]] (external tutorial on HackMD)&lt;br /&gt;
* [[Quasi-particles and Self-energy within the Multipole Approximation (MPA)]]&lt;br /&gt;
* [http://www.attaccalite.com/gw-correction-on-an-arbitrary-point-of-the-brillouin-zone GW on arbitrary k point] (external tutorial on www.attaccalite.com)&lt;br /&gt;
&lt;br /&gt;
== More on Linear response and BSE ==&lt;br /&gt;
* [[Hydrogen chain|TDDFT Failure and long range correlations]]&lt;br /&gt;
* [[SOC|Spin-orbit coupling in GaSb]]&lt;br /&gt;
* [[The magneto-optical Kerr effect|The magneto-optical Kerr effect in bulk iron, RPA]]&lt;br /&gt;
* [[The magneto-optical Kerr effect including excitonic effects|The magneto-optical Kerr effect in XXX, excitonic effects]] (todo)&lt;br /&gt;
* [[Dichroism in molecules]]&lt;br /&gt;
* [[Surface spectroscopy]] (to restore from older version)&lt;br /&gt;
* [[Si_Surface|Linear Response of a silicon surface (2D)]]&lt;br /&gt;
* [http://www.attaccalite.com/speed-up-dielectric-constant-calculations-using-the-double-grid-method-with-yambo/ Speed up dielectric constant calculations using the double-grid method] (to be imported)&lt;br /&gt;
* [[Si_wire|Linear Response from a silicon wire (1D)]] (to restore from old version)&lt;br /&gt;
* [[H2|H2 molecule: Linear Response &amp;amp; TDDFT (0D)]] (to restore from old version)&lt;br /&gt;
* [[SiH4|SiH4: isolated molecule TDDFT &amp;amp; BSE (0D)]] (restored from old version, still to be finalized)&lt;br /&gt;
&lt;br /&gt;
== Post Processing with ypp ==&lt;br /&gt;
* [[Yambo Post Processing (ypp)]]&lt;br /&gt;
&lt;br /&gt;
== Electron phonon coupling ==&lt;br /&gt;
* [[Electron Phonon Coupling|Electron Phonon Coupling]]&lt;br /&gt;
* [[Optical properties at finite temperature]]&lt;br /&gt;
* [[Phonon-assisted luminescence by finite atomic displacements]]&lt;br /&gt;
* [[Exciton-phonon coupling and luminescence]]&lt;br /&gt;
&lt;br /&gt;
== Real time &amp;amp; Non linear response ==&lt;br /&gt;
=== Linear response ===&lt;br /&gt;
* [[Linear response from real time simulations (density matrix only)|Linear response using the density matrix (IP)]]&lt;br /&gt;
* [[Linear response using Dynamical Berry Phase|Linear response using wave-functions and Dynamical Berry Phase (IP)]]&lt;br /&gt;
* [[Linear response in velocity gauge|Linear response using wave-functions in velocity gauge (IP)]]&lt;br /&gt;
* [[Real time Bethe-Salpeter Equation (density_matrix_only)|Linear response using the density matrix (TD-HSEX)]]&lt;br /&gt;
* [[Linear response from real time simulations|Linear response from real time simulations (IP &amp;amp; TD-HSEX)]] (modular tutorial)&lt;br /&gt;
&lt;br /&gt;
=== Non-Linear response ===&lt;br /&gt;
* [[Real time approach to non-linear response (SHG)]]&lt;br /&gt;
* [[Correlation effects in the non-linear response]]&lt;br /&gt;
* [[SHG within the TD-HSEX level (also called TD-aGW or TD-BSE)]]&lt;br /&gt;
* [[A fast approach to excitonic effects in linear/non-linear response]]&lt;br /&gt;
* [[Angular dependence of non-linear response]]&lt;br /&gt;
* [[Third Harmonic Generation (THG)]]&lt;br /&gt;
* [http://www.attaccalite.com/lumen/spin_orbit.html Spin-orbit coupling and non-linear response] (external tutorial on www.attaccalite.com)&lt;br /&gt;
* [[Two-photon absorption]]&lt;br /&gt;
* [[Parallelization for non-linear response calculations]]&lt;br /&gt;
&lt;br /&gt;
=== Pump and Probe experiments ===&lt;br /&gt;
* [[Nonequilibrium absorption in bulk silicon|Pump and Probe: Transient Absorption from BSE with NEQ occupations]]&lt;br /&gt;
* [[Pump and Probe|Pump and Probe: Transient Absorption from real time propagation with pump and probe]]&lt;br /&gt;
* [[Pump and Probe: Time resolved ARPES|Pump and Probe: Time resolved ARPES from real time propagation with pump]]&lt;br /&gt;
* [[Pump and Probe: reading electronic occuations from Perturbo code]]&lt;br /&gt;
&lt;br /&gt;
== Developing Yambo ==&lt;br /&gt;
* [[How to create a new project in Yambo]]&lt;br /&gt;
* [[How to create a new ypp interface]]&lt;br /&gt;
* [[Some hints on github]]&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
* [[SOC|Spin-Orbit Coupling MBPT]]&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- For each TUTORIAL (Solid_LiF, Solid_Al, ...) , therefore, you can download the ground state files (zip archive named TUTORIAL_ground_state.zip) and generate the Yambo databases from your own by running abinit/PWscf and a2y/p2y. In this case the Yambo input and reference files are contained in the zip file (TUTORIAL_reference_files.zip). Alternatively, if (and only if) you have compiled yambo with the NetCDF support you can directly download the zip files containing the Yambo core databases (TUTORIAL_NETCDF_databases_and_reference_files.zip). These are generated using the NetCDF interface in order to be readable in any platform.&lt;br /&gt;
After you have downloaded the tutorial zip files and unziped them you should have now a tutorial tree:&lt;br /&gt;
localhost:&amp;gt; ls &lt;br /&gt;
YAMBO_TUTORIALS/&lt;br /&gt;
localhost:&amp;gt; ls  YAMBO_TUTORIALS/&lt;br /&gt;
COPYING  Fantastic_Dimensions/  Hydrogen_Chain/  README  Solid_LiF/ Solid_Al/ SiH4/ ...&lt;br /&gt;
In each folder you will find an Abinit or Pwscf subfolder in case you have downloaded the ground state zip files and the YAMBO subfolder. The tutorials start by entering the YAMBO subfolder and followinf the informations provided in the tutorial documentation.  --&amp;gt;&lt;/div&gt;</summary>
		<author><name>Attacc</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Tutorials_all&amp;diff=9189</id>
		<title>Tutorials all</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Tutorials_all&amp;diff=9189"/>
		<updated>2025-10-27T18:38:59Z</updated>

		<summary type="html">&lt;p&gt;Attacc: /* Non-Linear response */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page contains the full list of available tutorials. These cover a variety of mixed topics, both physical and methodological. Some of these are om &amp;quot;Standalone mode&amp;quot; and are designed to be followed from start to finish in one page. Others have been ported in &amp;quot;Modular form&amp;quot;. These are also available under the link [[Tutorials modular]]. The tutorials do not require previous knowledge of yambo, unless explicitly specified. Each tutorial requires download of a specific core database, and typically they cover a specific physical system (like bulk GaSb or a hydrogen chain). Ground state input files and pseudopotentials are provided. Output files are also provided for reference.&lt;br /&gt;
&lt;br /&gt;
These tutorials can be accessed directly from this page of from the side bar. They include different kind of subjects:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Warning&#039;&#039;&#039;: These tutorials were prepared using previous version of the Yambo code: some command lines, variables, reports and outputs can be  slightly different from the last version of the code.  Scripts for parsing output cannot work anymore and should be edited to work with the new outputs. New command lines can be accessed typing &amp;lt;code&amp;gt;yambo -h &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic ==&lt;br /&gt;
* [[First steps: a walk through from DFT to optical properties]] (modular tutorial)&lt;br /&gt;
* [[Silicon|GW on bulk silicon]]&lt;br /&gt;
* [[GW on h-BN (standalone)|GW on h-BN]] (standalone version);  [[How to obtain the quasi-particle band structure of a bulk material: h-BN|GW on h-BN]] (modular version)&lt;br /&gt;
* [[LiF|BSE in lithium-floride]]&lt;br /&gt;
* [[BSE tutorial on hBN]]&lt;br /&gt;
* [[How to analyse excitons]]&lt;br /&gt;
&lt;br /&gt;
== More on GW and Quasi-particles ==&lt;br /&gt;
* [[Real_Axis_and_Lifetimes|Real Axis and Lifetimes]]&lt;br /&gt;
* [[Self-consistent GW on eigenvalues only]]&lt;br /&gt;
* [[GW parallel strategies|GW parallel strategies v1]]; [[GW parallel strategies CECAM|GW parallel strategies v2]];  [[Pushing convergence in parallel|GW convergence in parallel]] (modular tutorials)&lt;br /&gt;
* [[GW tutorial on HPC]] (external tutorial on HackMD)&lt;br /&gt;
* [[Quasi-particles and Self-energy within the Multipole Approximation (MPA)]]&lt;br /&gt;
* [http://www.attaccalite.com/gw-correction-on-an-arbitrary-point-of-the-brillouin-zone GW on arbitrary k point] (external tutorial on www.attaccalite.com)&lt;br /&gt;
&lt;br /&gt;
== More on Linear response and BSE ==&lt;br /&gt;
* [[Hydrogen chain|TDDFT Failure and long range correlations]]&lt;br /&gt;
* [[SOC|Spin-orbit coupling in GaSb]]&lt;br /&gt;
* [[The magneto-optical Kerr effect|The magneto-optical Kerr effect in bulk iron, RPA]]&lt;br /&gt;
* [[The magneto-optical Kerr effect including excitonic effects|The magneto-optical Kerr effect in XXX, excitonic effects]] (todo)&lt;br /&gt;
* [[Dichroism in molecules]]&lt;br /&gt;
* [[Surface spectroscopy]] (to restore from older version)&lt;br /&gt;
* [[Si_Surface|Linear Response of a silicon surface (2D)]]&lt;br /&gt;
* [http://www.attaccalite.com/speed-up-dielectric-constant-calculations-using-the-double-grid-method-with-yambo/ Speed up dielectric constant calculations using the double-grid method] (to be imported)&lt;br /&gt;
* [[Si_wire|Linear Response from a silicon wire (1D)]] (to restore from old version)&lt;br /&gt;
* [[H2|H2 molecule: Linear Response &amp;amp; TDDFT (0D)]] (to restore from old version)&lt;br /&gt;
* [[SiH4|SiH4: isolated molecule TDDFT &amp;amp; BSE (0D)]] (restored from old version, still to be finalized)&lt;br /&gt;
&lt;br /&gt;
== Post Processing with ypp ==&lt;br /&gt;
* [[Yambo Post Processing (ypp)]]&lt;br /&gt;
&lt;br /&gt;
== Electron phonon coupling ==&lt;br /&gt;
* [[Electron Phonon Coupling|Electron Phonon Coupling]]&lt;br /&gt;
* [[Optical properties at finite temperature]]&lt;br /&gt;
* [[Phonon-assisted luminescence by finite atomic displacements]]&lt;br /&gt;
* [[Exciton-phonon coupling and luminescence]]&lt;br /&gt;
&lt;br /&gt;
== Real time &amp;amp; Non linear response ==&lt;br /&gt;
=== Linear response ===&lt;br /&gt;
* [[Linear response from real time simulations (density matrix only)|Linear response using the density matrix (IP)]]&lt;br /&gt;
* [[Linear response using Dynamical Berry Phase|Linear response using wave-functions and Dynamical Berry Phase (IP)]]&lt;br /&gt;
* [[Linear response in velocity gauge|Linear response using wave-functions in velocity gauge (IP)]]&lt;br /&gt;
* [[Real time Bethe-Salpeter Equation (density_matrix_only)|Linear response using the density matrix (TD-HSEX)]]&lt;br /&gt;
* [[Linear response from real time simulations|Linear response from real time simulations (IP &amp;amp; TD-HSEX)]] (modular tutorial)&lt;br /&gt;
&lt;br /&gt;
=== Non-Linear response ===&lt;br /&gt;
* [[Real time approach to non-linear response (SHG)]]&lt;br /&gt;
* [[Correlation effects in the non-linear response]]&lt;br /&gt;
* [[SHG within the TD-HSEX level (also called TD-aGW or TD-BSE)]]&lt;br /&gt;
* [[A fast approach to excitonic effects in linear/non-linear response]]&lt;br /&gt;
* [[Angular dependence of non-linear response]]&lt;br /&gt;
* [[Third Harmonic Generation (THG)]]&lt;br /&gt;
* [http://www.attaccalite.com/lumen/spin_orbit.html Spin-orbit coupling and non-linear response] (external tutorial on www.attaccalite.com)&lt;br /&gt;
* [[Two-photon absorption]]&lt;br /&gt;
* [[Sum frequency generation]] &lt;br /&gt;
* [[Parallelization for non-linear response calculations]]&lt;br /&gt;
&lt;br /&gt;
=== Pump and Probe experiments ===&lt;br /&gt;
* [[Nonequilibrium absorption in bulk silicon|Pump and Probe: Transient Absorption from BSE with NEQ occupations]]&lt;br /&gt;
* [[Pump and Probe|Pump and Probe: Transient Absorption from real time propagation with pump and probe]]&lt;br /&gt;
* [[Pump and Probe: Time resolved ARPES|Pump and Probe: Time resolved ARPES from real time propagation with pump]]&lt;br /&gt;
* [[Pump and Probe: reading electronic occuations from Perturbo code]]&lt;br /&gt;
&lt;br /&gt;
== Developing Yambo ==&lt;br /&gt;
* [[How to create a new project in Yambo]]&lt;br /&gt;
* [[How to create a new ypp interface]]&lt;br /&gt;
* [[Some hints on github]]&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
* [[SOC|Spin-Orbit Coupling MBPT]]&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- For each TUTORIAL (Solid_LiF, Solid_Al, ...) , therefore, you can download the ground state files (zip archive named TUTORIAL_ground_state.zip) and generate the Yambo databases from your own by running abinit/PWscf and a2y/p2y. In this case the Yambo input and reference files are contained in the zip file (TUTORIAL_reference_files.zip). Alternatively, if (and only if) you have compiled yambo with the NetCDF support you can directly download the zip files containing the Yambo core databases (TUTORIAL_NETCDF_databases_and_reference_files.zip). These are generated using the NetCDF interface in order to be readable in any platform.&lt;br /&gt;
After you have downloaded the tutorial zip files and unziped them you should have now a tutorial tree:&lt;br /&gt;
localhost:&amp;gt; ls &lt;br /&gt;
YAMBO_TUTORIALS/&lt;br /&gt;
localhost:&amp;gt; ls  YAMBO_TUTORIALS/&lt;br /&gt;
COPYING  Fantastic_Dimensions/  Hydrogen_Chain/  README  Solid_LiF/ Solid_Al/ SiH4/ ...&lt;br /&gt;
In each folder you will find an Abinit or Pwscf subfolder in case you have downloaded the ground state zip files and the YAMBO subfolder. The tutorials start by entering the YAMBO subfolder and followinf the informations provided in the tutorial documentation.  --&amp;gt;&lt;/div&gt;</summary>
		<author><name>Attacc</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Shift_current&amp;diff=9188</id>
		<title>Shift current</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Shift_current&amp;diff=9188"/>
		<updated>2025-10-27T18:38:45Z</updated>

		<summary type="html">&lt;p&gt;Attacc: Blanked the page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Attacc</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Tutorials_all&amp;diff=9187</id>
		<title>Tutorials all</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Tutorials_all&amp;diff=9187"/>
		<updated>2025-10-27T07:44:28Z</updated>

		<summary type="html">&lt;p&gt;Attacc: /* Electron phonon coupling */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This page contains the full list of available tutorials. These cover a variety of mixed topics, both physical and methodological. Some of these are om &amp;quot;Standalone mode&amp;quot; and are designed to be followed from start to finish in one page. Others have been ported in &amp;quot;Modular form&amp;quot;. These are also available under the link [[Tutorials modular]]. The tutorials do not require previous knowledge of yambo, unless explicitly specified. Each tutorial requires download of a specific core database, and typically they cover a specific physical system (like bulk GaSb or a hydrogen chain). Ground state input files and pseudopotentials are provided. Output files are also provided for reference.&lt;br /&gt;
&lt;br /&gt;
These tutorials can be accessed directly from this page of from the side bar. They include different kind of subjects:&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Warning&#039;&#039;&#039;: These tutorials were prepared using previous version of the Yambo code: some command lines, variables, reports and outputs can be  slightly different from the last version of the code.  Scripts for parsing output cannot work anymore and should be edited to work with the new outputs. New command lines can be accessed typing &amp;lt;code&amp;gt;yambo -h &amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Basic ==&lt;br /&gt;
* [[First steps: a walk through from DFT to optical properties]] (modular tutorial)&lt;br /&gt;
* [[Silicon|GW on bulk silicon]]&lt;br /&gt;
* [[GW on h-BN (standalone)|GW on h-BN]] (standalone version);  [[How to obtain the quasi-particle band structure of a bulk material: h-BN|GW on h-BN]] (modular version)&lt;br /&gt;
* [[LiF|BSE in lithium-floride]]&lt;br /&gt;
* [[BSE tutorial on hBN]]&lt;br /&gt;
* [[How to analyse excitons]]&lt;br /&gt;
&lt;br /&gt;
== More on GW and Quasi-particles ==&lt;br /&gt;
* [[Real_Axis_and_Lifetimes|Real Axis and Lifetimes]]&lt;br /&gt;
* [[Self-consistent GW on eigenvalues only]]&lt;br /&gt;
* [[GW parallel strategies|GW parallel strategies v1]]; [[GW parallel strategies CECAM|GW parallel strategies v2]];  [[Pushing convergence in parallel|GW convergence in parallel]] (modular tutorials)&lt;br /&gt;
* [[GW tutorial on HPC]] (external tutorial on HackMD)&lt;br /&gt;
* [[Quasi-particles and Self-energy within the Multipole Approximation (MPA)]]&lt;br /&gt;
* [http://www.attaccalite.com/gw-correction-on-an-arbitrary-point-of-the-brillouin-zone GW on arbitrary k point] (external tutorial on www.attaccalite.com)&lt;br /&gt;
&lt;br /&gt;
== More on Linear response and BSE ==&lt;br /&gt;
* [[Hydrogen chain|TDDFT Failure and long range correlations]]&lt;br /&gt;
* [[SOC|Spin-orbit coupling in GaSb]]&lt;br /&gt;
* [[The magneto-optical Kerr effect|The magneto-optical Kerr effect in bulk iron, RPA]]&lt;br /&gt;
* [[The magneto-optical Kerr effect including excitonic effects|The magneto-optical Kerr effect in XXX, excitonic effects]] (todo)&lt;br /&gt;
* [[Dichroism in molecules]]&lt;br /&gt;
* [[Surface spectroscopy]] (to restore from older version)&lt;br /&gt;
* [[Si_Surface|Linear Response of a silicon surface (2D)]]&lt;br /&gt;
* [http://www.attaccalite.com/speed-up-dielectric-constant-calculations-using-the-double-grid-method-with-yambo/ Speed up dielectric constant calculations using the double-grid method] (to be imported)&lt;br /&gt;
* [[Si_wire|Linear Response from a silicon wire (1D)]] (to restore from old version)&lt;br /&gt;
* [[H2|H2 molecule: Linear Response &amp;amp; TDDFT (0D)]] (to restore from old version)&lt;br /&gt;
* [[SiH4|SiH4: isolated molecule TDDFT &amp;amp; BSE (0D)]] (restored from old version, still to be finalized)&lt;br /&gt;
&lt;br /&gt;
== Post Processing with ypp ==&lt;br /&gt;
* [[Yambo Post Processing (ypp)]]&lt;br /&gt;
&lt;br /&gt;
== Electron phonon coupling ==&lt;br /&gt;
* [[Electron Phonon Coupling|Electron Phonon Coupling]]&lt;br /&gt;
* [[Optical properties at finite temperature]]&lt;br /&gt;
* [[Phonon-assisted luminescence by finite atomic displacements]]&lt;br /&gt;
* [[Exciton-phonon coupling and luminescence]]&lt;br /&gt;
&lt;br /&gt;
== Real time &amp;amp; Non linear response ==&lt;br /&gt;
=== Linear response ===&lt;br /&gt;
* [[Linear response from real time simulations (density matrix only)|Linear response using the density matrix (IP)]]&lt;br /&gt;
* [[Linear response using Dynamical Berry Phase|Linear response using wave-functions and Dynamical Berry Phase (IP)]]&lt;br /&gt;
* [[Linear response in velocity gauge|Linear response using wave-functions in velocity gauge (IP)]]&lt;br /&gt;
* [[Real time Bethe-Salpeter Equation (density_matrix_only)|Linear response using the density matrix (TD-HSEX)]]&lt;br /&gt;
* [[Linear response from real time simulations|Linear response from real time simulations (IP &amp;amp; TD-HSEX)]] (modular tutorial)&lt;br /&gt;
&lt;br /&gt;
=== Non-Linear response ===&lt;br /&gt;
* [[Real time approach to non-linear response (SHG)]]&lt;br /&gt;
* [[Correlation effects in the non-linear response]]&lt;br /&gt;
* [[SHG within the TD-HSEX level (also called TD-aGW or TD-BSE)]]&lt;br /&gt;
* [[A fast approach to excitonic effects in linear/non-linear response]]&lt;br /&gt;
* [[Angular dependence of non-linear response]]&lt;br /&gt;
* [[Third Harmonic Generation (THG)]]&lt;br /&gt;
* [http://www.attaccalite.com/lumen/spin_orbit.html Spin-orbit coupling and non-linear response] (external tutorial on www.attaccalite.com)&lt;br /&gt;
* [[Two-photon absorption]]&lt;br /&gt;
* [[Sum frequency generation]] &lt;br /&gt;
* [[Shift current]]&lt;br /&gt;
* [[Parallelization for non-linear response calculations]]&lt;br /&gt;
&lt;br /&gt;
=== Pump and Probe experiments ===&lt;br /&gt;
* [[Nonequilibrium absorption in bulk silicon|Pump and Probe: Transient Absorption from BSE with NEQ occupations]]&lt;br /&gt;
* [[Pump and Probe|Pump and Probe: Transient Absorption from real time propagation with pump and probe]]&lt;br /&gt;
* [[Pump and Probe: Time resolved ARPES|Pump and Probe: Time resolved ARPES from real time propagation with pump]]&lt;br /&gt;
* [[Pump and Probe: reading electronic occuations from Perturbo code]]&lt;br /&gt;
&lt;br /&gt;
== Developing Yambo ==&lt;br /&gt;
* [[How to create a new project in Yambo]]&lt;br /&gt;
* [[How to create a new ypp interface]]&lt;br /&gt;
* [[Some hints on github]]&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
* [[SOC|Spin-Orbit Coupling MBPT]]&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- For each TUTORIAL (Solid_LiF, Solid_Al, ...) , therefore, you can download the ground state files (zip archive named TUTORIAL_ground_state.zip) and generate the Yambo databases from your own by running abinit/PWscf and a2y/p2y. In this case the Yambo input and reference files are contained in the zip file (TUTORIAL_reference_files.zip). Alternatively, if (and only if) you have compiled yambo with the NetCDF support you can directly download the zip files containing the Yambo core databases (TUTORIAL_NETCDF_databases_and_reference_files.zip). These are generated using the NetCDF interface in order to be readable in any platform.&lt;br /&gt;
After you have downloaded the tutorial zip files and unziped them you should have now a tutorial tree:&lt;br /&gt;
localhost:&amp;gt; ls &lt;br /&gt;
YAMBO_TUTORIALS/&lt;br /&gt;
localhost:&amp;gt; ls  YAMBO_TUTORIALS/&lt;br /&gt;
COPYING  Fantastic_Dimensions/  Hydrogen_Chain/  README  Solid_LiF/ Solid_Al/ SiH4/ ...&lt;br /&gt;
In each folder you will find an Abinit or Pwscf subfolder in case you have downloaded the ground state zip files and the YAMBO subfolder. The tutorials start by entering the YAMBO subfolder and followinf the informations provided in the tutorial documentation.  --&amp;gt;&lt;/div&gt;</summary>
		<author><name>Attacc</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Thermal_lines_and_special_displacements_with_YamboPy&amp;diff=9186</id>
		<title>Thermal lines and special displacements with YamboPy</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Thermal_lines_and_special_displacements_with_YamboPy&amp;diff=9186"/>
		<updated>2025-10-27T07:42:23Z</updated>

		<summary type="html">&lt;p&gt;Attacc: Blanked the page&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Attacc</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Exciton-phonon_coupling_and_luminescence&amp;diff=9177</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=9177"/>
		<updated>2025-10-06T12:25:50Z</updated>

		<summary type="html">&lt;p&gt;Attacc: /* Analysis of the couplings */&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://gitlab.com/lumen-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.&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. 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. &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 --debug&lt;br /&gt;
&lt;br /&gt;
At the end, check the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 ls SAVE/ndb.elph_gkkp*&lt;br /&gt;
&lt;br /&gt;
to see that it has created the Yambo-compatible electron-phonon databases.&lt;br /&gt;
&lt;br /&gt;
If you saved the &amp;lt;code&amp;gt;lelphc.in&amp;lt;/code&amp;gt; input file, you can 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;
You can also run it as it is, but the code will generate the database &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt;. In order to convert it to the &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases of Yambo, you still 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;
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;
== 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;. In this version of the tutorial we present the latter case.&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,q) - \sum_{cc^\prime vk} A^{\alpha, *}_{c^\prime v} (k+q, q) g_{c^\prime c}^\mu (k+q,q) A^{\lambda}_{cv}(k,q)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here, &amp;lt;math&amp;gt;A^{\lambda}_{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;
&lt;br /&gt;
We have to write a new yambo input, that we can call &amp;lt;code&amp;gt;excph.in&amp;lt;/code&amp;gt;, for this. You can copy (and adapt) the one below, or you can generate one by running from the command line:&lt;br /&gt;
&lt;br /&gt;
 yambo_ph -excph o&lt;br /&gt;
&lt;br /&gt;
This generates an input to compute luminescence (&amp;quot;o&amp;quot; is for &amp;quot;optics&amp;quot;). The variables that we are interested in are:&lt;br /&gt;
&lt;br /&gt;
 excph                            # [R] Exction-phonon&lt;br /&gt;
 ExcGkkp                          # [R][EXCPH] Exciton-Phonon Matrix Elelements&lt;br /&gt;
 % ELPhExcStates&lt;br /&gt;
  1 | 4 |                             # [EXCPH] Incoming (external) exciton states&lt;br /&gt;
 %&lt;br /&gt;
 % ELPhExcSum&lt;br /&gt;
  1 | 12 |                             # [EXCPH] Outgoing (virtual) exciton states&lt;br /&gt;
 %&lt;br /&gt;
 LoutPath= &amp;quot;./bse_Lfull&amp;quot;                 # [EXCPH] Path of the outgoing L&lt;br /&gt;
 % ElPhModes&lt;br /&gt;
   1 | 9 |                           # [ELPH] Phonon modes included&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
In this input, we have to select the initial exciton states &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; with &amp;lt;code&amp;gt;ELPhExcStates&amp;lt;/code&amp;gt;, the final exciton states &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; with &amp;lt;code&amp;gt;ELPhExcSum&amp;lt;/code&amp;gt; and the phonon modes &amp;lt;math&amp;gt;\mu&amp;lt;/math&amp;gt; with &amp;lt;code&amp;gt;ElPhModes&amp;lt;/code&amp;gt;. Here we consider the first four states at &amp;lt;math&amp;gt;Q=0&amp;lt;/math&amp;gt; (corresponding to just two excitons because they are both doubly degenerate -- do not break degeneracies when selecting states!) and the first twelve states at each finite-&amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; point. We also include all the nine phonon modes of monolayer MoS2.&lt;br /&gt;
&lt;br /&gt;
What about &amp;lt;code&amp;gt;LoutPath&amp;lt;/code&amp;gt;? This variable controls the directory where the databases for the final-state excitons &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; is located, which can be different from the directory with the initial-state excitons &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; read as usual with the &amp;lt;code&amp;gt;-J&amp;lt;/code&amp;gt; option when running the code. This makes it possible to compute the coupling between different exciton kinds. However, for our tutorial, we stick with the previously computed &amp;lt;code&amp;gt;Lfull&amp;lt;/code&amp;gt; in both cases.&lt;br /&gt;
&lt;br /&gt;
When we are satisfied with the input, we run the code using &amp;lt;code&amp;gt;yambo_ph&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 yambo_ph -F excph.in -J excph,bse_Lfull -C excph&lt;br /&gt;
&lt;br /&gt;
If you check the output, you should find the &amp;lt;code&amp;gt;ndb.excph*&amp;lt;/code&amp;gt; databases in the &amp;lt;code&amp;gt;excph&amp;lt;/code&amp;gt; directory.&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 using the &amp;lt;code&amp;gt;YamboExcitonPhononDB&amp;lt;/code&amp;gt; from yambopy. &lt;br /&gt;
You can find 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;
 # Exciton in states&lt;br /&gt;
 exc_in  = [2,3]     # A: 2,3 -- B: 6,7&lt;br /&gt;
 exc_out = [0,1,2,3] # first 4 states (dispersion of triplet state and A)&lt;br /&gt;
 ph_in  = &#039;all&#039;&lt;br /&gt;
 &lt;br /&gt;
 # Paths of databases&lt;br /&gt;
 ns_db1 =f&#039;{path}/SAVE/ns.db1&#039;&lt;br /&gt;
 ndb_exc=f&#039;{path}/excph&#039;&lt;br /&gt;
 &lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
Then, we load the data:&lt;br /&gt;
&lt;br /&gt;
 # Read lattice and k-space info&lt;br /&gt;
 ylat = YamboLatticeDB.from_db_file(filename=ns_db1),Expand=True)&lt;br /&gt;
 print(ylat)&lt;br /&gt;
 &lt;br /&gt;
 # Read exc-ph databases&lt;br /&gt;
 X = YamboExcitonPhononDB(ylat,save_excph=ndb_exc)&lt;br /&gt;
 print(X)&lt;br /&gt;
&lt;br /&gt;
The quantity &amp;lt;math&amp;gt;F_A(q)&amp;lt;/math&amp;gt; is defined inside the plotting function as&lt;br /&gt;
&lt;br /&gt;
 G_squared = excph.excph_sq&lt;br /&gt;
 G2plt = np.zeros(len(G_squared))&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 # Switch from Ha to eV&lt;br /&gt;
&lt;br /&gt;
And finally, we have to make a plotting function. For this tutorial we will use the default scatterplot provided by &amp;lt;code&amp;gt;YamboExcitonPhononDB&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 excph.plot_excph(F_q,plt_cbar=plt_cbar,**kwargs)&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 this 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 ExcPh.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^{(1)}_{PL}(\omega;T) \propto \frac{1}{N_q}\sum_{ s \mu \beta q} \left|\sum_\lambda\frac{D_\lambda \mathcal{G}^{\mu q}_{\alpha q,\lambda}}{E_{\alpha q}-E_\lambda -s\Omega_{\mu q}} \right|^2 N_{\alpha q}(T_{exc}) F^s_{\mu q}(T)\delta(\omega - \left[E_{\alpha q}-s\Omega_{\mu q}\right])&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;
The occupation function &amp;lt;math&amp;gt;F&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;F^s_{\mu q}(T)=n_{\mu q}(T)+\frac{1+s}{2}&amp;lt;/math&amp;gt;. Here, &amp;lt;math&amp;gt;n(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^{(1)}_{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;
=== 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 yambopy to get the el-ph matrix elements:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph path/of/dvscf/hbn.dvscf -b 7 10 -par 4 2 &lt;br /&gt;
&lt;br /&gt;
6. And finally we generate the exciton-phonon input &amp;lt;code&amp;gt;excph.in&amp;lt;/code&amp;gt; using &amp;lt;code&amp;gt;yambo_ph -excph o&amp;lt;/code&amp;gt;. Now, we take a look at all the additional variables that we didn&#039;t check before, specifying also the details for luminescence the spectrum calculation.&lt;br /&gt;
&lt;br /&gt;
 excph                            # [R] Exction-phonon&lt;br /&gt;
 ExcGkkp                          # [R][EXCPH] Exciton-Phonon Matrix Elelements&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;ExcPhOptics                      # [R][EXCPH] Exciton-Phonon Optics&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;BoseTemp=10.000000         Kn    # Bosonic Temperature&amp;lt;/span&amp;gt; &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;EXCTemp= 10.000000          Kn    # [EXCPH] Excitonic Temperature (for luminescence spectra)&amp;lt;/span&amp;gt;&lt;br /&gt;
 % ELPhExcStates&lt;br /&gt;
  1 | 4 |                             # [EXCPH] Incoming (external) exciton states&lt;br /&gt;
 %&lt;br /&gt;
 % ELPhExcSum&lt;br /&gt;
  1 | 12 |                             # [EXCPH] Outgoing (virtual) exciton states&lt;br /&gt;
 %&lt;br /&gt;
 % ElPhModes&lt;br /&gt;
  1 | 12 |                           # [ELPH] Phonon modes included&lt;br /&gt;
 %&lt;br /&gt;
 LoutPath= &amp;quot;./bse-L_full&amp;quot;                 # [EXCPH] Path of the outgoing L&lt;br /&gt;
 FANdEtresh= 0.100000E-5    eV    # [ELPH] Energy treshold for Fan denominator&lt;br /&gt;
 EXCPHdEtresh= 0.100000E-5  eV    # [ELPH] Energy treshold for exc-ph denominator&lt;br /&gt;
 LDamping= 0.500000E-3      eV    # [EXCPH] Damping of exc-ph self-energy&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# These are the plot parameters, same as in other parts of yambo&amp;lt;/span&amp;gt; &lt;br /&gt;
 % EnRngeXd&lt;br /&gt;
   4.00000 | 5.00000 |         eV    # [Xd] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 % DmRngeXd&lt;br /&gt;
  0.00500000 | 0.00500000 |         eV    # [Xd] Damping range&lt;br /&gt;
 %&lt;br /&gt;
 ETStpsXd= 4000                    # [Xd] Total Energy steps&lt;br /&gt;
&lt;br /&gt;
Here &amp;lt;code&amp;gt;BoseTemp&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXCTemp&amp;lt;/code&amp;gt; are the lattice and excitonic temperature, respectively.&lt;br /&gt;
&lt;br /&gt;
Now we run the calculation with &amp;lt;code&amp;gt;yambo_ph&amp;lt;/code&amp;gt;. Here, we read as &amp;lt;math&amp;gt;Q=0&amp;lt;/math&amp;gt; excitons with &amp;lt;code&amp;gt;-J&amp;lt;/code&amp;gt; the ones without the long-range Coulomb exchange:&lt;br /&gt;
&lt;br /&gt;
 yambo_ph -F excph.in -J excph,bse_Lbar -C excph&lt;br /&gt;
&lt;br /&gt;
and we find our outputs in the &amp;lt;code&amp;gt;excph&amp;lt;/code&amp;gt; directory. &lt;br /&gt;
&lt;br /&gt;
NB: Step 6 could have been equivalently run in yambopy, limiting the use of the yambo code to just step 4. This latter option is more flexible, as it allows for a greater degree of control by the user. We are in the last stages of the development and it will be available soon.&lt;br /&gt;
&lt;br /&gt;
=== Results ===&lt;br /&gt;
&lt;br /&gt;
If we check the output directory from the step 6 calculation, we find the &amp;lt;code&amp;gt;o-excph.pl_bse_ph_ass&amp;lt;/code&amp;gt; output files containing the luminescence spectra. We can plot them with gnuplot or any other tool:&lt;br /&gt;
&lt;br /&gt;
 gnuplot&lt;br /&gt;
 &amp;gt; set xrange[4.2:5]&lt;br /&gt;
 &amp;gt; p &#039;o-excph.pl_bse_ph_ass&#039; u 1:2 w l lc rgb &#039;red&#039; lw 3&lt;br /&gt;
&lt;br /&gt;
[[File:Luminescence plot.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;[https://m.booksee.org/book/1121964?force_lang=en Optical processes in solids], Toyozawa, Yutaka, and Chris Oxlade. 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;[https://www.yambo-code.eu/wiki/images/5/54/These_final.pdf Exciton-phonon coupling and phonon-assisted luminescence in hexagonal Boron Nitride nanostructures], PhD Thesis, Pierre Lechifflart (2023)&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;[https://arxiv.org/abs/2305.17554 Distinguishing different stackings in layered materials via luminescence spectroscopy], M. Zanfrognini et al. Phys. Rev. Lett. &#039;&#039;&#039;131&#039;&#039;&#039;, 206902 (2023) &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;[https://arxiv.org/abs/2205.02783 Exciton-phonon interaction calls for a revision of the “exciton” concept], F. Paleari, A. Marini, Phys. Rev. B, &#039;&#039;&#039;106&#039;&#039;&#039;, 125403 (2022)&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>Attacc</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Exciton-phonon_coupling_and_luminescence&amp;diff=9176</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=9176"/>
		<updated>2025-10-06T12:14:25Z</updated>

		<summary type="html">&lt;p&gt;Attacc: &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://gitlab.com/lumen-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.&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. 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. &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 --debug&lt;br /&gt;
&lt;br /&gt;
At the end, check the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 ls SAVE/ndb.elph_gkkp*&lt;br /&gt;
&lt;br /&gt;
to see that it has created the Yambo-compatible electron-phonon databases.&lt;br /&gt;
&lt;br /&gt;
If you saved the &amp;lt;code&amp;gt;lelphc.in&amp;lt;/code&amp;gt; input file, you can 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;
You can also run it as it is, but the code will generate the database &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt;. In order to convert it to the &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases of Yambo, you still 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;
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;
== 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;. In this version of the tutorial we present the latter case.&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,q) - \sum_{cc^\prime vk} A^{\alpha, *}_{c^\prime v} (k+q, q) g_{c^\prime c}^\mu (k+q,q) A^{\lambda}_{cv}(k,q)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here, &amp;lt;math&amp;gt;A^{\lambda}_{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;
&lt;br /&gt;
We have to write a new yambo input, that we can call &amp;lt;code&amp;gt;excph.in&amp;lt;/code&amp;gt;, for this. You can copy (and adapt) the one below, or you can generate one by running from the command line:&lt;br /&gt;
&lt;br /&gt;
 yambo_ph -excph o&lt;br /&gt;
&lt;br /&gt;
This generates an input to compute luminescence (&amp;quot;o&amp;quot; is for &amp;quot;optics&amp;quot;). The variables that we are interested in are:&lt;br /&gt;
&lt;br /&gt;
 excph                            # [R] Exction-phonon&lt;br /&gt;
 ExcGkkp                          # [R][EXCPH] Exciton-Phonon Matrix Elelements&lt;br /&gt;
 % ELPhExcStates&lt;br /&gt;
  1 | 4 |                             # [EXCPH] Incoming (external) exciton states&lt;br /&gt;
 %&lt;br /&gt;
 % ELPhExcSum&lt;br /&gt;
  1 | 12 |                             # [EXCPH] Outgoing (virtual) exciton states&lt;br /&gt;
 %&lt;br /&gt;
 LoutPath= &amp;quot;./bse_Lfull&amp;quot;                 # [EXCPH] Path of the outgoing L&lt;br /&gt;
 % ElPhModes&lt;br /&gt;
   1 | 9 |                           # [ELPH] Phonon modes included&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
In this input, we have to select the initial exciton states &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; with &amp;lt;code&amp;gt;ELPhExcStates&amp;lt;/code&amp;gt;, the final exciton states &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; with &amp;lt;code&amp;gt;ELPhExcSum&amp;lt;/code&amp;gt; and the phonon modes &amp;lt;math&amp;gt;\mu&amp;lt;/math&amp;gt; with &amp;lt;code&amp;gt;ElPhModes&amp;lt;/code&amp;gt;. Here we consider the first four states at &amp;lt;math&amp;gt;Q=0&amp;lt;/math&amp;gt; (corresponding to just two excitons because they are both doubly degenerate -- do not break degeneracies when selecting states!) and the first twelve states at each finite-&amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; point. We also include all the nine phonon modes of monolayer MoS2.&lt;br /&gt;
&lt;br /&gt;
What about &amp;lt;code&amp;gt;LoutPath&amp;lt;/code&amp;gt;? This variable controls the directory where the databases for the final-state excitons &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; is located, which can be different from the directory with the initial-state excitons &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; read as usual with the &amp;lt;code&amp;gt;-J&amp;lt;/code&amp;gt; option when running the code. This makes it possible to compute the coupling between different exciton kinds. However, for our tutorial, we stick with the previously computed &amp;lt;code&amp;gt;Lfull&amp;lt;/code&amp;gt; in both cases.&lt;br /&gt;
&lt;br /&gt;
When we are satisfied with the input, we run the code using &amp;lt;code&amp;gt;yambo_ph&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 yambo_ph -F excph.in -J excph,bse_Lfull -C excph&lt;br /&gt;
&lt;br /&gt;
If you check the output, you should find the &amp;lt;code&amp;gt;ndb.excph*&amp;lt;/code&amp;gt; databases in the &amp;lt;code&amp;gt;excph&amp;lt;/code&amp;gt; directory.&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 MoS2, 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 using the &amp;lt;code&amp;gt;YamboExcitonPhononDB&amp;lt;/code&amp;gt; from yambopy. &lt;br /&gt;
You can find 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;
 # Exciton in states&lt;br /&gt;
 exc_in  = [2,3]     # A: 2,3 -- B: 6,7&lt;br /&gt;
 exc_out = [0,1,2,3] # first 4 states (dispersion of triplet state and A)&lt;br /&gt;
 ph_in  = &#039;all&#039;&lt;br /&gt;
 &lt;br /&gt;
 # Paths of databases&lt;br /&gt;
 ns_db1 =f&#039;{path}/SAVE/ns.db1&#039;&lt;br /&gt;
 ndb_exc=f&#039;{path}/excph&#039;&lt;br /&gt;
 &lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
Then, we load the data:&lt;br /&gt;
&lt;br /&gt;
 # Read lattice and k-space info&lt;br /&gt;
 ylat = YamboLatticeDB.from_db_file(filename=ns_db1),Expand=True)&lt;br /&gt;
 print(ylat)&lt;br /&gt;
 &lt;br /&gt;
 # Read exc-ph databases&lt;br /&gt;
 X = YamboExcitonPhononDB(ylat,save_excph=ndb_exc)&lt;br /&gt;
 print(X)&lt;br /&gt;
&lt;br /&gt;
The quantity &amp;lt;math&amp;gt;F_A(q)&amp;lt;/math&amp;gt; is defined inside the plotting function as&lt;br /&gt;
&lt;br /&gt;
 G_squared = excph.excph_sq&lt;br /&gt;
 G2plt = np.zeros(len(G_squared))&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 # Switch from Ha to eV&lt;br /&gt;
&lt;br /&gt;
And finally, we have to make a plotting function. For this tutorial we will use the default scatterplot provided by &amp;lt;code&amp;gt;YamboExcitonPhononDB&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 excph.plot_excph(F_q,plt_cbar=plt_cbar,**kwargs)&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 this 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 ExcPh.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^{(1)}_{PL}(\omega;T) \propto \frac{1}{N_q}\sum_{ s \mu \beta q} \left|\sum_\lambda\frac{D_\lambda \mathcal{G}^{\mu q}_{\alpha q,\lambda}}{E_{\alpha q}-E_\lambda -s\Omega_{\mu q}} \right|^2 N_{\alpha q}(T_{exc}) F^s_{\mu q}(T)\delta(\omega - \left[E_{\alpha q}-s\Omega_{\mu q}\right])&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;
The occupation function &amp;lt;math&amp;gt;F&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;F^s_{\mu q}(T)=n_{\mu q}(T)+\frac{1+s}{2}&amp;lt;/math&amp;gt;. Here, &amp;lt;math&amp;gt;n(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^{(1)}_{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;
=== 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 yambopy to get the el-ph matrix elements:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph path/of/dvscf/hbn.dvscf -b 7 10 -par 4 2 &lt;br /&gt;
&lt;br /&gt;
6. And finally we generate the exciton-phonon input &amp;lt;code&amp;gt;excph.in&amp;lt;/code&amp;gt; using &amp;lt;code&amp;gt;yambo_ph -excph o&amp;lt;/code&amp;gt;. Now, we take a look at all the additional variables that we didn&#039;t check before, specifying also the details for luminescence the spectrum calculation.&lt;br /&gt;
&lt;br /&gt;
 excph                            # [R] Exction-phonon&lt;br /&gt;
 ExcGkkp                          # [R][EXCPH] Exciton-Phonon Matrix Elelements&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;ExcPhOptics                      # [R][EXCPH] Exciton-Phonon Optics&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;BoseTemp=10.000000         Kn    # Bosonic Temperature&amp;lt;/span&amp;gt; &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;EXCTemp= 10.000000          Kn    # [EXCPH] Excitonic Temperature (for luminescence spectra)&amp;lt;/span&amp;gt;&lt;br /&gt;
 % ELPhExcStates&lt;br /&gt;
  1 | 4 |                             # [EXCPH] Incoming (external) exciton states&lt;br /&gt;
 %&lt;br /&gt;
 % ELPhExcSum&lt;br /&gt;
  1 | 12 |                             # [EXCPH] Outgoing (virtual) exciton states&lt;br /&gt;
 %&lt;br /&gt;
 % ElPhModes&lt;br /&gt;
  1 | 12 |                           # [ELPH] Phonon modes included&lt;br /&gt;
 %&lt;br /&gt;
 LoutPath= &amp;quot;./bse-L_full&amp;quot;                 # [EXCPH] Path of the outgoing L&lt;br /&gt;
 FANdEtresh= 0.100000E-5    eV    # [ELPH] Energy treshold for Fan denominator&lt;br /&gt;
 EXCPHdEtresh= 0.100000E-5  eV    # [ELPH] Energy treshold for exc-ph denominator&lt;br /&gt;
 LDamping= 0.500000E-3      eV    # [EXCPH] Damping of exc-ph self-energy&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# These are the plot parameters, same as in other parts of yambo&amp;lt;/span&amp;gt; &lt;br /&gt;
 % EnRngeXd&lt;br /&gt;
   4.00000 | 5.00000 |         eV    # [Xd] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 % DmRngeXd&lt;br /&gt;
  0.00500000 | 0.00500000 |         eV    # [Xd] Damping range&lt;br /&gt;
 %&lt;br /&gt;
 ETStpsXd= 4000                    # [Xd] Total Energy steps&lt;br /&gt;
&lt;br /&gt;
Here &amp;lt;code&amp;gt;BoseTemp&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXCTemp&amp;lt;/code&amp;gt; are the lattice and excitonic temperature, respectively.&lt;br /&gt;
&lt;br /&gt;
Now we run the calculation with &amp;lt;code&amp;gt;yambo_ph&amp;lt;/code&amp;gt;. Here, we read as &amp;lt;math&amp;gt;Q=0&amp;lt;/math&amp;gt; excitons with &amp;lt;code&amp;gt;-J&amp;lt;/code&amp;gt; the ones without the long-range Coulomb exchange:&lt;br /&gt;
&lt;br /&gt;
 yambo_ph -F excph.in -J excph,bse_Lbar -C excph&lt;br /&gt;
&lt;br /&gt;
and we find our outputs in the &amp;lt;code&amp;gt;excph&amp;lt;/code&amp;gt; directory. &lt;br /&gt;
&lt;br /&gt;
NB: Step 6 could have been equivalently run in yambopy, limiting the use of the yambo code to just step 4. This latter option is more flexible, as it allows for a greater degree of control by the user. We are in the last stages of the development and it will be available soon.&lt;br /&gt;
&lt;br /&gt;
=== Results ===&lt;br /&gt;
&lt;br /&gt;
If we check the output directory from the step 6 calculation, we find the &amp;lt;code&amp;gt;o-excph.pl_bse_ph_ass&amp;lt;/code&amp;gt; output files containing the luminescence spectra. We can plot them with gnuplot or any other tool:&lt;br /&gt;
&lt;br /&gt;
 gnuplot&lt;br /&gt;
 &amp;gt; set xrange[4.2:5]&lt;br /&gt;
 &amp;gt; p &#039;o-excph.pl_bse_ph_ass&#039; u 1:2 w l lc rgb &#039;red&#039; lw 3&lt;br /&gt;
&lt;br /&gt;
[[File:Luminescence plot.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;[https://m.booksee.org/book/1121964?force_lang=en Optical processes in solids], Toyozawa, Yutaka, and Chris Oxlade. 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;[https://www.yambo-code.eu/wiki/images/5/54/These_final.pdf Exciton-phonon coupling and phonon-assisted luminescence in hexagonal Boron Nitride nanostructures], PhD Thesis, Pierre Lechifflart (2023)&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;[https://arxiv.org/abs/2305.17554 Distinguishing different stackings in layered materials via luminescence spectroscopy], M. Zanfrognini et al. Phys. Rev. Lett. &#039;&#039;&#039;131&#039;&#039;&#039;, 206902 (2023) &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;[https://arxiv.org/abs/2205.02783 Exciton-phonon interaction calls for a revision of the “exciton” concept], F. Paleari, A. Marini, Phys. Rev. B, &#039;&#039;&#039;106&#039;&#039;&#039;, 125403 (2022)&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>Attacc</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Exciton-phonon_coupling_and_luminescence&amp;diff=9175</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=9175"/>
		<updated>2025-10-06T12:02:17Z</updated>

		<summary type="html">&lt;p&gt;Attacc: &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 (&amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;) and the transfer momenta (&amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt;) 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://gitlab.com/lumen-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.&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. 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. &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 --debug&lt;br /&gt;
&lt;br /&gt;
At the end, check the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 ls SAVE/ndb.elph_gkkp*&lt;br /&gt;
&lt;br /&gt;
to see that it has created the Yambo-compatible electron-phonon databases.&lt;br /&gt;
&lt;br /&gt;
If you saved the &amp;lt;code&amp;gt;lelphc.in&amp;lt;/code&amp;gt; input file, you can 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;
You can also run it as it is, but the code will generate the database &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt;. In order to convert it to the &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases of Yambo, you still 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;
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;
== 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;. In this version of the tutorial we present the latter case.&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,q) - \sum_{cc^\prime vk} A^{\alpha, *}_{c^\prime v} (k+q, q) g_{c^\prime c}^\mu (k+q,q) A^{\lambda}_{cv}(k,q)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here, &amp;lt;math&amp;gt;A^{\lambda}_{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;
&lt;br /&gt;
We have to write a new yambo input, that we can call &amp;lt;code&amp;gt;excph.in&amp;lt;/code&amp;gt;, for this. You can copy (and adapt) the one below, or you can generate one by running from the command line:&lt;br /&gt;
&lt;br /&gt;
 yambo_ph -excph o&lt;br /&gt;
&lt;br /&gt;
This generates an input to compute luminescence (&amp;quot;o&amp;quot; is for &amp;quot;optics&amp;quot;). The variables that we are interested in are:&lt;br /&gt;
&lt;br /&gt;
 excph                            # [R] Exction-phonon&lt;br /&gt;
 ExcGkkp                          # [R][EXCPH] Exciton-Phonon Matrix Elelements&lt;br /&gt;
 % ELPhExcStates&lt;br /&gt;
  1 | 4 |                             # [EXCPH] Incoming (external) exciton states&lt;br /&gt;
 %&lt;br /&gt;
 % ELPhExcSum&lt;br /&gt;
  1 | 12 |                             # [EXCPH] Outgoing (virtual) exciton states&lt;br /&gt;
 %&lt;br /&gt;
 LoutPath= &amp;quot;./bse_Lfull&amp;quot;                 # [EXCPH] Path of the outgoing L&lt;br /&gt;
 % ElPhModes&lt;br /&gt;
   1 | 9 |                           # [ELPH] Phonon modes included&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
In this input, we have to select the initial exciton states &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; with &amp;lt;code&amp;gt;ELPhExcStates&amp;lt;/code&amp;gt;, the final exciton states &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; with &amp;lt;code&amp;gt;ELPhExcSum&amp;lt;/code&amp;gt; and the phonon modes &amp;lt;math&amp;gt;\mu&amp;lt;/math&amp;gt; with &amp;lt;code&amp;gt;ElPhModes&amp;lt;/code&amp;gt;. Here we consider the first four states at &amp;lt;math&amp;gt;Q=0&amp;lt;/math&amp;gt; (corresponding to just two excitons because they are both doubly degenerate -- do not break degeneracies when selecting states!) and the first twelve states at each finite-&amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; point. We also include all the nine phonon modes of monolayer MoS2.&lt;br /&gt;
&lt;br /&gt;
What about &amp;lt;code&amp;gt;LoutPath&amp;lt;/code&amp;gt;? This variable controls the directory where the databases for the final-state excitons &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; is located, which can be different from the directory with the initial-state excitons &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; read as usual with the &amp;lt;code&amp;gt;-J&amp;lt;/code&amp;gt; option when running the code. This makes it possible to compute the coupling between different exciton kinds. However, for our tutorial, we stick with the previously computed &amp;lt;code&amp;gt;Lfull&amp;lt;/code&amp;gt; in both cases.&lt;br /&gt;
&lt;br /&gt;
When we are satisfied with the input, we run the code using &amp;lt;code&amp;gt;yambo_ph&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 yambo_ph -F excph.in -J excph,bse_Lfull -C excph&lt;br /&gt;
&lt;br /&gt;
If you check the output, you should find the &amp;lt;code&amp;gt;ndb.excph*&amp;lt;/code&amp;gt; databases in the &amp;lt;code&amp;gt;excph&amp;lt;/code&amp;gt; directory.&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 MoS2, 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 using the &amp;lt;code&amp;gt;YamboExcitonPhononDB&amp;lt;/code&amp;gt; from yambopy. &lt;br /&gt;
You can find 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;
 # Exciton in states&lt;br /&gt;
 exc_in  = [2,3]     # A: 2,3 -- B: 6,7&lt;br /&gt;
 exc_out = [0,1,2,3] # first 4 states (dispersion of triplet state and A)&lt;br /&gt;
 ph_in  = &#039;all&#039;&lt;br /&gt;
 &lt;br /&gt;
 # Paths of databases&lt;br /&gt;
 ns_db1 =f&#039;{path}/SAVE/ns.db1&#039;&lt;br /&gt;
 ndb_exc=f&#039;{path}/excph&#039;&lt;br /&gt;
 &lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
Then, we load the data:&lt;br /&gt;
&lt;br /&gt;
 # Read lattice and k-space info&lt;br /&gt;
 ylat = YamboLatticeDB.from_db_file(filename=ns_db1),Expand=True)&lt;br /&gt;
 print(ylat)&lt;br /&gt;
 &lt;br /&gt;
 # Read exc-ph databases&lt;br /&gt;
 X = YamboExcitonPhononDB(ylat,save_excph=ndb_exc)&lt;br /&gt;
 print(X)&lt;br /&gt;
&lt;br /&gt;
The quantity &amp;lt;math&amp;gt;F_A(q)&amp;lt;/math&amp;gt; is defined inside the plotting function as&lt;br /&gt;
&lt;br /&gt;
 G_squared = excph.excph_sq&lt;br /&gt;
 G2plt = np.zeros(len(G_squared))&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 # Switch from Ha to eV&lt;br /&gt;
&lt;br /&gt;
And finally, we have to make a plotting function. For this tutorial we will use the default scatterplot provided by &amp;lt;code&amp;gt;YamboExcitonPhononDB&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 excph.plot_excph(F_q,plt_cbar=plt_cbar,**kwargs)&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 this 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 ExcPh.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^{(1)}_{PL}(\omega;T) \propto \frac{1}{N_q}\sum_{ s \mu \beta q} \left|\sum_\lambda\frac{D_\lambda \mathcal{G}^{\mu q}_{\alpha q,\lambda}}{E_{\alpha q}-E_\lambda -s\Omega_{\mu q}} \right|^2 N_{\alpha q}(T_{exc}) F^s_{\mu q}(T)\delta(\omega - \left[E_{\alpha q}-s\Omega_{\mu q}\right])&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;
The occupation function &amp;lt;math&amp;gt;F&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;F^s_{\mu q}(T)=n_{\mu q}(T)+\frac{1+s}{2}&amp;lt;/math&amp;gt;. Here, &amp;lt;math&amp;gt;n(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^{(1)}_{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;
=== 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 yambopy to get the el-ph matrix elements:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph path/of/dvscf/hbn.dvscf -b 7 10 -par 4 2 &lt;br /&gt;
&lt;br /&gt;
6. And finally we generate the exciton-phonon input &amp;lt;code&amp;gt;excph.in&amp;lt;/code&amp;gt; using &amp;lt;code&amp;gt;yambo_ph -excph o&amp;lt;/code&amp;gt;. Now, we take a look at all the additional variables that we didn&#039;t check before, specifying also the details for luminescence the spectrum calculation.&lt;br /&gt;
&lt;br /&gt;
 excph                            # [R] Exction-phonon&lt;br /&gt;
 ExcGkkp                          # [R][EXCPH] Exciton-Phonon Matrix Elelements&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;ExcPhOptics                      # [R][EXCPH] Exciton-Phonon Optics&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;BoseTemp=10.000000         Kn    # Bosonic Temperature&amp;lt;/span&amp;gt; &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;EXCTemp= 10.000000          Kn    # [EXCPH] Excitonic Temperature (for luminescence spectra)&amp;lt;/span&amp;gt;&lt;br /&gt;
 % ELPhExcStates&lt;br /&gt;
  1 | 4 |                             # [EXCPH] Incoming (external) exciton states&lt;br /&gt;
 %&lt;br /&gt;
 % ELPhExcSum&lt;br /&gt;
  1 | 12 |                             # [EXCPH] Outgoing (virtual) exciton states&lt;br /&gt;
 %&lt;br /&gt;
 % ElPhModes&lt;br /&gt;
  1 | 12 |                           # [ELPH] Phonon modes included&lt;br /&gt;
 %&lt;br /&gt;
 LoutPath= &amp;quot;./bse-L_full&amp;quot;                 # [EXCPH] Path of the outgoing L&lt;br /&gt;
 FANdEtresh= 0.100000E-5    eV    # [ELPH] Energy treshold for Fan denominator&lt;br /&gt;
 EXCPHdEtresh= 0.100000E-5  eV    # [ELPH] Energy treshold for exc-ph denominator&lt;br /&gt;
 LDamping= 0.500000E-3      eV    # [EXCPH] Damping of exc-ph self-energy&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# These are the plot parameters, same as in other parts of yambo&amp;lt;/span&amp;gt; &lt;br /&gt;
 % EnRngeXd&lt;br /&gt;
   4.00000 | 5.00000 |         eV    # [Xd] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 % DmRngeXd&lt;br /&gt;
  0.00500000 | 0.00500000 |         eV    # [Xd] Damping range&lt;br /&gt;
 %&lt;br /&gt;
 ETStpsXd= 4000                    # [Xd] Total Energy steps&lt;br /&gt;
&lt;br /&gt;
Here &amp;lt;code&amp;gt;BoseTemp&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXCTemp&amp;lt;/code&amp;gt; are the lattice and excitonic temperature, respectively.&lt;br /&gt;
&lt;br /&gt;
Now we run the calculation with &amp;lt;code&amp;gt;yambo_ph&amp;lt;/code&amp;gt;. Here, we read as &amp;lt;math&amp;gt;Q=0&amp;lt;/math&amp;gt; excitons with &amp;lt;code&amp;gt;-J&amp;lt;/code&amp;gt; the ones without the long-range Coulomb exchange:&lt;br /&gt;
&lt;br /&gt;
 yambo_ph -F excph.in -J excph,bse_Lbar -C excph&lt;br /&gt;
&lt;br /&gt;
and we find our outputs in the &amp;lt;code&amp;gt;excph&amp;lt;/code&amp;gt; directory. &lt;br /&gt;
&lt;br /&gt;
NB: Step 6 could have been equivalently run in yambopy, limiting the use of the yambo code to just step 4. This latter option is more flexible, as it allows for a greater degree of control by the user. We are in the last stages of the development and it will be available soon.&lt;br /&gt;
&lt;br /&gt;
=== Results ===&lt;br /&gt;
&lt;br /&gt;
If we check the output directory from the step 6 calculation, we find the &amp;lt;code&amp;gt;o-excph.pl_bse_ph_ass&amp;lt;/code&amp;gt; output files containing the luminescence spectra. We can plot them with gnuplot or any other tool:&lt;br /&gt;
&lt;br /&gt;
 gnuplot&lt;br /&gt;
 &amp;gt; set xrange[4.2:5]&lt;br /&gt;
 &amp;gt; p &#039;o-excph.pl_bse_ph_ass&#039; u 1:2 w l lc rgb &#039;red&#039; lw 3&lt;br /&gt;
&lt;br /&gt;
[[File:Luminescence plot.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;[https://m.booksee.org/book/1121964?force_lang=en Optical processes in solids], Toyozawa, Yutaka, and Chris Oxlade. 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;[https://www.yambo-code.eu/wiki/images/5/54/These_final.pdf Exciton-phonon coupling and phonon-assisted luminescence in hexagonal Boron Nitride nanostructures], PhD Thesis, Pierre Lechifflart (2023)&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;[https://arxiv.org/abs/2305.17554 Distinguishing different stackings in layered materials via luminescence spectroscopy], M. Zanfrognini et al. Phys. Rev. Lett. &#039;&#039;&#039;131&#039;&#039;&#039;, 206902 (2023) &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;[https://arxiv.org/abs/2205.02783 Exciton-phonon interaction calls for a revision of the “exciton” concept], F. Paleari, A. Marini, Phys. Rev. B, &#039;&#039;&#039;106&#039;&#039;&#039;, 125403 (2022)&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>Attacc</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Exciton-phonon_coupling_and_luminescence&amp;diff=9174</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=9174"/>
		<updated>2025-10-06T12:02:01Z</updated>

		<summary type="html">&lt;p&gt;Attacc: &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 (&amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;) and the transfer momenta (&amp;lt;math&amp;gt;&#039;&#039;&#039;Q&#039;&#039;&#039;&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;&#039;&#039;&#039;q&#039;&#039;&#039;&amp;lt;/math&amp;gt;) 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://gitlab.com/lumen-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.&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. 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. &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 --debug&lt;br /&gt;
&lt;br /&gt;
At the end, check the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 ls SAVE/ndb.elph_gkkp*&lt;br /&gt;
&lt;br /&gt;
to see that it has created the Yambo-compatible electron-phonon databases.&lt;br /&gt;
&lt;br /&gt;
If you saved the &amp;lt;code&amp;gt;lelphc.in&amp;lt;/code&amp;gt; input file, you can 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;
You can also run it as it is, but the code will generate the database &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt;. In order to convert it to the &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases of Yambo, you still 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;
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;
== 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;. In this version of the tutorial we present the latter case.&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,q) - \sum_{cc^\prime vk} A^{\alpha, *}_{c^\prime v} (k+q, q) g_{c^\prime c}^\mu (k+q,q) A^{\lambda}_{cv}(k,q)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here, &amp;lt;math&amp;gt;A^{\lambda}_{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;
&lt;br /&gt;
We have to write a new yambo input, that we can call &amp;lt;code&amp;gt;excph.in&amp;lt;/code&amp;gt;, for this. You can copy (and adapt) the one below, or you can generate one by running from the command line:&lt;br /&gt;
&lt;br /&gt;
 yambo_ph -excph o&lt;br /&gt;
&lt;br /&gt;
This generates an input to compute luminescence (&amp;quot;o&amp;quot; is for &amp;quot;optics&amp;quot;). The variables that we are interested in are:&lt;br /&gt;
&lt;br /&gt;
 excph                            # [R] Exction-phonon&lt;br /&gt;
 ExcGkkp                          # [R][EXCPH] Exciton-Phonon Matrix Elelements&lt;br /&gt;
 % ELPhExcStates&lt;br /&gt;
  1 | 4 |                             # [EXCPH] Incoming (external) exciton states&lt;br /&gt;
 %&lt;br /&gt;
 % ELPhExcSum&lt;br /&gt;
  1 | 12 |                             # [EXCPH] Outgoing (virtual) exciton states&lt;br /&gt;
 %&lt;br /&gt;
 LoutPath= &amp;quot;./bse_Lfull&amp;quot;                 # [EXCPH] Path of the outgoing L&lt;br /&gt;
 % ElPhModes&lt;br /&gt;
   1 | 9 |                           # [ELPH] Phonon modes included&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
In this input, we have to select the initial exciton states &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; with &amp;lt;code&amp;gt;ELPhExcStates&amp;lt;/code&amp;gt;, the final exciton states &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; with &amp;lt;code&amp;gt;ELPhExcSum&amp;lt;/code&amp;gt; and the phonon modes &amp;lt;math&amp;gt;\mu&amp;lt;/math&amp;gt; with &amp;lt;code&amp;gt;ElPhModes&amp;lt;/code&amp;gt;. Here we consider the first four states at &amp;lt;math&amp;gt;Q=0&amp;lt;/math&amp;gt; (corresponding to just two excitons because they are both doubly degenerate -- do not break degeneracies when selecting states!) and the first twelve states at each finite-&amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; point. We also include all the nine phonon modes of monolayer MoS2.&lt;br /&gt;
&lt;br /&gt;
What about &amp;lt;code&amp;gt;LoutPath&amp;lt;/code&amp;gt;? This variable controls the directory where the databases for the final-state excitons &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; is located, which can be different from the directory with the initial-state excitons &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; read as usual with the &amp;lt;code&amp;gt;-J&amp;lt;/code&amp;gt; option when running the code. This makes it possible to compute the coupling between different exciton kinds. However, for our tutorial, we stick with the previously computed &amp;lt;code&amp;gt;Lfull&amp;lt;/code&amp;gt; in both cases.&lt;br /&gt;
&lt;br /&gt;
When we are satisfied with the input, we run the code using &amp;lt;code&amp;gt;yambo_ph&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 yambo_ph -F excph.in -J excph,bse_Lfull -C excph&lt;br /&gt;
&lt;br /&gt;
If you check the output, you should find the &amp;lt;code&amp;gt;ndb.excph*&amp;lt;/code&amp;gt; databases in the &amp;lt;code&amp;gt;excph&amp;lt;/code&amp;gt; directory.&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 MoS2, 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 using the &amp;lt;code&amp;gt;YamboExcitonPhononDB&amp;lt;/code&amp;gt; from yambopy. &lt;br /&gt;
You can find 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;
 # Exciton in states&lt;br /&gt;
 exc_in  = [2,3]     # A: 2,3 -- B: 6,7&lt;br /&gt;
 exc_out = [0,1,2,3] # first 4 states (dispersion of triplet state and A)&lt;br /&gt;
 ph_in  = &#039;all&#039;&lt;br /&gt;
 &lt;br /&gt;
 # Paths of databases&lt;br /&gt;
 ns_db1 =f&#039;{path}/SAVE/ns.db1&#039;&lt;br /&gt;
 ndb_exc=f&#039;{path}/excph&#039;&lt;br /&gt;
 &lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
Then, we load the data:&lt;br /&gt;
&lt;br /&gt;
 # Read lattice and k-space info&lt;br /&gt;
 ylat = YamboLatticeDB.from_db_file(filename=ns_db1),Expand=True)&lt;br /&gt;
 print(ylat)&lt;br /&gt;
 &lt;br /&gt;
 # Read exc-ph databases&lt;br /&gt;
 X = YamboExcitonPhononDB(ylat,save_excph=ndb_exc)&lt;br /&gt;
 print(X)&lt;br /&gt;
&lt;br /&gt;
The quantity &amp;lt;math&amp;gt;F_A(q)&amp;lt;/math&amp;gt; is defined inside the plotting function as&lt;br /&gt;
&lt;br /&gt;
 G_squared = excph.excph_sq&lt;br /&gt;
 G2plt = np.zeros(len(G_squared))&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 # Switch from Ha to eV&lt;br /&gt;
&lt;br /&gt;
And finally, we have to make a plotting function. For this tutorial we will use the default scatterplot provided by &amp;lt;code&amp;gt;YamboExcitonPhononDB&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 excph.plot_excph(F_q,plt_cbar=plt_cbar,**kwargs)&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 this 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 ExcPh.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^{(1)}_{PL}(\omega;T) \propto \frac{1}{N_q}\sum_{ s \mu \beta q} \left|\sum_\lambda\frac{D_\lambda \mathcal{G}^{\mu q}_{\alpha q,\lambda}}{E_{\alpha q}-E_\lambda -s\Omega_{\mu q}} \right|^2 N_{\alpha q}(T_{exc}) F^s_{\mu q}(T)\delta(\omega - \left[E_{\alpha q}-s\Omega_{\mu q}\right])&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;
The occupation function &amp;lt;math&amp;gt;F&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;F^s_{\mu q}(T)=n_{\mu q}(T)+\frac{1+s}{2}&amp;lt;/math&amp;gt;. Here, &amp;lt;math&amp;gt;n(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^{(1)}_{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;
=== 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 yambopy to get the el-ph matrix elements:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph path/of/dvscf/hbn.dvscf -b 7 10 -par 4 2 &lt;br /&gt;
&lt;br /&gt;
6. And finally we generate the exciton-phonon input &amp;lt;code&amp;gt;excph.in&amp;lt;/code&amp;gt; using &amp;lt;code&amp;gt;yambo_ph -excph o&amp;lt;/code&amp;gt;. Now, we take a look at all the additional variables that we didn&#039;t check before, specifying also the details for luminescence the spectrum calculation.&lt;br /&gt;
&lt;br /&gt;
 excph                            # [R] Exction-phonon&lt;br /&gt;
 ExcGkkp                          # [R][EXCPH] Exciton-Phonon Matrix Elelements&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;ExcPhOptics                      # [R][EXCPH] Exciton-Phonon Optics&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;BoseTemp=10.000000         Kn    # Bosonic Temperature&amp;lt;/span&amp;gt; &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;EXCTemp= 10.000000          Kn    # [EXCPH] Excitonic Temperature (for luminescence spectra)&amp;lt;/span&amp;gt;&lt;br /&gt;
 % ELPhExcStates&lt;br /&gt;
  1 | 4 |                             # [EXCPH] Incoming (external) exciton states&lt;br /&gt;
 %&lt;br /&gt;
 % ELPhExcSum&lt;br /&gt;
  1 | 12 |                             # [EXCPH] Outgoing (virtual) exciton states&lt;br /&gt;
 %&lt;br /&gt;
 % ElPhModes&lt;br /&gt;
  1 | 12 |                           # [ELPH] Phonon modes included&lt;br /&gt;
 %&lt;br /&gt;
 LoutPath= &amp;quot;./bse-L_full&amp;quot;                 # [EXCPH] Path of the outgoing L&lt;br /&gt;
 FANdEtresh= 0.100000E-5    eV    # [ELPH] Energy treshold for Fan denominator&lt;br /&gt;
 EXCPHdEtresh= 0.100000E-5  eV    # [ELPH] Energy treshold for exc-ph denominator&lt;br /&gt;
 LDamping= 0.500000E-3      eV    # [EXCPH] Damping of exc-ph self-energy&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# These are the plot parameters, same as in other parts of yambo&amp;lt;/span&amp;gt; &lt;br /&gt;
 % EnRngeXd&lt;br /&gt;
   4.00000 | 5.00000 |         eV    # [Xd] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 % DmRngeXd&lt;br /&gt;
  0.00500000 | 0.00500000 |         eV    # [Xd] Damping range&lt;br /&gt;
 %&lt;br /&gt;
 ETStpsXd= 4000                    # [Xd] Total Energy steps&lt;br /&gt;
&lt;br /&gt;
Here &amp;lt;code&amp;gt;BoseTemp&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXCTemp&amp;lt;/code&amp;gt; are the lattice and excitonic temperature, respectively.&lt;br /&gt;
&lt;br /&gt;
Now we run the calculation with &amp;lt;code&amp;gt;yambo_ph&amp;lt;/code&amp;gt;. Here, we read as &amp;lt;math&amp;gt;Q=0&amp;lt;/math&amp;gt; excitons with &amp;lt;code&amp;gt;-J&amp;lt;/code&amp;gt; the ones without the long-range Coulomb exchange:&lt;br /&gt;
&lt;br /&gt;
 yambo_ph -F excph.in -J excph,bse_Lbar -C excph&lt;br /&gt;
&lt;br /&gt;
and we find our outputs in the &amp;lt;code&amp;gt;excph&amp;lt;/code&amp;gt; directory. &lt;br /&gt;
&lt;br /&gt;
NB: Step 6 could have been equivalently run in yambopy, limiting the use of the yambo code to just step 4. This latter option is more flexible, as it allows for a greater degree of control by the user. We are in the last stages of the development and it will be available soon.&lt;br /&gt;
&lt;br /&gt;
=== Results ===&lt;br /&gt;
&lt;br /&gt;
If we check the output directory from the step 6 calculation, we find the &amp;lt;code&amp;gt;o-excph.pl_bse_ph_ass&amp;lt;/code&amp;gt; output files containing the luminescence spectra. We can plot them with gnuplot or any other tool:&lt;br /&gt;
&lt;br /&gt;
 gnuplot&lt;br /&gt;
 &amp;gt; set xrange[4.2:5]&lt;br /&gt;
 &amp;gt; p &#039;o-excph.pl_bse_ph_ass&#039; u 1:2 w l lc rgb &#039;red&#039; lw 3&lt;br /&gt;
&lt;br /&gt;
[[File:Luminescence plot.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;[https://m.booksee.org/book/1121964?force_lang=en Optical processes in solids], Toyozawa, Yutaka, and Chris Oxlade. 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;[https://www.yambo-code.eu/wiki/images/5/54/These_final.pdf Exciton-phonon coupling and phonon-assisted luminescence in hexagonal Boron Nitride nanostructures], PhD Thesis, Pierre Lechifflart (2023)&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;[https://arxiv.org/abs/2305.17554 Distinguishing different stackings in layered materials via luminescence spectroscopy], M. Zanfrognini et al. Phys. Rev. Lett. &#039;&#039;&#039;131&#039;&#039;&#039;, 206902 (2023) &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;[https://arxiv.org/abs/2205.02783 Exciton-phonon interaction calls for a revision of the “exciton” concept], F. Paleari, A. Marini, Phys. Rev. B, &#039;&#039;&#039;106&#039;&#039;&#039;, 125403 (2022)&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>Attacc</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Exciton-phonon_coupling_and_luminescence&amp;diff=9173</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=9173"/>
		<updated>2025-10-06T12:01:28Z</updated>

		<summary type="html">&lt;p&gt;Attacc: &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 (&amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;) and the transfer momenta (&#039;&#039;&#039;&amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt;&#039;&#039;&#039;, &#039;&#039;&#039;&amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt;&#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://gitlab.com/lumen-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.&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. 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. &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 --debug&lt;br /&gt;
&lt;br /&gt;
At the end, check the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 ls SAVE/ndb.elph_gkkp*&lt;br /&gt;
&lt;br /&gt;
to see that it has created the Yambo-compatible electron-phonon databases.&lt;br /&gt;
&lt;br /&gt;
If you saved the &amp;lt;code&amp;gt;lelphc.in&amp;lt;/code&amp;gt; input file, you can 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;
You can also run it as it is, but the code will generate the database &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt;. In order to convert it to the &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases of Yambo, you still 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;
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;
== 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;. In this version of the tutorial we present the latter case.&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,q) - \sum_{cc^\prime vk} A^{\alpha, *}_{c^\prime v} (k+q, q) g_{c^\prime c}^\mu (k+q,q) A^{\lambda}_{cv}(k,q)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here, &amp;lt;math&amp;gt;A^{\lambda}_{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;
&lt;br /&gt;
We have to write a new yambo input, that we can call &amp;lt;code&amp;gt;excph.in&amp;lt;/code&amp;gt;, for this. You can copy (and adapt) the one below, or you can generate one by running from the command line:&lt;br /&gt;
&lt;br /&gt;
 yambo_ph -excph o&lt;br /&gt;
&lt;br /&gt;
This generates an input to compute luminescence (&amp;quot;o&amp;quot; is for &amp;quot;optics&amp;quot;). The variables that we are interested in are:&lt;br /&gt;
&lt;br /&gt;
 excph                            # [R] Exction-phonon&lt;br /&gt;
 ExcGkkp                          # [R][EXCPH] Exciton-Phonon Matrix Elelements&lt;br /&gt;
 % ELPhExcStates&lt;br /&gt;
  1 | 4 |                             # [EXCPH] Incoming (external) exciton states&lt;br /&gt;
 %&lt;br /&gt;
 % ELPhExcSum&lt;br /&gt;
  1 | 12 |                             # [EXCPH] Outgoing (virtual) exciton states&lt;br /&gt;
 %&lt;br /&gt;
 LoutPath= &amp;quot;./bse_Lfull&amp;quot;                 # [EXCPH] Path of the outgoing L&lt;br /&gt;
 % ElPhModes&lt;br /&gt;
   1 | 9 |                           # [ELPH] Phonon modes included&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
In this input, we have to select the initial exciton states &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; with &amp;lt;code&amp;gt;ELPhExcStates&amp;lt;/code&amp;gt;, the final exciton states &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; with &amp;lt;code&amp;gt;ELPhExcSum&amp;lt;/code&amp;gt; and the phonon modes &amp;lt;math&amp;gt;\mu&amp;lt;/math&amp;gt; with &amp;lt;code&amp;gt;ElPhModes&amp;lt;/code&amp;gt;. Here we consider the first four states at &amp;lt;math&amp;gt;Q=0&amp;lt;/math&amp;gt; (corresponding to just two excitons because they are both doubly degenerate -- do not break degeneracies when selecting states!) and the first twelve states at each finite-&amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; point. We also include all the nine phonon modes of monolayer MoS2.&lt;br /&gt;
&lt;br /&gt;
What about &amp;lt;code&amp;gt;LoutPath&amp;lt;/code&amp;gt;? This variable controls the directory where the databases for the final-state excitons &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; is located, which can be different from the directory with the initial-state excitons &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; read as usual with the &amp;lt;code&amp;gt;-J&amp;lt;/code&amp;gt; option when running the code. This makes it possible to compute the coupling between different exciton kinds. However, for our tutorial, we stick with the previously computed &amp;lt;code&amp;gt;Lfull&amp;lt;/code&amp;gt; in both cases.&lt;br /&gt;
&lt;br /&gt;
When we are satisfied with the input, we run the code using &amp;lt;code&amp;gt;yambo_ph&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 yambo_ph -F excph.in -J excph,bse_Lfull -C excph&lt;br /&gt;
&lt;br /&gt;
If you check the output, you should find the &amp;lt;code&amp;gt;ndb.excph*&amp;lt;/code&amp;gt; databases in the &amp;lt;code&amp;gt;excph&amp;lt;/code&amp;gt; directory.&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 MoS2, 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 using the &amp;lt;code&amp;gt;YamboExcitonPhononDB&amp;lt;/code&amp;gt; from yambopy. &lt;br /&gt;
You can find 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;
 # Exciton in states&lt;br /&gt;
 exc_in  = [2,3]     # A: 2,3 -- B: 6,7&lt;br /&gt;
 exc_out = [0,1,2,3] # first 4 states (dispersion of triplet state and A)&lt;br /&gt;
 ph_in  = &#039;all&#039;&lt;br /&gt;
 &lt;br /&gt;
 # Paths of databases&lt;br /&gt;
 ns_db1 =f&#039;{path}/SAVE/ns.db1&#039;&lt;br /&gt;
 ndb_exc=f&#039;{path}/excph&#039;&lt;br /&gt;
 &lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
Then, we load the data:&lt;br /&gt;
&lt;br /&gt;
 # Read lattice and k-space info&lt;br /&gt;
 ylat = YamboLatticeDB.from_db_file(filename=ns_db1),Expand=True)&lt;br /&gt;
 print(ylat)&lt;br /&gt;
 &lt;br /&gt;
 # Read exc-ph databases&lt;br /&gt;
 X = YamboExcitonPhononDB(ylat,save_excph=ndb_exc)&lt;br /&gt;
 print(X)&lt;br /&gt;
&lt;br /&gt;
The quantity &amp;lt;math&amp;gt;F_A(q)&amp;lt;/math&amp;gt; is defined inside the plotting function as&lt;br /&gt;
&lt;br /&gt;
 G_squared = excph.excph_sq&lt;br /&gt;
 G2plt = np.zeros(len(G_squared))&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 # Switch from Ha to eV&lt;br /&gt;
&lt;br /&gt;
And finally, we have to make a plotting function. For this tutorial we will use the default scatterplot provided by &amp;lt;code&amp;gt;YamboExcitonPhononDB&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 excph.plot_excph(F_q,plt_cbar=plt_cbar,**kwargs)&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 this 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 ExcPh.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^{(1)}_{PL}(\omega;T) \propto \frac{1}{N_q}\sum_{ s \mu \beta q} \left|\sum_\lambda\frac{D_\lambda \mathcal{G}^{\mu q}_{\alpha q,\lambda}}{E_{\alpha q}-E_\lambda -s\Omega_{\mu q}} \right|^2 N_{\alpha q}(T_{exc}) F^s_{\mu q}(T)\delta(\omega - \left[E_{\alpha q}-s\Omega_{\mu q}\right])&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;
The occupation function &amp;lt;math&amp;gt;F&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;F^s_{\mu q}(T)=n_{\mu q}(T)+\frac{1+s}{2}&amp;lt;/math&amp;gt;. Here, &amp;lt;math&amp;gt;n(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^{(1)}_{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;
=== 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 yambopy to get the el-ph matrix elements:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph path/of/dvscf/hbn.dvscf -b 7 10 -par 4 2 &lt;br /&gt;
&lt;br /&gt;
6. And finally we generate the exciton-phonon input &amp;lt;code&amp;gt;excph.in&amp;lt;/code&amp;gt; using &amp;lt;code&amp;gt;yambo_ph -excph o&amp;lt;/code&amp;gt;. Now, we take a look at all the additional variables that we didn&#039;t check before, specifying also the details for luminescence the spectrum calculation.&lt;br /&gt;
&lt;br /&gt;
 excph                            # [R] Exction-phonon&lt;br /&gt;
 ExcGkkp                          # [R][EXCPH] Exciton-Phonon Matrix Elelements&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;ExcPhOptics                      # [R][EXCPH] Exciton-Phonon Optics&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;BoseTemp=10.000000         Kn    # Bosonic Temperature&amp;lt;/span&amp;gt; &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;EXCTemp= 10.000000          Kn    # [EXCPH] Excitonic Temperature (for luminescence spectra)&amp;lt;/span&amp;gt;&lt;br /&gt;
 % ELPhExcStates&lt;br /&gt;
  1 | 4 |                             # [EXCPH] Incoming (external) exciton states&lt;br /&gt;
 %&lt;br /&gt;
 % ELPhExcSum&lt;br /&gt;
  1 | 12 |                             # [EXCPH] Outgoing (virtual) exciton states&lt;br /&gt;
 %&lt;br /&gt;
 % ElPhModes&lt;br /&gt;
  1 | 12 |                           # [ELPH] Phonon modes included&lt;br /&gt;
 %&lt;br /&gt;
 LoutPath= &amp;quot;./bse-L_full&amp;quot;                 # [EXCPH] Path of the outgoing L&lt;br /&gt;
 FANdEtresh= 0.100000E-5    eV    # [ELPH] Energy treshold for Fan denominator&lt;br /&gt;
 EXCPHdEtresh= 0.100000E-5  eV    # [ELPH] Energy treshold for exc-ph denominator&lt;br /&gt;
 LDamping= 0.500000E-3      eV    # [EXCPH] Damping of exc-ph self-energy&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# These are the plot parameters, same as in other parts of yambo&amp;lt;/span&amp;gt; &lt;br /&gt;
 % EnRngeXd&lt;br /&gt;
   4.00000 | 5.00000 |         eV    # [Xd] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 % DmRngeXd&lt;br /&gt;
  0.00500000 | 0.00500000 |         eV    # [Xd] Damping range&lt;br /&gt;
 %&lt;br /&gt;
 ETStpsXd= 4000                    # [Xd] Total Energy steps&lt;br /&gt;
&lt;br /&gt;
Here &amp;lt;code&amp;gt;BoseTemp&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXCTemp&amp;lt;/code&amp;gt; are the lattice and excitonic temperature, respectively.&lt;br /&gt;
&lt;br /&gt;
Now we run the calculation with &amp;lt;code&amp;gt;yambo_ph&amp;lt;/code&amp;gt;. Here, we read as &amp;lt;math&amp;gt;Q=0&amp;lt;/math&amp;gt; excitons with &amp;lt;code&amp;gt;-J&amp;lt;/code&amp;gt; the ones without the long-range Coulomb exchange:&lt;br /&gt;
&lt;br /&gt;
 yambo_ph -F excph.in -J excph,bse_Lbar -C excph&lt;br /&gt;
&lt;br /&gt;
and we find our outputs in the &amp;lt;code&amp;gt;excph&amp;lt;/code&amp;gt; directory. &lt;br /&gt;
&lt;br /&gt;
NB: Step 6 could have been equivalently run in yambopy, limiting the use of the yambo code to just step 4. This latter option is more flexible, as it allows for a greater degree of control by the user. We are in the last stages of the development and it will be available soon.&lt;br /&gt;
&lt;br /&gt;
=== Results ===&lt;br /&gt;
&lt;br /&gt;
If we check the output directory from the step 6 calculation, we find the &amp;lt;code&amp;gt;o-excph.pl_bse_ph_ass&amp;lt;/code&amp;gt; output files containing the luminescence spectra. We can plot them with gnuplot or any other tool:&lt;br /&gt;
&lt;br /&gt;
 gnuplot&lt;br /&gt;
 &amp;gt; set xrange[4.2:5]&lt;br /&gt;
 &amp;gt; p &#039;o-excph.pl_bse_ph_ass&#039; u 1:2 w l lc rgb &#039;red&#039; lw 3&lt;br /&gt;
&lt;br /&gt;
[[File:Luminescence plot.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;[https://m.booksee.org/book/1121964?force_lang=en Optical processes in solids], Toyozawa, Yutaka, and Chris Oxlade. 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;[https://www.yambo-code.eu/wiki/images/5/54/These_final.pdf Exciton-phonon coupling and phonon-assisted luminescence in hexagonal Boron Nitride nanostructures], PhD Thesis, Pierre Lechifflart (2023)&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;[https://arxiv.org/abs/2305.17554 Distinguishing different stackings in layered materials via luminescence spectroscopy], M. Zanfrognini et al. Phys. Rev. Lett. &#039;&#039;&#039;131&#039;&#039;&#039;, 206902 (2023) &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;[https://arxiv.org/abs/2205.02783 Exciton-phonon interaction calls for a revision of the “exciton” concept], F. Paleari, A. Marini, Phys. Rev. B, &#039;&#039;&#039;106&#039;&#039;&#039;, 125403 (2022)&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>Attacc</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Exciton-phonon_coupling_and_luminescence&amp;diff=9172</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=9172"/>
		<updated>2025-10-06T11:53:39Z</updated>

		<summary type="html">&lt;p&gt;Attacc: /* Step 5: run a BSE calculation */&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 (&amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;) and the transfer momenta (&amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt;) 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 MoS2, 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://gitlab.com/lumen-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.&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. 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. &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 --debug&lt;br /&gt;
&lt;br /&gt;
At the end, check the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 ls SAVE/ndb.elph_gkkp*&lt;br /&gt;
&lt;br /&gt;
to see that it has created the Yambo-compatible electron-phonon databases.&lt;br /&gt;
&lt;br /&gt;
If you saved the &amp;lt;code&amp;gt;lelphc.in&amp;lt;/code&amp;gt; input file, you can 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;
You can also run it as it is, but the code will generate the database &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt;. In order to convert it to the &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases of Yambo, you still 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;
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;
== 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;. In this version of the tutorial we present the latter case.&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,q) - \sum_{cc^\prime vk} A^{\alpha, *}_{c^\prime v} (k+q, q) g_{c^\prime c}^\mu (k+q,q) A^{\lambda}_{cv}(k,q)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here, &amp;lt;math&amp;gt;A^{\lambda}_{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;
&lt;br /&gt;
We have to write a new yambo input, that we can call &amp;lt;code&amp;gt;excph.in&amp;lt;/code&amp;gt;, for this. You can copy (and adapt) the one below, or you can generate one by running from the command line:&lt;br /&gt;
&lt;br /&gt;
 yambo_ph -excph o&lt;br /&gt;
&lt;br /&gt;
This generates an input to compute luminescence (&amp;quot;o&amp;quot; is for &amp;quot;optics&amp;quot;). The variables that we are interested in are:&lt;br /&gt;
&lt;br /&gt;
 excph                            # [R] Exction-phonon&lt;br /&gt;
 ExcGkkp                          # [R][EXCPH] Exciton-Phonon Matrix Elelements&lt;br /&gt;
 % ELPhExcStates&lt;br /&gt;
  1 | 4 |                             # [EXCPH] Incoming (external) exciton states&lt;br /&gt;
 %&lt;br /&gt;
 % ELPhExcSum&lt;br /&gt;
  1 | 12 |                             # [EXCPH] Outgoing (virtual) exciton states&lt;br /&gt;
 %&lt;br /&gt;
 LoutPath= &amp;quot;./bse_Lfull&amp;quot;                 # [EXCPH] Path of the outgoing L&lt;br /&gt;
 % ElPhModes&lt;br /&gt;
   1 | 9 |                           # [ELPH] Phonon modes included&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
In this input, we have to select the initial exciton states &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; with &amp;lt;code&amp;gt;ELPhExcStates&amp;lt;/code&amp;gt;, the final exciton states &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; with &amp;lt;code&amp;gt;ELPhExcSum&amp;lt;/code&amp;gt; and the phonon modes &amp;lt;math&amp;gt;\mu&amp;lt;/math&amp;gt; with &amp;lt;code&amp;gt;ElPhModes&amp;lt;/code&amp;gt;. Here we consider the first four states at &amp;lt;math&amp;gt;Q=0&amp;lt;/math&amp;gt; (corresponding to just two excitons because they are both doubly degenerate -- do not break degeneracies when selecting states!) and the first twelve states at each finite-&amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; point. We also include all the nine phonon modes of monolayer MoS2.&lt;br /&gt;
&lt;br /&gt;
What about &amp;lt;code&amp;gt;LoutPath&amp;lt;/code&amp;gt;? This variable controls the directory where the databases for the final-state excitons &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; is located, which can be different from the directory with the initial-state excitons &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; read as usual with the &amp;lt;code&amp;gt;-J&amp;lt;/code&amp;gt; option when running the code. This makes it possible to compute the coupling between different exciton kinds. However, for our tutorial, we stick with the previously computed &amp;lt;code&amp;gt;Lfull&amp;lt;/code&amp;gt; in both cases.&lt;br /&gt;
&lt;br /&gt;
When we are satisfied with the input, we run the code using &amp;lt;code&amp;gt;yambo_ph&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 yambo_ph -F excph.in -J excph,bse_Lfull -C excph&lt;br /&gt;
&lt;br /&gt;
If you check the output, you should find the &amp;lt;code&amp;gt;ndb.excph*&amp;lt;/code&amp;gt; databases in the &amp;lt;code&amp;gt;excph&amp;lt;/code&amp;gt; directory.&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 MoS2, 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 using the &amp;lt;code&amp;gt;YamboExcitonPhononDB&amp;lt;/code&amp;gt; from yambopy. &lt;br /&gt;
You can find 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;
 # Exciton in states&lt;br /&gt;
 exc_in  = [2,3]     # A: 2,3 -- B: 6,7&lt;br /&gt;
 exc_out = [0,1,2,3] # first 4 states (dispersion of triplet state and A)&lt;br /&gt;
 ph_in  = &#039;all&#039;&lt;br /&gt;
 &lt;br /&gt;
 # Paths of databases&lt;br /&gt;
 ns_db1 =f&#039;{path}/SAVE/ns.db1&#039;&lt;br /&gt;
 ndb_exc=f&#039;{path}/excph&#039;&lt;br /&gt;
 &lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
Then, we load the data:&lt;br /&gt;
&lt;br /&gt;
 # Read lattice and k-space info&lt;br /&gt;
 ylat = YamboLatticeDB.from_db_file(filename=ns_db1),Expand=True)&lt;br /&gt;
 print(ylat)&lt;br /&gt;
 &lt;br /&gt;
 # Read exc-ph databases&lt;br /&gt;
 X = YamboExcitonPhononDB(ylat,save_excph=ndb_exc)&lt;br /&gt;
 print(X)&lt;br /&gt;
&lt;br /&gt;
The quantity &amp;lt;math&amp;gt;F_A(q)&amp;lt;/math&amp;gt; is defined inside the plotting function as&lt;br /&gt;
&lt;br /&gt;
 G_squared = excph.excph_sq&lt;br /&gt;
 G2plt = np.zeros(len(G_squared))&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 # Switch from Ha to eV&lt;br /&gt;
&lt;br /&gt;
And finally, we have to make a plotting function. For this tutorial we will use the default scatterplot provided by &amp;lt;code&amp;gt;YamboExcitonPhononDB&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 excph.plot_excph(F_q,plt_cbar=plt_cbar,**kwargs)&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 this 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 ExcPh.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^{(1)}_{PL}(\omega;T) \propto \frac{1}{N_q}\sum_{ s \mu \beta q} \left|\sum_\lambda\frac{D_\lambda \mathcal{G}^{\mu q}_{\alpha q,\lambda}}{E_{\alpha q}-E_\lambda -s\Omega_{\mu q}} \right|^2 N_{\alpha q}(T_{exc}) F^s_{\mu q}(T)\delta(\omega - \left[E_{\alpha q}-s\Omega_{\mu q}\right])&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;
The occupation function &amp;lt;math&amp;gt;F&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;F^s_{\mu q}(T)=n_{\mu q}(T)+\frac{1+s}{2}&amp;lt;/math&amp;gt;. Here, &amp;lt;math&amp;gt;n(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^{(1)}_{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;
=== 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 yambopy to get the el-ph matrix elements:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph path/of/dvscf/hbn.dvscf -b 7 10 -par 4 2 &lt;br /&gt;
&lt;br /&gt;
6. And finally we generate the exciton-phonon input &amp;lt;code&amp;gt;excph.in&amp;lt;/code&amp;gt; using &amp;lt;code&amp;gt;yambo_ph -excph o&amp;lt;/code&amp;gt;. Now, we take a look at all the additional variables that we didn&#039;t check before, specifying also the details for luminescence the spectrum calculation.&lt;br /&gt;
&lt;br /&gt;
 excph                            # [R] Exction-phonon&lt;br /&gt;
 ExcGkkp                          # [R][EXCPH] Exciton-Phonon Matrix Elelements&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;ExcPhOptics                      # [R][EXCPH] Exciton-Phonon Optics&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;BoseTemp=10.000000         Kn    # Bosonic Temperature&amp;lt;/span&amp;gt; &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;EXCTemp= 10.000000          Kn    # [EXCPH] Excitonic Temperature (for luminescence spectra)&amp;lt;/span&amp;gt;&lt;br /&gt;
 % ELPhExcStates&lt;br /&gt;
  1 | 4 |                             # [EXCPH] Incoming (external) exciton states&lt;br /&gt;
 %&lt;br /&gt;
 % ELPhExcSum&lt;br /&gt;
  1 | 12 |                             # [EXCPH] Outgoing (virtual) exciton states&lt;br /&gt;
 %&lt;br /&gt;
 % ElPhModes&lt;br /&gt;
  1 | 12 |                           # [ELPH] Phonon modes included&lt;br /&gt;
 %&lt;br /&gt;
 LoutPath= &amp;quot;./bse-L_full&amp;quot;                 # [EXCPH] Path of the outgoing L&lt;br /&gt;
 FANdEtresh= 0.100000E-5    eV    # [ELPH] Energy treshold for Fan denominator&lt;br /&gt;
 EXCPHdEtresh= 0.100000E-5  eV    # [ELPH] Energy treshold for exc-ph denominator&lt;br /&gt;
 LDamping= 0.500000E-3      eV    # [EXCPH] Damping of exc-ph self-energy&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# These are the plot parameters, same as in other parts of yambo&amp;lt;/span&amp;gt; &lt;br /&gt;
 % EnRngeXd&lt;br /&gt;
   4.00000 | 5.00000 |         eV    # [Xd] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 % DmRngeXd&lt;br /&gt;
  0.00500000 | 0.00500000 |         eV    # [Xd] Damping range&lt;br /&gt;
 %&lt;br /&gt;
 ETStpsXd= 4000                    # [Xd] Total Energy steps&lt;br /&gt;
&lt;br /&gt;
Here &amp;lt;code&amp;gt;BoseTemp&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXCTemp&amp;lt;/code&amp;gt; are the lattice and excitonic temperature, respectively.&lt;br /&gt;
&lt;br /&gt;
Now we run the calculation with &amp;lt;code&amp;gt;yambo_ph&amp;lt;/code&amp;gt;. Here, we read as &amp;lt;math&amp;gt;Q=0&amp;lt;/math&amp;gt; excitons with &amp;lt;code&amp;gt;-J&amp;lt;/code&amp;gt; the ones without the long-range Coulomb exchange:&lt;br /&gt;
&lt;br /&gt;
 yambo_ph -F excph.in -J excph,bse_Lbar -C excph&lt;br /&gt;
&lt;br /&gt;
and we find our outputs in the &amp;lt;code&amp;gt;excph&amp;lt;/code&amp;gt; directory. &lt;br /&gt;
&lt;br /&gt;
NB: Step 6 could have been equivalently run in yambopy, limiting the use of the yambo code to just step 4. This latter option is more flexible, as it allows for a greater degree of control by the user. We are in the last stages of the development and it will be available soon.&lt;br /&gt;
&lt;br /&gt;
=== Results ===&lt;br /&gt;
&lt;br /&gt;
If we check the output directory from the step 6 calculation, we find the &amp;lt;code&amp;gt;o-excph.pl_bse_ph_ass&amp;lt;/code&amp;gt; output files containing the luminescence spectra. We can plot them with gnuplot or any other tool:&lt;br /&gt;
&lt;br /&gt;
 gnuplot&lt;br /&gt;
 &amp;gt; set xrange[4.2:5]&lt;br /&gt;
 &amp;gt; p &#039;o-excph.pl_bse_ph_ass&#039; u 1:2 w l lc rgb &#039;red&#039; lw 3&lt;br /&gt;
&lt;br /&gt;
[[File:Luminescence plot.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;[https://m.booksee.org/book/1121964?force_lang=en Optical processes in solids], Toyozawa, Yutaka, and Chris Oxlade. 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;[https://www.yambo-code.eu/wiki/images/5/54/These_final.pdf Exciton-phonon coupling and phonon-assisted luminescence in hexagonal Boron Nitride nanostructures], PhD Thesis, Pierre Lechifflart (2023)&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;[https://arxiv.org/abs/2305.17554 Distinguishing different stackings in layered materials via luminescence spectroscopy], M. Zanfrognini et al. Phys. Rev. Lett. &#039;&#039;&#039;131&#039;&#039;&#039;, 206902 (2023) &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;[https://arxiv.org/abs/2205.02783 Exciton-phonon interaction calls for a revision of the “exciton” concept], F. Paleari, A. Marini, Phys. Rev. B, &#039;&#039;&#039;106&#039;&#039;&#039;, 125403 (2022)&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>Attacc</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Exciton-phonon_coupling_and_luminescence&amp;diff=9171</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=9171"/>
		<updated>2025-10-06T11:52:51Z</updated>

		<summary type="html">&lt;p&gt;Attacc: /* Step 5: run a BSE calculation */&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 (&amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;) and the transfer momenta (&amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt;) 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 MoS2, 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://gitlab.com/lumen-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.&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/(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. 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. &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 --debug&lt;br /&gt;
&lt;br /&gt;
At the end, check the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 ls SAVE/ndb.elph_gkkp*&lt;br /&gt;
&lt;br /&gt;
to see that it has created the Yambo-compatible electron-phonon databases.&lt;br /&gt;
&lt;br /&gt;
If you saved the &amp;lt;code&amp;gt;lelphc.in&amp;lt;/code&amp;gt; input file, you can 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;
You can also run it as it is, but the code will generate the database &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt;. In order to convert it to the &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases of Yambo, you still 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;
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;
== 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;. In this version of the tutorial we present the latter case.&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,q) - \sum_{cc^\prime vk} A^{\alpha, *}_{c^\prime v} (k+q, q) g_{c^\prime c}^\mu (k+q,q) A^{\lambda}_{cv}(k,q)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here, &amp;lt;math&amp;gt;A^{\lambda}_{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;
&lt;br /&gt;
We have to write a new yambo input, that we can call &amp;lt;code&amp;gt;excph.in&amp;lt;/code&amp;gt;, for this. You can copy (and adapt) the one below, or you can generate one by running from the command line:&lt;br /&gt;
&lt;br /&gt;
 yambo_ph -excph o&lt;br /&gt;
&lt;br /&gt;
This generates an input to compute luminescence (&amp;quot;o&amp;quot; is for &amp;quot;optics&amp;quot;). The variables that we are interested in are:&lt;br /&gt;
&lt;br /&gt;
 excph                            # [R] Exction-phonon&lt;br /&gt;
 ExcGkkp                          # [R][EXCPH] Exciton-Phonon Matrix Elelements&lt;br /&gt;
 % ELPhExcStates&lt;br /&gt;
  1 | 4 |                             # [EXCPH] Incoming (external) exciton states&lt;br /&gt;
 %&lt;br /&gt;
 % ELPhExcSum&lt;br /&gt;
  1 | 12 |                             # [EXCPH] Outgoing (virtual) exciton states&lt;br /&gt;
 %&lt;br /&gt;
 LoutPath= &amp;quot;./bse_Lfull&amp;quot;                 # [EXCPH] Path of the outgoing L&lt;br /&gt;
 % ElPhModes&lt;br /&gt;
   1 | 9 |                           # [ELPH] Phonon modes included&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
In this input, we have to select the initial exciton states &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; with &amp;lt;code&amp;gt;ELPhExcStates&amp;lt;/code&amp;gt;, the final exciton states &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; with &amp;lt;code&amp;gt;ELPhExcSum&amp;lt;/code&amp;gt; and the phonon modes &amp;lt;math&amp;gt;\mu&amp;lt;/math&amp;gt; with &amp;lt;code&amp;gt;ElPhModes&amp;lt;/code&amp;gt;. Here we consider the first four states at &amp;lt;math&amp;gt;Q=0&amp;lt;/math&amp;gt; (corresponding to just two excitons because they are both doubly degenerate -- do not break degeneracies when selecting states!) and the first twelve states at each finite-&amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; point. We also include all the nine phonon modes of monolayer MoS2.&lt;br /&gt;
&lt;br /&gt;
What about &amp;lt;code&amp;gt;LoutPath&amp;lt;/code&amp;gt;? This variable controls the directory where the databases for the final-state excitons &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; is located, which can be different from the directory with the initial-state excitons &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; read as usual with the &amp;lt;code&amp;gt;-J&amp;lt;/code&amp;gt; option when running the code. This makes it possible to compute the coupling between different exciton kinds. However, for our tutorial, we stick with the previously computed &amp;lt;code&amp;gt;Lfull&amp;lt;/code&amp;gt; in both cases.&lt;br /&gt;
&lt;br /&gt;
When we are satisfied with the input, we run the code using &amp;lt;code&amp;gt;yambo_ph&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 yambo_ph -F excph.in -J excph,bse_Lfull -C excph&lt;br /&gt;
&lt;br /&gt;
If you check the output, you should find the &amp;lt;code&amp;gt;ndb.excph*&amp;lt;/code&amp;gt; databases in the &amp;lt;code&amp;gt;excph&amp;lt;/code&amp;gt; directory.&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 MoS2, 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 using the &amp;lt;code&amp;gt;YamboExcitonPhononDB&amp;lt;/code&amp;gt; from yambopy. &lt;br /&gt;
You can find 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;
 # Exciton in states&lt;br /&gt;
 exc_in  = [2,3]     # A: 2,3 -- B: 6,7&lt;br /&gt;
 exc_out = [0,1,2,3] # first 4 states (dispersion of triplet state and A)&lt;br /&gt;
 ph_in  = &#039;all&#039;&lt;br /&gt;
 &lt;br /&gt;
 # Paths of databases&lt;br /&gt;
 ns_db1 =f&#039;{path}/SAVE/ns.db1&#039;&lt;br /&gt;
 ndb_exc=f&#039;{path}/excph&#039;&lt;br /&gt;
 &lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
Then, we load the data:&lt;br /&gt;
&lt;br /&gt;
 # Read lattice and k-space info&lt;br /&gt;
 ylat = YamboLatticeDB.from_db_file(filename=ns_db1),Expand=True)&lt;br /&gt;
 print(ylat)&lt;br /&gt;
 &lt;br /&gt;
 # Read exc-ph databases&lt;br /&gt;
 X = YamboExcitonPhononDB(ylat,save_excph=ndb_exc)&lt;br /&gt;
 print(X)&lt;br /&gt;
&lt;br /&gt;
The quantity &amp;lt;math&amp;gt;F_A(q)&amp;lt;/math&amp;gt; is defined inside the plotting function as&lt;br /&gt;
&lt;br /&gt;
 G_squared = excph.excph_sq&lt;br /&gt;
 G2plt = np.zeros(len(G_squared))&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 # Switch from Ha to eV&lt;br /&gt;
&lt;br /&gt;
And finally, we have to make a plotting function. For this tutorial we will use the default scatterplot provided by &amp;lt;code&amp;gt;YamboExcitonPhononDB&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 excph.plot_excph(F_q,plt_cbar=plt_cbar,**kwargs)&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 this 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 ExcPh.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^{(1)}_{PL}(\omega;T) \propto \frac{1}{N_q}\sum_{ s \mu \beta q} \left|\sum_\lambda\frac{D_\lambda \mathcal{G}^{\mu q}_{\alpha q,\lambda}}{E_{\alpha q}-E_\lambda -s\Omega_{\mu q}} \right|^2 N_{\alpha q}(T_{exc}) F^s_{\mu q}(T)\delta(\omega - \left[E_{\alpha q}-s\Omega_{\mu q}\right])&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;
The occupation function &amp;lt;math&amp;gt;F&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;F^s_{\mu q}(T)=n_{\mu q}(T)+\frac{1+s}{2}&amp;lt;/math&amp;gt;. Here, &amp;lt;math&amp;gt;n(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^{(1)}_{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;
=== 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 yambopy to get the el-ph matrix elements:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph path/of/dvscf/hbn.dvscf -b 7 10 -par 4 2 &lt;br /&gt;
&lt;br /&gt;
6. And finally we generate the exciton-phonon input &amp;lt;code&amp;gt;excph.in&amp;lt;/code&amp;gt; using &amp;lt;code&amp;gt;yambo_ph -excph o&amp;lt;/code&amp;gt;. Now, we take a look at all the additional variables that we didn&#039;t check before, specifying also the details for luminescence the spectrum calculation.&lt;br /&gt;
&lt;br /&gt;
 excph                            # [R] Exction-phonon&lt;br /&gt;
 ExcGkkp                          # [R][EXCPH] Exciton-Phonon Matrix Elelements&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;ExcPhOptics                      # [R][EXCPH] Exciton-Phonon Optics&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;BoseTemp=10.000000         Kn    # Bosonic Temperature&amp;lt;/span&amp;gt; &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;EXCTemp= 10.000000          Kn    # [EXCPH] Excitonic Temperature (for luminescence spectra)&amp;lt;/span&amp;gt;&lt;br /&gt;
 % ELPhExcStates&lt;br /&gt;
  1 | 4 |                             # [EXCPH] Incoming (external) exciton states&lt;br /&gt;
 %&lt;br /&gt;
 % ELPhExcSum&lt;br /&gt;
  1 | 12 |                             # [EXCPH] Outgoing (virtual) exciton states&lt;br /&gt;
 %&lt;br /&gt;
 % ElPhModes&lt;br /&gt;
  1 | 12 |                           # [ELPH] Phonon modes included&lt;br /&gt;
 %&lt;br /&gt;
 LoutPath= &amp;quot;./bse-L_full&amp;quot;                 # [EXCPH] Path of the outgoing L&lt;br /&gt;
 FANdEtresh= 0.100000E-5    eV    # [ELPH] Energy treshold for Fan denominator&lt;br /&gt;
 EXCPHdEtresh= 0.100000E-5  eV    # [ELPH] Energy treshold for exc-ph denominator&lt;br /&gt;
 LDamping= 0.500000E-3      eV    # [EXCPH] Damping of exc-ph self-energy&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# These are the plot parameters, same as in other parts of yambo&amp;lt;/span&amp;gt; &lt;br /&gt;
 % EnRngeXd&lt;br /&gt;
   4.00000 | 5.00000 |         eV    # [Xd] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 % DmRngeXd&lt;br /&gt;
  0.00500000 | 0.00500000 |         eV    # [Xd] Damping range&lt;br /&gt;
 %&lt;br /&gt;
 ETStpsXd= 4000                    # [Xd] Total Energy steps&lt;br /&gt;
&lt;br /&gt;
Here &amp;lt;code&amp;gt;BoseTemp&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXCTemp&amp;lt;/code&amp;gt; are the lattice and excitonic temperature, respectively.&lt;br /&gt;
&lt;br /&gt;
Now we run the calculation with &amp;lt;code&amp;gt;yambo_ph&amp;lt;/code&amp;gt;. Here, we read as &amp;lt;math&amp;gt;Q=0&amp;lt;/math&amp;gt; excitons with &amp;lt;code&amp;gt;-J&amp;lt;/code&amp;gt; the ones without the long-range Coulomb exchange:&lt;br /&gt;
&lt;br /&gt;
 yambo_ph -F excph.in -J excph,bse_Lbar -C excph&lt;br /&gt;
&lt;br /&gt;
and we find our outputs in the &amp;lt;code&amp;gt;excph&amp;lt;/code&amp;gt; directory. &lt;br /&gt;
&lt;br /&gt;
NB: Step 6 could have been equivalently run in yambopy, limiting the use of the yambo code to just step 4. This latter option is more flexible, as it allows for a greater degree of control by the user. We are in the last stages of the development and it will be available soon.&lt;br /&gt;
&lt;br /&gt;
=== Results ===&lt;br /&gt;
&lt;br /&gt;
If we check the output directory from the step 6 calculation, we find the &amp;lt;code&amp;gt;o-excph.pl_bse_ph_ass&amp;lt;/code&amp;gt; output files containing the luminescence spectra. We can plot them with gnuplot or any other tool:&lt;br /&gt;
&lt;br /&gt;
 gnuplot&lt;br /&gt;
 &amp;gt; set xrange[4.2:5]&lt;br /&gt;
 &amp;gt; p &#039;o-excph.pl_bse_ph_ass&#039; u 1:2 w l lc rgb &#039;red&#039; lw 3&lt;br /&gt;
&lt;br /&gt;
[[File:Luminescence plot.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;[https://m.booksee.org/book/1121964?force_lang=en Optical processes in solids], Toyozawa, Yutaka, and Chris Oxlade. 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;[https://www.yambo-code.eu/wiki/images/5/54/These_final.pdf Exciton-phonon coupling and phonon-assisted luminescence in hexagonal Boron Nitride nanostructures], PhD Thesis, Pierre Lechifflart (2023)&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;[https://arxiv.org/abs/2305.17554 Distinguishing different stackings in layered materials via luminescence spectroscopy], M. Zanfrognini et al. Phys. Rev. Lett. &#039;&#039;&#039;131&#039;&#039;&#039;, 206902 (2023) &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;[https://arxiv.org/abs/2205.02783 Exciton-phonon interaction calls for a revision of the “exciton” concept], F. Paleari, A. Marini, Phys. Rev. B, &#039;&#039;&#039;106&#039;&#039;&#039;, 125403 (2022)&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>Attacc</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Exciton-phonon_coupling_and_luminescence&amp;diff=9170</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=9170"/>
		<updated>2025-10-06T11:52:15Z</updated>

		<summary type="html">&lt;p&gt;Attacc: /* Step 5: run a BSE calculation */&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 (&amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;) and the transfer momenta (&amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt;) 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 MoS2, 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://gitlab.com/lumen-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.&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= 8            Ry    # [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/(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. 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. &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 --debug&lt;br /&gt;
&lt;br /&gt;
At the end, check the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 ls SAVE/ndb.elph_gkkp*&lt;br /&gt;
&lt;br /&gt;
to see that it has created the Yambo-compatible electron-phonon databases.&lt;br /&gt;
&lt;br /&gt;
If you saved the &amp;lt;code&amp;gt;lelphc.in&amp;lt;/code&amp;gt; input file, you can 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;
You can also run it as it is, but the code will generate the database &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt;. In order to convert it to the &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases of Yambo, you still 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;
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;
== 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;. In this version of the tutorial we present the latter case.&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,q) - \sum_{cc^\prime vk} A^{\alpha, *}_{c^\prime v} (k+q, q) g_{c^\prime c}^\mu (k+q,q) A^{\lambda}_{cv}(k,q)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here, &amp;lt;math&amp;gt;A^{\lambda}_{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;
&lt;br /&gt;
We have to write a new yambo input, that we can call &amp;lt;code&amp;gt;excph.in&amp;lt;/code&amp;gt;, for this. You can copy (and adapt) the one below, or you can generate one by running from the command line:&lt;br /&gt;
&lt;br /&gt;
 yambo_ph -excph o&lt;br /&gt;
&lt;br /&gt;
This generates an input to compute luminescence (&amp;quot;o&amp;quot; is for &amp;quot;optics&amp;quot;). The variables that we are interested in are:&lt;br /&gt;
&lt;br /&gt;
 excph                            # [R] Exction-phonon&lt;br /&gt;
 ExcGkkp                          # [R][EXCPH] Exciton-Phonon Matrix Elelements&lt;br /&gt;
 % ELPhExcStates&lt;br /&gt;
  1 | 4 |                             # [EXCPH] Incoming (external) exciton states&lt;br /&gt;
 %&lt;br /&gt;
 % ELPhExcSum&lt;br /&gt;
  1 | 12 |                             # [EXCPH] Outgoing (virtual) exciton states&lt;br /&gt;
 %&lt;br /&gt;
 LoutPath= &amp;quot;./bse_Lfull&amp;quot;                 # [EXCPH] Path of the outgoing L&lt;br /&gt;
 % ElPhModes&lt;br /&gt;
   1 | 9 |                           # [ELPH] Phonon modes included&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
In this input, we have to select the initial exciton states &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; with &amp;lt;code&amp;gt;ELPhExcStates&amp;lt;/code&amp;gt;, the final exciton states &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; with &amp;lt;code&amp;gt;ELPhExcSum&amp;lt;/code&amp;gt; and the phonon modes &amp;lt;math&amp;gt;\mu&amp;lt;/math&amp;gt; with &amp;lt;code&amp;gt;ElPhModes&amp;lt;/code&amp;gt;. Here we consider the first four states at &amp;lt;math&amp;gt;Q=0&amp;lt;/math&amp;gt; (corresponding to just two excitons because they are both doubly degenerate -- do not break degeneracies when selecting states!) and the first twelve states at each finite-&amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; point. We also include all the nine phonon modes of monolayer MoS2.&lt;br /&gt;
&lt;br /&gt;
What about &amp;lt;code&amp;gt;LoutPath&amp;lt;/code&amp;gt;? This variable controls the directory where the databases for the final-state excitons &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; is located, which can be different from the directory with the initial-state excitons &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; read as usual with the &amp;lt;code&amp;gt;-J&amp;lt;/code&amp;gt; option when running the code. This makes it possible to compute the coupling between different exciton kinds. However, for our tutorial, we stick with the previously computed &amp;lt;code&amp;gt;Lfull&amp;lt;/code&amp;gt; in both cases.&lt;br /&gt;
&lt;br /&gt;
When we are satisfied with the input, we run the code using &amp;lt;code&amp;gt;yambo_ph&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 yambo_ph -F excph.in -J excph,bse_Lfull -C excph&lt;br /&gt;
&lt;br /&gt;
If you check the output, you should find the &amp;lt;code&amp;gt;ndb.excph*&amp;lt;/code&amp;gt; databases in the &amp;lt;code&amp;gt;excph&amp;lt;/code&amp;gt; directory.&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 MoS2, 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 using the &amp;lt;code&amp;gt;YamboExcitonPhononDB&amp;lt;/code&amp;gt; from yambopy. &lt;br /&gt;
You can find 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;
 # Exciton in states&lt;br /&gt;
 exc_in  = [2,3]     # A: 2,3 -- B: 6,7&lt;br /&gt;
 exc_out = [0,1,2,3] # first 4 states (dispersion of triplet state and A)&lt;br /&gt;
 ph_in  = &#039;all&#039;&lt;br /&gt;
 &lt;br /&gt;
 # Paths of databases&lt;br /&gt;
 ns_db1 =f&#039;{path}/SAVE/ns.db1&#039;&lt;br /&gt;
 ndb_exc=f&#039;{path}/excph&#039;&lt;br /&gt;
 &lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
Then, we load the data:&lt;br /&gt;
&lt;br /&gt;
 # Read lattice and k-space info&lt;br /&gt;
 ylat = YamboLatticeDB.from_db_file(filename=ns_db1),Expand=True)&lt;br /&gt;
 print(ylat)&lt;br /&gt;
 &lt;br /&gt;
 # Read exc-ph databases&lt;br /&gt;
 X = YamboExcitonPhononDB(ylat,save_excph=ndb_exc)&lt;br /&gt;
 print(X)&lt;br /&gt;
&lt;br /&gt;
The quantity &amp;lt;math&amp;gt;F_A(q)&amp;lt;/math&amp;gt; is defined inside the plotting function as&lt;br /&gt;
&lt;br /&gt;
 G_squared = excph.excph_sq&lt;br /&gt;
 G2plt = np.zeros(len(G_squared))&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 # Switch from Ha to eV&lt;br /&gt;
&lt;br /&gt;
And finally, we have to make a plotting function. For this tutorial we will use the default scatterplot provided by &amp;lt;code&amp;gt;YamboExcitonPhononDB&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 excph.plot_excph(F_q,plt_cbar=plt_cbar,**kwargs)&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 this 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 ExcPh.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^{(1)}_{PL}(\omega;T) \propto \frac{1}{N_q}\sum_{ s \mu \beta q} \left|\sum_\lambda\frac{D_\lambda \mathcal{G}^{\mu q}_{\alpha q,\lambda}}{E_{\alpha q}-E_\lambda -s\Omega_{\mu q}} \right|^2 N_{\alpha q}(T_{exc}) F^s_{\mu q}(T)\delta(\omega - \left[E_{\alpha q}-s\Omega_{\mu q}\right])&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;
The occupation function &amp;lt;math&amp;gt;F&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;F^s_{\mu q}(T)=n_{\mu q}(T)+\frac{1+s}{2}&amp;lt;/math&amp;gt;. Here, &amp;lt;math&amp;gt;n(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^{(1)}_{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;
=== 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 yambopy to get the el-ph matrix elements:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph path/of/dvscf/hbn.dvscf -b 7 10 -par 4 2 &lt;br /&gt;
&lt;br /&gt;
6. And finally we generate the exciton-phonon input &amp;lt;code&amp;gt;excph.in&amp;lt;/code&amp;gt; using &amp;lt;code&amp;gt;yambo_ph -excph o&amp;lt;/code&amp;gt;. Now, we take a look at all the additional variables that we didn&#039;t check before, specifying also the details for luminescence the spectrum calculation.&lt;br /&gt;
&lt;br /&gt;
 excph                            # [R] Exction-phonon&lt;br /&gt;
 ExcGkkp                          # [R][EXCPH] Exciton-Phonon Matrix Elelements&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;ExcPhOptics                      # [R][EXCPH] Exciton-Phonon Optics&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;BoseTemp=10.000000         Kn    # Bosonic Temperature&amp;lt;/span&amp;gt; &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;EXCTemp= 10.000000          Kn    # [EXCPH] Excitonic Temperature (for luminescence spectra)&amp;lt;/span&amp;gt;&lt;br /&gt;
 % ELPhExcStates&lt;br /&gt;
  1 | 4 |                             # [EXCPH] Incoming (external) exciton states&lt;br /&gt;
 %&lt;br /&gt;
 % ELPhExcSum&lt;br /&gt;
  1 | 12 |                             # [EXCPH] Outgoing (virtual) exciton states&lt;br /&gt;
 %&lt;br /&gt;
 % ElPhModes&lt;br /&gt;
  1 | 12 |                           # [ELPH] Phonon modes included&lt;br /&gt;
 %&lt;br /&gt;
 LoutPath= &amp;quot;./bse-L_full&amp;quot;                 # [EXCPH] Path of the outgoing L&lt;br /&gt;
 FANdEtresh= 0.100000E-5    eV    # [ELPH] Energy treshold for Fan denominator&lt;br /&gt;
 EXCPHdEtresh= 0.100000E-5  eV    # [ELPH] Energy treshold for exc-ph denominator&lt;br /&gt;
 LDamping= 0.500000E-3      eV    # [EXCPH] Damping of exc-ph self-energy&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# These are the plot parameters, same as in other parts of yambo&amp;lt;/span&amp;gt; &lt;br /&gt;
 % EnRngeXd&lt;br /&gt;
   4.00000 | 5.00000 |         eV    # [Xd] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 % DmRngeXd&lt;br /&gt;
  0.00500000 | 0.00500000 |         eV    # [Xd] Damping range&lt;br /&gt;
 %&lt;br /&gt;
 ETStpsXd= 4000                    # [Xd] Total Energy steps&lt;br /&gt;
&lt;br /&gt;
Here &amp;lt;code&amp;gt;BoseTemp&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXCTemp&amp;lt;/code&amp;gt; are the lattice and excitonic temperature, respectively.&lt;br /&gt;
&lt;br /&gt;
Now we run the calculation with &amp;lt;code&amp;gt;yambo_ph&amp;lt;/code&amp;gt;. Here, we read as &amp;lt;math&amp;gt;Q=0&amp;lt;/math&amp;gt; excitons with &amp;lt;code&amp;gt;-J&amp;lt;/code&amp;gt; the ones without the long-range Coulomb exchange:&lt;br /&gt;
&lt;br /&gt;
 yambo_ph -F excph.in -J excph,bse_Lbar -C excph&lt;br /&gt;
&lt;br /&gt;
and we find our outputs in the &amp;lt;code&amp;gt;excph&amp;lt;/code&amp;gt; directory. &lt;br /&gt;
&lt;br /&gt;
NB: Step 6 could have been equivalently run in yambopy, limiting the use of the yambo code to just step 4. This latter option is more flexible, as it allows for a greater degree of control by the user. We are in the last stages of the development and it will be available soon.&lt;br /&gt;
&lt;br /&gt;
=== Results ===&lt;br /&gt;
&lt;br /&gt;
If we check the output directory from the step 6 calculation, we find the &amp;lt;code&amp;gt;o-excph.pl_bse_ph_ass&amp;lt;/code&amp;gt; output files containing the luminescence spectra. We can plot them with gnuplot or any other tool:&lt;br /&gt;
&lt;br /&gt;
 gnuplot&lt;br /&gt;
 &amp;gt; set xrange[4.2:5]&lt;br /&gt;
 &amp;gt; p &#039;o-excph.pl_bse_ph_ass&#039; u 1:2 w l lc rgb &#039;red&#039; lw 3&lt;br /&gt;
&lt;br /&gt;
[[File:Luminescence plot.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;[https://m.booksee.org/book/1121964?force_lang=en Optical processes in solids], Toyozawa, Yutaka, and Chris Oxlade. 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;[https://www.yambo-code.eu/wiki/images/5/54/These_final.pdf Exciton-phonon coupling and phonon-assisted luminescence in hexagonal Boron Nitride nanostructures], PhD Thesis, Pierre Lechifflart (2023)&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;[https://arxiv.org/abs/2305.17554 Distinguishing different stackings in layered materials via luminescence spectroscopy], M. Zanfrognini et al. Phys. Rev. Lett. &#039;&#039;&#039;131&#039;&#039;&#039;, 206902 (2023) &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;[https://arxiv.org/abs/2205.02783 Exciton-phonon interaction calls for a revision of the “exciton” concept], F. Paleari, A. Marini, Phys. Rev. B, &#039;&#039;&#039;106&#039;&#039;&#039;, 125403 (2022)&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>Attacc</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Exciton-phonon_coupling_and_luminescence&amp;diff=9169</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=9169"/>
		<updated>2025-10-06T11:48:31Z</updated>

		<summary type="html">&lt;p&gt;Attacc: /* Step 5: run a BSE calculation */&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 (&amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;) and the transfer momenta (&amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt;) 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 MoS2, 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://gitlab.com/lumen-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.&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;
 % QpntsRXs&lt;br /&gt;
    1 | 7 |                 # [Xs] Transferred momenta&lt;br /&gt;
 %&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= 8            Ry    # [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/(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. 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. &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 --debug&lt;br /&gt;
&lt;br /&gt;
At the end, check the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 ls SAVE/ndb.elph_gkkp*&lt;br /&gt;
&lt;br /&gt;
to see that it has created the Yambo-compatible electron-phonon databases.&lt;br /&gt;
&lt;br /&gt;
If you saved the &amp;lt;code&amp;gt;lelphc.in&amp;lt;/code&amp;gt; input file, you can 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;
You can also run it as it is, but the code will generate the database &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt;. In order to convert it to the &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases of Yambo, you still 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;
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;
== 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;. In this version of the tutorial we present the latter case.&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,q) - \sum_{cc^\prime vk} A^{\alpha, *}_{c^\prime v} (k+q, q) g_{c^\prime c}^\mu (k+q,q) A^{\lambda}_{cv}(k,q)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here, &amp;lt;math&amp;gt;A^{\lambda}_{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;
&lt;br /&gt;
We have to write a new yambo input, that we can call &amp;lt;code&amp;gt;excph.in&amp;lt;/code&amp;gt;, for this. You can copy (and adapt) the one below, or you can generate one by running from the command line:&lt;br /&gt;
&lt;br /&gt;
 yambo_ph -excph o&lt;br /&gt;
&lt;br /&gt;
This generates an input to compute luminescence (&amp;quot;o&amp;quot; is for &amp;quot;optics&amp;quot;). The variables that we are interested in are:&lt;br /&gt;
&lt;br /&gt;
 excph                            # [R] Exction-phonon&lt;br /&gt;
 ExcGkkp                          # [R][EXCPH] Exciton-Phonon Matrix Elelements&lt;br /&gt;
 % ELPhExcStates&lt;br /&gt;
  1 | 4 |                             # [EXCPH] Incoming (external) exciton states&lt;br /&gt;
 %&lt;br /&gt;
 % ELPhExcSum&lt;br /&gt;
  1 | 12 |                             # [EXCPH] Outgoing (virtual) exciton states&lt;br /&gt;
 %&lt;br /&gt;
 LoutPath= &amp;quot;./bse_Lfull&amp;quot;                 # [EXCPH] Path of the outgoing L&lt;br /&gt;
 % ElPhModes&lt;br /&gt;
   1 | 9 |                           # [ELPH] Phonon modes included&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
In this input, we have to select the initial exciton states &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; with &amp;lt;code&amp;gt;ELPhExcStates&amp;lt;/code&amp;gt;, the final exciton states &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; with &amp;lt;code&amp;gt;ELPhExcSum&amp;lt;/code&amp;gt; and the phonon modes &amp;lt;math&amp;gt;\mu&amp;lt;/math&amp;gt; with &amp;lt;code&amp;gt;ElPhModes&amp;lt;/code&amp;gt;. Here we consider the first four states at &amp;lt;math&amp;gt;Q=0&amp;lt;/math&amp;gt; (corresponding to just two excitons because they are both doubly degenerate -- do not break degeneracies when selecting states!) and the first twelve states at each finite-&amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; point. We also include all the nine phonon modes of monolayer MoS2.&lt;br /&gt;
&lt;br /&gt;
What about &amp;lt;code&amp;gt;LoutPath&amp;lt;/code&amp;gt;? This variable controls the directory where the databases for the final-state excitons &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; is located, which can be different from the directory with the initial-state excitons &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; read as usual with the &amp;lt;code&amp;gt;-J&amp;lt;/code&amp;gt; option when running the code. This makes it possible to compute the coupling between different exciton kinds. However, for our tutorial, we stick with the previously computed &amp;lt;code&amp;gt;Lfull&amp;lt;/code&amp;gt; in both cases.&lt;br /&gt;
&lt;br /&gt;
When we are satisfied with the input, we run the code using &amp;lt;code&amp;gt;yambo_ph&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 yambo_ph -F excph.in -J excph,bse_Lfull -C excph&lt;br /&gt;
&lt;br /&gt;
If you check the output, you should find the &amp;lt;code&amp;gt;ndb.excph*&amp;lt;/code&amp;gt; databases in the &amp;lt;code&amp;gt;excph&amp;lt;/code&amp;gt; directory.&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 MoS2, 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 using the &amp;lt;code&amp;gt;YamboExcitonPhononDB&amp;lt;/code&amp;gt; from yambopy. &lt;br /&gt;
You can find 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;
 # Exciton in states&lt;br /&gt;
 exc_in  = [2,3]     # A: 2,3 -- B: 6,7&lt;br /&gt;
 exc_out = [0,1,2,3] # first 4 states (dispersion of triplet state and A)&lt;br /&gt;
 ph_in  = &#039;all&#039;&lt;br /&gt;
 &lt;br /&gt;
 # Paths of databases&lt;br /&gt;
 ns_db1 =f&#039;{path}/SAVE/ns.db1&#039;&lt;br /&gt;
 ndb_exc=f&#039;{path}/excph&#039;&lt;br /&gt;
 &lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
Then, we load the data:&lt;br /&gt;
&lt;br /&gt;
 # Read lattice and k-space info&lt;br /&gt;
 ylat = YamboLatticeDB.from_db_file(filename=ns_db1),Expand=True)&lt;br /&gt;
 print(ylat)&lt;br /&gt;
 &lt;br /&gt;
 # Read exc-ph databases&lt;br /&gt;
 X = YamboExcitonPhononDB(ylat,save_excph=ndb_exc)&lt;br /&gt;
 print(X)&lt;br /&gt;
&lt;br /&gt;
The quantity &amp;lt;math&amp;gt;F_A(q)&amp;lt;/math&amp;gt; is defined inside the plotting function as&lt;br /&gt;
&lt;br /&gt;
 G_squared = excph.excph_sq&lt;br /&gt;
 G2plt = np.zeros(len(G_squared))&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 # Switch from Ha to eV&lt;br /&gt;
&lt;br /&gt;
And finally, we have to make a plotting function. For this tutorial we will use the default scatterplot provided by &amp;lt;code&amp;gt;YamboExcitonPhononDB&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 excph.plot_excph(F_q,plt_cbar=plt_cbar,**kwargs)&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 this 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 ExcPh.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^{(1)}_{PL}(\omega;T) \propto \frac{1}{N_q}\sum_{ s \mu \beta q} \left|\sum_\lambda\frac{D_\lambda \mathcal{G}^{\mu q}_{\alpha q,\lambda}}{E_{\alpha q}-E_\lambda -s\Omega_{\mu q}} \right|^2 N_{\alpha q}(T_{exc}) F^s_{\mu q}(T)\delta(\omega - \left[E_{\alpha q}-s\Omega_{\mu q}\right])&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;
The occupation function &amp;lt;math&amp;gt;F&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;F^s_{\mu q}(T)=n_{\mu q}(T)+\frac{1+s}{2}&amp;lt;/math&amp;gt;. Here, &amp;lt;math&amp;gt;n(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^{(1)}_{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;
=== 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 yambopy to get the el-ph matrix elements:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph path/of/dvscf/hbn.dvscf -b 7 10 -par 4 2 &lt;br /&gt;
&lt;br /&gt;
6. And finally we generate the exciton-phonon input &amp;lt;code&amp;gt;excph.in&amp;lt;/code&amp;gt; using &amp;lt;code&amp;gt;yambo_ph -excph o&amp;lt;/code&amp;gt;. Now, we take a look at all the additional variables that we didn&#039;t check before, specifying also the details for luminescence the spectrum calculation.&lt;br /&gt;
&lt;br /&gt;
 excph                            # [R] Exction-phonon&lt;br /&gt;
 ExcGkkp                          # [R][EXCPH] Exciton-Phonon Matrix Elelements&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;ExcPhOptics                      # [R][EXCPH] Exciton-Phonon Optics&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;BoseTemp=10.000000         Kn    # Bosonic Temperature&amp;lt;/span&amp;gt; &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;EXCTemp= 10.000000          Kn    # [EXCPH] Excitonic Temperature (for luminescence spectra)&amp;lt;/span&amp;gt;&lt;br /&gt;
 % ELPhExcStates&lt;br /&gt;
  1 | 4 |                             # [EXCPH] Incoming (external) exciton states&lt;br /&gt;
 %&lt;br /&gt;
 % ELPhExcSum&lt;br /&gt;
  1 | 12 |                             # [EXCPH] Outgoing (virtual) exciton states&lt;br /&gt;
 %&lt;br /&gt;
 % ElPhModes&lt;br /&gt;
  1 | 12 |                           # [ELPH] Phonon modes included&lt;br /&gt;
 %&lt;br /&gt;
 LoutPath= &amp;quot;./bse-L_full&amp;quot;                 # [EXCPH] Path of the outgoing L&lt;br /&gt;
 FANdEtresh= 0.100000E-5    eV    # [ELPH] Energy treshold for Fan denominator&lt;br /&gt;
 EXCPHdEtresh= 0.100000E-5  eV    # [ELPH] Energy treshold for exc-ph denominator&lt;br /&gt;
 LDamping= 0.500000E-3      eV    # [EXCPH] Damping of exc-ph self-energy&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# These are the plot parameters, same as in other parts of yambo&amp;lt;/span&amp;gt; &lt;br /&gt;
 % EnRngeXd&lt;br /&gt;
   4.00000 | 5.00000 |         eV    # [Xd] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 % DmRngeXd&lt;br /&gt;
  0.00500000 | 0.00500000 |         eV    # [Xd] Damping range&lt;br /&gt;
 %&lt;br /&gt;
 ETStpsXd= 4000                    # [Xd] Total Energy steps&lt;br /&gt;
&lt;br /&gt;
Here &amp;lt;code&amp;gt;BoseTemp&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXCTemp&amp;lt;/code&amp;gt; are the lattice and excitonic temperature, respectively.&lt;br /&gt;
&lt;br /&gt;
Now we run the calculation with &amp;lt;code&amp;gt;yambo_ph&amp;lt;/code&amp;gt;. Here, we read as &amp;lt;math&amp;gt;Q=0&amp;lt;/math&amp;gt; excitons with &amp;lt;code&amp;gt;-J&amp;lt;/code&amp;gt; the ones without the long-range Coulomb exchange:&lt;br /&gt;
&lt;br /&gt;
 yambo_ph -F excph.in -J excph,bse_Lbar -C excph&lt;br /&gt;
&lt;br /&gt;
and we find our outputs in the &amp;lt;code&amp;gt;excph&amp;lt;/code&amp;gt; directory. &lt;br /&gt;
&lt;br /&gt;
NB: Step 6 could have been equivalently run in yambopy, limiting the use of the yambo code to just step 4. This latter option is more flexible, as it allows for a greater degree of control by the user. We are in the last stages of the development and it will be available soon.&lt;br /&gt;
&lt;br /&gt;
=== Results ===&lt;br /&gt;
&lt;br /&gt;
If we check the output directory from the step 6 calculation, we find the &amp;lt;code&amp;gt;o-excph.pl_bse_ph_ass&amp;lt;/code&amp;gt; output files containing the luminescence spectra. We can plot them with gnuplot or any other tool:&lt;br /&gt;
&lt;br /&gt;
 gnuplot&lt;br /&gt;
 &amp;gt; set xrange[4.2:5]&lt;br /&gt;
 &amp;gt; p &#039;o-excph.pl_bse_ph_ass&#039; u 1:2 w l lc rgb &#039;red&#039; lw 3&lt;br /&gt;
&lt;br /&gt;
[[File:Luminescence plot.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;[https://m.booksee.org/book/1121964?force_lang=en Optical processes in solids], Toyozawa, Yutaka, and Chris Oxlade. 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;[https://www.yambo-code.eu/wiki/images/5/54/These_final.pdf Exciton-phonon coupling and phonon-assisted luminescence in hexagonal Boron Nitride nanostructures], PhD Thesis, Pierre Lechifflart (2023)&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;[https://arxiv.org/abs/2305.17554 Distinguishing different stackings in layered materials via luminescence spectroscopy], M. Zanfrognini et al. Phys. Rev. Lett. &#039;&#039;&#039;131&#039;&#039;&#039;, 206902 (2023) &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;[https://arxiv.org/abs/2205.02783 Exciton-phonon interaction calls for a revision of the “exciton” concept], F. Paleari, A. Marini, Phys. Rev. B, &#039;&#039;&#039;106&#039;&#039;&#039;, 125403 (2022)&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>Attacc</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Exciton-phonon_coupling_and_luminescence&amp;diff=9168</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=9168"/>
		<updated>2025-10-06T11:48:10Z</updated>

		<summary type="html">&lt;p&gt;Attacc: /* Step 5: run a BSE calculation */&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 (&amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;) and the transfer momenta (&amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt;) 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 MoS2, 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://gitlab.com/lumen-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.&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;
 % QpntsRXs&lt;br /&gt;
    1 | 7 |                 # [Xs] Transferred momenta&lt;br /&gt;
 %&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= 8            Ry    # [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/(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 is 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. 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. &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 --debug&lt;br /&gt;
&lt;br /&gt;
At the end, check the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 ls SAVE/ndb.elph_gkkp*&lt;br /&gt;
&lt;br /&gt;
to see that it has created the Yambo-compatible electron-phonon databases.&lt;br /&gt;
&lt;br /&gt;
If you saved the &amp;lt;code&amp;gt;lelphc.in&amp;lt;/code&amp;gt; input file, you can 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;
You can also run it as it is, but the code will generate the database &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt;. In order to convert it to the &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases of Yambo, you still 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;
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;
== 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;. In this version of the tutorial we present the latter case.&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,q) - \sum_{cc^\prime vk} A^{\alpha, *}_{c^\prime v} (k+q, q) g_{c^\prime c}^\mu (k+q,q) A^{\lambda}_{cv}(k,q)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here, &amp;lt;math&amp;gt;A^{\lambda}_{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;
&lt;br /&gt;
We have to write a new yambo input, that we can call &amp;lt;code&amp;gt;excph.in&amp;lt;/code&amp;gt;, for this. You can copy (and adapt) the one below, or you can generate one by running from the command line:&lt;br /&gt;
&lt;br /&gt;
 yambo_ph -excph o&lt;br /&gt;
&lt;br /&gt;
This generates an input to compute luminescence (&amp;quot;o&amp;quot; is for &amp;quot;optics&amp;quot;). The variables that we are interested in are:&lt;br /&gt;
&lt;br /&gt;
 excph                            # [R] Exction-phonon&lt;br /&gt;
 ExcGkkp                          # [R][EXCPH] Exciton-Phonon Matrix Elelements&lt;br /&gt;
 % ELPhExcStates&lt;br /&gt;
  1 | 4 |                             # [EXCPH] Incoming (external) exciton states&lt;br /&gt;
 %&lt;br /&gt;
 % ELPhExcSum&lt;br /&gt;
  1 | 12 |                             # [EXCPH] Outgoing (virtual) exciton states&lt;br /&gt;
 %&lt;br /&gt;
 LoutPath= &amp;quot;./bse_Lfull&amp;quot;                 # [EXCPH] Path of the outgoing L&lt;br /&gt;
 % ElPhModes&lt;br /&gt;
   1 | 9 |                           # [ELPH] Phonon modes included&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
In this input, we have to select the initial exciton states &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; with &amp;lt;code&amp;gt;ELPhExcStates&amp;lt;/code&amp;gt;, the final exciton states &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; with &amp;lt;code&amp;gt;ELPhExcSum&amp;lt;/code&amp;gt; and the phonon modes &amp;lt;math&amp;gt;\mu&amp;lt;/math&amp;gt; with &amp;lt;code&amp;gt;ElPhModes&amp;lt;/code&amp;gt;. Here we consider the first four states at &amp;lt;math&amp;gt;Q=0&amp;lt;/math&amp;gt; (corresponding to just two excitons because they are both doubly degenerate -- do not break degeneracies when selecting states!) and the first twelve states at each finite-&amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; point. We also include all the nine phonon modes of monolayer MoS2.&lt;br /&gt;
&lt;br /&gt;
What about &amp;lt;code&amp;gt;LoutPath&amp;lt;/code&amp;gt;? This variable controls the directory where the databases for the final-state excitons &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; is located, which can be different from the directory with the initial-state excitons &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; read as usual with the &amp;lt;code&amp;gt;-J&amp;lt;/code&amp;gt; option when running the code. This makes it possible to compute the coupling between different exciton kinds. However, for our tutorial, we stick with the previously computed &amp;lt;code&amp;gt;Lfull&amp;lt;/code&amp;gt; in both cases.&lt;br /&gt;
&lt;br /&gt;
When we are satisfied with the input, we run the code using &amp;lt;code&amp;gt;yambo_ph&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 yambo_ph -F excph.in -J excph,bse_Lfull -C excph&lt;br /&gt;
&lt;br /&gt;
If you check the output, you should find the &amp;lt;code&amp;gt;ndb.excph*&amp;lt;/code&amp;gt; databases in the &amp;lt;code&amp;gt;excph&amp;lt;/code&amp;gt; directory.&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 MoS2, 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 using the &amp;lt;code&amp;gt;YamboExcitonPhononDB&amp;lt;/code&amp;gt; from yambopy. &lt;br /&gt;
You can find 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;
 # Exciton in states&lt;br /&gt;
 exc_in  = [2,3]     # A: 2,3 -- B: 6,7&lt;br /&gt;
 exc_out = [0,1,2,3] # first 4 states (dispersion of triplet state and A)&lt;br /&gt;
 ph_in  = &#039;all&#039;&lt;br /&gt;
 &lt;br /&gt;
 # Paths of databases&lt;br /&gt;
 ns_db1 =f&#039;{path}/SAVE/ns.db1&#039;&lt;br /&gt;
 ndb_exc=f&#039;{path}/excph&#039;&lt;br /&gt;
 &lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
Then, we load the data:&lt;br /&gt;
&lt;br /&gt;
 # Read lattice and k-space info&lt;br /&gt;
 ylat = YamboLatticeDB.from_db_file(filename=ns_db1),Expand=True)&lt;br /&gt;
 print(ylat)&lt;br /&gt;
 &lt;br /&gt;
 # Read exc-ph databases&lt;br /&gt;
 X = YamboExcitonPhononDB(ylat,save_excph=ndb_exc)&lt;br /&gt;
 print(X)&lt;br /&gt;
&lt;br /&gt;
The quantity &amp;lt;math&amp;gt;F_A(q)&amp;lt;/math&amp;gt; is defined inside the plotting function as&lt;br /&gt;
&lt;br /&gt;
 G_squared = excph.excph_sq&lt;br /&gt;
 G2plt = np.zeros(len(G_squared))&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 # Switch from Ha to eV&lt;br /&gt;
&lt;br /&gt;
And finally, we have to make a plotting function. For this tutorial we will use the default scatterplot provided by &amp;lt;code&amp;gt;YamboExcitonPhononDB&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 excph.plot_excph(F_q,plt_cbar=plt_cbar,**kwargs)&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 this 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 ExcPh.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^{(1)}_{PL}(\omega;T) \propto \frac{1}{N_q}\sum_{ s \mu \beta q} \left|\sum_\lambda\frac{D_\lambda \mathcal{G}^{\mu q}_{\alpha q,\lambda}}{E_{\alpha q}-E_\lambda -s\Omega_{\mu q}} \right|^2 N_{\alpha q}(T_{exc}) F^s_{\mu q}(T)\delta(\omega - \left[E_{\alpha q}-s\Omega_{\mu q}\right])&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;
The occupation function &amp;lt;math&amp;gt;F&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;F^s_{\mu q}(T)=n_{\mu q}(T)+\frac{1+s}{2}&amp;lt;/math&amp;gt;. Here, &amp;lt;math&amp;gt;n(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^{(1)}_{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;
=== 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 yambopy to get the el-ph matrix elements:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph path/of/dvscf/hbn.dvscf -b 7 10 -par 4 2 &lt;br /&gt;
&lt;br /&gt;
6. And finally we generate the exciton-phonon input &amp;lt;code&amp;gt;excph.in&amp;lt;/code&amp;gt; using &amp;lt;code&amp;gt;yambo_ph -excph o&amp;lt;/code&amp;gt;. Now, we take a look at all the additional variables that we didn&#039;t check before, specifying also the details for luminescence the spectrum calculation.&lt;br /&gt;
&lt;br /&gt;
 excph                            # [R] Exction-phonon&lt;br /&gt;
 ExcGkkp                          # [R][EXCPH] Exciton-Phonon Matrix Elelements&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;ExcPhOptics                      # [R][EXCPH] Exciton-Phonon Optics&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;BoseTemp=10.000000         Kn    # Bosonic Temperature&amp;lt;/span&amp;gt; &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;EXCTemp= 10.000000          Kn    # [EXCPH] Excitonic Temperature (for luminescence spectra)&amp;lt;/span&amp;gt;&lt;br /&gt;
 % ELPhExcStates&lt;br /&gt;
  1 | 4 |                             # [EXCPH] Incoming (external) exciton states&lt;br /&gt;
 %&lt;br /&gt;
 % ELPhExcSum&lt;br /&gt;
  1 | 12 |                             # [EXCPH] Outgoing (virtual) exciton states&lt;br /&gt;
 %&lt;br /&gt;
 % ElPhModes&lt;br /&gt;
  1 | 12 |                           # [ELPH] Phonon modes included&lt;br /&gt;
 %&lt;br /&gt;
 LoutPath= &amp;quot;./bse-L_full&amp;quot;                 # [EXCPH] Path of the outgoing L&lt;br /&gt;
 FANdEtresh= 0.100000E-5    eV    # [ELPH] Energy treshold for Fan denominator&lt;br /&gt;
 EXCPHdEtresh= 0.100000E-5  eV    # [ELPH] Energy treshold for exc-ph denominator&lt;br /&gt;
 LDamping= 0.500000E-3      eV    # [EXCPH] Damping of exc-ph self-energy&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# These are the plot parameters, same as in other parts of yambo&amp;lt;/span&amp;gt; &lt;br /&gt;
 % EnRngeXd&lt;br /&gt;
   4.00000 | 5.00000 |         eV    # [Xd] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 % DmRngeXd&lt;br /&gt;
  0.00500000 | 0.00500000 |         eV    # [Xd] Damping range&lt;br /&gt;
 %&lt;br /&gt;
 ETStpsXd= 4000                    # [Xd] Total Energy steps&lt;br /&gt;
&lt;br /&gt;
Here &amp;lt;code&amp;gt;BoseTemp&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXCTemp&amp;lt;/code&amp;gt; are the lattice and excitonic temperature, respectively.&lt;br /&gt;
&lt;br /&gt;
Now we run the calculation with &amp;lt;code&amp;gt;yambo_ph&amp;lt;/code&amp;gt;. Here, we read as &amp;lt;math&amp;gt;Q=0&amp;lt;/math&amp;gt; excitons with &amp;lt;code&amp;gt;-J&amp;lt;/code&amp;gt; the ones without the long-range Coulomb exchange:&lt;br /&gt;
&lt;br /&gt;
 yambo_ph -F excph.in -J excph,bse_Lbar -C excph&lt;br /&gt;
&lt;br /&gt;
and we find our outputs in the &amp;lt;code&amp;gt;excph&amp;lt;/code&amp;gt; directory. &lt;br /&gt;
&lt;br /&gt;
NB: Step 6 could have been equivalently run in yambopy, limiting the use of the yambo code to just step 4. This latter option is more flexible, as it allows for a greater degree of control by the user. We are in the last stages of the development and it will be available soon.&lt;br /&gt;
&lt;br /&gt;
=== Results ===&lt;br /&gt;
&lt;br /&gt;
If we check the output directory from the step 6 calculation, we find the &amp;lt;code&amp;gt;o-excph.pl_bse_ph_ass&amp;lt;/code&amp;gt; output files containing the luminescence spectra. We can plot them with gnuplot or any other tool:&lt;br /&gt;
&lt;br /&gt;
 gnuplot&lt;br /&gt;
 &amp;gt; set xrange[4.2:5]&lt;br /&gt;
 &amp;gt; p &#039;o-excph.pl_bse_ph_ass&#039; u 1:2 w l lc rgb &#039;red&#039; lw 3&lt;br /&gt;
&lt;br /&gt;
[[File:Luminescence plot.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;[https://m.booksee.org/book/1121964?force_lang=en Optical processes in solids], Toyozawa, Yutaka, and Chris Oxlade. 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;[https://www.yambo-code.eu/wiki/images/5/54/These_final.pdf Exciton-phonon coupling and phonon-assisted luminescence in hexagonal Boron Nitride nanostructures], PhD Thesis, Pierre Lechifflart (2023)&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;[https://arxiv.org/abs/2305.17554 Distinguishing different stackings in layered materials via luminescence spectroscopy], M. Zanfrognini et al. Phys. Rev. Lett. &#039;&#039;&#039;131&#039;&#039;&#039;, 206902 (2023) &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;[https://arxiv.org/abs/2205.02783 Exciton-phonon interaction calls for a revision of the “exciton” concept], F. Paleari, A. Marini, Phys. Rev. B, &#039;&#039;&#039;106&#039;&#039;&#039;, 125403 (2022)&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>Attacc</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Exciton-phonon_coupling_and_luminescence&amp;diff=9167</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=9167"/>
		<updated>2025-10-06T11:40:07Z</updated>

		<summary type="html">&lt;p&gt;Attacc: /* Running the jobs */&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 (&amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;) and the transfer momenta (&amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt;) 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 MoS2, 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://gitlab.com/lumen-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.&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;
 % QpntsRXs&lt;br /&gt;
    1 | 7 |                 # [Xs] Transferred momenta&lt;br /&gt;
 %&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= 8            Ry    # [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/(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;
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. 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. &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 --debug&lt;br /&gt;
&lt;br /&gt;
At the end, check the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 ls SAVE/ndb.elph_gkkp*&lt;br /&gt;
&lt;br /&gt;
to see that it has created the Yambo-compatible electron-phonon databases.&lt;br /&gt;
&lt;br /&gt;
If you saved the &amp;lt;code&amp;gt;lelphc.in&amp;lt;/code&amp;gt; input file, you can 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;
You can also run it as it is, but the code will generate the database &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt;. In order to convert it to the &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases of Yambo, you still 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;
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;
== 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;. In this version of the tutorial we present the latter case.&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,q) - \sum_{cc^\prime vk} A^{\alpha, *}_{c^\prime v} (k+q, q) g_{c^\prime c}^\mu (k+q,q) A^{\lambda}_{cv}(k,q)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here, &amp;lt;math&amp;gt;A^{\lambda}_{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;
&lt;br /&gt;
We have to write a new yambo input, that we can call &amp;lt;code&amp;gt;excph.in&amp;lt;/code&amp;gt;, for this. You can copy (and adapt) the one below, or you can generate one by running from the command line:&lt;br /&gt;
&lt;br /&gt;
 yambo_ph -excph o&lt;br /&gt;
&lt;br /&gt;
This generates an input to compute luminescence (&amp;quot;o&amp;quot; is for &amp;quot;optics&amp;quot;). The variables that we are interested in are:&lt;br /&gt;
&lt;br /&gt;
 excph                            # [R] Exction-phonon&lt;br /&gt;
 ExcGkkp                          # [R][EXCPH] Exciton-Phonon Matrix Elelements&lt;br /&gt;
 % ELPhExcStates&lt;br /&gt;
  1 | 4 |                             # [EXCPH] Incoming (external) exciton states&lt;br /&gt;
 %&lt;br /&gt;
 % ELPhExcSum&lt;br /&gt;
  1 | 12 |                             # [EXCPH] Outgoing (virtual) exciton states&lt;br /&gt;
 %&lt;br /&gt;
 LoutPath= &amp;quot;./bse_Lfull&amp;quot;                 # [EXCPH] Path of the outgoing L&lt;br /&gt;
 % ElPhModes&lt;br /&gt;
   1 | 9 |                           # [ELPH] Phonon modes included&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
In this input, we have to select the initial exciton states &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; with &amp;lt;code&amp;gt;ELPhExcStates&amp;lt;/code&amp;gt;, the final exciton states &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; with &amp;lt;code&amp;gt;ELPhExcSum&amp;lt;/code&amp;gt; and the phonon modes &amp;lt;math&amp;gt;\mu&amp;lt;/math&amp;gt; with &amp;lt;code&amp;gt;ElPhModes&amp;lt;/code&amp;gt;. Here we consider the first four states at &amp;lt;math&amp;gt;Q=0&amp;lt;/math&amp;gt; (corresponding to just two excitons because they are both doubly degenerate -- do not break degeneracies when selecting states!) and the first twelve states at each finite-&amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; point. We also include all the nine phonon modes of monolayer MoS2.&lt;br /&gt;
&lt;br /&gt;
What about &amp;lt;code&amp;gt;LoutPath&amp;lt;/code&amp;gt;? This variable controls the directory where the databases for the final-state excitons &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; is located, which can be different from the directory with the initial-state excitons &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; read as usual with the &amp;lt;code&amp;gt;-J&amp;lt;/code&amp;gt; option when running the code. This makes it possible to compute the coupling between different exciton kinds. However, for our tutorial, we stick with the previously computed &amp;lt;code&amp;gt;Lfull&amp;lt;/code&amp;gt; in both cases.&lt;br /&gt;
&lt;br /&gt;
When we are satisfied with the input, we run the code using &amp;lt;code&amp;gt;yambo_ph&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 yambo_ph -F excph.in -J excph,bse_Lfull -C excph&lt;br /&gt;
&lt;br /&gt;
If you check the output, you should find the &amp;lt;code&amp;gt;ndb.excph*&amp;lt;/code&amp;gt; databases in the &amp;lt;code&amp;gt;excph&amp;lt;/code&amp;gt; directory.&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 MoS2, 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 using the &amp;lt;code&amp;gt;YamboExcitonPhononDB&amp;lt;/code&amp;gt; from yambopy. &lt;br /&gt;
You can find 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;
 # Exciton in states&lt;br /&gt;
 exc_in  = [2,3]     # A: 2,3 -- B: 6,7&lt;br /&gt;
 exc_out = [0,1,2,3] # first 4 states (dispersion of triplet state and A)&lt;br /&gt;
 ph_in  = &#039;all&#039;&lt;br /&gt;
 &lt;br /&gt;
 # Paths of databases&lt;br /&gt;
 ns_db1 =f&#039;{path}/SAVE/ns.db1&#039;&lt;br /&gt;
 ndb_exc=f&#039;{path}/excph&#039;&lt;br /&gt;
 &lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
Then, we load the data:&lt;br /&gt;
&lt;br /&gt;
 # Read lattice and k-space info&lt;br /&gt;
 ylat = YamboLatticeDB.from_db_file(filename=ns_db1),Expand=True)&lt;br /&gt;
 print(ylat)&lt;br /&gt;
 &lt;br /&gt;
 # Read exc-ph databases&lt;br /&gt;
 X = YamboExcitonPhononDB(ylat,save_excph=ndb_exc)&lt;br /&gt;
 print(X)&lt;br /&gt;
&lt;br /&gt;
The quantity &amp;lt;math&amp;gt;F_A(q)&amp;lt;/math&amp;gt; is defined inside the plotting function as&lt;br /&gt;
&lt;br /&gt;
 G_squared = excph.excph_sq&lt;br /&gt;
 G2plt = np.zeros(len(G_squared))&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 # Switch from Ha to eV&lt;br /&gt;
&lt;br /&gt;
And finally, we have to make a plotting function. For this tutorial we will use the default scatterplot provided by &amp;lt;code&amp;gt;YamboExcitonPhononDB&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 excph.plot_excph(F_q,plt_cbar=plt_cbar,**kwargs)&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 this 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 ExcPh.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^{(1)}_{PL}(\omega;T) \propto \frac{1}{N_q}\sum_{ s \mu \beta q} \left|\sum_\lambda\frac{D_\lambda \mathcal{G}^{\mu q}_{\alpha q,\lambda}}{E_{\alpha q}-E_\lambda -s\Omega_{\mu q}} \right|^2 N_{\alpha q}(T_{exc}) F^s_{\mu q}(T)\delta(\omega - \left[E_{\alpha q}-s\Omega_{\mu q}\right])&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;
The occupation function &amp;lt;math&amp;gt;F&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;F^s_{\mu q}(T)=n_{\mu q}(T)+\frac{1+s}{2}&amp;lt;/math&amp;gt;. Here, &amp;lt;math&amp;gt;n(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^{(1)}_{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;
=== 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 yambopy to get the el-ph matrix elements:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph path/of/dvscf/hbn.dvscf -b 7 10 -par 4 2 &lt;br /&gt;
&lt;br /&gt;
6. And finally we generate the exciton-phonon input &amp;lt;code&amp;gt;excph.in&amp;lt;/code&amp;gt; using &amp;lt;code&amp;gt;yambo_ph -excph o&amp;lt;/code&amp;gt;. Now, we take a look at all the additional variables that we didn&#039;t check before, specifying also the details for luminescence the spectrum calculation.&lt;br /&gt;
&lt;br /&gt;
 excph                            # [R] Exction-phonon&lt;br /&gt;
 ExcGkkp                          # [R][EXCPH] Exciton-Phonon Matrix Elelements&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;ExcPhOptics                      # [R][EXCPH] Exciton-Phonon Optics&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;BoseTemp=10.000000         Kn    # Bosonic Temperature&amp;lt;/span&amp;gt; &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;EXCTemp= 10.000000          Kn    # [EXCPH] Excitonic Temperature (for luminescence spectra)&amp;lt;/span&amp;gt;&lt;br /&gt;
 % ELPhExcStates&lt;br /&gt;
  1 | 4 |                             # [EXCPH] Incoming (external) exciton states&lt;br /&gt;
 %&lt;br /&gt;
 % ELPhExcSum&lt;br /&gt;
  1 | 12 |                             # [EXCPH] Outgoing (virtual) exciton states&lt;br /&gt;
 %&lt;br /&gt;
 % ElPhModes&lt;br /&gt;
  1 | 12 |                           # [ELPH] Phonon modes included&lt;br /&gt;
 %&lt;br /&gt;
 LoutPath= &amp;quot;./bse-L_full&amp;quot;                 # [EXCPH] Path of the outgoing L&lt;br /&gt;
 FANdEtresh= 0.100000E-5    eV    # [ELPH] Energy treshold for Fan denominator&lt;br /&gt;
 EXCPHdEtresh= 0.100000E-5  eV    # [ELPH] Energy treshold for exc-ph denominator&lt;br /&gt;
 LDamping= 0.500000E-3      eV    # [EXCPH] Damping of exc-ph self-energy&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# These are the plot parameters, same as in other parts of yambo&amp;lt;/span&amp;gt; &lt;br /&gt;
 % EnRngeXd&lt;br /&gt;
   4.00000 | 5.00000 |         eV    # [Xd] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 % DmRngeXd&lt;br /&gt;
  0.00500000 | 0.00500000 |         eV    # [Xd] Damping range&lt;br /&gt;
 %&lt;br /&gt;
 ETStpsXd= 4000                    # [Xd] Total Energy steps&lt;br /&gt;
&lt;br /&gt;
Here &amp;lt;code&amp;gt;BoseTemp&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXCTemp&amp;lt;/code&amp;gt; are the lattice and excitonic temperature, respectively.&lt;br /&gt;
&lt;br /&gt;
Now we run the calculation with &amp;lt;code&amp;gt;yambo_ph&amp;lt;/code&amp;gt;. Here, we read as &amp;lt;math&amp;gt;Q=0&amp;lt;/math&amp;gt; excitons with &amp;lt;code&amp;gt;-J&amp;lt;/code&amp;gt; the ones without the long-range Coulomb exchange:&lt;br /&gt;
&lt;br /&gt;
 yambo_ph -F excph.in -J excph,bse_Lbar -C excph&lt;br /&gt;
&lt;br /&gt;
and we find our outputs in the &amp;lt;code&amp;gt;excph&amp;lt;/code&amp;gt; directory. &lt;br /&gt;
&lt;br /&gt;
NB: Step 6 could have been equivalently run in yambopy, limiting the use of the yambo code to just step 4. This latter option is more flexible, as it allows for a greater degree of control by the user. We are in the last stages of the development and it will be available soon.&lt;br /&gt;
&lt;br /&gt;
=== Results ===&lt;br /&gt;
&lt;br /&gt;
If we check the output directory from the step 6 calculation, we find the &amp;lt;code&amp;gt;o-excph.pl_bse_ph_ass&amp;lt;/code&amp;gt; output files containing the luminescence spectra. We can plot them with gnuplot or any other tool:&lt;br /&gt;
&lt;br /&gt;
 gnuplot&lt;br /&gt;
 &amp;gt; set xrange[4.2:5]&lt;br /&gt;
 &amp;gt; p &#039;o-excph.pl_bse_ph_ass&#039; u 1:2 w l lc rgb &#039;red&#039; lw 3&lt;br /&gt;
&lt;br /&gt;
[[File:Luminescence plot.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;[https://m.booksee.org/book/1121964?force_lang=en Optical processes in solids], Toyozawa, Yutaka, and Chris Oxlade. 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;[https://www.yambo-code.eu/wiki/images/5/54/These_final.pdf Exciton-phonon coupling and phonon-assisted luminescence in hexagonal Boron Nitride nanostructures], PhD Thesis, Pierre Lechifflart (2023)&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;[https://arxiv.org/abs/2305.17554 Distinguishing different stackings in layered materials via luminescence spectroscopy], M. Zanfrognini et al. Phys. Rev. Lett. &#039;&#039;&#039;131&#039;&#039;&#039;, 206902 (2023) &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;[https://arxiv.org/abs/2205.02783 Exciton-phonon interaction calls for a revision of the “exciton” concept], F. Paleari, A. Marini, Phys. Rev. B, &#039;&#039;&#039;106&#039;&#039;&#039;, 125403 (2022)&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>Attacc</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Exciton-phonon_coupling_and_luminescence&amp;diff=9166</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=9166"/>
		<updated>2025-10-06T11:38:46Z</updated>

		<summary type="html">&lt;p&gt;Attacc: /* Step 5: run a BSE calculation */&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 (&amp;lt;math&amp;gt;k&amp;lt;/math&amp;gt;) and the transfer momenta (&amp;lt;math&amp;gt;Q&amp;lt;/math&amp;gt;, &amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt;) 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 MoS2, 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://gitlab.com/lumen-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.&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;
 % QpntsRXs&lt;br /&gt;
    1 | 7 |                 # [Xs] Transferred momenta&lt;br /&gt;
 %&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= 8            Ry    # [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/(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;
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. 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. &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 --debug&lt;br /&gt;
&lt;br /&gt;
At the end, check the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 ls SAVE/ndb.elph_gkkp*&lt;br /&gt;
&lt;br /&gt;
to see that it has created the Yambo-compatible electron-phonon databases.&lt;br /&gt;
&lt;br /&gt;
If you saved the &amp;lt;code&amp;gt;lelphc.in&amp;lt;/code&amp;gt; input file, you can 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;
You can also run it as it is, but the code will generate the database &amp;lt;code&amp;gt;ndb.elph&amp;lt;/code&amp;gt;. In order to convert it to the &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt; databases of Yambo, you still 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;
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;
== 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;. In this version of the tutorial we present the latter case.&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,q) - \sum_{cc^\prime vk} A^{\alpha, *}_{c^\prime v} (k+q, q) g_{c^\prime c}^\mu (k+q,q) A^{\lambda}_{cv}(k,q)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here, &amp;lt;math&amp;gt;A^{\lambda}_{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;
&lt;br /&gt;
We have to write a new yambo input, that we can call &amp;lt;code&amp;gt;excph.in&amp;lt;/code&amp;gt;, for this. You can copy (and adapt) the one below, or you can generate one by running from the command line:&lt;br /&gt;
&lt;br /&gt;
 yambo_ph -excph o&lt;br /&gt;
&lt;br /&gt;
This generates an input to compute luminescence (&amp;quot;o&amp;quot; is for &amp;quot;optics&amp;quot;). The variables that we are interested in are:&lt;br /&gt;
&lt;br /&gt;
 excph                            # [R] Exction-phonon&lt;br /&gt;
 ExcGkkp                          # [R][EXCPH] Exciton-Phonon Matrix Elelements&lt;br /&gt;
 % ELPhExcStates&lt;br /&gt;
  1 | 4 |                             # [EXCPH] Incoming (external) exciton states&lt;br /&gt;
 %&lt;br /&gt;
 % ELPhExcSum&lt;br /&gt;
  1 | 12 |                             # [EXCPH] Outgoing (virtual) exciton states&lt;br /&gt;
 %&lt;br /&gt;
 LoutPath= &amp;quot;./bse_Lfull&amp;quot;                 # [EXCPH] Path of the outgoing L&lt;br /&gt;
 % ElPhModes&lt;br /&gt;
   1 | 9 |                           # [ELPH] Phonon modes included&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
In this input, we have to select the initial exciton states &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; with &amp;lt;code&amp;gt;ELPhExcStates&amp;lt;/code&amp;gt;, the final exciton states &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; with &amp;lt;code&amp;gt;ELPhExcSum&amp;lt;/code&amp;gt; and the phonon modes &amp;lt;math&amp;gt;\mu&amp;lt;/math&amp;gt; with &amp;lt;code&amp;gt;ElPhModes&amp;lt;/code&amp;gt;. Here we consider the first four states at &amp;lt;math&amp;gt;Q=0&amp;lt;/math&amp;gt; (corresponding to just two excitons because they are both doubly degenerate -- do not break degeneracies when selecting states!) and the first twelve states at each finite-&amp;lt;math&amp;gt;q&amp;lt;/math&amp;gt; point. We also include all the nine phonon modes of monolayer MoS2.&lt;br /&gt;
&lt;br /&gt;
What about &amp;lt;code&amp;gt;LoutPath&amp;lt;/code&amp;gt;? This variable controls the directory where the databases for the final-state excitons &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; is located, which can be different from the directory with the initial-state excitons &amp;lt;math&amp;gt;\lambda&amp;lt;/math&amp;gt; read as usual with the &amp;lt;code&amp;gt;-J&amp;lt;/code&amp;gt; option when running the code. This makes it possible to compute the coupling between different exciton kinds. However, for our tutorial, we stick with the previously computed &amp;lt;code&amp;gt;Lfull&amp;lt;/code&amp;gt; in both cases.&lt;br /&gt;
&lt;br /&gt;
When we are satisfied with the input, we run the code using &amp;lt;code&amp;gt;yambo_ph&amp;lt;/code&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
 yambo_ph -F excph.in -J excph,bse_Lfull -C excph&lt;br /&gt;
&lt;br /&gt;
If you check the output, you should find the &amp;lt;code&amp;gt;ndb.excph*&amp;lt;/code&amp;gt; databases in the &amp;lt;code&amp;gt;excph&amp;lt;/code&amp;gt; directory.&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 MoS2, 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 using the &amp;lt;code&amp;gt;YamboExcitonPhononDB&amp;lt;/code&amp;gt; from yambopy. &lt;br /&gt;
You can find 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;
 # Exciton in states&lt;br /&gt;
 exc_in  = [2,3]     # A: 2,3 -- B: 6,7&lt;br /&gt;
 exc_out = [0,1,2,3] # first 4 states (dispersion of triplet state and A)&lt;br /&gt;
 ph_in  = &#039;all&#039;&lt;br /&gt;
 &lt;br /&gt;
 # Paths of databases&lt;br /&gt;
 ns_db1 =f&#039;{path}/SAVE/ns.db1&#039;&lt;br /&gt;
 ndb_exc=f&#039;{path}/excph&#039;&lt;br /&gt;
 &lt;br /&gt;
 ...&lt;br /&gt;
&lt;br /&gt;
Then, we load the data:&lt;br /&gt;
&lt;br /&gt;
 # Read lattice and k-space info&lt;br /&gt;
 ylat = YamboLatticeDB.from_db_file(filename=ns_db1),Expand=True)&lt;br /&gt;
 print(ylat)&lt;br /&gt;
 &lt;br /&gt;
 # Read exc-ph databases&lt;br /&gt;
 X = YamboExcitonPhononDB(ylat,save_excph=ndb_exc)&lt;br /&gt;
 print(X)&lt;br /&gt;
&lt;br /&gt;
The quantity &amp;lt;math&amp;gt;F_A(q)&amp;lt;/math&amp;gt; is defined inside the plotting function as&lt;br /&gt;
&lt;br /&gt;
 G_squared = excph.excph_sq&lt;br /&gt;
 G2plt = np.zeros(len(G_squared))&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 # Switch from Ha to eV&lt;br /&gt;
&lt;br /&gt;
And finally, we have to make a plotting function. For this tutorial we will use the default scatterplot provided by &amp;lt;code&amp;gt;YamboExcitonPhononDB&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 excph.plot_excph(F_q,plt_cbar=plt_cbar,**kwargs)&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 this 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 ExcPh.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^{(1)}_{PL}(\omega;T) \propto \frac{1}{N_q}\sum_{ s \mu \beta q} \left|\sum_\lambda\frac{D_\lambda \mathcal{G}^{\mu q}_{\alpha q,\lambda}}{E_{\alpha q}-E_\lambda -s\Omega_{\mu q}} \right|^2 N_{\alpha q}(T_{exc}) F^s_{\mu q}(T)\delta(\omega - \left[E_{\alpha q}-s\Omega_{\mu q}\right])&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;
The occupation function &amp;lt;math&amp;gt;F&amp;lt;/math&amp;gt; is &amp;lt;math&amp;gt;F^s_{\mu q}(T)=n_{\mu q}(T)+\frac{1+s}{2}&amp;lt;/math&amp;gt;. Here, &amp;lt;math&amp;gt;n(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^{(1)}_{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;
=== 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= 30               Ry    # [BSK] Exchange components&lt;br /&gt;
 #ALLGexx                       # [BSS] Force the use use all RL vectors for the exchange part&lt;br /&gt;
 BSENGBlk=  9               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 yambopy to get the el-ph matrix elements:&lt;br /&gt;
&lt;br /&gt;
 yambopy l2y -ph path/of/dvscf/hbn.dvscf -b 7 10 -par 4 2 &lt;br /&gt;
&lt;br /&gt;
6. And finally we generate the exciton-phonon input &amp;lt;code&amp;gt;excph.in&amp;lt;/code&amp;gt; using &amp;lt;code&amp;gt;yambo_ph -excph o&amp;lt;/code&amp;gt;. Now, we take a look at all the additional variables that we didn&#039;t check before, specifying also the details for luminescence the spectrum calculation.&lt;br /&gt;
&lt;br /&gt;
 excph                            # [R] Exction-phonon&lt;br /&gt;
 ExcGkkp                          # [R][EXCPH] Exciton-Phonon Matrix Elelements&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;ExcPhOptics                      # [R][EXCPH] Exciton-Phonon Optics&amp;lt;/span&amp;gt;&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;BoseTemp=10.000000         Kn    # Bosonic Temperature&amp;lt;/span&amp;gt; &lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;EXCTemp= 10.000000          Kn    # [EXCPH] Excitonic Temperature (for luminescence spectra)&amp;lt;/span&amp;gt;&lt;br /&gt;
 % ELPhExcStates&lt;br /&gt;
  1 | 4 |                             # [EXCPH] Incoming (external) exciton states&lt;br /&gt;
 %&lt;br /&gt;
 % ELPhExcSum&lt;br /&gt;
  1 | 12 |                             # [EXCPH] Outgoing (virtual) exciton states&lt;br /&gt;
 %&lt;br /&gt;
 % ElPhModes&lt;br /&gt;
  1 | 12 |                           # [ELPH] Phonon modes included&lt;br /&gt;
 %&lt;br /&gt;
 LoutPath= &amp;quot;./bse-L_full&amp;quot;                 # [EXCPH] Path of the outgoing L&lt;br /&gt;
 FANdEtresh= 0.100000E-5    eV    # [ELPH] Energy treshold for Fan denominator&lt;br /&gt;
 EXCPHdEtresh= 0.100000E-5  eV    # [ELPH] Energy treshold for exc-ph denominator&lt;br /&gt;
 LDamping= 0.500000E-3      eV    # [EXCPH] Damping of exc-ph self-energy&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:blue&amp;quot;&amp;gt;# These are the plot parameters, same as in other parts of yambo&amp;lt;/span&amp;gt; &lt;br /&gt;
 % EnRngeXd&lt;br /&gt;
   4.00000 | 5.00000 |         eV    # [Xd] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 % DmRngeXd&lt;br /&gt;
  0.00500000 | 0.00500000 |         eV    # [Xd] Damping range&lt;br /&gt;
 %&lt;br /&gt;
 ETStpsXd= 4000                    # [Xd] Total Energy steps&lt;br /&gt;
&lt;br /&gt;
Here &amp;lt;code&amp;gt;BoseTemp&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;EXCTemp&amp;lt;/code&amp;gt; are the lattice and excitonic temperature, respectively.&lt;br /&gt;
&lt;br /&gt;
Now we run the calculation with &amp;lt;code&amp;gt;yambo_ph&amp;lt;/code&amp;gt;. Here, we read as &amp;lt;math&amp;gt;Q=0&amp;lt;/math&amp;gt; excitons with &amp;lt;code&amp;gt;-J&amp;lt;/code&amp;gt; the ones without the long-range Coulomb exchange:&lt;br /&gt;
&lt;br /&gt;
 yambo_ph -F excph.in -J excph,bse_Lbar -C excph&lt;br /&gt;
&lt;br /&gt;
and we find our outputs in the &amp;lt;code&amp;gt;excph&amp;lt;/code&amp;gt; directory. &lt;br /&gt;
&lt;br /&gt;
NB: Step 6 could have been equivalently run in yambopy, limiting the use of the yambo code to just step 4. This latter option is more flexible, as it allows for a greater degree of control by the user. We are in the last stages of the development and it will be available soon.&lt;br /&gt;
&lt;br /&gt;
=== Results ===&lt;br /&gt;
&lt;br /&gt;
If we check the output directory from the step 6 calculation, we find the &amp;lt;code&amp;gt;o-excph.pl_bse_ph_ass&amp;lt;/code&amp;gt; output files containing the luminescence spectra. We can plot them with gnuplot or any other tool:&lt;br /&gt;
&lt;br /&gt;
 gnuplot&lt;br /&gt;
 &amp;gt; set xrange[4.2:5]&lt;br /&gt;
 &amp;gt; p &#039;o-excph.pl_bse_ph_ass&#039; u 1:2 w l lc rgb &#039;red&#039; lw 3&lt;br /&gt;
&lt;br /&gt;
[[File:Luminescence plot.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;[https://m.booksee.org/book/1121964?force_lang=en Optical processes in solids], Toyozawa, Yutaka, and Chris Oxlade. 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;[https://www.yambo-code.eu/wiki/images/5/54/These_final.pdf Exciton-phonon coupling and phonon-assisted luminescence in hexagonal Boron Nitride nanostructures], PhD Thesis, Pierre Lechifflart (2023)&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;[https://arxiv.org/abs/2305.17554 Distinguishing different stackings in layered materials via luminescence spectroscopy], M. Zanfrognini et al. Phys. Rev. Lett. &#039;&#039;&#039;131&#039;&#039;&#039;, 206902 (2023) &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;[https://arxiv.org/abs/2205.02783 Exciton-phonon interaction calls for a revision of the “exciton” concept], F. Paleari, A. Marini, Phys. Rev. B, &#039;&#039;&#039;106&#039;&#039;&#039;, 125403 (2022)&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>Attacc</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Real_time_approach_to_non-linear_response_(SHG)&amp;diff=9165</id>
		<title>Real time approach to non-linear response (SHG)</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Real_time_approach_to_non-linear_response_(SHG)&amp;diff=9165"/>
		<updated>2025-09-28T08:04:04Z</updated>

		<summary type="html">&lt;p&gt;Attacc: /* How to choose the external field direction for the different X2 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Second Harmonic Generation in AlAs ==&lt;br /&gt;
In this tutorial, we will calculate the second harmonic generation of bulk AlAs, the Yambo databases can be downloaded here: [https://media.yambo-code.eu/educational/tutorials/files/AlAs_DBs.tar.gz AlAs_DBs.tar.gz] (10 MB). The first steps of this tutorials are the same as the one on [http://www.yambo-code.eu/wiki/index.php?title=Prerequisites_for_Real_Time_propagation_with_Yambo Prerequisites for Real-Time propagation with Yambo] with the only difference that we will work on AlAs and we will consider an external field in the direction &amp;lt;code&amp;gt; 1.000000 | 1.000000 | 0.000000 |&amp;lt;/code&amp;gt;. The DFT input are available here: [https://media.yambo-code.eu/educational/tutorials/files/AlAs_abinit.tar.gz ABINIT] or [https://media.yambo-code.eu/educational/tutorials/files/AlAs_pwscf.tar.gz QuantumEspresso].&lt;br /&gt;
You can run the DFT calculation with ABINIT with the command:&lt;br /&gt;
&lt;br /&gt;
 abinit &amp;lt; AlAs.in &amp;gt; output_AlAs                                             &lt;br /&gt;
&lt;br /&gt;
or using QuantumEspresso:&lt;br /&gt;
&lt;br /&gt;
 pw.x -inp AlAs.scf.in &amp;gt; output_scf&lt;br /&gt;
 pw.x -inp AlAs.nscf.in &amp;gt; output_scf                            &lt;br /&gt;
&lt;br /&gt;
and then import the ABINIT wave-function with the command:&lt;br /&gt;
&lt;br /&gt;
 a2y -F AlAso_DS2_WFK.nc                            &lt;br /&gt;
&lt;br /&gt;
and the QuantumEspresso one, in the folder AlAs.save with the command:&lt;br /&gt;
&lt;br /&gt;
 p2y                              &lt;br /&gt;
Now we consider an external field in the &amp;lt;code&amp;gt;[1,1,0]&amp;lt;/code&amp;gt; direction and remove symmetries not compatible with this field, as explained in the tutorial [http://www.yambo-code.eu/wiki/index.php?title=Prerequisites_for_Real_Time_propagation_with_Yambo Prerequisites for Real-Time propagation with Yambo].&lt;br /&gt;
&lt;br /&gt;
==Real-time simulation for the SHG==&lt;br /&gt;
&lt;br /&gt;
You can generate the input file with the command &amp;lt;code&amp;gt;yambo_nl -u n&amp;lt;/code&amp;gt;:&lt;br /&gt;
                       &lt;br /&gt;
 nloptics                      # [R NL] Non-linear optics&lt;br /&gt;
 % NLBands&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 3 | 6&amp;lt;/span&amp;gt; |                   # [NL] Bands&lt;br /&gt;
 %&lt;br /&gt;
 NLstep=   0.0100       fs    # [NL] Real Time step length&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;NLverbosity= &amp;quot;high&amp;quot;&amp;lt;/span&amp;gt;               # [NL] Verbosity level (low | high)&lt;br /&gt;
 NLtime=-1.000000           fs    # [NL] Simulation Time&lt;br /&gt;
 NLintegrator= &amp;quot;INVINT&amp;quot;       # [NL] Integrator (&amp;quot;EULEREXP/RK4/RK2EXP/HEUN/INVINT/CRANKNIC&amp;quot;)&lt;br /&gt;
 NLCorrelation= &amp;quot;IPA&amp;quot;         # [NL] Correlation (&amp;quot;IPA/HARTREE/TDDFT/LRC/JGM/SEX/HF&amp;quot;)&lt;br /&gt;
 NLLrcAlpha= 0.000000         # [NL] Long Range Correction&lt;br /&gt;
 % NLEnRange&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;  1.000000 | 5.000000 &amp;lt;/span&amp;gt;| eV    # [NL] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 NLEnSteps= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 5  &amp;lt;/span&amp;gt;              # [NL] Energy steps&lt;br /&gt;
 NLDamping= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 0.150000  &amp;lt;/span&amp;gt;  eV    # [NL] Damping&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 1.000000 | 1.000000 | 0.000000 &amp;lt;/span&amp;gt;|        # [RT Field1] Versor&lt;br /&gt;
 Field1_kind= &amp;quot;SOFTSIN&amp;quot;         # [NL ExtF] Kind(SIN|SOFTSIN|RES|ANTIRES|GAUSS|DELTA|QSSIN)&lt;br /&gt;
&lt;br /&gt;
The line &amp;lt;code&amp;gt;|1.000000 | 1.000000 | 0.000000 | # [RT Field1] Versor&amp;lt;/code&amp;gt; referees to the direction of the external field (x,y,0). At present only an external field is present but the code can be easily generalized to deal with more fields.&lt;br /&gt;
The default parameters of Yambo/Lumen are already tuned for second-harmonic generation, so the only thing you have to change is the band range, between 3 and 6 and the energy range between 1.0-5.0 eV and the number of energy steps in this interval that we set to 10. Notice that you cannot set to zero the lowest value of the energy range because this will requires a simulation that lasts infinite time, see below. Finally, consider that Yambo performs a separate calculation for each frequency, so if you set many energy steps the computational time grows linearly with this number.&lt;br /&gt;
Notice that we set &amp;lt;code&amp;gt;NLverbosity= &amp;quot;high&amp;quot;&amp;lt;/code&amp;gt; in this way the code will produce a file for each laser frequency containing the time dependent polarization.&lt;br /&gt;
Run &amp;lt;code&amp;gt;yambo_nl&amp;lt;/code&amp;gt;. Calculations will take about fifteen minutes on a single processor PC, you have time to study the next section that explains how non-linear response is extracted from the real-time simulations.&lt;br /&gt;
In order to speed up calculations, you can run them in parallel.&lt;br /&gt;
&lt;br /&gt;
==Non-linear response with Yambo==&lt;br /&gt;
&lt;br /&gt;
In order to calculate the non-linear response, the system is excited with different laser fields with a sinusoidal shape at frequencies &amp;lt;math&amp;gt;\omega_1, \omega_2, .... , \omega_n &amp;lt;/math&amp;gt; determined by the parameters [[Variables#NLEnRangev|NLEnRange]] and [[Variables#NLEnSteps|NLEnSteps]]. A dephasing term is added to the Hamiltonian &amp;lt;math&amp;gt;\gamma = &amp;lt;/math&amp;gt;[[Variables#NLDamping|NLDamping]] to simulate a finite broadening and to remove the eigenmodes that are excited by the sudden turning on of the external field. After the dephasing time the outgoing signal is analyzed to extract the non-linear coefficients as shown in the figure below: &lt;br /&gt;
&lt;br /&gt;
[[File:Pt analysis.png|600px|center|Non-linear response analysis]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the report file &amp;lt;code&amp;gt;r_nlinear&amp;lt;/code&amp;gt; you will find the length of the dephasing part and of the sampling one:&lt;br /&gt;
&lt;br /&gt;
  Dephasing Time          [fs]: 52.65695&lt;br /&gt;
  Sampling  Time          [fs]:  4.18566&lt;br /&gt;
  Total simulation time   [fs]: 56.84262                     &lt;br /&gt;
The length of the dephasing interval is inversely proportional to the damping term &amp;lt;math&amp;gt;T_{depth} \simeq 1/\gamma&amp;lt;/math&amp;gt; while the length of the sampling is dictated by the smallest frequency we are interested in: &amp;lt;math&amp;gt;T_{samp} \simeq 1/\omega_1 &amp;lt;/math&amp;gt;. For this reason if &amp;lt;math&amp;gt; \omega_1=0 &amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt; \gamma = 0 &amp;lt;/math&amp;gt; simulation time goes to infinity. The response at zero frequency can be calculated as limit of small frequency perturbation.&lt;br /&gt;
You can have a look to the file &amp;lt;code&amp;gt;src/nloptics/NL_initialize.F&amp;lt;/code&amp;gt; to see how simulation lengths are defined.&lt;br /&gt;
Calculations can take some time, run them in parallel, the best number of processors = number of frequencies or reduce the number of frequencies step in the SHG.&lt;br /&gt;
&lt;br /&gt;
==Analysis of the results==&lt;br /&gt;
&lt;br /&gt;
In the sampling region we suppose that the polarization can be written as: &amp;lt;math&amp;gt;\bf{P}(t) = \sum_{n=-\infty}^{+\infty} \bf{p}_n e^{-i\omega_n t} &amp;lt;/math&amp;gt; where the coefficient &amp;lt;math&amp;gt;\bf{p}_1,...,\bf{p}_n &amp;lt;/math&amp;gt; are related to &amp;lt;math&amp;gt;\chi^{(1)},...,\chi^{(n)} &amp;lt;/math&amp;gt;. We sample the polarization signal at different times and invert the previous equation by truncating the sum at a finite order &amp;lt;ref&amp;gt;[https://arxiv.org/abs/1309.4012 Nonlinear optics from an ab initio approach by means of the dynamical Berry phase: Application to second- and third-harmonic generation in semiconductors], C. Attaccalite and M. Grüning, Phys. Rev. B 88, 235113(2013)&amp;lt;/ref&amp;gt;.&lt;br /&gt;
This is done with the command &amp;lt;code&amp;gt;ypp_nl -u&amp;lt;/code&amp;gt; that automatically produce an input with the correct values:&lt;br /&gt;
&lt;br /&gt;
 nonlinear                    # [R] NonLinear Optics Post-Processing&lt;br /&gt;
 Xorder=   &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;4  &amp;lt;/span&amp;gt;                 # Max order of the response functions&lt;br /&gt;
 % TimeRange&lt;br /&gt;
  52.65695 | -1.00000 | fs    # Time-window where processing is done&lt;br /&gt;
 % &lt;br /&gt;
 ETStpsRt= 200                # Total Energy steps&lt;br /&gt;
 % EnRngeRt&lt;br /&gt;
   0.00000 | 10.00000 | eV    # Energy range&lt;br /&gt;
 %&lt;br /&gt;
 DampMode= &amp;quot;NONE&amp;quot;             # Damping type ( NONE | LORENTZIAN | GAUSSIAN )&lt;br /&gt;
 DampFactor=  0.10000   eV    # Damping parameter&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;code&amp;gt;Xorder&amp;lt;/code&amp;gt; is the order where the previous sum is truncated, and the TimeRange specifies the sampling region. Notice that differently from the first tutorial, in this case, we do not need Damping in &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; because we already included it in the real-time dynamics. Run &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; and it will produce a file called &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;. This file contains the different components of &amp;lt;math&amp;gt;\chi^2_{xy*} &amp;lt;/math&amp;gt; and in particular the columns 6 and 7 correspond to the imaginary and real part of &amp;lt;math&amp;gt;\chi^2_{xyz} &amp;lt;/math&amp;gt;. You can plot the result with gnuplot and the command:&lt;br /&gt;
&lt;br /&gt;
 p &#039;o.YPP-X_probe_order_2&#039; u 1:(sqrt($6**2+$7**2)) w lp ps 1.5 pt 7 lw 1.5&lt;br /&gt;
&lt;br /&gt;
the result should look like&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AlAs results.png|700px|center|SHG in AlAs]]&lt;br /&gt;
&lt;br /&gt;
and compare it with the &amp;lt;math&amp;gt; \chi^2_{zxy} &amp;lt;/math&amp;gt; calculated with more frequencies and with the converged result on a &amp;lt;math&amp;gt; 18x18x18&amp;lt;/math&amp;gt; k-point grid and bands between 2 and 10. In the figure you can find also the comparison with the results of Ref. &amp;lt;ref&amp;gt;Luppi et al. [https://arxiv.org/abs/1006.2649 PRB B, &#039;&#039;&#039;82&#039;&#039;&#039;, 235201(2010)]&amp;lt;/ref&amp;gt;. &lt;br /&gt;
Notice that the QuantumEspresso results are slightly different from the Abinit ones. This is due to the different pseudo-potential employed in the calculations if pseudopotentials were the same calculation would have been identical. You can download the script to generate this plot and the converged results [http://www.attaccalite.com/lumen/tutorials/AlAs/AlAs_results.tgz here].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notice that&#039;&#039;&#039; : the following parameters are not used in the non-linear response analysis: &amp;lt;code&amp;gt; EnRngeRt&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ETStpsRt&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;DampMode&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;DampFactor&amp;lt;/code&amp;gt;. The damping factor is set directly in the real-time simulation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;System of units in Non-linear Optics&amp;lt;/span&amp;gt;&#039;&#039;&#039;: notice that in Yambo the non-linear response functions are in the gaussian system of units, for example the &amp;lt;math&amp;gt; \chi^2 (\omega) &amp;lt;/math&amp;gt;  is in cm/statvolt. In order to convert the non-linear coefficients between different system of units, you can have a look at the [https://www.attaccalite.com/tutorials_yambo/Appendix_C_Boyd.pdf Appendix C] of the book [https://www.elsevier.com/books/nonlinear-optics/boyd/978-0-12-369470-6 &amp;quot;Non-linear optics&amp;quot;  by Robert W. Boyd].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;More tutorials&amp;lt;/span&amp;gt; on non-linear response (Third harmonic generation, parallelization, spin-orbit etc..) with Yambo can be found here: [http://www.attaccalite.com/lumen/tutorials.html More Tutorials]. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Analysis of the results using YamboPy==&lt;br /&gt;
The analysis of the result performed in the previous section using &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; can be performed using python script [https://github.com/yambo-code/yambopy YamboPy].&amp;lt;br&amp;gt;&lt;br /&gt;
In YamboPy we implemented all necessary functions to reads the Yambo databases and post-process the results. Here we show how to get the SHG signal from the previous &lt;br /&gt;
simulations. We suppose you correctly installed &amp;lt;code&amp;gt;YamboPy&amp;lt;/code&amp;gt; on your PC. Go in the folder where you ran non-linear calculation and type in the python:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
 from yambopy import *&lt;br /&gt;
 NLDB=YamboNLDB()&lt;br /&gt;
 pol =NLDB.Polarization[0]&lt;br /&gt;
 time=NLDB.IO_TIME_points&lt;br /&gt;
&lt;br /&gt;
in this way you read all the Non-linear databases. If your runs are in a different folder then the &#039;SAVE&#039; one you can specify it using the command:&lt;br /&gt;
 NLDB=YamboNLDB(calc=&#039;MYJOB&#039;)&lt;br /&gt;
&lt;br /&gt;
now in the array &amp;lt;code&amp;gt;pol&amp;lt;/code&amp;gt; you have all the polarization for all laser frequencies in the three Cartesian directions, while the variable &amp;lt;code&amp;gt;time&amp;lt;/code&amp;gt; contains all the time series of your simulation.&lt;br /&gt;
Now you can get the non-linear response with the command:&lt;br /&gt;
&lt;br /&gt;
 Harmonic_Analysis(NLDB,X_order=4)&lt;br /&gt;
&lt;br /&gt;
this command will perform a Fourier analysis of the results in the same way of &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; and generate new files with all the requested harmonics &#039;&#039;o.YamboPy-X_probe_order_1&#039;&#039;, &#039;&#039;o.YamboPy-X_probe_order_2&#039;&#039; etc...&lt;br /&gt;
equivalent to the one generated by &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt;. Results can be plot with gnuplot using the command:&lt;br /&gt;
 &lt;br /&gt;
 p &#039;o.YamboPy-X_probe_order_2&#039; u 1:(sqrt($6**2+$7**2)) w lp ps 1.5 pt 7 lw 1.5&lt;br /&gt;
&lt;br /&gt;
The script that performs non-linear analysis can be found in &amp;lt;code&amp;gt;yambopy/nl/harmonic_analysis.py&amp;lt;/code&amp;gt;. &amp;lt;br&amp;gt; We strongly advice you to have a look to this script and modify it according&lt;br /&gt;
to your needs and in order to extract other non-linear response functions.&lt;br /&gt;
&lt;br /&gt;
==How to choose the external field direction for the different X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
In the X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;abc&amp;lt;/sub&amp;gt; response you have three field directions. The two components &#039;&#039;b&#039;&#039; and &#039;&#039;c&#039;&#039; are determined by the external field and the third &#039;&#039;a&#039;&#039;&lt;br /&gt;
is the direction where you measure the response.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The external field in Yambo is set using the variable&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
   1.000000 | 0.000000 | 0.000000 |        # [NL ExtF] Versor .&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
For example if you set in Yambo field direction as:&lt;br /&gt;
&lt;br /&gt;
 1.0 | 0.0 | 0.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*xx&amp;lt;/sub&amp;gt;&lt;br /&gt;
 0.0 | 1.0 | 0.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*yy&amp;lt;/sub&amp;gt;&lt;br /&gt;
 0.0 | 0.0 | 1.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*zz&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the * correspond to the different direction in the response file &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;.&lt;br /&gt;
In the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt; you have seven columns:&lt;br /&gt;
&lt;br /&gt;
 The first column is the energy [[omega]],&lt;br /&gt;
 the 2nd and 3rd columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;x**&amp;lt;/sub&amp;gt;&lt;br /&gt;
 the 4th and 5th columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;y**&amp;lt;/sub&amp;gt;&lt;br /&gt;
 the 6th and 7th columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;z**&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where the ** are the direction of the incoming field, see above.&lt;br /&gt;
&lt;br /&gt;
For example if you want to calculate the &amp;lt;math&amp;gt;\chi^{(2)}_{zxx}&amp;lt;/math&amp;gt; you put the external field in the direction &amp;lt;code&amp;gt; 1.0 | 0.0 | 0.0 |&amp;lt;/code&amp;gt;&lt;br /&gt;
and then plot the column 6 and 7 of the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt; file.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to get the other components of the  X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; the calculation are more involved. For example if you put field in the&lt;br /&gt;
&lt;br /&gt;
 1.0 | 1.0 | 0.0 | &lt;br /&gt;
&lt;br /&gt;
this corresponds to &amp;lt;math&amp;gt;E(t)=\frac{1}{\sqrt{2}} [ E_x(t) + E_y(t) ]&amp;lt;/math&amp;gt; and so at the second order you will have &amp;lt;math&amp;gt;E^2(t)=\frac{1}{2} \left [ E^2_x(t) + E^2_y(t) +  E_x(t) E_y(t) +  E_y(t) E_x(t) \right]&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
this means that  the X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; in the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;  will correspond to a linear combination of the following different response functions.&amp;lt;br&amp;gt;&lt;br /&gt;
For example in the the 2nd and 3rd columns are the imaginary and real part of:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{x**}=\frac{1}{2} \left [\chi^2_{xxx}+\chi^{(2)}_{xyy} + \chi^{(2)}_{xxy} + \chi^{(2)}_{xyx} \right ]&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the same for the other column replacing the first &amp;lt;code&amp;gt;x&amp;lt;/code&amp;gt; for &amp;lt;code&amp;gt;y,z&amp;lt;/code&amp;gt;.&lt;br /&gt;
If you know that some components are zero this allow you to extract the corresponding off-diagonal part of &amp;lt;math&amp;gt;\chi^{(2)}_{abc}&amp;lt;/math&amp;gt; otherwise you have to perform different calculations to get the component you are interested in. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Now we present &#039;&#039;&#039;a simple example of monolayer hBN (m-hBN)&#039;&#039;&#039;. &amp;lt;br&amp;gt; In m-hBN there is only a non-zero component of the &amp;lt;math&amp;gt;\chi^{(2)}&amp;lt;/math&amp;gt;and all the others are related by symmetry:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{yyy}=-\chi^{(2)}_{yxx}=-\chi^{(2)}_{xxy}=-\chi^{(2)}_{xyx}&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
so if you put the field in the &amp;lt;code&amp;gt;|1|1|0|&amp;lt;/code&amp;gt; direction you will get:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{x**} = \frac{1}{2} \left[\chi^{(2)}_{xxy} + \chi^{(2)}_{xyx} \right] = - \chi^{(2)}_{yyy} &amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{y**} =\frac{1}{2} \left[ \chi^{(2)}_{yyy} + \chi^{(2)}_{yxx}  \right] = 0.0 &amp;lt;/math&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
In the figure below you can see the different &amp;lt;math&amp;gt;\chi^{(2)}&amp;lt;/math&amp;gt; of monolayer hBN. &lt;br /&gt;
&lt;br /&gt;
[[File:Xhi2 xy.png|center| 800px|xhi2_xy]]&lt;br /&gt;
&lt;br /&gt;
as you can see in the second panel, when the field is in the &amp;lt;code&amp;gt;xy&amp;lt;/code&amp;gt; you get a linear combination of  &amp;lt;math&amp;gt;\chi^{(2)}&amp;lt;/math&amp;gt; corresponding to the equation above, in this case the &amp;lt;code&amp;gt;y&amp;lt;/code&amp;gt; is zero while the &amp;lt;code&amp;gt;x&amp;lt;/code&amp;gt; component is equal to &amp;lt;math&amp;gt;-\chi^{(2)}_{yyy}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Nota bene:&#039;&#039;&#039; if you change the direction of the external field you must to remove the corresponding symmetries as explained in the tutorial [[Prerequisites for Real Time_propagation with Yambo#Reduce symmetries real-time linear response tutorial]]. If you have to calculate &amp;lt;math&amp;gt;\chi^{(2)}&amp;lt;/math&amp;gt; along many directions it can be convenient to remove all symmetries at once.&lt;br /&gt;
&lt;br /&gt;
==Non-linear response of low-dimensional structures: 2D or 1D ==&lt;br /&gt;
&lt;br /&gt;
The Yambo code is a 3D periodic code, so when you want to study a low-dimensional system 2D or 1D, you have to use a supercell approach.&lt;br /&gt;
For example to simulate the non-linear response in a 2D-crystal one, can put the crystal in the xy plane and choose a larger distance in the z-direction&lt;br /&gt;
in order to reduce the interaction between the periodic replica. Clearly in this case k-point sampling will be only in the x,y directions.&lt;br /&gt;
For calculations on this type of systems, these two warnings must be taken into account:&lt;br /&gt;
&lt;br /&gt;
* if you calculate GW corrections or include electron-hole interaction in the linear/non-linear response it is a good idea to use a &#039;&#039;&#039;Coulomb cutoff&#039;&#039;&#039;, similar to the 2D BSE case  [http://www.yambo-code.org/wiki/index.php?title=How_to_treat_low_dimensional_systems How to treat low dimensional systems]. You can add the cutoff just adding the &amp;quot;-r&amp;quot; in the input generation.&lt;br /&gt;
&lt;br /&gt;
* the calculation of SHG and THG are always performed respect to the supercell, therefore you have to &#039;&#039;&#039;re-scale&#039;&#039;&#039; the result to the effective thickness of the layer, usually the inter-layer distance of the corresponding bulk material for 2D systems: &amp;lt;math&amp;gt;\chi_{rescaled}(\omega) = L_z/d_{eff} \cdot \chi(\omega) &amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;L_z&amp;lt;/math&amp;gt; is the z-dimension of the supercell, and &amp;lt;math&amp;gt;d_{eff}&amp;lt;/math&amp;gt; is the effective thickness of the 2D system.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Nota bene&#039;&#039;&#039;: Non-linear response along &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;non-periodic directions&amp;lt;/span&amp;gt; is not implemented in Yambo, the code will print zero in these directions for all response functions. We plan to implement it in a future version of the code.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Links for schools==&lt;br /&gt;
* Back to [[Rome 2023#Tutorials]]&lt;br /&gt;
* Back to [[ICTP2020]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
{| style=&amp;quot;width:100%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|style=&amp;quot;width:25%; text-align:left&amp;quot;|Prev: [[Linear response from real time simulations|Linear response from real time simulations]]&lt;br /&gt;
|style=&amp;quot;width:45%; text-align:center&amp;quot;|Now: [[ICTP2020|ICTP  Tutorials]] --&amp;gt; [[Real time approach to non-linear response|Non Linear Response]] &lt;br /&gt;
|style=&amp;quot;width:50%; text-align:left&amp;quot;|Next: [[Correlation effects in the non-linear response|Correlation effects in the non-linear response ]]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Attacc</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Real_time_approach_to_non-linear_response_(SHG)&amp;diff=9164</id>
		<title>Real time approach to non-linear response (SHG)</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Real_time_approach_to_non-linear_response_(SHG)&amp;diff=9164"/>
		<updated>2025-09-28T08:03:05Z</updated>

		<summary type="html">&lt;p&gt;Attacc: /* How to choose the external field direction for the different X2 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Second Harmonic Generation in AlAs ==&lt;br /&gt;
In this tutorial, we will calculate the second harmonic generation of bulk AlAs, the Yambo databases can be downloaded here: [https://media.yambo-code.eu/educational/tutorials/files/AlAs_DBs.tar.gz AlAs_DBs.tar.gz] (10 MB). The first steps of this tutorials are the same as the one on [http://www.yambo-code.eu/wiki/index.php?title=Prerequisites_for_Real_Time_propagation_with_Yambo Prerequisites for Real-Time propagation with Yambo] with the only difference that we will work on AlAs and we will consider an external field in the direction &amp;lt;code&amp;gt; 1.000000 | 1.000000 | 0.000000 |&amp;lt;/code&amp;gt;. The DFT input are available here: [https://media.yambo-code.eu/educational/tutorials/files/AlAs_abinit.tar.gz ABINIT] or [https://media.yambo-code.eu/educational/tutorials/files/AlAs_pwscf.tar.gz QuantumEspresso].&lt;br /&gt;
You can run the DFT calculation with ABINIT with the command:&lt;br /&gt;
&lt;br /&gt;
 abinit &amp;lt; AlAs.in &amp;gt; output_AlAs                                             &lt;br /&gt;
&lt;br /&gt;
or using QuantumEspresso:&lt;br /&gt;
&lt;br /&gt;
 pw.x -inp AlAs.scf.in &amp;gt; output_scf&lt;br /&gt;
 pw.x -inp AlAs.nscf.in &amp;gt; output_scf                            &lt;br /&gt;
&lt;br /&gt;
and then import the ABINIT wave-function with the command:&lt;br /&gt;
&lt;br /&gt;
 a2y -F AlAso_DS2_WFK.nc                            &lt;br /&gt;
&lt;br /&gt;
and the QuantumEspresso one, in the folder AlAs.save with the command:&lt;br /&gt;
&lt;br /&gt;
 p2y                              &lt;br /&gt;
Now we consider an external field in the &amp;lt;code&amp;gt;[1,1,0]&amp;lt;/code&amp;gt; direction and remove symmetries not compatible with this field, as explained in the tutorial [http://www.yambo-code.eu/wiki/index.php?title=Prerequisites_for_Real_Time_propagation_with_Yambo Prerequisites for Real-Time propagation with Yambo].&lt;br /&gt;
&lt;br /&gt;
==Real-time simulation for the SHG==&lt;br /&gt;
&lt;br /&gt;
You can generate the input file with the command &amp;lt;code&amp;gt;yambo_nl -u n&amp;lt;/code&amp;gt;:&lt;br /&gt;
                       &lt;br /&gt;
 nloptics                      # [R NL] Non-linear optics&lt;br /&gt;
 % NLBands&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 3 | 6&amp;lt;/span&amp;gt; |                   # [NL] Bands&lt;br /&gt;
 %&lt;br /&gt;
 NLstep=   0.0100       fs    # [NL] Real Time step length&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;NLverbosity= &amp;quot;high&amp;quot;&amp;lt;/span&amp;gt;               # [NL] Verbosity level (low | high)&lt;br /&gt;
 NLtime=-1.000000           fs    # [NL] Simulation Time&lt;br /&gt;
 NLintegrator= &amp;quot;INVINT&amp;quot;       # [NL] Integrator (&amp;quot;EULEREXP/RK4/RK2EXP/HEUN/INVINT/CRANKNIC&amp;quot;)&lt;br /&gt;
 NLCorrelation= &amp;quot;IPA&amp;quot;         # [NL] Correlation (&amp;quot;IPA/HARTREE/TDDFT/LRC/JGM/SEX/HF&amp;quot;)&lt;br /&gt;
 NLLrcAlpha= 0.000000         # [NL] Long Range Correction&lt;br /&gt;
 % NLEnRange&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;  1.000000 | 5.000000 &amp;lt;/span&amp;gt;| eV    # [NL] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 NLEnSteps= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 5  &amp;lt;/span&amp;gt;              # [NL] Energy steps&lt;br /&gt;
 NLDamping= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 0.150000  &amp;lt;/span&amp;gt;  eV    # [NL] Damping&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 1.000000 | 1.000000 | 0.000000 &amp;lt;/span&amp;gt;|        # [RT Field1] Versor&lt;br /&gt;
 Field1_kind= &amp;quot;SOFTSIN&amp;quot;         # [NL ExtF] Kind(SIN|SOFTSIN|RES|ANTIRES|GAUSS|DELTA|QSSIN)&lt;br /&gt;
&lt;br /&gt;
The line &amp;lt;code&amp;gt;|1.000000 | 1.000000 | 0.000000 | # [RT Field1] Versor&amp;lt;/code&amp;gt; referees to the direction of the external field (x,y,0). At present only an external field is present but the code can be easily generalized to deal with more fields.&lt;br /&gt;
The default parameters of Yambo/Lumen are already tuned for second-harmonic generation, so the only thing you have to change is the band range, between 3 and 6 and the energy range between 1.0-5.0 eV and the number of energy steps in this interval that we set to 10. Notice that you cannot set to zero the lowest value of the energy range because this will requires a simulation that lasts infinite time, see below. Finally, consider that Yambo performs a separate calculation for each frequency, so if you set many energy steps the computational time grows linearly with this number.&lt;br /&gt;
Notice that we set &amp;lt;code&amp;gt;NLverbosity= &amp;quot;high&amp;quot;&amp;lt;/code&amp;gt; in this way the code will produce a file for each laser frequency containing the time dependent polarization.&lt;br /&gt;
Run &amp;lt;code&amp;gt;yambo_nl&amp;lt;/code&amp;gt;. Calculations will take about fifteen minutes on a single processor PC, you have time to study the next section that explains how non-linear response is extracted from the real-time simulations.&lt;br /&gt;
In order to speed up calculations, you can run them in parallel.&lt;br /&gt;
&lt;br /&gt;
==Non-linear response with Yambo==&lt;br /&gt;
&lt;br /&gt;
In order to calculate the non-linear response, the system is excited with different laser fields with a sinusoidal shape at frequencies &amp;lt;math&amp;gt;\omega_1, \omega_2, .... , \omega_n &amp;lt;/math&amp;gt; determined by the parameters [[Variables#NLEnRangev|NLEnRange]] and [[Variables#NLEnSteps|NLEnSteps]]. A dephasing term is added to the Hamiltonian &amp;lt;math&amp;gt;\gamma = &amp;lt;/math&amp;gt;[[Variables#NLDamping|NLDamping]] to simulate a finite broadening and to remove the eigenmodes that are excited by the sudden turning on of the external field. After the dephasing time the outgoing signal is analyzed to extract the non-linear coefficients as shown in the figure below: &lt;br /&gt;
&lt;br /&gt;
[[File:Pt analysis.png|600px|center|Non-linear response analysis]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the report file &amp;lt;code&amp;gt;r_nlinear&amp;lt;/code&amp;gt; you will find the length of the dephasing part and of the sampling one:&lt;br /&gt;
&lt;br /&gt;
  Dephasing Time          [fs]: 52.65695&lt;br /&gt;
  Sampling  Time          [fs]:  4.18566&lt;br /&gt;
  Total simulation time   [fs]: 56.84262                     &lt;br /&gt;
The length of the dephasing interval is inversely proportional to the damping term &amp;lt;math&amp;gt;T_{depth} \simeq 1/\gamma&amp;lt;/math&amp;gt; while the length of the sampling is dictated by the smallest frequency we are interested in: &amp;lt;math&amp;gt;T_{samp} \simeq 1/\omega_1 &amp;lt;/math&amp;gt;. For this reason if &amp;lt;math&amp;gt; \omega_1=0 &amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt; \gamma = 0 &amp;lt;/math&amp;gt; simulation time goes to infinity. The response at zero frequency can be calculated as limit of small frequency perturbation.&lt;br /&gt;
You can have a look to the file &amp;lt;code&amp;gt;src/nloptics/NL_initialize.F&amp;lt;/code&amp;gt; to see how simulation lengths are defined.&lt;br /&gt;
Calculations can take some time, run them in parallel, the best number of processors = number of frequencies or reduce the number of frequencies step in the SHG.&lt;br /&gt;
&lt;br /&gt;
==Analysis of the results==&lt;br /&gt;
&lt;br /&gt;
In the sampling region we suppose that the polarization can be written as: &amp;lt;math&amp;gt;\bf{P}(t) = \sum_{n=-\infty}^{+\infty} \bf{p}_n e^{-i\omega_n t} &amp;lt;/math&amp;gt; where the coefficient &amp;lt;math&amp;gt;\bf{p}_1,...,\bf{p}_n &amp;lt;/math&amp;gt; are related to &amp;lt;math&amp;gt;\chi^{(1)},...,\chi^{(n)} &amp;lt;/math&amp;gt;. We sample the polarization signal at different times and invert the previous equation by truncating the sum at a finite order &amp;lt;ref&amp;gt;[https://arxiv.org/abs/1309.4012 Nonlinear optics from an ab initio approach by means of the dynamical Berry phase: Application to second- and third-harmonic generation in semiconductors], C. Attaccalite and M. Grüning, Phys. Rev. B 88, 235113(2013)&amp;lt;/ref&amp;gt;.&lt;br /&gt;
This is done with the command &amp;lt;code&amp;gt;ypp_nl -u&amp;lt;/code&amp;gt; that automatically produce an input with the correct values:&lt;br /&gt;
&lt;br /&gt;
 nonlinear                    # [R] NonLinear Optics Post-Processing&lt;br /&gt;
 Xorder=   &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;4  &amp;lt;/span&amp;gt;                 # Max order of the response functions&lt;br /&gt;
 % TimeRange&lt;br /&gt;
  52.65695 | -1.00000 | fs    # Time-window where processing is done&lt;br /&gt;
 % &lt;br /&gt;
 ETStpsRt= 200                # Total Energy steps&lt;br /&gt;
 % EnRngeRt&lt;br /&gt;
   0.00000 | 10.00000 | eV    # Energy range&lt;br /&gt;
 %&lt;br /&gt;
 DampMode= &amp;quot;NONE&amp;quot;             # Damping type ( NONE | LORENTZIAN | GAUSSIAN )&lt;br /&gt;
 DampFactor=  0.10000   eV    # Damping parameter&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;code&amp;gt;Xorder&amp;lt;/code&amp;gt; is the order where the previous sum is truncated, and the TimeRange specifies the sampling region. Notice that differently from the first tutorial, in this case, we do not need Damping in &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; because we already included it in the real-time dynamics. Run &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; and it will produce a file called &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;. This file contains the different components of &amp;lt;math&amp;gt;\chi^2_{xy*} &amp;lt;/math&amp;gt; and in particular the columns 6 and 7 correspond to the imaginary and real part of &amp;lt;math&amp;gt;\chi^2_{xyz} &amp;lt;/math&amp;gt;. You can plot the result with gnuplot and the command:&lt;br /&gt;
&lt;br /&gt;
 p &#039;o.YPP-X_probe_order_2&#039; u 1:(sqrt($6**2+$7**2)) w lp ps 1.5 pt 7 lw 1.5&lt;br /&gt;
&lt;br /&gt;
the result should look like&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AlAs results.png|700px|center|SHG in AlAs]]&lt;br /&gt;
&lt;br /&gt;
and compare it with the &amp;lt;math&amp;gt; \chi^2_{zxy} &amp;lt;/math&amp;gt; calculated with more frequencies and with the converged result on a &amp;lt;math&amp;gt; 18x18x18&amp;lt;/math&amp;gt; k-point grid and bands between 2 and 10. In the figure you can find also the comparison with the results of Ref. &amp;lt;ref&amp;gt;Luppi et al. [https://arxiv.org/abs/1006.2649 PRB B, &#039;&#039;&#039;82&#039;&#039;&#039;, 235201(2010)]&amp;lt;/ref&amp;gt;. &lt;br /&gt;
Notice that the QuantumEspresso results are slightly different from the Abinit ones. This is due to the different pseudo-potential employed in the calculations if pseudopotentials were the same calculation would have been identical. You can download the script to generate this plot and the converged results [http://www.attaccalite.com/lumen/tutorials/AlAs/AlAs_results.tgz here].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notice that&#039;&#039;&#039; : the following parameters are not used in the non-linear response analysis: &amp;lt;code&amp;gt; EnRngeRt&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ETStpsRt&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;DampMode&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;DampFactor&amp;lt;/code&amp;gt;. The damping factor is set directly in the real-time simulation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;System of units in Non-linear Optics&amp;lt;/span&amp;gt;&#039;&#039;&#039;: notice that in Yambo the non-linear response functions are in the gaussian system of units, for example the &amp;lt;math&amp;gt; \chi^2 (\omega) &amp;lt;/math&amp;gt;  is in cm/statvolt. In order to convert the non-linear coefficients between different system of units, you can have a look at the [https://www.attaccalite.com/tutorials_yambo/Appendix_C_Boyd.pdf Appendix C] of the book [https://www.elsevier.com/books/nonlinear-optics/boyd/978-0-12-369470-6 &amp;quot;Non-linear optics&amp;quot;  by Robert W. Boyd].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;More tutorials&amp;lt;/span&amp;gt; on non-linear response (Third harmonic generation, parallelization, spin-orbit etc..) with Yambo can be found here: [http://www.attaccalite.com/lumen/tutorials.html More Tutorials]. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Analysis of the results using YamboPy==&lt;br /&gt;
The analysis of the result performed in the previous section using &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; can be performed using python script [https://github.com/yambo-code/yambopy YamboPy].&amp;lt;br&amp;gt;&lt;br /&gt;
In YamboPy we implemented all necessary functions to reads the Yambo databases and post-process the results. Here we show how to get the SHG signal from the previous &lt;br /&gt;
simulations. We suppose you correctly installed &amp;lt;code&amp;gt;YamboPy&amp;lt;/code&amp;gt; on your PC. Go in the folder where you ran non-linear calculation and type in the python:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
 from yambopy import *&lt;br /&gt;
 NLDB=YamboNLDB()&lt;br /&gt;
 pol =NLDB.Polarization[0]&lt;br /&gt;
 time=NLDB.IO_TIME_points&lt;br /&gt;
&lt;br /&gt;
in this way you read all the Non-linear databases. If your runs are in a different folder then the &#039;SAVE&#039; one you can specify it using the command:&lt;br /&gt;
 NLDB=YamboNLDB(calc=&#039;MYJOB&#039;)&lt;br /&gt;
&lt;br /&gt;
now in the array &amp;lt;code&amp;gt;pol&amp;lt;/code&amp;gt; you have all the polarization for all laser frequencies in the three Cartesian directions, while the variable &amp;lt;code&amp;gt;time&amp;lt;/code&amp;gt; contains all the time series of your simulation.&lt;br /&gt;
Now you can get the non-linear response with the command:&lt;br /&gt;
&lt;br /&gt;
 Harmonic_Analysis(NLDB,X_order=4)&lt;br /&gt;
&lt;br /&gt;
this command will perform a Fourier analysis of the results in the same way of &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; and generate new files with all the requested harmonics &#039;&#039;o.YamboPy-X_probe_order_1&#039;&#039;, &#039;&#039;o.YamboPy-X_probe_order_2&#039;&#039; etc...&lt;br /&gt;
equivalent to the one generated by &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt;. Results can be plot with gnuplot using the command:&lt;br /&gt;
 &lt;br /&gt;
 p &#039;o.YamboPy-X_probe_order_2&#039; u 1:(sqrt($6**2+$7**2)) w lp ps 1.5 pt 7 lw 1.5&lt;br /&gt;
&lt;br /&gt;
The script that performs non-linear analysis can be found in &amp;lt;code&amp;gt;yambopy/nl/harmonic_analysis.py&amp;lt;/code&amp;gt;. &amp;lt;br&amp;gt; We strongly advice you to have a look to this script and modify it according&lt;br /&gt;
to your needs and in order to extract other non-linear response functions.&lt;br /&gt;
&lt;br /&gt;
==How to choose the external field direction for the different X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
In the X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;abc&amp;lt;/sub&amp;gt; response you have three field directions. The two components &#039;&#039;b&#039;&#039; and &#039;&#039;c&#039;&#039; are determined by the external field and the third &#039;&#039;a&#039;&#039;&lt;br /&gt;
is the direction where you measure the response.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The external field in Yambo is set using the variable&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
   1.000000 | 0.000000 | 0.000000 |        # [NL ExtF] Versor .&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
For example if you set in Yambo field direction as:&lt;br /&gt;
&lt;br /&gt;
 1.0 | 0.0 | 0.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*xx&amp;lt;/sub&amp;gt;&lt;br /&gt;
 0.0 | 1.0 | 0.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*yy&amp;lt;/sub&amp;gt;&lt;br /&gt;
 0.0 | 0.0 | 1.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*zz&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the * correspond to the different direction in the response file &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;.&lt;br /&gt;
In the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt; you have seven columns:&lt;br /&gt;
&lt;br /&gt;
 The first column is the energy [[omega]],&lt;br /&gt;
 the 2nd and 3rd columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;x**&amp;lt;/sub&amp;gt;&lt;br /&gt;
 the 4th and 5th columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;y**&amp;lt;/sub&amp;gt;&lt;br /&gt;
 the 6th and 7th columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;z**&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where the ** are the direction of the incoming field, see above.&lt;br /&gt;
&lt;br /&gt;
For example if you want to calculate the &amp;lt;math&amp;gt;\chi^{(2)}_{zxx}&amp;lt;/math&amp;gt; you put the external field in the direction &amp;lt;code&amp;gt; 1.0 | 0.0 | 0.0 |&amp;lt;/code&amp;gt;&lt;br /&gt;
and then plot the column 6 and 7 of the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt; file.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to get the other components of the  X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; the calculation are more involved. For example if you put field in the&lt;br /&gt;
&lt;br /&gt;
 1.0 | 1.0 | 0.0 | &lt;br /&gt;
&lt;br /&gt;
this corresponds to &amp;lt;math&amp;gt;E(t)=\frac{1}{\sqrt{2}} [ E_x(t) + E_y(t) ]&amp;lt;/math&amp;gt; and so at the second order you will have &amp;lt;math&amp;gt;E^2(t)=\frac{1}{2} \left [ E^2_x(t) + E^2_y(t) +  E_x(t) E_y(t) +  E_y(t) E_x(t) \right]&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
this means that  the X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; in the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;  will correspond to a linear combination of the following different response functions.&amp;lt;br&amp;gt;&lt;br /&gt;
For example in the the 2nd and 3rd columns are the imaginary and real part of:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{x**}=\frac{1}{2} \left [\chi^2_{xxx}+\chi^{(2)}_{xyy} + \chi^{(2)}_{xxy} + \chi^{(2)}_{xyx} \right ]&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the same for the other column replacing the first &amp;lt;code&amp;gt;x&amp;lt;/code&amp;gt; for &amp;lt;code&amp;gt;y,z&amp;lt;/code&amp;gt;.&lt;br /&gt;
If you know that some components are zero this allow you to extract the corresponding off-diagonal part of &amp;lt;math&amp;gt;\chi^{(2)}_{abc}&amp;lt;/math&amp;gt; otherwise you have to perform different calculations to get the component you are interested in. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Now we present &#039;&#039;&#039;a simple example of monolayer hBN (m-hBN)&#039;&#039;&#039;. &amp;lt;br&amp;gt; In m-hBN there is only a non-zero component of the $\chi^2$ and all the others are related by symmetry:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{yyy}=-\chi^{(2)}_{yxx}=-\chi^{(2)}_{xxy}=-\chi^{(2)}_{xyx}&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
so if you put the field in the &amp;lt;code&amp;gt;|1|1|0|&amp;lt;/code&amp;gt; direction you will get:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{x**} = \frac{1}{2} \left[\chi^{(2)}_{xxy} + \chi^{(2)}_{xyx} \right] = - \chi^{(2)}_{yyy} &amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{y**} =\frac{1}{2} \left[ \chi^{(2)}_{yyy} + \chi^{(2)}_{yxx}  \right] = 0.0 &amp;lt;/math&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
In the figure below you can see the different &amp;lt;math&amp;gt;\chi^{(2)}&amp;lt;/math&amp;gt; of monolayer hBN. &lt;br /&gt;
&lt;br /&gt;
[[File:Xhi2 xy.png|center| 800px|xhi2_xy]]&lt;br /&gt;
&lt;br /&gt;
as you can see in the second panel, when the field is in the &amp;lt;code&amp;gt;xy&amp;lt;/code&amp;gt; you get a linear combination of  &amp;lt;code&amp;gt;\chi^{(2)}&amp;lt;/code&amp;gt; corresponding to the equation above, in this case the &amp;lt;code&amp;gt;y&amp;lt;/code&amp;gt; is zero while the &amp;lt;code&amp;gt;x&amp;lt;/code&amp;gt; component is equal to &amp;lt;math&amp;gt;-\chi^{(2)}_{yyy}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Nota bene:&#039;&#039;&#039; if you change the direction of the external field you must to remove the corresponding symmetries as explained in the tutorial [[Prerequisites for Real Time_propagation with Yambo#Reduce symmetries real-time linear response tutorial]]. If you have to calculate &amp;lt;math&amp;gt;\chi^{(2)}&amp;lt;/math&amp;gt; along many directions it can be convenient to remove all symmetries at once.&lt;br /&gt;
&lt;br /&gt;
==Non-linear response of low-dimensional structures: 2D or 1D ==&lt;br /&gt;
&lt;br /&gt;
The Yambo code is a 3D periodic code, so when you want to study a low-dimensional system 2D or 1D, you have to use a supercell approach.&lt;br /&gt;
For example to simulate the non-linear response in a 2D-crystal one, can put the crystal in the xy plane and choose a larger distance in the z-direction&lt;br /&gt;
in order to reduce the interaction between the periodic replica. Clearly in this case k-point sampling will be only in the x,y directions.&lt;br /&gt;
For calculations on this type of systems, these two warnings must be taken into account:&lt;br /&gt;
&lt;br /&gt;
* if you calculate GW corrections or include electron-hole interaction in the linear/non-linear response it is a good idea to use a &#039;&#039;&#039;Coulomb cutoff&#039;&#039;&#039;, similar to the 2D BSE case  [http://www.yambo-code.org/wiki/index.php?title=How_to_treat_low_dimensional_systems How to treat low dimensional systems]. You can add the cutoff just adding the &amp;quot;-r&amp;quot; in the input generation.&lt;br /&gt;
&lt;br /&gt;
* the calculation of SHG and THG are always performed respect to the supercell, therefore you have to &#039;&#039;&#039;re-scale&#039;&#039;&#039; the result to the effective thickness of the layer, usually the inter-layer distance of the corresponding bulk material for 2D systems: &amp;lt;math&amp;gt;\chi_{rescaled}(\omega) = L_z/d_{eff} \cdot \chi(\omega) &amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;L_z&amp;lt;/math&amp;gt; is the z-dimension of the supercell, and &amp;lt;math&amp;gt;d_{eff}&amp;lt;/math&amp;gt; is the effective thickness of the 2D system.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Nota bene&#039;&#039;&#039;: Non-linear response along &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;non-periodic directions&amp;lt;/span&amp;gt; is not implemented in Yambo, the code will print zero in these directions for all response functions. We plan to implement it in a future version of the code.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Links for schools==&lt;br /&gt;
* Back to [[Rome 2023#Tutorials]]&lt;br /&gt;
* Back to [[ICTP2020]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
{| style=&amp;quot;width:100%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|style=&amp;quot;width:25%; text-align:left&amp;quot;|Prev: [[Linear response from real time simulations|Linear response from real time simulations]]&lt;br /&gt;
|style=&amp;quot;width:45%; text-align:center&amp;quot;|Now: [[ICTP2020|ICTP  Tutorials]] --&amp;gt; [[Real time approach to non-linear response|Non Linear Response]] &lt;br /&gt;
|style=&amp;quot;width:50%; text-align:left&amp;quot;|Next: [[Correlation effects in the non-linear response|Correlation effects in the non-linear response ]]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Attacc</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Real_time_approach_to_non-linear_response_(SHG)&amp;diff=9163</id>
		<title>Real time approach to non-linear response (SHG)</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Real_time_approach_to_non-linear_response_(SHG)&amp;diff=9163"/>
		<updated>2025-09-28T07:55:40Z</updated>

		<summary type="html">&lt;p&gt;Attacc: /* How to choose the external field direction for the different X2 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Second Harmonic Generation in AlAs ==&lt;br /&gt;
In this tutorial, we will calculate the second harmonic generation of bulk AlAs, the Yambo databases can be downloaded here: [https://media.yambo-code.eu/educational/tutorials/files/AlAs_DBs.tar.gz AlAs_DBs.tar.gz] (10 MB). The first steps of this tutorials are the same as the one on [http://www.yambo-code.eu/wiki/index.php?title=Prerequisites_for_Real_Time_propagation_with_Yambo Prerequisites for Real-Time propagation with Yambo] with the only difference that we will work on AlAs and we will consider an external field in the direction &amp;lt;code&amp;gt; 1.000000 | 1.000000 | 0.000000 |&amp;lt;/code&amp;gt;. The DFT input are available here: [https://media.yambo-code.eu/educational/tutorials/files/AlAs_abinit.tar.gz ABINIT] or [https://media.yambo-code.eu/educational/tutorials/files/AlAs_pwscf.tar.gz QuantumEspresso].&lt;br /&gt;
You can run the DFT calculation with ABINIT with the command:&lt;br /&gt;
&lt;br /&gt;
 abinit &amp;lt; AlAs.in &amp;gt; output_AlAs                                             &lt;br /&gt;
&lt;br /&gt;
or using QuantumEspresso:&lt;br /&gt;
&lt;br /&gt;
 pw.x -inp AlAs.scf.in &amp;gt; output_scf&lt;br /&gt;
 pw.x -inp AlAs.nscf.in &amp;gt; output_scf                            &lt;br /&gt;
&lt;br /&gt;
and then import the ABINIT wave-function with the command:&lt;br /&gt;
&lt;br /&gt;
 a2y -F AlAso_DS2_WFK.nc                            &lt;br /&gt;
&lt;br /&gt;
and the QuantumEspresso one, in the folder AlAs.save with the command:&lt;br /&gt;
&lt;br /&gt;
 p2y                              &lt;br /&gt;
Now we consider an external field in the &amp;lt;code&amp;gt;[1,1,0]&amp;lt;/code&amp;gt; direction and remove symmetries not compatible with this field, as explained in the tutorial [http://www.yambo-code.eu/wiki/index.php?title=Prerequisites_for_Real_Time_propagation_with_Yambo Prerequisites for Real-Time propagation with Yambo].&lt;br /&gt;
&lt;br /&gt;
==Real-time simulation for the SHG==&lt;br /&gt;
&lt;br /&gt;
You can generate the input file with the command &amp;lt;code&amp;gt;yambo_nl -u n&amp;lt;/code&amp;gt;:&lt;br /&gt;
                       &lt;br /&gt;
 nloptics                      # [R NL] Non-linear optics&lt;br /&gt;
 % NLBands&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 3 | 6&amp;lt;/span&amp;gt; |                   # [NL] Bands&lt;br /&gt;
 %&lt;br /&gt;
 NLstep=   0.0100       fs    # [NL] Real Time step length&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;NLverbosity= &amp;quot;high&amp;quot;&amp;lt;/span&amp;gt;               # [NL] Verbosity level (low | high)&lt;br /&gt;
 NLtime=-1.000000           fs    # [NL] Simulation Time&lt;br /&gt;
 NLintegrator= &amp;quot;INVINT&amp;quot;       # [NL] Integrator (&amp;quot;EULEREXP/RK4/RK2EXP/HEUN/INVINT/CRANKNIC&amp;quot;)&lt;br /&gt;
 NLCorrelation= &amp;quot;IPA&amp;quot;         # [NL] Correlation (&amp;quot;IPA/HARTREE/TDDFT/LRC/JGM/SEX/HF&amp;quot;)&lt;br /&gt;
 NLLrcAlpha= 0.000000         # [NL] Long Range Correction&lt;br /&gt;
 % NLEnRange&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;  1.000000 | 5.000000 &amp;lt;/span&amp;gt;| eV    # [NL] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 NLEnSteps= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 5  &amp;lt;/span&amp;gt;              # [NL] Energy steps&lt;br /&gt;
 NLDamping= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 0.150000  &amp;lt;/span&amp;gt;  eV    # [NL] Damping&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 1.000000 | 1.000000 | 0.000000 &amp;lt;/span&amp;gt;|        # [RT Field1] Versor&lt;br /&gt;
 Field1_kind= &amp;quot;SOFTSIN&amp;quot;         # [NL ExtF] Kind(SIN|SOFTSIN|RES|ANTIRES|GAUSS|DELTA|QSSIN)&lt;br /&gt;
&lt;br /&gt;
The line &amp;lt;code&amp;gt;|1.000000 | 1.000000 | 0.000000 | # [RT Field1] Versor&amp;lt;/code&amp;gt; referees to the direction of the external field (x,y,0). At present only an external field is present but the code can be easily generalized to deal with more fields.&lt;br /&gt;
The default parameters of Yambo/Lumen are already tuned for second-harmonic generation, so the only thing you have to change is the band range, between 3 and 6 and the energy range between 1.0-5.0 eV and the number of energy steps in this interval that we set to 10. Notice that you cannot set to zero the lowest value of the energy range because this will requires a simulation that lasts infinite time, see below. Finally, consider that Yambo performs a separate calculation for each frequency, so if you set many energy steps the computational time grows linearly with this number.&lt;br /&gt;
Notice that we set &amp;lt;code&amp;gt;NLverbosity= &amp;quot;high&amp;quot;&amp;lt;/code&amp;gt; in this way the code will produce a file for each laser frequency containing the time dependent polarization.&lt;br /&gt;
Run &amp;lt;code&amp;gt;yambo_nl&amp;lt;/code&amp;gt;. Calculations will take about fifteen minutes on a single processor PC, you have time to study the next section that explains how non-linear response is extracted from the real-time simulations.&lt;br /&gt;
In order to speed up calculations, you can run them in parallel.&lt;br /&gt;
&lt;br /&gt;
==Non-linear response with Yambo==&lt;br /&gt;
&lt;br /&gt;
In order to calculate the non-linear response, the system is excited with different laser fields with a sinusoidal shape at frequencies &amp;lt;math&amp;gt;\omega_1, \omega_2, .... , \omega_n &amp;lt;/math&amp;gt; determined by the parameters [[Variables#NLEnRangev|NLEnRange]] and [[Variables#NLEnSteps|NLEnSteps]]. A dephasing term is added to the Hamiltonian &amp;lt;math&amp;gt;\gamma = &amp;lt;/math&amp;gt;[[Variables#NLDamping|NLDamping]] to simulate a finite broadening and to remove the eigenmodes that are excited by the sudden turning on of the external field. After the dephasing time the outgoing signal is analyzed to extract the non-linear coefficients as shown in the figure below: &lt;br /&gt;
&lt;br /&gt;
[[File:Pt analysis.png|600px|center|Non-linear response analysis]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the report file &amp;lt;code&amp;gt;r_nlinear&amp;lt;/code&amp;gt; you will find the length of the dephasing part and of the sampling one:&lt;br /&gt;
&lt;br /&gt;
  Dephasing Time          [fs]: 52.65695&lt;br /&gt;
  Sampling  Time          [fs]:  4.18566&lt;br /&gt;
  Total simulation time   [fs]: 56.84262                     &lt;br /&gt;
The length of the dephasing interval is inversely proportional to the damping term &amp;lt;math&amp;gt;T_{depth} \simeq 1/\gamma&amp;lt;/math&amp;gt; while the length of the sampling is dictated by the smallest frequency we are interested in: &amp;lt;math&amp;gt;T_{samp} \simeq 1/\omega_1 &amp;lt;/math&amp;gt;. For this reason if &amp;lt;math&amp;gt; \omega_1=0 &amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt; \gamma = 0 &amp;lt;/math&amp;gt; simulation time goes to infinity. The response at zero frequency can be calculated as limit of small frequency perturbation.&lt;br /&gt;
You can have a look to the file &amp;lt;code&amp;gt;src/nloptics/NL_initialize.F&amp;lt;/code&amp;gt; to see how simulation lengths are defined.&lt;br /&gt;
Calculations can take some time, run them in parallel, the best number of processors = number of frequencies or reduce the number of frequencies step in the SHG.&lt;br /&gt;
&lt;br /&gt;
==Analysis of the results==&lt;br /&gt;
&lt;br /&gt;
In the sampling region we suppose that the polarization can be written as: &amp;lt;math&amp;gt;\bf{P}(t) = \sum_{n=-\infty}^{+\infty} \bf{p}_n e^{-i\omega_n t} &amp;lt;/math&amp;gt; where the coefficient &amp;lt;math&amp;gt;\bf{p}_1,...,\bf{p}_n &amp;lt;/math&amp;gt; are related to &amp;lt;math&amp;gt;\chi^{(1)},...,\chi^{(n)} &amp;lt;/math&amp;gt;. We sample the polarization signal at different times and invert the previous equation by truncating the sum at a finite order &amp;lt;ref&amp;gt;[https://arxiv.org/abs/1309.4012 Nonlinear optics from an ab initio approach by means of the dynamical Berry phase: Application to second- and third-harmonic generation in semiconductors], C. Attaccalite and M. Grüning, Phys. Rev. B 88, 235113(2013)&amp;lt;/ref&amp;gt;.&lt;br /&gt;
This is done with the command &amp;lt;code&amp;gt;ypp_nl -u&amp;lt;/code&amp;gt; that automatically produce an input with the correct values:&lt;br /&gt;
&lt;br /&gt;
 nonlinear                    # [R] NonLinear Optics Post-Processing&lt;br /&gt;
 Xorder=   &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;4  &amp;lt;/span&amp;gt;                 # Max order of the response functions&lt;br /&gt;
 % TimeRange&lt;br /&gt;
  52.65695 | -1.00000 | fs    # Time-window where processing is done&lt;br /&gt;
 % &lt;br /&gt;
 ETStpsRt= 200                # Total Energy steps&lt;br /&gt;
 % EnRngeRt&lt;br /&gt;
   0.00000 | 10.00000 | eV    # Energy range&lt;br /&gt;
 %&lt;br /&gt;
 DampMode= &amp;quot;NONE&amp;quot;             # Damping type ( NONE | LORENTZIAN | GAUSSIAN )&lt;br /&gt;
 DampFactor=  0.10000   eV    # Damping parameter&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;code&amp;gt;Xorder&amp;lt;/code&amp;gt; is the order where the previous sum is truncated, and the TimeRange specifies the sampling region. Notice that differently from the first tutorial, in this case, we do not need Damping in &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; because we already included it in the real-time dynamics. Run &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; and it will produce a file called &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;. This file contains the different components of &amp;lt;math&amp;gt;\chi^2_{xy*} &amp;lt;/math&amp;gt; and in particular the columns 6 and 7 correspond to the imaginary and real part of &amp;lt;math&amp;gt;\chi^2_{xyz} &amp;lt;/math&amp;gt;. You can plot the result with gnuplot and the command:&lt;br /&gt;
&lt;br /&gt;
 p &#039;o.YPP-X_probe_order_2&#039; u 1:(sqrt($6**2+$7**2)) w lp ps 1.5 pt 7 lw 1.5&lt;br /&gt;
&lt;br /&gt;
the result should look like&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AlAs results.png|700px|center|SHG in AlAs]]&lt;br /&gt;
&lt;br /&gt;
and compare it with the &amp;lt;math&amp;gt; \chi^2_{zxy} &amp;lt;/math&amp;gt; calculated with more frequencies and with the converged result on a &amp;lt;math&amp;gt; 18x18x18&amp;lt;/math&amp;gt; k-point grid and bands between 2 and 10. In the figure you can find also the comparison with the results of Ref. &amp;lt;ref&amp;gt;Luppi et al. [https://arxiv.org/abs/1006.2649 PRB B, &#039;&#039;&#039;82&#039;&#039;&#039;, 235201(2010)]&amp;lt;/ref&amp;gt;. &lt;br /&gt;
Notice that the QuantumEspresso results are slightly different from the Abinit ones. This is due to the different pseudo-potential employed in the calculations if pseudopotentials were the same calculation would have been identical. You can download the script to generate this plot and the converged results [http://www.attaccalite.com/lumen/tutorials/AlAs/AlAs_results.tgz here].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notice that&#039;&#039;&#039; : the following parameters are not used in the non-linear response analysis: &amp;lt;code&amp;gt; EnRngeRt&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ETStpsRt&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;DampMode&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;DampFactor&amp;lt;/code&amp;gt;. The damping factor is set directly in the real-time simulation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;System of units in Non-linear Optics&amp;lt;/span&amp;gt;&#039;&#039;&#039;: notice that in Yambo the non-linear response functions are in the gaussian system of units, for example the &amp;lt;math&amp;gt; \chi^2 (\omega) &amp;lt;/math&amp;gt;  is in cm/statvolt. In order to convert the non-linear coefficients between different system of units, you can have a look at the [https://www.attaccalite.com/tutorials_yambo/Appendix_C_Boyd.pdf Appendix C] of the book [https://www.elsevier.com/books/nonlinear-optics/boyd/978-0-12-369470-6 &amp;quot;Non-linear optics&amp;quot;  by Robert W. Boyd].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;More tutorials&amp;lt;/span&amp;gt; on non-linear response (Third harmonic generation, parallelization, spin-orbit etc..) with Yambo can be found here: [http://www.attaccalite.com/lumen/tutorials.html More Tutorials]. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Analysis of the results using YamboPy==&lt;br /&gt;
The analysis of the result performed in the previous section using &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; can be performed using python script [https://github.com/yambo-code/yambopy YamboPy].&amp;lt;br&amp;gt;&lt;br /&gt;
In YamboPy we implemented all necessary functions to reads the Yambo databases and post-process the results. Here we show how to get the SHG signal from the previous &lt;br /&gt;
simulations. We suppose you correctly installed &amp;lt;code&amp;gt;YamboPy&amp;lt;/code&amp;gt; on your PC. Go in the folder where you ran non-linear calculation and type in the python:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
 from yambopy import *&lt;br /&gt;
 NLDB=YamboNLDB()&lt;br /&gt;
 pol =NLDB.Polarization[0]&lt;br /&gt;
 time=NLDB.IO_TIME_points&lt;br /&gt;
&lt;br /&gt;
in this way you read all the Non-linear databases. If your runs are in a different folder then the &#039;SAVE&#039; one you can specify it using the command:&lt;br /&gt;
 NLDB=YamboNLDB(calc=&#039;MYJOB&#039;)&lt;br /&gt;
&lt;br /&gt;
now in the array &amp;lt;code&amp;gt;pol&amp;lt;/code&amp;gt; you have all the polarization for all laser frequencies in the three Cartesian directions, while the variable &amp;lt;code&amp;gt;time&amp;lt;/code&amp;gt; contains all the time series of your simulation.&lt;br /&gt;
Now you can get the non-linear response with the command:&lt;br /&gt;
&lt;br /&gt;
 Harmonic_Analysis(NLDB,X_order=4)&lt;br /&gt;
&lt;br /&gt;
this command will perform a Fourier analysis of the results in the same way of &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; and generate new files with all the requested harmonics &#039;&#039;o.YamboPy-X_probe_order_1&#039;&#039;, &#039;&#039;o.YamboPy-X_probe_order_2&#039;&#039; etc...&lt;br /&gt;
equivalent to the one generated by &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt;. Results can be plot with gnuplot using the command:&lt;br /&gt;
 &lt;br /&gt;
 p &#039;o.YamboPy-X_probe_order_2&#039; u 1:(sqrt($6**2+$7**2)) w lp ps 1.5 pt 7 lw 1.5&lt;br /&gt;
&lt;br /&gt;
The script that performs non-linear analysis can be found in &amp;lt;code&amp;gt;yambopy/nl/harmonic_analysis.py&amp;lt;/code&amp;gt;. &amp;lt;br&amp;gt; We strongly advice you to have a look to this script and modify it according&lt;br /&gt;
to your needs and in order to extract other non-linear response functions.&lt;br /&gt;
&lt;br /&gt;
==How to choose the external field direction for the different X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
In the X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;abc&amp;lt;/sub&amp;gt; response you have three field directions. The two components &#039;&#039;b&#039;&#039; and &#039;&#039;c&#039;&#039; are determined by the external field and the third &#039;&#039;a&#039;&#039;&lt;br /&gt;
is the direction where you measure the response.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The external field in Yambo is set using the variable&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
   1.000000 | 0.000000 | 0.000000 |        # [NL ExtF] Versor .&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
For example if you set in Yambo field direction as:&lt;br /&gt;
&lt;br /&gt;
 1.0 | 0.0 | 0.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*xx&amp;lt;/sub&amp;gt;&lt;br /&gt;
 0.0 | 1.0 | 0.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*yy&amp;lt;/sub&amp;gt;&lt;br /&gt;
 0.0 | 0.0 | 1.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*zz&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the * correspond to the different direction in the response file &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;.&lt;br /&gt;
In the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt; you have seven columns:&lt;br /&gt;
&lt;br /&gt;
 The first column is the energy [[omega]],&lt;br /&gt;
 the 2nd and 3rd columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;x**&amp;lt;/sub&amp;gt;&lt;br /&gt;
 the 4th and 5th columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;y**&amp;lt;/sub&amp;gt;&lt;br /&gt;
 the 6th and 7th columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;z**&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where the ** are the direction of the incoming field, see above.&lt;br /&gt;
&lt;br /&gt;
For example if you want to calculate the &amp;lt;math&amp;gt;\chi^{(2)}_{zxx}&amp;lt;/math&amp;gt; you put the external field in the direction &amp;lt;code&amp;gt; 1.0 | 0.0 | 0.0 |&amp;lt;/code&amp;gt;&lt;br /&gt;
and then plot the column 6 and 7 of the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt; file.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to get the other components of the  X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; the calculation are more involved. For example if you put field in the&lt;br /&gt;
&lt;br /&gt;
 1.0 | 1.0 | 0.0 | &lt;br /&gt;
&lt;br /&gt;
this corresponds to &amp;lt;math&amp;gt;E(t)=\frac{1}{\sqrt{2}} [ E_x(t) + E_y(t) ]&amp;lt;/math&amp;gt; and so at the second order you will have &amp;lt;math&amp;gt;E^2(t)=\frac{1}{2} \left [ E^2_x(t) + E^2_y(t) +  E_x(t) E_y(t) +  E_y(t) E_x(t) \right]&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
this means that  the X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; in the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;  will correspond to a linear combination of the following different response functions.&amp;lt;br&amp;gt;&lt;br /&gt;
For example in the the 2nd and 3rd columns are the imaginary and real part of:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{x**}=\frac{1}{2} \left [\chi^2_{xxx}+\chi^{(2)}_{xyy} + \chi^{(2)}_{xxy} + \chi^{(2)}_{xyx} \right ]&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the same for the other column replacing the first &amp;lt;code&amp;gt;x&amp;lt;/code&amp;gt; for &amp;lt;code&amp;gt;y,z&amp;lt;/code&amp;gt;.&lt;br /&gt;
If you know that some components are zero this allow you to extract the corresponding off-diagonal part of &amp;lt;math&amp;gt;\chi^{(2)}_{abc}&amp;lt;/math&amp;gt; otherwise you have to perform different calculations to get the component you are interested in. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Now we present &#039;&#039;&#039;a simple example of monolayer hBN (m-hBN)&#039;&#039;&#039;. &amp;lt;br&amp;gt; In m-hBN there is only a non-zero component of the $\chi^2$ and all the others are related by symmetry:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{yyy}=-\chi^{(2)}_{yxx}=-\chi^{(2)}_{xxy}=-\chi^{(2)}_{xyx}&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
so if you put the field in the &amp;lt;code&amp;gt;|1|1|0|&amp;lt;/code&amp;gt; direction you will get:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{x**} = \frac{1}{2} \left[\chi^{(2)}_{xxy} + \chi^{(2)}_{xyx} \right] = - \chi^{(2)}_{yyy} &amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{y**} =\frac{1}{2} \left[ \chi^{(2)}_{yyy} + \chi^{(2)}_{yxx}  \right] = 0.0 &amp;lt;/math&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
In the figure below you can see the different &amp;lt;math&amp;gt;\chi^{(2)}&amp;lt;/math&amp;gt; of monolayer hBN. &lt;br /&gt;
&lt;br /&gt;
[[File:Xhi2 xy.png|center| 800px|xhi2_xy]]&lt;br /&gt;
&lt;br /&gt;
as you can see in the second panel, when the field is in the &amp;lt;code&amp;gt;xy&amp;lt;/code&amp;gt; you get a linear combination of  &amp;lt;code&amp;gt;\chi^{(2)}&amp;lt;/code&amp;gt; corresponding to the equation above, in this case the &amp;lt;code&amp;gt;y&amp;lt;/code&amp;gt; is zero while the &amp;lt;code&amp;gt;x&amp;lt;/code&amp;gt; component is equal to &amp;lt;math&amp;gt;\chi^{(2)}_{yyy}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Nota bene:&#039;&#039;&#039; if you change the direction of the external field you must to remove the corresponding symmetries as explained in the tutorial [[Prerequisites for Real Time_propagation with Yambo#Reduce symmetries real-time linear response tutorial]]. If you have to calculate &amp;lt;math&amp;gt;\chi^{(2)}&amp;lt;/math&amp;gt; along many directions it can be convenient to remove all symmetries at once.&lt;br /&gt;
&lt;br /&gt;
==Non-linear response of low-dimensional structures: 2D or 1D ==&lt;br /&gt;
&lt;br /&gt;
The Yambo code is a 3D periodic code, so when you want to study a low-dimensional system 2D or 1D, you have to use a supercell approach.&lt;br /&gt;
For example to simulate the non-linear response in a 2D-crystal one, can put the crystal in the xy plane and choose a larger distance in the z-direction&lt;br /&gt;
in order to reduce the interaction between the periodic replica. Clearly in this case k-point sampling will be only in the x,y directions.&lt;br /&gt;
For calculations on this type of systems, these two warnings must be taken into account:&lt;br /&gt;
&lt;br /&gt;
* if you calculate GW corrections or include electron-hole interaction in the linear/non-linear response it is a good idea to use a &#039;&#039;&#039;Coulomb cutoff&#039;&#039;&#039;, similar to the 2D BSE case  [http://www.yambo-code.org/wiki/index.php?title=How_to_treat_low_dimensional_systems How to treat low dimensional systems]. You can add the cutoff just adding the &amp;quot;-r&amp;quot; in the input generation.&lt;br /&gt;
&lt;br /&gt;
* the calculation of SHG and THG are always performed respect to the supercell, therefore you have to &#039;&#039;&#039;re-scale&#039;&#039;&#039; the result to the effective thickness of the layer, usually the inter-layer distance of the corresponding bulk material for 2D systems: &amp;lt;math&amp;gt;\chi_{rescaled}(\omega) = L_z/d_{eff} \cdot \chi(\omega) &amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;L_z&amp;lt;/math&amp;gt; is the z-dimension of the supercell, and &amp;lt;math&amp;gt;d_{eff}&amp;lt;/math&amp;gt; is the effective thickness of the 2D system.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Nota bene&#039;&#039;&#039;: Non-linear response along &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;non-periodic directions&amp;lt;/span&amp;gt; is not implemented in Yambo, the code will print zero in these directions for all response functions. We plan to implement it in a future version of the code.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Links for schools==&lt;br /&gt;
* Back to [[Rome 2023#Tutorials]]&lt;br /&gt;
* Back to [[ICTP2020]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
{| style=&amp;quot;width:100%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|style=&amp;quot;width:25%; text-align:left&amp;quot;|Prev: [[Linear response from real time simulations|Linear response from real time simulations]]&lt;br /&gt;
|style=&amp;quot;width:45%; text-align:center&amp;quot;|Now: [[ICTP2020|ICTP  Tutorials]] --&amp;gt; [[Real time approach to non-linear response|Non Linear Response]] &lt;br /&gt;
|style=&amp;quot;width:50%; text-align:left&amp;quot;|Next: [[Correlation effects in the non-linear response|Correlation effects in the non-linear response ]]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Attacc</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Real_time_approach_to_non-linear_response_(SHG)&amp;diff=9162</id>
		<title>Real time approach to non-linear response (SHG)</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Real_time_approach_to_non-linear_response_(SHG)&amp;diff=9162"/>
		<updated>2025-09-28T07:53:59Z</updated>

		<summary type="html">&lt;p&gt;Attacc: /* How to choose the external field direction for the different X2 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Second Harmonic Generation in AlAs ==&lt;br /&gt;
In this tutorial, we will calculate the second harmonic generation of bulk AlAs, the Yambo databases can be downloaded here: [https://media.yambo-code.eu/educational/tutorials/files/AlAs_DBs.tar.gz AlAs_DBs.tar.gz] (10 MB). The first steps of this tutorials are the same as the one on [http://www.yambo-code.eu/wiki/index.php?title=Prerequisites_for_Real_Time_propagation_with_Yambo Prerequisites for Real-Time propagation with Yambo] with the only difference that we will work on AlAs and we will consider an external field in the direction &amp;lt;code&amp;gt; 1.000000 | 1.000000 | 0.000000 |&amp;lt;/code&amp;gt;. The DFT input are available here: [https://media.yambo-code.eu/educational/tutorials/files/AlAs_abinit.tar.gz ABINIT] or [https://media.yambo-code.eu/educational/tutorials/files/AlAs_pwscf.tar.gz QuantumEspresso].&lt;br /&gt;
You can run the DFT calculation with ABINIT with the command:&lt;br /&gt;
&lt;br /&gt;
 abinit &amp;lt; AlAs.in &amp;gt; output_AlAs                                             &lt;br /&gt;
&lt;br /&gt;
or using QuantumEspresso:&lt;br /&gt;
&lt;br /&gt;
 pw.x -inp AlAs.scf.in &amp;gt; output_scf&lt;br /&gt;
 pw.x -inp AlAs.nscf.in &amp;gt; output_scf                            &lt;br /&gt;
&lt;br /&gt;
and then import the ABINIT wave-function with the command:&lt;br /&gt;
&lt;br /&gt;
 a2y -F AlAso_DS2_WFK.nc                            &lt;br /&gt;
&lt;br /&gt;
and the QuantumEspresso one, in the folder AlAs.save with the command:&lt;br /&gt;
&lt;br /&gt;
 p2y                              &lt;br /&gt;
Now we consider an external field in the &amp;lt;code&amp;gt;[1,1,0]&amp;lt;/code&amp;gt; direction and remove symmetries not compatible with this field, as explained in the tutorial [http://www.yambo-code.eu/wiki/index.php?title=Prerequisites_for_Real_Time_propagation_with_Yambo Prerequisites for Real-Time propagation with Yambo].&lt;br /&gt;
&lt;br /&gt;
==Real-time simulation for the SHG==&lt;br /&gt;
&lt;br /&gt;
You can generate the input file with the command &amp;lt;code&amp;gt;yambo_nl -u n&amp;lt;/code&amp;gt;:&lt;br /&gt;
                       &lt;br /&gt;
 nloptics                      # [R NL] Non-linear optics&lt;br /&gt;
 % NLBands&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 3 | 6&amp;lt;/span&amp;gt; |                   # [NL] Bands&lt;br /&gt;
 %&lt;br /&gt;
 NLstep=   0.0100       fs    # [NL] Real Time step length&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;NLverbosity= &amp;quot;high&amp;quot;&amp;lt;/span&amp;gt;               # [NL] Verbosity level (low | high)&lt;br /&gt;
 NLtime=-1.000000           fs    # [NL] Simulation Time&lt;br /&gt;
 NLintegrator= &amp;quot;INVINT&amp;quot;       # [NL] Integrator (&amp;quot;EULEREXP/RK4/RK2EXP/HEUN/INVINT/CRANKNIC&amp;quot;)&lt;br /&gt;
 NLCorrelation= &amp;quot;IPA&amp;quot;         # [NL] Correlation (&amp;quot;IPA/HARTREE/TDDFT/LRC/JGM/SEX/HF&amp;quot;)&lt;br /&gt;
 NLLrcAlpha= 0.000000         # [NL] Long Range Correction&lt;br /&gt;
 % NLEnRange&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;  1.000000 | 5.000000 &amp;lt;/span&amp;gt;| eV    # [NL] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 NLEnSteps= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 5  &amp;lt;/span&amp;gt;              # [NL] Energy steps&lt;br /&gt;
 NLDamping= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 0.150000  &amp;lt;/span&amp;gt;  eV    # [NL] Damping&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 1.000000 | 1.000000 | 0.000000 &amp;lt;/span&amp;gt;|        # [RT Field1] Versor&lt;br /&gt;
 Field1_kind= &amp;quot;SOFTSIN&amp;quot;         # [NL ExtF] Kind(SIN|SOFTSIN|RES|ANTIRES|GAUSS|DELTA|QSSIN)&lt;br /&gt;
&lt;br /&gt;
The line &amp;lt;code&amp;gt;|1.000000 | 1.000000 | 0.000000 | # [RT Field1] Versor&amp;lt;/code&amp;gt; referees to the direction of the external field (x,y,0). At present only an external field is present but the code can be easily generalized to deal with more fields.&lt;br /&gt;
The default parameters of Yambo/Lumen are already tuned for second-harmonic generation, so the only thing you have to change is the band range, between 3 and 6 and the energy range between 1.0-5.0 eV and the number of energy steps in this interval that we set to 10. Notice that you cannot set to zero the lowest value of the energy range because this will requires a simulation that lasts infinite time, see below. Finally, consider that Yambo performs a separate calculation for each frequency, so if you set many energy steps the computational time grows linearly with this number.&lt;br /&gt;
Notice that we set &amp;lt;code&amp;gt;NLverbosity= &amp;quot;high&amp;quot;&amp;lt;/code&amp;gt; in this way the code will produce a file for each laser frequency containing the time dependent polarization.&lt;br /&gt;
Run &amp;lt;code&amp;gt;yambo_nl&amp;lt;/code&amp;gt;. Calculations will take about fifteen minutes on a single processor PC, you have time to study the next section that explains how non-linear response is extracted from the real-time simulations.&lt;br /&gt;
In order to speed up calculations, you can run them in parallel.&lt;br /&gt;
&lt;br /&gt;
==Non-linear response with Yambo==&lt;br /&gt;
&lt;br /&gt;
In order to calculate the non-linear response, the system is excited with different laser fields with a sinusoidal shape at frequencies &amp;lt;math&amp;gt;\omega_1, \omega_2, .... , \omega_n &amp;lt;/math&amp;gt; determined by the parameters [[Variables#NLEnRangev|NLEnRange]] and [[Variables#NLEnSteps|NLEnSteps]]. A dephasing term is added to the Hamiltonian &amp;lt;math&amp;gt;\gamma = &amp;lt;/math&amp;gt;[[Variables#NLDamping|NLDamping]] to simulate a finite broadening and to remove the eigenmodes that are excited by the sudden turning on of the external field. After the dephasing time the outgoing signal is analyzed to extract the non-linear coefficients as shown in the figure below: &lt;br /&gt;
&lt;br /&gt;
[[File:Pt analysis.png|600px|center|Non-linear response analysis]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the report file &amp;lt;code&amp;gt;r_nlinear&amp;lt;/code&amp;gt; you will find the length of the dephasing part and of the sampling one:&lt;br /&gt;
&lt;br /&gt;
  Dephasing Time          [fs]: 52.65695&lt;br /&gt;
  Sampling  Time          [fs]:  4.18566&lt;br /&gt;
  Total simulation time   [fs]: 56.84262                     &lt;br /&gt;
The length of the dephasing interval is inversely proportional to the damping term &amp;lt;math&amp;gt;T_{depth} \simeq 1/\gamma&amp;lt;/math&amp;gt; while the length of the sampling is dictated by the smallest frequency we are interested in: &amp;lt;math&amp;gt;T_{samp} \simeq 1/\omega_1 &amp;lt;/math&amp;gt;. For this reason if &amp;lt;math&amp;gt; \omega_1=0 &amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt; \gamma = 0 &amp;lt;/math&amp;gt; simulation time goes to infinity. The response at zero frequency can be calculated as limit of small frequency perturbation.&lt;br /&gt;
You can have a look to the file &amp;lt;code&amp;gt;src/nloptics/NL_initialize.F&amp;lt;/code&amp;gt; to see how simulation lengths are defined.&lt;br /&gt;
Calculations can take some time, run them in parallel, the best number of processors = number of frequencies or reduce the number of frequencies step in the SHG.&lt;br /&gt;
&lt;br /&gt;
==Analysis of the results==&lt;br /&gt;
&lt;br /&gt;
In the sampling region we suppose that the polarization can be written as: &amp;lt;math&amp;gt;\bf{P}(t) = \sum_{n=-\infty}^{+\infty} \bf{p}_n e^{-i\omega_n t} &amp;lt;/math&amp;gt; where the coefficient &amp;lt;math&amp;gt;\bf{p}_1,...,\bf{p}_n &amp;lt;/math&amp;gt; are related to &amp;lt;math&amp;gt;\chi^{(1)},...,\chi^{(n)} &amp;lt;/math&amp;gt;. We sample the polarization signal at different times and invert the previous equation by truncating the sum at a finite order &amp;lt;ref&amp;gt;[https://arxiv.org/abs/1309.4012 Nonlinear optics from an ab initio approach by means of the dynamical Berry phase: Application to second- and third-harmonic generation in semiconductors], C. Attaccalite and M. Grüning, Phys. Rev. B 88, 235113(2013)&amp;lt;/ref&amp;gt;.&lt;br /&gt;
This is done with the command &amp;lt;code&amp;gt;ypp_nl -u&amp;lt;/code&amp;gt; that automatically produce an input with the correct values:&lt;br /&gt;
&lt;br /&gt;
 nonlinear                    # [R] NonLinear Optics Post-Processing&lt;br /&gt;
 Xorder=   &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;4  &amp;lt;/span&amp;gt;                 # Max order of the response functions&lt;br /&gt;
 % TimeRange&lt;br /&gt;
  52.65695 | -1.00000 | fs    # Time-window where processing is done&lt;br /&gt;
 % &lt;br /&gt;
 ETStpsRt= 200                # Total Energy steps&lt;br /&gt;
 % EnRngeRt&lt;br /&gt;
   0.00000 | 10.00000 | eV    # Energy range&lt;br /&gt;
 %&lt;br /&gt;
 DampMode= &amp;quot;NONE&amp;quot;             # Damping type ( NONE | LORENTZIAN | GAUSSIAN )&lt;br /&gt;
 DampFactor=  0.10000   eV    # Damping parameter&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;code&amp;gt;Xorder&amp;lt;/code&amp;gt; is the order where the previous sum is truncated, and the TimeRange specifies the sampling region. Notice that differently from the first tutorial, in this case, we do not need Damping in &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; because we already included it in the real-time dynamics. Run &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; and it will produce a file called &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;. This file contains the different components of &amp;lt;math&amp;gt;\chi^2_{xy*} &amp;lt;/math&amp;gt; and in particular the columns 6 and 7 correspond to the imaginary and real part of &amp;lt;math&amp;gt;\chi^2_{xyz} &amp;lt;/math&amp;gt;. You can plot the result with gnuplot and the command:&lt;br /&gt;
&lt;br /&gt;
 p &#039;o.YPP-X_probe_order_2&#039; u 1:(sqrt($6**2+$7**2)) w lp ps 1.5 pt 7 lw 1.5&lt;br /&gt;
&lt;br /&gt;
the result should look like&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AlAs results.png|700px|center|SHG in AlAs]]&lt;br /&gt;
&lt;br /&gt;
and compare it with the &amp;lt;math&amp;gt; \chi^2_{zxy} &amp;lt;/math&amp;gt; calculated with more frequencies and with the converged result on a &amp;lt;math&amp;gt; 18x18x18&amp;lt;/math&amp;gt; k-point grid and bands between 2 and 10. In the figure you can find also the comparison with the results of Ref. &amp;lt;ref&amp;gt;Luppi et al. [https://arxiv.org/abs/1006.2649 PRB B, &#039;&#039;&#039;82&#039;&#039;&#039;, 235201(2010)]&amp;lt;/ref&amp;gt;. &lt;br /&gt;
Notice that the QuantumEspresso results are slightly different from the Abinit ones. This is due to the different pseudo-potential employed in the calculations if pseudopotentials were the same calculation would have been identical. You can download the script to generate this plot and the converged results [http://www.attaccalite.com/lumen/tutorials/AlAs/AlAs_results.tgz here].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notice that&#039;&#039;&#039; : the following parameters are not used in the non-linear response analysis: &amp;lt;code&amp;gt; EnRngeRt&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ETStpsRt&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;DampMode&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;DampFactor&amp;lt;/code&amp;gt;. The damping factor is set directly in the real-time simulation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;System of units in Non-linear Optics&amp;lt;/span&amp;gt;&#039;&#039;&#039;: notice that in Yambo the non-linear response functions are in the gaussian system of units, for example the &amp;lt;math&amp;gt; \chi^2 (\omega) &amp;lt;/math&amp;gt;  is in cm/statvolt. In order to convert the non-linear coefficients between different system of units, you can have a look at the [https://www.attaccalite.com/tutorials_yambo/Appendix_C_Boyd.pdf Appendix C] of the book [https://www.elsevier.com/books/nonlinear-optics/boyd/978-0-12-369470-6 &amp;quot;Non-linear optics&amp;quot;  by Robert W. Boyd].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;More tutorials&amp;lt;/span&amp;gt; on non-linear response (Third harmonic generation, parallelization, spin-orbit etc..) with Yambo can be found here: [http://www.attaccalite.com/lumen/tutorials.html More Tutorials]. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Analysis of the results using YamboPy==&lt;br /&gt;
The analysis of the result performed in the previous section using &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; can be performed using python script [https://github.com/yambo-code/yambopy YamboPy].&amp;lt;br&amp;gt;&lt;br /&gt;
In YamboPy we implemented all necessary functions to reads the Yambo databases and post-process the results. Here we show how to get the SHG signal from the previous &lt;br /&gt;
simulations. We suppose you correctly installed &amp;lt;code&amp;gt;YamboPy&amp;lt;/code&amp;gt; on your PC. Go in the folder where you ran non-linear calculation and type in the python:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
 from yambopy import *&lt;br /&gt;
 NLDB=YamboNLDB()&lt;br /&gt;
 pol =NLDB.Polarization[0]&lt;br /&gt;
 time=NLDB.IO_TIME_points&lt;br /&gt;
&lt;br /&gt;
in this way you read all the Non-linear databases. If your runs are in a different folder then the &#039;SAVE&#039; one you can specify it using the command:&lt;br /&gt;
 NLDB=YamboNLDB(calc=&#039;MYJOB&#039;)&lt;br /&gt;
&lt;br /&gt;
now in the array &amp;lt;code&amp;gt;pol&amp;lt;/code&amp;gt; you have all the polarization for all laser frequencies in the three Cartesian directions, while the variable &amp;lt;code&amp;gt;time&amp;lt;/code&amp;gt; contains all the time series of your simulation.&lt;br /&gt;
Now you can get the non-linear response with the command:&lt;br /&gt;
&lt;br /&gt;
 Harmonic_Analysis(NLDB,X_order=4)&lt;br /&gt;
&lt;br /&gt;
this command will perform a Fourier analysis of the results in the same way of &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; and generate new files with all the requested harmonics &#039;&#039;o.YamboPy-X_probe_order_1&#039;&#039;, &#039;&#039;o.YamboPy-X_probe_order_2&#039;&#039; etc...&lt;br /&gt;
equivalent to the one generated by &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt;. Results can be plot with gnuplot using the command:&lt;br /&gt;
 &lt;br /&gt;
 p &#039;o.YamboPy-X_probe_order_2&#039; u 1:(sqrt($6**2+$7**2)) w lp ps 1.5 pt 7 lw 1.5&lt;br /&gt;
&lt;br /&gt;
The script that performs non-linear analysis can be found in &amp;lt;code&amp;gt;yambopy/nl/harmonic_analysis.py&amp;lt;/code&amp;gt;. &amp;lt;br&amp;gt; We strongly advice you to have a look to this script and modify it according&lt;br /&gt;
to your needs and in order to extract other non-linear response functions.&lt;br /&gt;
&lt;br /&gt;
==How to choose the external field direction for the different X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
In the X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;abc&amp;lt;/sub&amp;gt; response you have three field directions. The two components &#039;&#039;b&#039;&#039; and &#039;&#039;c&#039;&#039; are determined by the external field and the third &#039;&#039;a&#039;&#039;&lt;br /&gt;
is the direction where you measure the response.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The external field in Yambo is set using the variable&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
   1.000000 | 0.000000 | 0.000000 |        # [NL ExtF] Versor .&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
For example if you set in Yambo field direction as:&lt;br /&gt;
&lt;br /&gt;
 1.0 | 0.0 | 0.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*xx&amp;lt;/sub&amp;gt;&lt;br /&gt;
 0.0 | 1.0 | 0.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*yy&amp;lt;/sub&amp;gt;&lt;br /&gt;
 0.0 | 0.0 | 1.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*zz&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the * correspond to the different direction in the response file &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;.&lt;br /&gt;
In the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt; you have seven columns:&lt;br /&gt;
&lt;br /&gt;
 The first column is the energy [[omega]],&lt;br /&gt;
 the 2nd and 3rd columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;x**&amp;lt;/sub&amp;gt;&lt;br /&gt;
 the 4th and 5th columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;y**&amp;lt;/sub&amp;gt;&lt;br /&gt;
 the 6th and 7th columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;z**&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where the ** are the direction of the incoming field, see above.&lt;br /&gt;
&lt;br /&gt;
For example if you want to calculate the &amp;lt;math&amp;gt;\chi^{(2)}_{zxx}&amp;lt;/math&amp;gt; you put the external field in the direction &amp;lt;code&amp;gt; 1.0 | 0.0 | 0.0 |&amp;lt;/code&amp;gt;&lt;br /&gt;
and then plot the column 6 and 7 of the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt; file.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to get the other components of the  X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; the calculation are more involved. For example if you put field in the&lt;br /&gt;
&lt;br /&gt;
 1.0 | 1.0 | 0.0 | &lt;br /&gt;
&lt;br /&gt;
this corresponds to &amp;lt;math&amp;gt;E(t)=\frac{1}{\sqrt{2}} [ E_x(t) + E_y(t) ]&amp;lt;/math&amp;gt; and so at the second order you will have &amp;lt;math&amp;gt;E^2(t)=\frac{1}{2} \left [ E^2_x(t) + E^2_y(t) +  E_x(t) E_y(t) +  E_y(t) E_x(t) \right]&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
this means that  the X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; in the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;  will correspond to a linear combination of the following different response functions.&amp;lt;br&amp;gt;&lt;br /&gt;
For example in the the 2nd and 3rd columns are the imaginary and real part of:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{x**}=\frac{1}{2} \left [\chi^2_{xxx}+\chi^{(2)}_{xyy} + \chi^{(2)}_{xxy} + \chi^{(2)}_{xyx} \right ]&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the same for the other column replacing the first &amp;lt;code&amp;gt;x&amp;lt;/code&amp;gt; for &amp;lt;code&amp;gt;y,z&amp;lt;/code&amp;gt;.&lt;br /&gt;
If you know that some components are zero this allow you to extract the corresponding off-diagonal part of &amp;lt;math&amp;gt;\chi^{(2)}_{abc}&amp;lt;/math&amp;gt; otherwise you have to perform different calculations to get the component you are interested in. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Now we present &#039;&#039;&#039;a simple example of monolayer hBN (m-hBN)&#039;&#039;&#039;. &amp;lt;br&amp;gt; In m-hBN there is only a non-zero component of the $\chi^2$ and all the others are related by symmetry:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{yyy}=-\chi^{(2)}_{yxx}=-\chi^{(2)}_{xxy}=-\chi^{(2)}_{xyx}&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
so if you put the field in the &amp;lt;code&amp;gt;|1|1|0|&amp;lt;/code&amp;gt; direction you will get:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{x**} = \frac{1}{2} \left[\chi^{(2)}_{xxy} + \chi^{(2)}_{xyx} \right] = - \chi^{(2)}_{yyy} &amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{y**} =\frac{1}{2} \left[ \chi^{(2)}_{yyy} + \chi^{(2)}_{yxx}  \right] = 0.0 &amp;lt;/math&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
In the figure below you can see the different &amp;lt;math&amp;gt;\chi^{(2)}&amp;lt;/math&amp;gt; of monolayer hBN. &lt;br /&gt;
&lt;br /&gt;
[[File:Xhi2 xy.png|center| 800px|xhi2_xy]]&lt;br /&gt;
&lt;br /&gt;
as you can see in the second panel, when the field is in the &amp;lt;code&amp;gt;xy&amp;lt;/code&amp;gt; you get a linear combination of  &amp;lt;code&amp;gt;\chi^{(2)}&amp;lt;/code&amp;gt; corresponding to the equation above, in this case the &amp;lt;code&amp;gt;y&amp;lt;/code&amp;gt; is zero while the &amp;lt;code&amp;gt;x&amp;lt;/code&amp;gt; component is equal to &amp;lt;math&amp;gt;\chi^{(2)}_{yyy}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Nota bene:&#039;&#039;&#039; if you change the direction of the external field you have to remove the corresponding symmetries as explained in the tutorial [[Prerequisites for Real Time_propagation with Yambo#Reduce symmetries real-time linear response tutorial]].&lt;br /&gt;
&lt;br /&gt;
==Non-linear response of low-dimensional structures: 2D or 1D ==&lt;br /&gt;
&lt;br /&gt;
The Yambo code is a 3D periodic code, so when you want to study a low-dimensional system 2D or 1D, you have to use a supercell approach.&lt;br /&gt;
For example to simulate the non-linear response in a 2D-crystal one, can put the crystal in the xy plane and choose a larger distance in the z-direction&lt;br /&gt;
in order to reduce the interaction between the periodic replica. Clearly in this case k-point sampling will be only in the x,y directions.&lt;br /&gt;
For calculations on this type of systems, these two warnings must be taken into account:&lt;br /&gt;
&lt;br /&gt;
* if you calculate GW corrections or include electron-hole interaction in the linear/non-linear response it is a good idea to use a &#039;&#039;&#039;Coulomb cutoff&#039;&#039;&#039;, similar to the 2D BSE case  [http://www.yambo-code.org/wiki/index.php?title=How_to_treat_low_dimensional_systems How to treat low dimensional systems]. You can add the cutoff just adding the &amp;quot;-r&amp;quot; in the input generation.&lt;br /&gt;
&lt;br /&gt;
* the calculation of SHG and THG are always performed respect to the supercell, therefore you have to &#039;&#039;&#039;re-scale&#039;&#039;&#039; the result to the effective thickness of the layer, usually the inter-layer distance of the corresponding bulk material for 2D systems: &amp;lt;math&amp;gt;\chi_{rescaled}(\omega) = L_z/d_{eff} \cdot \chi(\omega) &amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;L_z&amp;lt;/math&amp;gt; is the z-dimension of the supercell, and &amp;lt;math&amp;gt;d_{eff}&amp;lt;/math&amp;gt; is the effective thickness of the 2D system.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Nota bene&#039;&#039;&#039;: Non-linear response along &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;non-periodic directions&amp;lt;/span&amp;gt; is not implemented in Yambo, the code will print zero in these directions for all response functions. We plan to implement it in a future version of the code.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Links for schools==&lt;br /&gt;
* Back to [[Rome 2023#Tutorials]]&lt;br /&gt;
* Back to [[ICTP2020]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
{| style=&amp;quot;width:100%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|style=&amp;quot;width:25%; text-align:left&amp;quot;|Prev: [[Linear response from real time simulations|Linear response from real time simulations]]&lt;br /&gt;
|style=&amp;quot;width:45%; text-align:center&amp;quot;|Now: [[ICTP2020|ICTP  Tutorials]] --&amp;gt; [[Real time approach to non-linear response|Non Linear Response]] &lt;br /&gt;
|style=&amp;quot;width:50%; text-align:left&amp;quot;|Next: [[Correlation effects in the non-linear response|Correlation effects in the non-linear response ]]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Attacc</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Real_time_approach_to_non-linear_response_(SHG)&amp;diff=9161</id>
		<title>Real time approach to non-linear response (SHG)</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Real_time_approach_to_non-linear_response_(SHG)&amp;diff=9161"/>
		<updated>2025-09-28T07:52:36Z</updated>

		<summary type="html">&lt;p&gt;Attacc: /* How to choose the external field direction for the different X2 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Second Harmonic Generation in AlAs ==&lt;br /&gt;
In this tutorial, we will calculate the second harmonic generation of bulk AlAs, the Yambo databases can be downloaded here: [https://media.yambo-code.eu/educational/tutorials/files/AlAs_DBs.tar.gz AlAs_DBs.tar.gz] (10 MB). The first steps of this tutorials are the same as the one on [http://www.yambo-code.eu/wiki/index.php?title=Prerequisites_for_Real_Time_propagation_with_Yambo Prerequisites for Real-Time propagation with Yambo] with the only difference that we will work on AlAs and we will consider an external field in the direction &amp;lt;code&amp;gt; 1.000000 | 1.000000 | 0.000000 |&amp;lt;/code&amp;gt;. The DFT input are available here: [https://media.yambo-code.eu/educational/tutorials/files/AlAs_abinit.tar.gz ABINIT] or [https://media.yambo-code.eu/educational/tutorials/files/AlAs_pwscf.tar.gz QuantumEspresso].&lt;br /&gt;
You can run the DFT calculation with ABINIT with the command:&lt;br /&gt;
&lt;br /&gt;
 abinit &amp;lt; AlAs.in &amp;gt; output_AlAs                                             &lt;br /&gt;
&lt;br /&gt;
or using QuantumEspresso:&lt;br /&gt;
&lt;br /&gt;
 pw.x -inp AlAs.scf.in &amp;gt; output_scf&lt;br /&gt;
 pw.x -inp AlAs.nscf.in &amp;gt; output_scf                            &lt;br /&gt;
&lt;br /&gt;
and then import the ABINIT wave-function with the command:&lt;br /&gt;
&lt;br /&gt;
 a2y -F AlAso_DS2_WFK.nc                            &lt;br /&gt;
&lt;br /&gt;
and the QuantumEspresso one, in the folder AlAs.save with the command:&lt;br /&gt;
&lt;br /&gt;
 p2y                              &lt;br /&gt;
Now we consider an external field in the &amp;lt;code&amp;gt;[1,1,0]&amp;lt;/code&amp;gt; direction and remove symmetries not compatible with this field, as explained in the tutorial [http://www.yambo-code.eu/wiki/index.php?title=Prerequisites_for_Real_Time_propagation_with_Yambo Prerequisites for Real-Time propagation with Yambo].&lt;br /&gt;
&lt;br /&gt;
==Real-time simulation for the SHG==&lt;br /&gt;
&lt;br /&gt;
You can generate the input file with the command &amp;lt;code&amp;gt;yambo_nl -u n&amp;lt;/code&amp;gt;:&lt;br /&gt;
                       &lt;br /&gt;
 nloptics                      # [R NL] Non-linear optics&lt;br /&gt;
 % NLBands&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 3 | 6&amp;lt;/span&amp;gt; |                   # [NL] Bands&lt;br /&gt;
 %&lt;br /&gt;
 NLstep=   0.0100       fs    # [NL] Real Time step length&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;NLverbosity= &amp;quot;high&amp;quot;&amp;lt;/span&amp;gt;               # [NL] Verbosity level (low | high)&lt;br /&gt;
 NLtime=-1.000000           fs    # [NL] Simulation Time&lt;br /&gt;
 NLintegrator= &amp;quot;INVINT&amp;quot;       # [NL] Integrator (&amp;quot;EULEREXP/RK4/RK2EXP/HEUN/INVINT/CRANKNIC&amp;quot;)&lt;br /&gt;
 NLCorrelation= &amp;quot;IPA&amp;quot;         # [NL] Correlation (&amp;quot;IPA/HARTREE/TDDFT/LRC/JGM/SEX/HF&amp;quot;)&lt;br /&gt;
 NLLrcAlpha= 0.000000         # [NL] Long Range Correction&lt;br /&gt;
 % NLEnRange&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;  1.000000 | 5.000000 &amp;lt;/span&amp;gt;| eV    # [NL] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 NLEnSteps= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 5  &amp;lt;/span&amp;gt;              # [NL] Energy steps&lt;br /&gt;
 NLDamping= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 0.150000  &amp;lt;/span&amp;gt;  eV    # [NL] Damping&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 1.000000 | 1.000000 | 0.000000 &amp;lt;/span&amp;gt;|        # [RT Field1] Versor&lt;br /&gt;
 Field1_kind= &amp;quot;SOFTSIN&amp;quot;         # [NL ExtF] Kind(SIN|SOFTSIN|RES|ANTIRES|GAUSS|DELTA|QSSIN)&lt;br /&gt;
&lt;br /&gt;
The line &amp;lt;code&amp;gt;|1.000000 | 1.000000 | 0.000000 | # [RT Field1] Versor&amp;lt;/code&amp;gt; referees to the direction of the external field (x,y,0). At present only an external field is present but the code can be easily generalized to deal with more fields.&lt;br /&gt;
The default parameters of Yambo/Lumen are already tuned for second-harmonic generation, so the only thing you have to change is the band range, between 3 and 6 and the energy range between 1.0-5.0 eV and the number of energy steps in this interval that we set to 10. Notice that you cannot set to zero the lowest value of the energy range because this will requires a simulation that lasts infinite time, see below. Finally, consider that Yambo performs a separate calculation for each frequency, so if you set many energy steps the computational time grows linearly with this number.&lt;br /&gt;
Notice that we set &amp;lt;code&amp;gt;NLverbosity= &amp;quot;high&amp;quot;&amp;lt;/code&amp;gt; in this way the code will produce a file for each laser frequency containing the time dependent polarization.&lt;br /&gt;
Run &amp;lt;code&amp;gt;yambo_nl&amp;lt;/code&amp;gt;. Calculations will take about fifteen minutes on a single processor PC, you have time to study the next section that explains how non-linear response is extracted from the real-time simulations.&lt;br /&gt;
In order to speed up calculations, you can run them in parallel.&lt;br /&gt;
&lt;br /&gt;
==Non-linear response with Yambo==&lt;br /&gt;
&lt;br /&gt;
In order to calculate the non-linear response, the system is excited with different laser fields with a sinusoidal shape at frequencies &amp;lt;math&amp;gt;\omega_1, \omega_2, .... , \omega_n &amp;lt;/math&amp;gt; determined by the parameters [[Variables#NLEnRangev|NLEnRange]] and [[Variables#NLEnSteps|NLEnSteps]]. A dephasing term is added to the Hamiltonian &amp;lt;math&amp;gt;\gamma = &amp;lt;/math&amp;gt;[[Variables#NLDamping|NLDamping]] to simulate a finite broadening and to remove the eigenmodes that are excited by the sudden turning on of the external field. After the dephasing time the outgoing signal is analyzed to extract the non-linear coefficients as shown in the figure below: &lt;br /&gt;
&lt;br /&gt;
[[File:Pt analysis.png|600px|center|Non-linear response analysis]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the report file &amp;lt;code&amp;gt;r_nlinear&amp;lt;/code&amp;gt; you will find the length of the dephasing part and of the sampling one:&lt;br /&gt;
&lt;br /&gt;
  Dephasing Time          [fs]: 52.65695&lt;br /&gt;
  Sampling  Time          [fs]:  4.18566&lt;br /&gt;
  Total simulation time   [fs]: 56.84262                     &lt;br /&gt;
The length of the dephasing interval is inversely proportional to the damping term &amp;lt;math&amp;gt;T_{depth} \simeq 1/\gamma&amp;lt;/math&amp;gt; while the length of the sampling is dictated by the smallest frequency we are interested in: &amp;lt;math&amp;gt;T_{samp} \simeq 1/\omega_1 &amp;lt;/math&amp;gt;. For this reason if &amp;lt;math&amp;gt; \omega_1=0 &amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt; \gamma = 0 &amp;lt;/math&amp;gt; simulation time goes to infinity. The response at zero frequency can be calculated as limit of small frequency perturbation.&lt;br /&gt;
You can have a look to the file &amp;lt;code&amp;gt;src/nloptics/NL_initialize.F&amp;lt;/code&amp;gt; to see how simulation lengths are defined.&lt;br /&gt;
Calculations can take some time, run them in parallel, the best number of processors = number of frequencies or reduce the number of frequencies step in the SHG.&lt;br /&gt;
&lt;br /&gt;
==Analysis of the results==&lt;br /&gt;
&lt;br /&gt;
In the sampling region we suppose that the polarization can be written as: &amp;lt;math&amp;gt;\bf{P}(t) = \sum_{n=-\infty}^{+\infty} \bf{p}_n e^{-i\omega_n t} &amp;lt;/math&amp;gt; where the coefficient &amp;lt;math&amp;gt;\bf{p}_1,...,\bf{p}_n &amp;lt;/math&amp;gt; are related to &amp;lt;math&amp;gt;\chi^{(1)},...,\chi^{(n)} &amp;lt;/math&amp;gt;. We sample the polarization signal at different times and invert the previous equation by truncating the sum at a finite order &amp;lt;ref&amp;gt;[https://arxiv.org/abs/1309.4012 Nonlinear optics from an ab initio approach by means of the dynamical Berry phase: Application to second- and third-harmonic generation in semiconductors], C. Attaccalite and M. Grüning, Phys. Rev. B 88, 235113(2013)&amp;lt;/ref&amp;gt;.&lt;br /&gt;
This is done with the command &amp;lt;code&amp;gt;ypp_nl -u&amp;lt;/code&amp;gt; that automatically produce an input with the correct values:&lt;br /&gt;
&lt;br /&gt;
 nonlinear                    # [R] NonLinear Optics Post-Processing&lt;br /&gt;
 Xorder=   &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;4  &amp;lt;/span&amp;gt;                 # Max order of the response functions&lt;br /&gt;
 % TimeRange&lt;br /&gt;
  52.65695 | -1.00000 | fs    # Time-window where processing is done&lt;br /&gt;
 % &lt;br /&gt;
 ETStpsRt= 200                # Total Energy steps&lt;br /&gt;
 % EnRngeRt&lt;br /&gt;
   0.00000 | 10.00000 | eV    # Energy range&lt;br /&gt;
 %&lt;br /&gt;
 DampMode= &amp;quot;NONE&amp;quot;             # Damping type ( NONE | LORENTZIAN | GAUSSIAN )&lt;br /&gt;
 DampFactor=  0.10000   eV    # Damping parameter&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;code&amp;gt;Xorder&amp;lt;/code&amp;gt; is the order where the previous sum is truncated, and the TimeRange specifies the sampling region. Notice that differently from the first tutorial, in this case, we do not need Damping in &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; because we already included it in the real-time dynamics. Run &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; and it will produce a file called &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;. This file contains the different components of &amp;lt;math&amp;gt;\chi^2_{xy*} &amp;lt;/math&amp;gt; and in particular the columns 6 and 7 correspond to the imaginary and real part of &amp;lt;math&amp;gt;\chi^2_{xyz} &amp;lt;/math&amp;gt;. You can plot the result with gnuplot and the command:&lt;br /&gt;
&lt;br /&gt;
 p &#039;o.YPP-X_probe_order_2&#039; u 1:(sqrt($6**2+$7**2)) w lp ps 1.5 pt 7 lw 1.5&lt;br /&gt;
&lt;br /&gt;
the result should look like&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AlAs results.png|700px|center|SHG in AlAs]]&lt;br /&gt;
&lt;br /&gt;
and compare it with the &amp;lt;math&amp;gt; \chi^2_{zxy} &amp;lt;/math&amp;gt; calculated with more frequencies and with the converged result on a &amp;lt;math&amp;gt; 18x18x18&amp;lt;/math&amp;gt; k-point grid and bands between 2 and 10. In the figure you can find also the comparison with the results of Ref. &amp;lt;ref&amp;gt;Luppi et al. [https://arxiv.org/abs/1006.2649 PRB B, &#039;&#039;&#039;82&#039;&#039;&#039;, 235201(2010)]&amp;lt;/ref&amp;gt;. &lt;br /&gt;
Notice that the QuantumEspresso results are slightly different from the Abinit ones. This is due to the different pseudo-potential employed in the calculations if pseudopotentials were the same calculation would have been identical. You can download the script to generate this plot and the converged results [http://www.attaccalite.com/lumen/tutorials/AlAs/AlAs_results.tgz here].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notice that&#039;&#039;&#039; : the following parameters are not used in the non-linear response analysis: &amp;lt;code&amp;gt; EnRngeRt&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ETStpsRt&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;DampMode&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;DampFactor&amp;lt;/code&amp;gt;. The damping factor is set directly in the real-time simulation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;System of units in Non-linear Optics&amp;lt;/span&amp;gt;&#039;&#039;&#039;: notice that in Yambo the non-linear response functions are in the gaussian system of units, for example the &amp;lt;math&amp;gt; \chi^2 (\omega) &amp;lt;/math&amp;gt;  is in cm/statvolt. In order to convert the non-linear coefficients between different system of units, you can have a look at the [https://www.attaccalite.com/tutorials_yambo/Appendix_C_Boyd.pdf Appendix C] of the book [https://www.elsevier.com/books/nonlinear-optics/boyd/978-0-12-369470-6 &amp;quot;Non-linear optics&amp;quot;  by Robert W. Boyd].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;More tutorials&amp;lt;/span&amp;gt; on non-linear response (Third harmonic generation, parallelization, spin-orbit etc..) with Yambo can be found here: [http://www.attaccalite.com/lumen/tutorials.html More Tutorials]. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Analysis of the results using YamboPy==&lt;br /&gt;
The analysis of the result performed in the previous section using &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; can be performed using python script [https://github.com/yambo-code/yambopy YamboPy].&amp;lt;br&amp;gt;&lt;br /&gt;
In YamboPy we implemented all necessary functions to reads the Yambo databases and post-process the results. Here we show how to get the SHG signal from the previous &lt;br /&gt;
simulations. We suppose you correctly installed &amp;lt;code&amp;gt;YamboPy&amp;lt;/code&amp;gt; on your PC. Go in the folder where you ran non-linear calculation and type in the python:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
 from yambopy import *&lt;br /&gt;
 NLDB=YamboNLDB()&lt;br /&gt;
 pol =NLDB.Polarization[0]&lt;br /&gt;
 time=NLDB.IO_TIME_points&lt;br /&gt;
&lt;br /&gt;
in this way you read all the Non-linear databases. If your runs are in a different folder then the &#039;SAVE&#039; one you can specify it using the command:&lt;br /&gt;
 NLDB=YamboNLDB(calc=&#039;MYJOB&#039;)&lt;br /&gt;
&lt;br /&gt;
now in the array &amp;lt;code&amp;gt;pol&amp;lt;/code&amp;gt; you have all the polarization for all laser frequencies in the three Cartesian directions, while the variable &amp;lt;code&amp;gt;time&amp;lt;/code&amp;gt; contains all the time series of your simulation.&lt;br /&gt;
Now you can get the non-linear response with the command:&lt;br /&gt;
&lt;br /&gt;
 Harmonic_Analysis(NLDB,X_order=4)&lt;br /&gt;
&lt;br /&gt;
this command will perform a Fourier analysis of the results in the same way of &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; and generate new files with all the requested harmonics &#039;&#039;o.YamboPy-X_probe_order_1&#039;&#039;, &#039;&#039;o.YamboPy-X_probe_order_2&#039;&#039; etc...&lt;br /&gt;
equivalent to the one generated by &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt;. Results can be plot with gnuplot using the command:&lt;br /&gt;
 &lt;br /&gt;
 p &#039;o.YamboPy-X_probe_order_2&#039; u 1:(sqrt($6**2+$7**2)) w lp ps 1.5 pt 7 lw 1.5&lt;br /&gt;
&lt;br /&gt;
The script that performs non-linear analysis can be found in &amp;lt;code&amp;gt;yambopy/nl/harmonic_analysis.py&amp;lt;/code&amp;gt;. &amp;lt;br&amp;gt; We strongly advice you to have a look to this script and modify it according&lt;br /&gt;
to your needs and in order to extract other non-linear response functions.&lt;br /&gt;
&lt;br /&gt;
==How to choose the external field direction for the different X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
In the X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;abc&amp;lt;/sub&amp;gt; response you have three field directions. The two components &#039;&#039;b&#039;&#039; and &#039;&#039;c&#039;&#039; are determined by the external field and the third &#039;&#039;a&#039;&#039;&lt;br /&gt;
is the direction where you measure the response.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The external field in Yambo is set using the variable&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
   1.000000 | 0.000000 | 0.000000 |        # [NL ExtF] Versor .&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
For example if you set in Yambo field direction as:&lt;br /&gt;
&lt;br /&gt;
 1.0 | 0.0 | 0.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*xx&amp;lt;/sub&amp;gt;&lt;br /&gt;
 0.0 | 1.0 | 0.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*yy&amp;lt;/sub&amp;gt;&lt;br /&gt;
 0.0 | 0.0 | 1.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*zz&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the * correspond to the different direction in the response file &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;.&lt;br /&gt;
In the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt; you have seven columns:&lt;br /&gt;
&lt;br /&gt;
 The first column is the energy [[omega]],&lt;br /&gt;
 the 2nd and 3rd columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;x**&amp;lt;/sub&amp;gt;&lt;br /&gt;
 the 4th and 5th columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;y**&amp;lt;/sub&amp;gt;&lt;br /&gt;
 the 6th and 7th columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;z**&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where the ** are the direction of the incoming field, see above.&lt;br /&gt;
&lt;br /&gt;
For example if you want to calculate the &amp;lt;math&amp;gt;\chi^{(2)}_{zxx}&amp;lt;/math&amp;gt; you put the external field in the direction &amp;lt;code&amp;gt; 1.0 | 0.0 | 0.0 |&amp;lt;/code&amp;gt;&lt;br /&gt;
and then plot the column 6 and 7 of the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt; file.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to get the other components of the  X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; the calculation are more involved. For example if you put field in the&lt;br /&gt;
&lt;br /&gt;
 1.0 | 1.0 | 0.0 | &lt;br /&gt;
&lt;br /&gt;
this corresponds to &amp;lt;math&amp;gt;E(t)=\frac{1}{\sqrt{2}} [ E_x(t) + E_y(t) ]&amp;lt;/math&amp;gt; and so at the second order you will have &amp;lt;math&amp;gt;E^2(t)=\frac{1}{2} \left [ E^2_x(t) + E^2_y(t) +  E_x(t) E_y(t) +  E_y(t) E_x(t) \right]&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
this means that  the X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; in the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;  will correspond to a linear combination of the following different response functions.&amp;lt;br&amp;gt;&lt;br /&gt;
For example in the the 2nd and 3rd columns are the imaginary and real part of:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{x**}=\frac{1}{2} \left [\chi^2_{xxx}+\chi^{(2)}_{xyy} + \chi^{(2)}_{xxy} + \chi^{(2)}_{xyx} \right ]&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the same for the other column replacing the first &amp;lt;code&amp;gt;x&amp;lt;/code&amp;gt; for &amp;lt;code&amp;gt;y,z&amp;lt;/code&amp;gt;.&lt;br /&gt;
If you know that some components are zero this allow you to extract the corresponding off-diagonal part of &amp;lt;math&amp;gt;\chi^{(2)}_{abc}&amp;lt;/math&amp;gt; otherwise you have to perform different calculations to get the component you are interested in. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Now we present &#039;&#039;&#039;a simple example of monolayer hBN (m-hBN)&#039;&#039;&#039;. &amp;lt;br&amp;gt; In m-hBN there is only a non-zero component of the $\chi^2$ and all the others are related by symmetry:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{yyy}=-\chi^{(2)}_{yxx}=-\chi^{(2)}_{xxy}=-\chi^{(2)}_{xyx}&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
so if you put the field in the &amp;lt;code&amp;gt;|1|1|0|&amp;lt;/code&amp;gt; direction you will get:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{x**} = \frac{1}{2} \left[\chi^{(2)}_{xxy} + \chi^{(2)}_{xyx} \right] = - \chi^{(2)}_{yyy} &amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{y**} =\frac{1}{2} \left[ \chi^{(2)}_{yyy} + \chi^{(2)}_{yxx}  \right] = 0.0 &amp;lt;/math&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
In the figure below you can see the different &amp;lt;math&amp;gt;\chi^{(2)}&amp;lt;/math&amp;gt; of monolayer hBN. &lt;br /&gt;
&lt;br /&gt;
[[File:Xhi2 xy.png|center| 800px|xhi2_xy]]&lt;br /&gt;
&lt;br /&gt;
as you can see in the second panel, when the field is in the &amp;lt;code&amp;gt;xy&amp;lt;/code&amp;gt; you get a linear combination of  &amp;lt;code&amp;gt;\chi^{(2)}&amp;lt;/code&amp;gt; corresponding to the equation above, in this case the &amp;lt;code&amp;gt;y&amp;lt;/code&amp;gt; is zero while the &amp;lt;code&amp;gt;x&amp;lt;/code&amp;gt; component is equal to &amp;lt;math&amp;gt;\chi^{(2)}_{yyy}&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Nota bene:&#039;&#039;&#039; if you change the direction of the external field you have to remove the corresponding symmetries as explained in the tutorial [[Prerequisites for Real Time_propagation with Yambo#Reduce symmetries real-time linear response tutorial]].&lt;br /&gt;
&lt;br /&gt;
==Non-linear response of low-dimensional structures: 2D or 1D ==&lt;br /&gt;
&lt;br /&gt;
The Yambo code is a 3D periodic code, so when you want to study a low-dimensional system 2D or 1D, you have to use a supercell approach.&lt;br /&gt;
For example to simulate the non-linear response in a 2D-crystal one, can put the crystal in the xy plane and choose a larger distance in the z-direction&lt;br /&gt;
in order to reduce the interaction between the periodic replica. Clearly in this case k-point sampling will be only in the x,y directions.&lt;br /&gt;
For calculations on this type of systems, these two warnings must be taken into account:&lt;br /&gt;
&lt;br /&gt;
* if you calculate GW corrections or include electron-hole interaction in the linear/non-linear response it is a good idea to use a &#039;&#039;&#039;Coulomb cutoff&#039;&#039;&#039;, similar to the 2D BSE case  [http://www.yambo-code.org/wiki/index.php?title=How_to_treat_low_dimensional_systems How to treat low dimensional systems]. You can add the cutoff just adding the &amp;quot;-r&amp;quot; in the input generation.&lt;br /&gt;
&lt;br /&gt;
* the calculation of SHG and THG are always performed respect to the supercell, therefore you have to &#039;&#039;&#039;re-scale&#039;&#039;&#039; the result to the effective thickness of the layer, usually the inter-layer distance of the corresponding bulk material for 2D systems: &amp;lt;math&amp;gt;\chi_{rescaled}(\omega) = L_z/d_{eff} \cdot \chi(\omega) &amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;L_z&amp;lt;/math&amp;gt; is the z-dimension of the supercell, and &amp;lt;math&amp;gt;d_{eff}&amp;lt;/math&amp;gt; is the effective thickness of the 2D system.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Nota bene&#039;&#039;&#039;: Non-linear response along &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;non-periodic directions&amp;lt;/span&amp;gt; is not implemented in Yambo, the code will print zero in these directions for all response functions. We plan to implement it in a future version of the code.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Links for schools==&lt;br /&gt;
* Back to [[Rome 2023#Tutorials]]&lt;br /&gt;
* Back to [[ICTP2020]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
{| style=&amp;quot;width:100%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|style=&amp;quot;width:25%; text-align:left&amp;quot;|Prev: [[Linear response from real time simulations|Linear response from real time simulations]]&lt;br /&gt;
|style=&amp;quot;width:45%; text-align:center&amp;quot;|Now: [[ICTP2020|ICTP  Tutorials]] --&amp;gt; [[Real time approach to non-linear response|Non Linear Response]] &lt;br /&gt;
|style=&amp;quot;width:50%; text-align:left&amp;quot;|Next: [[Correlation effects in the non-linear response|Correlation effects in the non-linear response ]]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Attacc</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Real_time_approach_to_non-linear_response_(SHG)&amp;diff=9160</id>
		<title>Real time approach to non-linear response (SHG)</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Real_time_approach_to_non-linear_response_(SHG)&amp;diff=9160"/>
		<updated>2025-09-28T07:50:38Z</updated>

		<summary type="html">&lt;p&gt;Attacc: /* How to choose the external field direction for the different X2 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Second Harmonic Generation in AlAs ==&lt;br /&gt;
In this tutorial, we will calculate the second harmonic generation of bulk AlAs, the Yambo databases can be downloaded here: [https://media.yambo-code.eu/educational/tutorials/files/AlAs_DBs.tar.gz AlAs_DBs.tar.gz] (10 MB). The first steps of this tutorials are the same as the one on [http://www.yambo-code.eu/wiki/index.php?title=Prerequisites_for_Real_Time_propagation_with_Yambo Prerequisites for Real-Time propagation with Yambo] with the only difference that we will work on AlAs and we will consider an external field in the direction &amp;lt;code&amp;gt; 1.000000 | 1.000000 | 0.000000 |&amp;lt;/code&amp;gt;. The DFT input are available here: [https://media.yambo-code.eu/educational/tutorials/files/AlAs_abinit.tar.gz ABINIT] or [https://media.yambo-code.eu/educational/tutorials/files/AlAs_pwscf.tar.gz QuantumEspresso].&lt;br /&gt;
You can run the DFT calculation with ABINIT with the command:&lt;br /&gt;
&lt;br /&gt;
 abinit &amp;lt; AlAs.in &amp;gt; output_AlAs                                             &lt;br /&gt;
&lt;br /&gt;
or using QuantumEspresso:&lt;br /&gt;
&lt;br /&gt;
 pw.x -inp AlAs.scf.in &amp;gt; output_scf&lt;br /&gt;
 pw.x -inp AlAs.nscf.in &amp;gt; output_scf                            &lt;br /&gt;
&lt;br /&gt;
and then import the ABINIT wave-function with the command:&lt;br /&gt;
&lt;br /&gt;
 a2y -F AlAso_DS2_WFK.nc                            &lt;br /&gt;
&lt;br /&gt;
and the QuantumEspresso one, in the folder AlAs.save with the command:&lt;br /&gt;
&lt;br /&gt;
 p2y                              &lt;br /&gt;
Now we consider an external field in the &amp;lt;code&amp;gt;[1,1,0]&amp;lt;/code&amp;gt; direction and remove symmetries not compatible with this field, as explained in the tutorial [http://www.yambo-code.eu/wiki/index.php?title=Prerequisites_for_Real_Time_propagation_with_Yambo Prerequisites for Real-Time propagation with Yambo].&lt;br /&gt;
&lt;br /&gt;
==Real-time simulation for the SHG==&lt;br /&gt;
&lt;br /&gt;
You can generate the input file with the command &amp;lt;code&amp;gt;yambo_nl -u n&amp;lt;/code&amp;gt;:&lt;br /&gt;
                       &lt;br /&gt;
 nloptics                      # [R NL] Non-linear optics&lt;br /&gt;
 % NLBands&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 3 | 6&amp;lt;/span&amp;gt; |                   # [NL] Bands&lt;br /&gt;
 %&lt;br /&gt;
 NLstep=   0.0100       fs    # [NL] Real Time step length&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;NLverbosity= &amp;quot;high&amp;quot;&amp;lt;/span&amp;gt;               # [NL] Verbosity level (low | high)&lt;br /&gt;
 NLtime=-1.000000           fs    # [NL] Simulation Time&lt;br /&gt;
 NLintegrator= &amp;quot;INVINT&amp;quot;       # [NL] Integrator (&amp;quot;EULEREXP/RK4/RK2EXP/HEUN/INVINT/CRANKNIC&amp;quot;)&lt;br /&gt;
 NLCorrelation= &amp;quot;IPA&amp;quot;         # [NL] Correlation (&amp;quot;IPA/HARTREE/TDDFT/LRC/JGM/SEX/HF&amp;quot;)&lt;br /&gt;
 NLLrcAlpha= 0.000000         # [NL] Long Range Correction&lt;br /&gt;
 % NLEnRange&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;  1.000000 | 5.000000 &amp;lt;/span&amp;gt;| eV    # [NL] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 NLEnSteps= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 5  &amp;lt;/span&amp;gt;              # [NL] Energy steps&lt;br /&gt;
 NLDamping= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 0.150000  &amp;lt;/span&amp;gt;  eV    # [NL] Damping&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 1.000000 | 1.000000 | 0.000000 &amp;lt;/span&amp;gt;|        # [RT Field1] Versor&lt;br /&gt;
 Field1_kind= &amp;quot;SOFTSIN&amp;quot;         # [NL ExtF] Kind(SIN|SOFTSIN|RES|ANTIRES|GAUSS|DELTA|QSSIN)&lt;br /&gt;
&lt;br /&gt;
The line &amp;lt;code&amp;gt;|1.000000 | 1.000000 | 0.000000 | # [RT Field1] Versor&amp;lt;/code&amp;gt; referees to the direction of the external field (x,y,0). At present only an external field is present but the code can be easily generalized to deal with more fields.&lt;br /&gt;
The default parameters of Yambo/Lumen are already tuned for second-harmonic generation, so the only thing you have to change is the band range, between 3 and 6 and the energy range between 1.0-5.0 eV and the number of energy steps in this interval that we set to 10. Notice that you cannot set to zero the lowest value of the energy range because this will requires a simulation that lasts infinite time, see below. Finally, consider that Yambo performs a separate calculation for each frequency, so if you set many energy steps the computational time grows linearly with this number.&lt;br /&gt;
Notice that we set &amp;lt;code&amp;gt;NLverbosity= &amp;quot;high&amp;quot;&amp;lt;/code&amp;gt; in this way the code will produce a file for each laser frequency containing the time dependent polarization.&lt;br /&gt;
Run &amp;lt;code&amp;gt;yambo_nl&amp;lt;/code&amp;gt;. Calculations will take about fifteen minutes on a single processor PC, you have time to study the next section that explains how non-linear response is extracted from the real-time simulations.&lt;br /&gt;
In order to speed up calculations, you can run them in parallel.&lt;br /&gt;
&lt;br /&gt;
==Non-linear response with Yambo==&lt;br /&gt;
&lt;br /&gt;
In order to calculate the non-linear response, the system is excited with different laser fields with a sinusoidal shape at frequencies &amp;lt;math&amp;gt;\omega_1, \omega_2, .... , \omega_n &amp;lt;/math&amp;gt; determined by the parameters [[Variables#NLEnRangev|NLEnRange]] and [[Variables#NLEnSteps|NLEnSteps]]. A dephasing term is added to the Hamiltonian &amp;lt;math&amp;gt;\gamma = &amp;lt;/math&amp;gt;[[Variables#NLDamping|NLDamping]] to simulate a finite broadening and to remove the eigenmodes that are excited by the sudden turning on of the external field. After the dephasing time the outgoing signal is analyzed to extract the non-linear coefficients as shown in the figure below: &lt;br /&gt;
&lt;br /&gt;
[[File:Pt analysis.png|600px|center|Non-linear response analysis]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the report file &amp;lt;code&amp;gt;r_nlinear&amp;lt;/code&amp;gt; you will find the length of the dephasing part and of the sampling one:&lt;br /&gt;
&lt;br /&gt;
  Dephasing Time          [fs]: 52.65695&lt;br /&gt;
  Sampling  Time          [fs]:  4.18566&lt;br /&gt;
  Total simulation time   [fs]: 56.84262                     &lt;br /&gt;
The length of the dephasing interval is inversely proportional to the damping term &amp;lt;math&amp;gt;T_{depth} \simeq 1/\gamma&amp;lt;/math&amp;gt; while the length of the sampling is dictated by the smallest frequency we are interested in: &amp;lt;math&amp;gt;T_{samp} \simeq 1/\omega_1 &amp;lt;/math&amp;gt;. For this reason if &amp;lt;math&amp;gt; \omega_1=0 &amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt; \gamma = 0 &amp;lt;/math&amp;gt; simulation time goes to infinity. The response at zero frequency can be calculated as limit of small frequency perturbation.&lt;br /&gt;
You can have a look to the file &amp;lt;code&amp;gt;src/nloptics/NL_initialize.F&amp;lt;/code&amp;gt; to see how simulation lengths are defined.&lt;br /&gt;
Calculations can take some time, run them in parallel, the best number of processors = number of frequencies or reduce the number of frequencies step in the SHG.&lt;br /&gt;
&lt;br /&gt;
==Analysis of the results==&lt;br /&gt;
&lt;br /&gt;
In the sampling region we suppose that the polarization can be written as: &amp;lt;math&amp;gt;\bf{P}(t) = \sum_{n=-\infty}^{+\infty} \bf{p}_n e^{-i\omega_n t} &amp;lt;/math&amp;gt; where the coefficient &amp;lt;math&amp;gt;\bf{p}_1,...,\bf{p}_n &amp;lt;/math&amp;gt; are related to &amp;lt;math&amp;gt;\chi^{(1)},...,\chi^{(n)} &amp;lt;/math&amp;gt;. We sample the polarization signal at different times and invert the previous equation by truncating the sum at a finite order &amp;lt;ref&amp;gt;[https://arxiv.org/abs/1309.4012 Nonlinear optics from an ab initio approach by means of the dynamical Berry phase: Application to second- and third-harmonic generation in semiconductors], C. Attaccalite and M. Grüning, Phys. Rev. B 88, 235113(2013)&amp;lt;/ref&amp;gt;.&lt;br /&gt;
This is done with the command &amp;lt;code&amp;gt;ypp_nl -u&amp;lt;/code&amp;gt; that automatically produce an input with the correct values:&lt;br /&gt;
&lt;br /&gt;
 nonlinear                    # [R] NonLinear Optics Post-Processing&lt;br /&gt;
 Xorder=   &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;4  &amp;lt;/span&amp;gt;                 # Max order of the response functions&lt;br /&gt;
 % TimeRange&lt;br /&gt;
  52.65695 | -1.00000 | fs    # Time-window where processing is done&lt;br /&gt;
 % &lt;br /&gt;
 ETStpsRt= 200                # Total Energy steps&lt;br /&gt;
 % EnRngeRt&lt;br /&gt;
   0.00000 | 10.00000 | eV    # Energy range&lt;br /&gt;
 %&lt;br /&gt;
 DampMode= &amp;quot;NONE&amp;quot;             # Damping type ( NONE | LORENTZIAN | GAUSSIAN )&lt;br /&gt;
 DampFactor=  0.10000   eV    # Damping parameter&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;code&amp;gt;Xorder&amp;lt;/code&amp;gt; is the order where the previous sum is truncated, and the TimeRange specifies the sampling region. Notice that differently from the first tutorial, in this case, we do not need Damping in &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; because we already included it in the real-time dynamics. Run &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; and it will produce a file called &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;. This file contains the different components of &amp;lt;math&amp;gt;\chi^2_{xy*} &amp;lt;/math&amp;gt; and in particular the columns 6 and 7 correspond to the imaginary and real part of &amp;lt;math&amp;gt;\chi^2_{xyz} &amp;lt;/math&amp;gt;. You can plot the result with gnuplot and the command:&lt;br /&gt;
&lt;br /&gt;
 p &#039;o.YPP-X_probe_order_2&#039; u 1:(sqrt($6**2+$7**2)) w lp ps 1.5 pt 7 lw 1.5&lt;br /&gt;
&lt;br /&gt;
the result should look like&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AlAs results.png|700px|center|SHG in AlAs]]&lt;br /&gt;
&lt;br /&gt;
and compare it with the &amp;lt;math&amp;gt; \chi^2_{zxy} &amp;lt;/math&amp;gt; calculated with more frequencies and with the converged result on a &amp;lt;math&amp;gt; 18x18x18&amp;lt;/math&amp;gt; k-point grid and bands between 2 and 10. In the figure you can find also the comparison with the results of Ref. &amp;lt;ref&amp;gt;Luppi et al. [https://arxiv.org/abs/1006.2649 PRB B, &#039;&#039;&#039;82&#039;&#039;&#039;, 235201(2010)]&amp;lt;/ref&amp;gt;. &lt;br /&gt;
Notice that the QuantumEspresso results are slightly different from the Abinit ones. This is due to the different pseudo-potential employed in the calculations if pseudopotentials were the same calculation would have been identical. You can download the script to generate this plot and the converged results [http://www.attaccalite.com/lumen/tutorials/AlAs/AlAs_results.tgz here].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notice that&#039;&#039;&#039; : the following parameters are not used in the non-linear response analysis: &amp;lt;code&amp;gt; EnRngeRt&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ETStpsRt&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;DampMode&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;DampFactor&amp;lt;/code&amp;gt;. The damping factor is set directly in the real-time simulation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;System of units in Non-linear Optics&amp;lt;/span&amp;gt;&#039;&#039;&#039;: notice that in Yambo the non-linear response functions are in the gaussian system of units, for example the &amp;lt;math&amp;gt; \chi^2 (\omega) &amp;lt;/math&amp;gt;  is in cm/statvolt. In order to convert the non-linear coefficients between different system of units, you can have a look at the [https://www.attaccalite.com/tutorials_yambo/Appendix_C_Boyd.pdf Appendix C] of the book [https://www.elsevier.com/books/nonlinear-optics/boyd/978-0-12-369470-6 &amp;quot;Non-linear optics&amp;quot;  by Robert W. Boyd].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;More tutorials&amp;lt;/span&amp;gt; on non-linear response (Third harmonic generation, parallelization, spin-orbit etc..) with Yambo can be found here: [http://www.attaccalite.com/lumen/tutorials.html More Tutorials]. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Analysis of the results using YamboPy==&lt;br /&gt;
The analysis of the result performed in the previous section using &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; can be performed using python script [https://github.com/yambo-code/yambopy YamboPy].&amp;lt;br&amp;gt;&lt;br /&gt;
In YamboPy we implemented all necessary functions to reads the Yambo databases and post-process the results. Here we show how to get the SHG signal from the previous &lt;br /&gt;
simulations. We suppose you correctly installed &amp;lt;code&amp;gt;YamboPy&amp;lt;/code&amp;gt; on your PC. Go in the folder where you ran non-linear calculation and type in the python:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
 from yambopy import *&lt;br /&gt;
 NLDB=YamboNLDB()&lt;br /&gt;
 pol =NLDB.Polarization[0]&lt;br /&gt;
 time=NLDB.IO_TIME_points&lt;br /&gt;
&lt;br /&gt;
in this way you read all the Non-linear databases. If your runs are in a different folder then the &#039;SAVE&#039; one you can specify it using the command:&lt;br /&gt;
 NLDB=YamboNLDB(calc=&#039;MYJOB&#039;)&lt;br /&gt;
&lt;br /&gt;
now in the array &amp;lt;code&amp;gt;pol&amp;lt;/code&amp;gt; you have all the polarization for all laser frequencies in the three Cartesian directions, while the variable &amp;lt;code&amp;gt;time&amp;lt;/code&amp;gt; contains all the time series of your simulation.&lt;br /&gt;
Now you can get the non-linear response with the command:&lt;br /&gt;
&lt;br /&gt;
 Harmonic_Analysis(NLDB,X_order=4)&lt;br /&gt;
&lt;br /&gt;
this command will perform a Fourier analysis of the results in the same way of &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; and generate new files with all the requested harmonics &#039;&#039;o.YamboPy-X_probe_order_1&#039;&#039;, &#039;&#039;o.YamboPy-X_probe_order_2&#039;&#039; etc...&lt;br /&gt;
equivalent to the one generated by &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt;. Results can be plot with gnuplot using the command:&lt;br /&gt;
 &lt;br /&gt;
 p &#039;o.YamboPy-X_probe_order_2&#039; u 1:(sqrt($6**2+$7**2)) w lp ps 1.5 pt 7 lw 1.5&lt;br /&gt;
&lt;br /&gt;
The script that performs non-linear analysis can be found in &amp;lt;code&amp;gt;yambopy/nl/harmonic_analysis.py&amp;lt;/code&amp;gt;. &amp;lt;br&amp;gt; We strongly advice you to have a look to this script and modify it according&lt;br /&gt;
to your needs and in order to extract other non-linear response functions.&lt;br /&gt;
&lt;br /&gt;
==How to choose the external field direction for the different X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
In the X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;abc&amp;lt;/sub&amp;gt; response you have three field directions. The two components &#039;&#039;b&#039;&#039; and &#039;&#039;c&#039;&#039; are determined by the external field and the third &#039;&#039;a&#039;&#039;&lt;br /&gt;
is the direction where you measure the response.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The external field in Yambo is set using the variable&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
   1.000000 | 0.000000 | 0.000000 |        # [NL ExtF] Versor .&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
For example if you set in Yambo field direction as:&lt;br /&gt;
&lt;br /&gt;
 1.0 | 0.0 | 0.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*xx&amp;lt;/sub&amp;gt;&lt;br /&gt;
 0.0 | 1.0 | 0.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*yy&amp;lt;/sub&amp;gt;&lt;br /&gt;
 0.0 | 0.0 | 1.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*zz&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the * correspond to the different direction in the response file &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;.&lt;br /&gt;
In the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt; you have seven columns:&lt;br /&gt;
&lt;br /&gt;
 The first column is the energy [[omega]],&lt;br /&gt;
 the 2nd and 3rd columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;x**&amp;lt;/sub&amp;gt;&lt;br /&gt;
 the 4th and 5th columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;y**&amp;lt;/sub&amp;gt;&lt;br /&gt;
 the 6th and 7th columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;z**&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where the ** are the direction of the incoming field, see above.&lt;br /&gt;
&lt;br /&gt;
For example if you want to calculate the &amp;lt;math&amp;gt;\chi^{(2)}_{zxx}&amp;lt;/math&amp;gt; you put the external field in the direction &amp;lt;code&amp;gt; 1.0 | 0.0 | 0.0 |&amp;lt;/code&amp;gt;&lt;br /&gt;
and then plot the column 6 and 7 of the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt; file.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to get the other components of the  X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; the calculation are more involved. For example if you put field in the&lt;br /&gt;
&lt;br /&gt;
 1.0 | 1.0 | 0.0 | &lt;br /&gt;
&lt;br /&gt;
this corresponds to &amp;lt;math&amp;gt;E(t)=\frac{1}{\sqrt{2}} [ E_x(t) + E_y(t) ]&amp;lt;/math&amp;gt; and so at the second order you will have &amp;lt;math&amp;gt;E^2(t)=\frac{1}{2} \left [ E^2_x(t) + E^2_y(t) +  E_x(t) E_y(t) +  E_y(t) E_x(t) \right]&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
this means that  the X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; in the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;  will correspond to a linear combination of the following different response functions.&amp;lt;br&amp;gt;&lt;br /&gt;
For example in the the 2nd and 3rd columns are the imaginary and real part of:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{x**}=\frac{1}{2} \left [\chi^2_{xxx}+\chi^{(2)}_{xyy} + \chi^{(2)}_{xxy} + \chi^{(2)}_{xyx} \right ]&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the same for the other column replacing the first &amp;lt;code&amp;gt;x&amp;lt;/code&amp;gt; for &amp;lt;code&amp;gt;y,z&amp;lt;/code&amp;gt;.&lt;br /&gt;
If you know that some components are zero this allow you to extract the corresponding off-diagonal part of &amp;lt;math&amp;gt;\chi^{(2)}_{abc}&amp;lt;/math&amp;gt; otherwise you have to perform different calculations to get the component you are interested in. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Now we present &#039;&#039;&#039;a simple example of monolayer hBN (m-hBN)&#039;&#039;&#039;. &amp;lt;br&amp;gt; In m-hBN there is only a non-zero component of the $\chi^2$ and all the others are related by symmetry:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{yyy}=-\chi^{(2)}_{yxx}=-\chi^{(2)}_{xxy}=-\chi^{(2)}_{xyx}&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
so if you put the field in the &amp;lt;code&amp;gt;|1|1|0|&amp;lt;/code&amp;gt; direction you will get:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{x**} = \frac{1}{2} \left[\chi^{(2)}_{xxy} + \chi^{(2)}_{xyx} \right] = - \chi^{(2)}_{yyy} &amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{y**} =\frac{1}{2} \left[ \chi^{(2)}_{yyy} + \chi^{(2)}_{yxx}  \right] = 0.0 &amp;lt;/math&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
In the figure below you can see the different $\chi^{(2)}$ of monolayer hBN. &lt;br /&gt;
&lt;br /&gt;
[[File:Xhi2 xy.png|center| 800px|xhi2_xy]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Nota bene:&#039;&#039;&#039; if you change the direction of the external field you have to remove the corresponding symmetries as explained in the tutorial [[Prerequisites for Real Time_propagation with Yambo#Reduce symmetries real-time linear response tutorial]].&lt;br /&gt;
&lt;br /&gt;
==Non-linear response of low-dimensional structures: 2D or 1D ==&lt;br /&gt;
&lt;br /&gt;
The Yambo code is a 3D periodic code, so when you want to study a low-dimensional system 2D or 1D, you have to use a supercell approach.&lt;br /&gt;
For example to simulate the non-linear response in a 2D-crystal one, can put the crystal in the xy plane and choose a larger distance in the z-direction&lt;br /&gt;
in order to reduce the interaction between the periodic replica. Clearly in this case k-point sampling will be only in the x,y directions.&lt;br /&gt;
For calculations on this type of systems, these two warnings must be taken into account:&lt;br /&gt;
&lt;br /&gt;
* if you calculate GW corrections or include electron-hole interaction in the linear/non-linear response it is a good idea to use a &#039;&#039;&#039;Coulomb cutoff&#039;&#039;&#039;, similar to the 2D BSE case  [http://www.yambo-code.org/wiki/index.php?title=How_to_treat_low_dimensional_systems How to treat low dimensional systems]. You can add the cutoff just adding the &amp;quot;-r&amp;quot; in the input generation.&lt;br /&gt;
&lt;br /&gt;
* the calculation of SHG and THG are always performed respect to the supercell, therefore you have to &#039;&#039;&#039;re-scale&#039;&#039;&#039; the result to the effective thickness of the layer, usually the inter-layer distance of the corresponding bulk material for 2D systems: &amp;lt;math&amp;gt;\chi_{rescaled}(\omega) = L_z/d_{eff} \cdot \chi(\omega) &amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;L_z&amp;lt;/math&amp;gt; is the z-dimension of the supercell, and &amp;lt;math&amp;gt;d_{eff}&amp;lt;/math&amp;gt; is the effective thickness of the 2D system.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Nota bene&#039;&#039;&#039;: Non-linear response along &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;non-periodic directions&amp;lt;/span&amp;gt; is not implemented in Yambo, the code will print zero in these directions for all response functions. We plan to implement it in a future version of the code.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Links for schools==&lt;br /&gt;
* Back to [[Rome 2023#Tutorials]]&lt;br /&gt;
* Back to [[ICTP2020]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
{| style=&amp;quot;width:100%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|style=&amp;quot;width:25%; text-align:left&amp;quot;|Prev: [[Linear response from real time simulations|Linear response from real time simulations]]&lt;br /&gt;
|style=&amp;quot;width:45%; text-align:center&amp;quot;|Now: [[ICTP2020|ICTP  Tutorials]] --&amp;gt; [[Real time approach to non-linear response|Non Linear Response]] &lt;br /&gt;
|style=&amp;quot;width:50%; text-align:left&amp;quot;|Next: [[Correlation effects in the non-linear response|Correlation effects in the non-linear response ]]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Attacc</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Real_time_approach_to_non-linear_response_(SHG)&amp;diff=9159</id>
		<title>Real time approach to non-linear response (SHG)</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Real_time_approach_to_non-linear_response_(SHG)&amp;diff=9159"/>
		<updated>2025-09-28T07:50:22Z</updated>

		<summary type="html">&lt;p&gt;Attacc: /* How to choose the external field direction for the different X2 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Second Harmonic Generation in AlAs ==&lt;br /&gt;
In this tutorial, we will calculate the second harmonic generation of bulk AlAs, the Yambo databases can be downloaded here: [https://media.yambo-code.eu/educational/tutorials/files/AlAs_DBs.tar.gz AlAs_DBs.tar.gz] (10 MB). The first steps of this tutorials are the same as the one on [http://www.yambo-code.eu/wiki/index.php?title=Prerequisites_for_Real_Time_propagation_with_Yambo Prerequisites for Real-Time propagation with Yambo] with the only difference that we will work on AlAs and we will consider an external field in the direction &amp;lt;code&amp;gt; 1.000000 | 1.000000 | 0.000000 |&amp;lt;/code&amp;gt;. The DFT input are available here: [https://media.yambo-code.eu/educational/tutorials/files/AlAs_abinit.tar.gz ABINIT] or [https://media.yambo-code.eu/educational/tutorials/files/AlAs_pwscf.tar.gz QuantumEspresso].&lt;br /&gt;
You can run the DFT calculation with ABINIT with the command:&lt;br /&gt;
&lt;br /&gt;
 abinit &amp;lt; AlAs.in &amp;gt; output_AlAs                                             &lt;br /&gt;
&lt;br /&gt;
or using QuantumEspresso:&lt;br /&gt;
&lt;br /&gt;
 pw.x -inp AlAs.scf.in &amp;gt; output_scf&lt;br /&gt;
 pw.x -inp AlAs.nscf.in &amp;gt; output_scf                            &lt;br /&gt;
&lt;br /&gt;
and then import the ABINIT wave-function with the command:&lt;br /&gt;
&lt;br /&gt;
 a2y -F AlAso_DS2_WFK.nc                            &lt;br /&gt;
&lt;br /&gt;
and the QuantumEspresso one, in the folder AlAs.save with the command:&lt;br /&gt;
&lt;br /&gt;
 p2y                              &lt;br /&gt;
Now we consider an external field in the &amp;lt;code&amp;gt;[1,1,0]&amp;lt;/code&amp;gt; direction and remove symmetries not compatible with this field, as explained in the tutorial [http://www.yambo-code.eu/wiki/index.php?title=Prerequisites_for_Real_Time_propagation_with_Yambo Prerequisites for Real-Time propagation with Yambo].&lt;br /&gt;
&lt;br /&gt;
==Real-time simulation for the SHG==&lt;br /&gt;
&lt;br /&gt;
You can generate the input file with the command &amp;lt;code&amp;gt;yambo_nl -u n&amp;lt;/code&amp;gt;:&lt;br /&gt;
                       &lt;br /&gt;
 nloptics                      # [R NL] Non-linear optics&lt;br /&gt;
 % NLBands&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 3 | 6&amp;lt;/span&amp;gt; |                   # [NL] Bands&lt;br /&gt;
 %&lt;br /&gt;
 NLstep=   0.0100       fs    # [NL] Real Time step length&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;NLverbosity= &amp;quot;high&amp;quot;&amp;lt;/span&amp;gt;               # [NL] Verbosity level (low | high)&lt;br /&gt;
 NLtime=-1.000000           fs    # [NL] Simulation Time&lt;br /&gt;
 NLintegrator= &amp;quot;INVINT&amp;quot;       # [NL] Integrator (&amp;quot;EULEREXP/RK4/RK2EXP/HEUN/INVINT/CRANKNIC&amp;quot;)&lt;br /&gt;
 NLCorrelation= &amp;quot;IPA&amp;quot;         # [NL] Correlation (&amp;quot;IPA/HARTREE/TDDFT/LRC/JGM/SEX/HF&amp;quot;)&lt;br /&gt;
 NLLrcAlpha= 0.000000         # [NL] Long Range Correction&lt;br /&gt;
 % NLEnRange&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;  1.000000 | 5.000000 &amp;lt;/span&amp;gt;| eV    # [NL] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 NLEnSteps= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 5  &amp;lt;/span&amp;gt;              # [NL] Energy steps&lt;br /&gt;
 NLDamping= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 0.150000  &amp;lt;/span&amp;gt;  eV    # [NL] Damping&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 1.000000 | 1.000000 | 0.000000 &amp;lt;/span&amp;gt;|        # [RT Field1] Versor&lt;br /&gt;
 Field1_kind= &amp;quot;SOFTSIN&amp;quot;         # [NL ExtF] Kind(SIN|SOFTSIN|RES|ANTIRES|GAUSS|DELTA|QSSIN)&lt;br /&gt;
&lt;br /&gt;
The line &amp;lt;code&amp;gt;|1.000000 | 1.000000 | 0.000000 | # [RT Field1] Versor&amp;lt;/code&amp;gt; referees to the direction of the external field (x,y,0). At present only an external field is present but the code can be easily generalized to deal with more fields.&lt;br /&gt;
The default parameters of Yambo/Lumen are already tuned for second-harmonic generation, so the only thing you have to change is the band range, between 3 and 6 and the energy range between 1.0-5.0 eV and the number of energy steps in this interval that we set to 10. Notice that you cannot set to zero the lowest value of the energy range because this will requires a simulation that lasts infinite time, see below. Finally, consider that Yambo performs a separate calculation for each frequency, so if you set many energy steps the computational time grows linearly with this number.&lt;br /&gt;
Notice that we set &amp;lt;code&amp;gt;NLverbosity= &amp;quot;high&amp;quot;&amp;lt;/code&amp;gt; in this way the code will produce a file for each laser frequency containing the time dependent polarization.&lt;br /&gt;
Run &amp;lt;code&amp;gt;yambo_nl&amp;lt;/code&amp;gt;. Calculations will take about fifteen minutes on a single processor PC, you have time to study the next section that explains how non-linear response is extracted from the real-time simulations.&lt;br /&gt;
In order to speed up calculations, you can run them in parallel.&lt;br /&gt;
&lt;br /&gt;
==Non-linear response with Yambo==&lt;br /&gt;
&lt;br /&gt;
In order to calculate the non-linear response, the system is excited with different laser fields with a sinusoidal shape at frequencies &amp;lt;math&amp;gt;\omega_1, \omega_2, .... , \omega_n &amp;lt;/math&amp;gt; determined by the parameters [[Variables#NLEnRangev|NLEnRange]] and [[Variables#NLEnSteps|NLEnSteps]]. A dephasing term is added to the Hamiltonian &amp;lt;math&amp;gt;\gamma = &amp;lt;/math&amp;gt;[[Variables#NLDamping|NLDamping]] to simulate a finite broadening and to remove the eigenmodes that are excited by the sudden turning on of the external field. After the dephasing time the outgoing signal is analyzed to extract the non-linear coefficients as shown in the figure below: &lt;br /&gt;
&lt;br /&gt;
[[File:Pt analysis.png|600px|center|Non-linear response analysis]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the report file &amp;lt;code&amp;gt;r_nlinear&amp;lt;/code&amp;gt; you will find the length of the dephasing part and of the sampling one:&lt;br /&gt;
&lt;br /&gt;
  Dephasing Time          [fs]: 52.65695&lt;br /&gt;
  Sampling  Time          [fs]:  4.18566&lt;br /&gt;
  Total simulation time   [fs]: 56.84262                     &lt;br /&gt;
The length of the dephasing interval is inversely proportional to the damping term &amp;lt;math&amp;gt;T_{depth} \simeq 1/\gamma&amp;lt;/math&amp;gt; while the length of the sampling is dictated by the smallest frequency we are interested in: &amp;lt;math&amp;gt;T_{samp} \simeq 1/\omega_1 &amp;lt;/math&amp;gt;. For this reason if &amp;lt;math&amp;gt; \omega_1=0 &amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt; \gamma = 0 &amp;lt;/math&amp;gt; simulation time goes to infinity. The response at zero frequency can be calculated as limit of small frequency perturbation.&lt;br /&gt;
You can have a look to the file &amp;lt;code&amp;gt;src/nloptics/NL_initialize.F&amp;lt;/code&amp;gt; to see how simulation lengths are defined.&lt;br /&gt;
Calculations can take some time, run them in parallel, the best number of processors = number of frequencies or reduce the number of frequencies step in the SHG.&lt;br /&gt;
&lt;br /&gt;
==Analysis of the results==&lt;br /&gt;
&lt;br /&gt;
In the sampling region we suppose that the polarization can be written as: &amp;lt;math&amp;gt;\bf{P}(t) = \sum_{n=-\infty}^{+\infty} \bf{p}_n e^{-i\omega_n t} &amp;lt;/math&amp;gt; where the coefficient &amp;lt;math&amp;gt;\bf{p}_1,...,\bf{p}_n &amp;lt;/math&amp;gt; are related to &amp;lt;math&amp;gt;\chi^{(1)},...,\chi^{(n)} &amp;lt;/math&amp;gt;. We sample the polarization signal at different times and invert the previous equation by truncating the sum at a finite order &amp;lt;ref&amp;gt;[https://arxiv.org/abs/1309.4012 Nonlinear optics from an ab initio approach by means of the dynamical Berry phase: Application to second- and third-harmonic generation in semiconductors], C. Attaccalite and M. Grüning, Phys. Rev. B 88, 235113(2013)&amp;lt;/ref&amp;gt;.&lt;br /&gt;
This is done with the command &amp;lt;code&amp;gt;ypp_nl -u&amp;lt;/code&amp;gt; that automatically produce an input with the correct values:&lt;br /&gt;
&lt;br /&gt;
 nonlinear                    # [R] NonLinear Optics Post-Processing&lt;br /&gt;
 Xorder=   &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;4  &amp;lt;/span&amp;gt;                 # Max order of the response functions&lt;br /&gt;
 % TimeRange&lt;br /&gt;
  52.65695 | -1.00000 | fs    # Time-window where processing is done&lt;br /&gt;
 % &lt;br /&gt;
 ETStpsRt= 200                # Total Energy steps&lt;br /&gt;
 % EnRngeRt&lt;br /&gt;
   0.00000 | 10.00000 | eV    # Energy range&lt;br /&gt;
 %&lt;br /&gt;
 DampMode= &amp;quot;NONE&amp;quot;             # Damping type ( NONE | LORENTZIAN | GAUSSIAN )&lt;br /&gt;
 DampFactor=  0.10000   eV    # Damping parameter&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;code&amp;gt;Xorder&amp;lt;/code&amp;gt; is the order where the previous sum is truncated, and the TimeRange specifies the sampling region. Notice that differently from the first tutorial, in this case, we do not need Damping in &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; because we already included it in the real-time dynamics. Run &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; and it will produce a file called &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;. This file contains the different components of &amp;lt;math&amp;gt;\chi^2_{xy*} &amp;lt;/math&amp;gt; and in particular the columns 6 and 7 correspond to the imaginary and real part of &amp;lt;math&amp;gt;\chi^2_{xyz} &amp;lt;/math&amp;gt;. You can plot the result with gnuplot and the command:&lt;br /&gt;
&lt;br /&gt;
 p &#039;o.YPP-X_probe_order_2&#039; u 1:(sqrt($6**2+$7**2)) w lp ps 1.5 pt 7 lw 1.5&lt;br /&gt;
&lt;br /&gt;
the result should look like&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AlAs results.png|700px|center|SHG in AlAs]]&lt;br /&gt;
&lt;br /&gt;
and compare it with the &amp;lt;math&amp;gt; \chi^2_{zxy} &amp;lt;/math&amp;gt; calculated with more frequencies and with the converged result on a &amp;lt;math&amp;gt; 18x18x18&amp;lt;/math&amp;gt; k-point grid and bands between 2 and 10. In the figure you can find also the comparison with the results of Ref. &amp;lt;ref&amp;gt;Luppi et al. [https://arxiv.org/abs/1006.2649 PRB B, &#039;&#039;&#039;82&#039;&#039;&#039;, 235201(2010)]&amp;lt;/ref&amp;gt;. &lt;br /&gt;
Notice that the QuantumEspresso results are slightly different from the Abinit ones. This is due to the different pseudo-potential employed in the calculations if pseudopotentials were the same calculation would have been identical. You can download the script to generate this plot and the converged results [http://www.attaccalite.com/lumen/tutorials/AlAs/AlAs_results.tgz here].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notice that&#039;&#039;&#039; : the following parameters are not used in the non-linear response analysis: &amp;lt;code&amp;gt; EnRngeRt&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ETStpsRt&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;DampMode&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;DampFactor&amp;lt;/code&amp;gt;. The damping factor is set directly in the real-time simulation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;System of units in Non-linear Optics&amp;lt;/span&amp;gt;&#039;&#039;&#039;: notice that in Yambo the non-linear response functions are in the gaussian system of units, for example the &amp;lt;math&amp;gt; \chi^2 (\omega) &amp;lt;/math&amp;gt;  is in cm/statvolt. In order to convert the non-linear coefficients between different system of units, you can have a look at the [https://www.attaccalite.com/tutorials_yambo/Appendix_C_Boyd.pdf Appendix C] of the book [https://www.elsevier.com/books/nonlinear-optics/boyd/978-0-12-369470-6 &amp;quot;Non-linear optics&amp;quot;  by Robert W. Boyd].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;More tutorials&amp;lt;/span&amp;gt; on non-linear response (Third harmonic generation, parallelization, spin-orbit etc..) with Yambo can be found here: [http://www.attaccalite.com/lumen/tutorials.html More Tutorials]. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Analysis of the results using YamboPy==&lt;br /&gt;
The analysis of the result performed in the previous section using &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; can be performed using python script [https://github.com/yambo-code/yambopy YamboPy].&amp;lt;br&amp;gt;&lt;br /&gt;
In YamboPy we implemented all necessary functions to reads the Yambo databases and post-process the results. Here we show how to get the SHG signal from the previous &lt;br /&gt;
simulations. We suppose you correctly installed &amp;lt;code&amp;gt;YamboPy&amp;lt;/code&amp;gt; on your PC. Go in the folder where you ran non-linear calculation and type in the python:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
 from yambopy import *&lt;br /&gt;
 NLDB=YamboNLDB()&lt;br /&gt;
 pol =NLDB.Polarization[0]&lt;br /&gt;
 time=NLDB.IO_TIME_points&lt;br /&gt;
&lt;br /&gt;
in this way you read all the Non-linear databases. If your runs are in a different folder then the &#039;SAVE&#039; one you can specify it using the command:&lt;br /&gt;
 NLDB=YamboNLDB(calc=&#039;MYJOB&#039;)&lt;br /&gt;
&lt;br /&gt;
now in the array &amp;lt;code&amp;gt;pol&amp;lt;/code&amp;gt; you have all the polarization for all laser frequencies in the three Cartesian directions, while the variable &amp;lt;code&amp;gt;time&amp;lt;/code&amp;gt; contains all the time series of your simulation.&lt;br /&gt;
Now you can get the non-linear response with the command:&lt;br /&gt;
&lt;br /&gt;
 Harmonic_Analysis(NLDB,X_order=4)&lt;br /&gt;
&lt;br /&gt;
this command will perform a Fourier analysis of the results in the same way of &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; and generate new files with all the requested harmonics &#039;&#039;o.YamboPy-X_probe_order_1&#039;&#039;, &#039;&#039;o.YamboPy-X_probe_order_2&#039;&#039; etc...&lt;br /&gt;
equivalent to the one generated by &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt;. Results can be plot with gnuplot using the command:&lt;br /&gt;
 &lt;br /&gt;
 p &#039;o.YamboPy-X_probe_order_2&#039; u 1:(sqrt($6**2+$7**2)) w lp ps 1.5 pt 7 lw 1.5&lt;br /&gt;
&lt;br /&gt;
The script that performs non-linear analysis can be found in &amp;lt;code&amp;gt;yambopy/nl/harmonic_analysis.py&amp;lt;/code&amp;gt;. &amp;lt;br&amp;gt; We strongly advice you to have a look to this script and modify it according&lt;br /&gt;
to your needs and in order to extract other non-linear response functions.&lt;br /&gt;
&lt;br /&gt;
==How to choose the external field direction for the different X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
In the X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;abc&amp;lt;/sub&amp;gt; response you have three field directions. The two components &#039;&#039;b&#039;&#039; and &#039;&#039;c&#039;&#039; are determined by the external field and the third &#039;&#039;a&#039;&#039;&lt;br /&gt;
is the direction where you measure the response.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The external field in Yambo is set using the variable&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
   1.000000 | 0.000000 | 0.000000 |        # [NL ExtF] Versor .&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
For example if you set in Yambo field direction as:&lt;br /&gt;
&lt;br /&gt;
 1.0 | 0.0 | 0.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*xx&amp;lt;/sub&amp;gt;&lt;br /&gt;
 0.0 | 1.0 | 0.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*yy&amp;lt;/sub&amp;gt;&lt;br /&gt;
 0.0 | 0.0 | 1.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*zz&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the * correspond to the different direction in the response file &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;.&lt;br /&gt;
In the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt; you have seven columns:&lt;br /&gt;
&lt;br /&gt;
 The first column is the energy [[omega]],&lt;br /&gt;
 the 2nd and 3rd columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;x**&amp;lt;/sub&amp;gt;&lt;br /&gt;
 the 4th and 5th columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;y**&amp;lt;/sub&amp;gt;&lt;br /&gt;
 the 6th and 7th columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;z**&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where the ** are the direction of the incoming field, see above.&lt;br /&gt;
&lt;br /&gt;
For example if you want to calculate the &amp;lt;math&amp;gt;\chi^{(2)}_{zxx}&amp;lt;/math&amp;gt; you put the external field in the direction &amp;lt;code&amp;gt; 1.0 | 0.0 | 0.0 |&amp;lt;/code&amp;gt;&lt;br /&gt;
and then plot the column 6 and 7 of the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt; file.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to get the other components of the  X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; the calculation are more involved. For example if you put field in the&lt;br /&gt;
&lt;br /&gt;
 1.0 | 1.0 | 0.0 | &lt;br /&gt;
&lt;br /&gt;
this corresponds to &amp;lt;math&amp;gt;E(t)=\frac{1}{\sqrt{2}} [ E_x(t) + E_y(t) ]&amp;lt;/math&amp;gt; and so at the second order you will have &amp;lt;math&amp;gt;E^2(t)=\frac{1}{2} \left [ E^2_x(t) + E^2_y(t) +  E_x(t) E_y(t) +  E_y(t) E_x(t) \right]&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
this means that  the X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; in the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;  will correspond to a linear combination of the following different response functions.&amp;lt;br&amp;gt;&lt;br /&gt;
For example in the the 2nd and 3rd columns are the imaginary and real part of:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{x**}=\frac{1}{2} \left [\chi^2_{xxx}+\chi^{(2)}_{xyy} + \chi^{(2)}_{xxy} + \chi^{(2)}_{xyx} \right ]&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the same for the other column replacing the first &amp;lt;code&amp;gt;x&amp;lt;/code&amp;gt; for &amp;lt;code&amp;gt;y,z&amp;lt;/code&amp;gt;.&lt;br /&gt;
If you know that some components are zero this allow you to extract the corresponding off-diagonal part of &amp;lt;math&amp;gt;\chi^{(2)}_{abc}&amp;lt;/math&amp;gt; otherwise you have to perform different calculations to get the component you are interested in. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Now we present &#039;&#039;&#039;a simple example of monolayer hBN (m-hBN)&#039;&#039;&#039;. &amp;lt;br&amp;gt; In m-hBN there is only a non-zero component of the $\chi^2$ and all the others are related by symmetry:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{yyy}=-\chi^{(2)}_{yxx}=-\chi^{(2)}_{xxy}=-\chi^{(2)}_{xyx}&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
so if you put the field in the &amp;lt;code&amp;gt;|1|1|0|&amp;lt;/code&amp;gt; direction you will get:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{x**} = \frac{1}{2} \left[\chi^{(2)}_{xxy} + \chi^{(2)}_{xyx} \right] = - \chi^{(2)}_{yyy} &amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{y**} =\frac{1}{2} \left[ \chi^{(2)}_{yyy} + \chi^{(2)}_{yxx}  \right] = 0.0 &amp;lt;/math&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
In the figure below you can see the different $\chi^{(2)}$ of monolayer hBN. &lt;br /&gt;
&lt;br /&gt;
[[File:Xhi2 xy.png|center| 300px|xhi2_xy]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Nota bene:&#039;&#039;&#039; if you change the direction of the external field you have to remove the corresponding symmetries as explained in the tutorial [[Prerequisites for Real Time_propagation with Yambo#Reduce symmetries real-time linear response tutorial]].&lt;br /&gt;
&lt;br /&gt;
==Non-linear response of low-dimensional structures: 2D or 1D ==&lt;br /&gt;
&lt;br /&gt;
The Yambo code is a 3D periodic code, so when you want to study a low-dimensional system 2D or 1D, you have to use a supercell approach.&lt;br /&gt;
For example to simulate the non-linear response in a 2D-crystal one, can put the crystal in the xy plane and choose a larger distance in the z-direction&lt;br /&gt;
in order to reduce the interaction between the periodic replica. Clearly in this case k-point sampling will be only in the x,y directions.&lt;br /&gt;
For calculations on this type of systems, these two warnings must be taken into account:&lt;br /&gt;
&lt;br /&gt;
* if you calculate GW corrections or include electron-hole interaction in the linear/non-linear response it is a good idea to use a &#039;&#039;&#039;Coulomb cutoff&#039;&#039;&#039;, similar to the 2D BSE case  [http://www.yambo-code.org/wiki/index.php?title=How_to_treat_low_dimensional_systems How to treat low dimensional systems]. You can add the cutoff just adding the &amp;quot;-r&amp;quot; in the input generation.&lt;br /&gt;
&lt;br /&gt;
* the calculation of SHG and THG are always performed respect to the supercell, therefore you have to &#039;&#039;&#039;re-scale&#039;&#039;&#039; the result to the effective thickness of the layer, usually the inter-layer distance of the corresponding bulk material for 2D systems: &amp;lt;math&amp;gt;\chi_{rescaled}(\omega) = L_z/d_{eff} \cdot \chi(\omega) &amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;L_z&amp;lt;/math&amp;gt; is the z-dimension of the supercell, and &amp;lt;math&amp;gt;d_{eff}&amp;lt;/math&amp;gt; is the effective thickness of the 2D system.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Nota bene&#039;&#039;&#039;: Non-linear response along &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;non-periodic directions&amp;lt;/span&amp;gt; is not implemented in Yambo, the code will print zero in these directions for all response functions. We plan to implement it in a future version of the code.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Links for schools==&lt;br /&gt;
* Back to [[Rome 2023#Tutorials]]&lt;br /&gt;
* Back to [[ICTP2020]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
{| style=&amp;quot;width:100%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|style=&amp;quot;width:25%; text-align:left&amp;quot;|Prev: [[Linear response from real time simulations|Linear response from real time simulations]]&lt;br /&gt;
|style=&amp;quot;width:45%; text-align:center&amp;quot;|Now: [[ICTP2020|ICTP  Tutorials]] --&amp;gt; [[Real time approach to non-linear response|Non Linear Response]] &lt;br /&gt;
|style=&amp;quot;width:50%; text-align:left&amp;quot;|Next: [[Correlation effects in the non-linear response|Correlation effects in the non-linear response ]]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Attacc</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=File:Xhi2_xy.png&amp;diff=9158</id>
		<title>File:Xhi2 xy.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=File:Xhi2_xy.png&amp;diff=9158"/>
		<updated>2025-09-28T07:49:20Z</updated>

		<summary type="html">&lt;p&gt;Attacc: 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=xhi2_xy}}&lt;br /&gt;
|date=2025-09-28&lt;br /&gt;
|source={{own}}&lt;br /&gt;
|author=[[User:Attacc|Attacc]]&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>Attacc</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Real_time_approach_to_non-linear_response_(SHG)&amp;diff=9157</id>
		<title>Real time approach to non-linear response (SHG)</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Real_time_approach_to_non-linear_response_(SHG)&amp;diff=9157"/>
		<updated>2025-09-27T10:23:35Z</updated>

		<summary type="html">&lt;p&gt;Attacc: /* How to choose the external field direction for the different X2 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Second Harmonic Generation in AlAs ==&lt;br /&gt;
In this tutorial, we will calculate the second harmonic generation of bulk AlAs, the Yambo databases can be downloaded here: [https://media.yambo-code.eu/educational/tutorials/files/AlAs_DBs.tar.gz AlAs_DBs.tar.gz] (10 MB). The first steps of this tutorials are the same as the one on [http://www.yambo-code.eu/wiki/index.php?title=Prerequisites_for_Real_Time_propagation_with_Yambo Prerequisites for Real-Time propagation with Yambo] with the only difference that we will work on AlAs and we will consider an external field in the direction &amp;lt;code&amp;gt; 1.000000 | 1.000000 | 0.000000 |&amp;lt;/code&amp;gt;. The DFT input are available here: [https://media.yambo-code.eu/educational/tutorials/files/AlAs_abinit.tar.gz ABINIT] or [https://media.yambo-code.eu/educational/tutorials/files/AlAs_pwscf.tar.gz QuantumEspresso].&lt;br /&gt;
You can run the DFT calculation with ABINIT with the command:&lt;br /&gt;
&lt;br /&gt;
 abinit &amp;lt; AlAs.in &amp;gt; output_AlAs                                             &lt;br /&gt;
&lt;br /&gt;
or using QuantumEspresso:&lt;br /&gt;
&lt;br /&gt;
 pw.x -inp AlAs.scf.in &amp;gt; output_scf&lt;br /&gt;
 pw.x -inp AlAs.nscf.in &amp;gt; output_scf                            &lt;br /&gt;
&lt;br /&gt;
and then import the ABINIT wave-function with the command:&lt;br /&gt;
&lt;br /&gt;
 a2y -F AlAso_DS2_WFK.nc                            &lt;br /&gt;
&lt;br /&gt;
and the QuantumEspresso one, in the folder AlAs.save with the command:&lt;br /&gt;
&lt;br /&gt;
 p2y                              &lt;br /&gt;
Now we consider an external field in the &amp;lt;code&amp;gt;[1,1,0]&amp;lt;/code&amp;gt; direction and remove symmetries not compatible with this field, as explained in the tutorial [http://www.yambo-code.eu/wiki/index.php?title=Prerequisites_for_Real_Time_propagation_with_Yambo Prerequisites for Real-Time propagation with Yambo].&lt;br /&gt;
&lt;br /&gt;
==Real-time simulation for the SHG==&lt;br /&gt;
&lt;br /&gt;
You can generate the input file with the command &amp;lt;code&amp;gt;yambo_nl -u n&amp;lt;/code&amp;gt;:&lt;br /&gt;
                       &lt;br /&gt;
 nloptics                      # [R NL] Non-linear optics&lt;br /&gt;
 % NLBands&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 3 | 6&amp;lt;/span&amp;gt; |                   # [NL] Bands&lt;br /&gt;
 %&lt;br /&gt;
 NLstep=   0.0100       fs    # [NL] Real Time step length&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;NLverbosity= &amp;quot;high&amp;quot;&amp;lt;/span&amp;gt;               # [NL] Verbosity level (low | high)&lt;br /&gt;
 NLtime=-1.000000           fs    # [NL] Simulation Time&lt;br /&gt;
 NLintegrator= &amp;quot;INVINT&amp;quot;       # [NL] Integrator (&amp;quot;EULEREXP/RK4/RK2EXP/HEUN/INVINT/CRANKNIC&amp;quot;)&lt;br /&gt;
 NLCorrelation= &amp;quot;IPA&amp;quot;         # [NL] Correlation (&amp;quot;IPA/HARTREE/TDDFT/LRC/JGM/SEX/HF&amp;quot;)&lt;br /&gt;
 NLLrcAlpha= 0.000000         # [NL] Long Range Correction&lt;br /&gt;
 % NLEnRange&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;  1.000000 | 5.000000 &amp;lt;/span&amp;gt;| eV    # [NL] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 NLEnSteps= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 5  &amp;lt;/span&amp;gt;              # [NL] Energy steps&lt;br /&gt;
 NLDamping= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 0.150000  &amp;lt;/span&amp;gt;  eV    # [NL] Damping&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 1.000000 | 1.000000 | 0.000000 &amp;lt;/span&amp;gt;|        # [RT Field1] Versor&lt;br /&gt;
 Field1_kind= &amp;quot;SOFTSIN&amp;quot;         # [NL ExtF] Kind(SIN|SOFTSIN|RES|ANTIRES|GAUSS|DELTA|QSSIN)&lt;br /&gt;
&lt;br /&gt;
The line &amp;lt;code&amp;gt;|1.000000 | 1.000000 | 0.000000 | # [RT Field1] Versor&amp;lt;/code&amp;gt; referees to the direction of the external field (x,y,0). At present only an external field is present but the code can be easily generalized to deal with more fields.&lt;br /&gt;
The default parameters of Yambo/Lumen are already tuned for second-harmonic generation, so the only thing you have to change is the band range, between 3 and 6 and the energy range between 1.0-5.0 eV and the number of energy steps in this interval that we set to 10. Notice that you cannot set to zero the lowest value of the energy range because this will requires a simulation that lasts infinite time, see below. Finally, consider that Yambo performs a separate calculation for each frequency, so if you set many energy steps the computational time grows linearly with this number.&lt;br /&gt;
Notice that we set &amp;lt;code&amp;gt;NLverbosity= &amp;quot;high&amp;quot;&amp;lt;/code&amp;gt; in this way the code will produce a file for each laser frequency containing the time dependent polarization.&lt;br /&gt;
Run &amp;lt;code&amp;gt;yambo_nl&amp;lt;/code&amp;gt;. Calculations will take about fifteen minutes on a single processor PC, you have time to study the next section that explains how non-linear response is extracted from the real-time simulations.&lt;br /&gt;
In order to speed up calculations, you can run them in parallel.&lt;br /&gt;
&lt;br /&gt;
==Non-linear response with Yambo==&lt;br /&gt;
&lt;br /&gt;
In order to calculate the non-linear response, the system is excited with different laser fields with a sinusoidal shape at frequencies &amp;lt;math&amp;gt;\omega_1, \omega_2, .... , \omega_n &amp;lt;/math&amp;gt; determined by the parameters [[Variables#NLEnRangev|NLEnRange]] and [[Variables#NLEnSteps|NLEnSteps]]. A dephasing term is added to the Hamiltonian &amp;lt;math&amp;gt;\gamma = &amp;lt;/math&amp;gt;[[Variables#NLDamping|NLDamping]] to simulate a finite broadening and to remove the eigenmodes that are excited by the sudden turning on of the external field. After the dephasing time the outgoing signal is analyzed to extract the non-linear coefficients as shown in the figure below: &lt;br /&gt;
&lt;br /&gt;
[[File:Pt analysis.png|600px|center|Non-linear response analysis]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the report file &amp;lt;code&amp;gt;r_nlinear&amp;lt;/code&amp;gt; you will find the length of the dephasing part and of the sampling one:&lt;br /&gt;
&lt;br /&gt;
  Dephasing Time          [fs]: 52.65695&lt;br /&gt;
  Sampling  Time          [fs]:  4.18566&lt;br /&gt;
  Total simulation time   [fs]: 56.84262                     &lt;br /&gt;
The length of the dephasing interval is inversely proportional to the damping term &amp;lt;math&amp;gt;T_{depth} \simeq 1/\gamma&amp;lt;/math&amp;gt; while the length of the sampling is dictated by the smallest frequency we are interested in: &amp;lt;math&amp;gt;T_{samp} \simeq 1/\omega_1 &amp;lt;/math&amp;gt;. For this reason if &amp;lt;math&amp;gt; \omega_1=0 &amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt; \gamma = 0 &amp;lt;/math&amp;gt; simulation time goes to infinity. The response at zero frequency can be calculated as limit of small frequency perturbation.&lt;br /&gt;
You can have a look to the file &amp;lt;code&amp;gt;src/nloptics/NL_initialize.F&amp;lt;/code&amp;gt; to see how simulation lengths are defined.&lt;br /&gt;
Calculations can take some time, run them in parallel, the best number of processors = number of frequencies or reduce the number of frequencies step in the SHG.&lt;br /&gt;
&lt;br /&gt;
==Analysis of the results==&lt;br /&gt;
&lt;br /&gt;
In the sampling region we suppose that the polarization can be written as: &amp;lt;math&amp;gt;\bf{P}(t) = \sum_{n=-\infty}^{+\infty} \bf{p}_n e^{-i\omega_n t} &amp;lt;/math&amp;gt; where the coefficient &amp;lt;math&amp;gt;\bf{p}_1,...,\bf{p}_n &amp;lt;/math&amp;gt; are related to &amp;lt;math&amp;gt;\chi^{(1)},...,\chi^{(n)} &amp;lt;/math&amp;gt;. We sample the polarization signal at different times and invert the previous equation by truncating the sum at a finite order &amp;lt;ref&amp;gt;[https://arxiv.org/abs/1309.4012 Nonlinear optics from an ab initio approach by means of the dynamical Berry phase: Application to second- and third-harmonic generation in semiconductors], C. Attaccalite and M. Grüning, Phys. Rev. B 88, 235113(2013)&amp;lt;/ref&amp;gt;.&lt;br /&gt;
This is done with the command &amp;lt;code&amp;gt;ypp_nl -u&amp;lt;/code&amp;gt; that automatically produce an input with the correct values:&lt;br /&gt;
&lt;br /&gt;
 nonlinear                    # [R] NonLinear Optics Post-Processing&lt;br /&gt;
 Xorder=   &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;4  &amp;lt;/span&amp;gt;                 # Max order of the response functions&lt;br /&gt;
 % TimeRange&lt;br /&gt;
  52.65695 | -1.00000 | fs    # Time-window where processing is done&lt;br /&gt;
 % &lt;br /&gt;
 ETStpsRt= 200                # Total Energy steps&lt;br /&gt;
 % EnRngeRt&lt;br /&gt;
   0.00000 | 10.00000 | eV    # Energy range&lt;br /&gt;
 %&lt;br /&gt;
 DampMode= &amp;quot;NONE&amp;quot;             # Damping type ( NONE | LORENTZIAN | GAUSSIAN )&lt;br /&gt;
 DampFactor=  0.10000   eV    # Damping parameter&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;code&amp;gt;Xorder&amp;lt;/code&amp;gt; is the order where the previous sum is truncated, and the TimeRange specifies the sampling region. Notice that differently from the first tutorial, in this case, we do not need Damping in &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; because we already included it in the real-time dynamics. Run &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; and it will produce a file called &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;. This file contains the different components of &amp;lt;math&amp;gt;\chi^2_{xy*} &amp;lt;/math&amp;gt; and in particular the columns 6 and 7 correspond to the imaginary and real part of &amp;lt;math&amp;gt;\chi^2_{xyz} &amp;lt;/math&amp;gt;. You can plot the result with gnuplot and the command:&lt;br /&gt;
&lt;br /&gt;
 p &#039;o.YPP-X_probe_order_2&#039; u 1:(sqrt($6**2+$7**2)) w lp ps 1.5 pt 7 lw 1.5&lt;br /&gt;
&lt;br /&gt;
the result should look like&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AlAs results.png|700px|center|SHG in AlAs]]&lt;br /&gt;
&lt;br /&gt;
and compare it with the &amp;lt;math&amp;gt; \chi^2_{zxy} &amp;lt;/math&amp;gt; calculated with more frequencies and with the converged result on a &amp;lt;math&amp;gt; 18x18x18&amp;lt;/math&amp;gt; k-point grid and bands between 2 and 10. In the figure you can find also the comparison with the results of Ref. &amp;lt;ref&amp;gt;Luppi et al. [https://arxiv.org/abs/1006.2649 PRB B, &#039;&#039;&#039;82&#039;&#039;&#039;, 235201(2010)]&amp;lt;/ref&amp;gt;. &lt;br /&gt;
Notice that the QuantumEspresso results are slightly different from the Abinit ones. This is due to the different pseudo-potential employed in the calculations if pseudopotentials were the same calculation would have been identical. You can download the script to generate this plot and the converged results [http://www.attaccalite.com/lumen/tutorials/AlAs/AlAs_results.tgz here].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notice that&#039;&#039;&#039; : the following parameters are not used in the non-linear response analysis: &amp;lt;code&amp;gt; EnRngeRt&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ETStpsRt&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;DampMode&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;DampFactor&amp;lt;/code&amp;gt;. The damping factor is set directly in the real-time simulation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;System of units in Non-linear Optics&amp;lt;/span&amp;gt;&#039;&#039;&#039;: notice that in Yambo the non-linear response functions are in the gaussian system of units, for example the &amp;lt;math&amp;gt; \chi^2 (\omega) &amp;lt;/math&amp;gt;  is in cm/statvolt. In order to convert the non-linear coefficients between different system of units, you can have a look at the [https://www.attaccalite.com/tutorials_yambo/Appendix_C_Boyd.pdf Appendix C] of the book [https://www.elsevier.com/books/nonlinear-optics/boyd/978-0-12-369470-6 &amp;quot;Non-linear optics&amp;quot;  by Robert W. Boyd].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;More tutorials&amp;lt;/span&amp;gt; on non-linear response (Third harmonic generation, parallelization, spin-orbit etc..) with Yambo can be found here: [http://www.attaccalite.com/lumen/tutorials.html More Tutorials]. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Analysis of the results using YamboPy==&lt;br /&gt;
The analysis of the result performed in the previous section using &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; can be performed using python script [https://github.com/yambo-code/yambopy YamboPy].&amp;lt;br&amp;gt;&lt;br /&gt;
In YamboPy we implemented all necessary functions to reads the Yambo databases and post-process the results. Here we show how to get the SHG signal from the previous &lt;br /&gt;
simulations. We suppose you correctly installed &amp;lt;code&amp;gt;YamboPy&amp;lt;/code&amp;gt; on your PC. Go in the folder where you ran non-linear calculation and type in the python:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
 from yambopy import *&lt;br /&gt;
 NLDB=YamboNLDB()&lt;br /&gt;
 pol =NLDB.Polarization[0]&lt;br /&gt;
 time=NLDB.IO_TIME_points&lt;br /&gt;
&lt;br /&gt;
in this way you read all the Non-linear databases. If your runs are in a different folder then the &#039;SAVE&#039; one you can specify it using the command:&lt;br /&gt;
 NLDB=YamboNLDB(calc=&#039;MYJOB&#039;)&lt;br /&gt;
&lt;br /&gt;
now in the array &amp;lt;code&amp;gt;pol&amp;lt;/code&amp;gt; you have all the polarization for all laser frequencies in the three Cartesian directions, while the variable &amp;lt;code&amp;gt;time&amp;lt;/code&amp;gt; contains all the time series of your simulation.&lt;br /&gt;
Now you can get the non-linear response with the command:&lt;br /&gt;
&lt;br /&gt;
 Harmonic_Analysis(NLDB,X_order=4)&lt;br /&gt;
&lt;br /&gt;
this command will perform a Fourier analysis of the results in the same way of &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; and generate new files with all the requested harmonics &#039;&#039;o.YamboPy-X_probe_order_1&#039;&#039;, &#039;&#039;o.YamboPy-X_probe_order_2&#039;&#039; etc...&lt;br /&gt;
equivalent to the one generated by &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt;. Results can be plot with gnuplot using the command:&lt;br /&gt;
 &lt;br /&gt;
 p &#039;o.YamboPy-X_probe_order_2&#039; u 1:(sqrt($6**2+$7**2)) w lp ps 1.5 pt 7 lw 1.5&lt;br /&gt;
&lt;br /&gt;
The script that performs non-linear analysis can be found in &amp;lt;code&amp;gt;yambopy/nl/harmonic_analysis.py&amp;lt;/code&amp;gt;. &amp;lt;br&amp;gt; We strongly advice you to have a look to this script and modify it according&lt;br /&gt;
to your needs and in order to extract other non-linear response functions.&lt;br /&gt;
&lt;br /&gt;
==How to choose the external field direction for the different X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
In the X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;abc&amp;lt;/sub&amp;gt; response you have three field directions. The two components &#039;&#039;b&#039;&#039; and &#039;&#039;c&#039;&#039; are determined by the external field and the third &#039;&#039;a&#039;&#039;&lt;br /&gt;
is the direction where you measure the response.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The external field in Yambo is set using the variable&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
   1.000000 | 0.000000 | 0.000000 |        # [NL ExtF] Versor .&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
For example if you set in Yambo field direction as:&lt;br /&gt;
&lt;br /&gt;
 1.0 | 0.0 | 0.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*xx&amp;lt;/sub&amp;gt;&lt;br /&gt;
 0.0 | 1.0 | 0.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*yy&amp;lt;/sub&amp;gt;&lt;br /&gt;
 0.0 | 0.0 | 1.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*zz&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the * correspond to the different direction in the response file &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;.&lt;br /&gt;
In the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt; you have seven columns:&lt;br /&gt;
&lt;br /&gt;
 The first column is the energy [[omega]],&lt;br /&gt;
 the 2nd and 3rd columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;x**&amp;lt;/sub&amp;gt;&lt;br /&gt;
 the 4th and 5th columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;y**&amp;lt;/sub&amp;gt;&lt;br /&gt;
 the 6th and 7th columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;z**&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where the ** are the direction of the incoming field, see above.&lt;br /&gt;
&lt;br /&gt;
For example if you want to calculate the &amp;lt;math&amp;gt;\chi^{(2)}_{zxx}&amp;lt;/math&amp;gt; you put the external field in the direction &amp;lt;code&amp;gt; 1.0 | 0.0 | 0.0 |&amp;lt;/code&amp;gt;&lt;br /&gt;
and then plot the column 6 and 7 of the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt; file.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to get the other components of the  X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; the calculation are more involved. For example if you put field in the&lt;br /&gt;
&lt;br /&gt;
 1.0 | 1.0 | 0.0 | &lt;br /&gt;
&lt;br /&gt;
this corresponds to &amp;lt;math&amp;gt;E(t)=\frac{1}{\sqrt{2}} [ E_x(t) + E_y(t) ]&amp;lt;/math&amp;gt; and so at the second order you will have &amp;lt;math&amp;gt;E^2(t)=\frac{1}{2} \left [ E^2_x(t) + E^2_y(t) +  E_x(t) E_y(t) +  E_y(t) E_x(t) \right]&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
this means that  the X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; in the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;  will correspond to a linear combination of the following different response functions.&amp;lt;br&amp;gt;&lt;br /&gt;
For example in the the 2nd and 3rd columns are the imaginary and real part of:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{x**}=\frac{1}{2} \left [\chi^2_{xxx}+\chi^{(2)}_{xyy} + \chi^{(2)}_{xxy} + \chi^{(2)}_{xyx} \right ]&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the same for the other column replacing the first &amp;lt;code&amp;gt;x&amp;lt;/code&amp;gt; for &amp;lt;code&amp;gt;y,z&amp;lt;/code&amp;gt;.&lt;br /&gt;
If you know that some components are zero this allow you to extract the corresponding off-diagonal part of &amp;lt;math&amp;gt;\chi^{(2)}_{abc}&amp;lt;/math&amp;gt; otherwise you have to perform different calculations to get the component you are interested in. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Now we present &#039;&#039;&#039;a simple example of monolayer hBN (m-hBN)&#039;&#039;&#039;. &amp;lt;br&amp;gt; In m-hBN there is only a non-zero component of the $\chi^2$ and all the others are related by symmetry:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{yyy}=-\chi^{(2)}_{yxx}=-\chi^{(2)}_{xxy}=-\chi^{(2)}_{xyx}&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
so if you put the field in the &amp;lt;code&amp;gt;|1|1|0|&amp;lt;/code&amp;gt; direction you will get:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{x**} = \frac{1}{2} \left[\chi^{(2)}_{xxy} + \chi^{(2)}_{xyx} \right] = - \chi^{(2)}_{yyy} &amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{y**} =\frac{1}{2} \left[ \chi^{(2)}_{yyy} + \chi^{(2)}_{yxx}  \right] = 0.0 &amp;lt;/math&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Nota bene:&#039;&#039;&#039; if you change the direction of the external field you have to remove the corresponding symmetries as explained in the tutorial [[Prerequisites for Real Time_propagation with Yambo#Reduce symmetries real-time linear response tutorial]].&lt;br /&gt;
&lt;br /&gt;
==Non-linear response of low-dimensional structures: 2D or 1D ==&lt;br /&gt;
&lt;br /&gt;
The Yambo code is a 3D periodic code, so when you want to study a low-dimensional system 2D or 1D, you have to use a supercell approach.&lt;br /&gt;
For example to simulate the non-linear response in a 2D-crystal one, can put the crystal in the xy plane and choose a larger distance in the z-direction&lt;br /&gt;
in order to reduce the interaction between the periodic replica. Clearly in this case k-point sampling will be only in the x,y directions.&lt;br /&gt;
For calculations on this type of systems, these two warnings must be taken into account:&lt;br /&gt;
&lt;br /&gt;
* if you calculate GW corrections or include electron-hole interaction in the linear/non-linear response it is a good idea to use a &#039;&#039;&#039;Coulomb cutoff&#039;&#039;&#039;, similar to the 2D BSE case  [http://www.yambo-code.org/wiki/index.php?title=How_to_treat_low_dimensional_systems How to treat low dimensional systems]. You can add the cutoff just adding the &amp;quot;-r&amp;quot; in the input generation.&lt;br /&gt;
&lt;br /&gt;
* the calculation of SHG and THG are always performed respect to the supercell, therefore you have to &#039;&#039;&#039;re-scale&#039;&#039;&#039; the result to the effective thickness of the layer, usually the inter-layer distance of the corresponding bulk material for 2D systems: &amp;lt;math&amp;gt;\chi_{rescaled}(\omega) = L_z/d_{eff} \cdot \chi(\omega) &amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;L_z&amp;lt;/math&amp;gt; is the z-dimension of the supercell, and &amp;lt;math&amp;gt;d_{eff}&amp;lt;/math&amp;gt; is the effective thickness of the 2D system.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Nota bene&#039;&#039;&#039;: Non-linear response along &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;non-periodic directions&amp;lt;/span&amp;gt; is not implemented in Yambo, the code will print zero in these directions for all response functions. We plan to implement it in a future version of the code.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Links for schools==&lt;br /&gt;
* Back to [[Rome 2023#Tutorials]]&lt;br /&gt;
* Back to [[ICTP2020]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
{| style=&amp;quot;width:100%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|style=&amp;quot;width:25%; text-align:left&amp;quot;|Prev: [[Linear response from real time simulations|Linear response from real time simulations]]&lt;br /&gt;
|style=&amp;quot;width:45%; text-align:center&amp;quot;|Now: [[ICTP2020|ICTP  Tutorials]] --&amp;gt; [[Real time approach to non-linear response|Non Linear Response]] &lt;br /&gt;
|style=&amp;quot;width:50%; text-align:left&amp;quot;|Next: [[Correlation effects in the non-linear response|Correlation effects in the non-linear response ]]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Attacc</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Real_time_approach_to_non-linear_response_(SHG)&amp;diff=9156</id>
		<title>Real time approach to non-linear response (SHG)</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Real_time_approach_to_non-linear_response_(SHG)&amp;diff=9156"/>
		<updated>2025-09-27T10:23:18Z</updated>

		<summary type="html">&lt;p&gt;Attacc: /* How to choose the external field direction for the different X2 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Second Harmonic Generation in AlAs ==&lt;br /&gt;
In this tutorial, we will calculate the second harmonic generation of bulk AlAs, the Yambo databases can be downloaded here: [https://media.yambo-code.eu/educational/tutorials/files/AlAs_DBs.tar.gz AlAs_DBs.tar.gz] (10 MB). The first steps of this tutorials are the same as the one on [http://www.yambo-code.eu/wiki/index.php?title=Prerequisites_for_Real_Time_propagation_with_Yambo Prerequisites for Real-Time propagation with Yambo] with the only difference that we will work on AlAs and we will consider an external field in the direction &amp;lt;code&amp;gt; 1.000000 | 1.000000 | 0.000000 |&amp;lt;/code&amp;gt;. The DFT input are available here: [https://media.yambo-code.eu/educational/tutorials/files/AlAs_abinit.tar.gz ABINIT] or [https://media.yambo-code.eu/educational/tutorials/files/AlAs_pwscf.tar.gz QuantumEspresso].&lt;br /&gt;
You can run the DFT calculation with ABINIT with the command:&lt;br /&gt;
&lt;br /&gt;
 abinit &amp;lt; AlAs.in &amp;gt; output_AlAs                                             &lt;br /&gt;
&lt;br /&gt;
or using QuantumEspresso:&lt;br /&gt;
&lt;br /&gt;
 pw.x -inp AlAs.scf.in &amp;gt; output_scf&lt;br /&gt;
 pw.x -inp AlAs.nscf.in &amp;gt; output_scf                            &lt;br /&gt;
&lt;br /&gt;
and then import the ABINIT wave-function with the command:&lt;br /&gt;
&lt;br /&gt;
 a2y -F AlAso_DS2_WFK.nc                            &lt;br /&gt;
&lt;br /&gt;
and the QuantumEspresso one, in the folder AlAs.save with the command:&lt;br /&gt;
&lt;br /&gt;
 p2y                              &lt;br /&gt;
Now we consider an external field in the &amp;lt;code&amp;gt;[1,1,0]&amp;lt;/code&amp;gt; direction and remove symmetries not compatible with this field, as explained in the tutorial [http://www.yambo-code.eu/wiki/index.php?title=Prerequisites_for_Real_Time_propagation_with_Yambo Prerequisites for Real-Time propagation with Yambo].&lt;br /&gt;
&lt;br /&gt;
==Real-time simulation for the SHG==&lt;br /&gt;
&lt;br /&gt;
You can generate the input file with the command &amp;lt;code&amp;gt;yambo_nl -u n&amp;lt;/code&amp;gt;:&lt;br /&gt;
                       &lt;br /&gt;
 nloptics                      # [R NL] Non-linear optics&lt;br /&gt;
 % NLBands&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 3 | 6&amp;lt;/span&amp;gt; |                   # [NL] Bands&lt;br /&gt;
 %&lt;br /&gt;
 NLstep=   0.0100       fs    # [NL] Real Time step length&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;NLverbosity= &amp;quot;high&amp;quot;&amp;lt;/span&amp;gt;               # [NL] Verbosity level (low | high)&lt;br /&gt;
 NLtime=-1.000000           fs    # [NL] Simulation Time&lt;br /&gt;
 NLintegrator= &amp;quot;INVINT&amp;quot;       # [NL] Integrator (&amp;quot;EULEREXP/RK4/RK2EXP/HEUN/INVINT/CRANKNIC&amp;quot;)&lt;br /&gt;
 NLCorrelation= &amp;quot;IPA&amp;quot;         # [NL] Correlation (&amp;quot;IPA/HARTREE/TDDFT/LRC/JGM/SEX/HF&amp;quot;)&lt;br /&gt;
 NLLrcAlpha= 0.000000         # [NL] Long Range Correction&lt;br /&gt;
 % NLEnRange&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;  1.000000 | 5.000000 &amp;lt;/span&amp;gt;| eV    # [NL] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 NLEnSteps= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 5  &amp;lt;/span&amp;gt;              # [NL] Energy steps&lt;br /&gt;
 NLDamping= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 0.150000  &amp;lt;/span&amp;gt;  eV    # [NL] Damping&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 1.000000 | 1.000000 | 0.000000 &amp;lt;/span&amp;gt;|        # [RT Field1] Versor&lt;br /&gt;
 Field1_kind= &amp;quot;SOFTSIN&amp;quot;         # [NL ExtF] Kind(SIN|SOFTSIN|RES|ANTIRES|GAUSS|DELTA|QSSIN)&lt;br /&gt;
&lt;br /&gt;
The line &amp;lt;code&amp;gt;|1.000000 | 1.000000 | 0.000000 | # [RT Field1] Versor&amp;lt;/code&amp;gt; referees to the direction of the external field (x,y,0). At present only an external field is present but the code can be easily generalized to deal with more fields.&lt;br /&gt;
The default parameters of Yambo/Lumen are already tuned for second-harmonic generation, so the only thing you have to change is the band range, between 3 and 6 and the energy range between 1.0-5.0 eV and the number of energy steps in this interval that we set to 10. Notice that you cannot set to zero the lowest value of the energy range because this will requires a simulation that lasts infinite time, see below. Finally, consider that Yambo performs a separate calculation for each frequency, so if you set many energy steps the computational time grows linearly with this number.&lt;br /&gt;
Notice that we set &amp;lt;code&amp;gt;NLverbosity= &amp;quot;high&amp;quot;&amp;lt;/code&amp;gt; in this way the code will produce a file for each laser frequency containing the time dependent polarization.&lt;br /&gt;
Run &amp;lt;code&amp;gt;yambo_nl&amp;lt;/code&amp;gt;. Calculations will take about fifteen minutes on a single processor PC, you have time to study the next section that explains how non-linear response is extracted from the real-time simulations.&lt;br /&gt;
In order to speed up calculations, you can run them in parallel.&lt;br /&gt;
&lt;br /&gt;
==Non-linear response with Yambo==&lt;br /&gt;
&lt;br /&gt;
In order to calculate the non-linear response, the system is excited with different laser fields with a sinusoidal shape at frequencies &amp;lt;math&amp;gt;\omega_1, \omega_2, .... , \omega_n &amp;lt;/math&amp;gt; determined by the parameters [[Variables#NLEnRangev|NLEnRange]] and [[Variables#NLEnSteps|NLEnSteps]]. A dephasing term is added to the Hamiltonian &amp;lt;math&amp;gt;\gamma = &amp;lt;/math&amp;gt;[[Variables#NLDamping|NLDamping]] to simulate a finite broadening and to remove the eigenmodes that are excited by the sudden turning on of the external field. After the dephasing time the outgoing signal is analyzed to extract the non-linear coefficients as shown in the figure below: &lt;br /&gt;
&lt;br /&gt;
[[File:Pt analysis.png|600px|center|Non-linear response analysis]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the report file &amp;lt;code&amp;gt;r_nlinear&amp;lt;/code&amp;gt; you will find the length of the dephasing part and of the sampling one:&lt;br /&gt;
&lt;br /&gt;
  Dephasing Time          [fs]: 52.65695&lt;br /&gt;
  Sampling  Time          [fs]:  4.18566&lt;br /&gt;
  Total simulation time   [fs]: 56.84262                     &lt;br /&gt;
The length of the dephasing interval is inversely proportional to the damping term &amp;lt;math&amp;gt;T_{depth} \simeq 1/\gamma&amp;lt;/math&amp;gt; while the length of the sampling is dictated by the smallest frequency we are interested in: &amp;lt;math&amp;gt;T_{samp} \simeq 1/\omega_1 &amp;lt;/math&amp;gt;. For this reason if &amp;lt;math&amp;gt; \omega_1=0 &amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt; \gamma = 0 &amp;lt;/math&amp;gt; simulation time goes to infinity. The response at zero frequency can be calculated as limit of small frequency perturbation.&lt;br /&gt;
You can have a look to the file &amp;lt;code&amp;gt;src/nloptics/NL_initialize.F&amp;lt;/code&amp;gt; to see how simulation lengths are defined.&lt;br /&gt;
Calculations can take some time, run them in parallel, the best number of processors = number of frequencies or reduce the number of frequencies step in the SHG.&lt;br /&gt;
&lt;br /&gt;
==Analysis of the results==&lt;br /&gt;
&lt;br /&gt;
In the sampling region we suppose that the polarization can be written as: &amp;lt;math&amp;gt;\bf{P}(t) = \sum_{n=-\infty}^{+\infty} \bf{p}_n e^{-i\omega_n t} &amp;lt;/math&amp;gt; where the coefficient &amp;lt;math&amp;gt;\bf{p}_1,...,\bf{p}_n &amp;lt;/math&amp;gt; are related to &amp;lt;math&amp;gt;\chi^{(1)},...,\chi^{(n)} &amp;lt;/math&amp;gt;. We sample the polarization signal at different times and invert the previous equation by truncating the sum at a finite order &amp;lt;ref&amp;gt;[https://arxiv.org/abs/1309.4012 Nonlinear optics from an ab initio approach by means of the dynamical Berry phase: Application to second- and third-harmonic generation in semiconductors], C. Attaccalite and M. Grüning, Phys. Rev. B 88, 235113(2013)&amp;lt;/ref&amp;gt;.&lt;br /&gt;
This is done with the command &amp;lt;code&amp;gt;ypp_nl -u&amp;lt;/code&amp;gt; that automatically produce an input with the correct values:&lt;br /&gt;
&lt;br /&gt;
 nonlinear                    # [R] NonLinear Optics Post-Processing&lt;br /&gt;
 Xorder=   &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;4  &amp;lt;/span&amp;gt;                 # Max order of the response functions&lt;br /&gt;
 % TimeRange&lt;br /&gt;
  52.65695 | -1.00000 | fs    # Time-window where processing is done&lt;br /&gt;
 % &lt;br /&gt;
 ETStpsRt= 200                # Total Energy steps&lt;br /&gt;
 % EnRngeRt&lt;br /&gt;
   0.00000 | 10.00000 | eV    # Energy range&lt;br /&gt;
 %&lt;br /&gt;
 DampMode= &amp;quot;NONE&amp;quot;             # Damping type ( NONE | LORENTZIAN | GAUSSIAN )&lt;br /&gt;
 DampFactor=  0.10000   eV    # Damping parameter&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;code&amp;gt;Xorder&amp;lt;/code&amp;gt; is the order where the previous sum is truncated, and the TimeRange specifies the sampling region. Notice that differently from the first tutorial, in this case, we do not need Damping in &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; because we already included it in the real-time dynamics. Run &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; and it will produce a file called &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;. This file contains the different components of &amp;lt;math&amp;gt;\chi^2_{xy*} &amp;lt;/math&amp;gt; and in particular the columns 6 and 7 correspond to the imaginary and real part of &amp;lt;math&amp;gt;\chi^2_{xyz} &amp;lt;/math&amp;gt;. You can plot the result with gnuplot and the command:&lt;br /&gt;
&lt;br /&gt;
 p &#039;o.YPP-X_probe_order_2&#039; u 1:(sqrt($6**2+$7**2)) w lp ps 1.5 pt 7 lw 1.5&lt;br /&gt;
&lt;br /&gt;
the result should look like&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AlAs results.png|700px|center|SHG in AlAs]]&lt;br /&gt;
&lt;br /&gt;
and compare it with the &amp;lt;math&amp;gt; \chi^2_{zxy} &amp;lt;/math&amp;gt; calculated with more frequencies and with the converged result on a &amp;lt;math&amp;gt; 18x18x18&amp;lt;/math&amp;gt; k-point grid and bands between 2 and 10. In the figure you can find also the comparison with the results of Ref. &amp;lt;ref&amp;gt;Luppi et al. [https://arxiv.org/abs/1006.2649 PRB B, &#039;&#039;&#039;82&#039;&#039;&#039;, 235201(2010)]&amp;lt;/ref&amp;gt;. &lt;br /&gt;
Notice that the QuantumEspresso results are slightly different from the Abinit ones. This is due to the different pseudo-potential employed in the calculations if pseudopotentials were the same calculation would have been identical. You can download the script to generate this plot and the converged results [http://www.attaccalite.com/lumen/tutorials/AlAs/AlAs_results.tgz here].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notice that&#039;&#039;&#039; : the following parameters are not used in the non-linear response analysis: &amp;lt;code&amp;gt; EnRngeRt&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ETStpsRt&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;DampMode&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;DampFactor&amp;lt;/code&amp;gt;. The damping factor is set directly in the real-time simulation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;System of units in Non-linear Optics&amp;lt;/span&amp;gt;&#039;&#039;&#039;: notice that in Yambo the non-linear response functions are in the gaussian system of units, for example the &amp;lt;math&amp;gt; \chi^2 (\omega) &amp;lt;/math&amp;gt;  is in cm/statvolt. In order to convert the non-linear coefficients between different system of units, you can have a look at the [https://www.attaccalite.com/tutorials_yambo/Appendix_C_Boyd.pdf Appendix C] of the book [https://www.elsevier.com/books/nonlinear-optics/boyd/978-0-12-369470-6 &amp;quot;Non-linear optics&amp;quot;  by Robert W. Boyd].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;More tutorials&amp;lt;/span&amp;gt; on non-linear response (Third harmonic generation, parallelization, spin-orbit etc..) with Yambo can be found here: [http://www.attaccalite.com/lumen/tutorials.html More Tutorials]. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Analysis of the results using YamboPy==&lt;br /&gt;
The analysis of the result performed in the previous section using &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; can be performed using python script [https://github.com/yambo-code/yambopy YamboPy].&amp;lt;br&amp;gt;&lt;br /&gt;
In YamboPy we implemented all necessary functions to reads the Yambo databases and post-process the results. Here we show how to get the SHG signal from the previous &lt;br /&gt;
simulations. We suppose you correctly installed &amp;lt;code&amp;gt;YamboPy&amp;lt;/code&amp;gt; on your PC. Go in the folder where you ran non-linear calculation and type in the python:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
 from yambopy import *&lt;br /&gt;
 NLDB=YamboNLDB()&lt;br /&gt;
 pol =NLDB.Polarization[0]&lt;br /&gt;
 time=NLDB.IO_TIME_points&lt;br /&gt;
&lt;br /&gt;
in this way you read all the Non-linear databases. If your runs are in a different folder then the &#039;SAVE&#039; one you can specify it using the command:&lt;br /&gt;
 NLDB=YamboNLDB(calc=&#039;MYJOB&#039;)&lt;br /&gt;
&lt;br /&gt;
now in the array &amp;lt;code&amp;gt;pol&amp;lt;/code&amp;gt; you have all the polarization for all laser frequencies in the three Cartesian directions, while the variable &amp;lt;code&amp;gt;time&amp;lt;/code&amp;gt; contains all the time series of your simulation.&lt;br /&gt;
Now you can get the non-linear response with the command:&lt;br /&gt;
&lt;br /&gt;
 Harmonic_Analysis(NLDB,X_order=4)&lt;br /&gt;
&lt;br /&gt;
this command will perform a Fourier analysis of the results in the same way of &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; and generate new files with all the requested harmonics &#039;&#039;o.YamboPy-X_probe_order_1&#039;&#039;, &#039;&#039;o.YamboPy-X_probe_order_2&#039;&#039; etc...&lt;br /&gt;
equivalent to the one generated by &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt;. Results can be plot with gnuplot using the command:&lt;br /&gt;
 &lt;br /&gt;
 p &#039;o.YamboPy-X_probe_order_2&#039; u 1:(sqrt($6**2+$7**2)) w lp ps 1.5 pt 7 lw 1.5&lt;br /&gt;
&lt;br /&gt;
The script that performs non-linear analysis can be found in &amp;lt;code&amp;gt;yambopy/nl/harmonic_analysis.py&amp;lt;/code&amp;gt;. &amp;lt;br&amp;gt; We strongly advice you to have a look to this script and modify it according&lt;br /&gt;
to your needs and in order to extract other non-linear response functions.&lt;br /&gt;
&lt;br /&gt;
==How to choose the external field direction for the different X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
In the X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;abc&amp;lt;/sub&amp;gt; response you have three field directions. The two components &#039;&#039;b&#039;&#039; and &#039;&#039;c&#039;&#039; are determined by the external field and the third &#039;&#039;a&#039;&#039;&lt;br /&gt;
is the direction where you measure the response.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The external field in Yambo is set using the variable&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
   1.000000 | 0.000000 | 0.000000 |        # [NL ExtF] Versor .&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
For example if you set in Yambo field direction as:&lt;br /&gt;
&lt;br /&gt;
 1.0 | 0.0 | 0.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*xx&amp;lt;/sub&amp;gt;&lt;br /&gt;
 0.0 | 1.0 | 0.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*yy&amp;lt;/sub&amp;gt;&lt;br /&gt;
 0.0 | 0.0 | 1.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*zz&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the * correspond to the different direction in the response file &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;.&lt;br /&gt;
In the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt; you have seven columns:&lt;br /&gt;
&lt;br /&gt;
 The first column is the energy [[omega]],&lt;br /&gt;
 the 2nd and 3rd columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;x**&amp;lt;/sub&amp;gt;&lt;br /&gt;
 the 4th and 5th columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;y**&amp;lt;/sub&amp;gt;&lt;br /&gt;
 the 6th and 7th columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;z**&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where the ** are the direction of the incoming field, see above.&lt;br /&gt;
&lt;br /&gt;
For example if you want to calculate the &amp;lt;math&amp;gt;\chi^{(2)}_{zxx}&amp;lt;/math&amp;gt; you put the external field in the direction &amp;lt;code&amp;gt; 1.0 | 0.0 | 0.0 |&amp;lt;/code&amp;gt;&lt;br /&gt;
and then plot the column 6 and 7 of the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt; file.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to get the other components of the  X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; the calculation are more involved. For example if you put field in the&lt;br /&gt;
&lt;br /&gt;
 1.0 | 1.0 | 0.0 | &lt;br /&gt;
&lt;br /&gt;
this corresponds to &amp;lt;math&amp;gt;E(t)=\frac{1}{\sqrt{2}} [ E_x(t) + E_y(t) ]&amp;lt;/math&amp;gt; and so at the second order you will have &amp;lt;math&amp;gt;E^2(t)=\frac{1}{2} \left [ E^2_x(t) + E^2_y(t) +  E_x(t) E_y(t) +  E_y(t) E_x(t) \right]&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
this means that  the X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; in the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;  will correspond to a linear combination of the following different response functions.&amp;lt;br&amp;gt;&lt;br /&gt;
For example in the the 2nd and 3rd columns are the imaginary and real part of:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{x**}=\frac{1}{2} \left [\chi^2_{xxx}+\chi^{(2)}_{xyy} + \chi^{(2)}_{xxy} + \chi^{(2)}_{xyx} \right ]&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the same for the other column replacing the first &amp;lt;code&amp;gt;x&amp;lt;/code&amp;gt; for &amp;lt;code&amp;gt;y,z&amp;lt;/code&amp;gt;.&lt;br /&gt;
If you know that some components are zero this allow you to extract the corresponding off-diagonal part of &amp;lt;math&amp;gt;\chi^{(2)}_{abc}&amp;lt;/math&amp;gt; otherwise you have to perform different calculations to get the component you are interested in. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Now we present &#039;&#039;&#039;a simple example of monolayer hBN (m-hBN)&#039;&#039;&#039;. &amp;lt;br&amp;gt; In m-hBN there is only a non-zero component of the $\chi^2$ and all the others are related by symmetry:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{yyy}=-\chi^{(2)}_{yxx}=-\chi^{(2)}_{xxy}=-\chi^{(2)}_{xyx}&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
so if you put the field in the &amp;lt;code&amp;gt;|1|1|0|&amp;lt;/code&amp;gt; direction you will get:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{x**} = \frac{1}{2} \left[\chi^{(2)}_{xxy} + \chi^{(2)}_{xyx} \right] = - \chi^{(2)}_{yyy} &amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{y**} =\frac{1}{2} \left[ \chi^{(2)}_{yyy} + \chi^{(2)}_{yxx}  \right] = 0.0 &amp;lt;/math&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Nota bene:&#039;&#039;&#039; if you change the direction of the external field you have to remove the corresponding symmetries as explained in the tutorial&lt;br /&gt;
 [[Prerequisites for Real Time_propagation with Yambo#Reduce symmetries real-time linear response tutorial]].&lt;br /&gt;
&lt;br /&gt;
==Non-linear response of low-dimensional structures: 2D or 1D ==&lt;br /&gt;
&lt;br /&gt;
The Yambo code is a 3D periodic code, so when you want to study a low-dimensional system 2D or 1D, you have to use a supercell approach.&lt;br /&gt;
For example to simulate the non-linear response in a 2D-crystal one, can put the crystal in the xy plane and choose a larger distance in the z-direction&lt;br /&gt;
in order to reduce the interaction between the periodic replica. Clearly in this case k-point sampling will be only in the x,y directions.&lt;br /&gt;
For calculations on this type of systems, these two warnings must be taken into account:&lt;br /&gt;
&lt;br /&gt;
* if you calculate GW corrections or include electron-hole interaction in the linear/non-linear response it is a good idea to use a &#039;&#039;&#039;Coulomb cutoff&#039;&#039;&#039;, similar to the 2D BSE case  [http://www.yambo-code.org/wiki/index.php?title=How_to_treat_low_dimensional_systems How to treat low dimensional systems]. You can add the cutoff just adding the &amp;quot;-r&amp;quot; in the input generation.&lt;br /&gt;
&lt;br /&gt;
* the calculation of SHG and THG are always performed respect to the supercell, therefore you have to &#039;&#039;&#039;re-scale&#039;&#039;&#039; the result to the effective thickness of the layer, usually the inter-layer distance of the corresponding bulk material for 2D systems: &amp;lt;math&amp;gt;\chi_{rescaled}(\omega) = L_z/d_{eff} \cdot \chi(\omega) &amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;L_z&amp;lt;/math&amp;gt; is the z-dimension of the supercell, and &amp;lt;math&amp;gt;d_{eff}&amp;lt;/math&amp;gt; is the effective thickness of the 2D system.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Nota bene&#039;&#039;&#039;: Non-linear response along &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;non-periodic directions&amp;lt;/span&amp;gt; is not implemented in Yambo, the code will print zero in these directions for all response functions. We plan to implement it in a future version of the code.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Links for schools==&lt;br /&gt;
* Back to [[Rome 2023#Tutorials]]&lt;br /&gt;
* Back to [[ICTP2020]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
{| style=&amp;quot;width:100%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|style=&amp;quot;width:25%; text-align:left&amp;quot;|Prev: [[Linear response from real time simulations|Linear response from real time simulations]]&lt;br /&gt;
|style=&amp;quot;width:45%; text-align:center&amp;quot;|Now: [[ICTP2020|ICTP  Tutorials]] --&amp;gt; [[Real time approach to non-linear response|Non Linear Response]] &lt;br /&gt;
|style=&amp;quot;width:50%; text-align:left&amp;quot;|Next: [[Correlation effects in the non-linear response|Correlation effects in the non-linear response ]]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Attacc</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Real_time_approach_to_non-linear_response_(SHG)&amp;diff=9155</id>
		<title>Real time approach to non-linear response (SHG)</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Real_time_approach_to_non-linear_response_(SHG)&amp;diff=9155"/>
		<updated>2025-09-27T10:22:45Z</updated>

		<summary type="html">&lt;p&gt;Attacc: /* How to choose the external field direction for the different X2 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Second Harmonic Generation in AlAs ==&lt;br /&gt;
In this tutorial, we will calculate the second harmonic generation of bulk AlAs, the Yambo databases can be downloaded here: [https://media.yambo-code.eu/educational/tutorials/files/AlAs_DBs.tar.gz AlAs_DBs.tar.gz] (10 MB). The first steps of this tutorials are the same as the one on [http://www.yambo-code.eu/wiki/index.php?title=Prerequisites_for_Real_Time_propagation_with_Yambo Prerequisites for Real-Time propagation with Yambo] with the only difference that we will work on AlAs and we will consider an external field in the direction &amp;lt;code&amp;gt; 1.000000 | 1.000000 | 0.000000 |&amp;lt;/code&amp;gt;. The DFT input are available here: [https://media.yambo-code.eu/educational/tutorials/files/AlAs_abinit.tar.gz ABINIT] or [https://media.yambo-code.eu/educational/tutorials/files/AlAs_pwscf.tar.gz QuantumEspresso].&lt;br /&gt;
You can run the DFT calculation with ABINIT with the command:&lt;br /&gt;
&lt;br /&gt;
 abinit &amp;lt; AlAs.in &amp;gt; output_AlAs                                             &lt;br /&gt;
&lt;br /&gt;
or using QuantumEspresso:&lt;br /&gt;
&lt;br /&gt;
 pw.x -inp AlAs.scf.in &amp;gt; output_scf&lt;br /&gt;
 pw.x -inp AlAs.nscf.in &amp;gt; output_scf                            &lt;br /&gt;
&lt;br /&gt;
and then import the ABINIT wave-function with the command:&lt;br /&gt;
&lt;br /&gt;
 a2y -F AlAso_DS2_WFK.nc                            &lt;br /&gt;
&lt;br /&gt;
and the QuantumEspresso one, in the folder AlAs.save with the command:&lt;br /&gt;
&lt;br /&gt;
 p2y                              &lt;br /&gt;
Now we consider an external field in the &amp;lt;code&amp;gt;[1,1,0]&amp;lt;/code&amp;gt; direction and remove symmetries not compatible with this field, as explained in the tutorial [http://www.yambo-code.eu/wiki/index.php?title=Prerequisites_for_Real_Time_propagation_with_Yambo Prerequisites for Real-Time propagation with Yambo].&lt;br /&gt;
&lt;br /&gt;
==Real-time simulation for the SHG==&lt;br /&gt;
&lt;br /&gt;
You can generate the input file with the command &amp;lt;code&amp;gt;yambo_nl -u n&amp;lt;/code&amp;gt;:&lt;br /&gt;
                       &lt;br /&gt;
 nloptics                      # [R NL] Non-linear optics&lt;br /&gt;
 % NLBands&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 3 | 6&amp;lt;/span&amp;gt; |                   # [NL] Bands&lt;br /&gt;
 %&lt;br /&gt;
 NLstep=   0.0100       fs    # [NL] Real Time step length&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;NLverbosity= &amp;quot;high&amp;quot;&amp;lt;/span&amp;gt;               # [NL] Verbosity level (low | high)&lt;br /&gt;
 NLtime=-1.000000           fs    # [NL] Simulation Time&lt;br /&gt;
 NLintegrator= &amp;quot;INVINT&amp;quot;       # [NL] Integrator (&amp;quot;EULEREXP/RK4/RK2EXP/HEUN/INVINT/CRANKNIC&amp;quot;)&lt;br /&gt;
 NLCorrelation= &amp;quot;IPA&amp;quot;         # [NL] Correlation (&amp;quot;IPA/HARTREE/TDDFT/LRC/JGM/SEX/HF&amp;quot;)&lt;br /&gt;
 NLLrcAlpha= 0.000000         # [NL] Long Range Correction&lt;br /&gt;
 % NLEnRange&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;  1.000000 | 5.000000 &amp;lt;/span&amp;gt;| eV    # [NL] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 NLEnSteps= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 5  &amp;lt;/span&amp;gt;              # [NL] Energy steps&lt;br /&gt;
 NLDamping= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 0.150000  &amp;lt;/span&amp;gt;  eV    # [NL] Damping&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 1.000000 | 1.000000 | 0.000000 &amp;lt;/span&amp;gt;|        # [RT Field1] Versor&lt;br /&gt;
 Field1_kind= &amp;quot;SOFTSIN&amp;quot;         # [NL ExtF] Kind(SIN|SOFTSIN|RES|ANTIRES|GAUSS|DELTA|QSSIN)&lt;br /&gt;
&lt;br /&gt;
The line &amp;lt;code&amp;gt;|1.000000 | 1.000000 | 0.000000 | # [RT Field1] Versor&amp;lt;/code&amp;gt; referees to the direction of the external field (x,y,0). At present only an external field is present but the code can be easily generalized to deal with more fields.&lt;br /&gt;
The default parameters of Yambo/Lumen are already tuned for second-harmonic generation, so the only thing you have to change is the band range, between 3 and 6 and the energy range between 1.0-5.0 eV and the number of energy steps in this interval that we set to 10. Notice that you cannot set to zero the lowest value of the energy range because this will requires a simulation that lasts infinite time, see below. Finally, consider that Yambo performs a separate calculation for each frequency, so if you set many energy steps the computational time grows linearly with this number.&lt;br /&gt;
Notice that we set &amp;lt;code&amp;gt;NLverbosity= &amp;quot;high&amp;quot;&amp;lt;/code&amp;gt; in this way the code will produce a file for each laser frequency containing the time dependent polarization.&lt;br /&gt;
Run &amp;lt;code&amp;gt;yambo_nl&amp;lt;/code&amp;gt;. Calculations will take about fifteen minutes on a single processor PC, you have time to study the next section that explains how non-linear response is extracted from the real-time simulations.&lt;br /&gt;
In order to speed up calculations, you can run them in parallel.&lt;br /&gt;
&lt;br /&gt;
==Non-linear response with Yambo==&lt;br /&gt;
&lt;br /&gt;
In order to calculate the non-linear response, the system is excited with different laser fields with a sinusoidal shape at frequencies &amp;lt;math&amp;gt;\omega_1, \omega_2, .... , \omega_n &amp;lt;/math&amp;gt; determined by the parameters [[Variables#NLEnRangev|NLEnRange]] and [[Variables#NLEnSteps|NLEnSteps]]. A dephasing term is added to the Hamiltonian &amp;lt;math&amp;gt;\gamma = &amp;lt;/math&amp;gt;[[Variables#NLDamping|NLDamping]] to simulate a finite broadening and to remove the eigenmodes that are excited by the sudden turning on of the external field. After the dephasing time the outgoing signal is analyzed to extract the non-linear coefficients as shown in the figure below: &lt;br /&gt;
&lt;br /&gt;
[[File:Pt analysis.png|600px|center|Non-linear response analysis]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the report file &amp;lt;code&amp;gt;r_nlinear&amp;lt;/code&amp;gt; you will find the length of the dephasing part and of the sampling one:&lt;br /&gt;
&lt;br /&gt;
  Dephasing Time          [fs]: 52.65695&lt;br /&gt;
  Sampling  Time          [fs]:  4.18566&lt;br /&gt;
  Total simulation time   [fs]: 56.84262                     &lt;br /&gt;
The length of the dephasing interval is inversely proportional to the damping term &amp;lt;math&amp;gt;T_{depth} \simeq 1/\gamma&amp;lt;/math&amp;gt; while the length of the sampling is dictated by the smallest frequency we are interested in: &amp;lt;math&amp;gt;T_{samp} \simeq 1/\omega_1 &amp;lt;/math&amp;gt;. For this reason if &amp;lt;math&amp;gt; \omega_1=0 &amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt; \gamma = 0 &amp;lt;/math&amp;gt; simulation time goes to infinity. The response at zero frequency can be calculated as limit of small frequency perturbation.&lt;br /&gt;
You can have a look to the file &amp;lt;code&amp;gt;src/nloptics/NL_initialize.F&amp;lt;/code&amp;gt; to see how simulation lengths are defined.&lt;br /&gt;
Calculations can take some time, run them in parallel, the best number of processors = number of frequencies or reduce the number of frequencies step in the SHG.&lt;br /&gt;
&lt;br /&gt;
==Analysis of the results==&lt;br /&gt;
&lt;br /&gt;
In the sampling region we suppose that the polarization can be written as: &amp;lt;math&amp;gt;\bf{P}(t) = \sum_{n=-\infty}^{+\infty} \bf{p}_n e^{-i\omega_n t} &amp;lt;/math&amp;gt; where the coefficient &amp;lt;math&amp;gt;\bf{p}_1,...,\bf{p}_n &amp;lt;/math&amp;gt; are related to &amp;lt;math&amp;gt;\chi^{(1)},...,\chi^{(n)} &amp;lt;/math&amp;gt;. We sample the polarization signal at different times and invert the previous equation by truncating the sum at a finite order &amp;lt;ref&amp;gt;[https://arxiv.org/abs/1309.4012 Nonlinear optics from an ab initio approach by means of the dynamical Berry phase: Application to second- and third-harmonic generation in semiconductors], C. Attaccalite and M. Grüning, Phys. Rev. B 88, 235113(2013)&amp;lt;/ref&amp;gt;.&lt;br /&gt;
This is done with the command &amp;lt;code&amp;gt;ypp_nl -u&amp;lt;/code&amp;gt; that automatically produce an input with the correct values:&lt;br /&gt;
&lt;br /&gt;
 nonlinear                    # [R] NonLinear Optics Post-Processing&lt;br /&gt;
 Xorder=   &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;4  &amp;lt;/span&amp;gt;                 # Max order of the response functions&lt;br /&gt;
 % TimeRange&lt;br /&gt;
  52.65695 | -1.00000 | fs    # Time-window where processing is done&lt;br /&gt;
 % &lt;br /&gt;
 ETStpsRt= 200                # Total Energy steps&lt;br /&gt;
 % EnRngeRt&lt;br /&gt;
   0.00000 | 10.00000 | eV    # Energy range&lt;br /&gt;
 %&lt;br /&gt;
 DampMode= &amp;quot;NONE&amp;quot;             # Damping type ( NONE | LORENTZIAN | GAUSSIAN )&lt;br /&gt;
 DampFactor=  0.10000   eV    # Damping parameter&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;code&amp;gt;Xorder&amp;lt;/code&amp;gt; is the order where the previous sum is truncated, and the TimeRange specifies the sampling region. Notice that differently from the first tutorial, in this case, we do not need Damping in &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; because we already included it in the real-time dynamics. Run &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; and it will produce a file called &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;. This file contains the different components of &amp;lt;math&amp;gt;\chi^2_{xy*} &amp;lt;/math&amp;gt; and in particular the columns 6 and 7 correspond to the imaginary and real part of &amp;lt;math&amp;gt;\chi^2_{xyz} &amp;lt;/math&amp;gt;. You can plot the result with gnuplot and the command:&lt;br /&gt;
&lt;br /&gt;
 p &#039;o.YPP-X_probe_order_2&#039; u 1:(sqrt($6**2+$7**2)) w lp ps 1.5 pt 7 lw 1.5&lt;br /&gt;
&lt;br /&gt;
the result should look like&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AlAs results.png|700px|center|SHG in AlAs]]&lt;br /&gt;
&lt;br /&gt;
and compare it with the &amp;lt;math&amp;gt; \chi^2_{zxy} &amp;lt;/math&amp;gt; calculated with more frequencies and with the converged result on a &amp;lt;math&amp;gt; 18x18x18&amp;lt;/math&amp;gt; k-point grid and bands between 2 and 10. In the figure you can find also the comparison with the results of Ref. &amp;lt;ref&amp;gt;Luppi et al. [https://arxiv.org/abs/1006.2649 PRB B, &#039;&#039;&#039;82&#039;&#039;&#039;, 235201(2010)]&amp;lt;/ref&amp;gt;. &lt;br /&gt;
Notice that the QuantumEspresso results are slightly different from the Abinit ones. This is due to the different pseudo-potential employed in the calculations if pseudopotentials were the same calculation would have been identical. You can download the script to generate this plot and the converged results [http://www.attaccalite.com/lumen/tutorials/AlAs/AlAs_results.tgz here].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notice that&#039;&#039;&#039; : the following parameters are not used in the non-linear response analysis: &amp;lt;code&amp;gt; EnRngeRt&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ETStpsRt&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;DampMode&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;DampFactor&amp;lt;/code&amp;gt;. The damping factor is set directly in the real-time simulation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;System of units in Non-linear Optics&amp;lt;/span&amp;gt;&#039;&#039;&#039;: notice that in Yambo the non-linear response functions are in the gaussian system of units, for example the &amp;lt;math&amp;gt; \chi^2 (\omega) &amp;lt;/math&amp;gt;  is in cm/statvolt. In order to convert the non-linear coefficients between different system of units, you can have a look at the [https://www.attaccalite.com/tutorials_yambo/Appendix_C_Boyd.pdf Appendix C] of the book [https://www.elsevier.com/books/nonlinear-optics/boyd/978-0-12-369470-6 &amp;quot;Non-linear optics&amp;quot;  by Robert W. Boyd].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;More tutorials&amp;lt;/span&amp;gt; on non-linear response (Third harmonic generation, parallelization, spin-orbit etc..) with Yambo can be found here: [http://www.attaccalite.com/lumen/tutorials.html More Tutorials]. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Analysis of the results using YamboPy==&lt;br /&gt;
The analysis of the result performed in the previous section using &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; can be performed using python script [https://github.com/yambo-code/yambopy YamboPy].&amp;lt;br&amp;gt;&lt;br /&gt;
In YamboPy we implemented all necessary functions to reads the Yambo databases and post-process the results. Here we show how to get the SHG signal from the previous &lt;br /&gt;
simulations. We suppose you correctly installed &amp;lt;code&amp;gt;YamboPy&amp;lt;/code&amp;gt; on your PC. Go in the folder where you ran non-linear calculation and type in the python:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
 from yambopy import *&lt;br /&gt;
 NLDB=YamboNLDB()&lt;br /&gt;
 pol =NLDB.Polarization[0]&lt;br /&gt;
 time=NLDB.IO_TIME_points&lt;br /&gt;
&lt;br /&gt;
in this way you read all the Non-linear databases. If your runs are in a different folder then the &#039;SAVE&#039; one you can specify it using the command:&lt;br /&gt;
 NLDB=YamboNLDB(calc=&#039;MYJOB&#039;)&lt;br /&gt;
&lt;br /&gt;
now in the array &amp;lt;code&amp;gt;pol&amp;lt;/code&amp;gt; you have all the polarization for all laser frequencies in the three Cartesian directions, while the variable &amp;lt;code&amp;gt;time&amp;lt;/code&amp;gt; contains all the time series of your simulation.&lt;br /&gt;
Now you can get the non-linear response with the command:&lt;br /&gt;
&lt;br /&gt;
 Harmonic_Analysis(NLDB,X_order=4)&lt;br /&gt;
&lt;br /&gt;
this command will perform a Fourier analysis of the results in the same way of &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; and generate new files with all the requested harmonics &#039;&#039;o.YamboPy-X_probe_order_1&#039;&#039;, &#039;&#039;o.YamboPy-X_probe_order_2&#039;&#039; etc...&lt;br /&gt;
equivalent to the one generated by &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt;. Results can be plot with gnuplot using the command:&lt;br /&gt;
 &lt;br /&gt;
 p &#039;o.YamboPy-X_probe_order_2&#039; u 1:(sqrt($6**2+$7**2)) w lp ps 1.5 pt 7 lw 1.5&lt;br /&gt;
&lt;br /&gt;
The script that performs non-linear analysis can be found in &amp;lt;code&amp;gt;yambopy/nl/harmonic_analysis.py&amp;lt;/code&amp;gt;. &amp;lt;br&amp;gt; We strongly advice you to have a look to this script and modify it according&lt;br /&gt;
to your needs and in order to extract other non-linear response functions.&lt;br /&gt;
&lt;br /&gt;
==How to choose the external field direction for the different X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
In the X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;abc&amp;lt;/sub&amp;gt; response you have three field directions. The two components &#039;&#039;b&#039;&#039; and &#039;&#039;c&#039;&#039; are determined by the external field and the third &#039;&#039;a&#039;&#039;&lt;br /&gt;
is the direction where you measure the response.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The external field in Yambo is set using the variable&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
   1.000000 | 0.000000 | 0.000000 |        # [NL ExtF] Versor .&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
For example if you set in Yambo field direction as:&lt;br /&gt;
&lt;br /&gt;
 1.0 | 0.0 | 0.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*xx&amp;lt;/sub&amp;gt;&lt;br /&gt;
 0.0 | 1.0 | 0.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*yy&amp;lt;/sub&amp;gt;&lt;br /&gt;
 0.0 | 0.0 | 1.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*zz&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the * correspond to the different direction in the response file &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;.&lt;br /&gt;
In the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt; you have seven columns:&lt;br /&gt;
&lt;br /&gt;
 The first column is the energy [[omega]],&lt;br /&gt;
 the 2nd and 3rd columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;x**&amp;lt;/sub&amp;gt;&lt;br /&gt;
 the 4th and 5th columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;y**&amp;lt;/sub&amp;gt;&lt;br /&gt;
 the 6th and 7th columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;z**&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where the ** are the direction of the incoming field, see above.&lt;br /&gt;
&lt;br /&gt;
For example if you want to calculate the &amp;lt;math&amp;gt;\chi^{(2)}_{zxx}&amp;lt;/math&amp;gt; you put the external field in the direction &amp;lt;code&amp;gt; 1.0 | 0.0 | 0.0 |&amp;lt;/code&amp;gt;&lt;br /&gt;
and then plot the column 6 and 7 of the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt; file.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
on [[Prerequisites for Real Time_propagation with Yambo#Reduce symmetries real-time linear response tutorial]].&lt;br /&gt;
&lt;br /&gt;
In order to get the other components of the  X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; the calculation are more involved. For example if you put field in the&lt;br /&gt;
&lt;br /&gt;
 1.0 | 1.0 | 0.0 | &lt;br /&gt;
&lt;br /&gt;
this corresponds to &amp;lt;math&amp;gt;E(t)=\frac{1}{\sqrt{2}} [ E_x(t) + E_y(t) ]&amp;lt;/math&amp;gt; and so at the second order you will have &amp;lt;math&amp;gt;E^2(t)=\frac{1}{2} \left [ E^2_x(t) + E^2_y(t) +  E_x(t) E_y(t) +  E_y(t) E_x(t) \right]&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
this means that  the X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; in the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;  will correspond to a linear combination of the following different response functions.&amp;lt;br&amp;gt;&lt;br /&gt;
For example in the the 2nd and 3rd columns are the imaginary and real part of:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{x**}=\frac{1}{2} \left [\chi^2_{xxx}+\chi^{(2)}_{xyy} + \chi^{(2)}_{xxy} + \chi^{(2)}_{xyx} \right ]&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the same for the other column replacing the first &amp;lt;code&amp;gt;x&amp;lt;/code&amp;gt; for &amp;lt;code&amp;gt;y,z&amp;lt;/code&amp;gt;.&lt;br /&gt;
If you know that some components are zero this allow you to extract the corresponding off-diagonal part of &amp;lt;math&amp;gt;\chi^{(2)}_{abc}&amp;lt;/math&amp;gt; otherwise you have to perform different calculations to get the component you are interested in. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Now we present &#039;&#039;&#039;a simple example of monolayer hBN (m-hBN)&#039;&#039;&#039;. &amp;lt;br&amp;gt; In m-hBN there is only a non-zero component of the $\chi^2$ and all the others are related by symmetry:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{yyy}=-\chi^{(2)}_{yxx}=-\chi^{(2)}_{xxy}=-\chi^{(2)}_{xyx}&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
so if you put the field in the &amp;lt;code&amp;gt;|1|1|0|&amp;lt;/code&amp;gt; direction you will get:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{x**} = \frac{1}{2} \left[\chi^{(2)}_{xxy} + \chi^{(2)}_{xyx} \right] = - \chi^{(2)}_{yyy} &amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{y**} =\frac{1}{2} \left[ \chi^{(2)}_{yyy} + \chi^{(2)}_{yxx}  \right] = 0.0 &amp;lt;/math&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;Nota bene:&#039;&#039;&#039; if you change the direction of the external field you have to remove the corresponding symmetries as explained in the tutorial&lt;br /&gt;
&lt;br /&gt;
==Non-linear response of low-dimensional structures: 2D or 1D ==&lt;br /&gt;
&lt;br /&gt;
The Yambo code is a 3D periodic code, so when you want to study a low-dimensional system 2D or 1D, you have to use a supercell approach.&lt;br /&gt;
For example to simulate the non-linear response in a 2D-crystal one, can put the crystal in the xy plane and choose a larger distance in the z-direction&lt;br /&gt;
in order to reduce the interaction between the periodic replica. Clearly in this case k-point sampling will be only in the x,y directions.&lt;br /&gt;
For calculations on this type of systems, these two warnings must be taken into account:&lt;br /&gt;
&lt;br /&gt;
* if you calculate GW corrections or include electron-hole interaction in the linear/non-linear response it is a good idea to use a &#039;&#039;&#039;Coulomb cutoff&#039;&#039;&#039;, similar to the 2D BSE case  [http://www.yambo-code.org/wiki/index.php?title=How_to_treat_low_dimensional_systems How to treat low dimensional systems]. You can add the cutoff just adding the &amp;quot;-r&amp;quot; in the input generation.&lt;br /&gt;
&lt;br /&gt;
* the calculation of SHG and THG are always performed respect to the supercell, therefore you have to &#039;&#039;&#039;re-scale&#039;&#039;&#039; the result to the effective thickness of the layer, usually the inter-layer distance of the corresponding bulk material for 2D systems: &amp;lt;math&amp;gt;\chi_{rescaled}(\omega) = L_z/d_{eff} \cdot \chi(\omega) &amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;L_z&amp;lt;/math&amp;gt; is the z-dimension of the supercell, and &amp;lt;math&amp;gt;d_{eff}&amp;lt;/math&amp;gt; is the effective thickness of the 2D system.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Nota bene&#039;&#039;&#039;: Non-linear response along &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;non-periodic directions&amp;lt;/span&amp;gt; is not implemented in Yambo, the code will print zero in these directions for all response functions. We plan to implement it in a future version of the code.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Links for schools==&lt;br /&gt;
* Back to [[Rome 2023#Tutorials]]&lt;br /&gt;
* Back to [[ICTP2020]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
{| style=&amp;quot;width:100%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|style=&amp;quot;width:25%; text-align:left&amp;quot;|Prev: [[Linear response from real time simulations|Linear response from real time simulations]]&lt;br /&gt;
|style=&amp;quot;width:45%; text-align:center&amp;quot;|Now: [[ICTP2020|ICTP  Tutorials]] --&amp;gt; [[Real time approach to non-linear response|Non Linear Response]] &lt;br /&gt;
|style=&amp;quot;width:50%; text-align:left&amp;quot;|Next: [[Correlation effects in the non-linear response|Correlation effects in the non-linear response ]]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Attacc</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Real_time_approach_to_non-linear_response_(SHG)&amp;diff=9154</id>
		<title>Real time approach to non-linear response (SHG)</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Real_time_approach_to_non-linear_response_(SHG)&amp;diff=9154"/>
		<updated>2025-09-27T10:21:26Z</updated>

		<summary type="html">&lt;p&gt;Attacc: /* How to choose the external field direction for the different X2 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Second Harmonic Generation in AlAs ==&lt;br /&gt;
In this tutorial, we will calculate the second harmonic generation of bulk AlAs, the Yambo databases can be downloaded here: [https://media.yambo-code.eu/educational/tutorials/files/AlAs_DBs.tar.gz AlAs_DBs.tar.gz] (10 MB). The first steps of this tutorials are the same as the one on [http://www.yambo-code.eu/wiki/index.php?title=Prerequisites_for_Real_Time_propagation_with_Yambo Prerequisites for Real-Time propagation with Yambo] with the only difference that we will work on AlAs and we will consider an external field in the direction &amp;lt;code&amp;gt; 1.000000 | 1.000000 | 0.000000 |&amp;lt;/code&amp;gt;. The DFT input are available here: [https://media.yambo-code.eu/educational/tutorials/files/AlAs_abinit.tar.gz ABINIT] or [https://media.yambo-code.eu/educational/tutorials/files/AlAs_pwscf.tar.gz QuantumEspresso].&lt;br /&gt;
You can run the DFT calculation with ABINIT with the command:&lt;br /&gt;
&lt;br /&gt;
 abinit &amp;lt; AlAs.in &amp;gt; output_AlAs                                             &lt;br /&gt;
&lt;br /&gt;
or using QuantumEspresso:&lt;br /&gt;
&lt;br /&gt;
 pw.x -inp AlAs.scf.in &amp;gt; output_scf&lt;br /&gt;
 pw.x -inp AlAs.nscf.in &amp;gt; output_scf                            &lt;br /&gt;
&lt;br /&gt;
and then import the ABINIT wave-function with the command:&lt;br /&gt;
&lt;br /&gt;
 a2y -F AlAso_DS2_WFK.nc                            &lt;br /&gt;
&lt;br /&gt;
and the QuantumEspresso one, in the folder AlAs.save with the command:&lt;br /&gt;
&lt;br /&gt;
 p2y                              &lt;br /&gt;
Now we consider an external field in the &amp;lt;code&amp;gt;[1,1,0]&amp;lt;/code&amp;gt; direction and remove symmetries not compatible with this field, as explained in the tutorial [http://www.yambo-code.eu/wiki/index.php?title=Prerequisites_for_Real_Time_propagation_with_Yambo Prerequisites for Real-Time propagation with Yambo].&lt;br /&gt;
&lt;br /&gt;
==Real-time simulation for the SHG==&lt;br /&gt;
&lt;br /&gt;
You can generate the input file with the command &amp;lt;code&amp;gt;yambo_nl -u n&amp;lt;/code&amp;gt;:&lt;br /&gt;
                       &lt;br /&gt;
 nloptics                      # [R NL] Non-linear optics&lt;br /&gt;
 % NLBands&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 3 | 6&amp;lt;/span&amp;gt; |                   # [NL] Bands&lt;br /&gt;
 %&lt;br /&gt;
 NLstep=   0.0100       fs    # [NL] Real Time step length&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;NLverbosity= &amp;quot;high&amp;quot;&amp;lt;/span&amp;gt;               # [NL] Verbosity level (low | high)&lt;br /&gt;
 NLtime=-1.000000           fs    # [NL] Simulation Time&lt;br /&gt;
 NLintegrator= &amp;quot;INVINT&amp;quot;       # [NL] Integrator (&amp;quot;EULEREXP/RK4/RK2EXP/HEUN/INVINT/CRANKNIC&amp;quot;)&lt;br /&gt;
 NLCorrelation= &amp;quot;IPA&amp;quot;         # [NL] Correlation (&amp;quot;IPA/HARTREE/TDDFT/LRC/JGM/SEX/HF&amp;quot;)&lt;br /&gt;
 NLLrcAlpha= 0.000000         # [NL] Long Range Correction&lt;br /&gt;
 % NLEnRange&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;  1.000000 | 5.000000 &amp;lt;/span&amp;gt;| eV    # [NL] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 NLEnSteps= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 5  &amp;lt;/span&amp;gt;              # [NL] Energy steps&lt;br /&gt;
 NLDamping= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 0.150000  &amp;lt;/span&amp;gt;  eV    # [NL] Damping&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 1.000000 | 1.000000 | 0.000000 &amp;lt;/span&amp;gt;|        # [RT Field1] Versor&lt;br /&gt;
 Field1_kind= &amp;quot;SOFTSIN&amp;quot;         # [NL ExtF] Kind(SIN|SOFTSIN|RES|ANTIRES|GAUSS|DELTA|QSSIN)&lt;br /&gt;
&lt;br /&gt;
The line &amp;lt;code&amp;gt;|1.000000 | 1.000000 | 0.000000 | # [RT Field1] Versor&amp;lt;/code&amp;gt; referees to the direction of the external field (x,y,0). At present only an external field is present but the code can be easily generalized to deal with more fields.&lt;br /&gt;
The default parameters of Yambo/Lumen are already tuned for second-harmonic generation, so the only thing you have to change is the band range, between 3 and 6 and the energy range between 1.0-5.0 eV and the number of energy steps in this interval that we set to 10. Notice that you cannot set to zero the lowest value of the energy range because this will requires a simulation that lasts infinite time, see below. Finally, consider that Yambo performs a separate calculation for each frequency, so if you set many energy steps the computational time grows linearly with this number.&lt;br /&gt;
Notice that we set &amp;lt;code&amp;gt;NLverbosity= &amp;quot;high&amp;quot;&amp;lt;/code&amp;gt; in this way the code will produce a file for each laser frequency containing the time dependent polarization.&lt;br /&gt;
Run &amp;lt;code&amp;gt;yambo_nl&amp;lt;/code&amp;gt;. Calculations will take about fifteen minutes on a single processor PC, you have time to study the next section that explains how non-linear response is extracted from the real-time simulations.&lt;br /&gt;
In order to speed up calculations, you can run them in parallel.&lt;br /&gt;
&lt;br /&gt;
==Non-linear response with Yambo==&lt;br /&gt;
&lt;br /&gt;
In order to calculate the non-linear response, the system is excited with different laser fields with a sinusoidal shape at frequencies &amp;lt;math&amp;gt;\omega_1, \omega_2, .... , \omega_n &amp;lt;/math&amp;gt; determined by the parameters [[Variables#NLEnRangev|NLEnRange]] and [[Variables#NLEnSteps|NLEnSteps]]. A dephasing term is added to the Hamiltonian &amp;lt;math&amp;gt;\gamma = &amp;lt;/math&amp;gt;[[Variables#NLDamping|NLDamping]] to simulate a finite broadening and to remove the eigenmodes that are excited by the sudden turning on of the external field. After the dephasing time the outgoing signal is analyzed to extract the non-linear coefficients as shown in the figure below: &lt;br /&gt;
&lt;br /&gt;
[[File:Pt analysis.png|600px|center|Non-linear response analysis]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the report file &amp;lt;code&amp;gt;r_nlinear&amp;lt;/code&amp;gt; you will find the length of the dephasing part and of the sampling one:&lt;br /&gt;
&lt;br /&gt;
  Dephasing Time          [fs]: 52.65695&lt;br /&gt;
  Sampling  Time          [fs]:  4.18566&lt;br /&gt;
  Total simulation time   [fs]: 56.84262                     &lt;br /&gt;
The length of the dephasing interval is inversely proportional to the damping term &amp;lt;math&amp;gt;T_{depth} \simeq 1/\gamma&amp;lt;/math&amp;gt; while the length of the sampling is dictated by the smallest frequency we are interested in: &amp;lt;math&amp;gt;T_{samp} \simeq 1/\omega_1 &amp;lt;/math&amp;gt;. For this reason if &amp;lt;math&amp;gt; \omega_1=0 &amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt; \gamma = 0 &amp;lt;/math&amp;gt; simulation time goes to infinity. The response at zero frequency can be calculated as limit of small frequency perturbation.&lt;br /&gt;
You can have a look to the file &amp;lt;code&amp;gt;src/nloptics/NL_initialize.F&amp;lt;/code&amp;gt; to see how simulation lengths are defined.&lt;br /&gt;
Calculations can take some time, run them in parallel, the best number of processors = number of frequencies or reduce the number of frequencies step in the SHG.&lt;br /&gt;
&lt;br /&gt;
==Analysis of the results==&lt;br /&gt;
&lt;br /&gt;
In the sampling region we suppose that the polarization can be written as: &amp;lt;math&amp;gt;\bf{P}(t) = \sum_{n=-\infty}^{+\infty} \bf{p}_n e^{-i\omega_n t} &amp;lt;/math&amp;gt; where the coefficient &amp;lt;math&amp;gt;\bf{p}_1,...,\bf{p}_n &amp;lt;/math&amp;gt; are related to &amp;lt;math&amp;gt;\chi^{(1)},...,\chi^{(n)} &amp;lt;/math&amp;gt;. We sample the polarization signal at different times and invert the previous equation by truncating the sum at a finite order &amp;lt;ref&amp;gt;[https://arxiv.org/abs/1309.4012 Nonlinear optics from an ab initio approach by means of the dynamical Berry phase: Application to second- and third-harmonic generation in semiconductors], C. Attaccalite and M. Grüning, Phys. Rev. B 88, 235113(2013)&amp;lt;/ref&amp;gt;.&lt;br /&gt;
This is done with the command &amp;lt;code&amp;gt;ypp_nl -u&amp;lt;/code&amp;gt; that automatically produce an input with the correct values:&lt;br /&gt;
&lt;br /&gt;
 nonlinear                    # [R] NonLinear Optics Post-Processing&lt;br /&gt;
 Xorder=   &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;4  &amp;lt;/span&amp;gt;                 # Max order of the response functions&lt;br /&gt;
 % TimeRange&lt;br /&gt;
  52.65695 | -1.00000 | fs    # Time-window where processing is done&lt;br /&gt;
 % &lt;br /&gt;
 ETStpsRt= 200                # Total Energy steps&lt;br /&gt;
 % EnRngeRt&lt;br /&gt;
   0.00000 | 10.00000 | eV    # Energy range&lt;br /&gt;
 %&lt;br /&gt;
 DampMode= &amp;quot;NONE&amp;quot;             # Damping type ( NONE | LORENTZIAN | GAUSSIAN )&lt;br /&gt;
 DampFactor=  0.10000   eV    # Damping parameter&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;code&amp;gt;Xorder&amp;lt;/code&amp;gt; is the order where the previous sum is truncated, and the TimeRange specifies the sampling region. Notice that differently from the first tutorial, in this case, we do not need Damping in &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; because we already included it in the real-time dynamics. Run &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; and it will produce a file called &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;. This file contains the different components of &amp;lt;math&amp;gt;\chi^2_{xy*} &amp;lt;/math&amp;gt; and in particular the columns 6 and 7 correspond to the imaginary and real part of &amp;lt;math&amp;gt;\chi^2_{xyz} &amp;lt;/math&amp;gt;. You can plot the result with gnuplot and the command:&lt;br /&gt;
&lt;br /&gt;
 p &#039;o.YPP-X_probe_order_2&#039; u 1:(sqrt($6**2+$7**2)) w lp ps 1.5 pt 7 lw 1.5&lt;br /&gt;
&lt;br /&gt;
the result should look like&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AlAs results.png|700px|center|SHG in AlAs]]&lt;br /&gt;
&lt;br /&gt;
and compare it with the &amp;lt;math&amp;gt; \chi^2_{zxy} &amp;lt;/math&amp;gt; calculated with more frequencies and with the converged result on a &amp;lt;math&amp;gt; 18x18x18&amp;lt;/math&amp;gt; k-point grid and bands between 2 and 10. In the figure you can find also the comparison with the results of Ref. &amp;lt;ref&amp;gt;Luppi et al. [https://arxiv.org/abs/1006.2649 PRB B, &#039;&#039;&#039;82&#039;&#039;&#039;, 235201(2010)]&amp;lt;/ref&amp;gt;. &lt;br /&gt;
Notice that the QuantumEspresso results are slightly different from the Abinit ones. This is due to the different pseudo-potential employed in the calculations if pseudopotentials were the same calculation would have been identical. You can download the script to generate this plot and the converged results [http://www.attaccalite.com/lumen/tutorials/AlAs/AlAs_results.tgz here].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notice that&#039;&#039;&#039; : the following parameters are not used in the non-linear response analysis: &amp;lt;code&amp;gt; EnRngeRt&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ETStpsRt&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;DampMode&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;DampFactor&amp;lt;/code&amp;gt;. The damping factor is set directly in the real-time simulation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;System of units in Non-linear Optics&amp;lt;/span&amp;gt;&#039;&#039;&#039;: notice that in Yambo the non-linear response functions are in the gaussian system of units, for example the &amp;lt;math&amp;gt; \chi^2 (\omega) &amp;lt;/math&amp;gt;  is in cm/statvolt. In order to convert the non-linear coefficients between different system of units, you can have a look at the [https://www.attaccalite.com/tutorials_yambo/Appendix_C_Boyd.pdf Appendix C] of the book [https://www.elsevier.com/books/nonlinear-optics/boyd/978-0-12-369470-6 &amp;quot;Non-linear optics&amp;quot;  by Robert W. Boyd].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;More tutorials&amp;lt;/span&amp;gt; on non-linear response (Third harmonic generation, parallelization, spin-orbit etc..) with Yambo can be found here: [http://www.attaccalite.com/lumen/tutorials.html More Tutorials]. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Analysis of the results using YamboPy==&lt;br /&gt;
The analysis of the result performed in the previous section using &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; can be performed using python script [https://github.com/yambo-code/yambopy YamboPy].&amp;lt;br&amp;gt;&lt;br /&gt;
In YamboPy we implemented all necessary functions to reads the Yambo databases and post-process the results. Here we show how to get the SHG signal from the previous &lt;br /&gt;
simulations. We suppose you correctly installed &amp;lt;code&amp;gt;YamboPy&amp;lt;/code&amp;gt; on your PC. Go in the folder where you ran non-linear calculation and type in the python:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
 from yambopy import *&lt;br /&gt;
 NLDB=YamboNLDB()&lt;br /&gt;
 pol =NLDB.Polarization[0]&lt;br /&gt;
 time=NLDB.IO_TIME_points&lt;br /&gt;
&lt;br /&gt;
in this way you read all the Non-linear databases. If your runs are in a different folder then the &#039;SAVE&#039; one you can specify it using the command:&lt;br /&gt;
 NLDB=YamboNLDB(calc=&#039;MYJOB&#039;)&lt;br /&gt;
&lt;br /&gt;
now in the array &amp;lt;code&amp;gt;pol&amp;lt;/code&amp;gt; you have all the polarization for all laser frequencies in the three Cartesian directions, while the variable &amp;lt;code&amp;gt;time&amp;lt;/code&amp;gt; contains all the time series of your simulation.&lt;br /&gt;
Now you can get the non-linear response with the command:&lt;br /&gt;
&lt;br /&gt;
 Harmonic_Analysis(NLDB,X_order=4)&lt;br /&gt;
&lt;br /&gt;
this command will perform a Fourier analysis of the results in the same way of &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; and generate new files with all the requested harmonics &#039;&#039;o.YamboPy-X_probe_order_1&#039;&#039;, &#039;&#039;o.YamboPy-X_probe_order_2&#039;&#039; etc...&lt;br /&gt;
equivalent to the one generated by &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt;. Results can be plot with gnuplot using the command:&lt;br /&gt;
 &lt;br /&gt;
 p &#039;o.YamboPy-X_probe_order_2&#039; u 1:(sqrt($6**2+$7**2)) w lp ps 1.5 pt 7 lw 1.5&lt;br /&gt;
&lt;br /&gt;
The script that performs non-linear analysis can be found in &amp;lt;code&amp;gt;yambopy/nl/harmonic_analysis.py&amp;lt;/code&amp;gt;. &amp;lt;br&amp;gt; We strongly advice you to have a look to this script and modify it according&lt;br /&gt;
to your needs and in order to extract other non-linear response functions.&lt;br /&gt;
&lt;br /&gt;
==How to choose the external field direction for the different X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
In the X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;abc&amp;lt;/sub&amp;gt; response you have three field directions. The two components &#039;&#039;b&#039;&#039; and &#039;&#039;c&#039;&#039; are determined by the external field and the third &#039;&#039;a&#039;&#039;&lt;br /&gt;
is the direction where you measure the response.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The external field in Yambo is set using the variable&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
   1.000000 | 0.000000 | 0.000000 |        # [NL ExtF] Versor .&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
For example if you set in Yambo field direction as:&lt;br /&gt;
&lt;br /&gt;
 1.0 | 0.0 | 0.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*xx&amp;lt;/sub&amp;gt;&lt;br /&gt;
 0.0 | 1.0 | 0.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*yy&amp;lt;/sub&amp;gt;&lt;br /&gt;
 0.0 | 0.0 | 1.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*zz&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the * correspond to the different direction in the response file &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;.&lt;br /&gt;
In the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt; you have seven columns:&lt;br /&gt;
&lt;br /&gt;
 The first column is the energy [[omega]],&lt;br /&gt;
 the 2nd and 3rd columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;x**&amp;lt;/sub&amp;gt;&lt;br /&gt;
 the 4th and 5th columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;y**&amp;lt;/sub&amp;gt;&lt;br /&gt;
 the 6th and 7th columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;z**&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where the ** are the direction of the incoming field, see above.&lt;br /&gt;
&lt;br /&gt;
For example if you want to calculate the &amp;lt;math&amp;gt;\chi^{(2)}_{zxx}&amp;lt;/math&amp;gt; you put the external field in the direction &amp;lt;code&amp;gt; 1.0 | 0.0 | 0.0 |&amp;lt;/code&amp;gt;&lt;br /&gt;
and then plot the column 6 and 7 of the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt; file.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Nota bene:&#039;&#039;&#039; if you change the direction of the external field you have to remove the corresponding symmetries as explained in the tutorial &lt;br /&gt;
on [[Prerequisites for Real Time_propagation with Yambo#Reduce symmetries real-time linear response tutorial]].&lt;br /&gt;
&lt;br /&gt;
In order to get the other components of the  X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; the calculation are more involved. For example if you put field in the&lt;br /&gt;
&lt;br /&gt;
 1.0 | 1.0 | 0.0 | &lt;br /&gt;
&lt;br /&gt;
this corresponds to &amp;lt;math&amp;gt;E(t)=\frac{1}{\sqrt{2}} [ E_x(t) + E_y(t) ]&amp;lt;/math&amp;gt; and so at the second order you will have &amp;lt;math&amp;gt;E^2(t)=\frac{1}{2} \left [ E^2_x(t) + E^2_y(t) +  E_x(t) E_y(t) +  E_y(t) E_x(t) \right]&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
this means that  the X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; in the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;  will correspond to a linear combination of the following different response functions.&amp;lt;br&amp;gt;&lt;br /&gt;
For example in the the 2nd and 3rd columns are the imaginary and real part of:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{x**}=\frac{1}{2} \left [\chi^2_{xxx}+\chi^{(2)}_{xyy} + \chi^{(2)}_{xxy} + \chi^{(2)}_{xyx} \right ]&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the same for the other column replacing the first &amp;lt;code&amp;gt;x&amp;lt;/code&amp;gt; for &amp;lt;code&amp;gt;y,z&amp;lt;/code&amp;gt;.&lt;br /&gt;
If you know that some components are zero this allow you to extract the corresponding off-diagonal part of &amp;lt;math&amp;gt;\chi^{(2)}_{abc}&amp;lt;/math&amp;gt; otherwise you have to perform different calculations to get the component you are interested in. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Now we present &#039;&#039;&#039;a simple example of monolayer hBN (m-hBN)&#039;&#039;&#039;. &amp;lt;br&amp;gt; In m-hBN there is only a non-zero component of the $\chi^2$ and all the others are related by symmetry:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{yyy}=-\chi^{(2)}_{yxx}=-\chi^{(2)}_{xxy}=-\chi^{(2)}_{xyx}&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
so if you put the field in the &amp;lt;code&amp;gt;|1|1|0|&amp;lt;/code&amp;gt; direction you will get:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{x**} = \frac{1}{2} \left[\chi^{(2)}_{xxy} + \chi^{(2)}_{xyx} \right] = - \chi^{(2)}_{yyy} &amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{y**} =\frac{1}{2} \left[ \chi^{(2)}_{yyy} + \chi^{(2)}_{yxx}  \right] = 0.0 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Non-linear response of low-dimensional structures: 2D or 1D ==&lt;br /&gt;
&lt;br /&gt;
The Yambo code is a 3D periodic code, so when you want to study a low-dimensional system 2D or 1D, you have to use a supercell approach.&lt;br /&gt;
For example to simulate the non-linear response in a 2D-crystal one, can put the crystal in the xy plane and choose a larger distance in the z-direction&lt;br /&gt;
in order to reduce the interaction between the periodic replica. Clearly in this case k-point sampling will be only in the x,y directions.&lt;br /&gt;
For calculations on this type of systems, these two warnings must be taken into account:&lt;br /&gt;
&lt;br /&gt;
* if you calculate GW corrections or include electron-hole interaction in the linear/non-linear response it is a good idea to use a &#039;&#039;&#039;Coulomb cutoff&#039;&#039;&#039;, similar to the 2D BSE case  [http://www.yambo-code.org/wiki/index.php?title=How_to_treat_low_dimensional_systems How to treat low dimensional systems]. You can add the cutoff just adding the &amp;quot;-r&amp;quot; in the input generation.&lt;br /&gt;
&lt;br /&gt;
* the calculation of SHG and THG are always performed respect to the supercell, therefore you have to &#039;&#039;&#039;re-scale&#039;&#039;&#039; the result to the effective thickness of the layer, usually the inter-layer distance of the corresponding bulk material for 2D systems: &amp;lt;math&amp;gt;\chi_{rescaled}(\omega) = L_z/d_{eff} \cdot \chi(\omega) &amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;L_z&amp;lt;/math&amp;gt; is the z-dimension of the supercell, and &amp;lt;math&amp;gt;d_{eff}&amp;lt;/math&amp;gt; is the effective thickness of the 2D system.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Nota bene&#039;&#039;&#039;: Non-linear response along &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;non-periodic directions&amp;lt;/span&amp;gt; is not implemented in Yambo, the code will print zero in these directions for all response functions. We plan to implement it in a future version of the code.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Links for schools==&lt;br /&gt;
* Back to [[Rome 2023#Tutorials]]&lt;br /&gt;
* Back to [[ICTP2020]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
{| style=&amp;quot;width:100%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|style=&amp;quot;width:25%; text-align:left&amp;quot;|Prev: [[Linear response from real time simulations|Linear response from real time simulations]]&lt;br /&gt;
|style=&amp;quot;width:45%; text-align:center&amp;quot;|Now: [[ICTP2020|ICTP  Tutorials]] --&amp;gt; [[Real time approach to non-linear response|Non Linear Response]] &lt;br /&gt;
|style=&amp;quot;width:50%; text-align:left&amp;quot;|Next: [[Correlation effects in the non-linear response|Correlation effects in the non-linear response ]]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Attacc</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Real_time_approach_to_non-linear_response_(SHG)&amp;diff=9153</id>
		<title>Real time approach to non-linear response (SHG)</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Real_time_approach_to_non-linear_response_(SHG)&amp;diff=9153"/>
		<updated>2025-09-27T08:42:32Z</updated>

		<summary type="html">&lt;p&gt;Attacc: /* How to choose the external field direction for the different X2 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Second Harmonic Generation in AlAs ==&lt;br /&gt;
In this tutorial, we will calculate the second harmonic generation of bulk AlAs, the Yambo databases can be downloaded here: [https://media.yambo-code.eu/educational/tutorials/files/AlAs_DBs.tar.gz AlAs_DBs.tar.gz] (10 MB). The first steps of this tutorials are the same as the one on [http://www.yambo-code.eu/wiki/index.php?title=Prerequisites_for_Real_Time_propagation_with_Yambo Prerequisites for Real-Time propagation with Yambo] with the only difference that we will work on AlAs and we will consider an external field in the direction &amp;lt;code&amp;gt; 1.000000 | 1.000000 | 0.000000 |&amp;lt;/code&amp;gt;. The DFT input are available here: [https://media.yambo-code.eu/educational/tutorials/files/AlAs_abinit.tar.gz ABINIT] or [https://media.yambo-code.eu/educational/tutorials/files/AlAs_pwscf.tar.gz QuantumEspresso].&lt;br /&gt;
You can run the DFT calculation with ABINIT with the command:&lt;br /&gt;
&lt;br /&gt;
 abinit &amp;lt; AlAs.in &amp;gt; output_AlAs                                             &lt;br /&gt;
&lt;br /&gt;
or using QuantumEspresso:&lt;br /&gt;
&lt;br /&gt;
 pw.x -inp AlAs.scf.in &amp;gt; output_scf&lt;br /&gt;
 pw.x -inp AlAs.nscf.in &amp;gt; output_scf                            &lt;br /&gt;
&lt;br /&gt;
and then import the ABINIT wave-function with the command:&lt;br /&gt;
&lt;br /&gt;
 a2y -F AlAso_DS2_WFK.nc                            &lt;br /&gt;
&lt;br /&gt;
and the QuantumEspresso one, in the folder AlAs.save with the command:&lt;br /&gt;
&lt;br /&gt;
 p2y                              &lt;br /&gt;
Now we consider an external field in the &amp;lt;code&amp;gt;[1,1,0]&amp;lt;/code&amp;gt; direction and remove symmetries not compatible with this field, as explained in the tutorial [http://www.yambo-code.eu/wiki/index.php?title=Prerequisites_for_Real_Time_propagation_with_Yambo Prerequisites for Real-Time propagation with Yambo].&lt;br /&gt;
&lt;br /&gt;
==Real-time simulation for the SHG==&lt;br /&gt;
&lt;br /&gt;
You can generate the input file with the command &amp;lt;code&amp;gt;yambo_nl -u n&amp;lt;/code&amp;gt;:&lt;br /&gt;
                       &lt;br /&gt;
 nloptics                      # [R NL] Non-linear optics&lt;br /&gt;
 % NLBands&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 3 | 6&amp;lt;/span&amp;gt; |                   # [NL] Bands&lt;br /&gt;
 %&lt;br /&gt;
 NLstep=   0.0100       fs    # [NL] Real Time step length&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;NLverbosity= &amp;quot;high&amp;quot;&amp;lt;/span&amp;gt;               # [NL] Verbosity level (low | high)&lt;br /&gt;
 NLtime=-1.000000           fs    # [NL] Simulation Time&lt;br /&gt;
 NLintegrator= &amp;quot;INVINT&amp;quot;       # [NL] Integrator (&amp;quot;EULEREXP/RK4/RK2EXP/HEUN/INVINT/CRANKNIC&amp;quot;)&lt;br /&gt;
 NLCorrelation= &amp;quot;IPA&amp;quot;         # [NL] Correlation (&amp;quot;IPA/HARTREE/TDDFT/LRC/JGM/SEX/HF&amp;quot;)&lt;br /&gt;
 NLLrcAlpha= 0.000000         # [NL] Long Range Correction&lt;br /&gt;
 % NLEnRange&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;  1.000000 | 5.000000 &amp;lt;/span&amp;gt;| eV    # [NL] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 NLEnSteps= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 5  &amp;lt;/span&amp;gt;              # [NL] Energy steps&lt;br /&gt;
 NLDamping= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 0.150000  &amp;lt;/span&amp;gt;  eV    # [NL] Damping&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 1.000000 | 1.000000 | 0.000000 &amp;lt;/span&amp;gt;|        # [RT Field1] Versor&lt;br /&gt;
 Field1_kind= &amp;quot;SOFTSIN&amp;quot;         # [NL ExtF] Kind(SIN|SOFTSIN|RES|ANTIRES|GAUSS|DELTA|QSSIN)&lt;br /&gt;
&lt;br /&gt;
The line &amp;lt;code&amp;gt;|1.000000 | 1.000000 | 0.000000 | # [RT Field1] Versor&amp;lt;/code&amp;gt; referees to the direction of the external field (x,y,0). At present only an external field is present but the code can be easily generalized to deal with more fields.&lt;br /&gt;
The default parameters of Yambo/Lumen are already tuned for second-harmonic generation, so the only thing you have to change is the band range, between 3 and 6 and the energy range between 1.0-5.0 eV and the number of energy steps in this interval that we set to 10. Notice that you cannot set to zero the lowest value of the energy range because this will requires a simulation that lasts infinite time, see below. Finally, consider that Yambo performs a separate calculation for each frequency, so if you set many energy steps the computational time grows linearly with this number.&lt;br /&gt;
Notice that we set &amp;lt;code&amp;gt;NLverbosity= &amp;quot;high&amp;quot;&amp;lt;/code&amp;gt; in this way the code will produce a file for each laser frequency containing the time dependent polarization.&lt;br /&gt;
Run &amp;lt;code&amp;gt;yambo_nl&amp;lt;/code&amp;gt;. Calculations will take about fifteen minutes on a single processor PC, you have time to study the next section that explains how non-linear response is extracted from the real-time simulations.&lt;br /&gt;
In order to speed up calculations, you can run them in parallel.&lt;br /&gt;
&lt;br /&gt;
==Non-linear response with Yambo==&lt;br /&gt;
&lt;br /&gt;
In order to calculate the non-linear response, the system is excited with different laser fields with a sinusoidal shape at frequencies &amp;lt;math&amp;gt;\omega_1, \omega_2, .... , \omega_n &amp;lt;/math&amp;gt; determined by the parameters [[Variables#NLEnRangev|NLEnRange]] and [[Variables#NLEnSteps|NLEnSteps]]. A dephasing term is added to the Hamiltonian &amp;lt;math&amp;gt;\gamma = &amp;lt;/math&amp;gt;[[Variables#NLDamping|NLDamping]] to simulate a finite broadening and to remove the eigenmodes that are excited by the sudden turning on of the external field. After the dephasing time the outgoing signal is analyzed to extract the non-linear coefficients as shown in the figure below: &lt;br /&gt;
&lt;br /&gt;
[[File:Pt analysis.png|600px|center|Non-linear response analysis]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the report file &amp;lt;code&amp;gt;r_nlinear&amp;lt;/code&amp;gt; you will find the length of the dephasing part and of the sampling one:&lt;br /&gt;
&lt;br /&gt;
  Dephasing Time          [fs]: 52.65695&lt;br /&gt;
  Sampling  Time          [fs]:  4.18566&lt;br /&gt;
  Total simulation time   [fs]: 56.84262                     &lt;br /&gt;
The length of the dephasing interval is inversely proportional to the damping term &amp;lt;math&amp;gt;T_{depth} \simeq 1/\gamma&amp;lt;/math&amp;gt; while the length of the sampling is dictated by the smallest frequency we are interested in: &amp;lt;math&amp;gt;T_{samp} \simeq 1/\omega_1 &amp;lt;/math&amp;gt;. For this reason if &amp;lt;math&amp;gt; \omega_1=0 &amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt; \gamma = 0 &amp;lt;/math&amp;gt; simulation time goes to infinity. The response at zero frequency can be calculated as limit of small frequency perturbation.&lt;br /&gt;
You can have a look to the file &amp;lt;code&amp;gt;src/nloptics/NL_initialize.F&amp;lt;/code&amp;gt; to see how simulation lengths are defined.&lt;br /&gt;
Calculations can take some time, run them in parallel, the best number of processors = number of frequencies or reduce the number of frequencies step in the SHG.&lt;br /&gt;
&lt;br /&gt;
==Analysis of the results==&lt;br /&gt;
&lt;br /&gt;
In the sampling region we suppose that the polarization can be written as: &amp;lt;math&amp;gt;\bf{P}(t) = \sum_{n=-\infty}^{+\infty} \bf{p}_n e^{-i\omega_n t} &amp;lt;/math&amp;gt; where the coefficient &amp;lt;math&amp;gt;\bf{p}_1,...,\bf{p}_n &amp;lt;/math&amp;gt; are related to &amp;lt;math&amp;gt;\chi^{(1)},...,\chi^{(n)} &amp;lt;/math&amp;gt;. We sample the polarization signal at different times and invert the previous equation by truncating the sum at a finite order &amp;lt;ref&amp;gt;[https://arxiv.org/abs/1309.4012 Nonlinear optics from an ab initio approach by means of the dynamical Berry phase: Application to second- and third-harmonic generation in semiconductors], C. Attaccalite and M. Grüning, Phys. Rev. B 88, 235113(2013)&amp;lt;/ref&amp;gt;.&lt;br /&gt;
This is done with the command &amp;lt;code&amp;gt;ypp_nl -u&amp;lt;/code&amp;gt; that automatically produce an input with the correct values:&lt;br /&gt;
&lt;br /&gt;
 nonlinear                    # [R] NonLinear Optics Post-Processing&lt;br /&gt;
 Xorder=   &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;4  &amp;lt;/span&amp;gt;                 # Max order of the response functions&lt;br /&gt;
 % TimeRange&lt;br /&gt;
  52.65695 | -1.00000 | fs    # Time-window where processing is done&lt;br /&gt;
 % &lt;br /&gt;
 ETStpsRt= 200                # Total Energy steps&lt;br /&gt;
 % EnRngeRt&lt;br /&gt;
   0.00000 | 10.00000 | eV    # Energy range&lt;br /&gt;
 %&lt;br /&gt;
 DampMode= &amp;quot;NONE&amp;quot;             # Damping type ( NONE | LORENTZIAN | GAUSSIAN )&lt;br /&gt;
 DampFactor=  0.10000   eV    # Damping parameter&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;code&amp;gt;Xorder&amp;lt;/code&amp;gt; is the order where the previous sum is truncated, and the TimeRange specifies the sampling region. Notice that differently from the first tutorial, in this case, we do not need Damping in &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; because we already included it in the real-time dynamics. Run &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; and it will produce a file called &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;. This file contains the different components of &amp;lt;math&amp;gt;\chi^2_{xy*} &amp;lt;/math&amp;gt; and in particular the columns 6 and 7 correspond to the imaginary and real part of &amp;lt;math&amp;gt;\chi^2_{xyz} &amp;lt;/math&amp;gt;. You can plot the result with gnuplot and the command:&lt;br /&gt;
&lt;br /&gt;
 p &#039;o.YPP-X_probe_order_2&#039; u 1:(sqrt($6**2+$7**2)) w lp ps 1.5 pt 7 lw 1.5&lt;br /&gt;
&lt;br /&gt;
the result should look like&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AlAs results.png|700px|center|SHG in AlAs]]&lt;br /&gt;
&lt;br /&gt;
and compare it with the &amp;lt;math&amp;gt; \chi^2_{zxy} &amp;lt;/math&amp;gt; calculated with more frequencies and with the converged result on a &amp;lt;math&amp;gt; 18x18x18&amp;lt;/math&amp;gt; k-point grid and bands between 2 and 10. In the figure you can find also the comparison with the results of Ref. &amp;lt;ref&amp;gt;Luppi et al. [https://arxiv.org/abs/1006.2649 PRB B, &#039;&#039;&#039;82&#039;&#039;&#039;, 235201(2010)]&amp;lt;/ref&amp;gt;. &lt;br /&gt;
Notice that the QuantumEspresso results are slightly different from the Abinit ones. This is due to the different pseudo-potential employed in the calculations if pseudopotentials were the same calculation would have been identical. You can download the script to generate this plot and the converged results [http://www.attaccalite.com/lumen/tutorials/AlAs/AlAs_results.tgz here].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notice that&#039;&#039;&#039; : the following parameters are not used in the non-linear response analysis: &amp;lt;code&amp;gt; EnRngeRt&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ETStpsRt&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;DampMode&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;DampFactor&amp;lt;/code&amp;gt;. The damping factor is set directly in the real-time simulation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;System of units in Non-linear Optics&amp;lt;/span&amp;gt;&#039;&#039;&#039;: notice that in Yambo the non-linear response functions are in the gaussian system of units, for example the &amp;lt;math&amp;gt; \chi^2 (\omega) &amp;lt;/math&amp;gt;  is in cm/statvolt. In order to convert the non-linear coefficients between different system of units, you can have a look at the [https://www.attaccalite.com/tutorials_yambo/Appendix_C_Boyd.pdf Appendix C] of the book [https://www.elsevier.com/books/nonlinear-optics/boyd/978-0-12-369470-6 &amp;quot;Non-linear optics&amp;quot;  by Robert W. Boyd].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;More tutorials&amp;lt;/span&amp;gt; on non-linear response (Third harmonic generation, parallelization, spin-orbit etc..) with Yambo can be found here: [http://www.attaccalite.com/lumen/tutorials.html More Tutorials]. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Analysis of the results using YamboPy==&lt;br /&gt;
The analysis of the result performed in the previous section using &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; can be performed using python script [https://github.com/yambo-code/yambopy YamboPy].&amp;lt;br&amp;gt;&lt;br /&gt;
In YamboPy we implemented all necessary functions to reads the Yambo databases and post-process the results. Here we show how to get the SHG signal from the previous &lt;br /&gt;
simulations. We suppose you correctly installed &amp;lt;code&amp;gt;YamboPy&amp;lt;/code&amp;gt; on your PC. Go in the folder where you ran non-linear calculation and type in the python:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
 from yambopy import *&lt;br /&gt;
 NLDB=YamboNLDB()&lt;br /&gt;
 pol =NLDB.Polarization[0]&lt;br /&gt;
 time=NLDB.IO_TIME_points&lt;br /&gt;
&lt;br /&gt;
in this way you read all the Non-linear databases. If your runs are in a different folder then the &#039;SAVE&#039; one you can specify it using the command:&lt;br /&gt;
 NLDB=YamboNLDB(calc=&#039;MYJOB&#039;)&lt;br /&gt;
&lt;br /&gt;
now in the array &amp;lt;code&amp;gt;pol&amp;lt;/code&amp;gt; you have all the polarization for all laser frequencies in the three Cartesian directions, while the variable &amp;lt;code&amp;gt;time&amp;lt;/code&amp;gt; contains all the time series of your simulation.&lt;br /&gt;
Now you can get the non-linear response with the command:&lt;br /&gt;
&lt;br /&gt;
 Harmonic_Analysis(NLDB,X_order=4)&lt;br /&gt;
&lt;br /&gt;
this command will perform a Fourier analysis of the results in the same way of &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; and generate new files with all the requested harmonics &#039;&#039;o.YamboPy-X_probe_order_1&#039;&#039;, &#039;&#039;o.YamboPy-X_probe_order_2&#039;&#039; etc...&lt;br /&gt;
equivalent to the one generated by &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt;. Results can be plot with gnuplot using the command:&lt;br /&gt;
 &lt;br /&gt;
 p &#039;o.YamboPy-X_probe_order_2&#039; u 1:(sqrt($6**2+$7**2)) w lp ps 1.5 pt 7 lw 1.5&lt;br /&gt;
&lt;br /&gt;
The script that performs non-linear analysis can be found in &amp;lt;code&amp;gt;yambopy/nl/harmonic_analysis.py&amp;lt;/code&amp;gt;. &amp;lt;br&amp;gt; We strongly advice you to have a look to this script and modify it according&lt;br /&gt;
to your needs and in order to extract other non-linear response functions.&lt;br /&gt;
&lt;br /&gt;
==How to choose the external field direction for the different X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
In the X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;abc&amp;lt;/sub&amp;gt; response you have three field directions. The two components &#039;&#039;b&#039;&#039; and &#039;&#039;c&#039;&#039; are determined by the external field and the third &#039;&#039;a&#039;&#039;&lt;br /&gt;
is the direction where you measure the response.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The external field in Yambo is set using the variable&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
   1.000000 | 0.000000 | 0.000000 |        # [NL ExtF] Versor .&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
For example if you set in Yambo field direction as:&lt;br /&gt;
&lt;br /&gt;
 1.0 | 0.0 | 0.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*xx&amp;lt;/sub&amp;gt;&lt;br /&gt;
 0.0 | 1.0 | 0.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*yy&amp;lt;/sub&amp;gt;&lt;br /&gt;
 0.0 | 0.0 | 1.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*zz&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the * correspond to the different direction in the response file &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;.&lt;br /&gt;
In the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt; you have seven columns:&lt;br /&gt;
&lt;br /&gt;
 The first column is the energy [[omega]],&lt;br /&gt;
 the 2nd and 3rd columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;x**&amp;lt;/sub&amp;gt;&lt;br /&gt;
 the 4th and 5th columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;y**&amp;lt;/sub&amp;gt;&lt;br /&gt;
 the 6th and 7th columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;z**&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where the ** are the direction of the incoming field, see above.&lt;br /&gt;
&lt;br /&gt;
For example if you want to calculate the &amp;lt;math&amp;gt;\chi^{(2)}_{zxx}&amp;lt;/math&amp;gt; you put the external field in the direction &amp;lt;code&amp;gt; 1.0 | 0.0 | 0.0 |&amp;lt;/code&amp;gt;&lt;br /&gt;
and then plot the column 6 and 7 of the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt; file.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Nota bene:&#039;&#039;&#039; if you change the direction of the external field you have to remove the corresponding symmetries as explained in the tutorial &lt;br /&gt;
on [[Prerequisites for Real Time_propagation with Yambo#Reduce symmetries real-time linear response tutorial]].&lt;br /&gt;
&lt;br /&gt;
In order to get the other components of the  X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; the calculation are more involved. For example if you put field in the&lt;br /&gt;
&lt;br /&gt;
 1.0 | 1.0 | 0.0 | &lt;br /&gt;
&lt;br /&gt;
this corresponds to &amp;lt;math&amp;gt;E(t)=\frac{1}{\sqrt{2}} [ E_x(t) + E_y(t) ]&amp;lt;/math&amp;gt; and so at the second order you will have &amp;lt;math&amp;gt;E^2(t)=\frac{1}{2} [ E^2_x(t) + E^2_y(t) +  E_x(t) E_y(t) +  E_y(t) E_x(t) ]&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
this means that  the X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; in the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;  will correspond to a linear combination of the following different response functions.&amp;lt;br&amp;gt;&lt;br /&gt;
For example in the the 2nd and 3rd columns are the imaginary and real part of:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{x**}=\frac{1}{2} \left [\chi^2_{xxx}+\chi^{(2)}_{xyy} + \chi^{(2)}_{xxy} + \chi^{(2)}_{xyx} \right ]&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the same for the other column replacing the first &amp;lt;code&amp;gt;x&amp;lt;/code&amp;gt; for &amp;lt;code&amp;gt;y,z&amp;lt;/code&amp;gt;.&lt;br /&gt;
If you know that some components are zero this allow you to extract the corresponding off-diagonal part of &amp;lt;math&amp;gt;\chi^{(2)}_{abc}&amp;lt;/math&amp;gt; otherwise you have to perform different calculations to get the component you are interested in. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Now we present &#039;&#039;&#039;a simple example of monolayer hBN (m-hBN)&#039;&#039;&#039;. &amp;lt;br&amp;gt; In m-hBN there is only a non-zero component of the $\chi^2$ and all the others are related by symmetry:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{yyy}=-\chi^{(2)}_{yxx}=-\chi^{(2)}_{xxy}=-\chi^{(2)}_{xyx}&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
so if you put the field in the &amp;lt;code&amp;gt;|1|1|0|&amp;lt;/code&amp;gt; direction you will get:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{x**} = \frac{1}{2} \left[\chi^{(2)}_{xxy} + \chi^{(2)}_{xyx} \right] = - \chi^{(2)}_{yyy} &amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{y**} =\frac{1}{2} \left[ \chi^{(2)}_{yyy} + \chi^{(2)}_{yxx}  \right] = 0.0 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Non-linear response of low-dimensional structures: 2D or 1D ==&lt;br /&gt;
&lt;br /&gt;
The Yambo code is a 3D periodic code, so when you want to study a low-dimensional system 2D or 1D, you have to use a supercell approach.&lt;br /&gt;
For example to simulate the non-linear response in a 2D-crystal one, can put the crystal in the xy plane and choose a larger distance in the z-direction&lt;br /&gt;
in order to reduce the interaction between the periodic replica. Clearly in this case k-point sampling will be only in the x,y directions.&lt;br /&gt;
For calculations on this type of systems, these two warnings must be taken into account:&lt;br /&gt;
&lt;br /&gt;
* if you calculate GW corrections or include electron-hole interaction in the linear/non-linear response it is a good idea to use a &#039;&#039;&#039;Coulomb cutoff&#039;&#039;&#039;, similar to the 2D BSE case  [http://www.yambo-code.org/wiki/index.php?title=How_to_treat_low_dimensional_systems How to treat low dimensional systems]. You can add the cutoff just adding the &amp;quot;-r&amp;quot; in the input generation.&lt;br /&gt;
&lt;br /&gt;
* the calculation of SHG and THG are always performed respect to the supercell, therefore you have to &#039;&#039;&#039;re-scale&#039;&#039;&#039; the result to the effective thickness of the layer, usually the inter-layer distance of the corresponding bulk material for 2D systems: &amp;lt;math&amp;gt;\chi_{rescaled}(\omega) = L_z/d_{eff} \cdot \chi(\omega) &amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;L_z&amp;lt;/math&amp;gt; is the z-dimension of the supercell, and &amp;lt;math&amp;gt;d_{eff}&amp;lt;/math&amp;gt; is the effective thickness of the 2D system.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Nota bene&#039;&#039;&#039;: Non-linear response along &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;non-periodic directions&amp;lt;/span&amp;gt; is not implemented in Yambo, the code will print zero in these directions for all response functions. We plan to implement it in a future version of the code.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Links for schools==&lt;br /&gt;
* Back to [[Rome 2023#Tutorials]]&lt;br /&gt;
* Back to [[ICTP2020]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
{| style=&amp;quot;width:100%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|style=&amp;quot;width:25%; text-align:left&amp;quot;|Prev: [[Linear response from real time simulations|Linear response from real time simulations]]&lt;br /&gt;
|style=&amp;quot;width:45%; text-align:center&amp;quot;|Now: [[ICTP2020|ICTP  Tutorials]] --&amp;gt; [[Real time approach to non-linear response|Non Linear Response]] &lt;br /&gt;
|style=&amp;quot;width:50%; text-align:left&amp;quot;|Next: [[Correlation effects in the non-linear response|Correlation effects in the non-linear response ]]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Attacc</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Real_time_approach_to_non-linear_response_(SHG)&amp;diff=9152</id>
		<title>Real time approach to non-linear response (SHG)</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Real_time_approach_to_non-linear_response_(SHG)&amp;diff=9152"/>
		<updated>2025-09-27T08:42:01Z</updated>

		<summary type="html">&lt;p&gt;Attacc: /* How to choose the external field direction for the different X2 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Second Harmonic Generation in AlAs ==&lt;br /&gt;
In this tutorial, we will calculate the second harmonic generation of bulk AlAs, the Yambo databases can be downloaded here: [https://media.yambo-code.eu/educational/tutorials/files/AlAs_DBs.tar.gz AlAs_DBs.tar.gz] (10 MB). The first steps of this tutorials are the same as the one on [http://www.yambo-code.eu/wiki/index.php?title=Prerequisites_for_Real_Time_propagation_with_Yambo Prerequisites for Real-Time propagation with Yambo] with the only difference that we will work on AlAs and we will consider an external field in the direction &amp;lt;code&amp;gt; 1.000000 | 1.000000 | 0.000000 |&amp;lt;/code&amp;gt;. The DFT input are available here: [https://media.yambo-code.eu/educational/tutorials/files/AlAs_abinit.tar.gz ABINIT] or [https://media.yambo-code.eu/educational/tutorials/files/AlAs_pwscf.tar.gz QuantumEspresso].&lt;br /&gt;
You can run the DFT calculation with ABINIT with the command:&lt;br /&gt;
&lt;br /&gt;
 abinit &amp;lt; AlAs.in &amp;gt; output_AlAs                                             &lt;br /&gt;
&lt;br /&gt;
or using QuantumEspresso:&lt;br /&gt;
&lt;br /&gt;
 pw.x -inp AlAs.scf.in &amp;gt; output_scf&lt;br /&gt;
 pw.x -inp AlAs.nscf.in &amp;gt; output_scf                            &lt;br /&gt;
&lt;br /&gt;
and then import the ABINIT wave-function with the command:&lt;br /&gt;
&lt;br /&gt;
 a2y -F AlAso_DS2_WFK.nc                            &lt;br /&gt;
&lt;br /&gt;
and the QuantumEspresso one, in the folder AlAs.save with the command:&lt;br /&gt;
&lt;br /&gt;
 p2y                              &lt;br /&gt;
Now we consider an external field in the &amp;lt;code&amp;gt;[1,1,0]&amp;lt;/code&amp;gt; direction and remove symmetries not compatible with this field, as explained in the tutorial [http://www.yambo-code.eu/wiki/index.php?title=Prerequisites_for_Real_Time_propagation_with_Yambo Prerequisites for Real-Time propagation with Yambo].&lt;br /&gt;
&lt;br /&gt;
==Real-time simulation for the SHG==&lt;br /&gt;
&lt;br /&gt;
You can generate the input file with the command &amp;lt;code&amp;gt;yambo_nl -u n&amp;lt;/code&amp;gt;:&lt;br /&gt;
                       &lt;br /&gt;
 nloptics                      # [R NL] Non-linear optics&lt;br /&gt;
 % NLBands&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 3 | 6&amp;lt;/span&amp;gt; |                   # [NL] Bands&lt;br /&gt;
 %&lt;br /&gt;
 NLstep=   0.0100       fs    # [NL] Real Time step length&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;NLverbosity= &amp;quot;high&amp;quot;&amp;lt;/span&amp;gt;               # [NL] Verbosity level (low | high)&lt;br /&gt;
 NLtime=-1.000000           fs    # [NL] Simulation Time&lt;br /&gt;
 NLintegrator= &amp;quot;INVINT&amp;quot;       # [NL] Integrator (&amp;quot;EULEREXP/RK4/RK2EXP/HEUN/INVINT/CRANKNIC&amp;quot;)&lt;br /&gt;
 NLCorrelation= &amp;quot;IPA&amp;quot;         # [NL] Correlation (&amp;quot;IPA/HARTREE/TDDFT/LRC/JGM/SEX/HF&amp;quot;)&lt;br /&gt;
 NLLrcAlpha= 0.000000         # [NL] Long Range Correction&lt;br /&gt;
 % NLEnRange&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;  1.000000 | 5.000000 &amp;lt;/span&amp;gt;| eV    # [NL] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 NLEnSteps= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 5  &amp;lt;/span&amp;gt;              # [NL] Energy steps&lt;br /&gt;
 NLDamping= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 0.150000  &amp;lt;/span&amp;gt;  eV    # [NL] Damping&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 1.000000 | 1.000000 | 0.000000 &amp;lt;/span&amp;gt;|        # [RT Field1] Versor&lt;br /&gt;
 Field1_kind= &amp;quot;SOFTSIN&amp;quot;         # [NL ExtF] Kind(SIN|SOFTSIN|RES|ANTIRES|GAUSS|DELTA|QSSIN)&lt;br /&gt;
&lt;br /&gt;
The line &amp;lt;code&amp;gt;|1.000000 | 1.000000 | 0.000000 | # [RT Field1] Versor&amp;lt;/code&amp;gt; referees to the direction of the external field (x,y,0). At present only an external field is present but the code can be easily generalized to deal with more fields.&lt;br /&gt;
The default parameters of Yambo/Lumen are already tuned for second-harmonic generation, so the only thing you have to change is the band range, between 3 and 6 and the energy range between 1.0-5.0 eV and the number of energy steps in this interval that we set to 10. Notice that you cannot set to zero the lowest value of the energy range because this will requires a simulation that lasts infinite time, see below. Finally, consider that Yambo performs a separate calculation for each frequency, so if you set many energy steps the computational time grows linearly with this number.&lt;br /&gt;
Notice that we set &amp;lt;code&amp;gt;NLverbosity= &amp;quot;high&amp;quot;&amp;lt;/code&amp;gt; in this way the code will produce a file for each laser frequency containing the time dependent polarization.&lt;br /&gt;
Run &amp;lt;code&amp;gt;yambo_nl&amp;lt;/code&amp;gt;. Calculations will take about fifteen minutes on a single processor PC, you have time to study the next section that explains how non-linear response is extracted from the real-time simulations.&lt;br /&gt;
In order to speed up calculations, you can run them in parallel.&lt;br /&gt;
&lt;br /&gt;
==Non-linear response with Yambo==&lt;br /&gt;
&lt;br /&gt;
In order to calculate the non-linear response, the system is excited with different laser fields with a sinusoidal shape at frequencies &amp;lt;math&amp;gt;\omega_1, \omega_2, .... , \omega_n &amp;lt;/math&amp;gt; determined by the parameters [[Variables#NLEnRangev|NLEnRange]] and [[Variables#NLEnSteps|NLEnSteps]]. A dephasing term is added to the Hamiltonian &amp;lt;math&amp;gt;\gamma = &amp;lt;/math&amp;gt;[[Variables#NLDamping|NLDamping]] to simulate a finite broadening and to remove the eigenmodes that are excited by the sudden turning on of the external field. After the dephasing time the outgoing signal is analyzed to extract the non-linear coefficients as shown in the figure below: &lt;br /&gt;
&lt;br /&gt;
[[File:Pt analysis.png|600px|center|Non-linear response analysis]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the report file &amp;lt;code&amp;gt;r_nlinear&amp;lt;/code&amp;gt; you will find the length of the dephasing part and of the sampling one:&lt;br /&gt;
&lt;br /&gt;
  Dephasing Time          [fs]: 52.65695&lt;br /&gt;
  Sampling  Time          [fs]:  4.18566&lt;br /&gt;
  Total simulation time   [fs]: 56.84262                     &lt;br /&gt;
The length of the dephasing interval is inversely proportional to the damping term &amp;lt;math&amp;gt;T_{depth} \simeq 1/\gamma&amp;lt;/math&amp;gt; while the length of the sampling is dictated by the smallest frequency we are interested in: &amp;lt;math&amp;gt;T_{samp} \simeq 1/\omega_1 &amp;lt;/math&amp;gt;. For this reason if &amp;lt;math&amp;gt; \omega_1=0 &amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt; \gamma = 0 &amp;lt;/math&amp;gt; simulation time goes to infinity. The response at zero frequency can be calculated as limit of small frequency perturbation.&lt;br /&gt;
You can have a look to the file &amp;lt;code&amp;gt;src/nloptics/NL_initialize.F&amp;lt;/code&amp;gt; to see how simulation lengths are defined.&lt;br /&gt;
Calculations can take some time, run them in parallel, the best number of processors = number of frequencies or reduce the number of frequencies step in the SHG.&lt;br /&gt;
&lt;br /&gt;
==Analysis of the results==&lt;br /&gt;
&lt;br /&gt;
In the sampling region we suppose that the polarization can be written as: &amp;lt;math&amp;gt;\bf{P}(t) = \sum_{n=-\infty}^{+\infty} \bf{p}_n e^{-i\omega_n t} &amp;lt;/math&amp;gt; where the coefficient &amp;lt;math&amp;gt;\bf{p}_1,...,\bf{p}_n &amp;lt;/math&amp;gt; are related to &amp;lt;math&amp;gt;\chi^{(1)},...,\chi^{(n)} &amp;lt;/math&amp;gt;. We sample the polarization signal at different times and invert the previous equation by truncating the sum at a finite order &amp;lt;ref&amp;gt;[https://arxiv.org/abs/1309.4012 Nonlinear optics from an ab initio approach by means of the dynamical Berry phase: Application to second- and third-harmonic generation in semiconductors], C. Attaccalite and M. Grüning, Phys. Rev. B 88, 235113(2013)&amp;lt;/ref&amp;gt;.&lt;br /&gt;
This is done with the command &amp;lt;code&amp;gt;ypp_nl -u&amp;lt;/code&amp;gt; that automatically produce an input with the correct values:&lt;br /&gt;
&lt;br /&gt;
 nonlinear                    # [R] NonLinear Optics Post-Processing&lt;br /&gt;
 Xorder=   &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;4  &amp;lt;/span&amp;gt;                 # Max order of the response functions&lt;br /&gt;
 % TimeRange&lt;br /&gt;
  52.65695 | -1.00000 | fs    # Time-window where processing is done&lt;br /&gt;
 % &lt;br /&gt;
 ETStpsRt= 200                # Total Energy steps&lt;br /&gt;
 % EnRngeRt&lt;br /&gt;
   0.00000 | 10.00000 | eV    # Energy range&lt;br /&gt;
 %&lt;br /&gt;
 DampMode= &amp;quot;NONE&amp;quot;             # Damping type ( NONE | LORENTZIAN | GAUSSIAN )&lt;br /&gt;
 DampFactor=  0.10000   eV    # Damping parameter&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;code&amp;gt;Xorder&amp;lt;/code&amp;gt; is the order where the previous sum is truncated, and the TimeRange specifies the sampling region. Notice that differently from the first tutorial, in this case, we do not need Damping in &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; because we already included it in the real-time dynamics. Run &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; and it will produce a file called &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;. This file contains the different components of &amp;lt;math&amp;gt;\chi^2_{xy*} &amp;lt;/math&amp;gt; and in particular the columns 6 and 7 correspond to the imaginary and real part of &amp;lt;math&amp;gt;\chi^2_{xyz} &amp;lt;/math&amp;gt;. You can plot the result with gnuplot and the command:&lt;br /&gt;
&lt;br /&gt;
 p &#039;o.YPP-X_probe_order_2&#039; u 1:(sqrt($6**2+$7**2)) w lp ps 1.5 pt 7 lw 1.5&lt;br /&gt;
&lt;br /&gt;
the result should look like&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AlAs results.png|700px|center|SHG in AlAs]]&lt;br /&gt;
&lt;br /&gt;
and compare it with the &amp;lt;math&amp;gt; \chi^2_{zxy} &amp;lt;/math&amp;gt; calculated with more frequencies and with the converged result on a &amp;lt;math&amp;gt; 18x18x18&amp;lt;/math&amp;gt; k-point grid and bands between 2 and 10. In the figure you can find also the comparison with the results of Ref. &amp;lt;ref&amp;gt;Luppi et al. [https://arxiv.org/abs/1006.2649 PRB B, &#039;&#039;&#039;82&#039;&#039;&#039;, 235201(2010)]&amp;lt;/ref&amp;gt;. &lt;br /&gt;
Notice that the QuantumEspresso results are slightly different from the Abinit ones. This is due to the different pseudo-potential employed in the calculations if pseudopotentials were the same calculation would have been identical. You can download the script to generate this plot and the converged results [http://www.attaccalite.com/lumen/tutorials/AlAs/AlAs_results.tgz here].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notice that&#039;&#039;&#039; : the following parameters are not used in the non-linear response analysis: &amp;lt;code&amp;gt; EnRngeRt&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ETStpsRt&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;DampMode&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;DampFactor&amp;lt;/code&amp;gt;. The damping factor is set directly in the real-time simulation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;System of units in Non-linear Optics&amp;lt;/span&amp;gt;&#039;&#039;&#039;: notice that in Yambo the non-linear response functions are in the gaussian system of units, for example the &amp;lt;math&amp;gt; \chi^2 (\omega) &amp;lt;/math&amp;gt;  is in cm/statvolt. In order to convert the non-linear coefficients between different system of units, you can have a look at the [https://www.attaccalite.com/tutorials_yambo/Appendix_C_Boyd.pdf Appendix C] of the book [https://www.elsevier.com/books/nonlinear-optics/boyd/978-0-12-369470-6 &amp;quot;Non-linear optics&amp;quot;  by Robert W. Boyd].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;More tutorials&amp;lt;/span&amp;gt; on non-linear response (Third harmonic generation, parallelization, spin-orbit etc..) with Yambo can be found here: [http://www.attaccalite.com/lumen/tutorials.html More Tutorials]. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Analysis of the results using YamboPy==&lt;br /&gt;
The analysis of the result performed in the previous section using &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; can be performed using python script [https://github.com/yambo-code/yambopy YamboPy].&amp;lt;br&amp;gt;&lt;br /&gt;
In YamboPy we implemented all necessary functions to reads the Yambo databases and post-process the results. Here we show how to get the SHG signal from the previous &lt;br /&gt;
simulations. We suppose you correctly installed &amp;lt;code&amp;gt;YamboPy&amp;lt;/code&amp;gt; on your PC. Go in the folder where you ran non-linear calculation and type in the python:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
 from yambopy import *&lt;br /&gt;
 NLDB=YamboNLDB()&lt;br /&gt;
 pol =NLDB.Polarization[0]&lt;br /&gt;
 time=NLDB.IO_TIME_points&lt;br /&gt;
&lt;br /&gt;
in this way you read all the Non-linear databases. If your runs are in a different folder then the &#039;SAVE&#039; one you can specify it using the command:&lt;br /&gt;
 NLDB=YamboNLDB(calc=&#039;MYJOB&#039;)&lt;br /&gt;
&lt;br /&gt;
now in the array &amp;lt;code&amp;gt;pol&amp;lt;/code&amp;gt; you have all the polarization for all laser frequencies in the three Cartesian directions, while the variable &amp;lt;code&amp;gt;time&amp;lt;/code&amp;gt; contains all the time series of your simulation.&lt;br /&gt;
Now you can get the non-linear response with the command:&lt;br /&gt;
&lt;br /&gt;
 Harmonic_Analysis(NLDB,X_order=4)&lt;br /&gt;
&lt;br /&gt;
this command will perform a Fourier analysis of the results in the same way of &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; and generate new files with all the requested harmonics &#039;&#039;o.YamboPy-X_probe_order_1&#039;&#039;, &#039;&#039;o.YamboPy-X_probe_order_2&#039;&#039; etc...&lt;br /&gt;
equivalent to the one generated by &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt;. Results can be plot with gnuplot using the command:&lt;br /&gt;
 &lt;br /&gt;
 p &#039;o.YamboPy-X_probe_order_2&#039; u 1:(sqrt($6**2+$7**2)) w lp ps 1.5 pt 7 lw 1.5&lt;br /&gt;
&lt;br /&gt;
The script that performs non-linear analysis can be found in &amp;lt;code&amp;gt;yambopy/nl/harmonic_analysis.py&amp;lt;/code&amp;gt;. &amp;lt;br&amp;gt; We strongly advice you to have a look to this script and modify it according&lt;br /&gt;
to your needs and in order to extract other non-linear response functions.&lt;br /&gt;
&lt;br /&gt;
==How to choose the external field direction for the different X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
In the X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;abc&amp;lt;/sub&amp;gt; response you have three field directions. The two components &#039;&#039;b&#039;&#039; and &#039;&#039;c&#039;&#039; are determined by the external field and the third &#039;&#039;a&#039;&#039;&lt;br /&gt;
is the direction where you measure the response.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The external field in Yambo is set using the variable&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
   1.000000 | 0.000000 | 0.000000 |        # [NL ExtF] Versor .&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
For example if you set in Yambo field direction as:&lt;br /&gt;
&lt;br /&gt;
 1.0 | 0.0 | 0.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*xx&amp;lt;/sub&amp;gt;&lt;br /&gt;
 0.0 | 1.0 | 0.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*yy&amp;lt;/sub&amp;gt;&lt;br /&gt;
 0.0 | 0.0 | 1.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*zz&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the * correspond to the different direction in the response file &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;.&lt;br /&gt;
In the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt; you have seven columns:&lt;br /&gt;
&lt;br /&gt;
 The first column is the energy [[omega]],&lt;br /&gt;
 the 2nd and 3rd columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;x**&amp;lt;/sub&amp;gt;&lt;br /&gt;
 the 4th and 5th columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;y**&amp;lt;/sub&amp;gt;&lt;br /&gt;
 the 6th and 7th columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;z**&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where the ** are the direction of the incoming field, see above.&lt;br /&gt;
&lt;br /&gt;
For example if you want to calculate the &amp;lt;math&amp;gt;\chi^{(2)}_{zxx}&amp;lt;/math&amp;gt; you put the external field in the direction &amp;lt;code&amp;gt; 1.0 | 0.0 | 0.0 |&amp;lt;/code&amp;gt;&lt;br /&gt;
and then plot the column 6 and 7 of the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt; file.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Nota bene:&#039;&#039;&#039; if you change the direction of the external field you have to remove the corresponding symmetries as explained in the tutorial &lt;br /&gt;
on [[Prerequisites for Real Time_propagation with Yambo#Reduce symmetries real-time linear response tutorial]].&lt;br /&gt;
&lt;br /&gt;
In order to get the other components of the  X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; the calculation are more involved. For example if you put field in the&lt;br /&gt;
&lt;br /&gt;
 1.0 | 1.0 | 0.0 | &lt;br /&gt;
&lt;br /&gt;
this corresponds to &amp;lt;math&amp;gt;E(t)=\frac{1}{\sqrt{2}} [ E_x(t) + E_y(t) ]&amp;lt;/math&amp;gt; and so at the second order you will have &amp;lt;math&amp;gt;E^2(t)=\frac{1}{2} [ E^2_x(t) + E^2_y(t) +  E_x(t) E_y(t) +  E_y(t) E_x(t) ]&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
this means that  the X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; in the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;  will correspond to a linear combination of the following different response functions.&amp;lt;br&amp;gt;&lt;br /&gt;
For example in the the 2nd and 3rd columns are the imaginary and real part of:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{x**}=\frac{1}{2} \left [\chi^2_{xxx}+\chi^{(2)}_{xyy} + \chi^{(2)}_{xxy} + \chi^{(2)}_{xyx} \right ]&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the same for the other column replacing the first &amp;lt;code&amp;gt;x&amp;lt;/code&amp;gt; for &amp;lt;code&amp;gt;y,z&amp;lt;/code&amp;gt;.&lt;br /&gt;
If you know that some components are zero this allow you to extract the corresponding off-diagonal part of &amp;lt;math&amp;gt;\chi^{(2)}_{abc}&amp;lt;/math&amp;gt; otherwise you have to perform different calculations to get the component you are interested in. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Now we present &#039;&#039;&#039;a simple example of monolayer hBN (m-hBN)&#039;&#039;&#039;. &amp;lt;br&amp;gt; In m-hBN there is only a non-zero component of the $\chi^2$ and all the others are related by symmetry:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{yyy}=-\chi^{(2)}_{yxx}=-\chi^{(2)}_{xxy}=-\chi^{(2)}_{xyx}&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
so if you put the field in the &amp;lt;code&amp;gt;|1|1|0|&amp;lt;/code&amp;gt; direction you will get:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{x**} = \frac{1}{2} \left[\chi^{(2)}_{xxy} + \chi^{(2)}_{xyx} \right] = - \chi^{(2)}_{yyy} &amp;lt;/math&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{y**} =\frac{1}{2} \left[ \chi^{(2)}_{yyy} + \chi^{(2)}_{yxx}  \right] = 0.0 &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Non-linear response of low-dimensional structures: 2D or 1D ==&lt;br /&gt;
&lt;br /&gt;
The Yambo code is a 3D periodic code, so when you want to study a low-dimensional system 2D or 1D, you have to use a supercell approach.&lt;br /&gt;
For example to simulate the non-linear response in a 2D-crystal one, can put the crystal in the xy plane and choose a larger distance in the z-direction&lt;br /&gt;
in order to reduce the interaction between the periodic replica. Clearly in this case k-point sampling will be only in the x,y directions.&lt;br /&gt;
For calculations on this type of systems, these two warnings must be taken into account:&lt;br /&gt;
&lt;br /&gt;
* if you calculate GW corrections or include electron-hole interaction in the linear/non-linear response it is a good idea to use a &#039;&#039;&#039;Coulomb cutoff&#039;&#039;&#039;, similar to the 2D BSE case  [http://www.yambo-code.org/wiki/index.php?title=How_to_treat_low_dimensional_systems How to treat low dimensional systems]. You can add the cutoff just adding the &amp;quot;-r&amp;quot; in the input generation.&lt;br /&gt;
&lt;br /&gt;
* the calculation of SHG and THG are always performed respect to the supercell, therefore you have to &#039;&#039;&#039;re-scale&#039;&#039;&#039; the result to the effective thickness of the layer, usually the inter-layer distance of the corresponding bulk material for 2D systems: &amp;lt;math&amp;gt;\chi_{rescaled}(\omega) = L_z/d_{eff} \cdot \chi(\omega) &amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;L_z&amp;lt;/math&amp;gt; is the z-dimension of the supercell, and &amp;lt;math&amp;gt;d_{eff}&amp;lt;/math&amp;gt; is the effective thickness of the 2D system.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Nota bene&#039;&#039;&#039;: Non-linear response along &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;non-periodic directions&amp;lt;/span&amp;gt; is not implemented in Yambo, the code will print zero in these directions for all response functions. We plan to implement it in a future version of the code.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Links for schools==&lt;br /&gt;
* Back to [[Rome 2023#Tutorials]]&lt;br /&gt;
* Back to [[ICTP2020]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
{| style=&amp;quot;width:100%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|style=&amp;quot;width:25%; text-align:left&amp;quot;|Prev: [[Linear response from real time simulations|Linear response from real time simulations]]&lt;br /&gt;
|style=&amp;quot;width:45%; text-align:center&amp;quot;|Now: [[ICTP2020|ICTP  Tutorials]] --&amp;gt; [[Real time approach to non-linear response|Non Linear Response]] &lt;br /&gt;
|style=&amp;quot;width:50%; text-align:left&amp;quot;|Next: [[Correlation effects in the non-linear response|Correlation effects in the non-linear response ]]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Attacc</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Real_time_approach_to_non-linear_response_(SHG)&amp;diff=9151</id>
		<title>Real time approach to non-linear response (SHG)</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Real_time_approach_to_non-linear_response_(SHG)&amp;diff=9151"/>
		<updated>2025-09-27T08:40:27Z</updated>

		<summary type="html">&lt;p&gt;Attacc: /* How to choose the external field direction for the different X2 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Second Harmonic Generation in AlAs ==&lt;br /&gt;
In this tutorial, we will calculate the second harmonic generation of bulk AlAs, the Yambo databases can be downloaded here: [https://media.yambo-code.eu/educational/tutorials/files/AlAs_DBs.tar.gz AlAs_DBs.tar.gz] (10 MB). The first steps of this tutorials are the same as the one on [http://www.yambo-code.eu/wiki/index.php?title=Prerequisites_for_Real_Time_propagation_with_Yambo Prerequisites for Real-Time propagation with Yambo] with the only difference that we will work on AlAs and we will consider an external field in the direction &amp;lt;code&amp;gt; 1.000000 | 1.000000 | 0.000000 |&amp;lt;/code&amp;gt;. The DFT input are available here: [https://media.yambo-code.eu/educational/tutorials/files/AlAs_abinit.tar.gz ABINIT] or [https://media.yambo-code.eu/educational/tutorials/files/AlAs_pwscf.tar.gz QuantumEspresso].&lt;br /&gt;
You can run the DFT calculation with ABINIT with the command:&lt;br /&gt;
&lt;br /&gt;
 abinit &amp;lt; AlAs.in &amp;gt; output_AlAs                                             &lt;br /&gt;
&lt;br /&gt;
or using QuantumEspresso:&lt;br /&gt;
&lt;br /&gt;
 pw.x -inp AlAs.scf.in &amp;gt; output_scf&lt;br /&gt;
 pw.x -inp AlAs.nscf.in &amp;gt; output_scf                            &lt;br /&gt;
&lt;br /&gt;
and then import the ABINIT wave-function with the command:&lt;br /&gt;
&lt;br /&gt;
 a2y -F AlAso_DS2_WFK.nc                            &lt;br /&gt;
&lt;br /&gt;
and the QuantumEspresso one, in the folder AlAs.save with the command:&lt;br /&gt;
&lt;br /&gt;
 p2y                              &lt;br /&gt;
Now we consider an external field in the &amp;lt;code&amp;gt;[1,1,0]&amp;lt;/code&amp;gt; direction and remove symmetries not compatible with this field, as explained in the tutorial [http://www.yambo-code.eu/wiki/index.php?title=Prerequisites_for_Real_Time_propagation_with_Yambo Prerequisites for Real-Time propagation with Yambo].&lt;br /&gt;
&lt;br /&gt;
==Real-time simulation for the SHG==&lt;br /&gt;
&lt;br /&gt;
You can generate the input file with the command &amp;lt;code&amp;gt;yambo_nl -u n&amp;lt;/code&amp;gt;:&lt;br /&gt;
                       &lt;br /&gt;
 nloptics                      # [R NL] Non-linear optics&lt;br /&gt;
 % NLBands&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 3 | 6&amp;lt;/span&amp;gt; |                   # [NL] Bands&lt;br /&gt;
 %&lt;br /&gt;
 NLstep=   0.0100       fs    # [NL] Real Time step length&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;NLverbosity= &amp;quot;high&amp;quot;&amp;lt;/span&amp;gt;               # [NL] Verbosity level (low | high)&lt;br /&gt;
 NLtime=-1.000000           fs    # [NL] Simulation Time&lt;br /&gt;
 NLintegrator= &amp;quot;INVINT&amp;quot;       # [NL] Integrator (&amp;quot;EULEREXP/RK4/RK2EXP/HEUN/INVINT/CRANKNIC&amp;quot;)&lt;br /&gt;
 NLCorrelation= &amp;quot;IPA&amp;quot;         # [NL] Correlation (&amp;quot;IPA/HARTREE/TDDFT/LRC/JGM/SEX/HF&amp;quot;)&lt;br /&gt;
 NLLrcAlpha= 0.000000         # [NL] Long Range Correction&lt;br /&gt;
 % NLEnRange&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;  1.000000 | 5.000000 &amp;lt;/span&amp;gt;| eV    # [NL] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 NLEnSteps= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 5  &amp;lt;/span&amp;gt;              # [NL] Energy steps&lt;br /&gt;
 NLDamping= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 0.150000  &amp;lt;/span&amp;gt;  eV    # [NL] Damping&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 1.000000 | 1.000000 | 0.000000 &amp;lt;/span&amp;gt;|        # [RT Field1] Versor&lt;br /&gt;
 Field1_kind= &amp;quot;SOFTSIN&amp;quot;         # [NL ExtF] Kind(SIN|SOFTSIN|RES|ANTIRES|GAUSS|DELTA|QSSIN)&lt;br /&gt;
&lt;br /&gt;
The line &amp;lt;code&amp;gt;|1.000000 | 1.000000 | 0.000000 | # [RT Field1] Versor&amp;lt;/code&amp;gt; referees to the direction of the external field (x,y,0). At present only an external field is present but the code can be easily generalized to deal with more fields.&lt;br /&gt;
The default parameters of Yambo/Lumen are already tuned for second-harmonic generation, so the only thing you have to change is the band range, between 3 and 6 and the energy range between 1.0-5.0 eV and the number of energy steps in this interval that we set to 10. Notice that you cannot set to zero the lowest value of the energy range because this will requires a simulation that lasts infinite time, see below. Finally, consider that Yambo performs a separate calculation for each frequency, so if you set many energy steps the computational time grows linearly with this number.&lt;br /&gt;
Notice that we set &amp;lt;code&amp;gt;NLverbosity= &amp;quot;high&amp;quot;&amp;lt;/code&amp;gt; in this way the code will produce a file for each laser frequency containing the time dependent polarization.&lt;br /&gt;
Run &amp;lt;code&amp;gt;yambo_nl&amp;lt;/code&amp;gt;. Calculations will take about fifteen minutes on a single processor PC, you have time to study the next section that explains how non-linear response is extracted from the real-time simulations.&lt;br /&gt;
In order to speed up calculations, you can run them in parallel.&lt;br /&gt;
&lt;br /&gt;
==Non-linear response with Yambo==&lt;br /&gt;
&lt;br /&gt;
In order to calculate the non-linear response, the system is excited with different laser fields with a sinusoidal shape at frequencies &amp;lt;math&amp;gt;\omega_1, \omega_2, .... , \omega_n &amp;lt;/math&amp;gt; determined by the parameters [[Variables#NLEnRangev|NLEnRange]] and [[Variables#NLEnSteps|NLEnSteps]]. A dephasing term is added to the Hamiltonian &amp;lt;math&amp;gt;\gamma = &amp;lt;/math&amp;gt;[[Variables#NLDamping|NLDamping]] to simulate a finite broadening and to remove the eigenmodes that are excited by the sudden turning on of the external field. After the dephasing time the outgoing signal is analyzed to extract the non-linear coefficients as shown in the figure below: &lt;br /&gt;
&lt;br /&gt;
[[File:Pt analysis.png|600px|center|Non-linear response analysis]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the report file &amp;lt;code&amp;gt;r_nlinear&amp;lt;/code&amp;gt; you will find the length of the dephasing part and of the sampling one:&lt;br /&gt;
&lt;br /&gt;
  Dephasing Time          [fs]: 52.65695&lt;br /&gt;
  Sampling  Time          [fs]:  4.18566&lt;br /&gt;
  Total simulation time   [fs]: 56.84262                     &lt;br /&gt;
The length of the dephasing interval is inversely proportional to the damping term &amp;lt;math&amp;gt;T_{depth} \simeq 1/\gamma&amp;lt;/math&amp;gt; while the length of the sampling is dictated by the smallest frequency we are interested in: &amp;lt;math&amp;gt;T_{samp} \simeq 1/\omega_1 &amp;lt;/math&amp;gt;. For this reason if &amp;lt;math&amp;gt; \omega_1=0 &amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt; \gamma = 0 &amp;lt;/math&amp;gt; simulation time goes to infinity. The response at zero frequency can be calculated as limit of small frequency perturbation.&lt;br /&gt;
You can have a look to the file &amp;lt;code&amp;gt;src/nloptics/NL_initialize.F&amp;lt;/code&amp;gt; to see how simulation lengths are defined.&lt;br /&gt;
Calculations can take some time, run them in parallel, the best number of processors = number of frequencies or reduce the number of frequencies step in the SHG.&lt;br /&gt;
&lt;br /&gt;
==Analysis of the results==&lt;br /&gt;
&lt;br /&gt;
In the sampling region we suppose that the polarization can be written as: &amp;lt;math&amp;gt;\bf{P}(t) = \sum_{n=-\infty}^{+\infty} \bf{p}_n e^{-i\omega_n t} &amp;lt;/math&amp;gt; where the coefficient &amp;lt;math&amp;gt;\bf{p}_1,...,\bf{p}_n &amp;lt;/math&amp;gt; are related to &amp;lt;math&amp;gt;\chi^{(1)},...,\chi^{(n)} &amp;lt;/math&amp;gt;. We sample the polarization signal at different times and invert the previous equation by truncating the sum at a finite order &amp;lt;ref&amp;gt;[https://arxiv.org/abs/1309.4012 Nonlinear optics from an ab initio approach by means of the dynamical Berry phase: Application to second- and third-harmonic generation in semiconductors], C. Attaccalite and M. Grüning, Phys. Rev. B 88, 235113(2013)&amp;lt;/ref&amp;gt;.&lt;br /&gt;
This is done with the command &amp;lt;code&amp;gt;ypp_nl -u&amp;lt;/code&amp;gt; that automatically produce an input with the correct values:&lt;br /&gt;
&lt;br /&gt;
 nonlinear                    # [R] NonLinear Optics Post-Processing&lt;br /&gt;
 Xorder=   &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;4  &amp;lt;/span&amp;gt;                 # Max order of the response functions&lt;br /&gt;
 % TimeRange&lt;br /&gt;
  52.65695 | -1.00000 | fs    # Time-window where processing is done&lt;br /&gt;
 % &lt;br /&gt;
 ETStpsRt= 200                # Total Energy steps&lt;br /&gt;
 % EnRngeRt&lt;br /&gt;
   0.00000 | 10.00000 | eV    # Energy range&lt;br /&gt;
 %&lt;br /&gt;
 DampMode= &amp;quot;NONE&amp;quot;             # Damping type ( NONE | LORENTZIAN | GAUSSIAN )&lt;br /&gt;
 DampFactor=  0.10000   eV    # Damping parameter&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;code&amp;gt;Xorder&amp;lt;/code&amp;gt; is the order where the previous sum is truncated, and the TimeRange specifies the sampling region. Notice that differently from the first tutorial, in this case, we do not need Damping in &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; because we already included it in the real-time dynamics. Run &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; and it will produce a file called &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;. This file contains the different components of &amp;lt;math&amp;gt;\chi^2_{xy*} &amp;lt;/math&amp;gt; and in particular the columns 6 and 7 correspond to the imaginary and real part of &amp;lt;math&amp;gt;\chi^2_{xyz} &amp;lt;/math&amp;gt;. You can plot the result with gnuplot and the command:&lt;br /&gt;
&lt;br /&gt;
 p &#039;o.YPP-X_probe_order_2&#039; u 1:(sqrt($6**2+$7**2)) w lp ps 1.5 pt 7 lw 1.5&lt;br /&gt;
&lt;br /&gt;
the result should look like&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AlAs results.png|700px|center|SHG in AlAs]]&lt;br /&gt;
&lt;br /&gt;
and compare it with the &amp;lt;math&amp;gt; \chi^2_{zxy} &amp;lt;/math&amp;gt; calculated with more frequencies and with the converged result on a &amp;lt;math&amp;gt; 18x18x18&amp;lt;/math&amp;gt; k-point grid and bands between 2 and 10. In the figure you can find also the comparison with the results of Ref. &amp;lt;ref&amp;gt;Luppi et al. [https://arxiv.org/abs/1006.2649 PRB B, &#039;&#039;&#039;82&#039;&#039;&#039;, 235201(2010)]&amp;lt;/ref&amp;gt;. &lt;br /&gt;
Notice that the QuantumEspresso results are slightly different from the Abinit ones. This is due to the different pseudo-potential employed in the calculations if pseudopotentials were the same calculation would have been identical. You can download the script to generate this plot and the converged results [http://www.attaccalite.com/lumen/tutorials/AlAs/AlAs_results.tgz here].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notice that&#039;&#039;&#039; : the following parameters are not used in the non-linear response analysis: &amp;lt;code&amp;gt; EnRngeRt&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ETStpsRt&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;DampMode&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;DampFactor&amp;lt;/code&amp;gt;. The damping factor is set directly in the real-time simulation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;System of units in Non-linear Optics&amp;lt;/span&amp;gt;&#039;&#039;&#039;: notice that in Yambo the non-linear response functions are in the gaussian system of units, for example the &amp;lt;math&amp;gt; \chi^2 (\omega) &amp;lt;/math&amp;gt;  is in cm/statvolt. In order to convert the non-linear coefficients between different system of units, you can have a look at the [https://www.attaccalite.com/tutorials_yambo/Appendix_C_Boyd.pdf Appendix C] of the book [https://www.elsevier.com/books/nonlinear-optics/boyd/978-0-12-369470-6 &amp;quot;Non-linear optics&amp;quot;  by Robert W. Boyd].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;More tutorials&amp;lt;/span&amp;gt; on non-linear response (Third harmonic generation, parallelization, spin-orbit etc..) with Yambo can be found here: [http://www.attaccalite.com/lumen/tutorials.html More Tutorials]. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Analysis of the results using YamboPy==&lt;br /&gt;
The analysis of the result performed in the previous section using &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; can be performed using python script [https://github.com/yambo-code/yambopy YamboPy].&amp;lt;br&amp;gt;&lt;br /&gt;
In YamboPy we implemented all necessary functions to reads the Yambo databases and post-process the results. Here we show how to get the SHG signal from the previous &lt;br /&gt;
simulations. We suppose you correctly installed &amp;lt;code&amp;gt;YamboPy&amp;lt;/code&amp;gt; on your PC. Go in the folder where you ran non-linear calculation and type in the python:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
 from yambopy import *&lt;br /&gt;
 NLDB=YamboNLDB()&lt;br /&gt;
 pol =NLDB.Polarization[0]&lt;br /&gt;
 time=NLDB.IO_TIME_points&lt;br /&gt;
&lt;br /&gt;
in this way you read all the Non-linear databases. If your runs are in a different folder then the &#039;SAVE&#039; one you can specify it using the command:&lt;br /&gt;
 NLDB=YamboNLDB(calc=&#039;MYJOB&#039;)&lt;br /&gt;
&lt;br /&gt;
now in the array &amp;lt;code&amp;gt;pol&amp;lt;/code&amp;gt; you have all the polarization for all laser frequencies in the three Cartesian directions, while the variable &amp;lt;code&amp;gt;time&amp;lt;/code&amp;gt; contains all the time series of your simulation.&lt;br /&gt;
Now you can get the non-linear response with the command:&lt;br /&gt;
&lt;br /&gt;
 Harmonic_Analysis(NLDB,X_order=4)&lt;br /&gt;
&lt;br /&gt;
this command will perform a Fourier analysis of the results in the same way of &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; and generate new files with all the requested harmonics &#039;&#039;o.YamboPy-X_probe_order_1&#039;&#039;, &#039;&#039;o.YamboPy-X_probe_order_2&#039;&#039; etc...&lt;br /&gt;
equivalent to the one generated by &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt;. Results can be plot with gnuplot using the command:&lt;br /&gt;
 &lt;br /&gt;
 p &#039;o.YamboPy-X_probe_order_2&#039; u 1:(sqrt($6**2+$7**2)) w lp ps 1.5 pt 7 lw 1.5&lt;br /&gt;
&lt;br /&gt;
The script that performs non-linear analysis can be found in &amp;lt;code&amp;gt;yambopy/nl/harmonic_analysis.py&amp;lt;/code&amp;gt;. &amp;lt;br&amp;gt; We strongly advice you to have a look to this script and modify it according&lt;br /&gt;
to your needs and in order to extract other non-linear response functions.&lt;br /&gt;
&lt;br /&gt;
==How to choose the external field direction for the different X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
In the X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;abc&amp;lt;/sub&amp;gt; response you have three field directions. The two components &#039;&#039;b&#039;&#039; and &#039;&#039;c&#039;&#039; are determined by the external field and the third &#039;&#039;a&#039;&#039;&lt;br /&gt;
is the direction where you measure the response.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The external field in Yambo is set using the variable&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
   1.000000 | 0.000000 | 0.000000 |        # [NL ExtF] Versor .&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
For example if you set in Yambo field direction as:&lt;br /&gt;
&lt;br /&gt;
 1.0 | 0.0 | 0.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*xx&amp;lt;/sub&amp;gt;&lt;br /&gt;
 0.0 | 1.0 | 0.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*yy&amp;lt;/sub&amp;gt;&lt;br /&gt;
 0.0 | 0.0 | 1.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*zz&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the * correspond to the different direction in the response file &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;.&lt;br /&gt;
In the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt; you have seven columns:&lt;br /&gt;
&lt;br /&gt;
 The first column is the energy [[omega]],&lt;br /&gt;
 the 2nd and 3rd columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;x**&amp;lt;/sub&amp;gt;&lt;br /&gt;
 the 4th and 5th columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;y**&amp;lt;/sub&amp;gt;&lt;br /&gt;
 the 6th and 7th columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;z**&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where the ** are the direction of the incoming field, see above.&lt;br /&gt;
&lt;br /&gt;
For example if you want to calculate the &amp;lt;math&amp;gt;\chi^{(2)}_{zxx}&amp;lt;/math&amp;gt; you put the external field in the direction &amp;lt;code&amp;gt; 1.0 | 0.0 | 0.0 |&amp;lt;/code&amp;gt;&lt;br /&gt;
and then plot the column 6 and 7 of the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt; file.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Nota bene:&#039;&#039;&#039; if you change the direction of the external field you have to remove the corresponding symmetries as explained in the tutorial &lt;br /&gt;
on [[Prerequisites for Real Time_propagation with Yambo#Reduce symmetries real-time linear response tutorial]].&lt;br /&gt;
&lt;br /&gt;
In order to get the other components of the  X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; the calculation are more involved. For example if you put field in the&lt;br /&gt;
&lt;br /&gt;
 1.0 | 1.0 | 0.0 | &lt;br /&gt;
&lt;br /&gt;
this corresponds to &amp;lt;math&amp;gt;E(t)=\frac{1}{\sqrt{2}} [ E_x(t) + E_y(t) ]&amp;lt;/math&amp;gt; and so at the second order you will have &amp;lt;math&amp;gt;E^2(t)=\frac{1}{2} [ E^2_x(t) + E^2_y(t) +  E_x(t) E_y(t) +  E_y(t) E_x(t) ]&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
this means that  the X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; in the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;  will correspond to a linear combination of the following different response functions.&amp;lt;br&amp;gt;&lt;br /&gt;
For example in the the 2nd and 3rd columns are the imaginary and real part of:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{x**}=\frac{1}{2} \left [\chi^2_{xxx}+\chi^{(2)}_{xyy} + \chi^{(2)}_{xxy} + \chi^{(2)}_{xyx} \right ]&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the same for the other column replacing the first &amp;lt;code&amp;gt;x&amp;lt;/code&amp;gt; for &amp;lt;code&amp;gt;y,z&amp;lt;/code&amp;gt;.&lt;br /&gt;
If you know that some components are zero this allow you to extract the corresponding off-diagonal part of &amp;lt;math&amp;gt;\chi^{(2)}_{abc}&amp;lt;/math&amp;gt; otherwise you have to perform different calculations to get the component you are interested in. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
Now we present &#039;&#039;&#039;a simple example of monolayer hBN (m-hBN)&#039;&#039;&#039;. &amp;lt;br&amp;gt; In m-hBN there is only a non-zero component of the $\chi^2$ and all the others are related by symmetry:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{yyy}=-\chi^{(2)}_{yxx}=-\chi^{(2)}_{xxy}=-\chi^{(2)}_{xyx}&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
so if you put the field in the &amp;lt;code&amp;gt;|1|1|0|&amp;lt;/code&amp;gt; direction you will get:&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{x**} = \frac{1}{2} \left[\chi^{(2)}_{xxy} + \chi^{(2)}_{xyx} \right] = - \chi^{(2)}_{yyy} &amp;lt;/math&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{y**} =-\chi^{(2)}_{yxx}=-\chi^{(2)}_{xxy}=-\chi^{(2)}_{xyx}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Non-linear response of low-dimensional structures: 2D or 1D ==&lt;br /&gt;
&lt;br /&gt;
The Yambo code is a 3D periodic code, so when you want to study a low-dimensional system 2D or 1D, you have to use a supercell approach.&lt;br /&gt;
For example to simulate the non-linear response in a 2D-crystal one, can put the crystal in the xy plane and choose a larger distance in the z-direction&lt;br /&gt;
in order to reduce the interaction between the periodic replica. Clearly in this case k-point sampling will be only in the x,y directions.&lt;br /&gt;
For calculations on this type of systems, these two warnings must be taken into account:&lt;br /&gt;
&lt;br /&gt;
* if you calculate GW corrections or include electron-hole interaction in the linear/non-linear response it is a good idea to use a &#039;&#039;&#039;Coulomb cutoff&#039;&#039;&#039;, similar to the 2D BSE case  [http://www.yambo-code.org/wiki/index.php?title=How_to_treat_low_dimensional_systems How to treat low dimensional systems]. You can add the cutoff just adding the &amp;quot;-r&amp;quot; in the input generation.&lt;br /&gt;
&lt;br /&gt;
* the calculation of SHG and THG are always performed respect to the supercell, therefore you have to &#039;&#039;&#039;re-scale&#039;&#039;&#039; the result to the effective thickness of the layer, usually the inter-layer distance of the corresponding bulk material for 2D systems: &amp;lt;math&amp;gt;\chi_{rescaled}(\omega) = L_z/d_{eff} \cdot \chi(\omega) &amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;L_z&amp;lt;/math&amp;gt; is the z-dimension of the supercell, and &amp;lt;math&amp;gt;d_{eff}&amp;lt;/math&amp;gt; is the effective thickness of the 2D system.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Nota bene&#039;&#039;&#039;: Non-linear response along &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;non-periodic directions&amp;lt;/span&amp;gt; is not implemented in Yambo, the code will print zero in these directions for all response functions. We plan to implement it in a future version of the code.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Links for schools==&lt;br /&gt;
* Back to [[Rome 2023#Tutorials]]&lt;br /&gt;
* Back to [[ICTP2020]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
{| style=&amp;quot;width:100%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|style=&amp;quot;width:25%; text-align:left&amp;quot;|Prev: [[Linear response from real time simulations|Linear response from real time simulations]]&lt;br /&gt;
|style=&amp;quot;width:45%; text-align:center&amp;quot;|Now: [[ICTP2020|ICTP  Tutorials]] --&amp;gt; [[Real time approach to non-linear response|Non Linear Response]] &lt;br /&gt;
|style=&amp;quot;width:50%; text-align:left&amp;quot;|Next: [[Correlation effects in the non-linear response|Correlation effects in the non-linear response ]]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Attacc</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Real_time_approach_to_non-linear_response_(SHG)&amp;diff=9150</id>
		<title>Real time approach to non-linear response (SHG)</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Real_time_approach_to_non-linear_response_(SHG)&amp;diff=9150"/>
		<updated>2025-09-27T08:39:40Z</updated>

		<summary type="html">&lt;p&gt;Attacc: /* How to choose the external field direction for the different X2 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Second Harmonic Generation in AlAs ==&lt;br /&gt;
In this tutorial, we will calculate the second harmonic generation of bulk AlAs, the Yambo databases can be downloaded here: [https://media.yambo-code.eu/educational/tutorials/files/AlAs_DBs.tar.gz AlAs_DBs.tar.gz] (10 MB). The first steps of this tutorials are the same as the one on [http://www.yambo-code.eu/wiki/index.php?title=Prerequisites_for_Real_Time_propagation_with_Yambo Prerequisites for Real-Time propagation with Yambo] with the only difference that we will work on AlAs and we will consider an external field in the direction &amp;lt;code&amp;gt; 1.000000 | 1.000000 | 0.000000 |&amp;lt;/code&amp;gt;. The DFT input are available here: [https://media.yambo-code.eu/educational/tutorials/files/AlAs_abinit.tar.gz ABINIT] or [https://media.yambo-code.eu/educational/tutorials/files/AlAs_pwscf.tar.gz QuantumEspresso].&lt;br /&gt;
You can run the DFT calculation with ABINIT with the command:&lt;br /&gt;
&lt;br /&gt;
 abinit &amp;lt; AlAs.in &amp;gt; output_AlAs                                             &lt;br /&gt;
&lt;br /&gt;
or using QuantumEspresso:&lt;br /&gt;
&lt;br /&gt;
 pw.x -inp AlAs.scf.in &amp;gt; output_scf&lt;br /&gt;
 pw.x -inp AlAs.nscf.in &amp;gt; output_scf                            &lt;br /&gt;
&lt;br /&gt;
and then import the ABINIT wave-function with the command:&lt;br /&gt;
&lt;br /&gt;
 a2y -F AlAso_DS2_WFK.nc                            &lt;br /&gt;
&lt;br /&gt;
and the QuantumEspresso one, in the folder AlAs.save with the command:&lt;br /&gt;
&lt;br /&gt;
 p2y                              &lt;br /&gt;
Now we consider an external field in the &amp;lt;code&amp;gt;[1,1,0]&amp;lt;/code&amp;gt; direction and remove symmetries not compatible with this field, as explained in the tutorial [http://www.yambo-code.eu/wiki/index.php?title=Prerequisites_for_Real_Time_propagation_with_Yambo Prerequisites for Real-Time propagation with Yambo].&lt;br /&gt;
&lt;br /&gt;
==Real-time simulation for the SHG==&lt;br /&gt;
&lt;br /&gt;
You can generate the input file with the command &amp;lt;code&amp;gt;yambo_nl -u n&amp;lt;/code&amp;gt;:&lt;br /&gt;
                       &lt;br /&gt;
 nloptics                      # [R NL] Non-linear optics&lt;br /&gt;
 % NLBands&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 3 | 6&amp;lt;/span&amp;gt; |                   # [NL] Bands&lt;br /&gt;
 %&lt;br /&gt;
 NLstep=   0.0100       fs    # [NL] Real Time step length&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;NLverbosity= &amp;quot;high&amp;quot;&amp;lt;/span&amp;gt;               # [NL] Verbosity level (low | high)&lt;br /&gt;
 NLtime=-1.000000           fs    # [NL] Simulation Time&lt;br /&gt;
 NLintegrator= &amp;quot;INVINT&amp;quot;       # [NL] Integrator (&amp;quot;EULEREXP/RK4/RK2EXP/HEUN/INVINT/CRANKNIC&amp;quot;)&lt;br /&gt;
 NLCorrelation= &amp;quot;IPA&amp;quot;         # [NL] Correlation (&amp;quot;IPA/HARTREE/TDDFT/LRC/JGM/SEX/HF&amp;quot;)&lt;br /&gt;
 NLLrcAlpha= 0.000000         # [NL] Long Range Correction&lt;br /&gt;
 % NLEnRange&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;  1.000000 | 5.000000 &amp;lt;/span&amp;gt;| eV    # [NL] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 NLEnSteps= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 5  &amp;lt;/span&amp;gt;              # [NL] Energy steps&lt;br /&gt;
 NLDamping= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 0.150000  &amp;lt;/span&amp;gt;  eV    # [NL] Damping&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 1.000000 | 1.000000 | 0.000000 &amp;lt;/span&amp;gt;|        # [RT Field1] Versor&lt;br /&gt;
 Field1_kind= &amp;quot;SOFTSIN&amp;quot;         # [NL ExtF] Kind(SIN|SOFTSIN|RES|ANTIRES|GAUSS|DELTA|QSSIN)&lt;br /&gt;
&lt;br /&gt;
The line &amp;lt;code&amp;gt;|1.000000 | 1.000000 | 0.000000 | # [RT Field1] Versor&amp;lt;/code&amp;gt; referees to the direction of the external field (x,y,0). At present only an external field is present but the code can be easily generalized to deal with more fields.&lt;br /&gt;
The default parameters of Yambo/Lumen are already tuned for second-harmonic generation, so the only thing you have to change is the band range, between 3 and 6 and the energy range between 1.0-5.0 eV and the number of energy steps in this interval that we set to 10. Notice that you cannot set to zero the lowest value of the energy range because this will requires a simulation that lasts infinite time, see below. Finally, consider that Yambo performs a separate calculation for each frequency, so if you set many energy steps the computational time grows linearly with this number.&lt;br /&gt;
Notice that we set &amp;lt;code&amp;gt;NLverbosity= &amp;quot;high&amp;quot;&amp;lt;/code&amp;gt; in this way the code will produce a file for each laser frequency containing the time dependent polarization.&lt;br /&gt;
Run &amp;lt;code&amp;gt;yambo_nl&amp;lt;/code&amp;gt;. Calculations will take about fifteen minutes on a single processor PC, you have time to study the next section that explains how non-linear response is extracted from the real-time simulations.&lt;br /&gt;
In order to speed up calculations, you can run them in parallel.&lt;br /&gt;
&lt;br /&gt;
==Non-linear response with Yambo==&lt;br /&gt;
&lt;br /&gt;
In order to calculate the non-linear response, the system is excited with different laser fields with a sinusoidal shape at frequencies &amp;lt;math&amp;gt;\omega_1, \omega_2, .... , \omega_n &amp;lt;/math&amp;gt; determined by the parameters [[Variables#NLEnRangev|NLEnRange]] and [[Variables#NLEnSteps|NLEnSteps]]. A dephasing term is added to the Hamiltonian &amp;lt;math&amp;gt;\gamma = &amp;lt;/math&amp;gt;[[Variables#NLDamping|NLDamping]] to simulate a finite broadening and to remove the eigenmodes that are excited by the sudden turning on of the external field. After the dephasing time the outgoing signal is analyzed to extract the non-linear coefficients as shown in the figure below: &lt;br /&gt;
&lt;br /&gt;
[[File:Pt analysis.png|600px|center|Non-linear response analysis]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the report file &amp;lt;code&amp;gt;r_nlinear&amp;lt;/code&amp;gt; you will find the length of the dephasing part and of the sampling one:&lt;br /&gt;
&lt;br /&gt;
  Dephasing Time          [fs]: 52.65695&lt;br /&gt;
  Sampling  Time          [fs]:  4.18566&lt;br /&gt;
  Total simulation time   [fs]: 56.84262                     &lt;br /&gt;
The length of the dephasing interval is inversely proportional to the damping term &amp;lt;math&amp;gt;T_{depth} \simeq 1/\gamma&amp;lt;/math&amp;gt; while the length of the sampling is dictated by the smallest frequency we are interested in: &amp;lt;math&amp;gt;T_{samp} \simeq 1/\omega_1 &amp;lt;/math&amp;gt;. For this reason if &amp;lt;math&amp;gt; \omega_1=0 &amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt; \gamma = 0 &amp;lt;/math&amp;gt; simulation time goes to infinity. The response at zero frequency can be calculated as limit of small frequency perturbation.&lt;br /&gt;
You can have a look to the file &amp;lt;code&amp;gt;src/nloptics/NL_initialize.F&amp;lt;/code&amp;gt; to see how simulation lengths are defined.&lt;br /&gt;
Calculations can take some time, run them in parallel, the best number of processors = number of frequencies or reduce the number of frequencies step in the SHG.&lt;br /&gt;
&lt;br /&gt;
==Analysis of the results==&lt;br /&gt;
&lt;br /&gt;
In the sampling region we suppose that the polarization can be written as: &amp;lt;math&amp;gt;\bf{P}(t) = \sum_{n=-\infty}^{+\infty} \bf{p}_n e^{-i\omega_n t} &amp;lt;/math&amp;gt; where the coefficient &amp;lt;math&amp;gt;\bf{p}_1,...,\bf{p}_n &amp;lt;/math&amp;gt; are related to &amp;lt;math&amp;gt;\chi^{(1)},...,\chi^{(n)} &amp;lt;/math&amp;gt;. We sample the polarization signal at different times and invert the previous equation by truncating the sum at a finite order &amp;lt;ref&amp;gt;[https://arxiv.org/abs/1309.4012 Nonlinear optics from an ab initio approach by means of the dynamical Berry phase: Application to second- and third-harmonic generation in semiconductors], C. Attaccalite and M. Grüning, Phys. Rev. B 88, 235113(2013)&amp;lt;/ref&amp;gt;.&lt;br /&gt;
This is done with the command &amp;lt;code&amp;gt;ypp_nl -u&amp;lt;/code&amp;gt; that automatically produce an input with the correct values:&lt;br /&gt;
&lt;br /&gt;
 nonlinear                    # [R] NonLinear Optics Post-Processing&lt;br /&gt;
 Xorder=   &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;4  &amp;lt;/span&amp;gt;                 # Max order of the response functions&lt;br /&gt;
 % TimeRange&lt;br /&gt;
  52.65695 | -1.00000 | fs    # Time-window where processing is done&lt;br /&gt;
 % &lt;br /&gt;
 ETStpsRt= 200                # Total Energy steps&lt;br /&gt;
 % EnRngeRt&lt;br /&gt;
   0.00000 | 10.00000 | eV    # Energy range&lt;br /&gt;
 %&lt;br /&gt;
 DampMode= &amp;quot;NONE&amp;quot;             # Damping type ( NONE | LORENTZIAN | GAUSSIAN )&lt;br /&gt;
 DampFactor=  0.10000   eV    # Damping parameter&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;code&amp;gt;Xorder&amp;lt;/code&amp;gt; is the order where the previous sum is truncated, and the TimeRange specifies the sampling region. Notice that differently from the first tutorial, in this case, we do not need Damping in &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; because we already included it in the real-time dynamics. Run &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; and it will produce a file called &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;. This file contains the different components of &amp;lt;math&amp;gt;\chi^2_{xy*} &amp;lt;/math&amp;gt; and in particular the columns 6 and 7 correspond to the imaginary and real part of &amp;lt;math&amp;gt;\chi^2_{xyz} &amp;lt;/math&amp;gt;. You can plot the result with gnuplot and the command:&lt;br /&gt;
&lt;br /&gt;
 p &#039;o.YPP-X_probe_order_2&#039; u 1:(sqrt($6**2+$7**2)) w lp ps 1.5 pt 7 lw 1.5&lt;br /&gt;
&lt;br /&gt;
the result should look like&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AlAs results.png|700px|center|SHG in AlAs]]&lt;br /&gt;
&lt;br /&gt;
and compare it with the &amp;lt;math&amp;gt; \chi^2_{zxy} &amp;lt;/math&amp;gt; calculated with more frequencies and with the converged result on a &amp;lt;math&amp;gt; 18x18x18&amp;lt;/math&amp;gt; k-point grid and bands between 2 and 10. In the figure you can find also the comparison with the results of Ref. &amp;lt;ref&amp;gt;Luppi et al. [https://arxiv.org/abs/1006.2649 PRB B, &#039;&#039;&#039;82&#039;&#039;&#039;, 235201(2010)]&amp;lt;/ref&amp;gt;. &lt;br /&gt;
Notice that the QuantumEspresso results are slightly different from the Abinit ones. This is due to the different pseudo-potential employed in the calculations if pseudopotentials were the same calculation would have been identical. You can download the script to generate this plot and the converged results [http://www.attaccalite.com/lumen/tutorials/AlAs/AlAs_results.tgz here].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notice that&#039;&#039;&#039; : the following parameters are not used in the non-linear response analysis: &amp;lt;code&amp;gt; EnRngeRt&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ETStpsRt&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;DampMode&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;DampFactor&amp;lt;/code&amp;gt;. The damping factor is set directly in the real-time simulation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;System of units in Non-linear Optics&amp;lt;/span&amp;gt;&#039;&#039;&#039;: notice that in Yambo the non-linear response functions are in the gaussian system of units, for example the &amp;lt;math&amp;gt; \chi^2 (\omega) &amp;lt;/math&amp;gt;  is in cm/statvolt. In order to convert the non-linear coefficients between different system of units, you can have a look at the [https://www.attaccalite.com/tutorials_yambo/Appendix_C_Boyd.pdf Appendix C] of the book [https://www.elsevier.com/books/nonlinear-optics/boyd/978-0-12-369470-6 &amp;quot;Non-linear optics&amp;quot;  by Robert W. Boyd].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;More tutorials&amp;lt;/span&amp;gt; on non-linear response (Third harmonic generation, parallelization, spin-orbit etc..) with Yambo can be found here: [http://www.attaccalite.com/lumen/tutorials.html More Tutorials]. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Analysis of the results using YamboPy==&lt;br /&gt;
The analysis of the result performed in the previous section using &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; can be performed using python script [https://github.com/yambo-code/yambopy YamboPy].&amp;lt;br&amp;gt;&lt;br /&gt;
In YamboPy we implemented all necessary functions to reads the Yambo databases and post-process the results. Here we show how to get the SHG signal from the previous &lt;br /&gt;
simulations. We suppose you correctly installed &amp;lt;code&amp;gt;YamboPy&amp;lt;/code&amp;gt; on your PC. Go in the folder where you ran non-linear calculation and type in the python:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
 from yambopy import *&lt;br /&gt;
 NLDB=YamboNLDB()&lt;br /&gt;
 pol =NLDB.Polarization[0]&lt;br /&gt;
 time=NLDB.IO_TIME_points&lt;br /&gt;
&lt;br /&gt;
in this way you read all the Non-linear databases. If your runs are in a different folder then the &#039;SAVE&#039; one you can specify it using the command:&lt;br /&gt;
 NLDB=YamboNLDB(calc=&#039;MYJOB&#039;)&lt;br /&gt;
&lt;br /&gt;
now in the array &amp;lt;code&amp;gt;pol&amp;lt;/code&amp;gt; you have all the polarization for all laser frequencies in the three Cartesian directions, while the variable &amp;lt;code&amp;gt;time&amp;lt;/code&amp;gt; contains all the time series of your simulation.&lt;br /&gt;
Now you can get the non-linear response with the command:&lt;br /&gt;
&lt;br /&gt;
 Harmonic_Analysis(NLDB,X_order=4)&lt;br /&gt;
&lt;br /&gt;
this command will perform a Fourier analysis of the results in the same way of &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; and generate new files with all the requested harmonics &#039;&#039;o.YamboPy-X_probe_order_1&#039;&#039;, &#039;&#039;o.YamboPy-X_probe_order_2&#039;&#039; etc...&lt;br /&gt;
equivalent to the one generated by &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt;. Results can be plot with gnuplot using the command:&lt;br /&gt;
 &lt;br /&gt;
 p &#039;o.YamboPy-X_probe_order_2&#039; u 1:(sqrt($6**2+$7**2)) w lp ps 1.5 pt 7 lw 1.5&lt;br /&gt;
&lt;br /&gt;
The script that performs non-linear analysis can be found in &amp;lt;code&amp;gt;yambopy/nl/harmonic_analysis.py&amp;lt;/code&amp;gt;. &amp;lt;br&amp;gt; We strongly advice you to have a look to this script and modify it according&lt;br /&gt;
to your needs and in order to extract other non-linear response functions.&lt;br /&gt;
&lt;br /&gt;
==How to choose the external field direction for the different X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
In the X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;abc&amp;lt;/sub&amp;gt; response you have three field directions. The two components &#039;&#039;b&#039;&#039; and &#039;&#039;c&#039;&#039; are determined by the external field and the third &#039;&#039;a&#039;&#039;&lt;br /&gt;
is the direction where you measure the response.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The external field in Yambo is set using the variable&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
   1.000000 | 0.000000 | 0.000000 |        # [NL ExtF] Versor .&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
For example if you set in Yambo field direction as:&lt;br /&gt;
&lt;br /&gt;
 1.0 | 0.0 | 0.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*xx&amp;lt;/sub&amp;gt;&lt;br /&gt;
 0.0 | 1.0 | 0.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*yy&amp;lt;/sub&amp;gt;&lt;br /&gt;
 0.0 | 0.0 | 1.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*zz&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the * correspond to the different direction in the response file &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;.&lt;br /&gt;
In the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt; you have seven columns:&lt;br /&gt;
&lt;br /&gt;
 The first column is the energy [[omega]],&lt;br /&gt;
 the 2nd and 3rd columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;x**&amp;lt;/sub&amp;gt;&lt;br /&gt;
 the 4th and 5th columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;y**&amp;lt;/sub&amp;gt;&lt;br /&gt;
 the 6th and 7th columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;z**&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where the ** are the direction of the incoming field, see above.&lt;br /&gt;
&lt;br /&gt;
For example if you want to calculate the &amp;lt;math&amp;gt;\chi^{(2)}_{zxx}&amp;lt;/math&amp;gt; you put the external field in the direction &amp;lt;code&amp;gt; 1.0 | 0.0 | 0.0 |&amp;lt;/code&amp;gt;&lt;br /&gt;
and then plot the column 6 and 7 of the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt; file.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Nota bene:&#039;&#039;&#039; if you change the direction of the external field you have to remove the corresponding symmetries as explained in the tutorial &lt;br /&gt;
on [[Prerequisites for Real Time_propagation with Yambo#Reduce symmetries real-time linear response tutorial]].&lt;br /&gt;
&lt;br /&gt;
In order to get the other components of the  X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; the calculation are more involved. For example if you put field in the&lt;br /&gt;
&lt;br /&gt;
 1.0 | 1.0 | 0.0 | &lt;br /&gt;
&lt;br /&gt;
this corresponds to &amp;lt;math&amp;gt;E(t)=\frac{1}{\sqrt{2}} [ E_x(t) + E_y(t) ]&amp;lt;/math&amp;gt; and so at the second order you will have &amp;lt;math&amp;gt;E^2(t)=\frac{1}{2} [ E^2_x(t) + E^2_y(t) +  E_x(t) E_y(t) +  E_y(t) E_x(t) ]&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
this means that  the X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; in the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;  will correspond to a linear combination of the following different response functions.&amp;lt;br&amp;gt;&lt;br /&gt;
For example in the the 2nd and 3rd columns are the imaginary and real part of:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{x**}=\frac{1}{2} \left [\chi^2_{xxx}+\chi^{(2)}_{xyy} + \chi^{(2)}_{xxy} + \chi^{(2)}_{xyx} \right ]&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the same for the other column replacing the first &amp;lt;code&amp;gt;x&amp;lt;/code&amp;gt; for &amp;lt;code&amp;gt;y,z&amp;lt;/code&amp;gt;.&lt;br /&gt;
If you know that some components are zero this allow you to extract the corresponding off-diagonal part of &amp;lt;math&amp;gt;\chi^{(2)}_{abc}&amp;lt;/math&amp;gt; otherwise you have to perform different calculations to get the component you are interested in. Hereafter we present a simple example of monolayer hBN (m-hBN). In m-hBN there is only a non-zero component of the $\chi^2$ and all the others are related by symmetry:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{yyy}=-\chi^{(2)}_{yxx}=-\chi^{(2)}_{xxy}=-\chi^{(2)}_{xyx}&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
so if you put the field in the &amp;lt;code&amp;gt;|1|1|0|&amp;lt;/code&amp;gt; direction you will get:&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{x**} = \frac{1}{2} \left[\chi^{(2)}_{xxy} + \chi^{(2)}_{xyx} \right] = - \chi^{(2)}_{yyy} &amp;lt;/math&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{y**} =-\chi^{(2)}_{yxx}=-\chi^{(2)}_{xxy}=-\chi^{(2)}_{xyx}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Non-linear response of low-dimensional structures: 2D or 1D ==&lt;br /&gt;
&lt;br /&gt;
The Yambo code is a 3D periodic code, so when you want to study a low-dimensional system 2D or 1D, you have to use a supercell approach.&lt;br /&gt;
For example to simulate the non-linear response in a 2D-crystal one, can put the crystal in the xy plane and choose a larger distance in the z-direction&lt;br /&gt;
in order to reduce the interaction between the periodic replica. Clearly in this case k-point sampling will be only in the x,y directions.&lt;br /&gt;
For calculations on this type of systems, these two warnings must be taken into account:&lt;br /&gt;
&lt;br /&gt;
* if you calculate GW corrections or include electron-hole interaction in the linear/non-linear response it is a good idea to use a &#039;&#039;&#039;Coulomb cutoff&#039;&#039;&#039;, similar to the 2D BSE case  [http://www.yambo-code.org/wiki/index.php?title=How_to_treat_low_dimensional_systems How to treat low dimensional systems]. You can add the cutoff just adding the &amp;quot;-r&amp;quot; in the input generation.&lt;br /&gt;
&lt;br /&gt;
* the calculation of SHG and THG are always performed respect to the supercell, therefore you have to &#039;&#039;&#039;re-scale&#039;&#039;&#039; the result to the effective thickness of the layer, usually the inter-layer distance of the corresponding bulk material for 2D systems: &amp;lt;math&amp;gt;\chi_{rescaled}(\omega) = L_z/d_{eff} \cdot \chi(\omega) &amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;L_z&amp;lt;/math&amp;gt; is the z-dimension of the supercell, and &amp;lt;math&amp;gt;d_{eff}&amp;lt;/math&amp;gt; is the effective thickness of the 2D system.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Nota bene&#039;&#039;&#039;: Non-linear response along &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;non-periodic directions&amp;lt;/span&amp;gt; is not implemented in Yambo, the code will print zero in these directions for all response functions. We plan to implement it in a future version of the code.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Links for schools==&lt;br /&gt;
* Back to [[Rome 2023#Tutorials]]&lt;br /&gt;
* Back to [[ICTP2020]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
{| style=&amp;quot;width:100%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|style=&amp;quot;width:25%; text-align:left&amp;quot;|Prev: [[Linear response from real time simulations|Linear response from real time simulations]]&lt;br /&gt;
|style=&amp;quot;width:45%; text-align:center&amp;quot;|Now: [[ICTP2020|ICTP  Tutorials]] --&amp;gt; [[Real time approach to non-linear response|Non Linear Response]] &lt;br /&gt;
|style=&amp;quot;width:50%; text-align:left&amp;quot;|Next: [[Correlation effects in the non-linear response|Correlation effects in the non-linear response ]]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Attacc</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Real_time_approach_to_non-linear_response_(SHG)&amp;diff=9149</id>
		<title>Real time approach to non-linear response (SHG)</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Real_time_approach_to_non-linear_response_(SHG)&amp;diff=9149"/>
		<updated>2025-09-27T08:38:47Z</updated>

		<summary type="html">&lt;p&gt;Attacc: /* How to choose the external field direction for the different X2 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Second Harmonic Generation in AlAs ==&lt;br /&gt;
In this tutorial, we will calculate the second harmonic generation of bulk AlAs, the Yambo databases can be downloaded here: [https://media.yambo-code.eu/educational/tutorials/files/AlAs_DBs.tar.gz AlAs_DBs.tar.gz] (10 MB). The first steps of this tutorials are the same as the one on [http://www.yambo-code.eu/wiki/index.php?title=Prerequisites_for_Real_Time_propagation_with_Yambo Prerequisites for Real-Time propagation with Yambo] with the only difference that we will work on AlAs and we will consider an external field in the direction &amp;lt;code&amp;gt; 1.000000 | 1.000000 | 0.000000 |&amp;lt;/code&amp;gt;. The DFT input are available here: [https://media.yambo-code.eu/educational/tutorials/files/AlAs_abinit.tar.gz ABINIT] or [https://media.yambo-code.eu/educational/tutorials/files/AlAs_pwscf.tar.gz QuantumEspresso].&lt;br /&gt;
You can run the DFT calculation with ABINIT with the command:&lt;br /&gt;
&lt;br /&gt;
 abinit &amp;lt; AlAs.in &amp;gt; output_AlAs                                             &lt;br /&gt;
&lt;br /&gt;
or using QuantumEspresso:&lt;br /&gt;
&lt;br /&gt;
 pw.x -inp AlAs.scf.in &amp;gt; output_scf&lt;br /&gt;
 pw.x -inp AlAs.nscf.in &amp;gt; output_scf                            &lt;br /&gt;
&lt;br /&gt;
and then import the ABINIT wave-function with the command:&lt;br /&gt;
&lt;br /&gt;
 a2y -F AlAso_DS2_WFK.nc                            &lt;br /&gt;
&lt;br /&gt;
and the QuantumEspresso one, in the folder AlAs.save with the command:&lt;br /&gt;
&lt;br /&gt;
 p2y                              &lt;br /&gt;
Now we consider an external field in the &amp;lt;code&amp;gt;[1,1,0]&amp;lt;/code&amp;gt; direction and remove symmetries not compatible with this field, as explained in the tutorial [http://www.yambo-code.eu/wiki/index.php?title=Prerequisites_for_Real_Time_propagation_with_Yambo Prerequisites for Real-Time propagation with Yambo].&lt;br /&gt;
&lt;br /&gt;
==Real-time simulation for the SHG==&lt;br /&gt;
&lt;br /&gt;
You can generate the input file with the command &amp;lt;code&amp;gt;yambo_nl -u n&amp;lt;/code&amp;gt;:&lt;br /&gt;
                       &lt;br /&gt;
 nloptics                      # [R NL] Non-linear optics&lt;br /&gt;
 % NLBands&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 3 | 6&amp;lt;/span&amp;gt; |                   # [NL] Bands&lt;br /&gt;
 %&lt;br /&gt;
 NLstep=   0.0100       fs    # [NL] Real Time step length&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;NLverbosity= &amp;quot;high&amp;quot;&amp;lt;/span&amp;gt;               # [NL] Verbosity level (low | high)&lt;br /&gt;
 NLtime=-1.000000           fs    # [NL] Simulation Time&lt;br /&gt;
 NLintegrator= &amp;quot;INVINT&amp;quot;       # [NL] Integrator (&amp;quot;EULEREXP/RK4/RK2EXP/HEUN/INVINT/CRANKNIC&amp;quot;)&lt;br /&gt;
 NLCorrelation= &amp;quot;IPA&amp;quot;         # [NL] Correlation (&amp;quot;IPA/HARTREE/TDDFT/LRC/JGM/SEX/HF&amp;quot;)&lt;br /&gt;
 NLLrcAlpha= 0.000000         # [NL] Long Range Correction&lt;br /&gt;
 % NLEnRange&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;  1.000000 | 5.000000 &amp;lt;/span&amp;gt;| eV    # [NL] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 NLEnSteps= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 5  &amp;lt;/span&amp;gt;              # [NL] Energy steps&lt;br /&gt;
 NLDamping= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 0.150000  &amp;lt;/span&amp;gt;  eV    # [NL] Damping&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 1.000000 | 1.000000 | 0.000000 &amp;lt;/span&amp;gt;|        # [RT Field1] Versor&lt;br /&gt;
 Field1_kind= &amp;quot;SOFTSIN&amp;quot;         # [NL ExtF] Kind(SIN|SOFTSIN|RES|ANTIRES|GAUSS|DELTA|QSSIN)&lt;br /&gt;
&lt;br /&gt;
The line &amp;lt;code&amp;gt;|1.000000 | 1.000000 | 0.000000 | # [RT Field1] Versor&amp;lt;/code&amp;gt; referees to the direction of the external field (x,y,0). At present only an external field is present but the code can be easily generalized to deal with more fields.&lt;br /&gt;
The default parameters of Yambo/Lumen are already tuned for second-harmonic generation, so the only thing you have to change is the band range, between 3 and 6 and the energy range between 1.0-5.0 eV and the number of energy steps in this interval that we set to 10. Notice that you cannot set to zero the lowest value of the energy range because this will requires a simulation that lasts infinite time, see below. Finally, consider that Yambo performs a separate calculation for each frequency, so if you set many energy steps the computational time grows linearly with this number.&lt;br /&gt;
Notice that we set &amp;lt;code&amp;gt;NLverbosity= &amp;quot;high&amp;quot;&amp;lt;/code&amp;gt; in this way the code will produce a file for each laser frequency containing the time dependent polarization.&lt;br /&gt;
Run &amp;lt;code&amp;gt;yambo_nl&amp;lt;/code&amp;gt;. Calculations will take about fifteen minutes on a single processor PC, you have time to study the next section that explains how non-linear response is extracted from the real-time simulations.&lt;br /&gt;
In order to speed up calculations, you can run them in parallel.&lt;br /&gt;
&lt;br /&gt;
==Non-linear response with Yambo==&lt;br /&gt;
&lt;br /&gt;
In order to calculate the non-linear response, the system is excited with different laser fields with a sinusoidal shape at frequencies &amp;lt;math&amp;gt;\omega_1, \omega_2, .... , \omega_n &amp;lt;/math&amp;gt; determined by the parameters [[Variables#NLEnRangev|NLEnRange]] and [[Variables#NLEnSteps|NLEnSteps]]. A dephasing term is added to the Hamiltonian &amp;lt;math&amp;gt;\gamma = &amp;lt;/math&amp;gt;[[Variables#NLDamping|NLDamping]] to simulate a finite broadening and to remove the eigenmodes that are excited by the sudden turning on of the external field. After the dephasing time the outgoing signal is analyzed to extract the non-linear coefficients as shown in the figure below: &lt;br /&gt;
&lt;br /&gt;
[[File:Pt analysis.png|600px|center|Non-linear response analysis]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the report file &amp;lt;code&amp;gt;r_nlinear&amp;lt;/code&amp;gt; you will find the length of the dephasing part and of the sampling one:&lt;br /&gt;
&lt;br /&gt;
  Dephasing Time          [fs]: 52.65695&lt;br /&gt;
  Sampling  Time          [fs]:  4.18566&lt;br /&gt;
  Total simulation time   [fs]: 56.84262                     &lt;br /&gt;
The length of the dephasing interval is inversely proportional to the damping term &amp;lt;math&amp;gt;T_{depth} \simeq 1/\gamma&amp;lt;/math&amp;gt; while the length of the sampling is dictated by the smallest frequency we are interested in: &amp;lt;math&amp;gt;T_{samp} \simeq 1/\omega_1 &amp;lt;/math&amp;gt;. For this reason if &amp;lt;math&amp;gt; \omega_1=0 &amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt; \gamma = 0 &amp;lt;/math&amp;gt; simulation time goes to infinity. The response at zero frequency can be calculated as limit of small frequency perturbation.&lt;br /&gt;
You can have a look to the file &amp;lt;code&amp;gt;src/nloptics/NL_initialize.F&amp;lt;/code&amp;gt; to see how simulation lengths are defined.&lt;br /&gt;
Calculations can take some time, run them in parallel, the best number of processors = number of frequencies or reduce the number of frequencies step in the SHG.&lt;br /&gt;
&lt;br /&gt;
==Analysis of the results==&lt;br /&gt;
&lt;br /&gt;
In the sampling region we suppose that the polarization can be written as: &amp;lt;math&amp;gt;\bf{P}(t) = \sum_{n=-\infty}^{+\infty} \bf{p}_n e^{-i\omega_n t} &amp;lt;/math&amp;gt; where the coefficient &amp;lt;math&amp;gt;\bf{p}_1,...,\bf{p}_n &amp;lt;/math&amp;gt; are related to &amp;lt;math&amp;gt;\chi^{(1)},...,\chi^{(n)} &amp;lt;/math&amp;gt;. We sample the polarization signal at different times and invert the previous equation by truncating the sum at a finite order &amp;lt;ref&amp;gt;[https://arxiv.org/abs/1309.4012 Nonlinear optics from an ab initio approach by means of the dynamical Berry phase: Application to second- and third-harmonic generation in semiconductors], C. Attaccalite and M. Grüning, Phys. Rev. B 88, 235113(2013)&amp;lt;/ref&amp;gt;.&lt;br /&gt;
This is done with the command &amp;lt;code&amp;gt;ypp_nl -u&amp;lt;/code&amp;gt; that automatically produce an input with the correct values:&lt;br /&gt;
&lt;br /&gt;
 nonlinear                    # [R] NonLinear Optics Post-Processing&lt;br /&gt;
 Xorder=   &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;4  &amp;lt;/span&amp;gt;                 # Max order of the response functions&lt;br /&gt;
 % TimeRange&lt;br /&gt;
  52.65695 | -1.00000 | fs    # Time-window where processing is done&lt;br /&gt;
 % &lt;br /&gt;
 ETStpsRt= 200                # Total Energy steps&lt;br /&gt;
 % EnRngeRt&lt;br /&gt;
   0.00000 | 10.00000 | eV    # Energy range&lt;br /&gt;
 %&lt;br /&gt;
 DampMode= &amp;quot;NONE&amp;quot;             # Damping type ( NONE | LORENTZIAN | GAUSSIAN )&lt;br /&gt;
 DampFactor=  0.10000   eV    # Damping parameter&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;code&amp;gt;Xorder&amp;lt;/code&amp;gt; is the order where the previous sum is truncated, and the TimeRange specifies the sampling region. Notice that differently from the first tutorial, in this case, we do not need Damping in &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; because we already included it in the real-time dynamics. Run &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; and it will produce a file called &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;. This file contains the different components of &amp;lt;math&amp;gt;\chi^2_{xy*} &amp;lt;/math&amp;gt; and in particular the columns 6 and 7 correspond to the imaginary and real part of &amp;lt;math&amp;gt;\chi^2_{xyz} &amp;lt;/math&amp;gt;. You can plot the result with gnuplot and the command:&lt;br /&gt;
&lt;br /&gt;
 p &#039;o.YPP-X_probe_order_2&#039; u 1:(sqrt($6**2+$7**2)) w lp ps 1.5 pt 7 lw 1.5&lt;br /&gt;
&lt;br /&gt;
the result should look like&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AlAs results.png|700px|center|SHG in AlAs]]&lt;br /&gt;
&lt;br /&gt;
and compare it with the &amp;lt;math&amp;gt; \chi^2_{zxy} &amp;lt;/math&amp;gt; calculated with more frequencies and with the converged result on a &amp;lt;math&amp;gt; 18x18x18&amp;lt;/math&amp;gt; k-point grid and bands between 2 and 10. In the figure you can find also the comparison with the results of Ref. &amp;lt;ref&amp;gt;Luppi et al. [https://arxiv.org/abs/1006.2649 PRB B, &#039;&#039;&#039;82&#039;&#039;&#039;, 235201(2010)]&amp;lt;/ref&amp;gt;. &lt;br /&gt;
Notice that the QuantumEspresso results are slightly different from the Abinit ones. This is due to the different pseudo-potential employed in the calculations if pseudopotentials were the same calculation would have been identical. You can download the script to generate this plot and the converged results [http://www.attaccalite.com/lumen/tutorials/AlAs/AlAs_results.tgz here].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notice that&#039;&#039;&#039; : the following parameters are not used in the non-linear response analysis: &amp;lt;code&amp;gt; EnRngeRt&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ETStpsRt&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;DampMode&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;DampFactor&amp;lt;/code&amp;gt;. The damping factor is set directly in the real-time simulation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;System of units in Non-linear Optics&amp;lt;/span&amp;gt;&#039;&#039;&#039;: notice that in Yambo the non-linear response functions are in the gaussian system of units, for example the &amp;lt;math&amp;gt; \chi^2 (\omega) &amp;lt;/math&amp;gt;  is in cm/statvolt. In order to convert the non-linear coefficients between different system of units, you can have a look at the [https://www.attaccalite.com/tutorials_yambo/Appendix_C_Boyd.pdf Appendix C] of the book [https://www.elsevier.com/books/nonlinear-optics/boyd/978-0-12-369470-6 &amp;quot;Non-linear optics&amp;quot;  by Robert W. Boyd].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;More tutorials&amp;lt;/span&amp;gt; on non-linear response (Third harmonic generation, parallelization, spin-orbit etc..) with Yambo can be found here: [http://www.attaccalite.com/lumen/tutorials.html More Tutorials]. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Analysis of the results using YamboPy==&lt;br /&gt;
The analysis of the result performed in the previous section using &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; can be performed using python script [https://github.com/yambo-code/yambopy YamboPy].&amp;lt;br&amp;gt;&lt;br /&gt;
In YamboPy we implemented all necessary functions to reads the Yambo databases and post-process the results. Here we show how to get the SHG signal from the previous &lt;br /&gt;
simulations. We suppose you correctly installed &amp;lt;code&amp;gt;YamboPy&amp;lt;/code&amp;gt; on your PC. Go in the folder where you ran non-linear calculation and type in the python:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
 from yambopy import *&lt;br /&gt;
 NLDB=YamboNLDB()&lt;br /&gt;
 pol =NLDB.Polarization[0]&lt;br /&gt;
 time=NLDB.IO_TIME_points&lt;br /&gt;
&lt;br /&gt;
in this way you read all the Non-linear databases. If your runs are in a different folder then the &#039;SAVE&#039; one you can specify it using the command:&lt;br /&gt;
 NLDB=YamboNLDB(calc=&#039;MYJOB&#039;)&lt;br /&gt;
&lt;br /&gt;
now in the array &amp;lt;code&amp;gt;pol&amp;lt;/code&amp;gt; you have all the polarization for all laser frequencies in the three Cartesian directions, while the variable &amp;lt;code&amp;gt;time&amp;lt;/code&amp;gt; contains all the time series of your simulation.&lt;br /&gt;
Now you can get the non-linear response with the command:&lt;br /&gt;
&lt;br /&gt;
 Harmonic_Analysis(NLDB,X_order=4)&lt;br /&gt;
&lt;br /&gt;
this command will perform a Fourier analysis of the results in the same way of &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; and generate new files with all the requested harmonics &#039;&#039;o.YamboPy-X_probe_order_1&#039;&#039;, &#039;&#039;o.YamboPy-X_probe_order_2&#039;&#039; etc...&lt;br /&gt;
equivalent to the one generated by &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt;. Results can be plot with gnuplot using the command:&lt;br /&gt;
 &lt;br /&gt;
 p &#039;o.YamboPy-X_probe_order_2&#039; u 1:(sqrt($6**2+$7**2)) w lp ps 1.5 pt 7 lw 1.5&lt;br /&gt;
&lt;br /&gt;
The script that performs non-linear analysis can be found in &amp;lt;code&amp;gt;yambopy/nl/harmonic_analysis.py&amp;lt;/code&amp;gt;. &amp;lt;br&amp;gt; We strongly advice you to have a look to this script and modify it according&lt;br /&gt;
to your needs and in order to extract other non-linear response functions.&lt;br /&gt;
&lt;br /&gt;
==How to choose the external field direction for the different X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
In the X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;abc&amp;lt;/sub&amp;gt; response you have three field directions. The two components &#039;&#039;b&#039;&#039; and &#039;&#039;c&#039;&#039; are determined by the external field and the third &#039;&#039;a&#039;&#039;&lt;br /&gt;
is the direction where you measure the response.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The external field in Yambo is set using the variable&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
   1.000000 | 0.000000 | 0.000000 |        # [NL ExtF] Versor .&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
For example if you set in Yambo field direction as:&lt;br /&gt;
&lt;br /&gt;
 1.0 | 0.0 | 0.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*xx&amp;lt;/sub&amp;gt;&lt;br /&gt;
 0.0 | 1.0 | 0.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*yy&amp;lt;/sub&amp;gt;&lt;br /&gt;
 0.0 | 0.0 | 1.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*zz&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the * correspond to the different direction in the response file &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;.&lt;br /&gt;
In the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt; you have seven columns:&lt;br /&gt;
&lt;br /&gt;
 The first column is the energy [[omega]],&lt;br /&gt;
 the 2nd and 3rd columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;x**&amp;lt;/sub&amp;gt;&lt;br /&gt;
 the 4th and 5th columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;y**&amp;lt;/sub&amp;gt;&lt;br /&gt;
 the 6th and 7th columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;z**&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where the ** are the direction of the incoming field, see above.&lt;br /&gt;
&lt;br /&gt;
For example if you want to calculate the &amp;lt;math&amp;gt;\chi^{(2)}_{zxx}&amp;lt;/math&amp;gt; you put the external field in the direction &amp;lt;code&amp;gt; 1.0 | 0.0 | 0.0 |&amp;lt;/code&amp;gt;&lt;br /&gt;
and then plot the column 6 and 7 of the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt; file.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Nota bene:&#039;&#039;&#039; if you change the direction of the external field you have to remove the corresponding symmetries as explained in the tutorial &lt;br /&gt;
on [[Prerequisites for Real Time_propagation with Yambo#Reduce symmetries real-time linear response tutorial]].&lt;br /&gt;
&lt;br /&gt;
In order to get the other components of the  X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; the calculation are more involved. For example if you put field in the&lt;br /&gt;
&lt;br /&gt;
 1.0 | 1.0 | 0.0 | &lt;br /&gt;
&lt;br /&gt;
this corresponds to &amp;lt;math&amp;gt;E(t)=\frac{1}{\sqrt{2}} [ E_x(t) + E_y(t) ]&amp;lt;/math&amp;gt; and so at the second order you will have &amp;lt;math&amp;gt;E^2(t)=\frac{1}{2} [ E^2_x(t) + E^2_y(t) +  E_x(t) E_y(t) +  E_y(t) E_x(t) ]&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
this means that  the X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; in the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;  will correspond to a linear combination of the following different response functions.&amp;lt;br&amp;gt;&lt;br /&gt;
For example in the the 2nd and 3rd columns are the imaginary and real part of:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{x**}=\frac{1}{2} \left [\chi^2_{xxx}+\chi^{(2)}_{xyy} + \chi^{(2)}_{xxy} + \chi^{(2)}_{xyx} \right ]&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the same for the other column replacing the first &amp;lt;code&amp;gt;x&amp;lt;/code&amp;gt; for &amp;lt;code&amp;gt;y,z&amp;lt;/code&amp;gt;.&lt;br /&gt;
If you know that some components are zero this allow you to extract the corresponding off-diagonal part of &amp;lt;math&amp;gt;\chi^{(2)}_{abc}&amp;lt;/math&amp;gt; otherwise you have to perform different calculations to get the component you are interested in. Hereafter we present a simple example of monolayer hBN (m-hBN). In m-hBN there is only a non-zero component of the $\chi^2$ and all the others are related by symmetry:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{yyy}=-\chi^{(2)}_{yxx}=-\chi^{(2)}_{xxy}=-\chi^{(2)}_{xyx}&amp;lt;/math&amp;gt;&lt;br /&gt;
so if you put the field in the &amp;lt;code&amp;gt;|1|1|0|&amp;lt;/code&amp;gt; direction you will get:&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{x**} = \frac{1}{2} \left[\chi^{(2)}_{xxy} + \chi^{(2)}_{xyx} \left] = - \chi^{(2)}_{yyy} &amp;lt;/math&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{y**} =-\chi^{(2)}_{yxx}=-\chi^{(2)}_{xxy}=-\chi^{(2)}_{xyx}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Non-linear response of low-dimensional structures: 2D or 1D ==&lt;br /&gt;
&lt;br /&gt;
The Yambo code is a 3D periodic code, so when you want to study a low-dimensional system 2D or 1D, you have to use a supercell approach.&lt;br /&gt;
For example to simulate the non-linear response in a 2D-crystal one, can put the crystal in the xy plane and choose a larger distance in the z-direction&lt;br /&gt;
in order to reduce the interaction between the periodic replica. Clearly in this case k-point sampling will be only in the x,y directions.&lt;br /&gt;
For calculations on this type of systems, these two warnings must be taken into account:&lt;br /&gt;
&lt;br /&gt;
* if you calculate GW corrections or include electron-hole interaction in the linear/non-linear response it is a good idea to use a &#039;&#039;&#039;Coulomb cutoff&#039;&#039;&#039;, similar to the 2D BSE case  [http://www.yambo-code.org/wiki/index.php?title=How_to_treat_low_dimensional_systems How to treat low dimensional systems]. You can add the cutoff just adding the &amp;quot;-r&amp;quot; in the input generation.&lt;br /&gt;
&lt;br /&gt;
* the calculation of SHG and THG are always performed respect to the supercell, therefore you have to &#039;&#039;&#039;re-scale&#039;&#039;&#039; the result to the effective thickness of the layer, usually the inter-layer distance of the corresponding bulk material for 2D systems: &amp;lt;math&amp;gt;\chi_{rescaled}(\omega) = L_z/d_{eff} \cdot \chi(\omega) &amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;L_z&amp;lt;/math&amp;gt; is the z-dimension of the supercell, and &amp;lt;math&amp;gt;d_{eff}&amp;lt;/math&amp;gt; is the effective thickness of the 2D system.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Nota bene&#039;&#039;&#039;: Non-linear response along &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;non-periodic directions&amp;lt;/span&amp;gt; is not implemented in Yambo, the code will print zero in these directions for all response functions. We plan to implement it in a future version of the code.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Links for schools==&lt;br /&gt;
* Back to [[Rome 2023#Tutorials]]&lt;br /&gt;
* Back to [[ICTP2020]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
{| style=&amp;quot;width:100%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|style=&amp;quot;width:25%; text-align:left&amp;quot;|Prev: [[Linear response from real time simulations|Linear response from real time simulations]]&lt;br /&gt;
|style=&amp;quot;width:45%; text-align:center&amp;quot;|Now: [[ICTP2020|ICTP  Tutorials]] --&amp;gt; [[Real time approach to non-linear response|Non Linear Response]] &lt;br /&gt;
|style=&amp;quot;width:50%; text-align:left&amp;quot;|Next: [[Correlation effects in the non-linear response|Correlation effects in the non-linear response ]]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Attacc</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Real_time_approach_to_non-linear_response_(SHG)&amp;diff=9148</id>
		<title>Real time approach to non-linear response (SHG)</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Real_time_approach_to_non-linear_response_(SHG)&amp;diff=9148"/>
		<updated>2025-09-27T08:36:08Z</updated>

		<summary type="html">&lt;p&gt;Attacc: /* How to choose the external field direction for the different X2 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Second Harmonic Generation in AlAs ==&lt;br /&gt;
In this tutorial, we will calculate the second harmonic generation of bulk AlAs, the Yambo databases can be downloaded here: [https://media.yambo-code.eu/educational/tutorials/files/AlAs_DBs.tar.gz AlAs_DBs.tar.gz] (10 MB). The first steps of this tutorials are the same as the one on [http://www.yambo-code.eu/wiki/index.php?title=Prerequisites_for_Real_Time_propagation_with_Yambo Prerequisites for Real-Time propagation with Yambo] with the only difference that we will work on AlAs and we will consider an external field in the direction &amp;lt;code&amp;gt; 1.000000 | 1.000000 | 0.000000 |&amp;lt;/code&amp;gt;. The DFT input are available here: [https://media.yambo-code.eu/educational/tutorials/files/AlAs_abinit.tar.gz ABINIT] or [https://media.yambo-code.eu/educational/tutorials/files/AlAs_pwscf.tar.gz QuantumEspresso].&lt;br /&gt;
You can run the DFT calculation with ABINIT with the command:&lt;br /&gt;
&lt;br /&gt;
 abinit &amp;lt; AlAs.in &amp;gt; output_AlAs                                             &lt;br /&gt;
&lt;br /&gt;
or using QuantumEspresso:&lt;br /&gt;
&lt;br /&gt;
 pw.x -inp AlAs.scf.in &amp;gt; output_scf&lt;br /&gt;
 pw.x -inp AlAs.nscf.in &amp;gt; output_scf                            &lt;br /&gt;
&lt;br /&gt;
and then import the ABINIT wave-function with the command:&lt;br /&gt;
&lt;br /&gt;
 a2y -F AlAso_DS2_WFK.nc                            &lt;br /&gt;
&lt;br /&gt;
and the QuantumEspresso one, in the folder AlAs.save with the command:&lt;br /&gt;
&lt;br /&gt;
 p2y                              &lt;br /&gt;
Now we consider an external field in the &amp;lt;code&amp;gt;[1,1,0]&amp;lt;/code&amp;gt; direction and remove symmetries not compatible with this field, as explained in the tutorial [http://www.yambo-code.eu/wiki/index.php?title=Prerequisites_for_Real_Time_propagation_with_Yambo Prerequisites for Real-Time propagation with Yambo].&lt;br /&gt;
&lt;br /&gt;
==Real-time simulation for the SHG==&lt;br /&gt;
&lt;br /&gt;
You can generate the input file with the command &amp;lt;code&amp;gt;yambo_nl -u n&amp;lt;/code&amp;gt;:&lt;br /&gt;
                       &lt;br /&gt;
 nloptics                      # [R NL] Non-linear optics&lt;br /&gt;
 % NLBands&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 3 | 6&amp;lt;/span&amp;gt; |                   # [NL] Bands&lt;br /&gt;
 %&lt;br /&gt;
 NLstep=   0.0100       fs    # [NL] Real Time step length&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;NLverbosity= &amp;quot;high&amp;quot;&amp;lt;/span&amp;gt;               # [NL] Verbosity level (low | high)&lt;br /&gt;
 NLtime=-1.000000           fs    # [NL] Simulation Time&lt;br /&gt;
 NLintegrator= &amp;quot;INVINT&amp;quot;       # [NL] Integrator (&amp;quot;EULEREXP/RK4/RK2EXP/HEUN/INVINT/CRANKNIC&amp;quot;)&lt;br /&gt;
 NLCorrelation= &amp;quot;IPA&amp;quot;         # [NL] Correlation (&amp;quot;IPA/HARTREE/TDDFT/LRC/JGM/SEX/HF&amp;quot;)&lt;br /&gt;
 NLLrcAlpha= 0.000000         # [NL] Long Range Correction&lt;br /&gt;
 % NLEnRange&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;  1.000000 | 5.000000 &amp;lt;/span&amp;gt;| eV    # [NL] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 NLEnSteps= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 5  &amp;lt;/span&amp;gt;              # [NL] Energy steps&lt;br /&gt;
 NLDamping= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 0.150000  &amp;lt;/span&amp;gt;  eV    # [NL] Damping&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 1.000000 | 1.000000 | 0.000000 &amp;lt;/span&amp;gt;|        # [RT Field1] Versor&lt;br /&gt;
 Field1_kind= &amp;quot;SOFTSIN&amp;quot;         # [NL ExtF] Kind(SIN|SOFTSIN|RES|ANTIRES|GAUSS|DELTA|QSSIN)&lt;br /&gt;
&lt;br /&gt;
The line &amp;lt;code&amp;gt;|1.000000 | 1.000000 | 0.000000 | # [RT Field1] Versor&amp;lt;/code&amp;gt; referees to the direction of the external field (x,y,0). At present only an external field is present but the code can be easily generalized to deal with more fields.&lt;br /&gt;
The default parameters of Yambo/Lumen are already tuned for second-harmonic generation, so the only thing you have to change is the band range, between 3 and 6 and the energy range between 1.0-5.0 eV and the number of energy steps in this interval that we set to 10. Notice that you cannot set to zero the lowest value of the energy range because this will requires a simulation that lasts infinite time, see below. Finally, consider that Yambo performs a separate calculation for each frequency, so if you set many energy steps the computational time grows linearly with this number.&lt;br /&gt;
Notice that we set &amp;lt;code&amp;gt;NLverbosity= &amp;quot;high&amp;quot;&amp;lt;/code&amp;gt; in this way the code will produce a file for each laser frequency containing the time dependent polarization.&lt;br /&gt;
Run &amp;lt;code&amp;gt;yambo_nl&amp;lt;/code&amp;gt;. Calculations will take about fifteen minutes on a single processor PC, you have time to study the next section that explains how non-linear response is extracted from the real-time simulations.&lt;br /&gt;
In order to speed up calculations, you can run them in parallel.&lt;br /&gt;
&lt;br /&gt;
==Non-linear response with Yambo==&lt;br /&gt;
&lt;br /&gt;
In order to calculate the non-linear response, the system is excited with different laser fields with a sinusoidal shape at frequencies &amp;lt;math&amp;gt;\omega_1, \omega_2, .... , \omega_n &amp;lt;/math&amp;gt; determined by the parameters [[Variables#NLEnRangev|NLEnRange]] and [[Variables#NLEnSteps|NLEnSteps]]. A dephasing term is added to the Hamiltonian &amp;lt;math&amp;gt;\gamma = &amp;lt;/math&amp;gt;[[Variables#NLDamping|NLDamping]] to simulate a finite broadening and to remove the eigenmodes that are excited by the sudden turning on of the external field. After the dephasing time the outgoing signal is analyzed to extract the non-linear coefficients as shown in the figure below: &lt;br /&gt;
&lt;br /&gt;
[[File:Pt analysis.png|600px|center|Non-linear response analysis]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the report file &amp;lt;code&amp;gt;r_nlinear&amp;lt;/code&amp;gt; you will find the length of the dephasing part and of the sampling one:&lt;br /&gt;
&lt;br /&gt;
  Dephasing Time          [fs]: 52.65695&lt;br /&gt;
  Sampling  Time          [fs]:  4.18566&lt;br /&gt;
  Total simulation time   [fs]: 56.84262                     &lt;br /&gt;
The length of the dephasing interval is inversely proportional to the damping term &amp;lt;math&amp;gt;T_{depth} \simeq 1/\gamma&amp;lt;/math&amp;gt; while the length of the sampling is dictated by the smallest frequency we are interested in: &amp;lt;math&amp;gt;T_{samp} \simeq 1/\omega_1 &amp;lt;/math&amp;gt;. For this reason if &amp;lt;math&amp;gt; \omega_1=0 &amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt; \gamma = 0 &amp;lt;/math&amp;gt; simulation time goes to infinity. The response at zero frequency can be calculated as limit of small frequency perturbation.&lt;br /&gt;
You can have a look to the file &amp;lt;code&amp;gt;src/nloptics/NL_initialize.F&amp;lt;/code&amp;gt; to see how simulation lengths are defined.&lt;br /&gt;
Calculations can take some time, run them in parallel, the best number of processors = number of frequencies or reduce the number of frequencies step in the SHG.&lt;br /&gt;
&lt;br /&gt;
==Analysis of the results==&lt;br /&gt;
&lt;br /&gt;
In the sampling region we suppose that the polarization can be written as: &amp;lt;math&amp;gt;\bf{P}(t) = \sum_{n=-\infty}^{+\infty} \bf{p}_n e^{-i\omega_n t} &amp;lt;/math&amp;gt; where the coefficient &amp;lt;math&amp;gt;\bf{p}_1,...,\bf{p}_n &amp;lt;/math&amp;gt; are related to &amp;lt;math&amp;gt;\chi^{(1)},...,\chi^{(n)} &amp;lt;/math&amp;gt;. We sample the polarization signal at different times and invert the previous equation by truncating the sum at a finite order &amp;lt;ref&amp;gt;[https://arxiv.org/abs/1309.4012 Nonlinear optics from an ab initio approach by means of the dynamical Berry phase: Application to second- and third-harmonic generation in semiconductors], C. Attaccalite and M. Grüning, Phys. Rev. B 88, 235113(2013)&amp;lt;/ref&amp;gt;.&lt;br /&gt;
This is done with the command &amp;lt;code&amp;gt;ypp_nl -u&amp;lt;/code&amp;gt; that automatically produce an input with the correct values:&lt;br /&gt;
&lt;br /&gt;
 nonlinear                    # [R] NonLinear Optics Post-Processing&lt;br /&gt;
 Xorder=   &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;4  &amp;lt;/span&amp;gt;                 # Max order of the response functions&lt;br /&gt;
 % TimeRange&lt;br /&gt;
  52.65695 | -1.00000 | fs    # Time-window where processing is done&lt;br /&gt;
 % &lt;br /&gt;
 ETStpsRt= 200                # Total Energy steps&lt;br /&gt;
 % EnRngeRt&lt;br /&gt;
   0.00000 | 10.00000 | eV    # Energy range&lt;br /&gt;
 %&lt;br /&gt;
 DampMode= &amp;quot;NONE&amp;quot;             # Damping type ( NONE | LORENTZIAN | GAUSSIAN )&lt;br /&gt;
 DampFactor=  0.10000   eV    # Damping parameter&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;code&amp;gt;Xorder&amp;lt;/code&amp;gt; is the order where the previous sum is truncated, and the TimeRange specifies the sampling region. Notice that differently from the first tutorial, in this case, we do not need Damping in &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; because we already included it in the real-time dynamics. Run &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; and it will produce a file called &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;. This file contains the different components of &amp;lt;math&amp;gt;\chi^2_{xy*} &amp;lt;/math&amp;gt; and in particular the columns 6 and 7 correspond to the imaginary and real part of &amp;lt;math&amp;gt;\chi^2_{xyz} &amp;lt;/math&amp;gt;. You can plot the result with gnuplot and the command:&lt;br /&gt;
&lt;br /&gt;
 p &#039;o.YPP-X_probe_order_2&#039; u 1:(sqrt($6**2+$7**2)) w lp ps 1.5 pt 7 lw 1.5&lt;br /&gt;
&lt;br /&gt;
the result should look like&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AlAs results.png|700px|center|SHG in AlAs]]&lt;br /&gt;
&lt;br /&gt;
and compare it with the &amp;lt;math&amp;gt; \chi^2_{zxy} &amp;lt;/math&amp;gt; calculated with more frequencies and with the converged result on a &amp;lt;math&amp;gt; 18x18x18&amp;lt;/math&amp;gt; k-point grid and bands between 2 and 10. In the figure you can find also the comparison with the results of Ref. &amp;lt;ref&amp;gt;Luppi et al. [https://arxiv.org/abs/1006.2649 PRB B, &#039;&#039;&#039;82&#039;&#039;&#039;, 235201(2010)]&amp;lt;/ref&amp;gt;. &lt;br /&gt;
Notice that the QuantumEspresso results are slightly different from the Abinit ones. This is due to the different pseudo-potential employed in the calculations if pseudopotentials were the same calculation would have been identical. You can download the script to generate this plot and the converged results [http://www.attaccalite.com/lumen/tutorials/AlAs/AlAs_results.tgz here].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notice that&#039;&#039;&#039; : the following parameters are not used in the non-linear response analysis: &amp;lt;code&amp;gt; EnRngeRt&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ETStpsRt&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;DampMode&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;DampFactor&amp;lt;/code&amp;gt;. The damping factor is set directly in the real-time simulation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;System of units in Non-linear Optics&amp;lt;/span&amp;gt;&#039;&#039;&#039;: notice that in Yambo the non-linear response functions are in the gaussian system of units, for example the &amp;lt;math&amp;gt; \chi^2 (\omega) &amp;lt;/math&amp;gt;  is in cm/statvolt. In order to convert the non-linear coefficients between different system of units, you can have a look at the [https://www.attaccalite.com/tutorials_yambo/Appendix_C_Boyd.pdf Appendix C] of the book [https://www.elsevier.com/books/nonlinear-optics/boyd/978-0-12-369470-6 &amp;quot;Non-linear optics&amp;quot;  by Robert W. Boyd].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;More tutorials&amp;lt;/span&amp;gt; on non-linear response (Third harmonic generation, parallelization, spin-orbit etc..) with Yambo can be found here: [http://www.attaccalite.com/lumen/tutorials.html More Tutorials]. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Analysis of the results using YamboPy==&lt;br /&gt;
The analysis of the result performed in the previous section using &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; can be performed using python script [https://github.com/yambo-code/yambopy YamboPy].&amp;lt;br&amp;gt;&lt;br /&gt;
In YamboPy we implemented all necessary functions to reads the Yambo databases and post-process the results. Here we show how to get the SHG signal from the previous &lt;br /&gt;
simulations. We suppose you correctly installed &amp;lt;code&amp;gt;YamboPy&amp;lt;/code&amp;gt; on your PC. Go in the folder where you ran non-linear calculation and type in the python:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
 from yambopy import *&lt;br /&gt;
 NLDB=YamboNLDB()&lt;br /&gt;
 pol =NLDB.Polarization[0]&lt;br /&gt;
 time=NLDB.IO_TIME_points&lt;br /&gt;
&lt;br /&gt;
in this way you read all the Non-linear databases. If your runs are in a different folder then the &#039;SAVE&#039; one you can specify it using the command:&lt;br /&gt;
 NLDB=YamboNLDB(calc=&#039;MYJOB&#039;)&lt;br /&gt;
&lt;br /&gt;
now in the array &amp;lt;code&amp;gt;pol&amp;lt;/code&amp;gt; you have all the polarization for all laser frequencies in the three Cartesian directions, while the variable &amp;lt;code&amp;gt;time&amp;lt;/code&amp;gt; contains all the time series of your simulation.&lt;br /&gt;
Now you can get the non-linear response with the command:&lt;br /&gt;
&lt;br /&gt;
 Harmonic_Analysis(NLDB,X_order=4)&lt;br /&gt;
&lt;br /&gt;
this command will perform a Fourier analysis of the results in the same way of &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; and generate new files with all the requested harmonics &#039;&#039;o.YamboPy-X_probe_order_1&#039;&#039;, &#039;&#039;o.YamboPy-X_probe_order_2&#039;&#039; etc...&lt;br /&gt;
equivalent to the one generated by &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt;. Results can be plot with gnuplot using the command:&lt;br /&gt;
 &lt;br /&gt;
 p &#039;o.YamboPy-X_probe_order_2&#039; u 1:(sqrt($6**2+$7**2)) w lp ps 1.5 pt 7 lw 1.5&lt;br /&gt;
&lt;br /&gt;
The script that performs non-linear analysis can be found in &amp;lt;code&amp;gt;yambopy/nl/harmonic_analysis.py&amp;lt;/code&amp;gt;. &amp;lt;br&amp;gt; We strongly advice you to have a look to this script and modify it according&lt;br /&gt;
to your needs and in order to extract other non-linear response functions.&lt;br /&gt;
&lt;br /&gt;
==How to choose the external field direction for the different X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
In the X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;abc&amp;lt;/sub&amp;gt; response you have three field directions. The two components &#039;&#039;b&#039;&#039; and &#039;&#039;c&#039;&#039; are determined by the external field and the third &#039;&#039;a&#039;&#039;&lt;br /&gt;
is the direction where you measure the response.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The external field in Yambo is set using the variable&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
   1.000000 | 0.000000 | 0.000000 |        # [NL ExtF] Versor .&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
For example if you set in Yambo field direction as:&lt;br /&gt;
&lt;br /&gt;
 1.0 | 0.0 | 0.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*xx&amp;lt;/sub&amp;gt;&lt;br /&gt;
 0.0 | 1.0 | 0.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*yy&amp;lt;/sub&amp;gt;&lt;br /&gt;
 0.0 | 0.0 | 1.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*zz&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the * correspond to the different direction in the response file &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;.&lt;br /&gt;
In the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt; you have seven columns:&lt;br /&gt;
&lt;br /&gt;
 The first column is the energy [[omega]],&lt;br /&gt;
 the 2nd and 3rd columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;x**&amp;lt;/sub&amp;gt;&lt;br /&gt;
 the 4th and 5th columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;y**&amp;lt;/sub&amp;gt;&lt;br /&gt;
 the 6th and 7th columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;z**&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where the ** are the direction of the incoming field, see above.&lt;br /&gt;
&lt;br /&gt;
For example if you want to calculate the &amp;lt;math&amp;gt;\chi^{(2)}_{zxx}&amp;lt;/math&amp;gt; you put the external field in the direction &amp;lt;code&amp;gt; 1.0 | 0.0 | 0.0 |&amp;lt;/code&amp;gt;&lt;br /&gt;
and then plot the column 6 and 7 of the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt; file.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Nota bene:&#039;&#039;&#039; if you change the direction of the external field you have to remove the corresponding symmetries as explained in the tutorial &lt;br /&gt;
on [[Prerequisites for Real Time_propagation with Yambo#Reduce symmetries real-time linear response tutorial]].&lt;br /&gt;
&lt;br /&gt;
In order to get the other components of the  X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; the calculation are more involved. For example if you put field in the&lt;br /&gt;
&lt;br /&gt;
 1.0 | 1.0 | 0.0 | &lt;br /&gt;
&lt;br /&gt;
this corresponds to &amp;lt;math&amp;gt;E(t)=\frac{1}{\sqrt{2}} [ E_x(t) + E_y(t) ]&amp;lt;/math&amp;gt; and so at the second order you will have &amp;lt;math&amp;gt;E^2(t)=\frac{1}{2} [ E^2_x(t) + E^2_y(t) +  E_x(t) E_y(t) +  E_y(t) E_x(t) ]&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
this means that  the X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; in the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;  will correspond to a linear combination of the following different response functions.&amp;lt;br&amp;gt;&lt;br /&gt;
For example in the the 2nd and 3rd columns are the imaginary and real part of:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{x**}=\frac{1}{2} \left [\chi^2_{xxx}+\chi^{(2)}_{xyy} + \chi^{(2)}_{xxy} + \chi^{(2)}_{xyx} \right ]&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the same for the other column replacing the first &amp;lt;code&amp;gt;x&amp;lt;/code&amp;gt; for &amp;lt;code&amp;gt;y,z&amp;lt;/code&amp;gt;.&lt;br /&gt;
If you know that some components are zero this allow you to extract the corresponding off-diagonal part of &amp;lt;math&amp;gt;\chi^{(2)}_{abc}&amp;lt;/math&amp;gt; otherwise you have to perform different calculations to get the component you are interested in. Hereafter we present a simple example of monolayer hBN (m-hBN). In m-hBN there is only a non-zero component of the $\chi^2$ and all the others are related by symmetry:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{yyy}=-\chi^{(2)}_{yxx}=-\chi^{(2)}_{xxy}=-\chi^{(2)}_{xyx}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Non-linear response of low-dimensional structures: 2D or 1D ==&lt;br /&gt;
&lt;br /&gt;
The Yambo code is a 3D periodic code, so when you want to study a low-dimensional system 2D or 1D, you have to use a supercell approach.&lt;br /&gt;
For example to simulate the non-linear response in a 2D-crystal one, can put the crystal in the xy plane and choose a larger distance in the z-direction&lt;br /&gt;
in order to reduce the interaction between the periodic replica. Clearly in this case k-point sampling will be only in the x,y directions.&lt;br /&gt;
For calculations on this type of systems, these two warnings must be taken into account:&lt;br /&gt;
&lt;br /&gt;
* if you calculate GW corrections or include electron-hole interaction in the linear/non-linear response it is a good idea to use a &#039;&#039;&#039;Coulomb cutoff&#039;&#039;&#039;, similar to the 2D BSE case  [http://www.yambo-code.org/wiki/index.php?title=How_to_treat_low_dimensional_systems How to treat low dimensional systems]. You can add the cutoff just adding the &amp;quot;-r&amp;quot; in the input generation.&lt;br /&gt;
&lt;br /&gt;
* the calculation of SHG and THG are always performed respect to the supercell, therefore you have to &#039;&#039;&#039;re-scale&#039;&#039;&#039; the result to the effective thickness of the layer, usually the inter-layer distance of the corresponding bulk material for 2D systems: &amp;lt;math&amp;gt;\chi_{rescaled}(\omega) = L_z/d_{eff} \cdot \chi(\omega) &amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;L_z&amp;lt;/math&amp;gt; is the z-dimension of the supercell, and &amp;lt;math&amp;gt;d_{eff}&amp;lt;/math&amp;gt; is the effective thickness of the 2D system.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Nota bene&#039;&#039;&#039;: Non-linear response along &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;non-periodic directions&amp;lt;/span&amp;gt; is not implemented in Yambo, the code will print zero in these directions for all response functions. We plan to implement it in a future version of the code.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Links for schools==&lt;br /&gt;
* Back to [[Rome 2023#Tutorials]]&lt;br /&gt;
* Back to [[ICTP2020]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
{| style=&amp;quot;width:100%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|style=&amp;quot;width:25%; text-align:left&amp;quot;|Prev: [[Linear response from real time simulations|Linear response from real time simulations]]&lt;br /&gt;
|style=&amp;quot;width:45%; text-align:center&amp;quot;|Now: [[ICTP2020|ICTP  Tutorials]] --&amp;gt; [[Real time approach to non-linear response|Non Linear Response]] &lt;br /&gt;
|style=&amp;quot;width:50%; text-align:left&amp;quot;|Next: [[Correlation effects in the non-linear response|Correlation effects in the non-linear response ]]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Attacc</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Real_time_approach_to_non-linear_response_(SHG)&amp;diff=9147</id>
		<title>Real time approach to non-linear response (SHG)</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Real_time_approach_to_non-linear_response_(SHG)&amp;diff=9147"/>
		<updated>2025-09-27T08:35:52Z</updated>

		<summary type="html">&lt;p&gt;Attacc: /* How to choose the external field direction for the different X2 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Second Harmonic Generation in AlAs ==&lt;br /&gt;
In this tutorial, we will calculate the second harmonic generation of bulk AlAs, the Yambo databases can be downloaded here: [https://media.yambo-code.eu/educational/tutorials/files/AlAs_DBs.tar.gz AlAs_DBs.tar.gz] (10 MB). The first steps of this tutorials are the same as the one on [http://www.yambo-code.eu/wiki/index.php?title=Prerequisites_for_Real_Time_propagation_with_Yambo Prerequisites for Real-Time propagation with Yambo] with the only difference that we will work on AlAs and we will consider an external field in the direction &amp;lt;code&amp;gt; 1.000000 | 1.000000 | 0.000000 |&amp;lt;/code&amp;gt;. The DFT input are available here: [https://media.yambo-code.eu/educational/tutorials/files/AlAs_abinit.tar.gz ABINIT] or [https://media.yambo-code.eu/educational/tutorials/files/AlAs_pwscf.tar.gz QuantumEspresso].&lt;br /&gt;
You can run the DFT calculation with ABINIT with the command:&lt;br /&gt;
&lt;br /&gt;
 abinit &amp;lt; AlAs.in &amp;gt; output_AlAs                                             &lt;br /&gt;
&lt;br /&gt;
or using QuantumEspresso:&lt;br /&gt;
&lt;br /&gt;
 pw.x -inp AlAs.scf.in &amp;gt; output_scf&lt;br /&gt;
 pw.x -inp AlAs.nscf.in &amp;gt; output_scf                            &lt;br /&gt;
&lt;br /&gt;
and then import the ABINIT wave-function with the command:&lt;br /&gt;
&lt;br /&gt;
 a2y -F AlAso_DS2_WFK.nc                            &lt;br /&gt;
&lt;br /&gt;
and the QuantumEspresso one, in the folder AlAs.save with the command:&lt;br /&gt;
&lt;br /&gt;
 p2y                              &lt;br /&gt;
Now we consider an external field in the &amp;lt;code&amp;gt;[1,1,0]&amp;lt;/code&amp;gt; direction and remove symmetries not compatible with this field, as explained in the tutorial [http://www.yambo-code.eu/wiki/index.php?title=Prerequisites_for_Real_Time_propagation_with_Yambo Prerequisites for Real-Time propagation with Yambo].&lt;br /&gt;
&lt;br /&gt;
==Real-time simulation for the SHG==&lt;br /&gt;
&lt;br /&gt;
You can generate the input file with the command &amp;lt;code&amp;gt;yambo_nl -u n&amp;lt;/code&amp;gt;:&lt;br /&gt;
                       &lt;br /&gt;
 nloptics                      # [R NL] Non-linear optics&lt;br /&gt;
 % NLBands&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 3 | 6&amp;lt;/span&amp;gt; |                   # [NL] Bands&lt;br /&gt;
 %&lt;br /&gt;
 NLstep=   0.0100       fs    # [NL] Real Time step length&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;NLverbosity= &amp;quot;high&amp;quot;&amp;lt;/span&amp;gt;               # [NL] Verbosity level (low | high)&lt;br /&gt;
 NLtime=-1.000000           fs    # [NL] Simulation Time&lt;br /&gt;
 NLintegrator= &amp;quot;INVINT&amp;quot;       # [NL] Integrator (&amp;quot;EULEREXP/RK4/RK2EXP/HEUN/INVINT/CRANKNIC&amp;quot;)&lt;br /&gt;
 NLCorrelation= &amp;quot;IPA&amp;quot;         # [NL] Correlation (&amp;quot;IPA/HARTREE/TDDFT/LRC/JGM/SEX/HF&amp;quot;)&lt;br /&gt;
 NLLrcAlpha= 0.000000         # [NL] Long Range Correction&lt;br /&gt;
 % NLEnRange&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;  1.000000 | 5.000000 &amp;lt;/span&amp;gt;| eV    # [NL] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 NLEnSteps= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 5  &amp;lt;/span&amp;gt;              # [NL] Energy steps&lt;br /&gt;
 NLDamping= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 0.150000  &amp;lt;/span&amp;gt;  eV    # [NL] Damping&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 1.000000 | 1.000000 | 0.000000 &amp;lt;/span&amp;gt;|        # [RT Field1] Versor&lt;br /&gt;
 Field1_kind= &amp;quot;SOFTSIN&amp;quot;         # [NL ExtF] Kind(SIN|SOFTSIN|RES|ANTIRES|GAUSS|DELTA|QSSIN)&lt;br /&gt;
&lt;br /&gt;
The line &amp;lt;code&amp;gt;|1.000000 | 1.000000 | 0.000000 | # [RT Field1] Versor&amp;lt;/code&amp;gt; referees to the direction of the external field (x,y,0). At present only an external field is present but the code can be easily generalized to deal with more fields.&lt;br /&gt;
The default parameters of Yambo/Lumen are already tuned for second-harmonic generation, so the only thing you have to change is the band range, between 3 and 6 and the energy range between 1.0-5.0 eV and the number of energy steps in this interval that we set to 10. Notice that you cannot set to zero the lowest value of the energy range because this will requires a simulation that lasts infinite time, see below. Finally, consider that Yambo performs a separate calculation for each frequency, so if you set many energy steps the computational time grows linearly with this number.&lt;br /&gt;
Notice that we set &amp;lt;code&amp;gt;NLverbosity= &amp;quot;high&amp;quot;&amp;lt;/code&amp;gt; in this way the code will produce a file for each laser frequency containing the time dependent polarization.&lt;br /&gt;
Run &amp;lt;code&amp;gt;yambo_nl&amp;lt;/code&amp;gt;. Calculations will take about fifteen minutes on a single processor PC, you have time to study the next section that explains how non-linear response is extracted from the real-time simulations.&lt;br /&gt;
In order to speed up calculations, you can run them in parallel.&lt;br /&gt;
&lt;br /&gt;
==Non-linear response with Yambo==&lt;br /&gt;
&lt;br /&gt;
In order to calculate the non-linear response, the system is excited with different laser fields with a sinusoidal shape at frequencies &amp;lt;math&amp;gt;\omega_1, \omega_2, .... , \omega_n &amp;lt;/math&amp;gt; determined by the parameters [[Variables#NLEnRangev|NLEnRange]] and [[Variables#NLEnSteps|NLEnSteps]]. A dephasing term is added to the Hamiltonian &amp;lt;math&amp;gt;\gamma = &amp;lt;/math&amp;gt;[[Variables#NLDamping|NLDamping]] to simulate a finite broadening and to remove the eigenmodes that are excited by the sudden turning on of the external field. After the dephasing time the outgoing signal is analyzed to extract the non-linear coefficients as shown in the figure below: &lt;br /&gt;
&lt;br /&gt;
[[File:Pt analysis.png|600px|center|Non-linear response analysis]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the report file &amp;lt;code&amp;gt;r_nlinear&amp;lt;/code&amp;gt; you will find the length of the dephasing part and of the sampling one:&lt;br /&gt;
&lt;br /&gt;
  Dephasing Time          [fs]: 52.65695&lt;br /&gt;
  Sampling  Time          [fs]:  4.18566&lt;br /&gt;
  Total simulation time   [fs]: 56.84262                     &lt;br /&gt;
The length of the dephasing interval is inversely proportional to the damping term &amp;lt;math&amp;gt;T_{depth} \simeq 1/\gamma&amp;lt;/math&amp;gt; while the length of the sampling is dictated by the smallest frequency we are interested in: &amp;lt;math&amp;gt;T_{samp} \simeq 1/\omega_1 &amp;lt;/math&amp;gt;. For this reason if &amp;lt;math&amp;gt; \omega_1=0 &amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt; \gamma = 0 &amp;lt;/math&amp;gt; simulation time goes to infinity. The response at zero frequency can be calculated as limit of small frequency perturbation.&lt;br /&gt;
You can have a look to the file &amp;lt;code&amp;gt;src/nloptics/NL_initialize.F&amp;lt;/code&amp;gt; to see how simulation lengths are defined.&lt;br /&gt;
Calculations can take some time, run them in parallel, the best number of processors = number of frequencies or reduce the number of frequencies step in the SHG.&lt;br /&gt;
&lt;br /&gt;
==Analysis of the results==&lt;br /&gt;
&lt;br /&gt;
In the sampling region we suppose that the polarization can be written as: &amp;lt;math&amp;gt;\bf{P}(t) = \sum_{n=-\infty}^{+\infty} \bf{p}_n e^{-i\omega_n t} &amp;lt;/math&amp;gt; where the coefficient &amp;lt;math&amp;gt;\bf{p}_1,...,\bf{p}_n &amp;lt;/math&amp;gt; are related to &amp;lt;math&amp;gt;\chi^{(1)},...,\chi^{(n)} &amp;lt;/math&amp;gt;. We sample the polarization signal at different times and invert the previous equation by truncating the sum at a finite order &amp;lt;ref&amp;gt;[https://arxiv.org/abs/1309.4012 Nonlinear optics from an ab initio approach by means of the dynamical Berry phase: Application to second- and third-harmonic generation in semiconductors], C. Attaccalite and M. Grüning, Phys. Rev. B 88, 235113(2013)&amp;lt;/ref&amp;gt;.&lt;br /&gt;
This is done with the command &amp;lt;code&amp;gt;ypp_nl -u&amp;lt;/code&amp;gt; that automatically produce an input with the correct values:&lt;br /&gt;
&lt;br /&gt;
 nonlinear                    # [R] NonLinear Optics Post-Processing&lt;br /&gt;
 Xorder=   &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;4  &amp;lt;/span&amp;gt;                 # Max order of the response functions&lt;br /&gt;
 % TimeRange&lt;br /&gt;
  52.65695 | -1.00000 | fs    # Time-window where processing is done&lt;br /&gt;
 % &lt;br /&gt;
 ETStpsRt= 200                # Total Energy steps&lt;br /&gt;
 % EnRngeRt&lt;br /&gt;
   0.00000 | 10.00000 | eV    # Energy range&lt;br /&gt;
 %&lt;br /&gt;
 DampMode= &amp;quot;NONE&amp;quot;             # Damping type ( NONE | LORENTZIAN | GAUSSIAN )&lt;br /&gt;
 DampFactor=  0.10000   eV    # Damping parameter&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;code&amp;gt;Xorder&amp;lt;/code&amp;gt; is the order where the previous sum is truncated, and the TimeRange specifies the sampling region. Notice that differently from the first tutorial, in this case, we do not need Damping in &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; because we already included it in the real-time dynamics. Run &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; and it will produce a file called &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;. This file contains the different components of &amp;lt;math&amp;gt;\chi^2_{xy*} &amp;lt;/math&amp;gt; and in particular the columns 6 and 7 correspond to the imaginary and real part of &amp;lt;math&amp;gt;\chi^2_{xyz} &amp;lt;/math&amp;gt;. You can plot the result with gnuplot and the command:&lt;br /&gt;
&lt;br /&gt;
 p &#039;o.YPP-X_probe_order_2&#039; u 1:(sqrt($6**2+$7**2)) w lp ps 1.5 pt 7 lw 1.5&lt;br /&gt;
&lt;br /&gt;
the result should look like&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AlAs results.png|700px|center|SHG in AlAs]]&lt;br /&gt;
&lt;br /&gt;
and compare it with the &amp;lt;math&amp;gt; \chi^2_{zxy} &amp;lt;/math&amp;gt; calculated with more frequencies and with the converged result on a &amp;lt;math&amp;gt; 18x18x18&amp;lt;/math&amp;gt; k-point grid and bands between 2 and 10. In the figure you can find also the comparison with the results of Ref. &amp;lt;ref&amp;gt;Luppi et al. [https://arxiv.org/abs/1006.2649 PRB B, &#039;&#039;&#039;82&#039;&#039;&#039;, 235201(2010)]&amp;lt;/ref&amp;gt;. &lt;br /&gt;
Notice that the QuantumEspresso results are slightly different from the Abinit ones. This is due to the different pseudo-potential employed in the calculations if pseudopotentials were the same calculation would have been identical. You can download the script to generate this plot and the converged results [http://www.attaccalite.com/lumen/tutorials/AlAs/AlAs_results.tgz here].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notice that&#039;&#039;&#039; : the following parameters are not used in the non-linear response analysis: &amp;lt;code&amp;gt; EnRngeRt&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ETStpsRt&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;DampMode&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;DampFactor&amp;lt;/code&amp;gt;. The damping factor is set directly in the real-time simulation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;System of units in Non-linear Optics&amp;lt;/span&amp;gt;&#039;&#039;&#039;: notice that in Yambo the non-linear response functions are in the gaussian system of units, for example the &amp;lt;math&amp;gt; \chi^2 (\omega) &amp;lt;/math&amp;gt;  is in cm/statvolt. In order to convert the non-linear coefficients between different system of units, you can have a look at the [https://www.attaccalite.com/tutorials_yambo/Appendix_C_Boyd.pdf Appendix C] of the book [https://www.elsevier.com/books/nonlinear-optics/boyd/978-0-12-369470-6 &amp;quot;Non-linear optics&amp;quot;  by Robert W. Boyd].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;More tutorials&amp;lt;/span&amp;gt; on non-linear response (Third harmonic generation, parallelization, spin-orbit etc..) with Yambo can be found here: [http://www.attaccalite.com/lumen/tutorials.html More Tutorials]. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Analysis of the results using YamboPy==&lt;br /&gt;
The analysis of the result performed in the previous section using &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; can be performed using python script [https://github.com/yambo-code/yambopy YamboPy].&amp;lt;br&amp;gt;&lt;br /&gt;
In YamboPy we implemented all necessary functions to reads the Yambo databases and post-process the results. Here we show how to get the SHG signal from the previous &lt;br /&gt;
simulations. We suppose you correctly installed &amp;lt;code&amp;gt;YamboPy&amp;lt;/code&amp;gt; on your PC. Go in the folder where you ran non-linear calculation and type in the python:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
 from yambopy import *&lt;br /&gt;
 NLDB=YamboNLDB()&lt;br /&gt;
 pol =NLDB.Polarization[0]&lt;br /&gt;
 time=NLDB.IO_TIME_points&lt;br /&gt;
&lt;br /&gt;
in this way you read all the Non-linear databases. If your runs are in a different folder then the &#039;SAVE&#039; one you can specify it using the command:&lt;br /&gt;
 NLDB=YamboNLDB(calc=&#039;MYJOB&#039;)&lt;br /&gt;
&lt;br /&gt;
now in the array &amp;lt;code&amp;gt;pol&amp;lt;/code&amp;gt; you have all the polarization for all laser frequencies in the three Cartesian directions, while the variable &amp;lt;code&amp;gt;time&amp;lt;/code&amp;gt; contains all the time series of your simulation.&lt;br /&gt;
Now you can get the non-linear response with the command:&lt;br /&gt;
&lt;br /&gt;
 Harmonic_Analysis(NLDB,X_order=4)&lt;br /&gt;
&lt;br /&gt;
this command will perform a Fourier analysis of the results in the same way of &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; and generate new files with all the requested harmonics &#039;&#039;o.YamboPy-X_probe_order_1&#039;&#039;, &#039;&#039;o.YamboPy-X_probe_order_2&#039;&#039; etc...&lt;br /&gt;
equivalent to the one generated by &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt;. Results can be plot with gnuplot using the command:&lt;br /&gt;
 &lt;br /&gt;
 p &#039;o.YamboPy-X_probe_order_2&#039; u 1:(sqrt($6**2+$7**2)) w lp ps 1.5 pt 7 lw 1.5&lt;br /&gt;
&lt;br /&gt;
The script that performs non-linear analysis can be found in &amp;lt;code&amp;gt;yambopy/nl/harmonic_analysis.py&amp;lt;/code&amp;gt;. &amp;lt;br&amp;gt; We strongly advice you to have a look to this script and modify it according&lt;br /&gt;
to your needs and in order to extract other non-linear response functions.&lt;br /&gt;
&lt;br /&gt;
==How to choose the external field direction for the different X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
In the X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;abc&amp;lt;/sub&amp;gt; response you have three field directions. The two components &#039;&#039;b&#039;&#039; and &#039;&#039;c&#039;&#039; are determined by the external field and the third &#039;&#039;a&#039;&#039;&lt;br /&gt;
is the direction where you measure the response.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The external field in Yambo is set using the variable&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
   1.000000 | 0.000000 | 0.000000 |        # [NL ExtF] Versor .&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
For example if you set in Yambo field direction as:&lt;br /&gt;
&lt;br /&gt;
 1.0 | 0.0 | 0.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*xx&amp;lt;/sub&amp;gt;&lt;br /&gt;
 0.0 | 1.0 | 0.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*yy&amp;lt;/sub&amp;gt;&lt;br /&gt;
 0.0 | 0.0 | 1.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*zz&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the * correspond to the different direction in the response file &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;.&lt;br /&gt;
In the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt; you have seven columns:&lt;br /&gt;
&lt;br /&gt;
 The first column is the energy [[omega]],&lt;br /&gt;
 the 2nd and 3rd columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;x**&amp;lt;/sub&amp;gt;&lt;br /&gt;
 the 4th and 5th columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;y**&amp;lt;/sub&amp;gt;&lt;br /&gt;
 the 6th and 7th columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;z**&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where the ** are the direction of the incoming field, see above.&lt;br /&gt;
&lt;br /&gt;
For example if you want to calculate the &amp;lt;math&amp;gt;\chi^{(2)}_{zxx}&amp;lt;/math&amp;gt; you put the external field in the direction &amp;lt;code&amp;gt; 1.0 | 0.0 | 0.0 |&amp;lt;/code&amp;gt;&lt;br /&gt;
and then plot the column 6 and 7 of the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt; file.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Nota bene:&#039;&#039;&#039; if you change the direction of the external field you have to remove the corresponding symmetries as explained in the tutorial &lt;br /&gt;
on [[Prerequisites for Real Time_propagation with Yambo#Reduce symmetries real-time linear response tutorial]].&lt;br /&gt;
&lt;br /&gt;
In order to get the other components of the  X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; the calculation are more involved. For example if you put field in the&lt;br /&gt;
&lt;br /&gt;
 1.0 | 1.0 | 0.0 | &lt;br /&gt;
&lt;br /&gt;
this corresponds to &amp;lt;math&amp;gt;E(t)=\frac{1}{\sqrt{2}} [ E_x(t) + E_y(t) ]&amp;lt;/math&amp;gt; and so at the second order you will have &amp;lt;math&amp;gt;E^2(t)=\frac{1}{2} [ E^2_x(t) + E^2_y(t) +  E_x(t) E_y(t) +  E_y(t) E_x(t) ]&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
this means that  the X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; in the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;  will correspond to a linear combination of the following different response functions.&amp;lt;br&amp;gt;&lt;br /&gt;
For example in the the 2nd and 3rd columns are the imaginary and real part of:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{x**}=\frac{1}{2} \left [\chi^2_{xxx}+\chi^{(2)}_{xyy} + \chi^{(2)}_{xxy} + \chi^{(2)}_{xyx} \right ]&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the same for the other column replacing the first &amp;lt;code&amp;gt;x&amp;lt;/code&amp;gt; for &amp;lt;code&amp;gt;y,z&amp;lt;/code&amp;gt;.&lt;br /&gt;
If you know that some components are zero this allow you to extract the corresponding off-diagonal part of &amp;lt;math&amp;gt;\chi^{(2)}_{abc}&amp;lt;/math&amp;gt; otherwise you have to perform different calculations to get the component you are interested in. Hereafter we present a simple example of monolayer hBN (m-hBN). In m-hBN there is only a non-zero component of the $\chi^2$ and all the others are related by symmetry:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{yyy}=-\chi^{(2)}_{yxx}=-\chi^{(2)}_{xxy}=-\chi^{(2)}_{xyx}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Non-linear response of low-dimensional structures: 2D or 1D ==&lt;br /&gt;
&lt;br /&gt;
The Yambo code is a 3D periodic code, so when you want to study a low-dimensional system 2D or 1D, you have to use a supercell approach.&lt;br /&gt;
For example to simulate the non-linear response in a 2D-crystal one, can put the crystal in the xy plane and choose a larger distance in the z-direction&lt;br /&gt;
in order to reduce the interaction between the periodic replica. Clearly in this case k-point sampling will be only in the x,y directions.&lt;br /&gt;
For calculations on this type of systems, these two warnings must be taken into account:&lt;br /&gt;
&lt;br /&gt;
* if you calculate GW corrections or include electron-hole interaction in the linear/non-linear response it is a good idea to use a &#039;&#039;&#039;Coulomb cutoff&#039;&#039;&#039;, similar to the 2D BSE case  [http://www.yambo-code.org/wiki/index.php?title=How_to_treat_low_dimensional_systems How to treat low dimensional systems]. You can add the cutoff just adding the &amp;quot;-r&amp;quot; in the input generation.&lt;br /&gt;
&lt;br /&gt;
* the calculation of SHG and THG are always performed respect to the supercell, therefore you have to &#039;&#039;&#039;re-scale&#039;&#039;&#039; the result to the effective thickness of the layer, usually the inter-layer distance of the corresponding bulk material for 2D systems: &amp;lt;math&amp;gt;\chi_{rescaled}(\omega) = L_z/d_{eff} \cdot \chi(\omega) &amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;L_z&amp;lt;/math&amp;gt; is the z-dimension of the supercell, and &amp;lt;math&amp;gt;d_{eff}&amp;lt;/math&amp;gt; is the effective thickness of the 2D system.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Nota bene&#039;&#039;&#039;: Non-linear response along &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;non-periodic directions&amp;lt;/span&amp;gt; is not implemented in Yambo, the code will print zero in these directions for all response functions. We plan to implement it in a future version of the code.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Links for schools==&lt;br /&gt;
* Back to [[Rome 2023#Tutorials]]&lt;br /&gt;
* Back to [[ICTP2020]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
{| style=&amp;quot;width:100%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|style=&amp;quot;width:25%; text-align:left&amp;quot;|Prev: [[Linear response from real time simulations|Linear response from real time simulations]]&lt;br /&gt;
|style=&amp;quot;width:45%; text-align:center&amp;quot;|Now: [[ICTP2020|ICTP  Tutorials]] --&amp;gt; [[Real time approach to non-linear response|Non Linear Response]] &lt;br /&gt;
|style=&amp;quot;width:50%; text-align:left&amp;quot;|Next: [[Correlation effects in the non-linear response|Correlation effects in the non-linear response ]]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Attacc</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Real_time_approach_to_non-linear_response_(SHG)&amp;diff=9146</id>
		<title>Real time approach to non-linear response (SHG)</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Real_time_approach_to_non-linear_response_(SHG)&amp;diff=9146"/>
		<updated>2025-09-27T08:34:06Z</updated>

		<summary type="html">&lt;p&gt;Attacc: /* How to choose the external field direction for the different X2 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Second Harmonic Generation in AlAs ==&lt;br /&gt;
In this tutorial, we will calculate the second harmonic generation of bulk AlAs, the Yambo databases can be downloaded here: [https://media.yambo-code.eu/educational/tutorials/files/AlAs_DBs.tar.gz AlAs_DBs.tar.gz] (10 MB). The first steps of this tutorials are the same as the one on [http://www.yambo-code.eu/wiki/index.php?title=Prerequisites_for_Real_Time_propagation_with_Yambo Prerequisites for Real-Time propagation with Yambo] with the only difference that we will work on AlAs and we will consider an external field in the direction &amp;lt;code&amp;gt; 1.000000 | 1.000000 | 0.000000 |&amp;lt;/code&amp;gt;. The DFT input are available here: [https://media.yambo-code.eu/educational/tutorials/files/AlAs_abinit.tar.gz ABINIT] or [https://media.yambo-code.eu/educational/tutorials/files/AlAs_pwscf.tar.gz QuantumEspresso].&lt;br /&gt;
You can run the DFT calculation with ABINIT with the command:&lt;br /&gt;
&lt;br /&gt;
 abinit &amp;lt; AlAs.in &amp;gt; output_AlAs                                             &lt;br /&gt;
&lt;br /&gt;
or using QuantumEspresso:&lt;br /&gt;
&lt;br /&gt;
 pw.x -inp AlAs.scf.in &amp;gt; output_scf&lt;br /&gt;
 pw.x -inp AlAs.nscf.in &amp;gt; output_scf                            &lt;br /&gt;
&lt;br /&gt;
and then import the ABINIT wave-function with the command:&lt;br /&gt;
&lt;br /&gt;
 a2y -F AlAso_DS2_WFK.nc                            &lt;br /&gt;
&lt;br /&gt;
and the QuantumEspresso one, in the folder AlAs.save with the command:&lt;br /&gt;
&lt;br /&gt;
 p2y                              &lt;br /&gt;
Now we consider an external field in the &amp;lt;code&amp;gt;[1,1,0]&amp;lt;/code&amp;gt; direction and remove symmetries not compatible with this field, as explained in the tutorial [http://www.yambo-code.eu/wiki/index.php?title=Prerequisites_for_Real_Time_propagation_with_Yambo Prerequisites for Real-Time propagation with Yambo].&lt;br /&gt;
&lt;br /&gt;
==Real-time simulation for the SHG==&lt;br /&gt;
&lt;br /&gt;
You can generate the input file with the command &amp;lt;code&amp;gt;yambo_nl -u n&amp;lt;/code&amp;gt;:&lt;br /&gt;
                       &lt;br /&gt;
 nloptics                      # [R NL] Non-linear optics&lt;br /&gt;
 % NLBands&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 3 | 6&amp;lt;/span&amp;gt; |                   # [NL] Bands&lt;br /&gt;
 %&lt;br /&gt;
 NLstep=   0.0100       fs    # [NL] Real Time step length&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;NLverbosity= &amp;quot;high&amp;quot;&amp;lt;/span&amp;gt;               # [NL] Verbosity level (low | high)&lt;br /&gt;
 NLtime=-1.000000           fs    # [NL] Simulation Time&lt;br /&gt;
 NLintegrator= &amp;quot;INVINT&amp;quot;       # [NL] Integrator (&amp;quot;EULEREXP/RK4/RK2EXP/HEUN/INVINT/CRANKNIC&amp;quot;)&lt;br /&gt;
 NLCorrelation= &amp;quot;IPA&amp;quot;         # [NL] Correlation (&amp;quot;IPA/HARTREE/TDDFT/LRC/JGM/SEX/HF&amp;quot;)&lt;br /&gt;
 NLLrcAlpha= 0.000000         # [NL] Long Range Correction&lt;br /&gt;
 % NLEnRange&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;  1.000000 | 5.000000 &amp;lt;/span&amp;gt;| eV    # [NL] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 NLEnSteps= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 5  &amp;lt;/span&amp;gt;              # [NL] Energy steps&lt;br /&gt;
 NLDamping= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 0.150000  &amp;lt;/span&amp;gt;  eV    # [NL] Damping&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 1.000000 | 1.000000 | 0.000000 &amp;lt;/span&amp;gt;|        # [RT Field1] Versor&lt;br /&gt;
 Field1_kind= &amp;quot;SOFTSIN&amp;quot;         # [NL ExtF] Kind(SIN|SOFTSIN|RES|ANTIRES|GAUSS|DELTA|QSSIN)&lt;br /&gt;
&lt;br /&gt;
The line &amp;lt;code&amp;gt;|1.000000 | 1.000000 | 0.000000 | # [RT Field1] Versor&amp;lt;/code&amp;gt; referees to the direction of the external field (x,y,0). At present only an external field is present but the code can be easily generalized to deal with more fields.&lt;br /&gt;
The default parameters of Yambo/Lumen are already tuned for second-harmonic generation, so the only thing you have to change is the band range, between 3 and 6 and the energy range between 1.0-5.0 eV and the number of energy steps in this interval that we set to 10. Notice that you cannot set to zero the lowest value of the energy range because this will requires a simulation that lasts infinite time, see below. Finally, consider that Yambo performs a separate calculation for each frequency, so if you set many energy steps the computational time grows linearly with this number.&lt;br /&gt;
Notice that we set &amp;lt;code&amp;gt;NLverbosity= &amp;quot;high&amp;quot;&amp;lt;/code&amp;gt; in this way the code will produce a file for each laser frequency containing the time dependent polarization.&lt;br /&gt;
Run &amp;lt;code&amp;gt;yambo_nl&amp;lt;/code&amp;gt;. Calculations will take about fifteen minutes on a single processor PC, you have time to study the next section that explains how non-linear response is extracted from the real-time simulations.&lt;br /&gt;
In order to speed up calculations, you can run them in parallel.&lt;br /&gt;
&lt;br /&gt;
==Non-linear response with Yambo==&lt;br /&gt;
&lt;br /&gt;
In order to calculate the non-linear response, the system is excited with different laser fields with a sinusoidal shape at frequencies &amp;lt;math&amp;gt;\omega_1, \omega_2, .... , \omega_n &amp;lt;/math&amp;gt; determined by the parameters [[Variables#NLEnRangev|NLEnRange]] and [[Variables#NLEnSteps|NLEnSteps]]. A dephasing term is added to the Hamiltonian &amp;lt;math&amp;gt;\gamma = &amp;lt;/math&amp;gt;[[Variables#NLDamping|NLDamping]] to simulate a finite broadening and to remove the eigenmodes that are excited by the sudden turning on of the external field. After the dephasing time the outgoing signal is analyzed to extract the non-linear coefficients as shown in the figure below: &lt;br /&gt;
&lt;br /&gt;
[[File:Pt analysis.png|600px|center|Non-linear response analysis]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the report file &amp;lt;code&amp;gt;r_nlinear&amp;lt;/code&amp;gt; you will find the length of the dephasing part and of the sampling one:&lt;br /&gt;
&lt;br /&gt;
  Dephasing Time          [fs]: 52.65695&lt;br /&gt;
  Sampling  Time          [fs]:  4.18566&lt;br /&gt;
  Total simulation time   [fs]: 56.84262                     &lt;br /&gt;
The length of the dephasing interval is inversely proportional to the damping term &amp;lt;math&amp;gt;T_{depth} \simeq 1/\gamma&amp;lt;/math&amp;gt; while the length of the sampling is dictated by the smallest frequency we are interested in: &amp;lt;math&amp;gt;T_{samp} \simeq 1/\omega_1 &amp;lt;/math&amp;gt;. For this reason if &amp;lt;math&amp;gt; \omega_1=0 &amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt; \gamma = 0 &amp;lt;/math&amp;gt; simulation time goes to infinity. The response at zero frequency can be calculated as limit of small frequency perturbation.&lt;br /&gt;
You can have a look to the file &amp;lt;code&amp;gt;src/nloptics/NL_initialize.F&amp;lt;/code&amp;gt; to see how simulation lengths are defined.&lt;br /&gt;
Calculations can take some time, run them in parallel, the best number of processors = number of frequencies or reduce the number of frequencies step in the SHG.&lt;br /&gt;
&lt;br /&gt;
==Analysis of the results==&lt;br /&gt;
&lt;br /&gt;
In the sampling region we suppose that the polarization can be written as: &amp;lt;math&amp;gt;\bf{P}(t) = \sum_{n=-\infty}^{+\infty} \bf{p}_n e^{-i\omega_n t} &amp;lt;/math&amp;gt; where the coefficient &amp;lt;math&amp;gt;\bf{p}_1,...,\bf{p}_n &amp;lt;/math&amp;gt; are related to &amp;lt;math&amp;gt;\chi^{(1)},...,\chi^{(n)} &amp;lt;/math&amp;gt;. We sample the polarization signal at different times and invert the previous equation by truncating the sum at a finite order &amp;lt;ref&amp;gt;[https://arxiv.org/abs/1309.4012 Nonlinear optics from an ab initio approach by means of the dynamical Berry phase: Application to second- and third-harmonic generation in semiconductors], C. Attaccalite and M. Grüning, Phys. Rev. B 88, 235113(2013)&amp;lt;/ref&amp;gt;.&lt;br /&gt;
This is done with the command &amp;lt;code&amp;gt;ypp_nl -u&amp;lt;/code&amp;gt; that automatically produce an input with the correct values:&lt;br /&gt;
&lt;br /&gt;
 nonlinear                    # [R] NonLinear Optics Post-Processing&lt;br /&gt;
 Xorder=   &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;4  &amp;lt;/span&amp;gt;                 # Max order of the response functions&lt;br /&gt;
 % TimeRange&lt;br /&gt;
  52.65695 | -1.00000 | fs    # Time-window where processing is done&lt;br /&gt;
 % &lt;br /&gt;
 ETStpsRt= 200                # Total Energy steps&lt;br /&gt;
 % EnRngeRt&lt;br /&gt;
   0.00000 | 10.00000 | eV    # Energy range&lt;br /&gt;
 %&lt;br /&gt;
 DampMode= &amp;quot;NONE&amp;quot;             # Damping type ( NONE | LORENTZIAN | GAUSSIAN )&lt;br /&gt;
 DampFactor=  0.10000   eV    # Damping parameter&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;code&amp;gt;Xorder&amp;lt;/code&amp;gt; is the order where the previous sum is truncated, and the TimeRange specifies the sampling region. Notice that differently from the first tutorial, in this case, we do not need Damping in &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; because we already included it in the real-time dynamics. Run &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; and it will produce a file called &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;. This file contains the different components of &amp;lt;math&amp;gt;\chi^2_{xy*} &amp;lt;/math&amp;gt; and in particular the columns 6 and 7 correspond to the imaginary and real part of &amp;lt;math&amp;gt;\chi^2_{xyz} &amp;lt;/math&amp;gt;. You can plot the result with gnuplot and the command:&lt;br /&gt;
&lt;br /&gt;
 p &#039;o.YPP-X_probe_order_2&#039; u 1:(sqrt($6**2+$7**2)) w lp ps 1.5 pt 7 lw 1.5&lt;br /&gt;
&lt;br /&gt;
the result should look like&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AlAs results.png|700px|center|SHG in AlAs]]&lt;br /&gt;
&lt;br /&gt;
and compare it with the &amp;lt;math&amp;gt; \chi^2_{zxy} &amp;lt;/math&amp;gt; calculated with more frequencies and with the converged result on a &amp;lt;math&amp;gt; 18x18x18&amp;lt;/math&amp;gt; k-point grid and bands between 2 and 10. In the figure you can find also the comparison with the results of Ref. &amp;lt;ref&amp;gt;Luppi et al. [https://arxiv.org/abs/1006.2649 PRB B, &#039;&#039;&#039;82&#039;&#039;&#039;, 235201(2010)]&amp;lt;/ref&amp;gt;. &lt;br /&gt;
Notice that the QuantumEspresso results are slightly different from the Abinit ones. This is due to the different pseudo-potential employed in the calculations if pseudopotentials were the same calculation would have been identical. You can download the script to generate this plot and the converged results [http://www.attaccalite.com/lumen/tutorials/AlAs/AlAs_results.tgz here].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notice that&#039;&#039;&#039; : the following parameters are not used in the non-linear response analysis: &amp;lt;code&amp;gt; EnRngeRt&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ETStpsRt&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;DampMode&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;DampFactor&amp;lt;/code&amp;gt;. The damping factor is set directly in the real-time simulation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;System of units in Non-linear Optics&amp;lt;/span&amp;gt;&#039;&#039;&#039;: notice that in Yambo the non-linear response functions are in the gaussian system of units, for example the &amp;lt;math&amp;gt; \chi^2 (\omega) &amp;lt;/math&amp;gt;  is in cm/statvolt. In order to convert the non-linear coefficients between different system of units, you can have a look at the [https://www.attaccalite.com/tutorials_yambo/Appendix_C_Boyd.pdf Appendix C] of the book [https://www.elsevier.com/books/nonlinear-optics/boyd/978-0-12-369470-6 &amp;quot;Non-linear optics&amp;quot;  by Robert W. Boyd].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;More tutorials&amp;lt;/span&amp;gt; on non-linear response (Third harmonic generation, parallelization, spin-orbit etc..) with Yambo can be found here: [http://www.attaccalite.com/lumen/tutorials.html More Tutorials]. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Analysis of the results using YamboPy==&lt;br /&gt;
The analysis of the result performed in the previous section using &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; can be performed using python script [https://github.com/yambo-code/yambopy YamboPy].&amp;lt;br&amp;gt;&lt;br /&gt;
In YamboPy we implemented all necessary functions to reads the Yambo databases and post-process the results. Here we show how to get the SHG signal from the previous &lt;br /&gt;
simulations. We suppose you correctly installed &amp;lt;code&amp;gt;YamboPy&amp;lt;/code&amp;gt; on your PC. Go in the folder where you ran non-linear calculation and type in the python:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
 from yambopy import *&lt;br /&gt;
 NLDB=YamboNLDB()&lt;br /&gt;
 pol =NLDB.Polarization[0]&lt;br /&gt;
 time=NLDB.IO_TIME_points&lt;br /&gt;
&lt;br /&gt;
in this way you read all the Non-linear databases. If your runs are in a different folder then the &#039;SAVE&#039; one you can specify it using the command:&lt;br /&gt;
 NLDB=YamboNLDB(calc=&#039;MYJOB&#039;)&lt;br /&gt;
&lt;br /&gt;
now in the array &amp;lt;code&amp;gt;pol&amp;lt;/code&amp;gt; you have all the polarization for all laser frequencies in the three Cartesian directions, while the variable &amp;lt;code&amp;gt;time&amp;lt;/code&amp;gt; contains all the time series of your simulation.&lt;br /&gt;
Now you can get the non-linear response with the command:&lt;br /&gt;
&lt;br /&gt;
 Harmonic_Analysis(NLDB,X_order=4)&lt;br /&gt;
&lt;br /&gt;
this command will perform a Fourier analysis of the results in the same way of &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; and generate new files with all the requested harmonics &#039;&#039;o.YamboPy-X_probe_order_1&#039;&#039;, &#039;&#039;o.YamboPy-X_probe_order_2&#039;&#039; etc...&lt;br /&gt;
equivalent to the one generated by &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt;. Results can be plot with gnuplot using the command:&lt;br /&gt;
 &lt;br /&gt;
 p &#039;o.YamboPy-X_probe_order_2&#039; u 1:(sqrt($6**2+$7**2)) w lp ps 1.5 pt 7 lw 1.5&lt;br /&gt;
&lt;br /&gt;
The script that performs non-linear analysis can be found in &amp;lt;code&amp;gt;yambopy/nl/harmonic_analysis.py&amp;lt;/code&amp;gt;. &amp;lt;br&amp;gt; We strongly advice you to have a look to this script and modify it according&lt;br /&gt;
to your needs and in order to extract other non-linear response functions.&lt;br /&gt;
&lt;br /&gt;
==How to choose the external field direction for the different X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
In the X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;abc&amp;lt;/sub&amp;gt; response you have three field directions. The two components &#039;&#039;b&#039;&#039; and &#039;&#039;c&#039;&#039; are determined by the external field and the third &#039;&#039;a&#039;&#039;&lt;br /&gt;
is the direction where you measure the response.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The external field in Yambo is set using the variable&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
   1.000000 | 0.000000 | 0.000000 |        # [NL ExtF] Versor .&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
For example if you set in Yambo field direction as:&lt;br /&gt;
&lt;br /&gt;
 1.0 | 0.0 | 0.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*xx&amp;lt;/sub&amp;gt;&lt;br /&gt;
 0.0 | 1.0 | 0.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*yy&amp;lt;/sub&amp;gt;&lt;br /&gt;
 0.0 | 0.0 | 1.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*zz&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the * correspond to the different direction in the response file &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;.&lt;br /&gt;
In the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt; you have seven columns:&lt;br /&gt;
&lt;br /&gt;
 The first column is the energy [[omega]],&lt;br /&gt;
 the 2nd and 3rd columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;x**&amp;lt;/sub&amp;gt;&lt;br /&gt;
 the 4th and 5th columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;y**&amp;lt;/sub&amp;gt;&lt;br /&gt;
 the 6th and 7th columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;z**&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where the ** are the direction of the incoming field, see above.&lt;br /&gt;
&lt;br /&gt;
For example if you want to calculate the X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;zxx&amp;lt;/sub&amp;gt; you put the external field in the direction &amp;lt;code&amp;gt; 1.0 | 0.0 | 0.0 |&amp;lt;/code&amp;gt;&lt;br /&gt;
and then plot the column 6 and 7 of the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt; file.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Nota bene:&#039;&#039;&#039; if you change the direction of the external field you have to remove the corresponding symmetries as explained in the tutorial &lt;br /&gt;
on [[Prerequisites for Real Time_propagation with Yambo#Reduce symmetries real-time linear response tutorial]].&lt;br /&gt;
&lt;br /&gt;
In order to get the other components of the  X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; the calculation are more involved. For example if you put field in the&lt;br /&gt;
&lt;br /&gt;
 1.0 | 1.0 | 0.0 | &lt;br /&gt;
&lt;br /&gt;
this corresponds to &amp;lt;math&amp;gt;E(t)=\frac{1}{\sqrt{2}} [ E_x(t) + E_y(t) ]&amp;lt;/math&amp;gt; and so at the second order you will have &amp;lt;math&amp;gt;E^2(t)=\frac{1}{2} [ E^2_x(t) + E^2_y(t) +  E_x(t) E_y(t) +  E_y(t) E_x(t) ]&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
this means that  the X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; in the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;  will correspond to a linear combination of the following different response functions.&amp;lt;br&amp;gt;&lt;br /&gt;
For example in the the 2nd and 3rd columns are the imaginary and real part of:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{x**}=\frac{1}{2} \left [\chi^2_{xxx}+\chi^{(2)}_{xyy} + \chi^{(2)}_{xxy} + \chi^{(2)}_{xyx} \right ]&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the same for the other column replacing the first &amp;lt;code&amp;gt;x&amp;lt;/code&amp;gt; for &amp;lt;code&amp;gt;y,z&amp;lt;/code&amp;gt;.&lt;br /&gt;
If you know that some components are zero this allow you to extract the corresponding off-diagonal part of &amp;lt;math&amp;gt;\chi^2_{abc}&amp;lt;/math&amp;gt; otherwise you have to perform different calculations to get the component you are interested in. Hereafter we present a simple example of monolayer hBN (m-hBN). In m-hBN there is only a non-zero component of the $\chi^2$ and all the others are related by symmetry:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^{(2)}_{222}=-\chi^{(2)}_{211}=-\chi^{(2)}_{112}=-\chi^{(2)}_{121} \equiv \chi^{(2)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Non-linear response of low-dimensional structures: 2D or 1D ==&lt;br /&gt;
&lt;br /&gt;
The Yambo code is a 3D periodic code, so when you want to study a low-dimensional system 2D or 1D, you have to use a supercell approach.&lt;br /&gt;
For example to simulate the non-linear response in a 2D-crystal one, can put the crystal in the xy plane and choose a larger distance in the z-direction&lt;br /&gt;
in order to reduce the interaction between the periodic replica. Clearly in this case k-point sampling will be only in the x,y directions.&lt;br /&gt;
For calculations on this type of systems, these two warnings must be taken into account:&lt;br /&gt;
&lt;br /&gt;
* if you calculate GW corrections or include electron-hole interaction in the linear/non-linear response it is a good idea to use a &#039;&#039;&#039;Coulomb cutoff&#039;&#039;&#039;, similar to the 2D BSE case  [http://www.yambo-code.org/wiki/index.php?title=How_to_treat_low_dimensional_systems How to treat low dimensional systems]. You can add the cutoff just adding the &amp;quot;-r&amp;quot; in the input generation.&lt;br /&gt;
&lt;br /&gt;
* the calculation of SHG and THG are always performed respect to the supercell, therefore you have to &#039;&#039;&#039;re-scale&#039;&#039;&#039; the result to the effective thickness of the layer, usually the inter-layer distance of the corresponding bulk material for 2D systems: &amp;lt;math&amp;gt;\chi_{rescaled}(\omega) = L_z/d_{eff} \cdot \chi(\omega) &amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;L_z&amp;lt;/math&amp;gt; is the z-dimension of the supercell, and &amp;lt;math&amp;gt;d_{eff}&amp;lt;/math&amp;gt; is the effective thickness of the 2D system.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Nota bene&#039;&#039;&#039;: Non-linear response along &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;non-periodic directions&amp;lt;/span&amp;gt; is not implemented in Yambo, the code will print zero in these directions for all response functions. We plan to implement it in a future version of the code.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Links for schools==&lt;br /&gt;
* Back to [[Rome 2023#Tutorials]]&lt;br /&gt;
* Back to [[ICTP2020]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
{| style=&amp;quot;width:100%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|style=&amp;quot;width:25%; text-align:left&amp;quot;|Prev: [[Linear response from real time simulations|Linear response from real time simulations]]&lt;br /&gt;
|style=&amp;quot;width:45%; text-align:center&amp;quot;|Now: [[ICTP2020|ICTP  Tutorials]] --&amp;gt; [[Real time approach to non-linear response|Non Linear Response]] &lt;br /&gt;
|style=&amp;quot;width:50%; text-align:left&amp;quot;|Next: [[Correlation effects in the non-linear response|Correlation effects in the non-linear response ]]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Attacc</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Real_time_approach_to_non-linear_response_(SHG)&amp;diff=9145</id>
		<title>Real time approach to non-linear response (SHG)</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Real_time_approach_to_non-linear_response_(SHG)&amp;diff=9145"/>
		<updated>2025-09-27T08:32:57Z</updated>

		<summary type="html">&lt;p&gt;Attacc: /* How to choose the external field direction for the different X2 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Second Harmonic Generation in AlAs ==&lt;br /&gt;
In this tutorial, we will calculate the second harmonic generation of bulk AlAs, the Yambo databases can be downloaded here: [https://media.yambo-code.eu/educational/tutorials/files/AlAs_DBs.tar.gz AlAs_DBs.tar.gz] (10 MB). The first steps of this tutorials are the same as the one on [http://www.yambo-code.eu/wiki/index.php?title=Prerequisites_for_Real_Time_propagation_with_Yambo Prerequisites for Real-Time propagation with Yambo] with the only difference that we will work on AlAs and we will consider an external field in the direction &amp;lt;code&amp;gt; 1.000000 | 1.000000 | 0.000000 |&amp;lt;/code&amp;gt;. The DFT input are available here: [https://media.yambo-code.eu/educational/tutorials/files/AlAs_abinit.tar.gz ABINIT] or [https://media.yambo-code.eu/educational/tutorials/files/AlAs_pwscf.tar.gz QuantumEspresso].&lt;br /&gt;
You can run the DFT calculation with ABINIT with the command:&lt;br /&gt;
&lt;br /&gt;
 abinit &amp;lt; AlAs.in &amp;gt; output_AlAs                                             &lt;br /&gt;
&lt;br /&gt;
or using QuantumEspresso:&lt;br /&gt;
&lt;br /&gt;
 pw.x -inp AlAs.scf.in &amp;gt; output_scf&lt;br /&gt;
 pw.x -inp AlAs.nscf.in &amp;gt; output_scf                            &lt;br /&gt;
&lt;br /&gt;
and then import the ABINIT wave-function with the command:&lt;br /&gt;
&lt;br /&gt;
 a2y -F AlAso_DS2_WFK.nc                            &lt;br /&gt;
&lt;br /&gt;
and the QuantumEspresso one, in the folder AlAs.save with the command:&lt;br /&gt;
&lt;br /&gt;
 p2y                              &lt;br /&gt;
Now we consider an external field in the &amp;lt;code&amp;gt;[1,1,0]&amp;lt;/code&amp;gt; direction and remove symmetries not compatible with this field, as explained in the tutorial [http://www.yambo-code.eu/wiki/index.php?title=Prerequisites_for_Real_Time_propagation_with_Yambo Prerequisites for Real-Time propagation with Yambo].&lt;br /&gt;
&lt;br /&gt;
==Real-time simulation for the SHG==&lt;br /&gt;
&lt;br /&gt;
You can generate the input file with the command &amp;lt;code&amp;gt;yambo_nl -u n&amp;lt;/code&amp;gt;:&lt;br /&gt;
                       &lt;br /&gt;
 nloptics                      # [R NL] Non-linear optics&lt;br /&gt;
 % NLBands&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 3 | 6&amp;lt;/span&amp;gt; |                   # [NL] Bands&lt;br /&gt;
 %&lt;br /&gt;
 NLstep=   0.0100       fs    # [NL] Real Time step length&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;NLverbosity= &amp;quot;high&amp;quot;&amp;lt;/span&amp;gt;               # [NL] Verbosity level (low | high)&lt;br /&gt;
 NLtime=-1.000000           fs    # [NL] Simulation Time&lt;br /&gt;
 NLintegrator= &amp;quot;INVINT&amp;quot;       # [NL] Integrator (&amp;quot;EULEREXP/RK4/RK2EXP/HEUN/INVINT/CRANKNIC&amp;quot;)&lt;br /&gt;
 NLCorrelation= &amp;quot;IPA&amp;quot;         # [NL] Correlation (&amp;quot;IPA/HARTREE/TDDFT/LRC/JGM/SEX/HF&amp;quot;)&lt;br /&gt;
 NLLrcAlpha= 0.000000         # [NL] Long Range Correction&lt;br /&gt;
 % NLEnRange&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;  1.000000 | 5.000000 &amp;lt;/span&amp;gt;| eV    # [NL] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 NLEnSteps= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 5  &amp;lt;/span&amp;gt;              # [NL] Energy steps&lt;br /&gt;
 NLDamping= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 0.150000  &amp;lt;/span&amp;gt;  eV    # [NL] Damping&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 1.000000 | 1.000000 | 0.000000 &amp;lt;/span&amp;gt;|        # [RT Field1] Versor&lt;br /&gt;
 Field1_kind= &amp;quot;SOFTSIN&amp;quot;         # [NL ExtF] Kind(SIN|SOFTSIN|RES|ANTIRES|GAUSS|DELTA|QSSIN)&lt;br /&gt;
&lt;br /&gt;
The line &amp;lt;code&amp;gt;|1.000000 | 1.000000 | 0.000000 | # [RT Field1] Versor&amp;lt;/code&amp;gt; referees to the direction of the external field (x,y,0). At present only an external field is present but the code can be easily generalized to deal with more fields.&lt;br /&gt;
The default parameters of Yambo/Lumen are already tuned for second-harmonic generation, so the only thing you have to change is the band range, between 3 and 6 and the energy range between 1.0-5.0 eV and the number of energy steps in this interval that we set to 10. Notice that you cannot set to zero the lowest value of the energy range because this will requires a simulation that lasts infinite time, see below. Finally, consider that Yambo performs a separate calculation for each frequency, so if you set many energy steps the computational time grows linearly with this number.&lt;br /&gt;
Notice that we set &amp;lt;code&amp;gt;NLverbosity= &amp;quot;high&amp;quot;&amp;lt;/code&amp;gt; in this way the code will produce a file for each laser frequency containing the time dependent polarization.&lt;br /&gt;
Run &amp;lt;code&amp;gt;yambo_nl&amp;lt;/code&amp;gt;. Calculations will take about fifteen minutes on a single processor PC, you have time to study the next section that explains how non-linear response is extracted from the real-time simulations.&lt;br /&gt;
In order to speed up calculations, you can run them in parallel.&lt;br /&gt;
&lt;br /&gt;
==Non-linear response with Yambo==&lt;br /&gt;
&lt;br /&gt;
In order to calculate the non-linear response, the system is excited with different laser fields with a sinusoidal shape at frequencies &amp;lt;math&amp;gt;\omega_1, \omega_2, .... , \omega_n &amp;lt;/math&amp;gt; determined by the parameters [[Variables#NLEnRangev|NLEnRange]] and [[Variables#NLEnSteps|NLEnSteps]]. A dephasing term is added to the Hamiltonian &amp;lt;math&amp;gt;\gamma = &amp;lt;/math&amp;gt;[[Variables#NLDamping|NLDamping]] to simulate a finite broadening and to remove the eigenmodes that are excited by the sudden turning on of the external field. After the dephasing time the outgoing signal is analyzed to extract the non-linear coefficients as shown in the figure below: &lt;br /&gt;
&lt;br /&gt;
[[File:Pt analysis.png|600px|center|Non-linear response analysis]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the report file &amp;lt;code&amp;gt;r_nlinear&amp;lt;/code&amp;gt; you will find the length of the dephasing part and of the sampling one:&lt;br /&gt;
&lt;br /&gt;
  Dephasing Time          [fs]: 52.65695&lt;br /&gt;
  Sampling  Time          [fs]:  4.18566&lt;br /&gt;
  Total simulation time   [fs]: 56.84262                     &lt;br /&gt;
The length of the dephasing interval is inversely proportional to the damping term &amp;lt;math&amp;gt;T_{depth} \simeq 1/\gamma&amp;lt;/math&amp;gt; while the length of the sampling is dictated by the smallest frequency we are interested in: &amp;lt;math&amp;gt;T_{samp} \simeq 1/\omega_1 &amp;lt;/math&amp;gt;. For this reason if &amp;lt;math&amp;gt; \omega_1=0 &amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt; \gamma = 0 &amp;lt;/math&amp;gt; simulation time goes to infinity. The response at zero frequency can be calculated as limit of small frequency perturbation.&lt;br /&gt;
You can have a look to the file &amp;lt;code&amp;gt;src/nloptics/NL_initialize.F&amp;lt;/code&amp;gt; to see how simulation lengths are defined.&lt;br /&gt;
Calculations can take some time, run them in parallel, the best number of processors = number of frequencies or reduce the number of frequencies step in the SHG.&lt;br /&gt;
&lt;br /&gt;
==Analysis of the results==&lt;br /&gt;
&lt;br /&gt;
In the sampling region we suppose that the polarization can be written as: &amp;lt;math&amp;gt;\bf{P}(t) = \sum_{n=-\infty}^{+\infty} \bf{p}_n e^{-i\omega_n t} &amp;lt;/math&amp;gt; where the coefficient &amp;lt;math&amp;gt;\bf{p}_1,...,\bf{p}_n &amp;lt;/math&amp;gt; are related to &amp;lt;math&amp;gt;\chi^{(1)},...,\chi^{(n)} &amp;lt;/math&amp;gt;. We sample the polarization signal at different times and invert the previous equation by truncating the sum at a finite order &amp;lt;ref&amp;gt;[https://arxiv.org/abs/1309.4012 Nonlinear optics from an ab initio approach by means of the dynamical Berry phase: Application to second- and third-harmonic generation in semiconductors], C. Attaccalite and M. Grüning, Phys. Rev. B 88, 235113(2013)&amp;lt;/ref&amp;gt;.&lt;br /&gt;
This is done with the command &amp;lt;code&amp;gt;ypp_nl -u&amp;lt;/code&amp;gt; that automatically produce an input with the correct values:&lt;br /&gt;
&lt;br /&gt;
 nonlinear                    # [R] NonLinear Optics Post-Processing&lt;br /&gt;
 Xorder=   &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;4  &amp;lt;/span&amp;gt;                 # Max order of the response functions&lt;br /&gt;
 % TimeRange&lt;br /&gt;
  52.65695 | -1.00000 | fs    # Time-window where processing is done&lt;br /&gt;
 % &lt;br /&gt;
 ETStpsRt= 200                # Total Energy steps&lt;br /&gt;
 % EnRngeRt&lt;br /&gt;
   0.00000 | 10.00000 | eV    # Energy range&lt;br /&gt;
 %&lt;br /&gt;
 DampMode= &amp;quot;NONE&amp;quot;             # Damping type ( NONE | LORENTZIAN | GAUSSIAN )&lt;br /&gt;
 DampFactor=  0.10000   eV    # Damping parameter&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;code&amp;gt;Xorder&amp;lt;/code&amp;gt; is the order where the previous sum is truncated, and the TimeRange specifies the sampling region. Notice that differently from the first tutorial, in this case, we do not need Damping in &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; because we already included it in the real-time dynamics. Run &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; and it will produce a file called &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;. This file contains the different components of &amp;lt;math&amp;gt;\chi^2_{xy*} &amp;lt;/math&amp;gt; and in particular the columns 6 and 7 correspond to the imaginary and real part of &amp;lt;math&amp;gt;\chi^2_{xyz} &amp;lt;/math&amp;gt;. You can plot the result with gnuplot and the command:&lt;br /&gt;
&lt;br /&gt;
 p &#039;o.YPP-X_probe_order_2&#039; u 1:(sqrt($6**2+$7**2)) w lp ps 1.5 pt 7 lw 1.5&lt;br /&gt;
&lt;br /&gt;
the result should look like&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AlAs results.png|700px|center|SHG in AlAs]]&lt;br /&gt;
&lt;br /&gt;
and compare it with the &amp;lt;math&amp;gt; \chi^2_{zxy} &amp;lt;/math&amp;gt; calculated with more frequencies and with the converged result on a &amp;lt;math&amp;gt; 18x18x18&amp;lt;/math&amp;gt; k-point grid and bands between 2 and 10. In the figure you can find also the comparison with the results of Ref. &amp;lt;ref&amp;gt;Luppi et al. [https://arxiv.org/abs/1006.2649 PRB B, &#039;&#039;&#039;82&#039;&#039;&#039;, 235201(2010)]&amp;lt;/ref&amp;gt;. &lt;br /&gt;
Notice that the QuantumEspresso results are slightly different from the Abinit ones. This is due to the different pseudo-potential employed in the calculations if pseudopotentials were the same calculation would have been identical. You can download the script to generate this plot and the converged results [http://www.attaccalite.com/lumen/tutorials/AlAs/AlAs_results.tgz here].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notice that&#039;&#039;&#039; : the following parameters are not used in the non-linear response analysis: &amp;lt;code&amp;gt; EnRngeRt&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ETStpsRt&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;DampMode&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;DampFactor&amp;lt;/code&amp;gt;. The damping factor is set directly in the real-time simulation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;System of units in Non-linear Optics&amp;lt;/span&amp;gt;&#039;&#039;&#039;: notice that in Yambo the non-linear response functions are in the gaussian system of units, for example the &amp;lt;math&amp;gt; \chi^2 (\omega) &amp;lt;/math&amp;gt;  is in cm/statvolt. In order to convert the non-linear coefficients between different system of units, you can have a look at the [https://www.attaccalite.com/tutorials_yambo/Appendix_C_Boyd.pdf Appendix C] of the book [https://www.elsevier.com/books/nonlinear-optics/boyd/978-0-12-369470-6 &amp;quot;Non-linear optics&amp;quot;  by Robert W. Boyd].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;More tutorials&amp;lt;/span&amp;gt; on non-linear response (Third harmonic generation, parallelization, spin-orbit etc..) with Yambo can be found here: [http://www.attaccalite.com/lumen/tutorials.html More Tutorials]. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Analysis of the results using YamboPy==&lt;br /&gt;
The analysis of the result performed in the previous section using &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; can be performed using python script [https://github.com/yambo-code/yambopy YamboPy].&amp;lt;br&amp;gt;&lt;br /&gt;
In YamboPy we implemented all necessary functions to reads the Yambo databases and post-process the results. Here we show how to get the SHG signal from the previous &lt;br /&gt;
simulations. We suppose you correctly installed &amp;lt;code&amp;gt;YamboPy&amp;lt;/code&amp;gt; on your PC. Go in the folder where you ran non-linear calculation and type in the python:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
 from yambopy import *&lt;br /&gt;
 NLDB=YamboNLDB()&lt;br /&gt;
 pol =NLDB.Polarization[0]&lt;br /&gt;
 time=NLDB.IO_TIME_points&lt;br /&gt;
&lt;br /&gt;
in this way you read all the Non-linear databases. If your runs are in a different folder then the &#039;SAVE&#039; one you can specify it using the command:&lt;br /&gt;
 NLDB=YamboNLDB(calc=&#039;MYJOB&#039;)&lt;br /&gt;
&lt;br /&gt;
now in the array &amp;lt;code&amp;gt;pol&amp;lt;/code&amp;gt; you have all the polarization for all laser frequencies in the three Cartesian directions, while the variable &amp;lt;code&amp;gt;time&amp;lt;/code&amp;gt; contains all the time series of your simulation.&lt;br /&gt;
Now you can get the non-linear response with the command:&lt;br /&gt;
&lt;br /&gt;
 Harmonic_Analysis(NLDB,X_order=4)&lt;br /&gt;
&lt;br /&gt;
this command will perform a Fourier analysis of the results in the same way of &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; and generate new files with all the requested harmonics &#039;&#039;o.YamboPy-X_probe_order_1&#039;&#039;, &#039;&#039;o.YamboPy-X_probe_order_2&#039;&#039; etc...&lt;br /&gt;
equivalent to the one generated by &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt;. Results can be plot with gnuplot using the command:&lt;br /&gt;
 &lt;br /&gt;
 p &#039;o.YamboPy-X_probe_order_2&#039; u 1:(sqrt($6**2+$7**2)) w lp ps 1.5 pt 7 lw 1.5&lt;br /&gt;
&lt;br /&gt;
The script that performs non-linear analysis can be found in &amp;lt;code&amp;gt;yambopy/nl/harmonic_analysis.py&amp;lt;/code&amp;gt;. &amp;lt;br&amp;gt; We strongly advice you to have a look to this script and modify it according&lt;br /&gt;
to your needs and in order to extract other non-linear response functions.&lt;br /&gt;
&lt;br /&gt;
==How to choose the external field direction for the different X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
In the X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;abc&amp;lt;/sub&amp;gt; response you have three field directions. The two components &#039;&#039;b&#039;&#039; and &#039;&#039;c&#039;&#039; are determined by the external field and the third &#039;&#039;a&#039;&#039;&lt;br /&gt;
is the direction where you measure the response.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The external field in Yambo is set using the variable&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
   1.000000 | 0.000000 | 0.000000 |        # [NL ExtF] Versor .&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
For example if you set in Yambo field direction as:&lt;br /&gt;
&lt;br /&gt;
 1.0 | 0.0 | 0.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*xx&amp;lt;/sub&amp;gt;&lt;br /&gt;
 0.0 | 1.0 | 0.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*yy&amp;lt;/sub&amp;gt;&lt;br /&gt;
 0.0 | 0.0 | 1.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*zz&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the * correspond to the different direction in the response file &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;.&lt;br /&gt;
In the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt; you have seven columns:&lt;br /&gt;
&lt;br /&gt;
 The first column is the energy [[omega]],&lt;br /&gt;
 the 2nd and 3rd columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;x**&amp;lt;/sub&amp;gt;&lt;br /&gt;
 the 4th and 5th columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;y**&amp;lt;/sub&amp;gt;&lt;br /&gt;
 the 6th and 7th columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;z**&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where the ** are the direction of the incoming field, see above.&lt;br /&gt;
&lt;br /&gt;
For example if you want to calculate the X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;zxx&amp;lt;/sub&amp;gt; you put the external field in the direction &amp;lt;code&amp;gt; 1.0 | 0.0 | 0.0 |&amp;lt;/code&amp;gt;&lt;br /&gt;
and then plot the column 6 and 7 of the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt; file.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Nota bene:&#039;&#039;&#039; if you change the direction of the external field you have to remove the corresponding symmetries as explained in the tutorial &lt;br /&gt;
on [[Prerequisites for Real Time_propagation with Yambo#Reduce symmetries real-time linear response tutorial]].&lt;br /&gt;
&lt;br /&gt;
In order to get the other components of the  X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; the calculation are more involved. For example if you put field in the&lt;br /&gt;
&lt;br /&gt;
 1.0 | 1.0 | 0.0 | &lt;br /&gt;
&lt;br /&gt;
this corresponds to &amp;lt;math&amp;gt;E(t)=\frac{1}{\sqrt{2}} [ E_x(t) + E_y(t) ]&amp;lt;/math&amp;gt; and so at the second order you will have &amp;lt;math&amp;gt;E^2(t)=\frac{1}{2} [ E^2_x(t) + E^2_y(t) +  E_x(t) E_y(t) +  E_y(t) E_x(t) ]&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
this means that  the X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; in the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;  will correspond to a linear combination of the following different response functions.&amp;lt;br&amp;gt;&lt;br /&gt;
For example in the the 2nd and 3rd columns are the imaginary and real part of:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^2_{x**}=\frac{1}{2} \left [\chi^2_{xxx}+\chi^2_{xyy} + \chi^2_{xxy} + \chi^2_{xyx} \right ]&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the same for the other column replacing the first &amp;lt;code&amp;gt;x&amp;lt;/code&amp;gt; for &amp;lt;code&amp;gt;y,z&amp;lt;/code&amp;gt;.&lt;br /&gt;
If you know that some components are zero this allow you to extract the corresponding off-diagonal part of &amp;lt;math&amp;gt;\chi^2_{abc}&amp;lt;/math&amp;gt; otherwise you have to perform different calculations to get the component you are interested in. Hereafter we present a simple example of monolayer hBN (m-hBN). In m-hBN there is only a non-zero component of the $\chi^2$ and all the others are related by symmetry:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;$\chi^{(2)}_{222}=-\chi^{(2)}_{211}=-\chi^{(2)}_{112}=-\chi^{(2)}_{121} \equiv \chi^{(2)}$&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Non-linear response of low-dimensional structures: 2D or 1D ==&lt;br /&gt;
&lt;br /&gt;
The Yambo code is a 3D periodic code, so when you want to study a low-dimensional system 2D or 1D, you have to use a supercell approach.&lt;br /&gt;
For example to simulate the non-linear response in a 2D-crystal one, can put the crystal in the xy plane and choose a larger distance in the z-direction&lt;br /&gt;
in order to reduce the interaction between the periodic replica. Clearly in this case k-point sampling will be only in the x,y directions.&lt;br /&gt;
For calculations on this type of systems, these two warnings must be taken into account:&lt;br /&gt;
&lt;br /&gt;
* if you calculate GW corrections or include electron-hole interaction in the linear/non-linear response it is a good idea to use a &#039;&#039;&#039;Coulomb cutoff&#039;&#039;&#039;, similar to the 2D BSE case  [http://www.yambo-code.org/wiki/index.php?title=How_to_treat_low_dimensional_systems How to treat low dimensional systems]. You can add the cutoff just adding the &amp;quot;-r&amp;quot; in the input generation.&lt;br /&gt;
&lt;br /&gt;
* the calculation of SHG and THG are always performed respect to the supercell, therefore you have to &#039;&#039;&#039;re-scale&#039;&#039;&#039; the result to the effective thickness of the layer, usually the inter-layer distance of the corresponding bulk material for 2D systems: &amp;lt;math&amp;gt;\chi_{rescaled}(\omega) = L_z/d_{eff} \cdot \chi(\omega) &amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;L_z&amp;lt;/math&amp;gt; is the z-dimension of the supercell, and &amp;lt;math&amp;gt;d_{eff}&amp;lt;/math&amp;gt; is the effective thickness of the 2D system.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Nota bene&#039;&#039;&#039;: Non-linear response along &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;non-periodic directions&amp;lt;/span&amp;gt; is not implemented in Yambo, the code will print zero in these directions for all response functions. We plan to implement it in a future version of the code.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Links for schools==&lt;br /&gt;
* Back to [[Rome 2023#Tutorials]]&lt;br /&gt;
* Back to [[ICTP2020]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
{| style=&amp;quot;width:100%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|style=&amp;quot;width:25%; text-align:left&amp;quot;|Prev: [[Linear response from real time simulations|Linear response from real time simulations]]&lt;br /&gt;
|style=&amp;quot;width:45%; text-align:center&amp;quot;|Now: [[ICTP2020|ICTP  Tutorials]] --&amp;gt; [[Real time approach to non-linear response|Non Linear Response]] &lt;br /&gt;
|style=&amp;quot;width:50%; text-align:left&amp;quot;|Next: [[Correlation effects in the non-linear response|Correlation effects in the non-linear response ]]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Attacc</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Real_time_approach_to_non-linear_response_(SHG)&amp;diff=9144</id>
		<title>Real time approach to non-linear response (SHG)</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Real_time_approach_to_non-linear_response_(SHG)&amp;diff=9144"/>
		<updated>2025-09-27T08:30:46Z</updated>

		<summary type="html">&lt;p&gt;Attacc: /* How to choose the external field direction for the different X2 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Second Harmonic Generation in AlAs ==&lt;br /&gt;
In this tutorial, we will calculate the second harmonic generation of bulk AlAs, the Yambo databases can be downloaded here: [https://media.yambo-code.eu/educational/tutorials/files/AlAs_DBs.tar.gz AlAs_DBs.tar.gz] (10 MB). The first steps of this tutorials are the same as the one on [http://www.yambo-code.eu/wiki/index.php?title=Prerequisites_for_Real_Time_propagation_with_Yambo Prerequisites for Real-Time propagation with Yambo] with the only difference that we will work on AlAs and we will consider an external field in the direction &amp;lt;code&amp;gt; 1.000000 | 1.000000 | 0.000000 |&amp;lt;/code&amp;gt;. The DFT input are available here: [https://media.yambo-code.eu/educational/tutorials/files/AlAs_abinit.tar.gz ABINIT] or [https://media.yambo-code.eu/educational/tutorials/files/AlAs_pwscf.tar.gz QuantumEspresso].&lt;br /&gt;
You can run the DFT calculation with ABINIT with the command:&lt;br /&gt;
&lt;br /&gt;
 abinit &amp;lt; AlAs.in &amp;gt; output_AlAs                                             &lt;br /&gt;
&lt;br /&gt;
or using QuantumEspresso:&lt;br /&gt;
&lt;br /&gt;
 pw.x -inp AlAs.scf.in &amp;gt; output_scf&lt;br /&gt;
 pw.x -inp AlAs.nscf.in &amp;gt; output_scf                            &lt;br /&gt;
&lt;br /&gt;
and then import the ABINIT wave-function with the command:&lt;br /&gt;
&lt;br /&gt;
 a2y -F AlAso_DS2_WFK.nc                            &lt;br /&gt;
&lt;br /&gt;
and the QuantumEspresso one, in the folder AlAs.save with the command:&lt;br /&gt;
&lt;br /&gt;
 p2y                              &lt;br /&gt;
Now we consider an external field in the &amp;lt;code&amp;gt;[1,1,0]&amp;lt;/code&amp;gt; direction and remove symmetries not compatible with this field, as explained in the tutorial [http://www.yambo-code.eu/wiki/index.php?title=Prerequisites_for_Real_Time_propagation_with_Yambo Prerequisites for Real-Time propagation with Yambo].&lt;br /&gt;
&lt;br /&gt;
==Real-time simulation for the SHG==&lt;br /&gt;
&lt;br /&gt;
You can generate the input file with the command &amp;lt;code&amp;gt;yambo_nl -u n&amp;lt;/code&amp;gt;:&lt;br /&gt;
                       &lt;br /&gt;
 nloptics                      # [R NL] Non-linear optics&lt;br /&gt;
 % NLBands&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 3 | 6&amp;lt;/span&amp;gt; |                   # [NL] Bands&lt;br /&gt;
 %&lt;br /&gt;
 NLstep=   0.0100       fs    # [NL] Real Time step length&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;NLverbosity= &amp;quot;high&amp;quot;&amp;lt;/span&amp;gt;               # [NL] Verbosity level (low | high)&lt;br /&gt;
 NLtime=-1.000000           fs    # [NL] Simulation Time&lt;br /&gt;
 NLintegrator= &amp;quot;INVINT&amp;quot;       # [NL] Integrator (&amp;quot;EULEREXP/RK4/RK2EXP/HEUN/INVINT/CRANKNIC&amp;quot;)&lt;br /&gt;
 NLCorrelation= &amp;quot;IPA&amp;quot;         # [NL] Correlation (&amp;quot;IPA/HARTREE/TDDFT/LRC/JGM/SEX/HF&amp;quot;)&lt;br /&gt;
 NLLrcAlpha= 0.000000         # [NL] Long Range Correction&lt;br /&gt;
 % NLEnRange&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;  1.000000 | 5.000000 &amp;lt;/span&amp;gt;| eV    # [NL] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 NLEnSteps= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 5  &amp;lt;/span&amp;gt;              # [NL] Energy steps&lt;br /&gt;
 NLDamping= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 0.150000  &amp;lt;/span&amp;gt;  eV    # [NL] Damping&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 1.000000 | 1.000000 | 0.000000 &amp;lt;/span&amp;gt;|        # [RT Field1] Versor&lt;br /&gt;
 Field1_kind= &amp;quot;SOFTSIN&amp;quot;         # [NL ExtF] Kind(SIN|SOFTSIN|RES|ANTIRES|GAUSS|DELTA|QSSIN)&lt;br /&gt;
&lt;br /&gt;
The line &amp;lt;code&amp;gt;|1.000000 | 1.000000 | 0.000000 | # [RT Field1] Versor&amp;lt;/code&amp;gt; referees to the direction of the external field (x,y,0). At present only an external field is present but the code can be easily generalized to deal with more fields.&lt;br /&gt;
The default parameters of Yambo/Lumen are already tuned for second-harmonic generation, so the only thing you have to change is the band range, between 3 and 6 and the energy range between 1.0-5.0 eV and the number of energy steps in this interval that we set to 10. Notice that you cannot set to zero the lowest value of the energy range because this will requires a simulation that lasts infinite time, see below. Finally, consider that Yambo performs a separate calculation for each frequency, so if you set many energy steps the computational time grows linearly with this number.&lt;br /&gt;
Notice that we set &amp;lt;code&amp;gt;NLverbosity= &amp;quot;high&amp;quot;&amp;lt;/code&amp;gt; in this way the code will produce a file for each laser frequency containing the time dependent polarization.&lt;br /&gt;
Run &amp;lt;code&amp;gt;yambo_nl&amp;lt;/code&amp;gt;. Calculations will take about fifteen minutes on a single processor PC, you have time to study the next section that explains how non-linear response is extracted from the real-time simulations.&lt;br /&gt;
In order to speed up calculations, you can run them in parallel.&lt;br /&gt;
&lt;br /&gt;
==Non-linear response with Yambo==&lt;br /&gt;
&lt;br /&gt;
In order to calculate the non-linear response, the system is excited with different laser fields with a sinusoidal shape at frequencies &amp;lt;math&amp;gt;\omega_1, \omega_2, .... , \omega_n &amp;lt;/math&amp;gt; determined by the parameters [[Variables#NLEnRangev|NLEnRange]] and [[Variables#NLEnSteps|NLEnSteps]]. A dephasing term is added to the Hamiltonian &amp;lt;math&amp;gt;\gamma = &amp;lt;/math&amp;gt;[[Variables#NLDamping|NLDamping]] to simulate a finite broadening and to remove the eigenmodes that are excited by the sudden turning on of the external field. After the dephasing time the outgoing signal is analyzed to extract the non-linear coefficients as shown in the figure below: &lt;br /&gt;
&lt;br /&gt;
[[File:Pt analysis.png|600px|center|Non-linear response analysis]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the report file &amp;lt;code&amp;gt;r_nlinear&amp;lt;/code&amp;gt; you will find the length of the dephasing part and of the sampling one:&lt;br /&gt;
&lt;br /&gt;
  Dephasing Time          [fs]: 52.65695&lt;br /&gt;
  Sampling  Time          [fs]:  4.18566&lt;br /&gt;
  Total simulation time   [fs]: 56.84262                     &lt;br /&gt;
The length of the dephasing interval is inversely proportional to the damping term &amp;lt;math&amp;gt;T_{depth} \simeq 1/\gamma&amp;lt;/math&amp;gt; while the length of the sampling is dictated by the smallest frequency we are interested in: &amp;lt;math&amp;gt;T_{samp} \simeq 1/\omega_1 &amp;lt;/math&amp;gt;. For this reason if &amp;lt;math&amp;gt; \omega_1=0 &amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt; \gamma = 0 &amp;lt;/math&amp;gt; simulation time goes to infinity. The response at zero frequency can be calculated as limit of small frequency perturbation.&lt;br /&gt;
You can have a look to the file &amp;lt;code&amp;gt;src/nloptics/NL_initialize.F&amp;lt;/code&amp;gt; to see how simulation lengths are defined.&lt;br /&gt;
Calculations can take some time, run them in parallel, the best number of processors = number of frequencies or reduce the number of frequencies step in the SHG.&lt;br /&gt;
&lt;br /&gt;
==Analysis of the results==&lt;br /&gt;
&lt;br /&gt;
In the sampling region we suppose that the polarization can be written as: &amp;lt;math&amp;gt;\bf{P}(t) = \sum_{n=-\infty}^{+\infty} \bf{p}_n e^{-i\omega_n t} &amp;lt;/math&amp;gt; where the coefficient &amp;lt;math&amp;gt;\bf{p}_1,...,\bf{p}_n &amp;lt;/math&amp;gt; are related to &amp;lt;math&amp;gt;\chi^{(1)},...,\chi^{(n)} &amp;lt;/math&amp;gt;. We sample the polarization signal at different times and invert the previous equation by truncating the sum at a finite order &amp;lt;ref&amp;gt;[https://arxiv.org/abs/1309.4012 Nonlinear optics from an ab initio approach by means of the dynamical Berry phase: Application to second- and third-harmonic generation in semiconductors], C. Attaccalite and M. Grüning, Phys. Rev. B 88, 235113(2013)&amp;lt;/ref&amp;gt;.&lt;br /&gt;
This is done with the command &amp;lt;code&amp;gt;ypp_nl -u&amp;lt;/code&amp;gt; that automatically produce an input with the correct values:&lt;br /&gt;
&lt;br /&gt;
 nonlinear                    # [R] NonLinear Optics Post-Processing&lt;br /&gt;
 Xorder=   &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;4  &amp;lt;/span&amp;gt;                 # Max order of the response functions&lt;br /&gt;
 % TimeRange&lt;br /&gt;
  52.65695 | -1.00000 | fs    # Time-window where processing is done&lt;br /&gt;
 % &lt;br /&gt;
 ETStpsRt= 200                # Total Energy steps&lt;br /&gt;
 % EnRngeRt&lt;br /&gt;
   0.00000 | 10.00000 | eV    # Energy range&lt;br /&gt;
 %&lt;br /&gt;
 DampMode= &amp;quot;NONE&amp;quot;             # Damping type ( NONE | LORENTZIAN | GAUSSIAN )&lt;br /&gt;
 DampFactor=  0.10000   eV    # Damping parameter&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;code&amp;gt;Xorder&amp;lt;/code&amp;gt; is the order where the previous sum is truncated, and the TimeRange specifies the sampling region. Notice that differently from the first tutorial, in this case, we do not need Damping in &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; because we already included it in the real-time dynamics. Run &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; and it will produce a file called &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;. This file contains the different components of &amp;lt;math&amp;gt;\chi^2_{xy*} &amp;lt;/math&amp;gt; and in particular the columns 6 and 7 correspond to the imaginary and real part of &amp;lt;math&amp;gt;\chi^2_{xyz} &amp;lt;/math&amp;gt;. You can plot the result with gnuplot and the command:&lt;br /&gt;
&lt;br /&gt;
 p &#039;o.YPP-X_probe_order_2&#039; u 1:(sqrt($6**2+$7**2)) w lp ps 1.5 pt 7 lw 1.5&lt;br /&gt;
&lt;br /&gt;
the result should look like&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AlAs results.png|700px|center|SHG in AlAs]]&lt;br /&gt;
&lt;br /&gt;
and compare it with the &amp;lt;math&amp;gt; \chi^2_{zxy} &amp;lt;/math&amp;gt; calculated with more frequencies and with the converged result on a &amp;lt;math&amp;gt; 18x18x18&amp;lt;/math&amp;gt; k-point grid and bands between 2 and 10. In the figure you can find also the comparison with the results of Ref. &amp;lt;ref&amp;gt;Luppi et al. [https://arxiv.org/abs/1006.2649 PRB B, &#039;&#039;&#039;82&#039;&#039;&#039;, 235201(2010)]&amp;lt;/ref&amp;gt;. &lt;br /&gt;
Notice that the QuantumEspresso results are slightly different from the Abinit ones. This is due to the different pseudo-potential employed in the calculations if pseudopotentials were the same calculation would have been identical. You can download the script to generate this plot and the converged results [http://www.attaccalite.com/lumen/tutorials/AlAs/AlAs_results.tgz here].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notice that&#039;&#039;&#039; : the following parameters are not used in the non-linear response analysis: &amp;lt;code&amp;gt; EnRngeRt&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ETStpsRt&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;DampMode&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;DampFactor&amp;lt;/code&amp;gt;. The damping factor is set directly in the real-time simulation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;System of units in Non-linear Optics&amp;lt;/span&amp;gt;&#039;&#039;&#039;: notice that in Yambo the non-linear response functions are in the gaussian system of units, for example the &amp;lt;math&amp;gt; \chi^2 (\omega) &amp;lt;/math&amp;gt;  is in cm/statvolt. In order to convert the non-linear coefficients between different system of units, you can have a look at the [https://www.attaccalite.com/tutorials_yambo/Appendix_C_Boyd.pdf Appendix C] of the book [https://www.elsevier.com/books/nonlinear-optics/boyd/978-0-12-369470-6 &amp;quot;Non-linear optics&amp;quot;  by Robert W. Boyd].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;More tutorials&amp;lt;/span&amp;gt; on non-linear response (Third harmonic generation, parallelization, spin-orbit etc..) with Yambo can be found here: [http://www.attaccalite.com/lumen/tutorials.html More Tutorials]. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Analysis of the results using YamboPy==&lt;br /&gt;
The analysis of the result performed in the previous section using &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; can be performed using python script [https://github.com/yambo-code/yambopy YamboPy].&amp;lt;br&amp;gt;&lt;br /&gt;
In YamboPy we implemented all necessary functions to reads the Yambo databases and post-process the results. Here we show how to get the SHG signal from the previous &lt;br /&gt;
simulations. We suppose you correctly installed &amp;lt;code&amp;gt;YamboPy&amp;lt;/code&amp;gt; on your PC. Go in the folder where you ran non-linear calculation and type in the python:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
 from yambopy import *&lt;br /&gt;
 NLDB=YamboNLDB()&lt;br /&gt;
 pol =NLDB.Polarization[0]&lt;br /&gt;
 time=NLDB.IO_TIME_points&lt;br /&gt;
&lt;br /&gt;
in this way you read all the Non-linear databases. If your runs are in a different folder then the &#039;SAVE&#039; one you can specify it using the command:&lt;br /&gt;
 NLDB=YamboNLDB(calc=&#039;MYJOB&#039;)&lt;br /&gt;
&lt;br /&gt;
now in the array &amp;lt;code&amp;gt;pol&amp;lt;/code&amp;gt; you have all the polarization for all laser frequencies in the three Cartesian directions, while the variable &amp;lt;code&amp;gt;time&amp;lt;/code&amp;gt; contains all the time series of your simulation.&lt;br /&gt;
Now you can get the non-linear response with the command:&lt;br /&gt;
&lt;br /&gt;
 Harmonic_Analysis(NLDB,X_order=4)&lt;br /&gt;
&lt;br /&gt;
this command will perform a Fourier analysis of the results in the same way of &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; and generate new files with all the requested harmonics &#039;&#039;o.YamboPy-X_probe_order_1&#039;&#039;, &#039;&#039;o.YamboPy-X_probe_order_2&#039;&#039; etc...&lt;br /&gt;
equivalent to the one generated by &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt;. Results can be plot with gnuplot using the command:&lt;br /&gt;
 &lt;br /&gt;
 p &#039;o.YamboPy-X_probe_order_2&#039; u 1:(sqrt($6**2+$7**2)) w lp ps 1.5 pt 7 lw 1.5&lt;br /&gt;
&lt;br /&gt;
The script that performs non-linear analysis can be found in &amp;lt;code&amp;gt;yambopy/nl/harmonic_analysis.py&amp;lt;/code&amp;gt;. &amp;lt;br&amp;gt; We strongly advice you to have a look to this script and modify it according&lt;br /&gt;
to your needs and in order to extract other non-linear response functions.&lt;br /&gt;
&lt;br /&gt;
==How to choose the external field direction for the different X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
In the X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;abc&amp;lt;/sub&amp;gt; response you have three field directions. The two components &#039;&#039;b&#039;&#039; and &#039;&#039;c&#039;&#039; are determined by the external field and the third &#039;&#039;a&#039;&#039;&lt;br /&gt;
is the direction where you measure the response.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The external field in Yambo is set using the variable&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
   1.000000 | 0.000000 | 0.000000 |        # [NL ExtF] Versor .&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
For example if you set in Yambo field direction as:&lt;br /&gt;
&lt;br /&gt;
 1.0 | 0.0 | 0.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*xx&amp;lt;/sub&amp;gt;&lt;br /&gt;
 0.0 | 1.0 | 0.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*yy&amp;lt;/sub&amp;gt;&lt;br /&gt;
 0.0 | 0.0 | 1.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*zz&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the * correspond to the different direction in the response file &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;.&lt;br /&gt;
In the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt; you have seven columns:&lt;br /&gt;
&lt;br /&gt;
 The first column is the energy [[omega]],&lt;br /&gt;
 the 2nd and 3rd columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;x**&amp;lt;/sub&amp;gt;&lt;br /&gt;
 the 4th and 5th columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;y**&amp;lt;/sub&amp;gt;&lt;br /&gt;
 the 6th and 7th columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;z**&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where the ** are the direction of the incoming field, see above.&lt;br /&gt;
&lt;br /&gt;
For example if you want to calculate the X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;zxx&amp;lt;/sub&amp;gt; you put the external field in the direction &amp;lt;code&amp;gt; 1.0 | 0.0 | 0.0 |&amp;lt;/code&amp;gt;&lt;br /&gt;
and then plot the column 6 and 7 of the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt; file.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Nota bene:&#039;&#039;&#039; if you change the direction of the external field you have to remove the corresponding symmetries as explained in the tutorial &lt;br /&gt;
on [[Prerequisites for Real Time_propagation with Yambo#Reduce symmetries real-time linear response tutorial]].&lt;br /&gt;
&lt;br /&gt;
In order to get the other components of the  X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; the calculation are more involved. For example if you put field in the&lt;br /&gt;
&lt;br /&gt;
 1.0 | 1.0 | 0.0 | &lt;br /&gt;
&lt;br /&gt;
this corresponds to &amp;lt;math&amp;gt;E(t)=\frac{1}{\sqrt{2}} [ E_x(t) + E_y(t) ]&amp;lt;/math&amp;gt; and so at the second order you will have &amp;lt;math&amp;gt;E^2(t)=\frac{1}{2} [ E^2_x(t) + E^2_y(t) +  E_x(t) E_y(t) +  E_y(t) E_x(t) ]&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
this means that  the X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; in the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;  will correspond to a linear combination of the following different response functions.&amp;lt;br&amp;gt;&lt;br /&gt;
For example in the the 2nd and 3rd columns are the imaginary and real part of:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^2_{x**}=\frac{1}{2} \left [\chi^2_{xxx}+\chi^2_{xyy} + \chi^2_{xxy} + \chi^2_{xyx} \right ]&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the same for the other column replacing the first &amp;lt;code&amp;gt;x&amp;lt;/code&amp;gt; for &amp;lt;code&amp;gt;y,z&amp;lt;/code&amp;gt;.&lt;br /&gt;
If you know that some components are zero this allow you to extract the corresponding off-diagonal part of &amp;lt;math&amp;gt;\chi^2_{abc}&amp;lt;/math&amp;gt; otherwise you have to perform different calculations to get the component you are interested in. Hereafter we present a simple example of monolayer hBN (m-hBN). In m-hBN there is only a non-zero component of the $\chi^2$ and all the others are related by symmetry, namely:&lt;br /&gt;
&lt;br /&gt;
==Non-linear response of low-dimensional structures: 2D or 1D ==&lt;br /&gt;
&lt;br /&gt;
The Yambo code is a 3D periodic code, so when you want to study a low-dimensional system 2D or 1D, you have to use a supercell approach.&lt;br /&gt;
For example to simulate the non-linear response in a 2D-crystal one, can put the crystal in the xy plane and choose a larger distance in the z-direction&lt;br /&gt;
in order to reduce the interaction between the periodic replica. Clearly in this case k-point sampling will be only in the x,y directions.&lt;br /&gt;
For calculations on this type of systems, these two warnings must be taken into account:&lt;br /&gt;
&lt;br /&gt;
* if you calculate GW corrections or include electron-hole interaction in the linear/non-linear response it is a good idea to use a &#039;&#039;&#039;Coulomb cutoff&#039;&#039;&#039;, similar to the 2D BSE case  [http://www.yambo-code.org/wiki/index.php?title=How_to_treat_low_dimensional_systems How to treat low dimensional systems]. You can add the cutoff just adding the &amp;quot;-r&amp;quot; in the input generation.&lt;br /&gt;
&lt;br /&gt;
* the calculation of SHG and THG are always performed respect to the supercell, therefore you have to &#039;&#039;&#039;re-scale&#039;&#039;&#039; the result to the effective thickness of the layer, usually the inter-layer distance of the corresponding bulk material for 2D systems: &amp;lt;math&amp;gt;\chi_{rescaled}(\omega) = L_z/d_{eff} \cdot \chi(\omega) &amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;L_z&amp;lt;/math&amp;gt; is the z-dimension of the supercell, and &amp;lt;math&amp;gt;d_{eff}&amp;lt;/math&amp;gt; is the effective thickness of the 2D system.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Nota bene&#039;&#039;&#039;: Non-linear response along &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;non-periodic directions&amp;lt;/span&amp;gt; is not implemented in Yambo, the code will print zero in these directions for all response functions. We plan to implement it in a future version of the code.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Links for schools==&lt;br /&gt;
* Back to [[Rome 2023#Tutorials]]&lt;br /&gt;
* Back to [[ICTP2020]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
{| style=&amp;quot;width:100%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|style=&amp;quot;width:25%; text-align:left&amp;quot;|Prev: [[Linear response from real time simulations|Linear response from real time simulations]]&lt;br /&gt;
|style=&amp;quot;width:45%; text-align:center&amp;quot;|Now: [[ICTP2020|ICTP  Tutorials]] --&amp;gt; [[Real time approach to non-linear response|Non Linear Response]] &lt;br /&gt;
|style=&amp;quot;width:50%; text-align:left&amp;quot;|Next: [[Correlation effects in the non-linear response|Correlation effects in the non-linear response ]]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Attacc</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Real_time_approach_to_non-linear_response_(SHG)&amp;diff=9143</id>
		<title>Real time approach to non-linear response (SHG)</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Real_time_approach_to_non-linear_response_(SHG)&amp;diff=9143"/>
		<updated>2025-09-27T08:29:36Z</updated>

		<summary type="html">&lt;p&gt;Attacc: /* How to choose the external field direction for the different X2 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Second Harmonic Generation in AlAs ==&lt;br /&gt;
In this tutorial, we will calculate the second harmonic generation of bulk AlAs, the Yambo databases can be downloaded here: [https://media.yambo-code.eu/educational/tutorials/files/AlAs_DBs.tar.gz AlAs_DBs.tar.gz] (10 MB). The first steps of this tutorials are the same as the one on [http://www.yambo-code.eu/wiki/index.php?title=Prerequisites_for_Real_Time_propagation_with_Yambo Prerequisites for Real-Time propagation with Yambo] with the only difference that we will work on AlAs and we will consider an external field in the direction &amp;lt;code&amp;gt; 1.000000 | 1.000000 | 0.000000 |&amp;lt;/code&amp;gt;. The DFT input are available here: [https://media.yambo-code.eu/educational/tutorials/files/AlAs_abinit.tar.gz ABINIT] or [https://media.yambo-code.eu/educational/tutorials/files/AlAs_pwscf.tar.gz QuantumEspresso].&lt;br /&gt;
You can run the DFT calculation with ABINIT with the command:&lt;br /&gt;
&lt;br /&gt;
 abinit &amp;lt; AlAs.in &amp;gt; output_AlAs                                             &lt;br /&gt;
&lt;br /&gt;
or using QuantumEspresso:&lt;br /&gt;
&lt;br /&gt;
 pw.x -inp AlAs.scf.in &amp;gt; output_scf&lt;br /&gt;
 pw.x -inp AlAs.nscf.in &amp;gt; output_scf                            &lt;br /&gt;
&lt;br /&gt;
and then import the ABINIT wave-function with the command:&lt;br /&gt;
&lt;br /&gt;
 a2y -F AlAso_DS2_WFK.nc                            &lt;br /&gt;
&lt;br /&gt;
and the QuantumEspresso one, in the folder AlAs.save with the command:&lt;br /&gt;
&lt;br /&gt;
 p2y                              &lt;br /&gt;
Now we consider an external field in the &amp;lt;code&amp;gt;[1,1,0]&amp;lt;/code&amp;gt; direction and remove symmetries not compatible with this field, as explained in the tutorial [http://www.yambo-code.eu/wiki/index.php?title=Prerequisites_for_Real_Time_propagation_with_Yambo Prerequisites for Real-Time propagation with Yambo].&lt;br /&gt;
&lt;br /&gt;
==Real-time simulation for the SHG==&lt;br /&gt;
&lt;br /&gt;
You can generate the input file with the command &amp;lt;code&amp;gt;yambo_nl -u n&amp;lt;/code&amp;gt;:&lt;br /&gt;
                       &lt;br /&gt;
 nloptics                      # [R NL] Non-linear optics&lt;br /&gt;
 % NLBands&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 3 | 6&amp;lt;/span&amp;gt; |                   # [NL] Bands&lt;br /&gt;
 %&lt;br /&gt;
 NLstep=   0.0100       fs    # [NL] Real Time step length&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;NLverbosity= &amp;quot;high&amp;quot;&amp;lt;/span&amp;gt;               # [NL] Verbosity level (low | high)&lt;br /&gt;
 NLtime=-1.000000           fs    # [NL] Simulation Time&lt;br /&gt;
 NLintegrator= &amp;quot;INVINT&amp;quot;       # [NL] Integrator (&amp;quot;EULEREXP/RK4/RK2EXP/HEUN/INVINT/CRANKNIC&amp;quot;)&lt;br /&gt;
 NLCorrelation= &amp;quot;IPA&amp;quot;         # [NL] Correlation (&amp;quot;IPA/HARTREE/TDDFT/LRC/JGM/SEX/HF&amp;quot;)&lt;br /&gt;
 NLLrcAlpha= 0.000000         # [NL] Long Range Correction&lt;br /&gt;
 % NLEnRange&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;  1.000000 | 5.000000 &amp;lt;/span&amp;gt;| eV    # [NL] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 NLEnSteps= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 5  &amp;lt;/span&amp;gt;              # [NL] Energy steps&lt;br /&gt;
 NLDamping= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 0.150000  &amp;lt;/span&amp;gt;  eV    # [NL] Damping&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 1.000000 | 1.000000 | 0.000000 &amp;lt;/span&amp;gt;|        # [RT Field1] Versor&lt;br /&gt;
 Field1_kind= &amp;quot;SOFTSIN&amp;quot;         # [NL ExtF] Kind(SIN|SOFTSIN|RES|ANTIRES|GAUSS|DELTA|QSSIN)&lt;br /&gt;
&lt;br /&gt;
The line &amp;lt;code&amp;gt;|1.000000 | 1.000000 | 0.000000 | # [RT Field1] Versor&amp;lt;/code&amp;gt; referees to the direction of the external field (x,y,0). At present only an external field is present but the code can be easily generalized to deal with more fields.&lt;br /&gt;
The default parameters of Yambo/Lumen are already tuned for second-harmonic generation, so the only thing you have to change is the band range, between 3 and 6 and the energy range between 1.0-5.0 eV and the number of energy steps in this interval that we set to 10. Notice that you cannot set to zero the lowest value of the energy range because this will requires a simulation that lasts infinite time, see below. Finally, consider that Yambo performs a separate calculation for each frequency, so if you set many energy steps the computational time grows linearly with this number.&lt;br /&gt;
Notice that we set &amp;lt;code&amp;gt;NLverbosity= &amp;quot;high&amp;quot;&amp;lt;/code&amp;gt; in this way the code will produce a file for each laser frequency containing the time dependent polarization.&lt;br /&gt;
Run &amp;lt;code&amp;gt;yambo_nl&amp;lt;/code&amp;gt;. Calculations will take about fifteen minutes on a single processor PC, you have time to study the next section that explains how non-linear response is extracted from the real-time simulations.&lt;br /&gt;
In order to speed up calculations, you can run them in parallel.&lt;br /&gt;
&lt;br /&gt;
==Non-linear response with Yambo==&lt;br /&gt;
&lt;br /&gt;
In order to calculate the non-linear response, the system is excited with different laser fields with a sinusoidal shape at frequencies &amp;lt;math&amp;gt;\omega_1, \omega_2, .... , \omega_n &amp;lt;/math&amp;gt; determined by the parameters [[Variables#NLEnRangev|NLEnRange]] and [[Variables#NLEnSteps|NLEnSteps]]. A dephasing term is added to the Hamiltonian &amp;lt;math&amp;gt;\gamma = &amp;lt;/math&amp;gt;[[Variables#NLDamping|NLDamping]] to simulate a finite broadening and to remove the eigenmodes that are excited by the sudden turning on of the external field. After the dephasing time the outgoing signal is analyzed to extract the non-linear coefficients as shown in the figure below: &lt;br /&gt;
&lt;br /&gt;
[[File:Pt analysis.png|600px|center|Non-linear response analysis]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the report file &amp;lt;code&amp;gt;r_nlinear&amp;lt;/code&amp;gt; you will find the length of the dephasing part and of the sampling one:&lt;br /&gt;
&lt;br /&gt;
  Dephasing Time          [fs]: 52.65695&lt;br /&gt;
  Sampling  Time          [fs]:  4.18566&lt;br /&gt;
  Total simulation time   [fs]: 56.84262                     &lt;br /&gt;
The length of the dephasing interval is inversely proportional to the damping term &amp;lt;math&amp;gt;T_{depth} \simeq 1/\gamma&amp;lt;/math&amp;gt; while the length of the sampling is dictated by the smallest frequency we are interested in: &amp;lt;math&amp;gt;T_{samp} \simeq 1/\omega_1 &amp;lt;/math&amp;gt;. For this reason if &amp;lt;math&amp;gt; \omega_1=0 &amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt; \gamma = 0 &amp;lt;/math&amp;gt; simulation time goes to infinity. The response at zero frequency can be calculated as limit of small frequency perturbation.&lt;br /&gt;
You can have a look to the file &amp;lt;code&amp;gt;src/nloptics/NL_initialize.F&amp;lt;/code&amp;gt; to see how simulation lengths are defined.&lt;br /&gt;
Calculations can take some time, run them in parallel, the best number of processors = number of frequencies or reduce the number of frequencies step in the SHG.&lt;br /&gt;
&lt;br /&gt;
==Analysis of the results==&lt;br /&gt;
&lt;br /&gt;
In the sampling region we suppose that the polarization can be written as: &amp;lt;math&amp;gt;\bf{P}(t) = \sum_{n=-\infty}^{+\infty} \bf{p}_n e^{-i\omega_n t} &amp;lt;/math&amp;gt; where the coefficient &amp;lt;math&amp;gt;\bf{p}_1,...,\bf{p}_n &amp;lt;/math&amp;gt; are related to &amp;lt;math&amp;gt;\chi^{(1)},...,\chi^{(n)} &amp;lt;/math&amp;gt;. We sample the polarization signal at different times and invert the previous equation by truncating the sum at a finite order &amp;lt;ref&amp;gt;[https://arxiv.org/abs/1309.4012 Nonlinear optics from an ab initio approach by means of the dynamical Berry phase: Application to second- and third-harmonic generation in semiconductors], C. Attaccalite and M. Grüning, Phys. Rev. B 88, 235113(2013)&amp;lt;/ref&amp;gt;.&lt;br /&gt;
This is done with the command &amp;lt;code&amp;gt;ypp_nl -u&amp;lt;/code&amp;gt; that automatically produce an input with the correct values:&lt;br /&gt;
&lt;br /&gt;
 nonlinear                    # [R] NonLinear Optics Post-Processing&lt;br /&gt;
 Xorder=   &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;4  &amp;lt;/span&amp;gt;                 # Max order of the response functions&lt;br /&gt;
 % TimeRange&lt;br /&gt;
  52.65695 | -1.00000 | fs    # Time-window where processing is done&lt;br /&gt;
 % &lt;br /&gt;
 ETStpsRt= 200                # Total Energy steps&lt;br /&gt;
 % EnRngeRt&lt;br /&gt;
   0.00000 | 10.00000 | eV    # Energy range&lt;br /&gt;
 %&lt;br /&gt;
 DampMode= &amp;quot;NONE&amp;quot;             # Damping type ( NONE | LORENTZIAN | GAUSSIAN )&lt;br /&gt;
 DampFactor=  0.10000   eV    # Damping parameter&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;code&amp;gt;Xorder&amp;lt;/code&amp;gt; is the order where the previous sum is truncated, and the TimeRange specifies the sampling region. Notice that differently from the first tutorial, in this case, we do not need Damping in &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; because we already included it in the real-time dynamics. Run &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; and it will produce a file called &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;. This file contains the different components of &amp;lt;math&amp;gt;\chi^2_{xy*} &amp;lt;/math&amp;gt; and in particular the columns 6 and 7 correspond to the imaginary and real part of &amp;lt;math&amp;gt;\chi^2_{xyz} &amp;lt;/math&amp;gt;. You can plot the result with gnuplot and the command:&lt;br /&gt;
&lt;br /&gt;
 p &#039;o.YPP-X_probe_order_2&#039; u 1:(sqrt($6**2+$7**2)) w lp ps 1.5 pt 7 lw 1.5&lt;br /&gt;
&lt;br /&gt;
the result should look like&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AlAs results.png|700px|center|SHG in AlAs]]&lt;br /&gt;
&lt;br /&gt;
and compare it with the &amp;lt;math&amp;gt; \chi^2_{zxy} &amp;lt;/math&amp;gt; calculated with more frequencies and with the converged result on a &amp;lt;math&amp;gt; 18x18x18&amp;lt;/math&amp;gt; k-point grid and bands between 2 and 10. In the figure you can find also the comparison with the results of Ref. &amp;lt;ref&amp;gt;Luppi et al. [https://arxiv.org/abs/1006.2649 PRB B, &#039;&#039;&#039;82&#039;&#039;&#039;, 235201(2010)]&amp;lt;/ref&amp;gt;. &lt;br /&gt;
Notice that the QuantumEspresso results are slightly different from the Abinit ones. This is due to the different pseudo-potential employed in the calculations if pseudopotentials were the same calculation would have been identical. You can download the script to generate this plot and the converged results [http://www.attaccalite.com/lumen/tutorials/AlAs/AlAs_results.tgz here].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notice that&#039;&#039;&#039; : the following parameters are not used in the non-linear response analysis: &amp;lt;code&amp;gt; EnRngeRt&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ETStpsRt&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;DampMode&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;DampFactor&amp;lt;/code&amp;gt;. The damping factor is set directly in the real-time simulation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;System of units in Non-linear Optics&amp;lt;/span&amp;gt;&#039;&#039;&#039;: notice that in Yambo the non-linear response functions are in the gaussian system of units, for example the &amp;lt;math&amp;gt; \chi^2 (\omega) &amp;lt;/math&amp;gt;  is in cm/statvolt. In order to convert the non-linear coefficients between different system of units, you can have a look at the [https://www.attaccalite.com/tutorials_yambo/Appendix_C_Boyd.pdf Appendix C] of the book [https://www.elsevier.com/books/nonlinear-optics/boyd/978-0-12-369470-6 &amp;quot;Non-linear optics&amp;quot;  by Robert W. Boyd].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;More tutorials&amp;lt;/span&amp;gt; on non-linear response (Third harmonic generation, parallelization, spin-orbit etc..) with Yambo can be found here: [http://www.attaccalite.com/lumen/tutorials.html More Tutorials]. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Analysis of the results using YamboPy==&lt;br /&gt;
The analysis of the result performed in the previous section using &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; can be performed using python script [https://github.com/yambo-code/yambopy YamboPy].&amp;lt;br&amp;gt;&lt;br /&gt;
In YamboPy we implemented all necessary functions to reads the Yambo databases and post-process the results. Here we show how to get the SHG signal from the previous &lt;br /&gt;
simulations. We suppose you correctly installed &amp;lt;code&amp;gt;YamboPy&amp;lt;/code&amp;gt; on your PC. Go in the folder where you ran non-linear calculation and type in the python:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
 from yambopy import *&lt;br /&gt;
 NLDB=YamboNLDB()&lt;br /&gt;
 pol =NLDB.Polarization[0]&lt;br /&gt;
 time=NLDB.IO_TIME_points&lt;br /&gt;
&lt;br /&gt;
in this way you read all the Non-linear databases. If your runs are in a different folder then the &#039;SAVE&#039; one you can specify it using the command:&lt;br /&gt;
 NLDB=YamboNLDB(calc=&#039;MYJOB&#039;)&lt;br /&gt;
&lt;br /&gt;
now in the array &amp;lt;code&amp;gt;pol&amp;lt;/code&amp;gt; you have all the polarization for all laser frequencies in the three Cartesian directions, while the variable &amp;lt;code&amp;gt;time&amp;lt;/code&amp;gt; contains all the time series of your simulation.&lt;br /&gt;
Now you can get the non-linear response with the command:&lt;br /&gt;
&lt;br /&gt;
 Harmonic_Analysis(NLDB,X_order=4)&lt;br /&gt;
&lt;br /&gt;
this command will perform a Fourier analysis of the results in the same way of &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; and generate new files with all the requested harmonics &#039;&#039;o.YamboPy-X_probe_order_1&#039;&#039;, &#039;&#039;o.YamboPy-X_probe_order_2&#039;&#039; etc...&lt;br /&gt;
equivalent to the one generated by &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt;. Results can be plot with gnuplot using the command:&lt;br /&gt;
 &lt;br /&gt;
 p &#039;o.YamboPy-X_probe_order_2&#039; u 1:(sqrt($6**2+$7**2)) w lp ps 1.5 pt 7 lw 1.5&lt;br /&gt;
&lt;br /&gt;
The script that performs non-linear analysis can be found in &amp;lt;code&amp;gt;yambopy/nl/harmonic_analysis.py&amp;lt;/code&amp;gt;. &amp;lt;br&amp;gt; We strongly advice you to have a look to this script and modify it according&lt;br /&gt;
to your needs and in order to extract other non-linear response functions.&lt;br /&gt;
&lt;br /&gt;
==How to choose the external field direction for the different X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
In the X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;abc&amp;lt;/sub&amp;gt; response you have three field directions. The two components &#039;&#039;b&#039;&#039; and &#039;&#039;c&#039;&#039; are determined by the external field and the third &#039;&#039;a&#039;&#039;&lt;br /&gt;
is the direction where you measure the response.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The external field in Yambo is set using the variable&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
   1.000000 | 0.000000 | 0.000000 |        # [NL ExtF] Versor .&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
For example if you set in Yambo field direction as:&lt;br /&gt;
&lt;br /&gt;
 1.0 | 0.0 | 0.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*xx&amp;lt;/sub&amp;gt;&lt;br /&gt;
 0.0 | 1.0 | 0.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*yy&amp;lt;/sub&amp;gt;&lt;br /&gt;
 0.0 | 0.0 | 1.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*zz&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the * correspond to the different direction in the response file &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;.&lt;br /&gt;
In the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt; you have seven columns:&lt;br /&gt;
&lt;br /&gt;
 The first column is the energy [[omega]],&lt;br /&gt;
 the 2nd and 3rd columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;x**&amp;lt;/sub&amp;gt;&lt;br /&gt;
 the 4th and 5th columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;y**&amp;lt;/sub&amp;gt;&lt;br /&gt;
 the 6th and 7th columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;z**&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where the ** are the direction of the incoming field, see above.&lt;br /&gt;
&lt;br /&gt;
For example if you want to calculate the X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;zxx&amp;lt;/sub&amp;gt; you put the external field in the direction &amp;lt;code&amp;gt; 1.0 | 0.0 | 0.0 |&amp;lt;/code&amp;gt;&lt;br /&gt;
and then plot the column 6 and 7 of the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt; file.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Nota bene:&#039;&#039;&#039; if you change the direction of the external field you have to remove the corresponding symmetries as explained in the tutorial &lt;br /&gt;
on [[Prerequisites for Real Time_propagation with Yambo#Reduce symmetries real-time linear response tutorial]].&lt;br /&gt;
&lt;br /&gt;
In order to get the other components of the  X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; the calculation are more involved. For example if you put field in the&lt;br /&gt;
&lt;br /&gt;
 1.0 | 1.0 | 0.0 | &lt;br /&gt;
&lt;br /&gt;
this corresponds to &amp;lt;math&amp;gt;E(t)=\frac{1}{\sqrt{2}} [ E_x(t) + E_y(t) ]&amp;lt;/math&amp;gt; and so at the second order you will have &amp;lt;math&amp;gt;E^2(t)=\frac{1}{2} [ E^2_x(t) + E^2_y(t) +  E_x(t) E_y(t) +  E_y(t) E_x(t) ]&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
this means that  the X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; in the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;  will correspond to a linear combination of the following different response functions.&amp;lt;br&amp;gt;&lt;br /&gt;
For example in the the 2nd and 3rd columns are the imaginary and real part of:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^2_{x**}=\frac{1}{2} \left [\chi^2_{xxx}+\chi^2_{xyy} + \chi^2_{xxy} + \chi^2_{xyx} \right ]&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the same for the other column replacing the first &amp;lt;code&amp;gt;x&amp;lt;/code&amp;gt; for &amp;lt;code&amp;gt;y,z&amp;lt;/code&amp;gt;.&lt;br /&gt;
If you know that some components are zero this allow you to extract the corresponding off-diagonal part of &amp;lt;math&amp;gt;\chi^2_{abc}&amp;lt;/math&amp;gt; otherwise you have to perform different calculations to get the component you are interested in. Hereafter we present a simple example of monolayer hBN.&lt;br /&gt;
&lt;br /&gt;
==Non-linear response of low-dimensional structures: 2D or 1D ==&lt;br /&gt;
&lt;br /&gt;
The Yambo code is a 3D periodic code, so when you want to study a low-dimensional system 2D or 1D, you have to use a supercell approach.&lt;br /&gt;
For example to simulate the non-linear response in a 2D-crystal one, can put the crystal in the xy plane and choose a larger distance in the z-direction&lt;br /&gt;
in order to reduce the interaction between the periodic replica. Clearly in this case k-point sampling will be only in the x,y directions.&lt;br /&gt;
For calculations on this type of systems, these two warnings must be taken into account:&lt;br /&gt;
&lt;br /&gt;
* if you calculate GW corrections or include electron-hole interaction in the linear/non-linear response it is a good idea to use a &#039;&#039;&#039;Coulomb cutoff&#039;&#039;&#039;, similar to the 2D BSE case  [http://www.yambo-code.org/wiki/index.php?title=How_to_treat_low_dimensional_systems How to treat low dimensional systems]. You can add the cutoff just adding the &amp;quot;-r&amp;quot; in the input generation.&lt;br /&gt;
&lt;br /&gt;
* the calculation of SHG and THG are always performed respect to the supercell, therefore you have to &#039;&#039;&#039;re-scale&#039;&#039;&#039; the result to the effective thickness of the layer, usually the inter-layer distance of the corresponding bulk material for 2D systems: &amp;lt;math&amp;gt;\chi_{rescaled}(\omega) = L_z/d_{eff} \cdot \chi(\omega) &amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;L_z&amp;lt;/math&amp;gt; is the z-dimension of the supercell, and &amp;lt;math&amp;gt;d_{eff}&amp;lt;/math&amp;gt; is the effective thickness of the 2D system.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Nota bene&#039;&#039;&#039;: Non-linear response along &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;non-periodic directions&amp;lt;/span&amp;gt; is not implemented in Yambo, the code will print zero in these directions for all response functions. We plan to implement it in a future version of the code.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Links for schools==&lt;br /&gt;
* Back to [[Rome 2023#Tutorials]]&lt;br /&gt;
* Back to [[ICTP2020]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
{| style=&amp;quot;width:100%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|style=&amp;quot;width:25%; text-align:left&amp;quot;|Prev: [[Linear response from real time simulations|Linear response from real time simulations]]&lt;br /&gt;
|style=&amp;quot;width:45%; text-align:center&amp;quot;|Now: [[ICTP2020|ICTP  Tutorials]] --&amp;gt; [[Real time approach to non-linear response|Non Linear Response]] &lt;br /&gt;
|style=&amp;quot;width:50%; text-align:left&amp;quot;|Next: [[Correlation effects in the non-linear response|Correlation effects in the non-linear response ]]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Attacc</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Real_time_approach_to_non-linear_response_(SHG)&amp;diff=9142</id>
		<title>Real time approach to non-linear response (SHG)</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Real_time_approach_to_non-linear_response_(SHG)&amp;diff=9142"/>
		<updated>2025-09-27T08:22:51Z</updated>

		<summary type="html">&lt;p&gt;Attacc: /* How to choose the external field direction for the different X2 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Second Harmonic Generation in AlAs ==&lt;br /&gt;
In this tutorial, we will calculate the second harmonic generation of bulk AlAs, the Yambo databases can be downloaded here: [https://media.yambo-code.eu/educational/tutorials/files/AlAs_DBs.tar.gz AlAs_DBs.tar.gz] (10 MB). The first steps of this tutorials are the same as the one on [http://www.yambo-code.eu/wiki/index.php?title=Prerequisites_for_Real_Time_propagation_with_Yambo Prerequisites for Real-Time propagation with Yambo] with the only difference that we will work on AlAs and we will consider an external field in the direction &amp;lt;code&amp;gt; 1.000000 | 1.000000 | 0.000000 |&amp;lt;/code&amp;gt;. The DFT input are available here: [https://media.yambo-code.eu/educational/tutorials/files/AlAs_abinit.tar.gz ABINIT] or [https://media.yambo-code.eu/educational/tutorials/files/AlAs_pwscf.tar.gz QuantumEspresso].&lt;br /&gt;
You can run the DFT calculation with ABINIT with the command:&lt;br /&gt;
&lt;br /&gt;
 abinit &amp;lt; AlAs.in &amp;gt; output_AlAs                                             &lt;br /&gt;
&lt;br /&gt;
or using QuantumEspresso:&lt;br /&gt;
&lt;br /&gt;
 pw.x -inp AlAs.scf.in &amp;gt; output_scf&lt;br /&gt;
 pw.x -inp AlAs.nscf.in &amp;gt; output_scf                            &lt;br /&gt;
&lt;br /&gt;
and then import the ABINIT wave-function with the command:&lt;br /&gt;
&lt;br /&gt;
 a2y -F AlAso_DS2_WFK.nc                            &lt;br /&gt;
&lt;br /&gt;
and the QuantumEspresso one, in the folder AlAs.save with the command:&lt;br /&gt;
&lt;br /&gt;
 p2y                              &lt;br /&gt;
Now we consider an external field in the &amp;lt;code&amp;gt;[1,1,0]&amp;lt;/code&amp;gt; direction and remove symmetries not compatible with this field, as explained in the tutorial [http://www.yambo-code.eu/wiki/index.php?title=Prerequisites_for_Real_Time_propagation_with_Yambo Prerequisites for Real-Time propagation with Yambo].&lt;br /&gt;
&lt;br /&gt;
==Real-time simulation for the SHG==&lt;br /&gt;
&lt;br /&gt;
You can generate the input file with the command &amp;lt;code&amp;gt;yambo_nl -u n&amp;lt;/code&amp;gt;:&lt;br /&gt;
                       &lt;br /&gt;
 nloptics                      # [R NL] Non-linear optics&lt;br /&gt;
 % NLBands&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 3 | 6&amp;lt;/span&amp;gt; |                   # [NL] Bands&lt;br /&gt;
 %&lt;br /&gt;
 NLstep=   0.0100       fs    # [NL] Real Time step length&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;NLverbosity= &amp;quot;high&amp;quot;&amp;lt;/span&amp;gt;               # [NL] Verbosity level (low | high)&lt;br /&gt;
 NLtime=-1.000000           fs    # [NL] Simulation Time&lt;br /&gt;
 NLintegrator= &amp;quot;INVINT&amp;quot;       # [NL] Integrator (&amp;quot;EULEREXP/RK4/RK2EXP/HEUN/INVINT/CRANKNIC&amp;quot;)&lt;br /&gt;
 NLCorrelation= &amp;quot;IPA&amp;quot;         # [NL] Correlation (&amp;quot;IPA/HARTREE/TDDFT/LRC/JGM/SEX/HF&amp;quot;)&lt;br /&gt;
 NLLrcAlpha= 0.000000         # [NL] Long Range Correction&lt;br /&gt;
 % NLEnRange&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;  1.000000 | 5.000000 &amp;lt;/span&amp;gt;| eV    # [NL] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 NLEnSteps= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 5  &amp;lt;/span&amp;gt;              # [NL] Energy steps&lt;br /&gt;
 NLDamping= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 0.150000  &amp;lt;/span&amp;gt;  eV    # [NL] Damping&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 1.000000 | 1.000000 | 0.000000 &amp;lt;/span&amp;gt;|        # [RT Field1] Versor&lt;br /&gt;
 Field1_kind= &amp;quot;SOFTSIN&amp;quot;         # [NL ExtF] Kind(SIN|SOFTSIN|RES|ANTIRES|GAUSS|DELTA|QSSIN)&lt;br /&gt;
&lt;br /&gt;
The line &amp;lt;code&amp;gt;|1.000000 | 1.000000 | 0.000000 | # [RT Field1] Versor&amp;lt;/code&amp;gt; referees to the direction of the external field (x,y,0). At present only an external field is present but the code can be easily generalized to deal with more fields.&lt;br /&gt;
The default parameters of Yambo/Lumen are already tuned for second-harmonic generation, so the only thing you have to change is the band range, between 3 and 6 and the energy range between 1.0-5.0 eV and the number of energy steps in this interval that we set to 10. Notice that you cannot set to zero the lowest value of the energy range because this will requires a simulation that lasts infinite time, see below. Finally, consider that Yambo performs a separate calculation for each frequency, so if you set many energy steps the computational time grows linearly with this number.&lt;br /&gt;
Notice that we set &amp;lt;code&amp;gt;NLverbosity= &amp;quot;high&amp;quot;&amp;lt;/code&amp;gt; in this way the code will produce a file for each laser frequency containing the time dependent polarization.&lt;br /&gt;
Run &amp;lt;code&amp;gt;yambo_nl&amp;lt;/code&amp;gt;. Calculations will take about fifteen minutes on a single processor PC, you have time to study the next section that explains how non-linear response is extracted from the real-time simulations.&lt;br /&gt;
In order to speed up calculations, you can run them in parallel.&lt;br /&gt;
&lt;br /&gt;
==Non-linear response with Yambo==&lt;br /&gt;
&lt;br /&gt;
In order to calculate the non-linear response, the system is excited with different laser fields with a sinusoidal shape at frequencies &amp;lt;math&amp;gt;\omega_1, \omega_2, .... , \omega_n &amp;lt;/math&amp;gt; determined by the parameters [[Variables#NLEnRangev|NLEnRange]] and [[Variables#NLEnSteps|NLEnSteps]]. A dephasing term is added to the Hamiltonian &amp;lt;math&amp;gt;\gamma = &amp;lt;/math&amp;gt;[[Variables#NLDamping|NLDamping]] to simulate a finite broadening and to remove the eigenmodes that are excited by the sudden turning on of the external field. After the dephasing time the outgoing signal is analyzed to extract the non-linear coefficients as shown in the figure below: &lt;br /&gt;
&lt;br /&gt;
[[File:Pt analysis.png|600px|center|Non-linear response analysis]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the report file &amp;lt;code&amp;gt;r_nlinear&amp;lt;/code&amp;gt; you will find the length of the dephasing part and of the sampling one:&lt;br /&gt;
&lt;br /&gt;
  Dephasing Time          [fs]: 52.65695&lt;br /&gt;
  Sampling  Time          [fs]:  4.18566&lt;br /&gt;
  Total simulation time   [fs]: 56.84262                     &lt;br /&gt;
The length of the dephasing interval is inversely proportional to the damping term &amp;lt;math&amp;gt;T_{depth} \simeq 1/\gamma&amp;lt;/math&amp;gt; while the length of the sampling is dictated by the smallest frequency we are interested in: &amp;lt;math&amp;gt;T_{samp} \simeq 1/\omega_1 &amp;lt;/math&amp;gt;. For this reason if &amp;lt;math&amp;gt; \omega_1=0 &amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt; \gamma = 0 &amp;lt;/math&amp;gt; simulation time goes to infinity. The response at zero frequency can be calculated as limit of small frequency perturbation.&lt;br /&gt;
You can have a look to the file &amp;lt;code&amp;gt;src/nloptics/NL_initialize.F&amp;lt;/code&amp;gt; to see how simulation lengths are defined.&lt;br /&gt;
Calculations can take some time, run them in parallel, the best number of processors = number of frequencies or reduce the number of frequencies step in the SHG.&lt;br /&gt;
&lt;br /&gt;
==Analysis of the results==&lt;br /&gt;
&lt;br /&gt;
In the sampling region we suppose that the polarization can be written as: &amp;lt;math&amp;gt;\bf{P}(t) = \sum_{n=-\infty}^{+\infty} \bf{p}_n e^{-i\omega_n t} &amp;lt;/math&amp;gt; where the coefficient &amp;lt;math&amp;gt;\bf{p}_1,...,\bf{p}_n &amp;lt;/math&amp;gt; are related to &amp;lt;math&amp;gt;\chi^{(1)},...,\chi^{(n)} &amp;lt;/math&amp;gt;. We sample the polarization signal at different times and invert the previous equation by truncating the sum at a finite order &amp;lt;ref&amp;gt;[https://arxiv.org/abs/1309.4012 Nonlinear optics from an ab initio approach by means of the dynamical Berry phase: Application to second- and third-harmonic generation in semiconductors], C. Attaccalite and M. Grüning, Phys. Rev. B 88, 235113(2013)&amp;lt;/ref&amp;gt;.&lt;br /&gt;
This is done with the command &amp;lt;code&amp;gt;ypp_nl -u&amp;lt;/code&amp;gt; that automatically produce an input with the correct values:&lt;br /&gt;
&lt;br /&gt;
 nonlinear                    # [R] NonLinear Optics Post-Processing&lt;br /&gt;
 Xorder=   &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;4  &amp;lt;/span&amp;gt;                 # Max order of the response functions&lt;br /&gt;
 % TimeRange&lt;br /&gt;
  52.65695 | -1.00000 | fs    # Time-window where processing is done&lt;br /&gt;
 % &lt;br /&gt;
 ETStpsRt= 200                # Total Energy steps&lt;br /&gt;
 % EnRngeRt&lt;br /&gt;
   0.00000 | 10.00000 | eV    # Energy range&lt;br /&gt;
 %&lt;br /&gt;
 DampMode= &amp;quot;NONE&amp;quot;             # Damping type ( NONE | LORENTZIAN | GAUSSIAN )&lt;br /&gt;
 DampFactor=  0.10000   eV    # Damping parameter&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;code&amp;gt;Xorder&amp;lt;/code&amp;gt; is the order where the previous sum is truncated, and the TimeRange specifies the sampling region. Notice that differently from the first tutorial, in this case, we do not need Damping in &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; because we already included it in the real-time dynamics. Run &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; and it will produce a file called &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;. This file contains the different components of &amp;lt;math&amp;gt;\chi^2_{xy*} &amp;lt;/math&amp;gt; and in particular the columns 6 and 7 correspond to the imaginary and real part of &amp;lt;math&amp;gt;\chi^2_{xyz} &amp;lt;/math&amp;gt;. You can plot the result with gnuplot and the command:&lt;br /&gt;
&lt;br /&gt;
 p &#039;o.YPP-X_probe_order_2&#039; u 1:(sqrt($6**2+$7**2)) w lp ps 1.5 pt 7 lw 1.5&lt;br /&gt;
&lt;br /&gt;
the result should look like&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AlAs results.png|700px|center|SHG in AlAs]]&lt;br /&gt;
&lt;br /&gt;
and compare it with the &amp;lt;math&amp;gt; \chi^2_{zxy} &amp;lt;/math&amp;gt; calculated with more frequencies and with the converged result on a &amp;lt;math&amp;gt; 18x18x18&amp;lt;/math&amp;gt; k-point grid and bands between 2 and 10. In the figure you can find also the comparison with the results of Ref. &amp;lt;ref&amp;gt;Luppi et al. [https://arxiv.org/abs/1006.2649 PRB B, &#039;&#039;&#039;82&#039;&#039;&#039;, 235201(2010)]&amp;lt;/ref&amp;gt;. &lt;br /&gt;
Notice that the QuantumEspresso results are slightly different from the Abinit ones. This is due to the different pseudo-potential employed in the calculations if pseudopotentials were the same calculation would have been identical. You can download the script to generate this plot and the converged results [http://www.attaccalite.com/lumen/tutorials/AlAs/AlAs_results.tgz here].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notice that&#039;&#039;&#039; : the following parameters are not used in the non-linear response analysis: &amp;lt;code&amp;gt; EnRngeRt&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ETStpsRt&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;DampMode&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;DampFactor&amp;lt;/code&amp;gt;. The damping factor is set directly in the real-time simulation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;System of units in Non-linear Optics&amp;lt;/span&amp;gt;&#039;&#039;&#039;: notice that in Yambo the non-linear response functions are in the gaussian system of units, for example the &amp;lt;math&amp;gt; \chi^2 (\omega) &amp;lt;/math&amp;gt;  is in cm/statvolt. In order to convert the non-linear coefficients between different system of units, you can have a look at the [https://www.attaccalite.com/tutorials_yambo/Appendix_C_Boyd.pdf Appendix C] of the book [https://www.elsevier.com/books/nonlinear-optics/boyd/978-0-12-369470-6 &amp;quot;Non-linear optics&amp;quot;  by Robert W. Boyd].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;More tutorials&amp;lt;/span&amp;gt; on non-linear response (Third harmonic generation, parallelization, spin-orbit etc..) with Yambo can be found here: [http://www.attaccalite.com/lumen/tutorials.html More Tutorials]. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Analysis of the results using YamboPy==&lt;br /&gt;
The analysis of the result performed in the previous section using &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; can be performed using python script [https://github.com/yambo-code/yambopy YamboPy].&amp;lt;br&amp;gt;&lt;br /&gt;
In YamboPy we implemented all necessary functions to reads the Yambo databases and post-process the results. Here we show how to get the SHG signal from the previous &lt;br /&gt;
simulations. We suppose you correctly installed &amp;lt;code&amp;gt;YamboPy&amp;lt;/code&amp;gt; on your PC. Go in the folder where you ran non-linear calculation and type in the python:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
 from yambopy import *&lt;br /&gt;
 NLDB=YamboNLDB()&lt;br /&gt;
 pol =NLDB.Polarization[0]&lt;br /&gt;
 time=NLDB.IO_TIME_points&lt;br /&gt;
&lt;br /&gt;
in this way you read all the Non-linear databases. If your runs are in a different folder then the &#039;SAVE&#039; one you can specify it using the command:&lt;br /&gt;
 NLDB=YamboNLDB(calc=&#039;MYJOB&#039;)&lt;br /&gt;
&lt;br /&gt;
now in the array &amp;lt;code&amp;gt;pol&amp;lt;/code&amp;gt; you have all the polarization for all laser frequencies in the three Cartesian directions, while the variable &amp;lt;code&amp;gt;time&amp;lt;/code&amp;gt; contains all the time series of your simulation.&lt;br /&gt;
Now you can get the non-linear response with the command:&lt;br /&gt;
&lt;br /&gt;
 Harmonic_Analysis(NLDB,X_order=4)&lt;br /&gt;
&lt;br /&gt;
this command will perform a Fourier analysis of the results in the same way of &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; and generate new files with all the requested harmonics &#039;&#039;o.YamboPy-X_probe_order_1&#039;&#039;, &#039;&#039;o.YamboPy-X_probe_order_2&#039;&#039; etc...&lt;br /&gt;
equivalent to the one generated by &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt;. Results can be plot with gnuplot using the command:&lt;br /&gt;
 &lt;br /&gt;
 p &#039;o.YamboPy-X_probe_order_2&#039; u 1:(sqrt($6**2+$7**2)) w lp ps 1.5 pt 7 lw 1.5&lt;br /&gt;
&lt;br /&gt;
The script that performs non-linear analysis can be found in &amp;lt;code&amp;gt;yambopy/nl/harmonic_analysis.py&amp;lt;/code&amp;gt;. &amp;lt;br&amp;gt; We strongly advice you to have a look to this script and modify it according&lt;br /&gt;
to your needs and in order to extract other non-linear response functions.&lt;br /&gt;
&lt;br /&gt;
==How to choose the external field direction for the different X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
In the X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;abc&amp;lt;/sub&amp;gt; response you have three field directions. The two components &#039;&#039;b&#039;&#039; and &#039;&#039;c&#039;&#039; are determined by the external field and the third &#039;&#039;a&#039;&#039;&lt;br /&gt;
is the direction where you measure the response.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The external field in Yambo is set using the variable&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
   1.000000 | 0.000000 | 0.000000 |        # [NL ExtF] Versor .&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
For example if you set in Yambo field direction as:&lt;br /&gt;
&lt;br /&gt;
 1.0 | 0.0 | 0.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*xx&amp;lt;/sub&amp;gt;&lt;br /&gt;
 0.0 | 1.0 | 0.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*yy&amp;lt;/sub&amp;gt;&lt;br /&gt;
 0.0 | 0.0 | 1.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*zz&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the * correspond to the different direction in the response file &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;.&lt;br /&gt;
In the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt; you have seven columns:&lt;br /&gt;
&lt;br /&gt;
 The first column is the energy [[omega]],&lt;br /&gt;
 the 2nd and 3rd columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;x**&amp;lt;/sub&amp;gt;&lt;br /&gt;
 the 4th and 5th columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;y**&amp;lt;/sub&amp;gt;&lt;br /&gt;
 the 6th and 7th columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;z**&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where the ** are the direction of the incoming field, see above.&lt;br /&gt;
&lt;br /&gt;
For example if you want to calculate the X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;zxx&amp;lt;/sub&amp;gt; you put the external field in the direction &amp;lt;code&amp;gt; 1.0 | 0.0 | 0.0 |&amp;lt;/code&amp;gt;&lt;br /&gt;
and then plot the column 6 and 7 of the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt; file.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Nota bene:&#039;&#039;&#039; if you change the direction of the external field you have to remove the corresponding symmetries as explained in the tutorial &lt;br /&gt;
on [[Prerequisites for Real Time_propagation with Yambo#Reduce symmetries real-time linear response tutorial]].&lt;br /&gt;
&lt;br /&gt;
In order to get the other components of the  X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; the calculation are more involved. For example if you put field in the&lt;br /&gt;
&lt;br /&gt;
 1.0 | 1.0 | 0.0 | &lt;br /&gt;
&lt;br /&gt;
this corresponds to &amp;lt;math&amp;gt;E(t)=\frac{1}{\sqrt{2}} [ E_x(t) + E_y(t) ]&amp;lt;/math&amp;gt; and so at the second order you will have &amp;lt;math&amp;gt;E^2(t)=\frac{1}{2} [ E^2_x(t) + E^2_y(t) +  E_x(t) E_y(t) +  E_y(t) E_x(t) ]&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
this means that  the X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; in the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;  will correspond to a linear combination of the following different response functions.&amp;lt;br&amp;gt;&lt;br /&gt;
For example in the the 2nd and 3rd columns are the imaginary and real part of:&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^2_{x**}=\frac{1}{2} \left [\chi^2_{xxx}+\chi^2_{xyy} + \chi^2_{xxy} + \chi^2_{xyx} \right ]&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the same for the other column replacing the first &amp;lt;code&amp;gt;x&amp;lt;/code&amp;gt; for &amp;lt;code&amp;gt;y,z&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Non-linear response of low-dimensional structures: 2D or 1D ==&lt;br /&gt;
&lt;br /&gt;
The Yambo code is a 3D periodic code, so when you want to study a low-dimensional system 2D or 1D, you have to use a supercell approach.&lt;br /&gt;
For example to simulate the non-linear response in a 2D-crystal one, can put the crystal in the xy plane and choose a larger distance in the z-direction&lt;br /&gt;
in order to reduce the interaction between the periodic replica. Clearly in this case k-point sampling will be only in the x,y directions.&lt;br /&gt;
For calculations on this type of systems, these two warnings must be taken into account:&lt;br /&gt;
&lt;br /&gt;
* if you calculate GW corrections or include electron-hole interaction in the linear/non-linear response it is a good idea to use a &#039;&#039;&#039;Coulomb cutoff&#039;&#039;&#039;, similar to the 2D BSE case  [http://www.yambo-code.org/wiki/index.php?title=How_to_treat_low_dimensional_systems How to treat low dimensional systems]. You can add the cutoff just adding the &amp;quot;-r&amp;quot; in the input generation.&lt;br /&gt;
&lt;br /&gt;
* the calculation of SHG and THG are always performed respect to the supercell, therefore you have to &#039;&#039;&#039;re-scale&#039;&#039;&#039; the result to the effective thickness of the layer, usually the inter-layer distance of the corresponding bulk material for 2D systems: &amp;lt;math&amp;gt;\chi_{rescaled}(\omega) = L_z/d_{eff} \cdot \chi(\omega) &amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;L_z&amp;lt;/math&amp;gt; is the z-dimension of the supercell, and &amp;lt;math&amp;gt;d_{eff}&amp;lt;/math&amp;gt; is the effective thickness of the 2D system.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Nota bene&#039;&#039;&#039;: Non-linear response along &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;non-periodic directions&amp;lt;/span&amp;gt; is not implemented in Yambo, the code will print zero in these directions for all response functions. We plan to implement it in a future version of the code.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Links for schools==&lt;br /&gt;
* Back to [[Rome 2023#Tutorials]]&lt;br /&gt;
* Back to [[ICTP2020]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
{| style=&amp;quot;width:100%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|style=&amp;quot;width:25%; text-align:left&amp;quot;|Prev: [[Linear response from real time simulations|Linear response from real time simulations]]&lt;br /&gt;
|style=&amp;quot;width:45%; text-align:center&amp;quot;|Now: [[ICTP2020|ICTP  Tutorials]] --&amp;gt; [[Real time approach to non-linear response|Non Linear Response]] &lt;br /&gt;
|style=&amp;quot;width:50%; text-align:left&amp;quot;|Next: [[Correlation effects in the non-linear response|Correlation effects in the non-linear response ]]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Attacc</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Real_time_approach_to_non-linear_response_(SHG)&amp;diff=9141</id>
		<title>Real time approach to non-linear response (SHG)</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Real_time_approach_to_non-linear_response_(SHG)&amp;diff=9141"/>
		<updated>2025-09-27T08:22:22Z</updated>

		<summary type="html">&lt;p&gt;Attacc: /* How to choose the external field direction for the different X2 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Second Harmonic Generation in AlAs ==&lt;br /&gt;
In this tutorial, we will calculate the second harmonic generation of bulk AlAs, the Yambo databases can be downloaded here: [https://media.yambo-code.eu/educational/tutorials/files/AlAs_DBs.tar.gz AlAs_DBs.tar.gz] (10 MB). The first steps of this tutorials are the same as the one on [http://www.yambo-code.eu/wiki/index.php?title=Prerequisites_for_Real_Time_propagation_with_Yambo Prerequisites for Real-Time propagation with Yambo] with the only difference that we will work on AlAs and we will consider an external field in the direction &amp;lt;code&amp;gt; 1.000000 | 1.000000 | 0.000000 |&amp;lt;/code&amp;gt;. The DFT input are available here: [https://media.yambo-code.eu/educational/tutorials/files/AlAs_abinit.tar.gz ABINIT] or [https://media.yambo-code.eu/educational/tutorials/files/AlAs_pwscf.tar.gz QuantumEspresso].&lt;br /&gt;
You can run the DFT calculation with ABINIT with the command:&lt;br /&gt;
&lt;br /&gt;
 abinit &amp;lt; AlAs.in &amp;gt; output_AlAs                                             &lt;br /&gt;
&lt;br /&gt;
or using QuantumEspresso:&lt;br /&gt;
&lt;br /&gt;
 pw.x -inp AlAs.scf.in &amp;gt; output_scf&lt;br /&gt;
 pw.x -inp AlAs.nscf.in &amp;gt; output_scf                            &lt;br /&gt;
&lt;br /&gt;
and then import the ABINIT wave-function with the command:&lt;br /&gt;
&lt;br /&gt;
 a2y -F AlAso_DS2_WFK.nc                            &lt;br /&gt;
&lt;br /&gt;
and the QuantumEspresso one, in the folder AlAs.save with the command:&lt;br /&gt;
&lt;br /&gt;
 p2y                              &lt;br /&gt;
Now we consider an external field in the &amp;lt;code&amp;gt;[1,1,0]&amp;lt;/code&amp;gt; direction and remove symmetries not compatible with this field, as explained in the tutorial [http://www.yambo-code.eu/wiki/index.php?title=Prerequisites_for_Real_Time_propagation_with_Yambo Prerequisites for Real-Time propagation with Yambo].&lt;br /&gt;
&lt;br /&gt;
==Real-time simulation for the SHG==&lt;br /&gt;
&lt;br /&gt;
You can generate the input file with the command &amp;lt;code&amp;gt;yambo_nl -u n&amp;lt;/code&amp;gt;:&lt;br /&gt;
                       &lt;br /&gt;
 nloptics                      # [R NL] Non-linear optics&lt;br /&gt;
 % NLBands&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 3 | 6&amp;lt;/span&amp;gt; |                   # [NL] Bands&lt;br /&gt;
 %&lt;br /&gt;
 NLstep=   0.0100       fs    # [NL] Real Time step length&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;NLverbosity= &amp;quot;high&amp;quot;&amp;lt;/span&amp;gt;               # [NL] Verbosity level (low | high)&lt;br /&gt;
 NLtime=-1.000000           fs    # [NL] Simulation Time&lt;br /&gt;
 NLintegrator= &amp;quot;INVINT&amp;quot;       # [NL] Integrator (&amp;quot;EULEREXP/RK4/RK2EXP/HEUN/INVINT/CRANKNIC&amp;quot;)&lt;br /&gt;
 NLCorrelation= &amp;quot;IPA&amp;quot;         # [NL] Correlation (&amp;quot;IPA/HARTREE/TDDFT/LRC/JGM/SEX/HF&amp;quot;)&lt;br /&gt;
 NLLrcAlpha= 0.000000         # [NL] Long Range Correction&lt;br /&gt;
 % NLEnRange&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;  1.000000 | 5.000000 &amp;lt;/span&amp;gt;| eV    # [NL] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 NLEnSteps= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 5  &amp;lt;/span&amp;gt;              # [NL] Energy steps&lt;br /&gt;
 NLDamping= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 0.150000  &amp;lt;/span&amp;gt;  eV    # [NL] Damping&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 1.000000 | 1.000000 | 0.000000 &amp;lt;/span&amp;gt;|        # [RT Field1] Versor&lt;br /&gt;
 Field1_kind= &amp;quot;SOFTSIN&amp;quot;         # [NL ExtF] Kind(SIN|SOFTSIN|RES|ANTIRES|GAUSS|DELTA|QSSIN)&lt;br /&gt;
&lt;br /&gt;
The line &amp;lt;code&amp;gt;|1.000000 | 1.000000 | 0.000000 | # [RT Field1] Versor&amp;lt;/code&amp;gt; referees to the direction of the external field (x,y,0). At present only an external field is present but the code can be easily generalized to deal with more fields.&lt;br /&gt;
The default parameters of Yambo/Lumen are already tuned for second-harmonic generation, so the only thing you have to change is the band range, between 3 and 6 and the energy range between 1.0-5.0 eV and the number of energy steps in this interval that we set to 10. Notice that you cannot set to zero the lowest value of the energy range because this will requires a simulation that lasts infinite time, see below. Finally, consider that Yambo performs a separate calculation for each frequency, so if you set many energy steps the computational time grows linearly with this number.&lt;br /&gt;
Notice that we set &amp;lt;code&amp;gt;NLverbosity= &amp;quot;high&amp;quot;&amp;lt;/code&amp;gt; in this way the code will produce a file for each laser frequency containing the time dependent polarization.&lt;br /&gt;
Run &amp;lt;code&amp;gt;yambo_nl&amp;lt;/code&amp;gt;. Calculations will take about fifteen minutes on a single processor PC, you have time to study the next section that explains how non-linear response is extracted from the real-time simulations.&lt;br /&gt;
In order to speed up calculations, you can run them in parallel.&lt;br /&gt;
&lt;br /&gt;
==Non-linear response with Yambo==&lt;br /&gt;
&lt;br /&gt;
In order to calculate the non-linear response, the system is excited with different laser fields with a sinusoidal shape at frequencies &amp;lt;math&amp;gt;\omega_1, \omega_2, .... , \omega_n &amp;lt;/math&amp;gt; determined by the parameters [[Variables#NLEnRangev|NLEnRange]] and [[Variables#NLEnSteps|NLEnSteps]]. A dephasing term is added to the Hamiltonian &amp;lt;math&amp;gt;\gamma = &amp;lt;/math&amp;gt;[[Variables#NLDamping|NLDamping]] to simulate a finite broadening and to remove the eigenmodes that are excited by the sudden turning on of the external field. After the dephasing time the outgoing signal is analyzed to extract the non-linear coefficients as shown in the figure below: &lt;br /&gt;
&lt;br /&gt;
[[File:Pt analysis.png|600px|center|Non-linear response analysis]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In the report file &amp;lt;code&amp;gt;r_nlinear&amp;lt;/code&amp;gt; you will find the length of the dephasing part and of the sampling one:&lt;br /&gt;
&lt;br /&gt;
  Dephasing Time          [fs]: 52.65695&lt;br /&gt;
  Sampling  Time          [fs]:  4.18566&lt;br /&gt;
  Total simulation time   [fs]: 56.84262                     &lt;br /&gt;
The length of the dephasing interval is inversely proportional to the damping term &amp;lt;math&amp;gt;T_{depth} \simeq 1/\gamma&amp;lt;/math&amp;gt; while the length of the sampling is dictated by the smallest frequency we are interested in: &amp;lt;math&amp;gt;T_{samp} \simeq 1/\omega_1 &amp;lt;/math&amp;gt;. For this reason if &amp;lt;math&amp;gt; \omega_1=0 &amp;lt;/math&amp;gt; or &amp;lt;math&amp;gt; \gamma = 0 &amp;lt;/math&amp;gt; simulation time goes to infinity. The response at zero frequency can be calculated as limit of small frequency perturbation.&lt;br /&gt;
You can have a look to the file &amp;lt;code&amp;gt;src/nloptics/NL_initialize.F&amp;lt;/code&amp;gt; to see how simulation lengths are defined.&lt;br /&gt;
Calculations can take some time, run them in parallel, the best number of processors = number of frequencies or reduce the number of frequencies step in the SHG.&lt;br /&gt;
&lt;br /&gt;
==Analysis of the results==&lt;br /&gt;
&lt;br /&gt;
In the sampling region we suppose that the polarization can be written as: &amp;lt;math&amp;gt;\bf{P}(t) = \sum_{n=-\infty}^{+\infty} \bf{p}_n e^{-i\omega_n t} &amp;lt;/math&amp;gt; where the coefficient &amp;lt;math&amp;gt;\bf{p}_1,...,\bf{p}_n &amp;lt;/math&amp;gt; are related to &amp;lt;math&amp;gt;\chi^{(1)},...,\chi^{(n)} &amp;lt;/math&amp;gt;. We sample the polarization signal at different times and invert the previous equation by truncating the sum at a finite order &amp;lt;ref&amp;gt;[https://arxiv.org/abs/1309.4012 Nonlinear optics from an ab initio approach by means of the dynamical Berry phase: Application to second- and third-harmonic generation in semiconductors], C. Attaccalite and M. Grüning, Phys. Rev. B 88, 235113(2013)&amp;lt;/ref&amp;gt;.&lt;br /&gt;
This is done with the command &amp;lt;code&amp;gt;ypp_nl -u&amp;lt;/code&amp;gt; that automatically produce an input with the correct values:&lt;br /&gt;
&lt;br /&gt;
 nonlinear                    # [R] NonLinear Optics Post-Processing&lt;br /&gt;
 Xorder=   &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;4  &amp;lt;/span&amp;gt;                 # Max order of the response functions&lt;br /&gt;
 % TimeRange&lt;br /&gt;
  52.65695 | -1.00000 | fs    # Time-window where processing is done&lt;br /&gt;
 % &lt;br /&gt;
 ETStpsRt= 200                # Total Energy steps&lt;br /&gt;
 % EnRngeRt&lt;br /&gt;
   0.00000 | 10.00000 | eV    # Energy range&lt;br /&gt;
 %&lt;br /&gt;
 DampMode= &amp;quot;NONE&amp;quot;             # Damping type ( NONE | LORENTZIAN | GAUSSIAN )&lt;br /&gt;
 DampFactor=  0.10000   eV    # Damping parameter&lt;br /&gt;
&lt;br /&gt;
where &amp;lt;code&amp;gt;Xorder&amp;lt;/code&amp;gt; is the order where the previous sum is truncated, and the TimeRange specifies the sampling region. Notice that differently from the first tutorial, in this case, we do not need Damping in &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; because we already included it in the real-time dynamics. Run &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; and it will produce a file called &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;. This file contains the different components of &amp;lt;math&amp;gt;\chi^2_{xy*} &amp;lt;/math&amp;gt; and in particular the columns 6 and 7 correspond to the imaginary and real part of &amp;lt;math&amp;gt;\chi^2_{xyz} &amp;lt;/math&amp;gt;. You can plot the result with gnuplot and the command:&lt;br /&gt;
&lt;br /&gt;
 p &#039;o.YPP-X_probe_order_2&#039; u 1:(sqrt($6**2+$7**2)) w lp ps 1.5 pt 7 lw 1.5&lt;br /&gt;
&lt;br /&gt;
the result should look like&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:AlAs results.png|700px|center|SHG in AlAs]]&lt;br /&gt;
&lt;br /&gt;
and compare it with the &amp;lt;math&amp;gt; \chi^2_{zxy} &amp;lt;/math&amp;gt; calculated with more frequencies and with the converged result on a &amp;lt;math&amp;gt; 18x18x18&amp;lt;/math&amp;gt; k-point grid and bands between 2 and 10. In the figure you can find also the comparison with the results of Ref. &amp;lt;ref&amp;gt;Luppi et al. [https://arxiv.org/abs/1006.2649 PRB B, &#039;&#039;&#039;82&#039;&#039;&#039;, 235201(2010)]&amp;lt;/ref&amp;gt;. &lt;br /&gt;
Notice that the QuantumEspresso results are slightly different from the Abinit ones. This is due to the different pseudo-potential employed in the calculations if pseudopotentials were the same calculation would have been identical. You can download the script to generate this plot and the converged results [http://www.attaccalite.com/lumen/tutorials/AlAs/AlAs_results.tgz here].&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Notice that&#039;&#039;&#039; : the following parameters are not used in the non-linear response analysis: &amp;lt;code&amp;gt; EnRngeRt&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ETStpsRt&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;DampMode&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;DampFactor&amp;lt;/code&amp;gt;. The damping factor is set directly in the real-time simulation.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;System of units in Non-linear Optics&amp;lt;/span&amp;gt;&#039;&#039;&#039;: notice that in Yambo the non-linear response functions are in the gaussian system of units, for example the &amp;lt;math&amp;gt; \chi^2 (\omega) &amp;lt;/math&amp;gt;  is in cm/statvolt. In order to convert the non-linear coefficients between different system of units, you can have a look at the [https://www.attaccalite.com/tutorials_yambo/Appendix_C_Boyd.pdf Appendix C] of the book [https://www.elsevier.com/books/nonlinear-optics/boyd/978-0-12-369470-6 &amp;quot;Non-linear optics&amp;quot;  by Robert W. Boyd].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color:green&amp;quot;&amp;gt;More tutorials&amp;lt;/span&amp;gt; on non-linear response (Third harmonic generation, parallelization, spin-orbit etc..) with Yambo can be found here: [http://www.attaccalite.com/lumen/tutorials.html More Tutorials]. &amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Analysis of the results using YamboPy==&lt;br /&gt;
The analysis of the result performed in the previous section using &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; can be performed using python script [https://github.com/yambo-code/yambopy YamboPy].&amp;lt;br&amp;gt;&lt;br /&gt;
In YamboPy we implemented all necessary functions to reads the Yambo databases and post-process the results. Here we show how to get the SHG signal from the previous &lt;br /&gt;
simulations. We suppose you correctly installed &amp;lt;code&amp;gt;YamboPy&amp;lt;/code&amp;gt; on your PC. Go in the folder where you ran non-linear calculation and type in the python:&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
 from yambopy import *&lt;br /&gt;
 NLDB=YamboNLDB()&lt;br /&gt;
 pol =NLDB.Polarization[0]&lt;br /&gt;
 time=NLDB.IO_TIME_points&lt;br /&gt;
&lt;br /&gt;
in this way you read all the Non-linear databases. If your runs are in a different folder then the &#039;SAVE&#039; one you can specify it using the command:&lt;br /&gt;
 NLDB=YamboNLDB(calc=&#039;MYJOB&#039;)&lt;br /&gt;
&lt;br /&gt;
now in the array &amp;lt;code&amp;gt;pol&amp;lt;/code&amp;gt; you have all the polarization for all laser frequencies in the three Cartesian directions, while the variable &amp;lt;code&amp;gt;time&amp;lt;/code&amp;gt; contains all the time series of your simulation.&lt;br /&gt;
Now you can get the non-linear response with the command:&lt;br /&gt;
&lt;br /&gt;
 Harmonic_Analysis(NLDB,X_order=4)&lt;br /&gt;
&lt;br /&gt;
this command will perform a Fourier analysis of the results in the same way of &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; and generate new files with all the requested harmonics &#039;&#039;o.YamboPy-X_probe_order_1&#039;&#039;, &#039;&#039;o.YamboPy-X_probe_order_2&#039;&#039; etc...&lt;br /&gt;
equivalent to the one generated by &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt;. Results can be plot with gnuplot using the command:&lt;br /&gt;
 &lt;br /&gt;
 p &#039;o.YamboPy-X_probe_order_2&#039; u 1:(sqrt($6**2+$7**2)) w lp ps 1.5 pt 7 lw 1.5&lt;br /&gt;
&lt;br /&gt;
The script that performs non-linear analysis can be found in &amp;lt;code&amp;gt;yambopy/nl/harmonic_analysis.py&amp;lt;/code&amp;gt;. &amp;lt;br&amp;gt; We strongly advice you to have a look to this script and modify it according&lt;br /&gt;
to your needs and in order to extract other non-linear response functions.&lt;br /&gt;
&lt;br /&gt;
==How to choose the external field direction for the different X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;==&lt;br /&gt;
&lt;br /&gt;
In the X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;abc&amp;lt;/sub&amp;gt; response you have three field directions. The two components &#039;&#039;b&#039;&#039; and &#039;&#039;c&#039;&#039; are determined by the external field and the third &#039;&#039;a&#039;&#039;&lt;br /&gt;
is the direction where you measure the response.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The external field in Yambo is set using the variable&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
   1.000000 | 0.000000 | 0.000000 |        # [NL ExtF] Versor .&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
For example if you set in Yambo field direction as:&lt;br /&gt;
&lt;br /&gt;
 1.0 | 0.0 | 0.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*xx&amp;lt;/sub&amp;gt;&lt;br /&gt;
 0.0 | 1.0 | 0.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*yy&amp;lt;/sub&amp;gt;&lt;br /&gt;
 0.0 | 0.0 | 1.0 | ---&amp;gt; you calculate all components X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;*zz&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the * correspond to the different direction in the response file &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;.&lt;br /&gt;
In the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt; you have seven columns:&lt;br /&gt;
&lt;br /&gt;
 The first column is the energy [[omega]],&lt;br /&gt;
 the 2nd and 3rd columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;x**&amp;lt;/sub&amp;gt;&lt;br /&gt;
 the 4th and 5th columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;y**&amp;lt;/sub&amp;gt;&lt;br /&gt;
 the 6th and 7th columns are the imaginary and real part of X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;z**&amp;lt;/sub&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where the ** are the direction of the incoming field, see above.&lt;br /&gt;
&lt;br /&gt;
For example if you want to calculate the X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;&amp;lt;sub&amp;gt;zxx&amp;lt;/sub&amp;gt; you put the external field in the direction &amp;lt;code&amp;gt; 1.0 | 0.0 | 0.0 |&amp;lt;/code&amp;gt;&lt;br /&gt;
and then plot the column 6 and 7 of the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt; file.&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Nota bene:&#039;&#039;&#039; if you change the direction of the external field you have to remove the corresponding symmetries as explained in the tutorial &lt;br /&gt;
on [[Prerequisites for Real Time_propagation with Yambo#Reduce symmetries real-time linear response tutorial]].&lt;br /&gt;
&lt;br /&gt;
In order to get the other components of the  X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; the calculation are more involved. For example if you put field in the&lt;br /&gt;
&lt;br /&gt;
 1.0 | 1.0 | 0.0 | &lt;br /&gt;
&lt;br /&gt;
this corresponds to &amp;lt;math&amp;gt;E(t)=\frac{1}{\sqrt{2}} [ E_x(t) + E_y(t) ]&amp;lt;/math&amp;gt; and so at the second order you will have &amp;lt;math&amp;gt;E^2(t)=\frac{1}{2} [ E^2_x(t) + E^2_y(t) +  E_x(t) E_y(t) +  E_y(t) E_x(t) ]&amp;lt;/math&amp;gt;&amp;lt;br&amp;gt;&lt;br /&gt;
this means that  the X&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; in the &amp;lt;code&amp;gt;o.YPP-X_probe_order_2&amp;lt;/code&amp;gt;  will correspond to a linear combination of the following different response functions.&amp;lt;br&amp;gt;&lt;br /&gt;
For example in the the 2nd and 3rd columns are the imaginary and real part of:&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;math&amp;gt;\chi^2_{x**}=\frac{1}{2}\chi^2_{xxx}+\chi^2_{xyy} + \chi^2_{xxy} + \chi^2_{xyx}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the same for the other column replacing the first &amp;lt;code&amp;gt;x&amp;lt;/code&amp;gt; for &amp;lt;code&amp;gt;y,z&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Non-linear response of low-dimensional structures: 2D or 1D ==&lt;br /&gt;
&lt;br /&gt;
The Yambo code is a 3D periodic code, so when you want to study a low-dimensional system 2D or 1D, you have to use a supercell approach.&lt;br /&gt;
For example to simulate the non-linear response in a 2D-crystal one, can put the crystal in the xy plane and choose a larger distance in the z-direction&lt;br /&gt;
in order to reduce the interaction between the periodic replica. Clearly in this case k-point sampling will be only in the x,y directions.&lt;br /&gt;
For calculations on this type of systems, these two warnings must be taken into account:&lt;br /&gt;
&lt;br /&gt;
* if you calculate GW corrections or include electron-hole interaction in the linear/non-linear response it is a good idea to use a &#039;&#039;&#039;Coulomb cutoff&#039;&#039;&#039;, similar to the 2D BSE case  [http://www.yambo-code.org/wiki/index.php?title=How_to_treat_low_dimensional_systems How to treat low dimensional systems]. You can add the cutoff just adding the &amp;quot;-r&amp;quot; in the input generation.&lt;br /&gt;
&lt;br /&gt;
* the calculation of SHG and THG are always performed respect to the supercell, therefore you have to &#039;&#039;&#039;re-scale&#039;&#039;&#039; the result to the effective thickness of the layer, usually the inter-layer distance of the corresponding bulk material for 2D systems: &amp;lt;math&amp;gt;\chi_{rescaled}(\omega) = L_z/d_{eff} \cdot \chi(\omega) &amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;L_z&amp;lt;/math&amp;gt; is the z-dimension of the supercell, and &amp;lt;math&amp;gt;d_{eff}&amp;lt;/math&amp;gt; is the effective thickness of the 2D system.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Nota bene&#039;&#039;&#039;: Non-linear response along &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;non-periodic directions&amp;lt;/span&amp;gt; is not implemented in Yambo, the code will print zero in these directions for all response functions. We plan to implement it in a future version of the code.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Links for schools==&lt;br /&gt;
* Back to [[Rome 2023#Tutorials]]&lt;br /&gt;
* Back to [[ICTP2020]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
{| style=&amp;quot;width:100%&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
|style=&amp;quot;width:25%; text-align:left&amp;quot;|Prev: [[Linear response from real time simulations|Linear response from real time simulations]]&lt;br /&gt;
|style=&amp;quot;width:45%; text-align:center&amp;quot;|Now: [[ICTP2020|ICTP  Tutorials]] --&amp;gt; [[Real time approach to non-linear response|Non Linear Response]] &lt;br /&gt;
|style=&amp;quot;width:50%; text-align:left&amp;quot;|Next: [[Correlation effects in the non-linear response|Correlation effects in the non-linear response ]]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Attacc</name></author>
	</entry>
</feed>