<?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=Fulvio</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=Fulvio"/>
	<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Special:Contributions/Fulvio"/>
	<updated>2026-05-17T21:22:15Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.39.8</generator>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_band_structures&amp;diff=7865</id>
		<title>Yambopy tutorial: band structures</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_band_structures&amp;diff=7865"/>
		<updated>2024-04-22T18:39:22Z</updated>

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

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

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

		<summary type="html">&lt;p&gt;Fulvio: /* Coulomb truncation convergence */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial we will deal with different aspects of running a Bethe-Salpeter (BSE) calculation for optical absorption spectra using yambopy. We continue using hexagonal boron nitride to illustrate how to perform convergence tests, and how to compare and analyse the results. &lt;br /&gt;
&lt;br /&gt;
Before you start this tutorial, make sure you have run the scf and nscf runs. If you have not, you can calculate the relax &amp;lt;code&amp;gt;-r&amp;lt;/code&amp;gt;, scf &amp;lt;code&amp;gt;-s&amp;lt;/code&amp;gt; and nscf &amp;lt;code&amp;gt;-n&amp;lt;/code&amp;gt; using the &amp;lt;code&amp;gt;gs_bn.py&amp;lt;/code&amp;gt; file:&lt;br /&gt;
 $ python gs_bn.py -r -s -n&lt;br /&gt;
Once that is over, you can start the tutorial.&lt;br /&gt;
&lt;br /&gt;
__FORCETOC__&lt;br /&gt;
&lt;br /&gt;
=== BSE convergence of optical spectra ===&lt;br /&gt;
&lt;br /&gt;
In this section of the tutorial we will use the &amp;lt;code&amp;gt;bse_conv_bn.py&amp;lt;/code&amp;gt; file. To evaluate the Bethe-Salpeter Kernel we need to first calculate the static dielectric screening, and then the screened Coulomb interaction matrix elements. This will be done with the file &amp;lt;code&amp;gt;bse_conv_bn.py&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;a. Static dielectric function&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
We begin by converging the static screening. In principle, all parameters can be converged independently one-by-one, and then the you can choose the best values for the final, fully converged result. To converge the static screening you will need:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;FFTGvecs&amp;lt;/code&amp;gt;: number of planewaves to include. Usually we need fewer planewaves than the total used in the self-consistent cycle that generated the ground state in the &amp;lt;code&amp;gt;scf&amp;lt;/code&amp;gt; run. Reducing the total number of planewaves used diminishes the amount of memory per process that you are going to need. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;BndsRnXs&amp;lt;/code&amp;gt;: number of bands to calculate the screening. Typically you need many bands (hundreds or even more) for the screening to converge. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;NGsBlkXs&amp;lt;/code&amp;gt;: number of components for the local fields. Averages the value of the dielectric screening over a number of periodic copies of the unit cell. This parameter greatly increases the computational cost of the calculation and thus should be increased slowly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We create a dictionary with different values for each variable. The python script (&amp;lt;code&amp;gt;bse_conv_bn.py&amp;lt;/code&amp;gt;) will then create a reference input file with the first value in each parameter&#039;s list. It will then create input files with the other parameters changing independently according to the values specified on the list:&lt;br /&gt;
&lt;br /&gt;
 #list of variables to optimize the dielectric screening&lt;br /&gt;
 conv = { &#039;FFTGvecs&#039;: [[10,10,15,20,30],&#039;Ry&#039;],&lt;br /&gt;
          &#039;NGsBlkXs&#039;: [[1,1,2,3,5,6], &#039;Ry&#039;],&lt;br /&gt;
          &#039;BndsRnXs&#039;: [[1,10],[1,10],[1,20],[1,30],[1,40]] }&lt;br /&gt;
&lt;br /&gt;
To run a calculation for each of the variables in the dictionary, we first define the &amp;lt;code&amp;gt;run&amp;lt;/code&amp;gt; function&lt;br /&gt;
&lt;br /&gt;
    def run(filename):&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        Function to be called by the optimize function&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        path = filename.split(&#039;.&#039;)[0]&lt;br /&gt;
        print(filename, path)&lt;br /&gt;
        shell = scheduler()&lt;br /&gt;
        shell.add_command(&#039;cd %s&#039;%folder)&lt;br /&gt;
        shell.add_command(&#039;%s mpirun -np %d %s -F %s -J %s -C %s 2&amp;gt; %s.log&#039;%(nohup,threads,yambo,filename,path,path,path))&lt;br /&gt;
        shell.add_command(&#039;touch %s/done&#039;%path)&lt;br /&gt;
        if not os.path.isfile(&amp;quot;%s/%s/done&amp;quot;%(folder,path)):&lt;br /&gt;
            shell.run()&lt;br /&gt;
&lt;br /&gt;
which together with the optimize function in the class &amp;lt;code&amp;gt;YamboIn&amp;lt;/code&amp;gt;, &lt;br /&gt;
 y.optimize(conv,folder=&#039;bse_conv&#039;,run=run,ref_run=False) &lt;br /&gt;
will run and manage the calculations as defined in the dictionary. All calculation files and outputs will be in their respective directories inside the folder &amp;lt;code&amp;gt;bse_conv&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
To check which options are available in the script &amp;lt;code&amp;gt;bse_conv_bn.py&amp;lt;/code&amp;gt;, run &lt;br /&gt;
 $ python bse_conv_bn.py&lt;br /&gt;
which will give you the following list:&lt;br /&gt;
&lt;br /&gt;
 usage: bse_conv_bn.py [-h] [-r] [-a] [-p] [-e] [-b] [-u] [-t THREADS]&lt;br /&gt;
 &lt;br /&gt;
 Test the yambopy script.&lt;br /&gt;
 &lt;br /&gt;
 optional arguments:&lt;br /&gt;
   -h, --help            show this help message and exit&lt;br /&gt;
   -r, --run             run BSE convergence calculation&lt;br /&gt;
   -a, --analyse         analyse results data&lt;br /&gt;
   -p, --plot            plot the results&lt;br /&gt;
   -e, --epsilon         converge epsilon parameters&lt;br /&gt;
   -b, --bse             converge bse parameters&lt;br /&gt;
   -u, --nohup           run the commands with nohup&lt;br /&gt;
   -t THREADS, --threads THREADS&lt;br /&gt;
                         number of threads to use&lt;br /&gt;
&lt;br /&gt;
So, in order to converge the screening, you will need to run&lt;br /&gt;
&lt;br /&gt;
 $ python bse_conv_bn.py -r -e&lt;br /&gt;
&lt;br /&gt;
By default we have set up the total number of threads to be equal to 2. If you have access to more, you can change this using the &amp;lt;code&amp;gt;-t&amp;lt;/code&amp;gt; option shown on the list, followed by the number of threads you want to use. &lt;br /&gt;
&lt;br /&gt;
As you can see, the python script is running all the calculations changing the value of the input variables. You are free to open the &amp;lt;code&amp;gt;bse_conv_bn.py&amp;lt;/code&amp;gt; file and modify it according to your own needs. Using the optimal parameters, you can run a calculation and save the dielectric screening databases &amp;lt;code&amp;gt;ndb.em1s*&amp;lt;/code&amp;gt; to re-use them in the subsequent calculations. For that you can copy these files to the SAVE folder. &amp;lt;code&amp;gt;yambo&amp;lt;/code&amp;gt; will only re-calculate any database if it does not find it or some parameter has changed.&lt;br /&gt;
&lt;br /&gt;
Once the calculations are done you can plot resulting optical spectra by running &lt;br /&gt;
 $ python bse_conv_bn.py -a &lt;br /&gt;
followed by &lt;br /&gt;
 $ python bse_conv_bn.py -p -e &lt;br /&gt;
It will search the folder &amp;lt;code&amp;gt;bse_conv&amp;lt;/code&amp;gt; for all calculations you performed previously and plot the results, using the class &amp;lt;code&amp;gt;YamboAnalyser&amp;lt;/code&amp;gt; class.&lt;br /&gt;
&lt;br /&gt;
[[File:Bse-hbn-conv-2.png|x750px|Yambo tutorial image]]&lt;br /&gt;
&lt;br /&gt;
Alternatively, you can obtain the same plots by running the the following script: &lt;br /&gt;
 $ python plot-bse-conv.py &lt;br /&gt;
If you want to, you can now add new entries to the lists in the dictionary, specially the &amp;lt;code&amp;gt;BndsRnXs&amp;lt;/code&amp;gt;, which usually requires a lot of bands to achieve convergence. Keep its number less than or equal to the number of bands in the nscf calculation, re-run the script and plot the results again. You can also test if some variables can converge with smaller values than the ones you used up to now. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;b. Screened Coulomb interaction&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Up to this point we have been focused on the variables which control the static screening. We still need to deal with the variables which setup the Bethe-Salpeter auxiliary Hamiltonian matrix. Once this matrix is set up, &amp;lt;code&amp;gt;yambo&amp;lt;/code&amp;gt; will use a diagonalisation algorithm to obtain the excitonic states and energies. The relevant variables for this process are:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;blockquote&amp;gt;&amp;lt;code&amp;gt;BSEBands&amp;lt;/code&amp;gt;: number of bands to generate the transitions. Should be as small as possible as the size of the BSE auxiliary hamiltonian has (in the resonant approximation) dimensions &amp;lt;code&amp;gt;Nk*Nv*Nc&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Another way to converge the number of transitions is using &amp;lt;code&amp;gt;BSEEhEny&amp;lt;/code&amp;gt;. This variable selects the number of transitions based on the electron-hole energy difference (it&#039;s the one we are going to use).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;BSENGBlk&amp;lt;/code&amp;gt; is the number of blocks for the dielectric screening average over the unit cells. This uses the static screening computed previously and controlled by the variable &amp;lt;code&amp;gt;NGsBlkXs&amp;lt;/code&amp;gt;. So you &amp;lt;code&amp;gt;BSENGBlk&amp;lt;/code&amp;gt; cannot be larger than &amp;lt;code&amp;gt;NGsBlkXs&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;BSENGexx&amp;lt;/code&amp;gt; in the number of exchange components. Relatively cheap to calculate, but should be kept as small as possible to save memory.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;KfnQP_E&amp;lt;/code&amp;gt; is the scissor operator for the BSE. The first value is the rigid scissor, the second and third are the stretching for the conduction and valence respectively. The optical absorption spectrum is obtained in a range of energies given by &amp;lt;code&amp;gt;BEnRange&amp;lt;/code&amp;gt; and the number of frequencies in the interval is &amp;lt;code&amp;gt;BEnSteps&amp;lt;/code&amp;gt;. Alternatively a quasiparticle energy database can be included from a previous GW calculation.&lt;br /&gt;
&amp;lt;/blockquote&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For the last variable you will be using a predefined scissor operator. If you want to know how to compute a scissor operator you can go and follow the GW tutorial here [[GW tutorial. Convergence and approximations (BN)]]. &lt;br /&gt;
&lt;br /&gt;
The dictionary of convergence in this case is:&lt;br /&gt;
&lt;br /&gt;
 #list of variables to optimize the BSE&lt;br /&gt;
         conv = { &#039;BSEEhEny&#039;: [[[1,10],[1,10],[1,12],[1,14]],&#039;eV&#039;],&lt;br /&gt;
                  &#039;BSENGBlk&#039;: [[0,0,1,2], &#039;Ry&#039;],&lt;br /&gt;
                  &#039;BSENGexx&#039;: [[10,10,15,20],&#039;Ry&#039;]}&lt;br /&gt;
&lt;br /&gt;
All these variables do not change the dielectric screening, so optionally you can calculate it once (using the previous section to determine converged parameters) and put the database in the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; folder to make the calculations faster. Otherwise the dielectric screening will be computed for each run (in the case of this tutorial, this is still quite fast). This is a slightly advanced use of &amp;lt;code&amp;gt;yambo&amp;lt;/code&amp;gt;, so it is better to leave till you are more familiar with the code and its flow. &lt;br /&gt;
&lt;br /&gt;
To run the convergence calculations for the BSE Hamiltonian write:&lt;br /&gt;
&lt;br /&gt;
 $ python bse_conv_bn.py -r -b&lt;br /&gt;
Once the calculations are done you can plot the optical absorption spectra:&lt;br /&gt;
&lt;br /&gt;
 $ python bse_conv_bn.py -a&lt;br /&gt;
 $ python bse_conv_bn.py -p -b&lt;br /&gt;
&lt;br /&gt;
[[File:Bse-hbn-conv-1.png|x750px|Yambo tutorial image]]&lt;br /&gt;
&lt;br /&gt;
Alternatively, you can obtain the same plots by running the the following script: &amp;lt;source&amp;gt;$ python plot-bse-conv.py &amp;lt;/source&amp;gt;&lt;br /&gt;
Again, we invite you to change the values in the dictionary to check if the calculation would converge better using larger or smaller parameters.&lt;br /&gt;
&lt;br /&gt;
=== Coulomb truncation convergence ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;a. Running for different layer separation distances&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Here we will check how the dielectric screening changes with vacuum spacing between layers and including a coulomb truncation technique. For that we define a loop where we do a self-consistent ground state calculation, non self-consistent calculation, create the databases and run a &amp;lt;code&amp;gt;yambo&amp;lt;/code&amp;gt; BSE calculation for different vacuum spacings.&lt;br /&gt;
&lt;br /&gt;
To analyze the data we will plot the dielectric screening and check how the different values of the screening change the absorption spectra.&lt;br /&gt;
In the folder &amp;lt;code&amp;gt;tutorials/bn/&amp;lt;/code&amp;gt; you find the python script &amp;lt;code&amp;gt;bse_cutoff_bn.py&amp;lt;/code&amp;gt;. This script takes some time to be executed, you can run both variants without the cutoff and with the cutoff &amp;lt;code&amp;gt;-c&amp;lt;/code&amp;gt; simultaneously to save time. You can run this script with:&lt;br /&gt;
&lt;br /&gt;
 python bse_cutoff_bn.py -r -t4    # without coulomb cutoff&lt;br /&gt;
 python bse_cutoff_bn.py -r -c -t4 # with coulomb cutoff&lt;br /&gt;
where &amp;lt;code&amp;gt;-t&amp;lt;/code&amp;gt; specifies the number of MPI threads to use. The main loop changes the &amp;lt;code&amp;gt;layer_separation&amp;lt;/code&amp;gt; variable using values from a list in the header of the file. In the script you can find how the functions &amp;lt;code&amp;gt;scf&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ncf&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;database&amp;lt;/code&amp;gt; are defined.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;b. Plot the dielectric function&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In a similar way as what was done before we can now plot the dielectric function for different layer separations:&lt;br /&gt;
&lt;br /&gt;
 yambopy plotem1s bse_cutoff/*/*     # without coulomb cutoff  &lt;br /&gt;
 yambopy plotem1s bse_cutoff_cut/*/* # with coulomb cutoff&lt;br /&gt;
&lt;br /&gt;
[[File:Bn em1s cutoff cut.png|Yambo tutorial image]]&lt;br /&gt;
&lt;br /&gt;
[[File:Bn em1s cutoff.png|Yambo tutorial image]]&lt;br /&gt;
&lt;br /&gt;
In these figures it is clear that the long-range part of the coulomb interaction (q=0 in reciprocal space) is truncated, i. e. it is forced to go to zero.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;c. Plot the absorption spectrum&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
You can also plot how the absorption spectra changes with the cutoff using:&lt;br /&gt;
&lt;br /&gt;
 python bse_cutoff_bn.py -p&lt;br /&gt;
 python bse_cutoff_bn.py -p -c&lt;br /&gt;
&lt;br /&gt;
[[File:Bn bse cutoff.png|bn bse cutoff]]&lt;br /&gt;
&lt;br /&gt;
[[File:Bn bse cutoff cut.png|bn bse cutoff cut]]&lt;br /&gt;
&lt;br /&gt;
As you can see, the spectra is still changing with the vacuum spacing, you should increase the vacuum until convergence. For that you can add larger values to the &amp;lt;code&amp;gt;layer_separations&amp;lt;/code&amp;gt; list and run the calculations and analysis again.&lt;br /&gt;
&lt;br /&gt;
=== Excitonic wavefunctions in reciprocal space ===&lt;br /&gt;
&lt;br /&gt;
In this example we show how to use &amp;lt;code&amp;gt;yambopy&amp;lt;/code&amp;gt; to plot the excitonic wavefunction weights that result from a BSE calculation (specifically from the diagonalisation of the excitonic Hamiltonian). The script we will use this time is: &amp;lt;code&amp;gt;bse_bn.py&amp;lt;/code&amp;gt;. Be aware the parameters specified for the calculation are not high enough to obtain a converged result. &lt;br /&gt;
&lt;br /&gt;
To run the BSE calculation do:&lt;br /&gt;
&lt;br /&gt;
 python bse_bn.py -r&lt;br /&gt;
Alternatively, you can run  &lt;br /&gt;
 python bse_bn.py -r -c  &lt;br /&gt;
to add the Coulomb cutoff.&lt;br /&gt;
&lt;br /&gt;
Then, the absorption spectrum is readily plotted by running the auxiliary script&lt;br /&gt;
 python plot-bse.py&lt;br /&gt;
 &lt;br /&gt;
[[File:bse_abs_plt.png|Yambo tutorial image]]&lt;br /&gt;
&lt;br /&gt;
Afterwards you can run a basic analysis of the excitonic states and store the wavefunctions of the ones that are the most optically active, plotting them in reciprocal space. Plots in real space (not covered here) are also possible using yambopy (by calling ypp). &lt;br /&gt;
&lt;br /&gt;
In order to proceed we will use the script &amp;lt;code&amp;gt;plot-excitondb.py&amp;lt;/code&amp;gt;.&lt;br /&gt;
After running it as &lt;br /&gt;
&lt;br /&gt;
 python plot-excitondb.py&lt;br /&gt;
 &lt;br /&gt;
it will produce three plots.&lt;br /&gt;
&lt;br /&gt;
The first one is a representation of the excitonic weights (or rather their modulus) in reciprocal space, band- and kpoint-resolved, for the lowest-bound exciton.&lt;br /&gt;
You can see that the electronic transitions contributing to this state originate mostly at symmetry point K (direct band gap) and along the KM line (the bands here have pi-type orbital character).&lt;br /&gt;
&lt;br /&gt;
[[File:exc_bands.png|Yambo tutorial image]]&lt;br /&gt;
&lt;br /&gt;
The second figure is an interpolated version of the first, with the bands and excitonic contributions appearing smoother.&lt;br /&gt;
&lt;br /&gt;
[[File:exc_bands_interp.png|Yambo tutorial image]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The final figure is a representation of the excitonic weights, summed over all bands, within the Brillouin zone. The brighter colors indicate where the most important electronic transitions for this excitonic state are located.&lt;br /&gt;
&lt;br /&gt;
[[File:exc_BZ.png|Yambo tutorial image]]&lt;br /&gt;
&lt;br /&gt;
You can obtain plots for different excitonic states by changing the line&lt;br /&gt;
&lt;br /&gt;
 # List of states to be merged&lt;br /&gt;
 states = [1,2]&lt;br /&gt;
 &lt;br /&gt;
in &amp;lt;code&amp;gt;plot-excitondb.py&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
You may also want to test the script with a more converged calculation: to this end you can increase the number of kpoints in the nscf calculation by going to &amp;lt;code&amp;gt;gs_bn.py&amp;lt;/code&amp;gt; and changing the line&lt;br /&gt;
&lt;br /&gt;
 kpoints_nscf = [6,6,1]&lt;br /&gt;
&lt;br /&gt;
to your liking (for example to &amp;lt;code&amp;gt;12x12x1&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Then, run again the following commands (nscf calculation, regeneration of yambo database, new BSE calculation).&lt;br /&gt;
&lt;br /&gt;
 python gs_bn.py -n&lt;br /&gt;
 rm -r database&lt;br /&gt;
 python bse_bn.py -r -t 4&lt;br /&gt;
&lt;br /&gt;
As for the plotting, you may want to increase the value of &amp;lt;code&amp;gt;lpratio&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;plot-excitondb.py&amp;lt;/code&amp;gt; to ensure that the interpolation works, as well as reduce the value of &amp;lt;code&amp;gt;scale&amp;lt;/code&amp;gt; for a nicer plot in the hexagonal BN.&lt;br /&gt;
The lines to be changed are&lt;br /&gt;
&lt;br /&gt;
 exc_bands_inter = yexc.interpolate(save,path,states,lpratio=5,f=None,size=0.5,verbose=True)&lt;br /&gt;
&lt;br /&gt;
and&lt;br /&gt;
&lt;br /&gt;
 yexc.plot_exciton_2D_ax(ax,states,mode=&#039;hexagon&#039;,limfactor=0.8,scale=160)&lt;br /&gt;
&lt;br /&gt;
Then, you can run &amp;lt;code&amp;gt;plot-excitondb.py&amp;lt;/code&amp;gt; again.&lt;br /&gt;
&lt;br /&gt;
Again, be aware that these figures serve only to show the kind of representation that can be obtained with &amp;lt;code&amp;gt;yambo&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ypp&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;yambopy&amp;lt;/code&amp;gt;. Further convergence tests need to be performed to obtain accurate results, but that is left to the user.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
You can now visualise these wavefunctions in real space using our online tool: [http://henriquemiranda.github.io/excitonwebsite/ http://henriquemiranda.github.io/excitonwebsite/]&lt;br /&gt;
&lt;br /&gt;
For that, go to the website, and in the &amp;lt;code&amp;gt;Excitons&amp;lt;/code&amp;gt; section select &amp;lt;code&amp;gt;absorptionspectra.json&amp;lt;/code&amp;gt; file using the &amp;lt;code&amp;gt;Custom File&amp;lt;/code&amp;gt;. You should see on the right part the absorption spectra and on the left the representation of the wavefunction in real space. Alternatively you can vizualise the individually generated &amp;lt;code&amp;gt;.xsf&amp;lt;/code&amp;gt; files using xcrysden.&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
=== Parallel static screening ===&lt;br /&gt;
&lt;br /&gt;
In this tutorial we will show how you can split the calculation of the dielectric function in different jobs using &amp;lt;code&amp;gt;yambopy&amp;lt;/code&amp;gt;. The dielectric function can then be used to calculate the excitonic states using the BSE.&lt;br /&gt;
&lt;br /&gt;
The idea is that in certain clusters it is advantageous to split the jobs as much as possible. The dielectric function is calculated for different momentum transfer (q-points) over the brillouin zone. Each calculation is independent and can run at the same time. Using the &amp;lt;code&amp;gt;yambo&amp;lt;/code&amp;gt; parallelization you can separate the dielectric function calculation among many cpus using the variable &amp;lt;code&amp;gt;q&amp;lt;/code&amp;gt; in &amp;lt;code&amp;gt;X_all_q_CPU&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;X_all_q_ROLEs&amp;lt;/code&amp;gt;. The issue is that you still need to make a big reservation and in some cases there is load imbalance (some nodes end up waiting for others). Splitting in smaller jobs can help your jobs to get ahead in the queue and avoid the load imbalance. If there are many free nodes you might end up running all the q-points at the same time.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;The idea is quite simple:&#039;&#039;&#039; you create an individual input file for each q-point, submit each job separately, collect the results and do the final BSE step (this method should also apply for a GW calculation).&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;2. Parallel Dielectric function&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
To run the dielectric function in parallel do:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;python bse_par_bn.py -r -t2&amp;lt;/source&amp;gt;&lt;br /&gt;
Here we tell &amp;lt;code&amp;gt;yambo&amp;lt;/code&amp;gt; to calculate the dielectric function. We read the number of q-points the system has and generate one input file per q-point. Next we tell &amp;lt;code&amp;gt;yambo&amp;lt;/code&amp;gt; to calculate the first q-point. &amp;lt;code&amp;gt;yambo&amp;lt;/code&amp;gt; will calculate the dipoles and the dielectric function at the first q-point. Once the calculation is done we copy the dipoles to the SAVE directory. After that we run each q-point calculation as a separate job. Here the user can decide to submit one job per q-point on a cluster or use the python &amp;lt;code&amp;gt;multiprocessing&amp;lt;/code&amp;gt; module to submit the jobs in parallel. In this example we use the second option.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;from yambopy import *&lt;br /&gt;
import os&lt;br /&gt;
import multiprocessing&lt;br /&gt;
&lt;br /&gt;
yambo = &amp;quot;yambo&amp;quot;;&lt;br /&gt;
folder = &amp;quot;bse_par&amp;quot;;&lt;br /&gt;
nthreads = 2 #create two simultaneous jobs&lt;br /&gt;
&lt;br /&gt;
#create the yambo input file&lt;br /&gt;
y = YamboIn(&#039;yambo -r -b -o b -V all&#039;,folder=folder)&lt;br /&gt;
&lt;br /&gt;
y[&#039;FFTGvecs&#039;] = [30,&#039;Ry&#039;]&lt;br /&gt;
y[&#039;NGsBlkXs&#039;] = [1,&#039;Ry&#039;]&lt;br /&gt;
y[&#039;BndsRnXs&#039;] = [[1,30],&#039;&#039;]&lt;br /&gt;
y.write(&#039;%s/yambo_run.in&#039;%folder)&lt;br /&gt;
&lt;br /&gt;
#get the number of q-points&lt;br /&gt;
startk,endk = map(int,y[&#039;QpntsRXs&#039;][0])&lt;br /&gt;
&lt;br /&gt;
#prepare the q-points input files&lt;br /&gt;
jobs = []&lt;br /&gt;
for nk in xrange(1,endk+1):&lt;br /&gt;
    y[&#039;QpntsRXs&#039;] = [[nk,nk],&#039;&#039;]&lt;br /&gt;
    y.write(&#039;%s/yambo_q%d.in&#039;%(folder,nk))&lt;br /&gt;
    if nk != 1:&lt;br /&gt;
        jobs.append(&#039;cd %s; %s -F yambo_q%d.in -J yambo_q%d -C yambo_q%d 2&amp;amp;gt; log%d&#039;%(folder,yambo,nk,nk,nk,nk))&lt;br /&gt;
&lt;br /&gt;
#calculate first q-point and dipoles&lt;br /&gt;
os.system(&#039;cd %s; %s -F yambo_q1.in -J yambo_q1 -C yambo_q1&#039;%(folder,yambo))&lt;br /&gt;
#copy dipoles to save&lt;br /&gt;
os.system(&#039;cp %s/yambo_q1/ndb.dip* %s/SAVE&#039;%(folder,folder))&lt;br /&gt;
&lt;br /&gt;
p = multiprocessing.Pool(nthreads)&lt;br /&gt;
p.map(run_job, jobs)&amp;lt;/source&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;3. BSE&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Once the dielectric function is calculated, it is time to collect the data in one folder and do the last step of the calculation: generate the BSE Hamiltonian, diagonalize it and calculate the absorption.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;#gather all the files&lt;br /&gt;
if not os.path.isdir(&#039;%s/yambo&#039;%folder):&lt;br /&gt;
    os.mkdir(&#039;%s/yambo&#039;%folder)&lt;br /&gt;
os.system(&#039;cp %s/yambo_q1/ndb.em* %s/yambo&#039;%(folder,folder))&lt;br /&gt;
os.system(&#039;cp %s/*/ndb.em*_fragment* %s/yambo&#039;%(folder,folder))&lt;br /&gt;
&lt;br /&gt;
y = YamboIn(&#039;yambo -r -b -o b -k sex -y d -V all&#039;,folder=folder)&lt;br /&gt;
y[&#039;FFTGvecs&#039;] = [30,&#039;Ry&#039;]&lt;br /&gt;
y[&#039;NGsBlkXs&#039;] = [1,&#039;Ry&#039;]&lt;br /&gt;
y[&#039;BndsRnXs&#039;] = [[1,30],&#039;&#039;]&lt;br /&gt;
y[&#039;BSEBands&#039;] = [[3,6],&#039;&#039;]&lt;br /&gt;
y[&#039;BEnSteps&#039;] = [500,&#039;&#039;]&lt;br /&gt;
y[&#039;BEnRange&#039;] = [[0.0,10.0],&#039;eV&#039;]&lt;br /&gt;
y[&#039;KfnQP_E&#039;]  = [2.91355133,1.0,1.0] #some scissor shift&lt;br /&gt;
y.arguments.append(&#039;WRbsWF&#039;)&lt;br /&gt;
y.write(&#039;%s/yambo_run.in&#039;%folder)&lt;br /&gt;
&lt;br /&gt;
print(&#039;running yambo&#039;)&lt;br /&gt;
os.system(&#039;cd %s; %s -F yambo_run.in -J yambo&#039;%(folder,yambo))&amp;lt;/source&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;3. Collect and plot the results&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
You can then plot the data as before:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;python bse_par_bn.py -p&amp;lt;/source&amp;gt;&lt;br /&gt;
This will execute the following code:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;#collect the data&lt;br /&gt;
pack_files_in_folder(&#039;bse_par&#039;)&lt;br /&gt;
&lt;br /&gt;
#plot the results using yambo analyser&lt;br /&gt;
y = YamboAnalyser()&lt;br /&gt;
print y&lt;br /&gt;
y.plot_bse([&#039;eps&#039;,&#039;diago&#039;])&amp;lt;/source&amp;gt;&lt;br /&gt;
You should obtain a plot like this:&lt;br /&gt;
&lt;br /&gt;
[[File:Bethe Salpeter in BN.png|Yambo tutorial image]]&lt;br /&gt;
--&amp;gt;&lt;/div&gt;</summary>
		<author><name>Fulvio</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=First_steps_in_Yambopy&amp;diff=7770</id>
		<title>First steps in Yambopy</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=First_steps_in_Yambopy&amp;diff=7770"/>
		<updated>2024-04-17T11:03:33Z</updated>

		<summary type="html">&lt;p&gt;Fulvio: /* Tutorials */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The yambopy project aims to develop python tools to: &lt;br /&gt;
&lt;br /&gt;
* Read and edit yambo and quantum espresso input files&lt;br /&gt;
* Easily perform pre- and post-processing of the simulation data for these two codes - including hard-to-get, database-encoded data beyond standard outputs&lt;br /&gt;
* Provide easy visualization and plotting options &lt;br /&gt;
* Set up simple automatization workflows (e.g., convergence tests)&lt;br /&gt;
&lt;br /&gt;
=== Setup ===&lt;br /&gt;
First of all, make sure that you have a suitable python environment (crated for example with [https://docs.conda.io/projects/miniconda/en/latest/| conda] or [https://docs.python.org/3/library/venv.html| venv]) with python &amp;gt;=3.8.&lt;br /&gt;
&lt;br /&gt;
Then, you may install yambopy in one of the following ways.&lt;br /&gt;
&lt;br /&gt;
==== Quick installation from PyPI repository ====&lt;br /&gt;
&lt;br /&gt;
* In order to quickly install the officially released version type:&lt;br /&gt;
&lt;br /&gt;
 pip install yambopy&lt;br /&gt;
&lt;br /&gt;
==== Installation from tarball ====&lt;br /&gt;
&lt;br /&gt;
* In case you don&#039;t want to download from the pip repository and prefer to install a version of yambopy locally, you may download the appropriate tarball from the [https://github.com/yambo-code/yambopy/releases| yambopy github page]. Extract the tarball, enter the yambopy folder and type &amp;lt;code&amp;gt;pip install .&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Installation of latest patch ====&lt;br /&gt;
&lt;br /&gt;
* In case you want the latest version of the code including new updates and patches that might not be present in the official version, then you can clone the yambopy git repository (a basic knowledge of git may be helpful):&lt;br /&gt;
&lt;br /&gt;
 git clone https://github.com/yambo-code/yambopy.git&lt;br /&gt;
 cd yambopy&lt;br /&gt;
 pip install .&lt;br /&gt;
&lt;br /&gt;
==== Dependencies ====&lt;br /&gt;
&lt;br /&gt;
* In principle, &amp;lt;code&amp;gt;pip&amp;lt;/code&amp;gt; should take care of the required python dependencies. They are &amp;lt;code&amp;gt;numpy&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;scipy&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;matplotlib&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;netCDF4&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;lxml&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;PyYAML&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;monty&amp;lt;/code&amp;gt;. In case some dependency-related problem arises, you can install each of them separately beforehand with:&lt;br /&gt;
&lt;br /&gt;
 pip install &amp;lt;code&amp;gt;dependency-name&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Tutorials ===&lt;br /&gt;
Now yambopy is ready to use! Just go to the tutorials folder and follow the docs!&lt;br /&gt;
&lt;br /&gt;
 cd tutorial/&lt;br /&gt;
&lt;br /&gt;
On this wiki, we provide steps for the following tutorials:&lt;br /&gt;
&lt;br /&gt;
1. Data postprocessing:&lt;br /&gt;
* [[Yambopy tutorial: band structures | Database and plotting tutorial for quantum espresso: qepy]] (Get the databases: [https://media.yambo-code.eu/educational/tutorials/files/databases_qepy.tar.gz databases_qepy], 46.5MB)&lt;br /&gt;
* [[Yambopy tutorial: Yambo databases | Database and plotting tutorial for yambo: yambopy ]] (Get the databases: [https://media.yambo-code.eu/educational/tutorials/files/databases_yambopy.tar.gz databases_yambopy], 129MB)&lt;br /&gt;
2. Manage QE and Yambo runs:&lt;br /&gt;
* [[GW tutorial. Convergence and approximations (BN)]]&lt;br /&gt;
* [[Bethe-Salpeter equation tutorial. Optical absorption (BN)]]&lt;br /&gt;
3. Advanced topics:&lt;br /&gt;
* [[Phonon-assisted luminescence by finite atomic displacements]]&lt;/div&gt;</summary>
		<author><name>Fulvio</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=First_steps_in_Yambopy&amp;diff=7769</id>
		<title>First steps in Yambopy</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=First_steps_in_Yambopy&amp;diff=7769"/>
		<updated>2024-04-17T11:03:21Z</updated>

		<summary type="html">&lt;p&gt;Fulvio: /* Tutorials */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The yambopy project aims to develop python tools to: &lt;br /&gt;
&lt;br /&gt;
* Read and edit yambo and quantum espresso input files&lt;br /&gt;
* Easily perform pre- and post-processing of the simulation data for these two codes - including hard-to-get, database-encoded data beyond standard outputs&lt;br /&gt;
* Provide easy visualization and plotting options &lt;br /&gt;
* Set up simple automatization workflows (e.g., convergence tests)&lt;br /&gt;
&lt;br /&gt;
=== Setup ===&lt;br /&gt;
First of all, make sure that you have a suitable python environment (crated for example with [https://docs.conda.io/projects/miniconda/en/latest/| conda] or [https://docs.python.org/3/library/venv.html| venv]) with python &amp;gt;=3.8.&lt;br /&gt;
&lt;br /&gt;
Then, you may install yambopy in one of the following ways.&lt;br /&gt;
&lt;br /&gt;
==== Quick installation from PyPI repository ====&lt;br /&gt;
&lt;br /&gt;
* In order to quickly install the officially released version type:&lt;br /&gt;
&lt;br /&gt;
 pip install yambopy&lt;br /&gt;
&lt;br /&gt;
==== Installation from tarball ====&lt;br /&gt;
&lt;br /&gt;
* In case you don&#039;t want to download from the pip repository and prefer to install a version of yambopy locally, you may download the appropriate tarball from the [https://github.com/yambo-code/yambopy/releases| yambopy github page]. Extract the tarball, enter the yambopy folder and type &amp;lt;code&amp;gt;pip install .&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Installation of latest patch ====&lt;br /&gt;
&lt;br /&gt;
* In case you want the latest version of the code including new updates and patches that might not be present in the official version, then you can clone the yambopy git repository (a basic knowledge of git may be helpful):&lt;br /&gt;
&lt;br /&gt;
 git clone https://github.com/yambo-code/yambopy.git&lt;br /&gt;
 cd yambopy&lt;br /&gt;
 pip install .&lt;br /&gt;
&lt;br /&gt;
==== Dependencies ====&lt;br /&gt;
&lt;br /&gt;
* In principle, &amp;lt;code&amp;gt;pip&amp;lt;/code&amp;gt; should take care of the required python dependencies. They are &amp;lt;code&amp;gt;numpy&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;scipy&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;matplotlib&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;netCDF4&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;lxml&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;PyYAML&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;monty&amp;lt;/code&amp;gt;. In case some dependency-related problem arises, you can install each of them separately beforehand with:&lt;br /&gt;
&lt;br /&gt;
 pip install &amp;lt;code&amp;gt;dependency-name&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Tutorials ===&lt;br /&gt;
Now yambopy is ready to use! Just go to the tutorials folder and follow the docs!&lt;br /&gt;
&lt;br /&gt;
 cd tutorial/&lt;br /&gt;
&lt;br /&gt;
On this wiki, we provide steps for the following tutorials:&lt;br /&gt;
1. Data postprocessing:&lt;br /&gt;
* [[Yambopy tutorial: band structures | Database and plotting tutorial for quantum espresso: qepy]] (Get the databases: [https://media.yambo-code.eu/educational/tutorials/files/databases_qepy.tar.gz databases_qepy], 46.5MB)&lt;br /&gt;
* [[Yambopy tutorial: Yambo databases | Database and plotting tutorial for yambo: yambopy ]] (Get the databases: [https://media.yambo-code.eu/educational/tutorials/files/databases_yambopy.tar.gz databases_yambopy], 129MB)&lt;br /&gt;
2. Manage QE and Yambo runs:&lt;br /&gt;
* [[GW tutorial. Convergence and approximations (BN)]]&lt;br /&gt;
* [[Bethe-Salpeter equation tutorial. Optical absorption (BN)]]&lt;br /&gt;
3. Advanced topics:&lt;br /&gt;
* [[Phonon-assisted luminescence by finite atomic displacements]]&lt;/div&gt;</summary>
		<author><name>Fulvio</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_Yambo_databases&amp;diff=7759</id>
		<title>Yambopy tutorial: Yambo databases</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_Yambo_databases&amp;diff=7759"/>
		<updated>2024-04-12T15:36:38Z</updated>

		<summary type="html">&lt;p&gt;Fulvio: Replaced figure&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial we will see some examples on how to read and analyse the data contained in the Yambo netCDF databases, which are not readily available as human readable outputs.&lt;br /&gt;
&lt;br /&gt;
In particular we will take a look at:&lt;br /&gt;
* Lattice geometry data (Yambo database: &amp;lt;code&amp;gt;ns.db1&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
* Electron-phonon matrix elements (Yambo databases: &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
* Dipole matrix elements (Yambo databases: &amp;lt;code&amp;gt;ndb.dipoles&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboDipolesDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
* Exciton wavefunctions, energy and spectra (Yambo databases: &amp;lt;code&amp;gt;ndb.BS_diago_Q*&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboExcitonDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
We will also check the command line instructions to quickly generate yambo SAVE folders.&lt;br /&gt;
&lt;br /&gt;
The scripts of the tutorial, but not the databases, can be found in the yambopy directory:&lt;br /&gt;
 $cd tutorial/databases_yambopy&lt;br /&gt;
&lt;br /&gt;
The full tutorial, including the Quantum espresso and Yambo databases that we will read, can be downloaded and extracted from the yambo website:&lt;br /&gt;
 $wget https://media.yambo-code.eu/educational/tutorials/files/databases_yambopy.tar.gz&lt;br /&gt;
 $tar -xvzf databases_yambopy.tar.gz&lt;br /&gt;
 $cd databases_yambopy&lt;br /&gt;
&lt;br /&gt;
We will work with monolayer hexagonal boron nitride electron-phonon and exciton data obtained on a &amp;lt;code&amp;gt;12x12x1&amp;lt;/code&amp;gt; kpoint grid. Beware that these are certainly not converged.&lt;br /&gt;
&lt;br /&gt;
=== Command line: generating the Yambo SAVE ===&lt;br /&gt;
Yambopy offers a set of command line options. In order to review them, you can type&lt;br /&gt;
 $yambopy&lt;br /&gt;
which will print the output&lt;br /&gt;
 yambopy&lt;br /&gt;
 Available commands are:&lt;br /&gt;
 &lt;br /&gt;
       plotem1s -&amp;gt;     Plot em1s calculation&lt;br /&gt;
      analysebse -&amp;gt;     Using ypp, you can study the convergence of BSE calculations in 2 ways:&lt;br /&gt;
      analysegw -&amp;gt;     Study the convergence of GW calculations by looking at the change in band-gap value.&lt;br /&gt;
   plotexcitons -&amp;gt;     Plot excitons calculation&lt;br /&gt;
          addqp -&amp;gt;     Add corrections from QP databases.&lt;br /&gt;
        mergeqp -&amp;gt;     Merge QP databases&lt;br /&gt;
           save -&amp;gt;     Produce a SAVE folder&lt;br /&gt;
           gkkp -&amp;gt;     Produce a SAVE folder including elph_gkkp databases&lt;br /&gt;
          bands -&amp;gt;     Script to produce band structure data and visualization from QE.&lt;br /&gt;
         serial -&amp;gt;     Script to update serial numbers of yambo ndb.* databases in order to import them to new calculations.&lt;br /&gt;
           test -&amp;gt;     Run yambopy tests&lt;br /&gt;
&lt;br /&gt;
For this tutorial, we will need the &amp;lt;code&amp;gt;save&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;gkkp&amp;lt;/code&amp;gt; options.&lt;br /&gt;
By typing in one of these, additional information about how to run the commands will be printed, e.g.:&lt;br /&gt;
 $yambopy save&lt;br /&gt;
&lt;br /&gt;
 Produce a SAVE folder&lt;br /&gt;
 &lt;br /&gt;
 Arguments are:&lt;br /&gt;
   -nscf, --nscf_dir  -&amp;gt; Path to nscf save folder&lt;br /&gt;
   -y, --yambo_dir    -&amp;gt; &amp;lt;Optional&amp;gt; Path to yambo executables&lt;br /&gt;
&lt;br /&gt;
The quantum espresso save for hBN is provided in the directory &amp;lt;code&amp;gt;BSE_saves/QE_saves/hBN.save&amp;lt;/code&amp;gt; (you can check the contents of the various folders). &lt;br /&gt;
Then, following the instructions printed on screen, we can generate a yambo SAVE from the hBN.save by typing&lt;br /&gt;
&lt;br /&gt;
 $yambopy save -nscf BSE_saves/QE_saves/hBN.save&lt;br /&gt;
&lt;br /&gt;
This should produce a SAVE folder in the current directory.&lt;br /&gt;
&lt;br /&gt;
=== Lattice intro: plot k-point coordinates in IBZ/BZ ===&lt;br /&gt;
For this section we will use the script &amp;lt;code&amp;gt;bz_plot.py&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
By inspecting the SAVE folder we have just generated, we will find the &amp;lt;code&amp;gt;ns.db1&amp;lt;/code&amp;gt; database which contains all the geometry and lattice information.&lt;br /&gt;
We are now going to read it in python by using the Yambopy class &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
&lt;br /&gt;
 from yambopy import *&lt;br /&gt;
 ylat = YamboLatticeDB.from_db_file(filename=&amp;quot;PATH/TO/SAVE/ns.db1&amp;quot;)&lt;br /&gt;
(remember to edit the variable &amp;lt;code&amp;gt;save_path&amp;lt;/code&amp;gt; in order to point at your yambo SAVE).&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;ylat&amp;lt;/code&amp;gt; object now contains many useful information as attributes, such as the k-points in Cartesian or crystal coordinates, the system symmetries, lattice constants and basis vectors in real and reciprocal space, etc.&lt;br /&gt;
The k-points are also automatically expanded in the full Brillouin zone from the irreducible one (you can turn this off with the option &amp;lt;code&amp;gt;Expand=False&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Directly printing the object with&lt;br /&gt;
 print(ylat)&lt;br /&gt;
will also give us some general parameters related to the database. &lt;br /&gt;
&lt;br /&gt;
Now check the &amp;lt;code&amp;gt;bz_plot.py&amp;lt;/code&amp;gt; script. You will see that it performs three plots: &lt;br /&gt;
* Scatterplot of the k-points in Cartesian coordinates with both expanded and unexpanded grids, with annotated indices [&amp;lt;code&amp;gt;Cartesian_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Scatterplot of the k-points in crystal coordinates [&amp;lt;code&amp;gt;Crystal_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Manual transformation of a chosen k-point from irreducible to full Brillouin zone (you can change the index &amp;lt;code&amp;gt;i_k&amp;lt;/code&amp;gt; in the script to check different cases) [&amp;lt;code&amp;gt;Symmetry_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
[[File:Car kpoints hbn.jpg|YamboLatticeDB plot from yambopy tutorial| 500px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Dipoles intro: plots of dipoles on BZ, plot of IP absorption ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;dipoles_plot.py&amp;lt;/code&amp;gt; and read the dipole databases generated in an optical absorption calculation by yambo. Keep in mind that from now on we will use the &amp;quot;BSE&amp;quot; yambo SAVE generated in the [[#Command line: generating the Yambo SAVE|first section]].&lt;br /&gt;
&lt;br /&gt;
The databases written after a calculation of optical properties with yambo (dipoles, static screening, excitons) are in the directory &amp;lt;code&amp;gt;BSE_saves/BSE_databases&amp;lt;/code&amp;gt;. Here we will also find &amp;lt;code&amp;gt;ndb.dipoles&amp;lt;/code&amp;gt; which is needed now, since it contains the matrix elements d_{vck}(\alpha) where vk and ck are the valence and electron states involved in the transition and \alpha the polarisation direction of the external electric field.&lt;br /&gt;
&lt;br /&gt;
In order to read it in python we use the Yambopy class &amp;lt;code&amp;gt;YamboDipolesDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
 ydip = YamboDipolesDB(ylat,save=&#039;path/to/BSE/databases&#039;,filename=&#039;ndb.dipoles&#039;)&lt;br /&gt;
(notice that it requires a previous instance of &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
In addition, in order to read the Kohn-Sham energies, we can also instance the &amp;lt;code&amp;gt;YamboElectronsDB&amp;lt;/code&amp;gt; as&lt;br /&gt;
 yel = YamboElectronsDB(ylat,save=&#039;path/to/SAVE&#039;)&lt;br /&gt;
&lt;br /&gt;
The object &amp;lt;code&amp;gt;ydip&amp;lt;/code&amp;gt; now has a method that permits to retrieve the independent-particle absorption spectrum with customly chosen energy range, steps, and broadening:&lt;br /&gt;
 w, eps2 = ydip.ip_eps2(yel)&lt;br /&gt;
&lt;br /&gt;
In order to see all this in action, take a look at the &amp;lt;code&amp;gt;dipoles_plot.py&amp;lt;/code&amp;gt; script. You will see that it performs two plots:&lt;br /&gt;
* Plot of |d(k)| in the BZ for selected v,c and \alpha (we choose the layer plane &#039;xy&#039;) [&amp;lt;code&amp;gt;Kspace_Plot=True&amp;lt;/code&amp;gt;]. From this plot you can appreciate which sections of the BZ contribute the most to the absorption rate.&lt;br /&gt;
* Plot of the independent-particles absorption spectrum [&amp;lt;code&amp;gt;Absorption_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
You can play with the indices and the plot parameters to check what happens.&lt;br /&gt;
&lt;br /&gt;
[[File:Dipoles hbn2.png|YamboDipolesDB plot from yambopy tutorial|500px]]&lt;br /&gt;
&lt;br /&gt;
=== Exciton intro 1: read and sort data ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;exc_read.py&amp;lt;/code&amp;gt; and read the exciton data resulting from a BSE calculation in order to familiarise with their structure. This time we are going to read the &amp;lt;code&amp;gt;ndb.BS_diago_Q*&amp;lt;/code&amp;gt; databases which correspond to BSE calculations at various momenta Q (Q=1 being the zero-momentum optical absorption limit - notice that python indexing starts from 0, while the databases are counted starting from 1).&lt;br /&gt;
&lt;br /&gt;
In order to read them in python we use the Yambopy class &amp;lt;code&amp;gt;YamboExcitonDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
 yexc = YamboExcitonDB.from_db_file(ylat,filename=&#039;path/to/BSE/databases/ndb.BS_diago_Q%d&#039;(i_Q+1))&lt;br /&gt;
(notice that it requires a previous instance of &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Now the &amp;lt;code&amp;gt;yexc&amp;lt;/code&amp;gt; object contains information about the exciton energies (&amp;lt;code&amp;gt;yexc.eigenvalues&amp;lt;/code&amp;gt;), wave functions (&amp;lt;code&amp;gt;yexc.eigenvectors&amp;lt;/code&amp;gt;) and intensities (&amp;lt;code&amp;gt;yexc.l_residuals&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yexc.r_residuals&amp;lt;/code&amp;gt;) for Qpoint i_Q. You can start by keeping &amp;lt;code&amp;gt;Q1&amp;lt;/code&amp;gt; which is the optical limit and then check other momenta.&lt;br /&gt;
&lt;br /&gt;
The exciton wave function components A_{vck}^{\lambda Q} (\lambda being the exciton index) are stored as A_{t}^{\lambda} in each Q-dependent database, with t being the transition index grouping the single-particle indices vck. Therefore, &amp;lt;code&amp;gt;yexc.eigenvectors&amp;lt;/code&amp;gt; is an array with (N_excitons,N_transitions) dimension. In order to make the connection t-&amp;gt;kcv, the table &amp;lt;code&amp;gt;yexc.table&amp;lt;/code&amp;gt; provides k,v,c and spin indices corresponding to each transition.&lt;br /&gt;
&lt;br /&gt;
In order to get a clearer picture, take a look at the script &amp;lt;code&amp;gt;exc_read.py&amp;lt;/code&amp;gt;. Run it and try to understand the outputs.&lt;br /&gt;
  $ python exc_read.py&lt;br /&gt;
&lt;br /&gt;
=== Exciton intro 2: plot exciton weights on k-BZ and (interpolated) band structure ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;exc_kspace_plot.py&amp;lt;/code&amp;gt; and work with the quantities defined in the previous section.&lt;br /&gt;
&lt;br /&gt;
For now, only the i_Q=0 case is implemented in this section.&lt;br /&gt;
We want to check the relative importance of the various (vk-&amp;gt;ck) electronic transitions in forming a certain excitonic state. &lt;br /&gt;
&lt;br /&gt;
Since many excitonic states are degenerate, we first need to tell Yambopy which states we want to check. For example, in monolayer hexagonal boron nitride, the lowest-bound exciton - forming the main peak in the BSE absorption spectrum - is doubly degenerate. In order to analyse it, in the &amp;lt;code&amp;gt;exc_kspace_plot.py&amp;lt;/code&amp;gt; script we set&lt;br /&gt;
 states = [1,2]&lt;br /&gt;
(we can also set [3,4] to check the second excitonic state, and then [5] for the non-degenerate third state, and so on; we can check degeneracies by printing the energies using the script &amp;lt;code&amp;gt;exc_read.py&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
In order to make a band structure plot, it is necessary to read the band energies, for example with the &amp;lt;code&amp;gt;YamboSaveDB&amp;lt;/code&amp;gt; class&lt;br /&gt;
 yel = YamboSaveDB.from_db_file(folder=&#039;path/to/SAVE&#039;)&lt;br /&gt;
and specify the path in the BZ using crystal coordinates via the &amp;lt;code&amp;gt;Path&amp;lt;/code&amp;gt; function:   &lt;br /&gt;
 npoints = 20&lt;br /&gt;
 path = Path([ [[  0.0,  0.0,  0.0],&#039;$\Gamma$&#039;],&lt;br /&gt;
               [[  0.5,  0.0,  0.0],&#039;M&#039;],&lt;br /&gt;
               [[1./3.,1./3.,  0.0],&#039;K&#039;],&lt;br /&gt;
               [[  0.0,  0.0,  0.0],&#039;$\Gamma$&#039;]],&lt;br /&gt;
               [int(npoints*2),int(npoints),int(sqrt(5)*npoints)] )&lt;br /&gt;
&lt;br /&gt;
Now let&#039;s take a closer look at the &amp;lt;code&amp;gt;exc_kspace_plot.py&amp;lt;/code&amp;gt; script. You will see that it performs three plots:&lt;br /&gt;
* Plot of |A(k)| in the k-BZ for the selected exciton state. You can see how most contributions come from the area around K and the MK direction [&amp;lt;code&amp;gt;Kspace_Plot=True&amp;lt;/code&amp;gt;]. &lt;br /&gt;
* Plot of |A(v,c,k)| on the electronic band structure for the selected exciton state. Here you can better see how the top valence and bottom conduction around MK are mostly involved [&amp;lt;code&amp;gt;Bands_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Plot of interpolated |A(v,c,k)| on the interpolated electronic band structure for the selected exciton state [&amp;lt;code&amp;gt;Bands_Plot_Interpolated=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
As always, try to play with the parameters, for example by changing the excitonic states to analyse.&lt;br /&gt;
&lt;br /&gt;
[[File:Exc bands1 hbn.jpg|YamboExcitonDB plot from yambopy tutorial|300px| Uninterpolated exciton weights on top of band structure]][[File:Exc bands2 hbn.jpg|YamboExcitonDB plot from yambopy tutorial|300px]]&lt;br /&gt;
&lt;br /&gt;
=== Exciton intro 3: plot BSE optical absorption with custom options ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;exc_abs_plot.py&amp;lt;/code&amp;gt; and work with the quantities defined in the previous sections.&lt;br /&gt;
&lt;br /&gt;
The class &amp;lt;code&amp;gt;YamboExcitonDB&amp;lt;/code&amp;gt; also enables us, of course, to read the dielectric function eps(w) and print absorption and related spectra in python.&lt;br /&gt;
&lt;br /&gt;
The advantages over using the standard human-readable yambo outputs are mainly two:&lt;br /&gt;
# We can freely select energy ranges, energy steps, peak broadenings and number of excitonic states included without having to rerun the &amp;lt;code&amp;gt;yambo&amp;lt;/code&amp;gt; executable every time. This reduces the chance of mistakenly editing the yambo input and allows for greater freedom since these plots can now be done in your local machine without having to transfer the output data from a remote cluster.&lt;br /&gt;
# The dielectric function constructed from netCDF database variables has a much higher precision (number of significant digits) than the human readable output, which may be important if you want to perform additional operations in python (e.g., computing refractive index, reflectivity and other optical spectra from it, performing finite-difference derivatives, etc).&lt;br /&gt;
&lt;br /&gt;
We can read eps(w) as a &amp;lt;code&amp;gt;numpy&amp;lt;/code&amp;gt; array with the specified options as (energy values are in eV):&lt;br /&gt;
 w, eps = yexc.get_chi(nexcitons=&#039;all&#039;,emin=0,emax=7,estep=0.005,broad=0.04)&lt;br /&gt;
Or, you can directly prepare a plot of its imaginary part with&lt;br /&gt;
 w, chi = yexc.plot_chi_ax(ax,nexcitons=&#039;all&#039;,emin=0,emax=7,estep=0.005,broad=0.04)&lt;br /&gt;
where &amp;lt;code&amp;gt;ax&amp;lt;/code&amp;gt; is a previously defined &amp;lt;code&amp;gt;Axes&amp;lt;/code&amp;gt; object from &amp;lt;code&amp;gt;matplotlib&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In order to see how this works, let&#039;s take a look at the &amp;lt;code&amp;gt;exc_abs_plot.py&amp;lt;/code&amp;gt; script.&lt;br /&gt;
You will see that it performs the two operations described above:&lt;br /&gt;
* Plotting the BSE absorption spectrum [&amp;lt;code&amp;gt;Absorption_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Reading the complex dielectric function.&lt;br /&gt;
&lt;br /&gt;
Try to customise the plots by changing the &amp;lt;code&amp;gt;nexcitons&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;emin&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;emax&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;estep&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;broad&amp;lt;/code&amp;gt; parameters.&lt;br /&gt;
&lt;br /&gt;
[[File:Exc abs hbn.jpg|YamboExcitonDB plot from yambopy tutorial|500px]]&lt;br /&gt;
&lt;br /&gt;
=== Command line: importing electron-phonon matrix elements ===&lt;br /&gt;
You may have seen how to calculate and import electron-phonon matrix elements in yambo in the [[Electron Phonon Coupling|electron-phonon tutorial]].&lt;br /&gt;
&lt;br /&gt;
With Yambopy, we can generate a yambo SAVE folder and import the matrix elements with a single command.&lt;br /&gt;
Typing &lt;br /&gt;
 $yambopy gkkp&lt;br /&gt;
will print the necessary documentation:&lt;br /&gt;
 Produce a SAVE folder including elph_gkkp databases&lt;br /&gt;
 &lt;br /&gt;
 Arguments are:&lt;br /&gt;
   -nscf, --nscf_dir  -&amp;gt; &amp;lt;Optional&amp;gt; Path to nscf save folder&lt;br /&gt;
   -elph, --elph_dir  -&amp;gt; Path to elph_dir folder&lt;br /&gt;
   -y, --yambo_dir    -&amp;gt; &amp;lt;Optional&amp;gt; Path to yambo executables&lt;br /&gt;
   -e, --expand       -&amp;gt; &amp;lt;Optional&amp;gt; Expand gkkp databases&lt;br /&gt;
&lt;br /&gt;
The necessary quantum espresso databases are stored in &amp;lt;code&amp;gt;ELPH_SAVES/QE_SAVES/hBN.save&amp;lt;/code&amp;gt; (nscf calculation) and &amp;lt;code&amp;gt;ELPH_SAVES/QE_SAVES/elph_dir&amp;lt;/code&amp;gt; (matrix elements from the dfpt calculation). For this tutorial we also need to expand the electron-phonon matrix elements to the full Brillouin zone. Since this is a different calculation with respect to the previous section, please generate this SAVE in a different directory than the one you used for the previous SAVE, which should be the current directory.&lt;br /&gt;
For example:&lt;br /&gt;
 $mkdir yambo-with-elph&lt;br /&gt;
 $cd yambo-with-elph&lt;br /&gt;
&lt;br /&gt;
Now we can run yambopy as in the instructions:&lt;br /&gt;
 $yambopy gkkp -nscf ../ELPH_saves/QE_saves/hBN.save -elph ../ELPH_saves/QE_saves/elph_dir --expand&lt;br /&gt;
This should generate a yambo SAVE folder which contains the &amp;lt;code&amp;gt;ndb.elph_gkkp_expanded*&amp;lt;/code&amp;gt; databases.&lt;br /&gt;
&lt;br /&gt;
=== Electron-phonon intro: plots of el-ph matrix elements on k-BZ and q-BZ ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; and read the electron-phonon databases that you generated in the previous section.&lt;br /&gt;
&lt;br /&gt;
In order to read the &amp;lt;code&amp;gt;ndb.elph_gkkp_expanded*&amp;lt;/code&amp;gt; databases in python we use the Yambopy class &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
 yelph = YamboElectronPhononDB(ylat,folder_gkkp=&#039;path/to/elph/folder&#039;,save=&#039;path/to/SAVE&#039;)&lt;br /&gt;
(notice that it requires a previous instance of &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Now, the &amp;lt;code&amp;gt;yelph&amp;lt;/code&amp;gt; object contains phonon frequencies, phonon eigenvectors, qpoint information and, of course, the electron-phonon matrix elements g_{nm\nu}(k,q) where n, m are electron band states, \nu is a phonon branch, and k and q are the electronic and transfer momenta.&lt;br /&gt;
&lt;br /&gt;
We can print the docstring of the &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt; class with&lt;br /&gt;
 print(yelph.__doc__)&lt;br /&gt;
to get an idea of the information stored and of its capabilities.&lt;br /&gt;
&lt;br /&gt;
Now check the &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; script. You will see that it performs two plots: &lt;br /&gt;
* Plot of |g(k)| in the k-BZ for selected n,m,\nu and q [&amp;lt;code&amp;gt;Kspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Plot of |g(q)| in the q-BZ for selected n,m,\nu and k [&amp;lt;code&amp;gt;Qspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
You can change the electronic, phononic and momentum indices to see what happens.&lt;br /&gt;
&lt;br /&gt;
[[File:Elph hbn.jpg|YamboElectronPhononDB plot from yambopy tutorial|500px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Links==&lt;br /&gt;
* Back to [[Rome 2023#Tutorials]]&lt;br /&gt;
* Back to [[ICTP 2022#Tutorials]]&lt;/div&gt;</summary>
		<author><name>Fulvio</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=File:Dipoles_hbn2.png&amp;diff=7758</id>
		<title>File:Dipoles hbn2.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=File:Dipoles_hbn2.png&amp;diff=7758"/>
		<updated>2024-04-12T15:35:27Z</updated>

		<summary type="html">&lt;p&gt;Fulvio: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Dipoles plot for yambopy tutorial&lt;/div&gt;</summary>
		<author><name>Fulvio</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Two-photon_absorption&amp;diff=7749</id>
		<title>Two-photon absorption</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Two-photon_absorption&amp;diff=7749"/>
		<updated>2024-04-04T14:40:16Z</updated>

		<summary type="html">&lt;p&gt;Fulvio: /* Perform Fourier analysis of the polarization */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Tpa skeme.png|right|200px | tpa skeme]]&lt;br /&gt;
In this tutorial we will show how to calculate two-photon absorption(TPA) in bulk silicon, following the approach descried in Ref. &amp;lt;ref name=&amp;quot;tpa&amp;quot;&amp;gt;[https://amu.hal.science/hal-01755879/document Two-photon absorption in two-dimensional materials: The case of hexagonal boron nitride] Claudio Attaccalite, Myrta Grüning, Hakim Amara, Sylvain Latil, and François Ducastelle Phys. Rev. B &#039;&#039;&#039;98&#039;&#039;&#039;, 165126 (2018)  &amp;lt;/ref&amp;gt;. &amp;lt;br&amp;gt;In this tutorial we suppose you are already familiar with the non-linear response using the Yambo code. &amp;lt;br&amp;gt; If it is not the case please study the previous tutorials: [[Linear response using Dynamical Berry Phase]] and [[Real time approach to non-linear response (SHG)]].&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The tutorial is divided in different steps from the DFT calculation to the final TPA spectrum. For the calculation of the TPA we will use the real-time approach proposed in Ref. &amp;lt;ref name=nl&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 &#039;&#039;&#039;88&#039;&#039;&#039;, 235113(2013)&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== DFT calculations ==&lt;br /&gt;
&lt;br /&gt;
Here we provide input files for QuantumEspresso both the self-consistent calculation and the non-self-consistent: [https://www.attaccalite.com/tutorials_yambo/QE_silicon.tgz QE_silicon.tgz] &amp;lt;br&amp;gt;&lt;br /&gt;
Run them, import the wave-function in Yambo and run the setup. (see previous tutorials).&lt;br /&gt;
&lt;br /&gt;
== Removing symmetries ==&lt;br /&gt;
In this tutorial we will calculate the TPA along the &#039;x&#039; direction therefore we remove symmetries not compatible with an external field along this direction, with the command &amp;lt;code&amp;gt; ypp_nl -y&amp;lt;/code&amp;gt;: &lt;br /&gt;
&lt;br /&gt;
 fixsyms                          # [R] Remove symmetries not consistent with an &lt;br /&gt;
 external perturbation&lt;br /&gt;
 % Efield1&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;       # First external Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 % Efield2&lt;br /&gt;
  0.000000 | 0.000000 | 0.000000 |        # 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;
the you can go in the &amp;lt;code&amp;gt;FixSymm&amp;lt;/code&amp;gt; folder and run the setup again.&lt;br /&gt;
&lt;br /&gt;
== Calculations at different field intensities ==&lt;br /&gt;
&lt;br /&gt;
In order to extract the TPA coefficient we will run a series of simulation at different intensities of the external field: &#039;&#039;&#039;Ε&#039;&#039;&#039;, &#039;&#039;&#039;Ε/2&#039;&#039;&#039;, &#039;&#039;&#039;Ε/4&#039;&#039;&#039;. The polarization obtained from these simulation can be expanded in the field as:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Pols3.png|center|500px | 3 polarization]]&lt;br /&gt;
&lt;br /&gt;
then we will combine them to obtain the TPA coefficient as:&lt;br /&gt;
&lt;br /&gt;
[[File:Extrapolation.png|center|350px| extrapolation]]&lt;br /&gt;
&lt;br /&gt;
for more detail see Ref.&amp;lt;ref name=tpa&amp;gt;&amp;lt;/ref&amp;gt;. Hereafter the inputs for the real-time simulation. These inputs can be generated using the command &amp;lt;code&amp;gt;yambo -u n -V qp&amp;lt;/code&amp;gt;. The first input that we will call&amp;lt;code&amp;gt;input1.in&amp;lt;/code&amp;gt; reads:&lt;br /&gt;
 &lt;br /&gt;
 nloptics                         # [R] Non-linear spectroscopy&lt;br /&gt;
 % NLBands&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;  1 | 7 | &amp;lt;/span&amp;gt;                          # [NL] Bands range&lt;br /&gt;
 %&lt;br /&gt;
 NLverbosity= &amp;quot;low&amp;quot;               # [NL] Verbosity level (low | high)&lt;br /&gt;
 NLtime=74.000000           fs    # [NL] Simulation Time&lt;br /&gt;
 NLstep= 0.002500           fs    # [NL] Time step length&lt;br /&gt;
 NLintegrator= &amp;quot;INVINT&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;
 % NLEnRange&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;  0.200000 | 5.000000 | &amp;lt;/span&amp;gt;        eV    # [NL] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;NLEnSteps= 24  &amp;lt;/span&amp;gt;                 # [NL] Energy steps&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;NLDamping= 0.100000    &amp;lt;/span&amp;gt;    eV    # [NL] Damping (or dephasing)&lt;br /&gt;
 #EvalCurrent                   # [NL] Evaluate the current&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;    # [NL Field1] Field Versor&lt;br /&gt;
 %&lt;br /&gt;
 Field1_kind= &amp;quot;SIN&amp;quot;             # [NL Field1] Kind(SIN|SOFTSIN|RES|ANTIRES|GAUSS|DELTA|QSSIN)&lt;br /&gt;
 % GfnQP_E&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 0.600000 | 1.000000 | 1.000000 |   &amp;lt;/span&amp;gt;     # [EXTQP G] 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;Field1_Int=4.0000E+4  &amp;lt;/span&amp;gt;       kWLm2 # [NL Field1] Intensity &lt;br /&gt;
 Field1_Tstart= 0.000000      fs    # [NL Field1] Initial Time&lt;br /&gt;
&lt;br /&gt;
the second and third input files (&amp;lt;code&amp;gt;input2.in&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;input3.in&amp;lt;/code&amp;gt;) are equivalent to the first one but with different field intensities: &amp;lt;code&amp;gt;Field1_Int=1.0000E+4&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Field1_Int=0.2500E+4&amp;lt;/code&amp;gt;/&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then you can run the three simulations with the command:&lt;br /&gt;
&lt;br /&gt;
 yambo -J input1.in -J RUN1&lt;br /&gt;
 yambo -J input2.in -J RUN2&lt;br /&gt;
 yambo -J input3.in -J RUN3&lt;br /&gt;
&lt;br /&gt;
Nota bene: these runs are long, they will take approximativelly 3 hours on a serial machine. In order to speed up them you can decrease &amp;lt;code&amp;gt;NLEnSteps=12&amp;lt;/code&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
or you can run in parallel and add two lines at the beginning of the input:&lt;br /&gt;
&lt;br /&gt;
 NL_CPU= &amp;quot;12 1&amp;quot;                    # [PARALLEL] CPUs for each role&lt;br /&gt;
 NL_ROLEs= &amp;quot;w k&amp;quot;                  # [PARALLEL] CPUs roles (w,k)&lt;br /&gt;
&lt;br /&gt;
where 12 is the number of core you want to use. The best is to use a divisor of 24 (number of energy steps).&lt;br /&gt;
&lt;br /&gt;
== Perform Fourier analysis of the polarization ==&lt;br /&gt;
When real-time simulation are terminated, we can  use &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; to analyze the real-time polarization in a way similar to the tutorial on second harmonic generation ([[Real time approach to non-linear response (SHG)]]).&amp;lt;br&amp;gt;&lt;br /&gt;
The &amp;lt;code&amp;gt;ypp_fourier.in&amp;lt;/code&amp;gt; input, generated with the commanda &amp;lt;code&amp;gt;ypp_nl -u&amp;lt;/code&amp;gt;, reads:&lt;br /&gt;
 nonlinear                        # [R] Non-linear response analysis&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;Xorder= 5  &amp;lt;/span&amp;gt;                      # 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;
 # From here onwards, it is ignored in SHG&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.000000       eV    # Damping parameter&lt;br /&gt;
&lt;br /&gt;
you can do:&lt;br /&gt;
&lt;br /&gt;
 ypp_nl -F ypp_fourier.in -J RUN1&lt;br /&gt;
 ypp_nl -F ypp_fourier.in -J RUN2 &lt;br /&gt;
 ypp_nl -F ypp_fourier.in -J RUN3&lt;br /&gt;
&lt;br /&gt;
this will produce the corresponding coefficients χ&amp;lt;sup&amp;gt;1&amp;lt;/sup&amp;gt;(ω)=P(ω)/E(ω), χ&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;(2ω)=P(2ω)/E&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;(ω), χ&amp;lt;sup&amp;gt;3&amp;lt;/sup&amp;gt;, etc.. in the file &amp;lt;code&amp;gt;o-RUN1.YPP-order &amp;lt;/code&amp;gt;...&lt;br /&gt;
&lt;br /&gt;
== Use Richardson extrapolation to extract the TPA ==&lt;br /&gt;
&lt;br /&gt;
Finally we will use the formula:&lt;br /&gt;
&lt;br /&gt;
[[File:Extrapolation.png|center|350px| extrapolation]]&lt;br /&gt;
&lt;br /&gt;
to combine the different polarization and extract the TPA coefficient. This can be done using the following script: &lt;br /&gt;
[https://www.attaccalite.com/tutorials_yambo/NLAbsorption_PP.py NLAbsorption_PP.py] &amp;lt;br&amp;gt;&lt;br /&gt;
Do not forget to set the correct file name and path in the the python script, then you can execute it with the command:&lt;br /&gt;
&lt;br /&gt;
 python3 NLAbsorption_PP.py -nr 3&lt;br /&gt;
&lt;br /&gt;
The result can be plotted using gnuplot with the script: [https://www.attaccalite.com/tutorials_yambo/plot-ip-tpa.gpi plot-ip-tpa.gpi] &lt;br /&gt;
&lt;br /&gt;
[[File:Fig-TPA-IPA-Si 24.png|center|600px|TPA_silicon_24]]&lt;br /&gt;
&lt;br /&gt;
This result was calculated with few energy steps (NLEnSteps= 24) but if you increase this number you can get a smoother result, but this will require more computational time. &lt;br /&gt;
For example in the figure below we used 481 energy steps.&lt;br /&gt;
&lt;br /&gt;
[[File:Fig-TPA-IPA-Si.png|center| 600px | tpa converged]]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;/div&gt;</summary>
		<author><name>Fulvio</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Two-photon_absorption&amp;diff=7748</id>
		<title>Two-photon absorption</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Two-photon_absorption&amp;diff=7748"/>
		<updated>2024-04-04T14:39:57Z</updated>

		<summary type="html">&lt;p&gt;Fulvio: /* Perform Fourier analysis of the polarization */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Tpa skeme.png|right|200px | tpa skeme]]&lt;br /&gt;
In this tutorial we will show how to calculate two-photon absorption(TPA) in bulk silicon, following the approach descried in Ref. &amp;lt;ref name=&amp;quot;tpa&amp;quot;&amp;gt;[https://amu.hal.science/hal-01755879/document Two-photon absorption in two-dimensional materials: The case of hexagonal boron nitride] Claudio Attaccalite, Myrta Grüning, Hakim Amara, Sylvain Latil, and François Ducastelle Phys. Rev. B &#039;&#039;&#039;98&#039;&#039;&#039;, 165126 (2018)  &amp;lt;/ref&amp;gt;. &amp;lt;br&amp;gt;In this tutorial we suppose you are already familiar with the non-linear response using the Yambo code. &amp;lt;br&amp;gt; If it is not the case please study the previous tutorials: [[Linear response using Dynamical Berry Phase]] and [[Real time approach to non-linear response (SHG)]].&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The tutorial is divided in different steps from the DFT calculation to the final TPA spectrum. For the calculation of the TPA we will use the real-time approach proposed in Ref. &amp;lt;ref name=nl&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 &#039;&#039;&#039;88&#039;&#039;&#039;, 235113(2013)&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== DFT calculations ==&lt;br /&gt;
&lt;br /&gt;
Here we provide input files for QuantumEspresso both the self-consistent calculation and the non-self-consistent: [https://www.attaccalite.com/tutorials_yambo/QE_silicon.tgz QE_silicon.tgz] &amp;lt;br&amp;gt;&lt;br /&gt;
Run them, import the wave-function in Yambo and run the setup. (see previous tutorials).&lt;br /&gt;
&lt;br /&gt;
== Removing symmetries ==&lt;br /&gt;
In this tutorial we will calculate the TPA along the &#039;x&#039; direction therefore we remove symmetries not compatible with an external field along this direction, with the command &amp;lt;code&amp;gt; ypp_nl -y&amp;lt;/code&amp;gt;: &lt;br /&gt;
&lt;br /&gt;
 fixsyms                          # [R] Remove symmetries not consistent with an &lt;br /&gt;
 external perturbation&lt;br /&gt;
 % Efield1&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;       # First external Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 % Efield2&lt;br /&gt;
  0.000000 | 0.000000 | 0.000000 |        # 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;
the you can go in the &amp;lt;code&amp;gt;FixSymm&amp;lt;/code&amp;gt; folder and run the setup again.&lt;br /&gt;
&lt;br /&gt;
== Calculations at different field intensities ==&lt;br /&gt;
&lt;br /&gt;
In order to extract the TPA coefficient we will run a series of simulation at different intensities of the external field: &#039;&#039;&#039;Ε&#039;&#039;&#039;, &#039;&#039;&#039;Ε/2&#039;&#039;&#039;, &#039;&#039;&#039;Ε/4&#039;&#039;&#039;. The polarization obtained from these simulation can be expanded in the field as:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Pols3.png|center|500px | 3 polarization]]&lt;br /&gt;
&lt;br /&gt;
then we will combine them to obtain the TPA coefficient as:&lt;br /&gt;
&lt;br /&gt;
[[File:Extrapolation.png|center|350px| extrapolation]]&lt;br /&gt;
&lt;br /&gt;
for more detail see Ref.&amp;lt;ref name=tpa&amp;gt;&amp;lt;/ref&amp;gt;. Hereafter the inputs for the real-time simulation. These inputs can be generated using the command &amp;lt;code&amp;gt;yambo -u n -V qp&amp;lt;/code&amp;gt;. The first input that we will call&amp;lt;code&amp;gt;input1.in&amp;lt;/code&amp;gt; reads:&lt;br /&gt;
 &lt;br /&gt;
 nloptics                         # [R] Non-linear spectroscopy&lt;br /&gt;
 % NLBands&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;  1 | 7 | &amp;lt;/span&amp;gt;                          # [NL] Bands range&lt;br /&gt;
 %&lt;br /&gt;
 NLverbosity= &amp;quot;low&amp;quot;               # [NL] Verbosity level (low | high)&lt;br /&gt;
 NLtime=74.000000           fs    # [NL] Simulation Time&lt;br /&gt;
 NLstep= 0.002500           fs    # [NL] Time step length&lt;br /&gt;
 NLintegrator= &amp;quot;INVINT&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;
 % NLEnRange&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;  0.200000 | 5.000000 | &amp;lt;/span&amp;gt;        eV    # [NL] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;NLEnSteps= 24  &amp;lt;/span&amp;gt;                 # [NL] Energy steps&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;NLDamping= 0.100000    &amp;lt;/span&amp;gt;    eV    # [NL] Damping (or dephasing)&lt;br /&gt;
 #EvalCurrent                   # [NL] Evaluate the current&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;    # [NL Field1] Field Versor&lt;br /&gt;
 %&lt;br /&gt;
 Field1_kind= &amp;quot;SIN&amp;quot;             # [NL Field1] Kind(SIN|SOFTSIN|RES|ANTIRES|GAUSS|DELTA|QSSIN)&lt;br /&gt;
 % GfnQP_E&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt; 0.600000 | 1.000000 | 1.000000 |   &amp;lt;/span&amp;gt;     # [EXTQP G] 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;Field1_Int=4.0000E+4  &amp;lt;/span&amp;gt;       kWLm2 # [NL Field1] Intensity &lt;br /&gt;
 Field1_Tstart= 0.000000      fs    # [NL Field1] Initial Time&lt;br /&gt;
&lt;br /&gt;
the second and third input files (&amp;lt;code&amp;gt;input2.in&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;input3.in&amp;lt;/code&amp;gt;) are equivalent to the first one but with different field intensities: &amp;lt;code&amp;gt;Field1_Int=1.0000E+4&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;Field1_Int=0.2500E+4&amp;lt;/code&amp;gt;/&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then you can run the three simulations with the command:&lt;br /&gt;
&lt;br /&gt;
 yambo -J input1.in -J RUN1&lt;br /&gt;
 yambo -J input2.in -J RUN2&lt;br /&gt;
 yambo -J input3.in -J RUN3&lt;br /&gt;
&lt;br /&gt;
Nota bene: these runs are long, they will take approximativelly 3 hours on a serial machine. In order to speed up them you can decrease &amp;lt;code&amp;gt;NLEnSteps=12&amp;lt;/code&amp;gt; &amp;lt;br&amp;gt;&lt;br /&gt;
or you can run in parallel and add two lines at the beginning of the input:&lt;br /&gt;
&lt;br /&gt;
 NL_CPU= &amp;quot;12 1&amp;quot;                    # [PARALLEL] CPUs for each role&lt;br /&gt;
 NL_ROLEs= &amp;quot;w k&amp;quot;                  # [PARALLEL] CPUs roles (w,k)&lt;br /&gt;
&lt;br /&gt;
where 12 is the number of core you want to use. The best is to use a divisor of 24 (number of energy steps).&lt;br /&gt;
&lt;br /&gt;
== Perform Fourier analysis of the polarization ==&lt;br /&gt;
When real-time simulation are terminated, we can  use &amp;lt;code&amp;gt;ypp_nl&amp;lt;/code&amp;gt; to analyze the real-time polarization &amp;lt;br&amp;gt;&lt;br /&gt;
in a way similar to the tutorial on second harmonic generation ([[Real time approach to non-linear response (SHG)]]).&amp;lt;br&amp;gt;&lt;br /&gt;
The &amp;lt;code&amp;gt;ypp_fourier.in&amp;lt;/code&amp;gt; input, generated with the commanda &amp;lt;code&amp;gt;ypp_nl -u&amp;lt;/code&amp;gt;, reads:&lt;br /&gt;
 nonlinear                        # [R] Non-linear response analysis&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;Xorder= 5  &amp;lt;/span&amp;gt;                      # 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;
 # From here onwards, it is ignored in SHG&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.000000       eV    # Damping parameter&lt;br /&gt;
&lt;br /&gt;
you can do:&lt;br /&gt;
&lt;br /&gt;
 ypp_nl -F ypp_fourier.in -J RUN1&lt;br /&gt;
 ypp_nl -F ypp_fourier.in -J RUN2 &lt;br /&gt;
 ypp_nl -F ypp_fourier.in -J RUN3&lt;br /&gt;
&lt;br /&gt;
this will produce the corresponding coefficients χ&amp;lt;sup&amp;gt;1&amp;lt;/sup&amp;gt;(ω)=P(ω)/E(ω), χ&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;(2ω)=P(2ω)/E&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt;(ω), χ&amp;lt;sup&amp;gt;3&amp;lt;/sup&amp;gt;, etc.. in the file &amp;lt;code&amp;gt;o-RUN1.YPP-order &amp;lt;/code&amp;gt;...&lt;br /&gt;
&lt;br /&gt;
== Use Richardson extrapolation to extract the TPA ==&lt;br /&gt;
&lt;br /&gt;
Finally we will use the formula:&lt;br /&gt;
&lt;br /&gt;
[[File:Extrapolation.png|center|350px| extrapolation]]&lt;br /&gt;
&lt;br /&gt;
to combine the different polarization and extract the TPA coefficient. This can be done using the following script: &lt;br /&gt;
[https://www.attaccalite.com/tutorials_yambo/NLAbsorption_PP.py NLAbsorption_PP.py] &amp;lt;br&amp;gt;&lt;br /&gt;
Do not forget to set the correct file name and path in the the python script, then you can execute it with the command:&lt;br /&gt;
&lt;br /&gt;
 python3 NLAbsorption_PP.py -nr 3&lt;br /&gt;
&lt;br /&gt;
The result can be plotted using gnuplot with the script: [https://www.attaccalite.com/tutorials_yambo/plot-ip-tpa.gpi plot-ip-tpa.gpi] &lt;br /&gt;
&lt;br /&gt;
[[File:Fig-TPA-IPA-Si 24.png|center|600px|TPA_silicon_24]]&lt;br /&gt;
&lt;br /&gt;
This result was calculated with few energy steps (NLEnSteps= 24) but if you increase this number you can get a smoother result, but this will require more computational time. &lt;br /&gt;
For example in the figure below we used 481 energy steps.&lt;br /&gt;
&lt;br /&gt;
[[File:Fig-TPA-IPA-Si.png|center| 600px | tpa converged]]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;/div&gt;</summary>
		<author><name>Fulvio</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_band_structures&amp;diff=7632</id>
		<title>Yambopy tutorial: band structures</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_band_structures&amp;diff=7632"/>
		<updated>2024-02-21T14:08:14Z</updated>

		<summary type="html">&lt;p&gt;Fulvio: /* Tutorial 3: GW bands */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
This tutorial will show you how to visualise wave-function and band-structure related information, such as atomic, orbital and spin projections, following a DFT Quantum Espresso calculation using the &amp;quot;qepy&amp;quot; module of Yambopy. It also contains a section about Yambo and GW band structures.&lt;br /&gt;
&lt;br /&gt;
The full tutorial, including the Quantum espresso and Yambo databases that we will read, can be downloaded and extracted from the yambo website:&lt;br /&gt;
 $wget https://media.yambo-code.eu/educational/tutorials/files/databases_qepy.tar.gz&lt;br /&gt;
 $tar -xvzf databases_qepy.tar.gz&lt;br /&gt;
 $cd databases_qepy&lt;br /&gt;
&lt;br /&gt;
==Tutorial 1. BN (semiconductor). Band structure==&lt;br /&gt;
&lt;br /&gt;
First enter in the folder &lt;br /&gt;
 cd databases_qepy/bn-semiconductor&lt;br /&gt;
and have a look to the &lt;br /&gt;
 vim plot-qe-bands.py&lt;br /&gt;
The qepy classes are useful both to execute Quantum Espresso and to analyze the results. Enter in the python environment, by typing &amp;lt;code&amp;gt;python&amp;lt;/code&amp;gt;, then the full qepy library is imported by simply doing:&lt;br /&gt;
&lt;br /&gt;
 from qepy import *&lt;br /&gt;
&lt;br /&gt;
===Plot Band structure===&lt;br /&gt;
&lt;br /&gt;
The qepy class &#039;&#039;&#039;PwXML&#039;&#039;&#039; reads the data file generated by Quantum Espresso and post-processes the data. The class is instanced by doing:&lt;br /&gt;
&lt;br /&gt;
 xml = PwXML(prefix=&#039;bn&#039;, path=&#039;bands&#039;)&lt;br /&gt;
&lt;br /&gt;
The variable prefix corresponds to the same variable of the QE input. The folder location is indicated by variable path. In order to plot the bands, we also define the k-points path (in crystal coordinates) using the function Path:&lt;br /&gt;
&lt;br /&gt;
 npoints = 50&lt;br /&gt;
 path_kpoints = Path([ [[0.0, 0.0, 0.0],&#039;$\Gamma$&#039;],&lt;br /&gt;
                       [[0.5, 0.0, 0.0],&#039;M&#039;],&lt;br /&gt;
                       [[1./3,1./3,0.0],&#039;K&#039;],&lt;br /&gt;
                       [[0.0, 0.0, 0.0],&#039;$\Gamma$&#039;]], [int(npoints*2),int(npoints),int(sqrt(5)*npoints)])&lt;br /&gt;
&lt;br /&gt;
It is worth to note that the path should coincide with the selected path for the QE band calculations.&lt;br /&gt;
&lt;br /&gt;
In order to show the plot we call the &#039;&#039;&#039;plot_eigen&#039;&#039;&#039; method of the &#039;&#039;&#039;PwXML&#039;&#039;&#039; class:&lt;br /&gt;
&lt;br /&gt;
 xml.plot_eigen(path_kpoints)&lt;br /&gt;
&lt;br /&gt;
This function will automatically plot the bands as shown below running the script:&lt;br /&gt;
&lt;br /&gt;
 python plot-qe-bands.py&lt;br /&gt;
&lt;br /&gt;
[[File:Bands BN 1.png| 400 px | center |Band structure of BN calculated at the level of DFT-LDA]]&lt;br /&gt;
&lt;br /&gt;
Alternatively, we can use the function &#039;&#039;&#039;plot_eigen_ax&#039;&#039;&#039;. This functions requires as input a matplotlib &#039;&#039;&#039;figure&#039;&#039;&#039; object with given axes, as you will see in the next example.&lt;br /&gt;
&lt;br /&gt;
===Plot atomic orbital projected Band structure===&lt;br /&gt;
&lt;br /&gt;
In addition to the band structure, useful information regarding the atomic orbital nature of the electronic wave functions can be displayed using the class &#039;&#039;&#039;ProjwfcXML&#039;&#039;&#039;. &lt;br /&gt;
In order to make quantum espresso calculate the relevant data, we need to use the QE executable &#039;&#039;&#039;projwfc.x&#039;&#039;&#039;, which will create the file &#039;&#039;&#039;atomic_proj.xml&#039;&#039;&#039;. This executable projects the Kohn-Sham wavefunctions onto orthogonalized atomic orbitals, among others functionalities. The orbital indexing  and ordering are explained in the input documentation of the projwfc.x function which you are invited to check (https://www.quantum-espresso.org/Doc/INPUT_PROJWFC.html#idm94). We can run &#039;&#039;&#039;projwf.x&#039;&#039;&#039; directly from the python script using the qepy class &#039;&#039;&#039;ProjwfcIn&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
 proj = ProjwfcIn(prefix=&#039;bn&#039;)&lt;br /&gt;
 proj.run(folder=&#039;bands&#039;)&lt;br /&gt;
&lt;br /&gt;
Be aware that this can take a while in a large system with many k-points. As in the class &#039;&#039;&#039;PwXML&#039;&#039;&#039;, we then define the path_kpoints and also the selected atomic orbitals to project our bands. We have chosen to represent the projection weight onto the nitrogen (1) and boron (2) orbitals, which according to the projection orderings is given by&lt;br /&gt;
&lt;br /&gt;
 atom_1 = list(range(16))&lt;br /&gt;
 atom_2 = list(range(16,32)) &lt;br /&gt;
&lt;br /&gt;
The full list of orbitals is written in the file &#039;&#039;&#039;bands/prowfc.log&#039;&#039;&#039;. We have also defined the figure box&lt;br /&gt;
&lt;br /&gt;
 import matplotlib.pyplot as plt&lt;br /&gt;
 fig = plt.figure(figsize=(5,7))&lt;br /&gt;
 ax  = fig.add_axes( [ 0.12, 0.10, 0.70, 0.80 ])&lt;br /&gt;
&lt;br /&gt;
The class &#039;&#039;&#039;ProjwfcXML&#039;&#039;&#039; then runs as in this example:&lt;br /&gt;
&lt;br /&gt;
 band = ProjwfcXML(prefix=&#039;bn&#039;,path=&#039;bands&#039;,qe_version=&#039;7.0&#039;)&lt;br /&gt;
 band.plot_eigen(ax,path_kpoints=path_kpoints,cmap=&#039;viridis&#039;,selected_orbitals=atom_1,selected_orbitals_2=atom_2)&lt;br /&gt;
&lt;br /&gt;
We can run now the file:&lt;br /&gt;
&lt;br /&gt;
 python plot-qe-orbitals.py&lt;br /&gt;
&lt;br /&gt;
[[File:Bands AOP BN 1.png| 400 px | center | Atomic orbital projected band structure of monolayer BN]]&lt;br /&gt;
&lt;br /&gt;
We have chosen the colormap &#039;viridis&#039; (variable cmap). You see that the colormap goes from maximum &#039;&#039;&#039;selected_orbitals&#039;&#039;&#039; content (in this case nitrogen) to the maximum &#039;&#039;&#039;selected_orbitals_2&#039;&#039;&#039; content (in this case boron). &lt;br /&gt;
The colormap can be represented in many ways and qepy does not include a particular function for this. An example is:&lt;br /&gt;
&lt;br /&gt;
 import matplotlib as mpl&lt;br /&gt;
 cmap=plt.get_cmap(&#039;viridis&#039;)&lt;br /&gt;
 bx  = fig.add_axes( [ 0.88, 0.10, 0.05, 0.80 ])&lt;br /&gt;
 norm = mpl.colors.Normalize(vmin=0.,vmax=1.)&lt;br /&gt;
 cb1 = mpl.colorbar.ColorbarBase(bx, cmap=cmap, norm=norm,orientation=&#039;vertical&#039;,ticks=[0,1])&lt;br /&gt;
 cb1.set_ticklabels([&#039;B&#039;, &#039;N&#039;])&lt;br /&gt;
&lt;br /&gt;
We can also plot the band orbital charater with size variation instead of a color scale. In this case we have to pass only the variable selected_orbitals (see the next tutorial).&lt;br /&gt;
&lt;br /&gt;
==Tutorial 2. Iron. Ferromagnetic metalic material==&lt;br /&gt;
&lt;br /&gt;
In the case of spin-polarized calculations we can plot the spin up and down band structures. We have included in the tutorial a small workflow example to run quantum espresso calculations from scratch. This is done using the classes Tasks and Flows developed in yambopy. You can check the file flow-iron.py for an example. &lt;br /&gt;
Yambopy includes basic predefined workflows to run the common QE and Yambo calculations. In this case we are using the class &#039;&#039;&#039;PwBandsTasks&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
 python flow-iron.py&lt;br /&gt;
&lt;br /&gt;
In order to plot the spin-polarized bands. After doing all the calculations from scratch with the flows (flow-iron.py), we can make the band plot by running the script:&lt;br /&gt;
&lt;br /&gt;
 python plot-qe-bands.py&lt;br /&gt;
&lt;br /&gt;
The class PwXML automatically detects the spin polarized case (nspin=2 in the QE input file). The spin up channel is displayed with red and the spin down channel with blue. In the case of iron we have selected this k-point path:&lt;br /&gt;
&lt;br /&gt;
 npoints = 50&lt;br /&gt;
 path_kpoints = Path([ [[0.0, 0.0, 0.0 ],&#039;G&#039;],&lt;br /&gt;
                       [[0.0, 0.0, 1.0 ],&#039;H&#039;],&lt;br /&gt;
                       [[1./2,0.0,1./2.],&#039;N&#039;],&lt;br /&gt;
                       [[0.0, 0.0, 0.0 ],&#039;G&#039;],&lt;br /&gt;
                       [[1./2, 1./2, 1./2 ],&#039;P&#039;],&lt;br /&gt;
                       [[1./2,0.0,1./2. ],&#039;N&#039;]], [npoints,npoints,npoints,npoints,npoints])&lt;br /&gt;
&lt;br /&gt;
 xml = PwXML(prefix=&#039;pw&#039;,path=&#039;bands/t0&#039;)&lt;br /&gt;
 xml.plot_eigen(path_kpoints)&lt;br /&gt;
&lt;br /&gt;
[[File:Figure 3-iron-bands.png| 600 px | center |Spin polarized band structure of iron calculated by DFT]]&lt;br /&gt;
&lt;br /&gt;
The analysis of the projected atomic orbitals is also implemented. In this case the results are more cumbersome because the projection is separated in spin up and down channels.&amp;lt;br&amp;gt; &lt;br /&gt;
Let us look first at the file &#039;&#039;&#039;plot-qe-orbitals-size&#039;&#039;&#039;. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NB: If you generated the quantum espresso databases using the flows instead of relying on the precomputed databases, you also need to rerun the quantum espresso executable projwfc.x to recompute the orbital projections. In this case, please uncomment the following lines in the script&#039;&#039;&#039; (plot-qe-orbitals-size.py) :&lt;br /&gt;
 #proj = ProjwfcIn(prefix=&#039;pw&#039;)&lt;br /&gt;
 #proj.run(folder=&#039;bands/t0&#039;)&lt;br /&gt;
&lt;br /&gt;
Now, we can use the dot size as a function of the weight of the orbitals&lt;br /&gt;
 atom_s = [8]&lt;br /&gt;
 atom_p = [0,1,2]&lt;br /&gt;
 atom_d = [3,4,5,6,7]&lt;br /&gt;
&lt;br /&gt;
and the plots are done with&lt;br /&gt;
 band = ProjwfcXML(prefix=&#039;pw&#039;,path=&#039;bands/t0&#039;,qe_version=&#039;7.0&#039;)&lt;br /&gt;
 band.plot_eigen(ax,path_kpoints=path_kpoints,&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;selected_orbitals=atom_s,&amp;lt;/span&amp;gt;color=&#039;pink&#039;,color_2=&#039;black&#039;)&lt;br /&gt;
 band.plot_eigen(ax,path_kpoints=path_kpoints,&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;selected_orbitals=atom_p,&amp;lt;/span&amp;gt;color=&#039;green&#039;,color_2=&#039;orange&#039;)&lt;br /&gt;
 band.plot_eigen(ax,path_kpoints=path_kpoints,&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;selected_orbitals=atom_d,&amp;lt;/span&amp;gt;color=&#039;red&#039;,color_2=&#039;blue&#039;)&lt;br /&gt;
&lt;br /&gt;
As an example, we can select just the &#039;&#039;d&#039;&#039; orbitals by commenting the first two plots and then running the file:&lt;br /&gt;
&lt;br /&gt;
 plot-qe-orbitals-size.py&lt;br /&gt;
&lt;br /&gt;
[[File:Figure 4-iron-bands-size-d-orbitals.png|400px|center|Iron band structure. Size is proportional to the weights of the projection on atomic d-orbitals. Red (blue) is up (down) spin polarization.]]&lt;br /&gt;
&lt;br /&gt;
From the plot is clear that &#039;&#039;d&#039;&#039; orbitals are mainly localized around the Fermi energy. The plot above is in red and blue, while the default choice in your script should be pink and black. You can experiment with the colors and other &#039;&#039;matplotlib&#039;&#039; plot options and also plot the other orbital types.&lt;br /&gt;
&lt;br /&gt;
Another option is to plot the orbital composition as a colormap running the file:&lt;br /&gt;
&lt;br /&gt;
 plot-qe-orbitals-colormap.py&lt;br /&gt;
&lt;br /&gt;
[[File:Figure 5-iron-bands-colormap.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
Here we have added the p and d orbitals in the analysis:&lt;br /&gt;
&lt;br /&gt;
 atom_p = [0,1,2]&lt;br /&gt;
 atom_d = [3,4,5,6,7]&lt;br /&gt;
 band = ProjwfcXML(prefix=&#039;pw&#039;,path=&#039;bands/t0&#039;,qe_version=&#039;7.0&#039;)&lt;br /&gt;
 band.plot_eigen(ax,path_kpoints=path_kpoints,cmap=&#039;viridis&#039;,cmap2=&#039;rainbow&#039;,selected_orbitals=atom_p,selected_orbitals_2=atom_d)&lt;br /&gt;
&lt;br /&gt;
The colormap bar is added in the same way as in Tutorial 1 (see script), but this time we have a different colormap for each spin polarisation.&lt;br /&gt;
&lt;br /&gt;
==Tutorial 3: GW bands==&lt;br /&gt;
&lt;br /&gt;
Yambopy can be used either to run Yambo and QE calculations, or to analyse the results of QE and Yambo by dealing with their generated databases. This is done with a variety of classes included in the qepy (for QE) or yambopy (for Yambo) modules. &lt;br /&gt;
In the case of Yambo GW quasi-particle calculations, we can use the yambopy class &#039;&#039;&#039;YamboQPDB&#039;&#039;&#039; to read the database produced by the simulation.&lt;br /&gt;
Enter in the folder&lt;br /&gt;
 cd ../gw-bands&lt;br /&gt;
We can use this to find the scissor operator, plot the GW bands and to interpolate the GW bands on a smoother k-path. The example runs by typing:&lt;br /&gt;
&lt;br /&gt;
 python plot-qp.py&lt;br /&gt;
&lt;br /&gt;
See below for an explanation of the tutorial. As usual, we can import the qepy and yambopy libraries:&lt;br /&gt;
&lt;br /&gt;
  from qepy import *&lt;br /&gt;
  from yambopy import *&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
&lt;br /&gt;
We define the k-points path.&lt;br /&gt;
  npoints = 10&lt;br /&gt;
  path = Path([ [[  0.0,  0.0,  0.0],&#039;$\Gamma$&#039;],&lt;br /&gt;
                [[  0.5,  0.0,  0.0],&#039;M&#039;],&lt;br /&gt;
                [[1./3.,1./3.,  0.0],&#039;K&#039;],&lt;br /&gt;
                [[  0.0,  0.0,  0.0],&#039;$\Gamma$&#039;]], [int(npoints*2),int(npoints),int(sqrt(5)*npoints)] )&lt;br /&gt;
&lt;br /&gt;
Importantly, the number of points is a free choice. We can increase the variable npoints as we wish, it just means that the interpolation step will take more time. In order to analyse GW results we need to have the file related to the basic data of our Yambo calculation (&#039;&#039;&#039;SAVE/ns.db1&#039;&#039;&#039;) and the netcdf file with the quasi-particle results (&#039;&#039;&#039;ndb.QP&#039;&#039;&#039;). We load the data calling the respective classes:&lt;br /&gt;
&lt;br /&gt;
 # Read Lattice information from SAVE&lt;br /&gt;
 lat  = YamboSaveDB.from_db_file(folder=&#039;SAVE&#039;,filename=&#039;ns.db1&#039;)&lt;br /&gt;
 # Read QP database&lt;br /&gt;
 ydb  = YamboQPDB.from_db(filename=&#039;ndb.QP&#039;,folder=&#039;qp-gw&#039;)&lt;br /&gt;
(in the yambopy module, each class is specialised to read a specific Yambo database)&lt;br /&gt;
&lt;br /&gt;
The first option is to plot the energies and calculate the ideal Kohn-Sham to GW scissor operator. We need to select the index of the top valence band:&lt;br /&gt;
&lt;br /&gt;
 n_top_vb = 4&lt;br /&gt;
 ydb.plot_scissor_ax(ax,n_top_vb)&lt;br /&gt;
&lt;br /&gt;
Yambopy displays the fitting and also the data of the slope of each fitting. Notice that this is also a test if the GW calculations are running well. &#039;&#039;&#039;If the dependence is not linear you should double-check your results!&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[[File:Figure 6-slope-scissor.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
In this case the slope is:&lt;br /&gt;
&lt;br /&gt;
 valence bands:&lt;br /&gt;
 slope:     1.0515886598785766&lt;br /&gt;
 conduction bands:&lt;br /&gt;
 slope:     1.026524081134514&lt;br /&gt;
 scissor list (shift,c,v) [eV,adim,adim]: [1.8985204833551723, 1.026524081134514, 1.0515886598785766]&lt;br /&gt;
&lt;br /&gt;
In addition to the scissor operator, we can plot the GW (and DFT) band structure along the path. The first choice would be to plot the actual GW calculations, without interpolation, to check that the results are meaningful (or not). This plot is independent of the number of k-points (&#039;&#039;&#039;npoints&#039;&#039;&#039;) that we want to put in the interpolation. The class YamboQPDB finds the calculated points that belong to the path and plots them. Be aware that if we use coarse grids the class would not find any point and the function will not work.&lt;br /&gt;
&lt;br /&gt;
 ks_bs_0, qp_bs_0 = ydb.get_bs_path(lat,path)&lt;br /&gt;
 ks_bs_0.plot_ax(ax,legend=True,c_bands=&#039;r&#039;,label=&#039;KS&#039;)&lt;br /&gt;
 qp_bs_0.plot_ax(ax,legend=True,c_bands=&#039;b&#039;,label=&#039;QP-GW&#039;)&lt;br /&gt;
&lt;br /&gt;
[[File:Figure 7-GW-band-structure-non-interpolated.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
The interpolation of the DFT and GW band structures looks similar:&lt;br /&gt;
&lt;br /&gt;
 ks_bs, qp_bs = ydb.interpolate(lat,path,what=&#039;QP+KS&#039;,lpratio=20)&lt;br /&gt;
 ks_bs.plot_ax(ax,legend=True,c_bands=&#039;r&#039;,label=&#039;KS&#039;)&lt;br /&gt;
 qp_bs.plot_ax(ax,legend=True,c_bands=&#039;b&#039;,label=&#039;QP-GW&#039;)&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;lpratio&#039;&#039;&#039; can be increased if the interpolation does not work as well as intended. The interpolation is the same one implemented in abipy and currently requires abipy installed in order to work.&lt;br /&gt;
&lt;br /&gt;
[[File:Figure 8-GW-band-structure-interpolated.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
Finally, we can compare the calculated GW eigenvalues with the interpolation.&lt;br /&gt;
&lt;br /&gt;
[[File:Figure 8-GW-band-structure-comparison.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
==Links==&lt;br /&gt;
* Back to [[Rome 2023#Tutorials]]&lt;br /&gt;
* Back to [[ICTP 2022#Tutorials]]&lt;/div&gt;</summary>
		<author><name>Fulvio</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=First_steps_in_Yambopy&amp;diff=7624</id>
		<title>First steps in Yambopy</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=First_steps_in_Yambopy&amp;diff=7624"/>
		<updated>2024-02-07T14:05:48Z</updated>

		<summary type="html">&lt;p&gt;Fulvio: /* Tutorials */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The yambopy project aims to develop python tools to: &lt;br /&gt;
&lt;br /&gt;
* Read and edit yambo and quantum espresso input files&lt;br /&gt;
* Easily perform pre- and post-processing of the simulation data for these two codes - including hard-to-get, database-encoded data beyond standard outputs&lt;br /&gt;
* Provide easy visualization and plotting options &lt;br /&gt;
* Set up simple automatization workflows (e.g., convergence tests)&lt;br /&gt;
&lt;br /&gt;
=== Setup ===&lt;br /&gt;
First of all, make sure that you have a suitable python environment (crated for example with [https://docs.conda.io/projects/miniconda/en/latest/| conda] or [https://docs.python.org/3/library/venv.html| venv]) with python &amp;gt;=3.8.&lt;br /&gt;
&lt;br /&gt;
Then, you may install yambopy in one of the following ways.&lt;br /&gt;
&lt;br /&gt;
==== Quick installation from PyPI repository ====&lt;br /&gt;
&lt;br /&gt;
* In order to quickly install the officially released version type:&lt;br /&gt;
&lt;br /&gt;
 pip install yambopy&lt;br /&gt;
&lt;br /&gt;
==== Installation from tarball ====&lt;br /&gt;
&lt;br /&gt;
* In case you don&#039;t want to download from the pip repository and prefer to install a version of yambopy locally, you may download the appropriate tarball from the [https://github.com/yambo-code/yambopy/releases| yambopy github page]. Extract the tarball, enter the yambopy folder and type &amp;lt;code&amp;gt;pip install .&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Installation of latest patch ====&lt;br /&gt;
&lt;br /&gt;
* In case you want the latest version of the code including new updates and patches that might not be present in the official version, then you can clone the yambopy git repository (a basic knowledge of git may be helpful):&lt;br /&gt;
&lt;br /&gt;
 git clone https://github.com/yambo-code/yambopy.git&lt;br /&gt;
 cd yambopy&lt;br /&gt;
 pip install .&lt;br /&gt;
&lt;br /&gt;
==== Dependencies ====&lt;br /&gt;
&lt;br /&gt;
* In principle, &amp;lt;code&amp;gt;pip&amp;lt;/code&amp;gt; should take care of the required python dependencies. They are &amp;lt;code&amp;gt;numpy&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;scipy&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;matplotlib&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;netCDF4&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;lxml&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;PyYAML&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;monty&amp;lt;/code&amp;gt;. In case some dependency-related problem arises, you can install each of them separately beforehand with:&lt;br /&gt;
&lt;br /&gt;
 pip install &amp;lt;code&amp;gt;dependency-name&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Tutorials ===&lt;br /&gt;
Now yambopy is ready to use! Just go to the tutorials folder and follow the docs!&lt;br /&gt;
&lt;br /&gt;
 cd tutorial/&lt;br /&gt;
&lt;br /&gt;
On this wiki, we provide steps for the following tutorials:&lt;br /&gt;
* [[GW tutorial. Convergence and approximations (BN)]]&lt;br /&gt;
* [[Bethe-Salpeter equation tutorial. Optical absorption (BN)]]&lt;br /&gt;
* [[Yambopy tutorial: band structures | Database and plotting tutorial for quantum espresso: qepy]] (Get the databases: [https://media.yambo-code.eu/educational/tutorials/files/databases_qepy.tar.gz databases_qepy], 46.5MB)&lt;br /&gt;
* [[Yambopy tutorial: Yambo databases | Database and plotting tutorial for yambo: yambopy ]] (Get the databases: [https://media.yambo-code.eu/educational/tutorials/files/databases_yambopy.tar.gz databases_yambopy], 129MB)&lt;br /&gt;
* [[Phonon-assisted luminescence by finite atomic displacements]]&lt;/div&gt;</summary>
		<author><name>Fulvio</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_band_structures&amp;diff=7623</id>
		<title>Yambopy tutorial: band structures</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_band_structures&amp;diff=7623"/>
		<updated>2024-02-07T14:04:09Z</updated>

		<summary type="html">&lt;p&gt;Fulvio: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
This tutorial will show you how to visualise wave-function and band-structure related information, such as atomic, orbital and spin projections, following a DFT Quantum Espresso calculation using the &amp;quot;qepy&amp;quot; module of Yambopy. It also contains a section about Yambo and GW band structures.&lt;br /&gt;
&lt;br /&gt;
The full tutorial, including the Quantum espresso and Yambo databases that we will read, can be downloaded and extracted from the yambo website:&lt;br /&gt;
 $wget https://media.yambo-code.eu/educational/tutorials/files/databases_qepy.tar.gz&lt;br /&gt;
 $tar -xvzf databases_qepy.tar.gz&lt;br /&gt;
 $cd databases_qepy&lt;br /&gt;
&lt;br /&gt;
==Tutorial 1. BN (semiconductor). Band structure==&lt;br /&gt;
&lt;br /&gt;
First enter in the folder &lt;br /&gt;
 cd databases_qepy/bn-semiconductor&lt;br /&gt;
and have a look to the &lt;br /&gt;
 vim plot-qe-bands.py&lt;br /&gt;
The qepy classes are useful both to execute Quantum Espresso and to analyze the results. Enter in the python environment, by typing &amp;lt;code&amp;gt;python&amp;lt;/code&amp;gt;, then the full qepy library is imported by simply doing:&lt;br /&gt;
&lt;br /&gt;
 from qepy import *&lt;br /&gt;
&lt;br /&gt;
===Plot Band structure===&lt;br /&gt;
&lt;br /&gt;
The qepy class &#039;&#039;&#039;PwXML&#039;&#039;&#039; reads the data file generated by Quantum Espresso and post-processes the data. The class is instanced by doing:&lt;br /&gt;
&lt;br /&gt;
 xml = PwXML(prefix=&#039;bn&#039;, path=&#039;bands&#039;)&lt;br /&gt;
&lt;br /&gt;
The variable prefix corresponds to the same variable of the QE input. The folder location is indicated by variable path. In order to plot the bands, we also define the k-points path (in crystal coordinates) using the function Path:&lt;br /&gt;
&lt;br /&gt;
 npoints = 50&lt;br /&gt;
 path_kpoints = Path([ [[0.0, 0.0, 0.0],&#039;$\Gamma$&#039;],&lt;br /&gt;
                       [[0.5, 0.0, 0.0],&#039;M&#039;],&lt;br /&gt;
                       [[1./3,1./3,0.0],&#039;K&#039;],&lt;br /&gt;
                       [[0.0, 0.0, 0.0],&#039;$\Gamma$&#039;]], [int(npoints*2),int(npoints),int(sqrt(5)*npoints)])&lt;br /&gt;
&lt;br /&gt;
It is worth to note that the path should coincide with the selected path for the QE band calculations.&lt;br /&gt;
&lt;br /&gt;
In order to show the plot we call the &#039;&#039;&#039;plot_eigen&#039;&#039;&#039; method of the &#039;&#039;&#039;PwXML&#039;&#039;&#039; class:&lt;br /&gt;
&lt;br /&gt;
 xml.plot_eigen(path_kpoints)&lt;br /&gt;
&lt;br /&gt;
This function will automatically plot the bands as shown below running the script:&lt;br /&gt;
&lt;br /&gt;
 python plot-qe-bands.py&lt;br /&gt;
&lt;br /&gt;
[[File:Bands BN 1.png| 400 px | center |Band structure of BN calculated at the level of DFT-LDA]]&lt;br /&gt;
&lt;br /&gt;
Alternatively, we can use the function &#039;&#039;&#039;plot_eigen_ax&#039;&#039;&#039;. This functions requires as input a matplotlib &#039;&#039;&#039;figure&#039;&#039;&#039; object with given axes, as you will see in the next example.&lt;br /&gt;
&lt;br /&gt;
===Plot atomic orbital projected Band structure===&lt;br /&gt;
&lt;br /&gt;
In addition to the band structure, useful information regarding the atomic orbital nature of the electronic wave functions can be displayed using the class &#039;&#039;&#039;ProjwfcXML&#039;&#039;&#039;. &lt;br /&gt;
In order to make quantum espresso calculate the relevant data, we need to use the QE executable &#039;&#039;&#039;projwfc.x&#039;&#039;&#039;, which will create the file &#039;&#039;&#039;atomic_proj.xml&#039;&#039;&#039;. This executable projects the Kohn-Sham wavefunctions onto orthogonalized atomic orbitals, among others functionalities. The orbital indexing  and ordering are explained in the input documentation of the projwfc.x function which you are invited to check (https://www.quantum-espresso.org/Doc/INPUT_PROJWFC.html#idm94). We can run &#039;&#039;&#039;projwf.x&#039;&#039;&#039; directly from the python script using the qepy class &#039;&#039;&#039;ProjwfcIn&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
 proj = ProjwfcIn(prefix=&#039;bn&#039;)&lt;br /&gt;
 proj.run(folder=&#039;bands&#039;)&lt;br /&gt;
&lt;br /&gt;
Be aware that this can take a while in a large system with many k-points. As in the class &#039;&#039;&#039;PwXML&#039;&#039;&#039;, we then define the path_kpoints and also the selected atomic orbitals to project our bands. We have chosen to represent the projection weight onto the nitrogen (1) and boron (2) orbitals, which according to the projection orderings is given by&lt;br /&gt;
&lt;br /&gt;
 atom_1 = list(range(16))&lt;br /&gt;
 atom_2 = list(range(16,32)) &lt;br /&gt;
&lt;br /&gt;
The full list of orbitals is written in the file &#039;&#039;&#039;bands/prowfc.log&#039;&#039;&#039;. We have also defined the figure box&lt;br /&gt;
&lt;br /&gt;
 import matplotlib.pyplot as plt&lt;br /&gt;
 fig = plt.figure(figsize=(5,7))&lt;br /&gt;
 ax  = fig.add_axes( [ 0.12, 0.10, 0.70, 0.80 ])&lt;br /&gt;
&lt;br /&gt;
The class &#039;&#039;&#039;ProjwfcXML&#039;&#039;&#039; then runs as in this example:&lt;br /&gt;
&lt;br /&gt;
 band = ProjwfcXML(prefix=&#039;bn&#039;,path=&#039;bands&#039;,qe_version=&#039;7.0&#039;)&lt;br /&gt;
 band.plot_eigen(ax,path_kpoints=path_kpoints,cmap=&#039;viridis&#039;,selected_orbitals=atom_1,selected_orbitals_2=atom_2)&lt;br /&gt;
&lt;br /&gt;
We can run now the file:&lt;br /&gt;
&lt;br /&gt;
 python plot-qe-orbitals.py&lt;br /&gt;
&lt;br /&gt;
[[File:Bands AOP BN 1.png| 400 px | center | Atomic orbital projected band structure of monolayer BN]]&lt;br /&gt;
&lt;br /&gt;
We have chosen the colormap &#039;viridis&#039; (variable cmap). You see that the colormap goes from maximum &#039;&#039;&#039;selected_orbitals&#039;&#039;&#039; content (in this case nitrogen) to the maximum &#039;&#039;&#039;selected_orbitals_2&#039;&#039;&#039; content (in this case boron). &lt;br /&gt;
The colormap can be represented in many ways and qepy does not include a particular function for this. An example is:&lt;br /&gt;
&lt;br /&gt;
 import matplotlib as mpl&lt;br /&gt;
 cmap=plt.get_cmap(&#039;viridis&#039;)&lt;br /&gt;
 bx  = fig.add_axes( [ 0.88, 0.10, 0.05, 0.80 ])&lt;br /&gt;
 norm = mpl.colors.Normalize(vmin=0.,vmax=1.)&lt;br /&gt;
 cb1 = mpl.colorbar.ColorbarBase(bx, cmap=cmap, norm=norm,orientation=&#039;vertical&#039;,ticks=[0,1])&lt;br /&gt;
 cb1.set_ticklabels([&#039;B&#039;, &#039;N&#039;])&lt;br /&gt;
&lt;br /&gt;
We can also plot the band orbital charater with size variation instead of a color scale. In this case we have to pass only the variable selected_orbitals (see the next tutorial).&lt;br /&gt;
&lt;br /&gt;
==Tutorial 2. Iron. Ferromagnetic metalic material==&lt;br /&gt;
&lt;br /&gt;
In the case of spin-polarized calculations we can plot the spin up and down band structures. We have included in the tutorial a small workflow example to run quantum espresso calculations from scratch. This is done using the classes Tasks and Flows developed in yambopy. You can check the file flow-iron.py for an example. &lt;br /&gt;
Yambopy includes basic predefined workflows to run the common QE and Yambo calculations. In this case we are using the class &#039;&#039;&#039;PwBandsTasks&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
 python flow-iron.py&lt;br /&gt;
&lt;br /&gt;
In order to plot the spin-polarized bands. After doing all the calculations from scratch with the flows (flow-iron.py), we can make the band plot by running the script:&lt;br /&gt;
&lt;br /&gt;
 python plot-qe-bands.py&lt;br /&gt;
&lt;br /&gt;
The class PwXML automatically detects the spin polarized case (nspin=2 in the QE input file). The spin up channel is displayed with red and the spin down channel with blue. In the case of iron we have selected this k-point path:&lt;br /&gt;
&lt;br /&gt;
 npoints = 50&lt;br /&gt;
 path_kpoints = Path([ [[0.0, 0.0, 0.0 ],&#039;G&#039;],&lt;br /&gt;
                       [[0.0, 0.0, 1.0 ],&#039;H&#039;],&lt;br /&gt;
                       [[1./2,0.0,1./2.],&#039;N&#039;],&lt;br /&gt;
                       [[0.0, 0.0, 0.0 ],&#039;G&#039;],&lt;br /&gt;
                       [[1./2, 1./2, 1./2 ],&#039;P&#039;],&lt;br /&gt;
                       [[1./2,0.0,1./2. ],&#039;N&#039;]], [npoints,npoints,npoints,npoints,npoints])&lt;br /&gt;
&lt;br /&gt;
 xml = PwXML(prefix=&#039;pw&#039;,path=&#039;bands/t0&#039;)&lt;br /&gt;
 xml.plot_eigen(path_kpoints)&lt;br /&gt;
&lt;br /&gt;
[[File:Figure 3-iron-bands.png| 600 px | center |Spin polarized band structure of iron calculated by DFT]]&lt;br /&gt;
&lt;br /&gt;
The analysis of the projected atomic orbitals is also implemented. In this case the results are more cumbersome because the projection is separated in spin up and down channels.&amp;lt;br&amp;gt; &lt;br /&gt;
Let us look first at the file &#039;&#039;&#039;plot-qe-orbitals-size&#039;&#039;&#039;. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NB: If you generated the quantum espresso databases using the flows instead of relying on the precomputed databases, you also need to rerun the quantum espresso executable projwfc.x to recompute the orbital projections. In this case, please uncomment the following lines in the script&#039;&#039;&#039; (plot-qe-orbitals-size.py) :&lt;br /&gt;
 #proj = ProjwfcIn(prefix=&#039;pw&#039;)&lt;br /&gt;
 #proj.run(folder=&#039;bands/t0&#039;)&lt;br /&gt;
&lt;br /&gt;
Now, we can use the dot size as a function of the weight of the orbitals&lt;br /&gt;
 atom_s = [8]&lt;br /&gt;
 atom_p = [0,1,2]&lt;br /&gt;
 atom_d = [3,4,5,6,7]&lt;br /&gt;
&lt;br /&gt;
and the plots are done with&lt;br /&gt;
 band = ProjwfcXML(prefix=&#039;pw&#039;,path=&#039;bands/t0&#039;,qe_version=&#039;7.0&#039;)&lt;br /&gt;
 band.plot_eigen(ax,path_kpoints=path_kpoints,&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;selected_orbitals=atom_s,&amp;lt;/span&amp;gt;color=&#039;pink&#039;,color_2=&#039;black&#039;)&lt;br /&gt;
 band.plot_eigen(ax,path_kpoints=path_kpoints,&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;selected_orbitals=atom_p,&amp;lt;/span&amp;gt;color=&#039;green&#039;,color_2=&#039;orange&#039;)&lt;br /&gt;
 band.plot_eigen(ax,path_kpoints=path_kpoints,&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;selected_orbitals=atom_d,&amp;lt;/span&amp;gt;color=&#039;red&#039;,color_2=&#039;blue&#039;)&lt;br /&gt;
&lt;br /&gt;
As an example, we can select just the &#039;&#039;d&#039;&#039; orbitals by commenting the first two plots and then running the file:&lt;br /&gt;
&lt;br /&gt;
 plot-qe-orbitals-size.py&lt;br /&gt;
&lt;br /&gt;
[[File:Figure 4-iron-bands-size-d-orbitals.png|400px|center|Iron band structure. Size is proportional to the weights of the projection on atomic d-orbitals. Red (blue) is up (down) spin polarization.]]&lt;br /&gt;
&lt;br /&gt;
From the plot is clear that &#039;&#039;d&#039;&#039; orbitals are mainly localized around the Fermi energy. The plot above is in red and blue, while the default choice in your script should be pink and black. You can experiment with the colors and other &#039;&#039;matplotlib&#039;&#039; plot options and also plot the other orbital types.&lt;br /&gt;
&lt;br /&gt;
Another option is to plot the orbital composition as a colormap running the file:&lt;br /&gt;
&lt;br /&gt;
 plot-qe-orbitals-colormap.py&lt;br /&gt;
&lt;br /&gt;
[[File:Figure 5-iron-bands-colormap.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
Here we have added the p and d orbitals in the analysis:&lt;br /&gt;
&lt;br /&gt;
 atom_p = [0,1,2]&lt;br /&gt;
 atom_d = [3,4,5,6,7]&lt;br /&gt;
 band = ProjwfcXML(prefix=&#039;pw&#039;,path=&#039;bands/t0&#039;,qe_version=&#039;7.0&#039;)&lt;br /&gt;
 band.plot_eigen(ax,path_kpoints=path_kpoints,cmap=&#039;viridis&#039;,cmap2=&#039;rainbow&#039;,selected_orbitals=atom_p,selected_orbitals_2=atom_d)&lt;br /&gt;
&lt;br /&gt;
The colormap bar is added in the same way as in Tutorial 1 (see script), but this time we have a different colormap for each spin polarisation.&lt;br /&gt;
&lt;br /&gt;
==Tutorial 3: GW bands==&lt;br /&gt;
&lt;br /&gt;
Yambopy can be used either to run Yambo and QE calculations, or to analyse the results of QE and Yambo by dealing with their generated databases. This is done with a variety of classes included in the qepy (for QE) or yambopy (for Yambo) modules. &lt;br /&gt;
In the case of Yambo GW quasi-particle calculations, we can use the yambopy class &#039;&#039;&#039;YamboQPDB&#039;&#039;&#039; to read the database produced by the simulation.&lt;br /&gt;
Enter in the folder&lt;br /&gt;
 cd ../gw-bands&lt;br /&gt;
We can use this to find the scissor operator, plot the GW bands and to interpolate the GW bands on a smoother k-path. The example runs by typing:&lt;br /&gt;
&lt;br /&gt;
 python plot-qp.py&lt;br /&gt;
&lt;br /&gt;
See below for an explanation of the tutorial. As usual, we can import the qepy and yambopy libraries:&lt;br /&gt;
&lt;br /&gt;
  from qepy import *&lt;br /&gt;
  from yambopy import *&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
&lt;br /&gt;
We define the k-points path.&lt;br /&gt;
  npoints = 10&lt;br /&gt;
  path = Path([ [[  0.0,  0.0,  0.0],&#039;$\Gamma$&#039;],&lt;br /&gt;
                [[  0.5,  0.0,  0.0],&#039;M&#039;],&lt;br /&gt;
                [[1./3.,1./3.,  0.0],&#039;K&#039;],&lt;br /&gt;
                [[  0.0,  0.0,  0.0],&#039;$\Gamma$&#039;]], [int(npoints*2),int(npoints),int(sqrt(5)*npoints)] )&lt;br /&gt;
&lt;br /&gt;
Importantly, the number of points is a free choice. We can increase the variable npoints as we wish, it just means that the interpolation step will take more time. In order to analyse GW results we need to have the file related to the basic data of our Yambo calculation (&#039;&#039;&#039;SAVE/ns.db1&#039;&#039;&#039;) and the netcdf file with the quasi-particle results (&#039;&#039;&#039;ndb.QP&#039;&#039;&#039;). We load the data calling the respective classes:&lt;br /&gt;
&lt;br /&gt;
 # Read Lattice information from SAVE&lt;br /&gt;
 lat  = YamboSaveDB.from_db_file(folder=&#039;SAVE&#039;,filename=&#039;ns.db1&#039;)&lt;br /&gt;
 # Read QP database&lt;br /&gt;
 ydb  = YamboQPDB.from_db(filename=&#039;ndb.QP&#039;,folder=&#039;qp-gw&#039;)&lt;br /&gt;
(in the yambopy module, each class is specialised to read a specific Yambo database)&lt;br /&gt;
&lt;br /&gt;
The first option is to plot the energies and calculate the ideal Kohn-Sham to GW scissor operator. We need to select the index of the top valence band:&lt;br /&gt;
&lt;br /&gt;
 n_top_vb = 4&lt;br /&gt;
 ydb.plot_scissor_ax(ax,n_top_vb)&lt;br /&gt;
&lt;br /&gt;
Yambopy displays the fitting and also the data of the slope of each fitting. Notice that this is also a test if the GW calculations are running well. &#039;&#039;&#039;If the dependence is not linear you should double-check your results!&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[[File:Figure 6-slope-scissor.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
In this case the slope is:&lt;br /&gt;
&lt;br /&gt;
 valence bands:&lt;br /&gt;
 slope:     1.0515886598785766&lt;br /&gt;
 conduction bands:&lt;br /&gt;
 slope:     1.026524081134514&lt;br /&gt;
 scissor list (shift,c,v) [eV,adim,adim]: [1.8985204833551723, 1.026524081134514, 1.0515886598785766]&lt;br /&gt;
&lt;br /&gt;
In addition to the scissor operator, we can plot the GW (and DFT) band structure along the path. The first choice would be to plot the actual GW calculations, without interpolation, to check that the results are meaningful (or not). This plot is independent of the number of k-points (&#039;&#039;&#039;npoints&#039;&#039;&#039;) that we want to put in the interpolation. The class YamboQPDB finds the calculated points that belong to the path and plots them. Be aware that if we use coarse grids the class would not find any point and the function will not work.&lt;br /&gt;
&lt;br /&gt;
 ks_bs_0, qp_bs_0 = ydb.get_bs_path(lat,path)&lt;br /&gt;
 ks_bs_0.plot_ax(ax,legend=True,color_bands=&#039;r&#039;,label=&#039;KS&#039;)&lt;br /&gt;
 qp_bs_0.plot_ax(ax,legend=True,color_bands=&#039;b&#039;,label=&#039;QP-GW&#039;)&lt;br /&gt;
&lt;br /&gt;
[[File:Figure 7-GW-band-structure-non-interpolated.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
The interpolation of the DFT and GW band structures looks similar:&lt;br /&gt;
&lt;br /&gt;
 ks_bs, qp_bs = ydb.interpolate(lat,path,what=&#039;QP+KS&#039;,lpratio=20)&lt;br /&gt;
 ks_bs.plot_ax(ax,legend=True,color_bands=&#039;r&#039;,label=&#039;KS&#039;)&lt;br /&gt;
 qp_bs.plot_ax(ax,legend=True,color_bands=&#039;b&#039;,label=&#039;QP-GW&#039;)&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;lpratio&#039;&#039;&#039; can be increased if the interpolation does not work as well as intended. The interpolation is the same one implemented in abipy and currently requires abipy installed in order to work.&lt;br /&gt;
&lt;br /&gt;
[[File:Figure 8-GW-band-structure-interpolated.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
Finally, we can compare the calculated GW eigenvalues with the interpolation.&lt;br /&gt;
&lt;br /&gt;
[[File:Figure 8-GW-band-structure-comparison.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
==Links==&lt;br /&gt;
* Back to [[Rome 2023#Tutorials]]&lt;br /&gt;
* Back to [[ICTP 2022#Tutorials]]&lt;/div&gt;</summary>
		<author><name>Fulvio</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_band_structures&amp;diff=7622</id>
		<title>Yambopy tutorial: band structures</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_band_structures&amp;diff=7622"/>
		<updated>2024-02-07T14:03:10Z</updated>

		<summary type="html">&lt;p&gt;Fulvio: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
This tutorial will show you how to visualise wave-function and band-structure related information following a DFT Quantum Espresso calculation using the &amp;quot;qepy&amp;quot; module of Yambopy.&lt;br /&gt;
&lt;br /&gt;
The full tutorial, including the Quantum espresso and Yambo databases that we will read, can be downloaded and extracted from the yambo website:&lt;br /&gt;
 $wget https://media.yambo-code.eu/educational/tutorials/files/databases_qepy.tar.gz&lt;br /&gt;
 $tar -xvzf databases_qepy.tar.gz&lt;br /&gt;
 $cd databases_qepy&lt;br /&gt;
&lt;br /&gt;
==Tutorial 1. BN (semiconductor). Band structure==&lt;br /&gt;
&lt;br /&gt;
First enter in the folder &lt;br /&gt;
 cd databases_qepy/bn-semiconductor&lt;br /&gt;
and have a look to the &lt;br /&gt;
 vim plot-qe-bands.py&lt;br /&gt;
The qepy classes are useful both to execute Quantum Espresso and to analyze the results. Enter in the python environment, by typing &amp;lt;code&amp;gt;python&amp;lt;/code&amp;gt;, then the full qepy library is imported by simply doing:&lt;br /&gt;
&lt;br /&gt;
 from qepy import *&lt;br /&gt;
&lt;br /&gt;
===Plot Band structure===&lt;br /&gt;
&lt;br /&gt;
The qepy class &#039;&#039;&#039;PwXML&#039;&#039;&#039; reads the data file generated by Quantum Espresso and post-processes the data. The class is instanced by doing:&lt;br /&gt;
&lt;br /&gt;
 xml = PwXML(prefix=&#039;bn&#039;, path=&#039;bands&#039;)&lt;br /&gt;
&lt;br /&gt;
The variable prefix corresponds to the same variable of the QE input. The folder location is indicated by variable path. In order to plot the bands, we also define the k-points path (in crystal coordinates) using the function Path:&lt;br /&gt;
&lt;br /&gt;
 npoints = 50&lt;br /&gt;
 path_kpoints = Path([ [[0.0, 0.0, 0.0],&#039;$\Gamma$&#039;],&lt;br /&gt;
                       [[0.5, 0.0, 0.0],&#039;M&#039;],&lt;br /&gt;
                       [[1./3,1./3,0.0],&#039;K&#039;],&lt;br /&gt;
                       [[0.0, 0.0, 0.0],&#039;$\Gamma$&#039;]], [int(npoints*2),int(npoints),int(sqrt(5)*npoints)])&lt;br /&gt;
&lt;br /&gt;
It is worth to note that the path should coincide with the selected path for the QE band calculations.&lt;br /&gt;
&lt;br /&gt;
In order to show the plot we call the &#039;&#039;&#039;plot_eigen&#039;&#039;&#039; method of the &#039;&#039;&#039;PwXML&#039;&#039;&#039; class:&lt;br /&gt;
&lt;br /&gt;
 xml.plot_eigen(path_kpoints)&lt;br /&gt;
&lt;br /&gt;
This function will automatically plot the bands as shown below running the script:&lt;br /&gt;
&lt;br /&gt;
 python plot-qe-bands.py&lt;br /&gt;
&lt;br /&gt;
[[File:Bands BN 1.png| 400 px | center |Band structure of BN calculated at the level of DFT-LDA]]&lt;br /&gt;
&lt;br /&gt;
Alternatively, we can use the function &#039;&#039;&#039;plot_eigen_ax&#039;&#039;&#039;. This functions requires as input a matplotlib &#039;&#039;&#039;figure&#039;&#039;&#039; object with given axes, as you will see in the next example.&lt;br /&gt;
&lt;br /&gt;
===Plot atomic orbital projected Band structure===&lt;br /&gt;
&lt;br /&gt;
In addition to the band structure, useful information regarding the atomic orbital nature of the electronic wave functions can be displayed using the class &#039;&#039;&#039;ProjwfcXML&#039;&#039;&#039;. &lt;br /&gt;
In order to make quantum espresso calculate the relevant data, we need to use the QE executable &#039;&#039;&#039;projwfc.x&#039;&#039;&#039;, which will create the file &#039;&#039;&#039;atomic_proj.xml&#039;&#039;&#039;. This executable projects the Kohn-Sham wavefunctions onto orthogonalized atomic orbitals, among others functionalities. The orbital indexing  and ordering are explained in the input documentation of the projwfc.x function which you are invited to check (https://www.quantum-espresso.org/Doc/INPUT_PROJWFC.html#idm94). We can run &#039;&#039;&#039;projwf.x&#039;&#039;&#039; directly from the python script using the qepy class &#039;&#039;&#039;ProjwfcIn&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
 proj = ProjwfcIn(prefix=&#039;bn&#039;)&lt;br /&gt;
 proj.run(folder=&#039;bands&#039;)&lt;br /&gt;
&lt;br /&gt;
Be aware that this can take a while in a large system with many k-points. As in the class &#039;&#039;&#039;PwXML&#039;&#039;&#039;, we then define the path_kpoints and also the selected atomic orbitals to project our bands. We have chosen to represent the projection weight onto the nitrogen (1) and boron (2) orbitals, which according to the projection orderings is given by&lt;br /&gt;
&lt;br /&gt;
 atom_1 = list(range(16))&lt;br /&gt;
 atom_2 = list(range(16,32)) &lt;br /&gt;
&lt;br /&gt;
The full list of orbitals is written in the file &#039;&#039;&#039;bands/prowfc.log&#039;&#039;&#039;. We have also defined the figure box&lt;br /&gt;
&lt;br /&gt;
 import matplotlib.pyplot as plt&lt;br /&gt;
 fig = plt.figure(figsize=(5,7))&lt;br /&gt;
 ax  = fig.add_axes( [ 0.12, 0.10, 0.70, 0.80 ])&lt;br /&gt;
&lt;br /&gt;
The class &#039;&#039;&#039;ProjwfcXML&#039;&#039;&#039; then runs as in this example:&lt;br /&gt;
&lt;br /&gt;
 band = ProjwfcXML(prefix=&#039;bn&#039;,path=&#039;bands&#039;,qe_version=&#039;7.0&#039;)&lt;br /&gt;
 band.plot_eigen(ax,path_kpoints=path_kpoints,cmap=&#039;viridis&#039;,selected_orbitals=atom_1,selected_orbitals_2=atom_2)&lt;br /&gt;
&lt;br /&gt;
We can run now the file:&lt;br /&gt;
&lt;br /&gt;
 python plot-qe-orbitals.py&lt;br /&gt;
&lt;br /&gt;
[[File:Bands AOP BN 1.png| 400 px | center | Atomic orbital projected band structure of monolayer BN]]&lt;br /&gt;
&lt;br /&gt;
We have chosen the colormap &#039;viridis&#039; (variable cmap). You see that the colormap goes from maximum &#039;&#039;&#039;selected_orbitals&#039;&#039;&#039; content (in this case nitrogen) to the maximum &#039;&#039;&#039;selected_orbitals_2&#039;&#039;&#039; content (in this case boron). &lt;br /&gt;
The colormap can be represented in many ways and qepy does not include a particular function for this. An example is:&lt;br /&gt;
&lt;br /&gt;
 import matplotlib as mpl&lt;br /&gt;
 cmap=plt.get_cmap(&#039;viridis&#039;)&lt;br /&gt;
 bx  = fig.add_axes( [ 0.88, 0.10, 0.05, 0.80 ])&lt;br /&gt;
 norm = mpl.colors.Normalize(vmin=0.,vmax=1.)&lt;br /&gt;
 cb1 = mpl.colorbar.ColorbarBase(bx, cmap=cmap, norm=norm,orientation=&#039;vertical&#039;,ticks=[0,1])&lt;br /&gt;
 cb1.set_ticklabels([&#039;B&#039;, &#039;N&#039;])&lt;br /&gt;
&lt;br /&gt;
We can also plot the band orbital charater with size variation instead of a color scale. In this case we have to pass only the variable selected_orbitals (see the next tutorial).&lt;br /&gt;
&lt;br /&gt;
==Tutorial 2. Iron. Ferromagnetic metalic material==&lt;br /&gt;
&lt;br /&gt;
In the case of spin-polarized calculations we can plot the spin up and down band structures. We have included in the tutorial a small workflow example to run quantum espresso calculations from scratch. This is done using the classes Tasks and Flows developed in yambopy. You can check the file flow-iron.py for an example. &lt;br /&gt;
Yambopy includes basic predefined workflows to run the common QE and Yambo calculations. In this case we are using the class &#039;&#039;&#039;PwBandsTasks&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
 python flow-iron.py&lt;br /&gt;
&lt;br /&gt;
In order to plot the spin-polarized bands. After doing all the calculations from scratch with the flows (flow-iron.py), we can make the band plot by running the script:&lt;br /&gt;
&lt;br /&gt;
 python plot-qe-bands.py&lt;br /&gt;
&lt;br /&gt;
The class PwXML automatically detects the spin polarized case (nspin=2 in the QE input file). The spin up channel is displayed with red and the spin down channel with blue. In the case of iron we have selected this k-point path:&lt;br /&gt;
&lt;br /&gt;
 npoints = 50&lt;br /&gt;
 path_kpoints = Path([ [[0.0, 0.0, 0.0 ],&#039;G&#039;],&lt;br /&gt;
                       [[0.0, 0.0, 1.0 ],&#039;H&#039;],&lt;br /&gt;
                       [[1./2,0.0,1./2.],&#039;N&#039;],&lt;br /&gt;
                       [[0.0, 0.0, 0.0 ],&#039;G&#039;],&lt;br /&gt;
                       [[1./2, 1./2, 1./2 ],&#039;P&#039;],&lt;br /&gt;
                       [[1./2,0.0,1./2. ],&#039;N&#039;]], [npoints,npoints,npoints,npoints,npoints])&lt;br /&gt;
&lt;br /&gt;
 xml = PwXML(prefix=&#039;pw&#039;,path=&#039;bands/t0&#039;)&lt;br /&gt;
 xml.plot_eigen(path_kpoints)&lt;br /&gt;
&lt;br /&gt;
[[File:Figure 3-iron-bands.png| 600 px | center |Spin polarized band structure of iron calculated by DFT]]&lt;br /&gt;
&lt;br /&gt;
The analysis of the projected atomic orbitals is also implemented. In this case the results are more cumbersome because the projection is separated in spin up and down channels.&amp;lt;br&amp;gt; &lt;br /&gt;
Let us look first at the file &#039;&#039;&#039;plot-qe-orbitals-size&#039;&#039;&#039;. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NB: If you generated the quantum espresso databases using the flows instead of relying on the precomputed databases, you also need to rerun the quantum espresso executable projwfc.x to recompute the orbital projections. In this case, please uncomment the following lines in the script&#039;&#039;&#039; (plot-qe-orbitals-size.py) :&lt;br /&gt;
 #proj = ProjwfcIn(prefix=&#039;pw&#039;)&lt;br /&gt;
 #proj.run(folder=&#039;bands/t0&#039;)&lt;br /&gt;
&lt;br /&gt;
Now, we can use the dot size as a function of the weight of the orbitals&lt;br /&gt;
 atom_s = [8]&lt;br /&gt;
 atom_p = [0,1,2]&lt;br /&gt;
 atom_d = [3,4,5,6,7]&lt;br /&gt;
&lt;br /&gt;
and the plots are done with&lt;br /&gt;
 band = ProjwfcXML(prefix=&#039;pw&#039;,path=&#039;bands/t0&#039;,qe_version=&#039;7.0&#039;)&lt;br /&gt;
 band.plot_eigen(ax,path_kpoints=path_kpoints,&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;selected_orbitals=atom_s,&amp;lt;/span&amp;gt;color=&#039;pink&#039;,color_2=&#039;black&#039;)&lt;br /&gt;
 band.plot_eigen(ax,path_kpoints=path_kpoints,&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;selected_orbitals=atom_p,&amp;lt;/span&amp;gt;color=&#039;green&#039;,color_2=&#039;orange&#039;)&lt;br /&gt;
 band.plot_eigen(ax,path_kpoints=path_kpoints,&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;selected_orbitals=atom_d,&amp;lt;/span&amp;gt;color=&#039;red&#039;,color_2=&#039;blue&#039;)&lt;br /&gt;
&lt;br /&gt;
As an example, we can select just the &#039;&#039;d&#039;&#039; orbitals by commenting the first two plots and then running the file:&lt;br /&gt;
&lt;br /&gt;
 plot-qe-orbitals-size.py&lt;br /&gt;
&lt;br /&gt;
[[File:Figure 4-iron-bands-size-d-orbitals.png|400px|center|Iron band structure. Size is proportional to the weights of the projection on atomic d-orbitals. Red (blue) is up (down) spin polarization.]]&lt;br /&gt;
&lt;br /&gt;
From the plot is clear that &#039;&#039;d&#039;&#039; orbitals are mainly localized around the Fermi energy. The plot above is in red and blue, while the default choice in your script should be pink and black. You can experiment with the colors and other &#039;&#039;matplotlib&#039;&#039; plot options and also plot the other orbital types.&lt;br /&gt;
&lt;br /&gt;
Another option is to plot the orbital composition as a colormap running the file:&lt;br /&gt;
&lt;br /&gt;
 plot-qe-orbitals-colormap.py&lt;br /&gt;
&lt;br /&gt;
[[File:Figure 5-iron-bands-colormap.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
Here we have added the p and d orbitals in the analysis:&lt;br /&gt;
&lt;br /&gt;
 atom_p = [0,1,2]&lt;br /&gt;
 atom_d = [3,4,5,6,7]&lt;br /&gt;
 band = ProjwfcXML(prefix=&#039;pw&#039;,path=&#039;bands/t0&#039;,qe_version=&#039;7.0&#039;)&lt;br /&gt;
 band.plot_eigen(ax,path_kpoints=path_kpoints,cmap=&#039;viridis&#039;,cmap2=&#039;rainbow&#039;,selected_orbitals=atom_p,selected_orbitals_2=atom_d)&lt;br /&gt;
&lt;br /&gt;
The colormap bar is added in the same way as in Tutorial 1 (see script), but this time we have a different colormap for each spin polarisation.&lt;br /&gt;
&lt;br /&gt;
==Tutorial 3: GW bands==&lt;br /&gt;
&lt;br /&gt;
Yambopy can be used either to run Yambo and QE calculations, or to analyse the results of QE and Yambo by dealing with their generated databases. This is done with a variety of classes included in the qepy (for QE) or yambopy (for Yambo) modules. &lt;br /&gt;
In the case of Yambo GW quasi-particle calculations, we can use the yambopy class &#039;&#039;&#039;YamboQPDB&#039;&#039;&#039; to read the database produced by the simulation.&lt;br /&gt;
Enter in the folder&lt;br /&gt;
 cd ../gw-bands&lt;br /&gt;
We can use this to find the scissor operator, plot the GW bands and to interpolate the GW bands on a smoother k-path. The example runs by typing:&lt;br /&gt;
&lt;br /&gt;
 python plot-qp.py&lt;br /&gt;
&lt;br /&gt;
See below for an explanation of the tutorial. As usual, we can import the qepy and yambopy libraries:&lt;br /&gt;
&lt;br /&gt;
  from qepy import *&lt;br /&gt;
  from yambopy import *&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
&lt;br /&gt;
We define the k-points path.&lt;br /&gt;
  npoints = 10&lt;br /&gt;
  path = Path([ [[  0.0,  0.0,  0.0],&#039;$\Gamma$&#039;],&lt;br /&gt;
                [[  0.5,  0.0,  0.0],&#039;M&#039;],&lt;br /&gt;
                [[1./3.,1./3.,  0.0],&#039;K&#039;],&lt;br /&gt;
                [[  0.0,  0.0,  0.0],&#039;$\Gamma$&#039;]], [int(npoints*2),int(npoints),int(sqrt(5)*npoints)] )&lt;br /&gt;
&lt;br /&gt;
Importantly, the number of points is a free choice. We can increase the variable npoints as we wish, it just means that the interpolation step will take more time. In order to analyse GW results we need to have the file related to the basic data of our Yambo calculation (&#039;&#039;&#039;SAVE/ns.db1&#039;&#039;&#039;) and the netcdf file with the quasi-particle results (&#039;&#039;&#039;ndb.QP&#039;&#039;&#039;). We load the data calling the respective classes:&lt;br /&gt;
&lt;br /&gt;
 # Read Lattice information from SAVE&lt;br /&gt;
 lat  = YamboSaveDB.from_db_file(folder=&#039;SAVE&#039;,filename=&#039;ns.db1&#039;)&lt;br /&gt;
 # Read QP database&lt;br /&gt;
 ydb  = YamboQPDB.from_db(filename=&#039;ndb.QP&#039;,folder=&#039;qp-gw&#039;)&lt;br /&gt;
(in the yambopy module, each class is specialised to read a specific Yambo database)&lt;br /&gt;
&lt;br /&gt;
The first option is to plot the energies and calculate the ideal Kohn-Sham to GW scissor operator. We need to select the index of the top valence band:&lt;br /&gt;
&lt;br /&gt;
 n_top_vb = 4&lt;br /&gt;
 ydb.plot_scissor_ax(ax,n_top_vb)&lt;br /&gt;
&lt;br /&gt;
Yambopy displays the fitting and also the data of the slope of each fitting. Notice that this is also a test if the GW calculations are running well. &#039;&#039;&#039;If the dependence is not linear you should double-check your results!&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[[File:Figure 6-slope-scissor.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
In this case the slope is:&lt;br /&gt;
&lt;br /&gt;
 valence bands:&lt;br /&gt;
 slope:     1.0515886598785766&lt;br /&gt;
 conduction bands:&lt;br /&gt;
 slope:     1.026524081134514&lt;br /&gt;
 scissor list (shift,c,v) [eV,adim,adim]: [1.8985204833551723, 1.026524081134514, 1.0515886598785766]&lt;br /&gt;
&lt;br /&gt;
In addition to the scissor operator, we can plot the GW (and DFT) band structure along the path. The first choice would be to plot the actual GW calculations, without interpolation, to check that the results are meaningful (or not). This plot is independent of the number of k-points (&#039;&#039;&#039;npoints&#039;&#039;&#039;) that we want to put in the interpolation. The class YamboQPDB finds the calculated points that belong to the path and plots them. Be aware that if we use coarse grids the class would not find any point and the function will not work.&lt;br /&gt;
&lt;br /&gt;
 ks_bs_0, qp_bs_0 = ydb.get_bs_path(lat,path)&lt;br /&gt;
 ks_bs_0.plot_ax(ax,legend=True,color_bands=&#039;r&#039;,label=&#039;KS&#039;)&lt;br /&gt;
 qp_bs_0.plot_ax(ax,legend=True,color_bands=&#039;b&#039;,label=&#039;QP-GW&#039;)&lt;br /&gt;
&lt;br /&gt;
[[File:Figure 7-GW-band-structure-non-interpolated.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
The interpolation of the DFT and GW band structures looks similar:&lt;br /&gt;
&lt;br /&gt;
 ks_bs, qp_bs = ydb.interpolate(lat,path,what=&#039;QP+KS&#039;,lpratio=20)&lt;br /&gt;
 ks_bs.plot_ax(ax,legend=True,color_bands=&#039;r&#039;,label=&#039;KS&#039;)&lt;br /&gt;
 qp_bs.plot_ax(ax,legend=True,color_bands=&#039;b&#039;,label=&#039;QP-GW&#039;)&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;lpratio&#039;&#039;&#039; can be increased if the interpolation does not work as well as intended. The interpolation is the same one implemented in abipy and currently requires abipy installed in order to work.&lt;br /&gt;
&lt;br /&gt;
[[File:Figure 8-GW-band-structure-interpolated.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
Finally, we can compare the calculated GW eigenvalues with the interpolation.&lt;br /&gt;
&lt;br /&gt;
[[File:Figure 8-GW-band-structure-comparison.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
==Links==&lt;br /&gt;
* Back to [[Rome 2023#Tutorials]]&lt;br /&gt;
* Back to [[ICTP 2022#Tutorials]]&lt;/div&gt;</summary>
		<author><name>Fulvio</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_band_structures&amp;diff=7621</id>
		<title>Yambopy tutorial: band structures</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_band_structures&amp;diff=7621"/>
		<updated>2024-02-07T14:02:20Z</updated>

		<summary type="html">&lt;p&gt;Fulvio: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
This tutorial will show you how to visualise wave-function and band-structure related information following a DFT Quantum Espresso calculation using the &amp;quot;qepy&amp;quot; module of Yambopy.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Concerning the ICTP school: recall that for the yambopy tutorials you have to load the yambo, quantum-espresso and anaconda3 modules:&#039;&#039;&#039;&lt;br /&gt;
 spack load yambo&lt;br /&gt;
 spack load quantum-espresso&lt;br /&gt;
 spack load anaconda3&lt;br /&gt;
&#039;&#039;&#039;You can copy the tutorial databases as explained in the virtual machine setup page: &#039;&#039;&#039;&lt;br /&gt;
 cp -r /media/ictpuser/smr3694/ictptutor/YAMBOPY_TUTORIALS ~/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The full tutorial, including the Quantum espresso and Yambo databases that we will read, can be downloaded and extracted from the yambo website:&lt;br /&gt;
 $wget https://media.yambo-code.eu/educational/tutorials/files/databases_qepy.tar.gz&lt;br /&gt;
 $tar -xvzf databases_qepy.tar.gz&lt;br /&gt;
 $cd databases_qepy&lt;br /&gt;
&lt;br /&gt;
==Tutorial 1. BN (semiconductor). Band structure==&lt;br /&gt;
&lt;br /&gt;
First enter in the folder &lt;br /&gt;
 cd databases_qepy/bn-semiconductor&lt;br /&gt;
and have a look to the &lt;br /&gt;
 vim plot-qe-bands.py&lt;br /&gt;
The qepy classes are useful both to execute Quantum Espresso and to analyze the results. Enter in the python environment, by typing &amp;lt;code&amp;gt;python&amp;lt;/code&amp;gt;, then the full qepy library is imported by simply doing:&lt;br /&gt;
&lt;br /&gt;
 from qepy import *&lt;br /&gt;
&lt;br /&gt;
===Plot Band structure===&lt;br /&gt;
&lt;br /&gt;
The qepy class &#039;&#039;&#039;PwXML&#039;&#039;&#039; reads the data file generated by Quantum Espresso and post-processes the data. The class is instanced by doing:&lt;br /&gt;
&lt;br /&gt;
 xml = PwXML(prefix=&#039;bn&#039;, path=&#039;bands&#039;)&lt;br /&gt;
&lt;br /&gt;
The variable prefix corresponds to the same variable of the QE input. The folder location is indicated by variable path. In order to plot the bands, we also define the k-points path (in crystal coordinates) using the function Path:&lt;br /&gt;
&lt;br /&gt;
 npoints = 50&lt;br /&gt;
 path_kpoints = Path([ [[0.0, 0.0, 0.0],&#039;$\Gamma$&#039;],&lt;br /&gt;
                       [[0.5, 0.0, 0.0],&#039;M&#039;],&lt;br /&gt;
                       [[1./3,1./3,0.0],&#039;K&#039;],&lt;br /&gt;
                       [[0.0, 0.0, 0.0],&#039;$\Gamma$&#039;]], [int(npoints*2),int(npoints),int(sqrt(5)*npoints)])&lt;br /&gt;
&lt;br /&gt;
It is worth to note that the path should coincide with the selected path for the QE band calculations.&lt;br /&gt;
&lt;br /&gt;
In order to show the plot we call the &#039;&#039;&#039;plot_eigen&#039;&#039;&#039; method of the &#039;&#039;&#039;PwXML&#039;&#039;&#039; class:&lt;br /&gt;
&lt;br /&gt;
 xml.plot_eigen(path_kpoints)&lt;br /&gt;
&lt;br /&gt;
This function will automatically plot the bands as shown below running the script:&lt;br /&gt;
&lt;br /&gt;
 python plot-qe-bands.py&lt;br /&gt;
&lt;br /&gt;
[[File:Bands BN 1.png| 400 px | center |Band structure of BN calculated at the level of DFT-LDA]]&lt;br /&gt;
&lt;br /&gt;
Alternatively, we can use the function &#039;&#039;&#039;plot_eigen_ax&#039;&#039;&#039;. This functions requires as input a matplotlib &#039;&#039;&#039;figure&#039;&#039;&#039; object with given axes, as you will see in the next example.&lt;br /&gt;
&lt;br /&gt;
===Plot atomic orbital projected Band structure===&lt;br /&gt;
&lt;br /&gt;
In addition to the band structure, useful information regarding the atomic orbital nature of the electronic wave functions can be displayed using the class &#039;&#039;&#039;ProjwfcXML&#039;&#039;&#039;. &lt;br /&gt;
In order to make quantum espresso calculate the relevant data, we need to use the QE executable &#039;&#039;&#039;projwfc.x&#039;&#039;&#039;, which will create the file &#039;&#039;&#039;atomic_proj.xml&#039;&#039;&#039;. This executable projects the Kohn-Sham wavefunctions onto orthogonalized atomic orbitals, among others functionalities. The orbital indexing  and ordering are explained in the input documentation of the projwfc.x function which you are invited to check (https://www.quantum-espresso.org/Doc/INPUT_PROJWFC.html#idm94). We can run &#039;&#039;&#039;projwf.x&#039;&#039;&#039; directly from the python script using the qepy class &#039;&#039;&#039;ProjwfcIn&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
 proj = ProjwfcIn(prefix=&#039;bn&#039;)&lt;br /&gt;
 proj.run(folder=&#039;bands&#039;)&lt;br /&gt;
&lt;br /&gt;
Be aware that this can take a while in a large system with many k-points. As in the class &#039;&#039;&#039;PwXML&#039;&#039;&#039;, we then define the path_kpoints and also the selected atomic orbitals to project our bands. We have chosen to represent the projection weight onto the nitrogen (1) and boron (2) orbitals, which according to the projection orderings is given by&lt;br /&gt;
&lt;br /&gt;
 atom_1 = list(range(16))&lt;br /&gt;
 atom_2 = list(range(16,32)) &lt;br /&gt;
&lt;br /&gt;
The full list of orbitals is written in the file &#039;&#039;&#039;bands/prowfc.log&#039;&#039;&#039;. We have also defined the figure box&lt;br /&gt;
&lt;br /&gt;
 import matplotlib.pyplot as plt&lt;br /&gt;
 fig = plt.figure(figsize=(5,7))&lt;br /&gt;
 ax  = fig.add_axes( [ 0.12, 0.10, 0.70, 0.80 ])&lt;br /&gt;
&lt;br /&gt;
The class &#039;&#039;&#039;ProjwfcXML&#039;&#039;&#039; then runs as in this example:&lt;br /&gt;
&lt;br /&gt;
 band = ProjwfcXML(prefix=&#039;bn&#039;,path=&#039;bands&#039;,qe_version=&#039;7.0&#039;)&lt;br /&gt;
 band.plot_eigen(ax,path_kpoints=path_kpoints,cmap=&#039;viridis&#039;,selected_orbitals=atom_1,selected_orbitals_2=atom_2)&lt;br /&gt;
&lt;br /&gt;
We can run now the file:&lt;br /&gt;
&lt;br /&gt;
 python plot-qe-orbitals.py&lt;br /&gt;
&lt;br /&gt;
[[File:Bands AOP BN 1.png| 400 px | center | Atomic orbital projected band structure of monolayer BN]]&lt;br /&gt;
&lt;br /&gt;
We have chosen the colormap &#039;viridis&#039; (variable cmap). You see that the colormap goes from maximum &#039;&#039;&#039;selected_orbitals&#039;&#039;&#039; content (in this case nitrogen) to the maximum &#039;&#039;&#039;selected_orbitals_2&#039;&#039;&#039; content (in this case boron). &lt;br /&gt;
The colormap can be represented in many ways and qepy does not include a particular function for this. An example is:&lt;br /&gt;
&lt;br /&gt;
 import matplotlib as mpl&lt;br /&gt;
 cmap=plt.get_cmap(&#039;viridis&#039;)&lt;br /&gt;
 bx  = fig.add_axes( [ 0.88, 0.10, 0.05, 0.80 ])&lt;br /&gt;
 norm = mpl.colors.Normalize(vmin=0.,vmax=1.)&lt;br /&gt;
 cb1 = mpl.colorbar.ColorbarBase(bx, cmap=cmap, norm=norm,orientation=&#039;vertical&#039;,ticks=[0,1])&lt;br /&gt;
 cb1.set_ticklabels([&#039;B&#039;, &#039;N&#039;])&lt;br /&gt;
&lt;br /&gt;
We can also plot the band orbital charater with size variation instead of a color scale. In this case we have to pass only the variable selected_orbitals (see the next tutorial).&lt;br /&gt;
&lt;br /&gt;
==Tutorial 2. Iron. Ferromagnetic metalic material==&lt;br /&gt;
&lt;br /&gt;
In the case of spin-polarized calculations we can plot the spin up and down band structures. We have included in the tutorial a small workflow example to run quantum espresso calculations from scratch. This is done using the classes Tasks and Flows developed in yambopy. You can check the file flow-iron.py for an example. &lt;br /&gt;
Yambopy includes basic predefined workflows to run the common QE and Yambo calculations. In this case we are using the class &#039;&#039;&#039;PwBandsTasks&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
 python flow-iron.py&lt;br /&gt;
&lt;br /&gt;
In order to plot the spin-polarized bands. After doing all the calculations from scratch with the flows (flow-iron.py), we can make the band plot by running the script:&lt;br /&gt;
&lt;br /&gt;
 python plot-qe-bands.py&lt;br /&gt;
&lt;br /&gt;
The class PwXML automatically detects the spin polarized case (nspin=2 in the QE input file). The spin up channel is displayed with red and the spin down channel with blue. In the case of iron we have selected this k-point path:&lt;br /&gt;
&lt;br /&gt;
 npoints = 50&lt;br /&gt;
 path_kpoints = Path([ [[0.0, 0.0, 0.0 ],&#039;G&#039;],&lt;br /&gt;
                       [[0.0, 0.0, 1.0 ],&#039;H&#039;],&lt;br /&gt;
                       [[1./2,0.0,1./2.],&#039;N&#039;],&lt;br /&gt;
                       [[0.0, 0.0, 0.0 ],&#039;G&#039;],&lt;br /&gt;
                       [[1./2, 1./2, 1./2 ],&#039;P&#039;],&lt;br /&gt;
                       [[1./2,0.0,1./2. ],&#039;N&#039;]], [npoints,npoints,npoints,npoints,npoints])&lt;br /&gt;
&lt;br /&gt;
 xml = PwXML(prefix=&#039;pw&#039;,path=&#039;bands/t0&#039;)&lt;br /&gt;
 xml.plot_eigen(path_kpoints)&lt;br /&gt;
&lt;br /&gt;
[[File:Figure 3-iron-bands.png| 600 px | center |Spin polarized band structure of iron calculated by DFT]]&lt;br /&gt;
&lt;br /&gt;
The analysis of the projected atomic orbitals is also implemented. In this case the results are more cumbersome because the projection is separated in spin up and down channels.&amp;lt;br&amp;gt; &lt;br /&gt;
Let us look first at the file &#039;&#039;&#039;plot-qe-orbitals-size&#039;&#039;&#039;. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NB: If you generated the quantum espresso databases using the flows instead of relying on the precomputed databases, you also need to rerun the quantum espresso executable projwfc.x to recompute the orbital projections. In this case, please uncomment the following lines in the script&#039;&#039;&#039; (plot-qe-orbitals-size.py) :&lt;br /&gt;
 #proj = ProjwfcIn(prefix=&#039;pw&#039;)&lt;br /&gt;
 #proj.run(folder=&#039;bands/t0&#039;)&lt;br /&gt;
&lt;br /&gt;
Now, we can use the dot size as a function of the weight of the orbitals&lt;br /&gt;
 atom_s = [8]&lt;br /&gt;
 atom_p = [0,1,2]&lt;br /&gt;
 atom_d = [3,4,5,6,7]&lt;br /&gt;
&lt;br /&gt;
and the plots are done with&lt;br /&gt;
 band = ProjwfcXML(prefix=&#039;pw&#039;,path=&#039;bands/t0&#039;,qe_version=&#039;7.0&#039;)&lt;br /&gt;
 band.plot_eigen(ax,path_kpoints=path_kpoints,&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;selected_orbitals=atom_s,&amp;lt;/span&amp;gt;color=&#039;pink&#039;,color_2=&#039;black&#039;)&lt;br /&gt;
 band.plot_eigen(ax,path_kpoints=path_kpoints,&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;selected_orbitals=atom_p,&amp;lt;/span&amp;gt;color=&#039;green&#039;,color_2=&#039;orange&#039;)&lt;br /&gt;
 band.plot_eigen(ax,path_kpoints=path_kpoints,&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;selected_orbitals=atom_d,&amp;lt;/span&amp;gt;color=&#039;red&#039;,color_2=&#039;blue&#039;)&lt;br /&gt;
&lt;br /&gt;
As an example, we can select just the &#039;&#039;d&#039;&#039; orbitals by commenting the first two plots and then running the file:&lt;br /&gt;
&lt;br /&gt;
 plot-qe-orbitals-size.py&lt;br /&gt;
&lt;br /&gt;
[[File:Figure 4-iron-bands-size-d-orbitals.png|400px|center|Iron band structure. Size is proportional to the weights of the projection on atomic d-orbitals. Red (blue) is up (down) spin polarization.]]&lt;br /&gt;
&lt;br /&gt;
From the plot is clear that &#039;&#039;d&#039;&#039; orbitals are mainly localized around the Fermi energy. The plot above is in red and blue, while the default choice in your script should be pink and black. You can experiment with the colors and other &#039;&#039;matplotlib&#039;&#039; plot options and also plot the other orbital types.&lt;br /&gt;
&lt;br /&gt;
Another option is to plot the orbital composition as a colormap running the file:&lt;br /&gt;
&lt;br /&gt;
 plot-qe-orbitals-colormap.py&lt;br /&gt;
&lt;br /&gt;
[[File:Figure 5-iron-bands-colormap.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
Here we have added the p and d orbitals in the analysis:&lt;br /&gt;
&lt;br /&gt;
 atom_p = [0,1,2]&lt;br /&gt;
 atom_d = [3,4,5,6,7]&lt;br /&gt;
 band = ProjwfcXML(prefix=&#039;pw&#039;,path=&#039;bands/t0&#039;,qe_version=&#039;7.0&#039;)&lt;br /&gt;
 band.plot_eigen(ax,path_kpoints=path_kpoints,cmap=&#039;viridis&#039;,cmap2=&#039;rainbow&#039;,selected_orbitals=atom_p,selected_orbitals_2=atom_d)&lt;br /&gt;
&lt;br /&gt;
The colormap bar is added in the same way as in Tutorial 1 (see script), but this time we have a different colormap for each spin polarisation.&lt;br /&gt;
&lt;br /&gt;
==Tutorial 3: GW bands==&lt;br /&gt;
&lt;br /&gt;
Yambopy can be used either to run Yambo and QE calculations, or to analyse the results of QE and Yambo by dealing with their generated databases. This is done with a variety of classes included in the qepy (for QE) or yambopy (for Yambo) modules. &lt;br /&gt;
In the case of Yambo GW quasi-particle calculations, we can use the yambopy class &#039;&#039;&#039;YamboQPDB&#039;&#039;&#039; to read the database produced by the simulation.&lt;br /&gt;
Enter in the folder&lt;br /&gt;
 cd ../gw-bands&lt;br /&gt;
We can use this to find the scissor operator, plot the GW bands and to interpolate the GW bands on a smoother k-path. The example runs by typing:&lt;br /&gt;
&lt;br /&gt;
 python plot-qp.py&lt;br /&gt;
&lt;br /&gt;
See below for an explanation of the tutorial. As usual, we can import the qepy and yambopy libraries:&lt;br /&gt;
&lt;br /&gt;
  from qepy import *&lt;br /&gt;
  from yambopy import *&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
&lt;br /&gt;
We define the k-points path.&lt;br /&gt;
  npoints = 10&lt;br /&gt;
  path = Path([ [[  0.0,  0.0,  0.0],&#039;$\Gamma$&#039;],&lt;br /&gt;
                [[  0.5,  0.0,  0.0],&#039;M&#039;],&lt;br /&gt;
                [[1./3.,1./3.,  0.0],&#039;K&#039;],&lt;br /&gt;
                [[  0.0,  0.0,  0.0],&#039;$\Gamma$&#039;]], [int(npoints*2),int(npoints),int(sqrt(5)*npoints)] )&lt;br /&gt;
&lt;br /&gt;
Importantly, the number of points is a free choice. We can increase the variable npoints as we wish, it just means that the interpolation step will take more time. In order to analyse GW results we need to have the file related to the basic data of our Yambo calculation (&#039;&#039;&#039;SAVE/ns.db1&#039;&#039;&#039;) and the netcdf file with the quasi-particle results (&#039;&#039;&#039;ndb.QP&#039;&#039;&#039;). We load the data calling the respective classes:&lt;br /&gt;
&lt;br /&gt;
 # Read Lattice information from SAVE&lt;br /&gt;
 lat  = YamboSaveDB.from_db_file(folder=&#039;SAVE&#039;,filename=&#039;ns.db1&#039;)&lt;br /&gt;
 # Read QP database&lt;br /&gt;
 ydb  = YamboQPDB.from_db(filename=&#039;ndb.QP&#039;,folder=&#039;qp-gw&#039;)&lt;br /&gt;
(in the yambopy module, each class is specialised to read a specific Yambo database)&lt;br /&gt;
&lt;br /&gt;
The first option is to plot the energies and calculate the ideal Kohn-Sham to GW scissor operator. We need to select the index of the top valence band:&lt;br /&gt;
&lt;br /&gt;
 n_top_vb = 4&lt;br /&gt;
 ydb.plot_scissor_ax(ax,n_top_vb)&lt;br /&gt;
&lt;br /&gt;
Yambopy displays the fitting and also the data of the slope of each fitting. Notice that this is also a test if the GW calculations are running well. &#039;&#039;&#039;If the dependence is not linear you should double-check your results!&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[[File:Figure 6-slope-scissor.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
In this case the slope is:&lt;br /&gt;
&lt;br /&gt;
 valence bands:&lt;br /&gt;
 slope:     1.0515886598785766&lt;br /&gt;
 conduction bands:&lt;br /&gt;
 slope:     1.026524081134514&lt;br /&gt;
 scissor list (shift,c,v) [eV,adim,adim]: [1.8985204833551723, 1.026524081134514, 1.0515886598785766]&lt;br /&gt;
&lt;br /&gt;
In addition to the scissor operator, we can plot the GW (and DFT) band structure along the path. The first choice would be to plot the actual GW calculations, without interpolation, to check that the results are meaningful (or not). This plot is independent of the number of k-points (&#039;&#039;&#039;npoints&#039;&#039;&#039;) that we want to put in the interpolation. The class YamboQPDB finds the calculated points that belong to the path and plots them. Be aware that if we use coarse grids the class would not find any point and the function will not work.&lt;br /&gt;
&lt;br /&gt;
 ks_bs_0, qp_bs_0 = ydb.get_bs_path(lat,path)&lt;br /&gt;
 ks_bs_0.plot_ax(ax,legend=True,color_bands=&#039;r&#039;,label=&#039;KS&#039;)&lt;br /&gt;
 qp_bs_0.plot_ax(ax,legend=True,color_bands=&#039;b&#039;,label=&#039;QP-GW&#039;)&lt;br /&gt;
&lt;br /&gt;
[[File:Figure 7-GW-band-structure-non-interpolated.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
The interpolation of the DFT and GW band structures looks similar:&lt;br /&gt;
&lt;br /&gt;
 ks_bs, qp_bs = ydb.interpolate(lat,path,what=&#039;QP+KS&#039;,lpratio=20)&lt;br /&gt;
 ks_bs.plot_ax(ax,legend=True,color_bands=&#039;r&#039;,label=&#039;KS&#039;)&lt;br /&gt;
 qp_bs.plot_ax(ax,legend=True,color_bands=&#039;b&#039;,label=&#039;QP-GW&#039;)&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;lpratio&#039;&#039;&#039; can be increased if the interpolation does not work as well as intended. The interpolation is the same one implemented in abipy and currently requires abipy installed in order to work.&lt;br /&gt;
&lt;br /&gt;
[[File:Figure 8-GW-band-structure-interpolated.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
Finally, we can compare the calculated GW eigenvalues with the interpolation.&lt;br /&gt;
&lt;br /&gt;
[[File:Figure 8-GW-band-structure-comparison.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
==Links==&lt;br /&gt;
* Back to [[Rome 2023#Tutorials]]&lt;br /&gt;
* Back to [[ICTP 2022#Tutorials]]&lt;/div&gt;</summary>
		<author><name>Fulvio</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_Yambo_databases&amp;diff=7620</id>
		<title>Yambopy tutorial: Yambo databases</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_Yambo_databases&amp;diff=7620"/>
		<updated>2024-02-07T14:01:59Z</updated>

		<summary type="html">&lt;p&gt;Fulvio: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In this tutorial we will see some examples on how to read and analyse the data contained in the Yambo netCDF databases, which are not readily available as human readable outputs.&lt;br /&gt;
&lt;br /&gt;
In particular we will take a look at:&lt;br /&gt;
* Lattice geometry data (Yambo database: &amp;lt;code&amp;gt;ns.db1&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
* Electron-phonon matrix elements (Yambo databases: &amp;lt;code&amp;gt;ndb.elph_gkkp*&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
* Dipole matrix elements (Yambo databases: &amp;lt;code&amp;gt;ndb.dipoles&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboDipolesDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
* Exciton wavefunctions, energy and spectra (Yambo databases: &amp;lt;code&amp;gt;ndb.BS_diago_Q*&amp;lt;/code&amp;gt;, Yambopy class: &amp;lt;code&amp;gt;YamboExcitonDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
We will also check the command line instructions to quickly generate yambo SAVE folders.&lt;br /&gt;
&lt;br /&gt;
The scripts of the tutorial, but not the databases, can be found in the yambopy directory:&lt;br /&gt;
 $cd tutorial/databases_yambopy&lt;br /&gt;
&lt;br /&gt;
The full tutorial, including the Quantum espresso and Yambo databases that we will read, can be downloaded and extracted from the yambo website:&lt;br /&gt;
 $wget https://media.yambo-code.eu/educational/tutorials/files/databases_yambopy.tar.gz&lt;br /&gt;
 $tar -xvzf databases_yambopy.tar.gz&lt;br /&gt;
 $cd databases_yambopy&lt;br /&gt;
&lt;br /&gt;
We will work with monolayer hexagonal boron nitride electron-phonon and exciton data obtained on a &amp;lt;code&amp;gt;12x12x1&amp;lt;/code&amp;gt; kpoint grid. Beware that these are certainly not converged.&lt;br /&gt;
&lt;br /&gt;
=== Command line: generating the Yambo SAVE ===&lt;br /&gt;
Yambopy offers a set of command line options. In order to review them, you can type&lt;br /&gt;
 $yambopy&lt;br /&gt;
which will print the output&lt;br /&gt;
 yambopy&lt;br /&gt;
 Available commands are:&lt;br /&gt;
 &lt;br /&gt;
       plotem1s -&amp;gt;     Plot em1s calculation&lt;br /&gt;
      analysebse -&amp;gt;     Using ypp, you can study the convergence of BSE calculations in 2 ways:&lt;br /&gt;
      analysegw -&amp;gt;     Study the convergence of GW calculations by looking at the change in band-gap value.&lt;br /&gt;
   plotexcitons -&amp;gt;     Plot excitons calculation&lt;br /&gt;
          addqp -&amp;gt;     Add corrections from QP databases.&lt;br /&gt;
        mergeqp -&amp;gt;     Merge QP databases&lt;br /&gt;
           save -&amp;gt;     Produce a SAVE folder&lt;br /&gt;
           gkkp -&amp;gt;     Produce a SAVE folder including elph_gkkp databases&lt;br /&gt;
          bands -&amp;gt;     Script to produce band structure data and visualization from QE.&lt;br /&gt;
         serial -&amp;gt;     Script to update serial numbers of yambo ndb.* databases in order to import them to new calculations.&lt;br /&gt;
           test -&amp;gt;     Run yambopy tests&lt;br /&gt;
&lt;br /&gt;
For this tutorial, we will need the &amp;lt;code&amp;gt;save&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;gkkp&amp;lt;/code&amp;gt; options.&lt;br /&gt;
By typing in one of these, additional information about how to run the commands will be printed, e.g.:&lt;br /&gt;
 $yambopy save&lt;br /&gt;
&lt;br /&gt;
 Produce a SAVE folder&lt;br /&gt;
 &lt;br /&gt;
 Arguments are:&lt;br /&gt;
   -nscf, --nscf_dir  -&amp;gt; Path to nscf save folder&lt;br /&gt;
   -y, --yambo_dir    -&amp;gt; &amp;lt;Optional&amp;gt; Path to yambo executables&lt;br /&gt;
&lt;br /&gt;
The quantum espresso save for hBN is provided in the directory &amp;lt;code&amp;gt;BSE_saves/QE_saves/hBN.save&amp;lt;/code&amp;gt; (you can check the contents of the various folders). &lt;br /&gt;
Then, following the instructions printed on screen, we can generate a yambo SAVE from the hBN.save by typing&lt;br /&gt;
&lt;br /&gt;
 $yambopy save -nscf BSE_saves/QE_saves/hBN.save&lt;br /&gt;
&lt;br /&gt;
This should produce a SAVE folder in the current directory.&lt;br /&gt;
&lt;br /&gt;
=== Lattice intro: plot k-point coordinates in IBZ/BZ ===&lt;br /&gt;
For this section we will use the script &amp;lt;code&amp;gt;bz_plot.py&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
By inspecting the SAVE folder we have just generated, we will find the &amp;lt;code&amp;gt;ns.db1&amp;lt;/code&amp;gt; database which contains all the geometry and lattice information.&lt;br /&gt;
We are now going to read it in python by using the Yambopy class &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
&lt;br /&gt;
 from yambopy import *&lt;br /&gt;
 ylat = YamboLatticeDB.from_db_file(filename=&amp;quot;PATH/TO/SAVE/ns.db1&amp;quot;)&lt;br /&gt;
(remember to edit the variable &amp;lt;code&amp;gt;save_path&amp;lt;/code&amp;gt; in order to point at your yambo SAVE).&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;ylat&amp;lt;/code&amp;gt; object now contains many useful information as attributes, such as the k-points in Cartesian or crystal coordinates, the system symmetries, lattice constants and basis vectors in real and reciprocal space, etc.&lt;br /&gt;
The k-points are also automatically expanded in the full Brillouin zone from the irreducible one (you can turn this off with the option &amp;lt;code&amp;gt;Expand=False&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Directly printing the object with&lt;br /&gt;
 print(ylat)&lt;br /&gt;
will also give us some general parameters related to the database. &lt;br /&gt;
&lt;br /&gt;
Now check the &amp;lt;code&amp;gt;bz_plot.py&amp;lt;/code&amp;gt; script. You will see that it performs three plots: &lt;br /&gt;
* Scatterplot of the k-points in Cartesian coordinates with both expanded and unexpanded grids, with annotated indices [&amp;lt;code&amp;gt;Cartesian_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Scatterplot of the k-points in crystal coordinates [&amp;lt;code&amp;gt;Crystal_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Manual transformation of a chosen k-point from irreducible to full Brillouin zone (you can change the index &amp;lt;code&amp;gt;i_k&amp;lt;/code&amp;gt; in the script to check different cases) [&amp;lt;code&amp;gt;Symmetry_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
[[File:Car kpoints hbn.jpg|YamboLatticeDB plot from yambopy tutorial| 500px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Dipoles intro: plots of dipoles on BZ, plot of IP absorption ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;dipoles_plot.py&amp;lt;/code&amp;gt; and read the dipole databases generated in an optical absorption calculation by yambo. Keep in mind that from now on we will use the &amp;quot;BSE&amp;quot; yambo SAVE generated in the [[#Command line: generating the Yambo SAVE|first section]].&lt;br /&gt;
&lt;br /&gt;
The databases written after a calculation of optical properties with yambo (dipoles, static screening, excitons) are in the directory &amp;lt;code&amp;gt;BSE_saves/BSE_databases&amp;lt;/code&amp;gt;. Here we will also find &amp;lt;code&amp;gt;ndb.dipoles&amp;lt;/code&amp;gt; which is needed now, since it contains the matrix elements d_{vck}(\alpha) where vk and ck are the valence and electron states involved in the transition and \alpha the polarisation direction of the external electric field.&lt;br /&gt;
&lt;br /&gt;
In order to read it in python we use the Yambopy class &amp;lt;code&amp;gt;YamboDipolesDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
 ydip = YamboDipolesDB(ylat,save=&#039;path/to/BSE/databases&#039;,filename=&#039;ndb.dipoles&#039;)&lt;br /&gt;
(notice that it requires a previous instance of &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
In addition, in order to read the Kohn-Sham energies, we can also instance the &amp;lt;code&amp;gt;YamboElectronsDB&amp;lt;/code&amp;gt; as&lt;br /&gt;
 yel = YamboElectronsDB(ylat,save=&#039;path/to/SAVE&#039;)&lt;br /&gt;
&lt;br /&gt;
The object &amp;lt;code&amp;gt;ydip&amp;lt;/code&amp;gt; now has a method that permits to retrieve the independent-particle absorption spectrum with customly chosen energy range, steps, and broadening:&lt;br /&gt;
 w, eps2 = ydip.ip_eps2(yel)&lt;br /&gt;
&lt;br /&gt;
In order to see all this in action, take a look at the &amp;lt;code&amp;gt;dipoles_plot.py&amp;lt;/code&amp;gt; script. You will see that it performs two plots:&lt;br /&gt;
* Plot of |d(k)| in the BZ for selected v,c and \alpha (we choose the layer plane &#039;xy&#039;) [&amp;lt;code&amp;gt;Kspace_Plot=True&amp;lt;/code&amp;gt;]. From this plot you can appreciate which sections of the BZ contribute the most to the absorption rate.&lt;br /&gt;
* Plot of the independent-particles absorption spectrum [&amp;lt;code&amp;gt;Absorption_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
You can play with the indices and the plot parameters to check what happens.&lt;br /&gt;
&lt;br /&gt;
[[File:Dipoles hbn.jpg|YamboDipolesDB plot from yambopy tutorial|500px]]&lt;br /&gt;
&lt;br /&gt;
=== Exciton intro 1: read and sort data ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;exc_read.py&amp;lt;/code&amp;gt; and read the exciton data resulting from a BSE calculation in order to familiarise with their structure. This time we are going to read the &amp;lt;code&amp;gt;ndb.BS_diago_Q*&amp;lt;/code&amp;gt; databases which correspond to BSE calculations at various momenta Q (Q=1 being the zero-momentum optical absorption limit - notice that python indexing starts from 0, while the databases are counted starting from 1).&lt;br /&gt;
&lt;br /&gt;
In order to read them in python we use the Yambopy class &amp;lt;code&amp;gt;YamboExcitonDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
 yexc = YamboExcitonDB.from_db_file(ylat,filename=&#039;path/to/BSE/databases/ndb.BS_diago_Q%d&#039;(i_Q+1))&lt;br /&gt;
(notice that it requires a previous instance of &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Now the &amp;lt;code&amp;gt;yexc&amp;lt;/code&amp;gt; object contains information about the exciton energies (&amp;lt;code&amp;gt;yexc.eigenvalues&amp;lt;/code&amp;gt;), wave functions (&amp;lt;code&amp;gt;yexc.eigenvectors&amp;lt;/code&amp;gt;) and intensities (&amp;lt;code&amp;gt;yexc.l_residuals&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;yexc.r_residuals&amp;lt;/code&amp;gt;) for Qpoint i_Q. You can start by keeping &amp;lt;code&amp;gt;Q1&amp;lt;/code&amp;gt; which is the optical limit and then check other momenta.&lt;br /&gt;
&lt;br /&gt;
The exciton wave function components A_{vck}^{\lambda Q} (\lambda being the exciton index) are stored as A_{t}^{\lambda} in each Q-dependent database, with t being the transition index grouping the single-particle indices vck. Therefore, &amp;lt;code&amp;gt;yexc.eigenvectors&amp;lt;/code&amp;gt; is an array with (N_excitons,N_transitions) dimension. In order to make the connection t-&amp;gt;kcv, the table &amp;lt;code&amp;gt;yexc.table&amp;lt;/code&amp;gt; provides k,v,c and spin indices corresponding to each transition.&lt;br /&gt;
&lt;br /&gt;
In order to get a clearer picture, take a look at the script &amp;lt;code&amp;gt;exc_read.py&amp;lt;/code&amp;gt;. Run it and try to understand the outputs.&lt;br /&gt;
  $ python exc_read.py&lt;br /&gt;
&lt;br /&gt;
=== Exciton intro 2: plot exciton weights on k-BZ and (interpolated) band structure ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;exc_kspace_plot.py&amp;lt;/code&amp;gt; and work with the quantities defined in the previous section.&lt;br /&gt;
&lt;br /&gt;
For now, only the i_Q=0 case is implemented in this section.&lt;br /&gt;
We want to check the relative importance of the various (vk-&amp;gt;ck) electronic transitions in forming a certain excitonic state. &lt;br /&gt;
&lt;br /&gt;
Since many excitonic states are degenerate, we first need to tell Yambopy which states we want to check. For example, in monolayer hexagonal boron nitride, the lowest-bound exciton - forming the main peak in the BSE absorption spectrum - is doubly degenerate. In order to analyse it, in the &amp;lt;code&amp;gt;exc_kspace_plot.py&amp;lt;/code&amp;gt; script we set&lt;br /&gt;
 states = [1,2]&lt;br /&gt;
(we can also set [3,4] to check the second excitonic state, and then [5] for the non-degenerate third state, and so on; we can check degeneracies by printing the energies using the script &amp;lt;code&amp;gt;exc_read.py&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
In order to make a band structure plot, it is necessary to read the band energies, for example with the &amp;lt;code&amp;gt;YamboSaveDB&amp;lt;/code&amp;gt; class&lt;br /&gt;
 yel = YamboSaveDB.from_db_file(folder=&#039;path/to/SAVE&#039;)&lt;br /&gt;
and specify the path in the BZ using crystal coordinates via the &amp;lt;code&amp;gt;Path&amp;lt;/code&amp;gt; function:   &lt;br /&gt;
 npoints = 20&lt;br /&gt;
 path = Path([ [[  0.0,  0.0,  0.0],&#039;$\Gamma$&#039;],&lt;br /&gt;
               [[  0.5,  0.0,  0.0],&#039;M&#039;],&lt;br /&gt;
               [[1./3.,1./3.,  0.0],&#039;K&#039;],&lt;br /&gt;
               [[  0.0,  0.0,  0.0],&#039;$\Gamma$&#039;]],&lt;br /&gt;
               [int(npoints*2),int(npoints),int(sqrt(5)*npoints)] )&lt;br /&gt;
&lt;br /&gt;
Now let&#039;s take a closer look at the &amp;lt;code&amp;gt;exc_kspace_plot.py&amp;lt;/code&amp;gt; script. You will see that it performs three plots:&lt;br /&gt;
* Plot of |A(k)| in the k-BZ for the selected exciton state. You can see how most contributions come from the area around K and the MK direction [&amp;lt;code&amp;gt;Kspace_Plot=True&amp;lt;/code&amp;gt;]. &lt;br /&gt;
* Plot of |A(v,c,k)| on the electronic band structure for the selected exciton state. Here you can better see how the top valence and bottom conduction around MK are mostly involved [&amp;lt;code&amp;gt;Bands_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Plot of interpolated |A(v,c,k)| on the interpolated electronic band structure for the selected exciton state [&amp;lt;code&amp;gt;Bands_Plot_Interpolated=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
As always, try to play with the parameters, for example by changing the excitonic states to analyse.&lt;br /&gt;
&lt;br /&gt;
[[File:Exc bands1 hbn.jpg|YamboExcitonDB plot from yambopy tutorial|300px| Uninterpolated exciton weights on top of band structure]][[File:Exc bands2 hbn.jpg|YamboExcitonDB plot from yambopy tutorial|300px]]&lt;br /&gt;
&lt;br /&gt;
=== Exciton intro 3: plot BSE optical absorption with custom options ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;exc_abs_plot.py&amp;lt;/code&amp;gt; and work with the quantities defined in the previous sections.&lt;br /&gt;
&lt;br /&gt;
The class &amp;lt;code&amp;gt;YamboExcitonDB&amp;lt;/code&amp;gt; also enables us, of course, to read the dielectric function eps(w) and print absorption and related spectra in python.&lt;br /&gt;
&lt;br /&gt;
The advantages over using the standard human-readable yambo outputs are mainly two:&lt;br /&gt;
# We can freely select energy ranges, energy steps, peak broadenings and number of excitonic states included without having to rerun the &amp;lt;code&amp;gt;yambo&amp;lt;/code&amp;gt; executable every time. This reduces the chance of mistakenly editing the yambo input and allows for greater freedom since these plots can now be done in your local machine without having to transfer the output data from a remote cluster.&lt;br /&gt;
# The dielectric function constructed from netCDF database variables has a much higher precision (number of significant digits) than the human readable output, which may be important if you want to perform additional operations in python (e.g., computing refractive index, reflectivity and other optical spectra from it, performing finite-difference derivatives, etc).&lt;br /&gt;
&lt;br /&gt;
We can read eps(w) as a &amp;lt;code&amp;gt;numpy&amp;lt;/code&amp;gt; array with the specified options as (energy values are in eV):&lt;br /&gt;
 w, eps = yexc.get_chi(nexcitons=&#039;all&#039;,emin=0,emax=7,estep=0.005,broad=0.04)&lt;br /&gt;
Or, you can directly prepare a plot of its imaginary part with&lt;br /&gt;
 w, chi = yexc.plot_chi_ax(ax,nexcitons=&#039;all&#039;,emin=0,emax=7,estep=0.005,broad=0.04)&lt;br /&gt;
where &amp;lt;code&amp;gt;ax&amp;lt;/code&amp;gt; is a previously defined &amp;lt;code&amp;gt;Axes&amp;lt;/code&amp;gt; object from &amp;lt;code&amp;gt;matplotlib&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In order to see how this works, let&#039;s take a look at the &amp;lt;code&amp;gt;exc_abs_plot.py&amp;lt;/code&amp;gt; script.&lt;br /&gt;
You will see that it performs the two operations described above:&lt;br /&gt;
* Plotting the BSE absorption spectrum [&amp;lt;code&amp;gt;Absorption_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Reading the complex dielectric function.&lt;br /&gt;
&lt;br /&gt;
Try to customise the plots by changing the &amp;lt;code&amp;gt;nexcitons&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;emin&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;emax&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;estep&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;broad&amp;lt;/code&amp;gt; parameters.&lt;br /&gt;
&lt;br /&gt;
[[File:Exc abs hbn.jpg|YamboExcitonDB plot from yambopy tutorial|500px]]&lt;br /&gt;
&lt;br /&gt;
=== Command line: importing electron-phonon matrix elements ===&lt;br /&gt;
You may have seen how to calculate and import electron-phonon matrix elements in yambo in the [[Electron Phonon Coupling|electron-phonon tutorial]].&lt;br /&gt;
&lt;br /&gt;
With Yambopy, we can generate a yambo SAVE folder and import the matrix elements with a single command.&lt;br /&gt;
Typing &lt;br /&gt;
 $yambopy gkkp&lt;br /&gt;
will print the necessary documentation:&lt;br /&gt;
 Produce a SAVE folder including elph_gkkp databases&lt;br /&gt;
 &lt;br /&gt;
 Arguments are:&lt;br /&gt;
   -nscf, --nscf_dir  -&amp;gt; &amp;lt;Optional&amp;gt; Path to nscf save folder&lt;br /&gt;
   -elph, --elph_dir  -&amp;gt; Path to elph_dir folder&lt;br /&gt;
   -y, --yambo_dir    -&amp;gt; &amp;lt;Optional&amp;gt; Path to yambo executables&lt;br /&gt;
   -e, --expand       -&amp;gt; &amp;lt;Optional&amp;gt; Expand gkkp databases&lt;br /&gt;
&lt;br /&gt;
The necessary quantum espresso databases are stored in &amp;lt;code&amp;gt;ELPH_SAVES/QE_SAVES/hBN.save&amp;lt;/code&amp;gt; (nscf calculation) and &amp;lt;code&amp;gt;ELPH_SAVES/QE_SAVES/elph_dir&amp;lt;/code&amp;gt; (matrix elements from the dfpt calculation). For this tutorial we also need to expand the electron-phonon matrix elements to the full Brillouin zone. Since this is a different calculation with respect to the previous section, please generate this SAVE in a different directory than the one you used for the previous SAVE, which should be the current directory.&lt;br /&gt;
For example:&lt;br /&gt;
 $mkdir yambo-with-elph&lt;br /&gt;
 $cd yambo-with-elph&lt;br /&gt;
&lt;br /&gt;
Now we can run yambopy as in the instructions:&lt;br /&gt;
 $yambopy gkkp -nscf ../ELPH_saves/QE_saves/hBN.save -elph ../ELPH_saves/QE_saves/elph_dir --expand&lt;br /&gt;
This should generate a yambo SAVE folder which contains the &amp;lt;code&amp;gt;ndb.elph_gkkp_expanded*&amp;lt;/code&amp;gt; databases.&lt;br /&gt;
&lt;br /&gt;
=== Electron-phonon intro: plots of el-ph matrix elements on k-BZ and q-BZ ===&lt;br /&gt;
In this section we will use the script &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; and read the electron-phonon databases that you generated in the previous section.&lt;br /&gt;
&lt;br /&gt;
In order to read the &amp;lt;code&amp;gt;ndb.elph_gkkp_expanded*&amp;lt;/code&amp;gt; databases in python we use the Yambopy class &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt;, which can be instanced like this:&lt;br /&gt;
 yelph = YamboElectronPhononDB(ylat,folder_gkkp=&#039;path/to/elph/folder&#039;,save=&#039;path/to/SAVE&#039;)&lt;br /&gt;
(notice that it requires a previous instance of &amp;lt;code&amp;gt;YamboLatticeDB&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Now, the &amp;lt;code&amp;gt;yelph&amp;lt;/code&amp;gt; object contains phonon frequencies, phonon eigenvectors, qpoint information and, of course, the electron-phonon matrix elements g_{nm\nu}(k,q) where n, m are electron band states, \nu is a phonon branch, and k and q are the electronic and transfer momenta.&lt;br /&gt;
&lt;br /&gt;
We can print the docstring of the &amp;lt;code&amp;gt;YamboElectronPhononDB&amp;lt;/code&amp;gt; class with&lt;br /&gt;
 print(yelph.__doc__)&lt;br /&gt;
to get an idea of the information stored and of its capabilities.&lt;br /&gt;
&lt;br /&gt;
Now check the &amp;lt;code&amp;gt;elph_plot.py&amp;lt;/code&amp;gt; script. You will see that it performs two plots: &lt;br /&gt;
* Plot of |g(k)| in the k-BZ for selected n,m,\nu and q [&amp;lt;code&amp;gt;Kspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
* Plot of |g(q)| in the q-BZ for selected n,m,\nu and k [&amp;lt;code&amp;gt;Qspace_Plot=True&amp;lt;/code&amp;gt;].&lt;br /&gt;
&lt;br /&gt;
You can change the electronic, phononic and momentum indices to see what happens.&lt;br /&gt;
&lt;br /&gt;
[[File:Elph hbn.jpg|YamboElectronPhononDB plot from yambopy tutorial|500px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Links==&lt;br /&gt;
* Back to [[Rome 2023#Tutorials]]&lt;br /&gt;
* Back to [[ICTP 2022#Tutorials]]&lt;/div&gt;</summary>
		<author><name>Fulvio</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_band_structures&amp;diff=7619</id>
		<title>Yambopy tutorial: band structures</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_band_structures&amp;diff=7619"/>
		<updated>2024-02-07T14:01:29Z</updated>

		<summary type="html">&lt;p&gt;Fulvio: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
This tutorial will show you how to visualise wave-function and band-structure related information following a DFT Quantum Espresso calculation using the &amp;quot;qepy&amp;quot; module of Yambopy.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Concerning the ICTP school: recall that for the yambopy tutorials you have to load the yambo, quantum-espresso and anaconda3 modules:&#039;&#039;&#039;&lt;br /&gt;
 spack load yambo&lt;br /&gt;
 spack load quantum-espresso&lt;br /&gt;
 spack load anaconda3&lt;br /&gt;
&#039;&#039;&#039;You can copy the tutorial databases as explained in the virtual machine setup page: &#039;&#039;&#039;&lt;br /&gt;
 cp -r /media/ictpuser/smr3694/ictptutor/YAMBOPY_TUTORIALS ~/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The full tutorial, including the Quantum espresso and Yambo databases that we will read, can be downloaded and extracted from the yambo website:&lt;br /&gt;
 $wget https://media.yambo-code.eu/educational/tutorials/files/databases_qepy.tar.gz&lt;br /&gt;
 $tar -xvf databases_qepy.tar&lt;br /&gt;
 $cd databases_qepy&lt;br /&gt;
&lt;br /&gt;
==Tutorial 1. BN (semiconductor). Band structure==&lt;br /&gt;
&lt;br /&gt;
First enter in the folder &lt;br /&gt;
 cd databases_qepy/bn-semiconductor&lt;br /&gt;
and have a look to the &lt;br /&gt;
 vim plot-qe-bands.py&lt;br /&gt;
The qepy classes are useful both to execute Quantum Espresso and to analyze the results. Enter in the python environment, by typing &amp;lt;code&amp;gt;python&amp;lt;/code&amp;gt;, then the full qepy library is imported by simply doing:&lt;br /&gt;
&lt;br /&gt;
 from qepy import *&lt;br /&gt;
&lt;br /&gt;
===Plot Band structure===&lt;br /&gt;
&lt;br /&gt;
The qepy class &#039;&#039;&#039;PwXML&#039;&#039;&#039; reads the data file generated by Quantum Espresso and post-processes the data. The class is instanced by doing:&lt;br /&gt;
&lt;br /&gt;
 xml = PwXML(prefix=&#039;bn&#039;, path=&#039;bands&#039;)&lt;br /&gt;
&lt;br /&gt;
The variable prefix corresponds to the same variable of the QE input. The folder location is indicated by variable path. In order to plot the bands, we also define the k-points path (in crystal coordinates) using the function Path:&lt;br /&gt;
&lt;br /&gt;
 npoints = 50&lt;br /&gt;
 path_kpoints = Path([ [[0.0, 0.0, 0.0],&#039;$\Gamma$&#039;],&lt;br /&gt;
                       [[0.5, 0.0, 0.0],&#039;M&#039;],&lt;br /&gt;
                       [[1./3,1./3,0.0],&#039;K&#039;],&lt;br /&gt;
                       [[0.0, 0.0, 0.0],&#039;$\Gamma$&#039;]], [int(npoints*2),int(npoints),int(sqrt(5)*npoints)])&lt;br /&gt;
&lt;br /&gt;
It is worth to note that the path should coincide with the selected path for the QE band calculations.&lt;br /&gt;
&lt;br /&gt;
In order to show the plot we call the &#039;&#039;&#039;plot_eigen&#039;&#039;&#039; method of the &#039;&#039;&#039;PwXML&#039;&#039;&#039; class:&lt;br /&gt;
&lt;br /&gt;
 xml.plot_eigen(path_kpoints)&lt;br /&gt;
&lt;br /&gt;
This function will automatically plot the bands as shown below running the script:&lt;br /&gt;
&lt;br /&gt;
 python plot-qe-bands.py&lt;br /&gt;
&lt;br /&gt;
[[File:Bands BN 1.png| 400 px | center |Band structure of BN calculated at the level of DFT-LDA]]&lt;br /&gt;
&lt;br /&gt;
Alternatively, we can use the function &#039;&#039;&#039;plot_eigen_ax&#039;&#039;&#039;. This functions requires as input a matplotlib &#039;&#039;&#039;figure&#039;&#039;&#039; object with given axes, as you will see in the next example.&lt;br /&gt;
&lt;br /&gt;
===Plot atomic orbital projected Band structure===&lt;br /&gt;
&lt;br /&gt;
In addition to the band structure, useful information regarding the atomic orbital nature of the electronic wave functions can be displayed using the class &#039;&#039;&#039;ProjwfcXML&#039;&#039;&#039;. &lt;br /&gt;
In order to make quantum espresso calculate the relevant data, we need to use the QE executable &#039;&#039;&#039;projwfc.x&#039;&#039;&#039;, which will create the file &#039;&#039;&#039;atomic_proj.xml&#039;&#039;&#039;. This executable projects the Kohn-Sham wavefunctions onto orthogonalized atomic orbitals, among others functionalities. The orbital indexing  and ordering are explained in the input documentation of the projwfc.x function which you are invited to check (https://www.quantum-espresso.org/Doc/INPUT_PROJWFC.html#idm94). We can run &#039;&#039;&#039;projwf.x&#039;&#039;&#039; directly from the python script using the qepy class &#039;&#039;&#039;ProjwfcIn&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
 proj = ProjwfcIn(prefix=&#039;bn&#039;)&lt;br /&gt;
 proj.run(folder=&#039;bands&#039;)&lt;br /&gt;
&lt;br /&gt;
Be aware that this can take a while in a large system with many k-points. As in the class &#039;&#039;&#039;PwXML&#039;&#039;&#039;, we then define the path_kpoints and also the selected atomic orbitals to project our bands. We have chosen to represent the projection weight onto the nitrogen (1) and boron (2) orbitals, which according to the projection orderings is given by&lt;br /&gt;
&lt;br /&gt;
 atom_1 = list(range(16))&lt;br /&gt;
 atom_2 = list(range(16,32)) &lt;br /&gt;
&lt;br /&gt;
The full list of orbitals is written in the file &#039;&#039;&#039;bands/prowfc.log&#039;&#039;&#039;. We have also defined the figure box&lt;br /&gt;
&lt;br /&gt;
 import matplotlib.pyplot as plt&lt;br /&gt;
 fig = plt.figure(figsize=(5,7))&lt;br /&gt;
 ax  = fig.add_axes( [ 0.12, 0.10, 0.70, 0.80 ])&lt;br /&gt;
&lt;br /&gt;
The class &#039;&#039;&#039;ProjwfcXML&#039;&#039;&#039; then runs as in this example:&lt;br /&gt;
&lt;br /&gt;
 band = ProjwfcXML(prefix=&#039;bn&#039;,path=&#039;bands&#039;,qe_version=&#039;7.0&#039;)&lt;br /&gt;
 band.plot_eigen(ax,path_kpoints=path_kpoints,cmap=&#039;viridis&#039;,selected_orbitals=atom_1,selected_orbitals_2=atom_2)&lt;br /&gt;
&lt;br /&gt;
We can run now the file:&lt;br /&gt;
&lt;br /&gt;
 python plot-qe-orbitals.py&lt;br /&gt;
&lt;br /&gt;
[[File:Bands AOP BN 1.png| 400 px | center | Atomic orbital projected band structure of monolayer BN]]&lt;br /&gt;
&lt;br /&gt;
We have chosen the colormap &#039;viridis&#039; (variable cmap). You see that the colormap goes from maximum &#039;&#039;&#039;selected_orbitals&#039;&#039;&#039; content (in this case nitrogen) to the maximum &#039;&#039;&#039;selected_orbitals_2&#039;&#039;&#039; content (in this case boron). &lt;br /&gt;
The colormap can be represented in many ways and qepy does not include a particular function for this. An example is:&lt;br /&gt;
&lt;br /&gt;
 import matplotlib as mpl&lt;br /&gt;
 cmap=plt.get_cmap(&#039;viridis&#039;)&lt;br /&gt;
 bx  = fig.add_axes( [ 0.88, 0.10, 0.05, 0.80 ])&lt;br /&gt;
 norm = mpl.colors.Normalize(vmin=0.,vmax=1.)&lt;br /&gt;
 cb1 = mpl.colorbar.ColorbarBase(bx, cmap=cmap, norm=norm,orientation=&#039;vertical&#039;,ticks=[0,1])&lt;br /&gt;
 cb1.set_ticklabels([&#039;B&#039;, &#039;N&#039;])&lt;br /&gt;
&lt;br /&gt;
We can also plot the band orbital charater with size variation instead of a color scale. In this case we have to pass only the variable selected_orbitals (see the next tutorial).&lt;br /&gt;
&lt;br /&gt;
==Tutorial 2. Iron. Ferromagnetic metalic material==&lt;br /&gt;
&lt;br /&gt;
In the case of spin-polarized calculations we can plot the spin up and down band structures. We have included in the tutorial a small workflow example to run quantum espresso calculations from scratch. This is done using the classes Tasks and Flows developed in yambopy. You can check the file flow-iron.py for an example. &lt;br /&gt;
Yambopy includes basic predefined workflows to run the common QE and Yambo calculations. In this case we are using the class &#039;&#039;&#039;PwBandsTasks&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
 python flow-iron.py&lt;br /&gt;
&lt;br /&gt;
In order to plot the spin-polarized bands. After doing all the calculations from scratch with the flows (flow-iron.py), we can make the band plot by running the script:&lt;br /&gt;
&lt;br /&gt;
 python plot-qe-bands.py&lt;br /&gt;
&lt;br /&gt;
The class PwXML automatically detects the spin polarized case (nspin=2 in the QE input file). The spin up channel is displayed with red and the spin down channel with blue. In the case of iron we have selected this k-point path:&lt;br /&gt;
&lt;br /&gt;
 npoints = 50&lt;br /&gt;
 path_kpoints = Path([ [[0.0, 0.0, 0.0 ],&#039;G&#039;],&lt;br /&gt;
                       [[0.0, 0.0, 1.0 ],&#039;H&#039;],&lt;br /&gt;
                       [[1./2,0.0,1./2.],&#039;N&#039;],&lt;br /&gt;
                       [[0.0, 0.0, 0.0 ],&#039;G&#039;],&lt;br /&gt;
                       [[1./2, 1./2, 1./2 ],&#039;P&#039;],&lt;br /&gt;
                       [[1./2,0.0,1./2. ],&#039;N&#039;]], [npoints,npoints,npoints,npoints,npoints])&lt;br /&gt;
&lt;br /&gt;
 xml = PwXML(prefix=&#039;pw&#039;,path=&#039;bands/t0&#039;)&lt;br /&gt;
 xml.plot_eigen(path_kpoints)&lt;br /&gt;
&lt;br /&gt;
[[File:Figure 3-iron-bands.png| 600 px | center |Spin polarized band structure of iron calculated by DFT]]&lt;br /&gt;
&lt;br /&gt;
The analysis of the projected atomic orbitals is also implemented. In this case the results are more cumbersome because the projection is separated in spin up and down channels.&amp;lt;br&amp;gt; &lt;br /&gt;
Let us look first at the file &#039;&#039;&#039;plot-qe-orbitals-size&#039;&#039;&#039;. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NB: If you generated the quantum espresso databases using the flows instead of relying on the precomputed databases, you also need to rerun the quantum espresso executable projwfc.x to recompute the orbital projections. In this case, please uncomment the following lines in the script&#039;&#039;&#039; (plot-qe-orbitals-size.py) :&lt;br /&gt;
 #proj = ProjwfcIn(prefix=&#039;pw&#039;)&lt;br /&gt;
 #proj.run(folder=&#039;bands/t0&#039;)&lt;br /&gt;
&lt;br /&gt;
Now, we can use the dot size as a function of the weight of the orbitals&lt;br /&gt;
 atom_s = [8]&lt;br /&gt;
 atom_p = [0,1,2]&lt;br /&gt;
 atom_d = [3,4,5,6,7]&lt;br /&gt;
&lt;br /&gt;
and the plots are done with&lt;br /&gt;
 band = ProjwfcXML(prefix=&#039;pw&#039;,path=&#039;bands/t0&#039;,qe_version=&#039;7.0&#039;)&lt;br /&gt;
 band.plot_eigen(ax,path_kpoints=path_kpoints,&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;selected_orbitals=atom_s,&amp;lt;/span&amp;gt;color=&#039;pink&#039;,color_2=&#039;black&#039;)&lt;br /&gt;
 band.plot_eigen(ax,path_kpoints=path_kpoints,&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;selected_orbitals=atom_p,&amp;lt;/span&amp;gt;color=&#039;green&#039;,color_2=&#039;orange&#039;)&lt;br /&gt;
 band.plot_eigen(ax,path_kpoints=path_kpoints,&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;selected_orbitals=atom_d,&amp;lt;/span&amp;gt;color=&#039;red&#039;,color_2=&#039;blue&#039;)&lt;br /&gt;
&lt;br /&gt;
As an example, we can select just the &#039;&#039;d&#039;&#039; orbitals by commenting the first two plots and then running the file:&lt;br /&gt;
&lt;br /&gt;
 plot-qe-orbitals-size.py&lt;br /&gt;
&lt;br /&gt;
[[File:Figure 4-iron-bands-size-d-orbitals.png|400px|center|Iron band structure. Size is proportional to the weights of the projection on atomic d-orbitals. Red (blue) is up (down) spin polarization.]]&lt;br /&gt;
&lt;br /&gt;
From the plot is clear that &#039;&#039;d&#039;&#039; orbitals are mainly localized around the Fermi energy. The plot above is in red and blue, while the default choice in your script should be pink and black. You can experiment with the colors and other &#039;&#039;matplotlib&#039;&#039; plot options and also plot the other orbital types.&lt;br /&gt;
&lt;br /&gt;
Another option is to plot the orbital composition as a colormap running the file:&lt;br /&gt;
&lt;br /&gt;
 plot-qe-orbitals-colormap.py&lt;br /&gt;
&lt;br /&gt;
[[File:Figure 5-iron-bands-colormap.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
Here we have added the p and d orbitals in the analysis:&lt;br /&gt;
&lt;br /&gt;
 atom_p = [0,1,2]&lt;br /&gt;
 atom_d = [3,4,5,6,7]&lt;br /&gt;
 band = ProjwfcXML(prefix=&#039;pw&#039;,path=&#039;bands/t0&#039;,qe_version=&#039;7.0&#039;)&lt;br /&gt;
 band.plot_eigen(ax,path_kpoints=path_kpoints,cmap=&#039;viridis&#039;,cmap2=&#039;rainbow&#039;,selected_orbitals=atom_p,selected_orbitals_2=atom_d)&lt;br /&gt;
&lt;br /&gt;
The colormap bar is added in the same way as in Tutorial 1 (see script), but this time we have a different colormap for each spin polarisation.&lt;br /&gt;
&lt;br /&gt;
==Tutorial 3: GW bands==&lt;br /&gt;
&lt;br /&gt;
Yambopy can be used either to run Yambo and QE calculations, or to analyse the results of QE and Yambo by dealing with their generated databases. This is done with a variety of classes included in the qepy (for QE) or yambopy (for Yambo) modules. &lt;br /&gt;
In the case of Yambo GW quasi-particle calculations, we can use the yambopy class &#039;&#039;&#039;YamboQPDB&#039;&#039;&#039; to read the database produced by the simulation.&lt;br /&gt;
Enter in the folder&lt;br /&gt;
 cd ../gw-bands&lt;br /&gt;
We can use this to find the scissor operator, plot the GW bands and to interpolate the GW bands on a smoother k-path. The example runs by typing:&lt;br /&gt;
&lt;br /&gt;
 python plot-qp.py&lt;br /&gt;
&lt;br /&gt;
See below for an explanation of the tutorial. As usual, we can import the qepy and yambopy libraries:&lt;br /&gt;
&lt;br /&gt;
  from qepy import *&lt;br /&gt;
  from yambopy import *&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
&lt;br /&gt;
We define the k-points path.&lt;br /&gt;
  npoints = 10&lt;br /&gt;
  path = Path([ [[  0.0,  0.0,  0.0],&#039;$\Gamma$&#039;],&lt;br /&gt;
                [[  0.5,  0.0,  0.0],&#039;M&#039;],&lt;br /&gt;
                [[1./3.,1./3.,  0.0],&#039;K&#039;],&lt;br /&gt;
                [[  0.0,  0.0,  0.0],&#039;$\Gamma$&#039;]], [int(npoints*2),int(npoints),int(sqrt(5)*npoints)] )&lt;br /&gt;
&lt;br /&gt;
Importantly, the number of points is a free choice. We can increase the variable npoints as we wish, it just means that the interpolation step will take more time. In order to analyse GW results we need to have the file related to the basic data of our Yambo calculation (&#039;&#039;&#039;SAVE/ns.db1&#039;&#039;&#039;) and the netcdf file with the quasi-particle results (&#039;&#039;&#039;ndb.QP&#039;&#039;&#039;). We load the data calling the respective classes:&lt;br /&gt;
&lt;br /&gt;
 # Read Lattice information from SAVE&lt;br /&gt;
 lat  = YamboSaveDB.from_db_file(folder=&#039;SAVE&#039;,filename=&#039;ns.db1&#039;)&lt;br /&gt;
 # Read QP database&lt;br /&gt;
 ydb  = YamboQPDB.from_db(filename=&#039;ndb.QP&#039;,folder=&#039;qp-gw&#039;)&lt;br /&gt;
(in the yambopy module, each class is specialised to read a specific Yambo database)&lt;br /&gt;
&lt;br /&gt;
The first option is to plot the energies and calculate the ideal Kohn-Sham to GW scissor operator. We need to select the index of the top valence band:&lt;br /&gt;
&lt;br /&gt;
 n_top_vb = 4&lt;br /&gt;
 ydb.plot_scissor_ax(ax,n_top_vb)&lt;br /&gt;
&lt;br /&gt;
Yambopy displays the fitting and also the data of the slope of each fitting. Notice that this is also a test if the GW calculations are running well. &#039;&#039;&#039;If the dependence is not linear you should double-check your results!&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[[File:Figure 6-slope-scissor.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
In this case the slope is:&lt;br /&gt;
&lt;br /&gt;
 valence bands:&lt;br /&gt;
 slope:     1.0515886598785766&lt;br /&gt;
 conduction bands:&lt;br /&gt;
 slope:     1.026524081134514&lt;br /&gt;
 scissor list (shift,c,v) [eV,adim,adim]: [1.8985204833551723, 1.026524081134514, 1.0515886598785766]&lt;br /&gt;
&lt;br /&gt;
In addition to the scissor operator, we can plot the GW (and DFT) band structure along the path. The first choice would be to plot the actual GW calculations, without interpolation, to check that the results are meaningful (or not). This plot is independent of the number of k-points (&#039;&#039;&#039;npoints&#039;&#039;&#039;) that we want to put in the interpolation. The class YamboQPDB finds the calculated points that belong to the path and plots them. Be aware that if we use coarse grids the class would not find any point and the function will not work.&lt;br /&gt;
&lt;br /&gt;
 ks_bs_0, qp_bs_0 = ydb.get_bs_path(lat,path)&lt;br /&gt;
 ks_bs_0.plot_ax(ax,legend=True,color_bands=&#039;r&#039;,label=&#039;KS&#039;)&lt;br /&gt;
 qp_bs_0.plot_ax(ax,legend=True,color_bands=&#039;b&#039;,label=&#039;QP-GW&#039;)&lt;br /&gt;
&lt;br /&gt;
[[File:Figure 7-GW-band-structure-non-interpolated.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
The interpolation of the DFT and GW band structures looks similar:&lt;br /&gt;
&lt;br /&gt;
 ks_bs, qp_bs = ydb.interpolate(lat,path,what=&#039;QP+KS&#039;,lpratio=20)&lt;br /&gt;
 ks_bs.plot_ax(ax,legend=True,color_bands=&#039;r&#039;,label=&#039;KS&#039;)&lt;br /&gt;
 qp_bs.plot_ax(ax,legend=True,color_bands=&#039;b&#039;,label=&#039;QP-GW&#039;)&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;lpratio&#039;&#039;&#039; can be increased if the interpolation does not work as well as intended. The interpolation is the same one implemented in abipy and currently requires abipy installed in order to work.&lt;br /&gt;
&lt;br /&gt;
[[File:Figure 8-GW-band-structure-interpolated.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
Finally, we can compare the calculated GW eigenvalues with the interpolation.&lt;br /&gt;
&lt;br /&gt;
[[File:Figure 8-GW-band-structure-comparison.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
==Links==&lt;br /&gt;
* Back to [[Rome 2023#Tutorials]]&lt;br /&gt;
* Back to [[ICTP 2022#Tutorials]]&lt;/div&gt;</summary>
		<author><name>Fulvio</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=First_steps_in_Yambopy&amp;diff=7618</id>
		<title>First steps in Yambopy</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=First_steps_in_Yambopy&amp;diff=7618"/>
		<updated>2024-02-07T14:01:04Z</updated>

		<summary type="html">&lt;p&gt;Fulvio: /* Tutorials */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The yambopy project aims to develop python tools to: &lt;br /&gt;
&lt;br /&gt;
* Read and edit yambo and quantum espresso input files&lt;br /&gt;
* Easily perform pre- and post-processing of the simulation data for these two codes - including hard-to-get, database-encoded data beyond standard outputs&lt;br /&gt;
* Provide easy visualization and plotting options &lt;br /&gt;
* Set up simple automatization workflows (e.g., convergence tests)&lt;br /&gt;
&lt;br /&gt;
=== Setup ===&lt;br /&gt;
First of all, make sure that you have a suitable python environment (crated for example with [https://docs.conda.io/projects/miniconda/en/latest/| conda] or [https://docs.python.org/3/library/venv.html| venv]) with python &amp;gt;=3.8.&lt;br /&gt;
&lt;br /&gt;
Then, you may install yambopy in one of the following ways.&lt;br /&gt;
&lt;br /&gt;
==== Quick installation from PyPI repository ====&lt;br /&gt;
&lt;br /&gt;
* In order to quickly install the officially released version type:&lt;br /&gt;
&lt;br /&gt;
 pip install yambopy&lt;br /&gt;
&lt;br /&gt;
==== Installation from tarball ====&lt;br /&gt;
&lt;br /&gt;
* In case you don&#039;t want to download from the pip repository and prefer to install a version of yambopy locally, you may download the appropriate tarball from the [https://github.com/yambo-code/yambopy/releases| yambopy github page]. Extract the tarball, enter the yambopy folder and type &amp;lt;code&amp;gt;pip install .&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Installation of latest patch ====&lt;br /&gt;
&lt;br /&gt;
* In case you want the latest version of the code including new updates and patches that might not be present in the official version, then you can clone the yambopy git repository (a basic knowledge of git may be helpful):&lt;br /&gt;
&lt;br /&gt;
 git clone https://github.com/yambo-code/yambopy.git&lt;br /&gt;
 cd yambopy&lt;br /&gt;
 pip install .&lt;br /&gt;
&lt;br /&gt;
==== Dependencies ====&lt;br /&gt;
&lt;br /&gt;
* In principle, &amp;lt;code&amp;gt;pip&amp;lt;/code&amp;gt; should take care of the required python dependencies. They are &amp;lt;code&amp;gt;numpy&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;scipy&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;matplotlib&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;netCDF4&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;lxml&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;PyYAML&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;monty&amp;lt;/code&amp;gt;. In case some dependency-related problem arises, you can install each of them separately beforehand with:&lt;br /&gt;
&lt;br /&gt;
 pip install &amp;lt;code&amp;gt;dependency-name&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Tutorials ===&lt;br /&gt;
Now yambopy is ready to use! Just go to the tutorials folder and follow the docs!&lt;br /&gt;
&lt;br /&gt;
 cd tutorial/&lt;br /&gt;
&lt;br /&gt;
On this wiki, we provide steps for the following tutorials:&lt;br /&gt;
* [[GW tutorial. Convergence and approximations (BN)]]&lt;br /&gt;
* [[Bethe-Salpeter equation tutorial. Optical absorption (BN)]]&lt;br /&gt;
* [[Yambopy tutorial: band structures | Database and plotting tutorial for quantum espresso: qepy]] (Get the databases: [https://media.yambo-code.eu/educational/tutorials/files/databases_qepy.tar.gz databases_qepy], 59MB)&lt;br /&gt;
* [[Yambopy tutorial: Yambo databases | Database and plotting tutorial for yambo: yambopy ]] (Get the databases: [https://media.yambo-code.eu/educational/tutorials/files/databases_yambopy.tar.gz databases_yambopy], 226MB)&lt;br /&gt;
* [[Phonon-assisted luminescence by finite atomic displacements]]&lt;/div&gt;</summary>
		<author><name>Fulvio</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=First_steps_in_Yambopy&amp;diff=7616</id>
		<title>First steps in Yambopy</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=First_steps_in_Yambopy&amp;diff=7616"/>
		<updated>2024-02-01T18:16:27Z</updated>

		<summary type="html">&lt;p&gt;Fulvio: /* Setup */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The yambopy project aims to develop python tools to: &lt;br /&gt;
&lt;br /&gt;
* Read and edit yambo and quantum espresso input files&lt;br /&gt;
* Easily perform pre- and post-processing of the simulation data for these two codes - including hard-to-get, database-encoded data beyond standard outputs&lt;br /&gt;
* Provide easy visualization and plotting options &lt;br /&gt;
* Set up simple automatization workflows (e.g., convergence tests)&lt;br /&gt;
&lt;br /&gt;
=== Setup ===&lt;br /&gt;
First of all, make sure that you have a suitable python environment (crated for example with [https://docs.conda.io/projects/miniconda/en/latest/| conda] or [https://docs.python.org/3/library/venv.html| venv]) with python &amp;gt;=3.8.&lt;br /&gt;
&lt;br /&gt;
Then, you may install yambopy in one of the following ways.&lt;br /&gt;
&lt;br /&gt;
==== Quick installation from PyPI repository ====&lt;br /&gt;
&lt;br /&gt;
* In order to quickly install the officially released version type:&lt;br /&gt;
&lt;br /&gt;
 pip install yambopy&lt;br /&gt;
&lt;br /&gt;
==== Installation from tarball ====&lt;br /&gt;
&lt;br /&gt;
* In case you don&#039;t want to download from the pip repository and prefer to install a version of yambopy locally, you may download the appropriate tarball from the [https://github.com/yambo-code/yambopy/releases| yambopy github page]. Extract the tarball, enter the yambopy folder and type &amp;lt;code&amp;gt;pip install .&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Installation of latest patch ====&lt;br /&gt;
&lt;br /&gt;
* In case you want the latest version of the code including new updates and patches that might not be present in the official version, then you can clone the yambopy git repository (a basic knowledge of git may be helpful):&lt;br /&gt;
&lt;br /&gt;
 git clone https://github.com/yambo-code/yambopy.git&lt;br /&gt;
 cd yambopy&lt;br /&gt;
 pip install .&lt;br /&gt;
&lt;br /&gt;
==== Dependencies ====&lt;br /&gt;
&lt;br /&gt;
* In principle, &amp;lt;code&amp;gt;pip&amp;lt;/code&amp;gt; should take care of the required python dependencies. They are &amp;lt;code&amp;gt;numpy&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;scipy&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;matplotlib&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;netCDF4&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;lxml&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;PyYAML&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;monty&amp;lt;/code&amp;gt;. In case some dependency-related problem arises, you can install each of them separately beforehand with:&lt;br /&gt;
&lt;br /&gt;
 pip install &amp;lt;code&amp;gt;dependency-name&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Tutorials ===&lt;br /&gt;
Now yambopy is ready to use! Just go to the tutorials folder and follow the docs!&lt;br /&gt;
&lt;br /&gt;
 cd tutorial/&lt;br /&gt;
&lt;br /&gt;
On this wiki, we provide steps for the following tutorials:&lt;br /&gt;
* [[GW tutorial. Convergence and approximations (BN)]]&lt;br /&gt;
* [[Bethe-Salpeter equation tutorial. Optical absorption (BN)]]&lt;br /&gt;
* [[Yambopy tutorial: band structures | Database and plotting tutorial for quantum espresso: qepy]] (Get the databases: [https://media.yambo-code.eu/educational/tutorials/files/databases_qepy.tar databases_qepy], 59MB)&lt;br /&gt;
* [[Yambopy tutorial: Yambo databases | Database and plotting tutorial for yambo: yambopy ]] (Get the databases: [https://media.yambo-code.eu/educational/tutorials/files/databases_yambopy.tar databases_yambopy], 226MB)&lt;br /&gt;
* [[Phonon-assisted luminescence by finite atomic displacements]]&lt;/div&gt;</summary>
		<author><name>Fulvio</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=First_steps_in_Yambopy&amp;diff=7615</id>
		<title>First steps in Yambopy</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=First_steps_in_Yambopy&amp;diff=7615"/>
		<updated>2024-02-01T18:12:48Z</updated>

		<summary type="html">&lt;p&gt;Fulvio: /* Setup */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The yambopy project aims to develop python tools to: &lt;br /&gt;
&lt;br /&gt;
* Read and edit yambo and quantum espresso input files&lt;br /&gt;
* Easily perform pre- and post-processing of the simulation data for these two codes - including hard-to-get, database-encoded data beyond standard outputs&lt;br /&gt;
* Provide easy visualization and plotting options &lt;br /&gt;
* Set up simple automatization workflows (e.g., convergence tests)&lt;br /&gt;
&lt;br /&gt;
=== Setup ===&lt;br /&gt;
First of all, make sure that you have a suitable python environment (crated for example with [https://docs.conda.io/projects/miniconda/en/latest/| conda] or [https://docs.python.org/3/library/venv.html| venv]) with python &amp;gt;=3.8.&lt;br /&gt;
&lt;br /&gt;
Then, you may install yambopy in one of the following ways:&lt;br /&gt;
&lt;br /&gt;
* In order to quickly install the officially released version type:&lt;br /&gt;
&lt;br /&gt;
 pip install yambopy&lt;br /&gt;
&lt;br /&gt;
* In case you don&#039;t want to download from the pip repository and prefer to install a version of yambopy locally, you may download the appropriate tarball from the [https://github.com/yambo-code/yambopy/releases| yambopy github page]. Extract the tarball, enter the yambopy folder and type &amp;lt;code&amp;gt;pip install .&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* In case you want the latest version of the code including new updates and patches that might not be present in the official version, then you can clone the yambopy git repository (a basic knowledge of git may be helpful):&lt;br /&gt;
&lt;br /&gt;
 git clone https://github.com/yambo-code/yambopy.git&lt;br /&gt;
 cd yambopy&lt;br /&gt;
 pip install .&lt;br /&gt;
&lt;br /&gt;
* In principle, &amp;lt;code&amp;gt;pip&amp;lt;/code&amp;gt; should take care of the required python dependencies. They are &amp;lt;code&amp;gt;numpy&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;scipy&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;matplotlib&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;netCDF4&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;lxml&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;PyYAML&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;monty&amp;lt;/code&amp;gt;. In case some dependency-related problem arises, you can install each of them separately beforehand with:&lt;br /&gt;
&lt;br /&gt;
 pip install &amp;lt;code&amp;gt;dependency-name&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Tutorials ===&lt;br /&gt;
Now yambopy is ready to use! Just go to the tutorials folder and follow the docs!&lt;br /&gt;
&lt;br /&gt;
 cd tutorial/&lt;br /&gt;
&lt;br /&gt;
On this wiki, we provide steps for the following tutorials:&lt;br /&gt;
* [[GW tutorial. Convergence and approximations (BN)]]&lt;br /&gt;
* [[Bethe-Salpeter equation tutorial. Optical absorption (BN)]]&lt;br /&gt;
* [[Yambopy tutorial: band structures | Database and plotting tutorial for quantum espresso: qepy]] (Get the databases: [https://media.yambo-code.eu/educational/tutorials/files/databases_qepy.tar databases_qepy], 59MB)&lt;br /&gt;
* [[Yambopy tutorial: Yambo databases | Database and plotting tutorial for yambo: yambopy ]] (Get the databases: [https://media.yambo-code.eu/educational/tutorials/files/databases_yambopy.tar databases_yambopy], 226MB)&lt;br /&gt;
* [[Phonon-assisted luminescence by finite atomic displacements]]&lt;/div&gt;</summary>
		<author><name>Fulvio</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Setting_up_Yambo&amp;diff=7614</id>
		<title>Setting up Yambo</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Setting_up_Yambo&amp;diff=7614"/>
		<updated>2024-02-01T18:11:53Z</updated>

		<summary type="html">&lt;p&gt;Fulvio: /* Setting up Yambopy */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;To able to follow the tutorials you need a running version of the yambo, yambopy (and QE or abinit codes).&lt;br /&gt;
&lt;br /&gt;
== Setting up Yambo (and eventually QE or abinit)  ==&lt;br /&gt;
There are several different ways to prepare a working environment.&lt;br /&gt;
&lt;br /&gt;
=== Virtual Machine(s) ===&lt;br /&gt;
The easiest way is to access to a virtual machine which contains both (i) yambo/QE and (ii) the tutorials.&lt;br /&gt;
&lt;br /&gt;
You can do it in one of two ways:&lt;br /&gt;
* Virtual machine via [[ICTP cloud|ICTP cloud]] If the schools you are attending provided an ICTP virtual machine this is the preferred option. It works through internet connection inside a browser.&lt;br /&gt;
* Install the [[Yambo_Virtual_Machine|yambo virtual machine]] on your laptop / desktop. This requires Oracle virtual box. Pre-download of the Virtual machine. No internet connection needed.&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
URL of the machine : https://ins45100.ictp.it/&lt;br /&gt;
READ-ONLY PASSWORD for TUTOR (ictptutor) access:&lt;br /&gt;
NairibiTutor&lt;br /&gt;
READ-WRITE password for PARTICIPANT&#039;s (ictpuser) access:&lt;br /&gt;
NairobiUser&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== User installation  ===&lt;br /&gt;
You can also setup the yambo code on your on laptop / desktop using different methods.&lt;br /&gt;
&lt;br /&gt;
As far as the Yambo source is concerned you can:&lt;br /&gt;
* Install [[Yambo via Docker|Yambo via Docker]]&lt;br /&gt;
* [[download|Download]] and [[Installation|install]] yambo on your laptop / desktop (requires a linux machine).&lt;br /&gt;
* Install yambo on your laptop/desktop/cluster [https://github.com/nicspalla/my-repo via Spack].&lt;br /&gt;
* Install using  Anaconda.&lt;br /&gt;
&lt;br /&gt;
=== Yambo User Installation with Anaconda ===&lt;br /&gt;
It is possible to install Yambo (up to v5.0.4) and Quantum-ESPRESSO via conda-forge (a conda channel/repository):&lt;br /&gt;
To setup Anaconda, please start from installing [https://www.anaconda.com/products/distribution#Downloads Anaconda] or [https://docs.conda.io/en/latest/miniconda.html Miniconda].&lt;br /&gt;
&lt;br /&gt;
Then we suggest to create a conda environment and activate it:&lt;br /&gt;
 conda create --name yambo-env -c conda-forge&lt;br /&gt;
 conda activate yambo-env&lt;br /&gt;
Then you can install the prerequisites and the two codes:&lt;br /&gt;
 conda install numpy scipy netcdf4 matplotlib pyyaml lxml pandas&lt;br /&gt;
 conda install yambo &lt;br /&gt;
 conda install qe&lt;br /&gt;
&lt;br /&gt;
==Setting up Yambopy==&lt;br /&gt;
&lt;br /&gt;
You can simply type&lt;br /&gt;
&lt;br /&gt;
 pip install yambopy&lt;br /&gt;
&lt;br /&gt;
In a suitable python environment. For more information, go to the [[First steps in Yambopy| Yambopy setup page]].&lt;/div&gt;</summary>
		<author><name>Fulvio</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=First_steps_in_Yambopy&amp;diff=7613</id>
		<title>First steps in Yambopy</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=First_steps_in_Yambopy&amp;diff=7613"/>
		<updated>2024-02-01T18:09:56Z</updated>

		<summary type="html">&lt;p&gt;Fulvio: /* Setup */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The yambopy project aims to develop python tools to: &lt;br /&gt;
&lt;br /&gt;
* Read and edit yambo and quantum espresso input files&lt;br /&gt;
* Easily perform pre- and post-processing of the simulation data for these two codes - including hard-to-get, database-encoded data beyond standard outputs&lt;br /&gt;
* Provide easy visualization and plotting options &lt;br /&gt;
* Set up simple automatization workflows (e.g., convergence tests)&lt;br /&gt;
&lt;br /&gt;
=== Setup ===&lt;br /&gt;
First of all, make sure that you have a suitable python environment (crated for example with [https://docs.conda.io/projects/miniconda/en/latest/| conda] or [https://docs.python.org/3/library/venv.html| venv]) with python &amp;gt;=3.8.&lt;br /&gt;
&lt;br /&gt;
Then, you may install yambopy in one of the following ways:&lt;br /&gt;
&lt;br /&gt;
* In order to install the officially released version type:&lt;br /&gt;
&lt;br /&gt;
 pip install yambopy&lt;br /&gt;
&lt;br /&gt;
* In case you don&#039;t want to download from the pip repository and prefer to install a version of yambopy locally, you may download the appropriate tarball from the [https://github.com/yambo-code/yambopy/releases| yambopy github page]. Extract the tarball, enter the yambopy folder and type &amp;lt;code&amp;gt;pip install .&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* In case you want the latest version of the code including new updates and patches that might not be present in the official version, then you can clone the yambopy git repository (a basic knowledge of git may be helpful):&lt;br /&gt;
&lt;br /&gt;
 git clone https://github.com/yambo-code/yambopy.git&lt;br /&gt;
 cd yambopy&lt;br /&gt;
 pip install .&lt;br /&gt;
&lt;br /&gt;
* In principle, &amp;lt;code&amp;gt;pip&amp;lt;/code&amp;gt; should take care of the required python dependencies. They are &amp;lt;code&amp;gt;numpy&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;scipy&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;matplotlib&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;netCDF4&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;lxml&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;PyYAML&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;monty&amp;lt;/code&amp;gt;. In case some dependency-related problem arises, you can install each of them separately beforehand with:&lt;br /&gt;
&lt;br /&gt;
 pip install &amp;lt;code&amp;gt;dependency-name&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Tutorials ===&lt;br /&gt;
Now yambopy is ready to use! Just go to the tutorials folder and follow the docs!&lt;br /&gt;
&lt;br /&gt;
 cd tutorial/&lt;br /&gt;
&lt;br /&gt;
On this wiki, we provide steps for the following tutorials:&lt;br /&gt;
* [[GW tutorial. Convergence and approximations (BN)]]&lt;br /&gt;
* [[Bethe-Salpeter equation tutorial. Optical absorption (BN)]]&lt;br /&gt;
* [[Yambopy tutorial: band structures | Database and plotting tutorial for quantum espresso: qepy]] (Get the databases: [https://media.yambo-code.eu/educational/tutorials/files/databases_qepy.tar databases_qepy], 59MB)&lt;br /&gt;
* [[Yambopy tutorial: Yambo databases | Database and plotting tutorial for yambo: yambopy ]] (Get the databases: [https://media.yambo-code.eu/educational/tutorials/files/databases_yambopy.tar databases_yambopy], 226MB)&lt;br /&gt;
* [[Phonon-assisted luminescence by finite atomic displacements]]&lt;/div&gt;</summary>
		<author><name>Fulvio</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=First_steps_in_Yambopy&amp;diff=7612</id>
		<title>First steps in Yambopy</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=First_steps_in_Yambopy&amp;diff=7612"/>
		<updated>2024-02-01T18:07:56Z</updated>

		<summary type="html">&lt;p&gt;Fulvio: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The yambopy project aims to develop python tools to: &lt;br /&gt;
&lt;br /&gt;
* Read and edit yambo and quantum espresso input files&lt;br /&gt;
* Easily perform pre- and post-processing of the simulation data for these two codes - including hard-to-get, database-encoded data beyond standard outputs&lt;br /&gt;
* Provide easy visualization and plotting options &lt;br /&gt;
* Set up simple automatization workflows (e.g., convergence tests)&lt;br /&gt;
&lt;br /&gt;
=== Setup ===&lt;br /&gt;
First of all, make sure that you have a suitable python environment (crated for example with [[https://docs.conda.io/projects/miniconda/en/latest/|conda]] or [[https://docs.python.org/3/library/venv.html|venv]]) with python &amp;gt;=3.8.&lt;br /&gt;
&lt;br /&gt;
Then, you may install yambopy in one of the following ways:&lt;br /&gt;
&lt;br /&gt;
* In order to install the officially released version type:&lt;br /&gt;
&lt;br /&gt;
 pip install yambopy&lt;br /&gt;
&lt;br /&gt;
* In case you don&#039;t want to download from the pip repository and prefer to install a version of yambopy locally, you may download the appropriate tarball from the [[https://github.com/yambo-code/yambopy/releases|yambopy github page]]. Extract the tarball, enter the yambopy folder and type:&lt;br /&gt;
 &lt;br /&gt;
 pip install .&lt;br /&gt;
&lt;br /&gt;
* In case you want the latest version of the code including new updates and patches that might not be present in the official version, then you can clone the yambopy git repository (a basic knowledge of git may be helpful):&lt;br /&gt;
&lt;br /&gt;
 git clone https://github.com/yambo-code/yambopy.git&lt;br /&gt;
 cd yambopy&lt;br /&gt;
 pip install .&lt;br /&gt;
&lt;br /&gt;
* In principle, &amp;lt;code&amp;gt;pip&amp;lt;/code&amp;gt; should take care of the required python dependencies. They are &amp;lt;code&amp;gt;numpy&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;scipy&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;matplotlib&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;netCDF4&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;lxml&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;PyYAML&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;monty&amp;lt;/code&amp;gt;. In case some dependency-related problem arises, you can install each of them separately beforehand with:&lt;br /&gt;
&lt;br /&gt;
 pip install &amp;lt;code&amp;gt;dependency-name&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Tutorials ===&lt;br /&gt;
Now yambopy is ready to use! Just go to the tutorials folder and follow the docs!&lt;br /&gt;
&lt;br /&gt;
 cd tutorial/&lt;br /&gt;
&lt;br /&gt;
On this wiki, we provide steps for the following tutorials:&lt;br /&gt;
* [[GW tutorial. Convergence and approximations (BN)]]&lt;br /&gt;
* [[Bethe-Salpeter equation tutorial. Optical absorption (BN)]]&lt;br /&gt;
* [[Yambopy tutorial: band structures | Database and plotting tutorial for quantum espresso: qepy]] (Get the databases: [https://media.yambo-code.eu/educational/tutorials/files/databases_qepy.tar databases_qepy], 59MB)&lt;br /&gt;
* [[Yambopy tutorial: Yambo databases | Database and plotting tutorial for yambo: yambopy ]] (Get the databases: [https://media.yambo-code.eu/educational/tutorials/files/databases_yambopy.tar databases_yambopy], 226MB)&lt;br /&gt;
* [[Phonon-assisted luminescence by finite atomic displacements]]&lt;/div&gt;</summary>
		<author><name>Fulvio</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=First_steps_in_Yambopy&amp;diff=7611</id>
		<title>First steps in Yambopy</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=First_steps_in_Yambopy&amp;diff=7611"/>
		<updated>2024-02-01T18:05:31Z</updated>

		<summary type="html">&lt;p&gt;Fulvio: /* Setup */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The yambopy project aims to develop python tools to: &lt;br /&gt;
&lt;br /&gt;
* Read and edit yambo and quantum espresso input files&lt;br /&gt;
* Easily perform pre- and post-processing of the simulation data for these two codes - including hard-to-get, database-encoded data beyond standard outputs&lt;br /&gt;
* Provide easy visualization and plotting options &lt;br /&gt;
* Set up simple automatization workflows (e.g., convergence tests)&lt;br /&gt;
&lt;br /&gt;
=== Setup ===&lt;br /&gt;
First of all, make sure that you have a suitable python environment (crated for example with [conda][https://docs.conda.io/projects/miniconda/en/latest/] or [venv][https://docs.python.org/3/library/venv.html]) with python &amp;gt;=3.8.&lt;br /&gt;
&lt;br /&gt;
Then, you may install yambopy in one of the following ways:&lt;br /&gt;
&lt;br /&gt;
* In order to install the officially released version type:&lt;br /&gt;
&lt;br /&gt;
 pip install yambopy&lt;br /&gt;
&lt;br /&gt;
* In case you don&#039;t want to download from the pip repository and prefer to install a version of yambopy locally, you may download the appropriate tarball from the [yambopy github page][https://github.com/yambo-code/yambopy/releases]. Extract the tarball, enter the yambopy folder and type:&lt;br /&gt;
 &lt;br /&gt;
 pip install .&lt;br /&gt;
  &lt;br /&gt;
* In case you want the latest version of the code including new updates and patches that might not be present in the official version, then you can clone the yambopy git repository (a basic knowledge of git may be helpful):&lt;br /&gt;
&lt;br /&gt;
 git clone https://github.com/yambo-code/yambopy.git&lt;br /&gt;
 cd yambopy&lt;br /&gt;
 pip install .&lt;br /&gt;
&lt;br /&gt;
* In principle, &amp;lt;code&amp;gt;pip&amp;lt;/code&amp;gt; should take care of the required python dependencies. They are &amp;lt;code&amp;gt;numpy&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;scipy&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;matplotlib&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;netCDF4&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;lxml&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;PyYAML&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;monty&amp;lt;/code&amp;gt;. In case some dependency-related problem arises, you can install each of them separately beforehand with:&lt;br /&gt;
&lt;br /&gt;
 pip install &amp;lt;code&amp;gt;dependency-name&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Tutorials ===&lt;br /&gt;
Now yambopy is ready to use! Just go to the tutorials folder and follow the docs!&lt;br /&gt;
&lt;br /&gt;
 cd tutorial/&lt;br /&gt;
&lt;br /&gt;
On this wiki, we provide steps for the following tutorials:&lt;br /&gt;
* [[GW tutorial. Convergence and approximations (BN)]]&lt;br /&gt;
* [[Bethe-Salpeter equation tutorial. Optical absorption (BN)]]&lt;br /&gt;
* [[Yambopy tutorial: band structures | Database and plotting tutorial for quantum espresso: qepy]] (Get the databases: [https://media.yambo-code.eu/educational/tutorials/files/databases_qepy.tar databases_qepy], 59MB)&lt;br /&gt;
* [[Yambopy tutorial: Yambo databases | Database and plotting tutorial for yambo: yambopy ]] (Get the databases: [https://media.yambo-code.eu/educational/tutorials/files/databases_yambopy.tar databases_yambopy], 226MB)&lt;br /&gt;
* [[Phonon-assisted luminescence by finite atomic displacements]]&lt;/div&gt;</summary>
		<author><name>Fulvio</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Setting_up_Yambo&amp;diff=7610</id>
		<title>Setting up Yambo</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Setting_up_Yambo&amp;diff=7610"/>
		<updated>2024-02-01T17:40:28Z</updated>

		<summary type="html">&lt;p&gt;Fulvio: /* Yambo User Installation with Anaconda */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;To able to follow the tutorials you need a running version of the yambo, yambopy (and QE or abinit codes).&lt;br /&gt;
&lt;br /&gt;
== Setting up Yambo (and eventually QE or abinit)  ==&lt;br /&gt;
There are several different ways to prepare a working environment.&lt;br /&gt;
&lt;br /&gt;
=== Virtual Machine(s) ===&lt;br /&gt;
The easiest way is to access to a virtual machine which contains both (i) yambo/QE and (ii) the tutorials.&lt;br /&gt;
&lt;br /&gt;
You can do it in one of two ways:&lt;br /&gt;
* Virtual machine via [[ICTP cloud|ICTP cloud]] If the schools you are attending provided an ICTP virtual machine this is the preferred option. It works through internet connection inside a browser.&lt;br /&gt;
* Install the [[Yambo_Virtual_Machine|yambo virtual machine]] on your laptop / desktop. This requires Oracle virtual box. Pre-download of the Virtual machine. No internet connection needed.&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
URL of the machine : https://ins45100.ictp.it/&lt;br /&gt;
READ-ONLY PASSWORD for TUTOR (ictptutor) access:&lt;br /&gt;
NairibiTutor&lt;br /&gt;
READ-WRITE password for PARTICIPANT&#039;s (ictpuser) access:&lt;br /&gt;
NairobiUser&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== User installation  ===&lt;br /&gt;
You can also setup the yambo code on your on laptop / desktop using different methods.&lt;br /&gt;
&lt;br /&gt;
As far as the Yambo source is concerned you can:&lt;br /&gt;
* Install [[Yambo via Docker|Yambo via Docker]]&lt;br /&gt;
* [[download|Download]] and [[Installation|install]] yambo on your laptop / desktop (requires a linux machine).&lt;br /&gt;
* Install yambo on your laptop/desktop/cluster [https://github.com/nicspalla/my-repo via Spack].&lt;br /&gt;
* Install using  Anaconda.&lt;br /&gt;
&lt;br /&gt;
=== Yambo User Installation with Anaconda ===&lt;br /&gt;
It is possible to install Yambo (up to v5.0.4) and Quantum-ESPRESSO via conda-forge (a conda channel/repository):&lt;br /&gt;
To setup Anaconda, please start from installing [https://www.anaconda.com/products/distribution#Downloads Anaconda] or [https://docs.conda.io/en/latest/miniconda.html Miniconda].&lt;br /&gt;
&lt;br /&gt;
Then we suggest to create a conda environment and activate it:&lt;br /&gt;
 conda create --name yambo-env -c conda-forge&lt;br /&gt;
 conda activate yambo-env&lt;br /&gt;
Then you can install the prerequisites and the two codes:&lt;br /&gt;
 conda install numpy scipy netcdf4 matplotlib pyyaml lxml pandas&lt;br /&gt;
 conda install yambo &lt;br /&gt;
 conda install qe&lt;br /&gt;
&lt;br /&gt;
==Setting up Yambopy==&lt;br /&gt;
&lt;br /&gt;
===Quick installation===&lt;br /&gt;
&lt;br /&gt;
A quick way to start using Yambopy is described here.&lt;br /&gt;
&lt;br /&gt;
* Make sure that you are using Python 3 and that you have the following python packages: &amp;lt;code&amp;gt;numpy&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;scipy&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;matplotlib&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;netCDF4&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;lxml&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;pyyaml&amp;lt;/code&amp;gt;. Optionally, you may want to have abipy [[https://abinit.github.io/abipy/index.html]] installed for band structure interpolations.&lt;br /&gt;
&lt;br /&gt;
* Go to a directory of your choice and clone yambopy from the git repository&lt;br /&gt;
&lt;br /&gt;
 git clone https://github.com/yambo-code/yambopy.git&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t want to use git, you may download a tarball from the git repository instead.&lt;br /&gt;
&lt;br /&gt;
* Enter into the yambopy folder and install&lt;br /&gt;
&lt;br /&gt;
 cd yambopy&lt;br /&gt;
 sudo python setup.py install&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t have administrative privileges (for example on a computing cluster), type instead&lt;br /&gt;
&lt;br /&gt;
 cd yambopy&lt;br /&gt;
 python setup.py install --user&lt;br /&gt;
&lt;br /&gt;
===Installing dependencies with Anaconda===&lt;br /&gt;
We suggest installing yambopy using Anaconda [[https://www.anaconda.com/products/distribution]] to manage the various python packages.&lt;br /&gt;
&lt;br /&gt;
In this case, you can follow these steps.&lt;br /&gt;
&lt;br /&gt;
First, install the required dependencies:&lt;br /&gt;
 conda install numpy scipy netcdf4 lxml pyyaml&lt;br /&gt;
&lt;br /&gt;
Then we create a conda environment based on python 3.6 (this is to ensure compatibility with abipy if we want to install it later on):&lt;br /&gt;
 conda create --name NAME_ENV python=3.6&lt;br /&gt;
Here choose &amp;lt;code&amp;gt;NAME_ENV&amp;lt;/code&amp;gt; as you want, e.g. &amp;lt;code&amp;gt;yenv&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Now, we install abipy and its dependency pymatgen using &amp;lt;code&amp;gt;pip&amp;lt;/code&amp;gt;. Here make sure that you are using the &amp;lt;code&amp;gt;pip&amp;lt;/code&amp;gt; version provided by Anaconda and not your system version.&lt;br /&gt;
&lt;br /&gt;
 pip install pymatgen&lt;br /&gt;
 pip install abipy&lt;br /&gt;
&lt;br /&gt;
Finally, we are ready to install yambopy:&lt;br /&gt;
&lt;br /&gt;
 git clone https://github.com/yambo-code/yambopy.git &lt;br /&gt;
&lt;br /&gt;
(or download and extract tarball) and follow the steps outlined in the quick installation section.&lt;br /&gt;
&lt;br /&gt;
Now enter into the yambopy folder and install&lt;br /&gt;
&lt;br /&gt;
 cd yambopy&lt;br /&gt;
 sudo python setup.py install&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t have administrative privileges (for example on a computing cluster), type instead&lt;br /&gt;
&lt;br /&gt;
 cd yambopy&lt;br /&gt;
 python setup.py install --user&lt;br /&gt;
&lt;br /&gt;
===Frequent issues===&lt;br /&gt;
When running the installation you may get a &amp;lt;code&amp;gt;SyntaxError&amp;lt;/code&amp;gt; related to utf-8 encoding or it may complain that module &amp;lt;code&amp;gt;setuptools&amp;lt;/code&amp;gt; is not installed even though it is. In this case, it means that the &amp;lt;code&amp;gt;sudo&amp;lt;/code&amp;gt; command is not preserving the correct &amp;lt;code&amp;gt;PATH&amp;lt;/code&amp;gt; for your python executable.&lt;br /&gt;
&lt;br /&gt;
Solve the problem by running the installation step as&lt;br /&gt;
&lt;br /&gt;
 sudo /your/path/to/python setup.py install&lt;br /&gt;
or&lt;br /&gt;
 sudo env PATH=$PATH python setup.py install&lt;br /&gt;
&lt;br /&gt;
This applies only to the installation step and not to subsequent yambopy use.&lt;/div&gt;</summary>
		<author><name>Fulvio</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Test-suite&amp;diff=7546</id>
		<title>Test-suite</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Test-suite&amp;diff=7546"/>
		<updated>2023-12-11T09:21:40Z</updated>

		<summary type="html">&lt;p&gt;Fulvio: /* Web-Interface */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Web-Interface ==&lt;br /&gt;
&lt;br /&gt;
The updated list of test-suite runs can be found on the old Yambo web-page.&lt;br /&gt;
&lt;br /&gt;
Tests&#039; list is splitted in [http://media.yambo-code.eu/robots/index.php branches].&lt;br /&gt;
For each branch many robots are shown.&lt;br /&gt;
Check the [http://media.yambo-code.eu/robots/bug-fixes/polluce.php bug-fixes] branch as an example.&lt;br /&gt;
&lt;br /&gt;
This list is automatically updated by the test-suite driver.pl when the -report option is used.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
The test suite is available on GitHub via git&lt;br /&gt;
&lt;br /&gt;
 $git clone https://github.com/yambo-code/yambo-tests.git yambo-tests&lt;br /&gt;
&lt;br /&gt;
you may need to provide your GitHub username and password.&lt;br /&gt;
&lt;br /&gt;
Then init and update the ROBOTS submodule&lt;br /&gt;
&lt;br /&gt;
 $cd yambo-tests&lt;br /&gt;
 $git submodule init&lt;br /&gt;
 $git submodule update&lt;br /&gt;
 $cd ROBOTS&lt;br /&gt;
 $git checkout master&lt;br /&gt;
 $cd ..&lt;br /&gt;
&lt;br /&gt;
After the first thing to do is the configuration&lt;br /&gt;
&lt;br /&gt;
 $./configure --with-yambo=/home/marini/Yambo/yambo/master/&lt;br /&gt;
&lt;br /&gt;
If the configuration works you should see something similar to the following message:&lt;br /&gt;
&lt;br /&gt;
 $./configure --with-yambo=/home/marini/Yambo/yambo/master/&lt;br /&gt;
 checking build system type... x86_64-unknown-linux-gnu&lt;br /&gt;
 checking host system type... x86_64-unknown-linux-gnu&lt;br /&gt;
 checking the anomaly.mlib.ism.cnr.it ROBOT... created&lt;br /&gt;
 hecking for nccopy... no&lt;br /&gt;
 checking for ncftp... ncftp&lt;br /&gt;
 checking for ncftpls... ncftpls&lt;br /&gt;
 checking for ncftpput... ncftpput&lt;br /&gt;
 checking for awk... awk&lt;br /&gt;
 checking for txt2html... txt2html&lt;br /&gt;
 checking the Yambo source... /home/marini/Yambo/yambo/master/&lt;br /&gt;
 configure: creating ./config.status&lt;br /&gt;
 config.status: creating config/MODULES.pl&lt;br /&gt;
 config.status: creating config/TOOLS.pl&lt;br /&gt;
&lt;br /&gt;
=== Robot informations ===&lt;br /&gt;
&lt;br /&gt;
By typing&lt;br /&gt;
&lt;br /&gt;
 $./driver.pl -i&lt;br /&gt;
&lt;br /&gt;
you will see some basic info about your machine. This command is useful to see the available flows, configurations and so on. An example is&lt;br /&gt;
&lt;br /&gt;
   Running on host: anomaly.mlib.ism.cnr.it&lt;br /&gt;
   By user        : marini&lt;br /&gt;
   Version        : 5.0&lt;br /&gt;
   Available CPU&#039;s: 8&lt;br /&gt;
   Available confs: default.sh&lt;br /&gt;
   Available flows: failed_master.pl validate.pl default.pl failed_SLK.pl failed_devel-qp-dbs.pl minimal.pl&lt;br /&gt;
&lt;br /&gt;
=== Database download ===&lt;br /&gt;
Now it is time to download all databases. This can be easily done using the -d option&lt;br /&gt;
&lt;br /&gt;
 $./driver.pl -d all&lt;br /&gt;
&lt;br /&gt;
=== Compilation ===&lt;br /&gt;
By default the configure copies a basic compilation script in ROBOTS/&amp;lt;YOUR ROBOT&amp;gt;/CONFIGURATIONS/default.sh. This uses internally compiled libraries so it should work easily. In order to test it launch&lt;br /&gt;
&lt;br /&gt;
 $./driver.pl -compile&lt;br /&gt;
&lt;br /&gt;
=== Internal Test ===&lt;br /&gt;
Use the autotest to verify your compiled source:&lt;br /&gt;
&lt;br /&gt;
 $./driver.pl -autotest&lt;br /&gt;
&lt;br /&gt;
If everything works you should see as log the following message&lt;br /&gt;
&lt;br /&gt;
 ==================================================================================&lt;br /&gt;
 = Starting Yambo test-suite&lt;br /&gt;
 ==================================================================================&lt;br /&gt;
  - Check requirements : ...ncftp...ncftpls...ncftpput...txt2html&lt;br /&gt;
  -     Test selection : from input&lt;br /&gt;
                ncdump : /opt/gcc4/netcdf-4.0.1/bin/ncdump&lt;br /&gt;
  -  Executable checks : (yambo  OK ) (ypp  FAIL )(a2y  FAIL )(p2y  FAIL )&lt;br /&gt;
         Running tests : hBN/GW-OPTICS 01_init 02_HF&lt;br /&gt;
              Projects : nopj&lt;br /&gt;
             Verbosity : low &lt;br /&gt;
             Precision : 0.01 &lt;br /&gt;
              Hostname : anomaly.mlib.ism.cnr.it &lt;br /&gt;
              revision : 14505 &lt;br /&gt;
                 build : MPI+SLK &lt;br /&gt;
               bin dir : bin &lt;br /&gt;
            shortname  : &lt;br /&gt;
                source : master_-precompiled &lt;br /&gt;
         Parallel Loop : SERIAL&lt;br /&gt;
 =--------------------------------------------------------------------------------=&lt;br /&gt;
  &amp;gt;  [1  /1  ] hBN/GW-OPTICS[serial]   &#039;&#039;&#039;5 passes&#039;&#039;&#039; &lt;br /&gt;
 =--------------------------------------------------------------------------------=&lt;br /&gt;
&lt;br /&gt;
The  &#039;&#039;&#039;5 passes&#039;&#039;&#039; are important as they represent the number of passed tests.&lt;br /&gt;
&lt;br /&gt;
== For the impatiens: quick cron run and final reporting ==&lt;br /&gt;
If you do not want to bother with all details of the testing script and want just to install the suite read this section and stop.&lt;br /&gt;
&lt;br /&gt;
In order to properly setup your machine for night test-suite runs you have to:&lt;br /&gt;
&lt;br /&gt;
#Choose the branch(s) to test&lt;br /&gt;
For this purpose use &lt;br /&gt;
 $./driver.pl -edit branches&lt;br /&gt;
#create a crontab entry&lt;br /&gt;
See [https://corenominal.org/2016/05/12/howto-setup-a-crontab-file/ here] for detailled informations on cron. My personal crontab file looks like&lt;br /&gt;
&lt;br /&gt;
 # m  h   dom mon dow   command&lt;br /&gt;
  30 18  *   *   Thu   ~/bin/scripts/yambo_validation.tcsh validate &amp;gt;&amp;gt; /home/marini/Yambo/sources/svn/yambo-tests/test-suite/LOG 2&amp;gt;&amp;amp;1&lt;br /&gt;
&lt;br /&gt;
with&lt;br /&gt;
&lt;br /&gt;
 $cat bin/scripts/yambo_validation.tcsh &lt;br /&gt;
 #!/usr/bin/tcsh&lt;br /&gt;
 cd /home/marini/Yambo/sources/svn/yambo-tests/test-suite&lt;br /&gt;
 ./driver.pl -flow $argv[1] -report&lt;br /&gt;
&lt;br /&gt;
That&#039;s all you need.&lt;br /&gt;
&lt;br /&gt;
== Available tests ==&lt;br /&gt;
The list of tests can be done using the -l option:&lt;br /&gt;
&lt;br /&gt;
 $./driver.pl -l&lt;br /&gt;
&lt;br /&gt;
Note that you can add a TEST to -l to list the specific inputs of that test. For example&lt;br /&gt;
&lt;br /&gt;
 $./driver.pl -l GaAs001-c4x4/YAMBO&lt;br /&gt;
 &lt;br /&gt;
 Available input files for GaAs001-c4x4/YAMBO are:  01_init 02_RAS_full 03_RAS_full 04_RAS_front 05_RAS_dimer&lt;br /&gt;
&lt;br /&gt;
== Reports &amp;amp; Logs ==&lt;br /&gt;
The autotest and any other run of the test-suite produces three files. Each file is labelled with the date of the run.&lt;br /&gt;
&lt;br /&gt;
In order to see the meaning and the in formations written in the files let&#039;s do a quick run of a Dummy test created in order to reproduce some of the possible error conditions.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s first clean the suite&lt;br /&gt;
&lt;br /&gt;
 $./driver.pl -c&lt;br /&gt;
&lt;br /&gt;
and use the -force to run also tests tagged as BROKEN (like the Dummy one). First thing to do is to download the Dummy database adding the -force option.&lt;br /&gt;
&lt;br /&gt;
 $./driver.pl -d Dummy -force&lt;br /&gt;
&lt;br /&gt;
Then we can run the Dummy test using&lt;br /&gt;
 &lt;br /&gt;
 $./driver.pl -tests Dummy -force&lt;br /&gt;
&lt;br /&gt;
The result will now be&lt;br /&gt;
&lt;br /&gt;
 =--------------------------------------------------------------------------------=&lt;br /&gt;
  &amp;gt;  [1  /1  ] Dummy[serial]          11 passes  5 fails &lt;br /&gt;
 =--------------------------------------------------------------------------------=&lt;br /&gt;
&lt;br /&gt;
The 5 fails cover most of the potential errors detected by the test-suite. Details can be now found in the report/log files&lt;br /&gt;
&lt;br /&gt;
=== REPORT file ===&lt;br /&gt;
This file contains very condensed information about the run. There is the duration time plus some detail of the reasons behind the 5 fails.&lt;br /&gt;
&lt;br /&gt;
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%&lt;br /&gt;
 % Yambo test suite global REPORT&lt;br /&gt;
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%&lt;br /&gt;
 ==================================================================================&lt;br /&gt;
 Running tests           :Dummy&lt;br /&gt;
 Projects                :nopj&lt;br /&gt;
 Date - Time             :Fri-19-May - 11-46&lt;br /&gt;
 Build                   :master - MPI+SLK - rev.14505&lt;br /&gt;
 Parallel Conf           :[serial] - none&lt;br /&gt;
 =--------------------------------------------------------------------------------=&lt;br /&gt;
 FAIL: 5 &amp;amp; NO RUN: 0 &amp;amp; SKIPS: 0 % WHITELIST: 1 % OKs: 10&lt;br /&gt;
 FAIL details: 1 wrong output % 1 no reference % 1 no output % 2 no DB&lt;br /&gt;
 =--------------------------------------------------------------------------------=&lt;br /&gt;
 % Section Duration : 0:0:3 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%&lt;br /&gt;
 % TOTAL   Duration : 0:0:3 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%&lt;br /&gt;
&lt;br /&gt;
In the dummy case indeed the suite should detect:&lt;br /&gt;
# 1 wrong output&lt;br /&gt;
# 1 output missing the REFERENCE &lt;br /&gt;
# 1 missing output (not generated by the run)&lt;br /&gt;
# 2 missing databases.&lt;br /&gt;
&lt;br /&gt;
More details can be found in the LOG and and in the ERROR.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;The REPORT file is the one used to send final logs to the mailing list.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
=== ERROR file ===&lt;br /&gt;
This is a useful file with detailed information about the errors only. &lt;br /&gt;
&lt;br /&gt;
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%&lt;br /&gt;
 % Yambo test suite ERRORs log&lt;br /&gt;
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%&lt;br /&gt;
 ==================================================================================&lt;br /&gt;
 Running tests           :Dummy&lt;br /&gt;
 Projects                :nopj&lt;br /&gt;
 Date - Time             :Fri-19-May - 11-46&lt;br /&gt;
 Build                   :master - MPI+SLK - rev.14505&lt;br /&gt;
 Parallel Conf           :[serial] - none&lt;br /&gt;
 =--------------------------------------------------------------------------------=&lt;br /&gt;
 Dummy/02_hf-serial-master/o-02_hf.hf  : VALUE(#  17)@COL#  6 is  -5.4691     [REF] vs  -4.4691     [OUT] corresponding to  6.1013     [% RELATIVE TO MAX]&lt;br /&gt;
 Dummy/02_hf-serial-master  :  NO REFERENCE/o-02_hf.ndb.em1s_fragment_1 in OUTPUT&lt;br /&gt;
 Dummy/04_em1s-serial-master  :  NO o-04_em1s.ndb.em1s_fragment_1 in REFERENCE&lt;br /&gt;
 % Section Duration : 0:0:3 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%&lt;br /&gt;
 % TOTAL   Duration : 0:0:3 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%&lt;br /&gt;
&lt;br /&gt;
== Running ==&lt;br /&gt;
Before entering in the details of the different running methods let&#039;s first describe the Parallel Options&lt;br /&gt;
&lt;br /&gt;
=== Parallel Options ===&lt;br /&gt;
    (parallel options)&lt;br /&gt;
              -np     &amp;lt;N&amp;gt;            Fixed number of CPU used&lt;br /&gt;
              -np_min &amp;lt;N&amp;gt;            Minimum number of CPU used&lt;br /&gt;
              -np_max &amp;lt;N&amp;gt;            Maximum number of CPU used&lt;br /&gt;
              -nt     &amp;lt;T&amp;gt;            # of OMP threads&lt;br /&gt;
              -nl     &amp;lt;L&amp;gt;            # of CPU used for linear algebra&lt;br /&gt;
              -def_par               Use the default parallelization scheme&lt;br /&gt;
              -rand_par              Use randomly generated parallel structures&lt;br /&gt;
&lt;br /&gt;
Examples:&lt;br /&gt;
&lt;br /&gt;
 $./driver.pl -tests Dummy -force -np 2&lt;br /&gt;
&lt;br /&gt;
produces all possible combinations of 2 cpu&#039;s for the Dummy tests. Each run is labelled in such a way to be unique. The Dummy folder will look like&lt;br /&gt;
&lt;br /&gt;
 $ls tests/Dummy/&lt;br /&gt;
 01_init-Nmpi2-1-master/  02_hf-Nmpi2-3-master/      03_optics-Nmpi2-3-master/  04_em1s-Nmpi2-3-master/  INPUTS/     yambo.in&lt;br /&gt;
 02_hf                    03_optics                  04_em1s                    04_em1s-Nmpi2-4-master/  LOG/&lt;br /&gt;
 02_hf-Nmpi2-1-master/    03_optics-Nmpi2-1-master/  04_em1s-Nmpi2-1-master/    BROKEN                   REFERENCE/&lt;br /&gt;
 02_hf-Nmpi2-2-master/    03_optics-Nmpi2-2-master/  04_em1s-Nmpi2-2-master/    Dummy.tar.gz             SAVE/&lt;br /&gt;
&lt;br /&gt;
Note that each run is labelled by the number of MPI cpus (&#039;&#039;&#039;Nmpi2&#039;&#039;&#039;) and by the increasing counter of potential combinations of the two cpu&#039;s (&#039;&#039;&#039;-1-master,-2-master,...&#039;&#039;&#039;).&lt;br /&gt;
&lt;br /&gt;
Other potential combinations are&lt;br /&gt;
&lt;br /&gt;
* MPI, default parallelization (no cycle)&lt;br /&gt;
&lt;br /&gt;
 $./driver.pl -tests Dummy -force -np 2 -def_par&lt;br /&gt;
  &lt;br /&gt;
* MPI, random parallelization (no cycle, good for testing)&lt;br /&gt;
&lt;br /&gt;
 $./driver.pl -tests Dummy -force -np 2 -rand_par&lt;br /&gt;
&lt;br /&gt;
* MPI, using 2 and 4 cpu&#039;s, no cycle on combinations, using random parallelization&lt;br /&gt;
&lt;br /&gt;
 $./driver.pl -tests Dummy -force -np_min 2 -np_max 4 -rand_par&lt;br /&gt;
&lt;br /&gt;
* OpenMP (if compiled with OpenMP)&lt;br /&gt;
&lt;br /&gt;
 $./driver.pl -tests Dummy -force -nt 2&lt;br /&gt;
&lt;br /&gt;
* MPI+SLK&lt;br /&gt;
&lt;br /&gt;
 $./driver.pl -tests Dummy -force -np 4 -nl 4 -def_par&lt;br /&gt;
&lt;br /&gt;
== Tests selection ==&lt;br /&gt;
The test-suite can be run in three different ways&lt;br /&gt;
&lt;br /&gt;
# Using a theme&lt;br /&gt;
# Passing individual sets of tests&lt;br /&gt;
# Using flows&lt;br /&gt;
&lt;br /&gt;
Moreover tests can be selected using projects.&lt;br /&gt;
&lt;br /&gt;
Flows are discussed in the [[Test-suite|Flows]].&lt;br /&gt;
&lt;br /&gt;
=== Theme ===&lt;br /&gt;
A theme is a just a series of tests. Themes are stored in the THEMES/ folder and are used simply using&lt;br /&gt;
&lt;br /&gt;
 %./driver.pl -theme test&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;test&#039;&#039; is a text file in the THEMES folder.&lt;br /&gt;
&lt;br /&gt;
=== Individual Tests ===&lt;br /&gt;
This is the way we used to run the Dummy test. Just use &lt;br /&gt;
&lt;br /&gt;
 %./driver.pl -tests Dummy&lt;br /&gt;
&lt;br /&gt;
to select a combination of specific inputs and tests you can use more complex tests options:&lt;br /&gt;
&lt;br /&gt;
 %./driver.pl -tests &amp;quot;Dummy 01_init 02_hf; Si_bulk/GW-OPTICS 00_init 02Cohsex&amp;quot;&lt;br /&gt;
&lt;br /&gt;
=== Projects &amp;amp; Keys ===&lt;br /&gt;
Project are listed with the test lists and are accessed with the lowercase options: elph,sc,rt,nl...&lt;br /&gt;
&lt;br /&gt;
So in order to run &#039;&#039;&#039;all&#039;&#039;&#039; tests belonging to the &#039;&#039;&#039;sc&#039;&#039;&#039; project just type&lt;br /&gt;
&lt;br /&gt;
 $./driver.pl -tests all -keys sc&lt;br /&gt;
&lt;br /&gt;
Actually the -keys option is more powerful as, in the future, should also select all inputs with specific observables (like gw, optics and so on).&lt;br /&gt;
&lt;br /&gt;
The list of project are accessed by simply the first column in the list obtained by using the -l option. In the following are in bold.&lt;br /&gt;
&lt;br /&gt;
 $./driver.pl -l&lt;br /&gt;
 Available test materials/systems: &lt;br /&gt;
 [YAMBO]    Al111&lt;br /&gt;
            C6H3Cl3&lt;br /&gt;
            PA_chain[H]&lt;br /&gt;
            SiH4&lt;br /&gt;
            Al_bulk/GW-OPTICS&lt;br /&gt;
            H2/OPTICS&lt;br /&gt;
            H_chain/2.05&lt;br /&gt;
            H_chain/2.5&lt;br /&gt;
            hBN/GW-OPTICS&lt;br /&gt;
            LiF/GW-OPTICS&lt;br /&gt;
            Si_bulk/GW-OPTICS&lt;br /&gt;
            Si_surface/OPTICS&lt;br /&gt;
            Si_wire/OPTICS&lt;br /&gt;
            MoS2/pwscf/OPTICS&lt;br /&gt;
            MoS2/abinit/OPTICS/With-SOC&lt;br /&gt;
            MoS2/abinit/OPTICS/Without-SOC-sp1&lt;br /&gt;
            MoS2/abinit/OPTICS/Without-SOC-sp2&lt;br /&gt;
 [&#039;&#039;&#039;QED&#039;&#039;&#039;]      Si_bulk/QED&lt;br /&gt;
 [&#039;&#039;&#039;NL&#039;&#039;&#039;]       hBN/NL&lt;br /&gt;
 [&#039;&#039;&#039;RT&#039;&#039;&#039;]       AlAs[H]&lt;br /&gt;
            H2/RT&lt;br /&gt;
            hBN/RT&lt;br /&gt;
            Si_bulk/RT&lt;br /&gt;
            WSe2/RT[H]&lt;br /&gt;
            MoS2/pwscf/RT&lt;br /&gt;
 [&#039;&#039;&#039;SC&#039;&#039;&#039;]       H2/SC&lt;br /&gt;
            hBN/SC&lt;br /&gt;
            Si_bulk/SC&lt;br /&gt;
 [&#039;&#039;&#039;MAGNETIC&#039;&#039;&#039;] Si_bulk/MAGNETIC&lt;br /&gt;
 [&#039;&#039;&#039;ELPH&#039;&#039;&#039;]     Diamond/ELPH1[H]&lt;br /&gt;
            Si_bulk/ELPH/BSE&lt;br /&gt;
            Si_bulk/ELPH/ELPH_base&lt;br /&gt;
            Si_bulk/ELPH/ELPH_for_BSE&lt;br /&gt;
            Si_bulk/ELPH/QP_CTL&lt;br /&gt;
 [&#039;&#039;&#039;KERR&#039;&#039;&#039;]     Cobalt&lt;br /&gt;
            Nickel&lt;br /&gt;
            Iron/pwscf&lt;br /&gt;
            Iron/abinit/With-SOC&lt;br /&gt;
            Iron/abinit/Without-SOC&lt;br /&gt;
 [BROKEN]   Dummy&lt;br /&gt;
            GaAs001-c4x4/YAMBO&lt;br /&gt;
            hBN/PL[PL]&lt;br /&gt;
            Si001-c4x2/YAMBO&lt;br /&gt;
            WS2/PL[PL]&lt;br /&gt;
&lt;br /&gt;
Note that to access any of these projects you must use the lowercase option. For example&lt;br /&gt;
*SC → -keys sc&lt;br /&gt;
*RT → -keys rt&lt;br /&gt;
*SC+RT → -keys &#039;sc rt&#039;&lt;br /&gt;
&lt;br /&gt;
=== HARD tests ===&lt;br /&gt;
Some of the tests are long. In the tests list they are labelled with a &#039;&#039;&#039;[H]&#039;&#039;&#039;. In order to run them the key &#039;&#039;hard&#039;&#039; must be used. For example&lt;br /&gt;
&lt;br /&gt;
 %./driver.pl -tests all -keys &#039;sc rt hard&#039;&lt;br /&gt;
&lt;br /&gt;
runs all SC+RT tests including the heavy ones.&lt;br /&gt;
&lt;br /&gt;
== FLOWS ==&lt;br /&gt;
All properties of a single launch of the test-suite and also a more complex test-suite launch looping on several parallel, tests, branches, combinations can be controlled via the FLOW feature.&lt;br /&gt;
&lt;br /&gt;
A FLOW is a perl file (like validate.pl) containing combinations of descriptors.&lt;br /&gt;
&lt;br /&gt;
All FLOW files are in the &#039;&#039;&#039;ROBOTS/&amp;lt;YOUR ROBOT&amp;gt;/FLOWS&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
A FLOW is run using &lt;br /&gt;
&lt;br /&gt;
%./driver.pl -flow validate&lt;br /&gt;
&lt;br /&gt;
A general flow descriptor is&lt;br /&gt;
 % {&lt;br /&gt;
 % ACTIVE      =&amp;gt; &amp;quot;yes&amp;quot;, # can be yes or no&lt;br /&gt;
 % MPI_CPU     =&amp;gt; &amp;quot;NP&amp;quot;,&lt;br /&gt;
 % SLK_CPU     =&amp;gt; &amp;quot;NM&amp;quot;,&lt;br /&gt;
 % PAR_MODE    =&amp;gt; &amp;quot;TEXT&amp;quot;, # (TEXT can be default, random, loop)&lt;br /&gt;
 % THREADS     =&amp;gt; &amp;quot;NT&amp;quot;,&lt;br /&gt;
 % BRANCH      =&amp;gt; &amp;quot;/home/marini/Yambo/sources/git/yambo/branches/SLK&amp;quot;, # (SAVED)&lt;br /&gt;
 % THEME       =&amp;gt; &amp;quot;G_parallelization&amp;quot;, # (SAVED)&lt;br /&gt;
 % CONFIG      =&amp;gt; &amp;quot;gfortran_slk.sh&amp;quot;, # (SAVED)&lt;br /&gt;
 % TESTS       =&amp;gt; &amp;quot;hBN/GW-OPTICS&amp;quot;, #  (SAVED)&lt;br /&gt;
 % KEYS        =&amp;gt; &amp;quot;nopj elph hard bse rpa&amp;quot;, # (SAVED)&lt;br /&gt;
 %}&lt;br /&gt;
&lt;br /&gt;
The fields labelled with a &#039;&#039;&#039;(SAVE)&#039;&#039;&#039; are not changed if this descriptor is included in a more complex FLOW. In order to explain this feature let&#039;s just have a look at the default validate FLOW provided by default:&lt;br /&gt;
&lt;br /&gt;
 %#!/usr/bin/perl&lt;br /&gt;
 %#&lt;br /&gt;
 %@flow = (&lt;br /&gt;
 %{&lt;br /&gt;
 % ACTIVE      =&amp;gt; &amp;quot;yes&amp;quot;,&lt;br /&gt;
 % CONFIG      =&amp;gt; &amp;quot;default.sh&amp;quot;,&lt;br /&gt;
 % KEYS        =&amp;gt; &amp;quot;nopj elph sc hard&amp;quot;,&lt;br /&gt;
 %},&lt;br /&gt;
 %{&lt;br /&gt;
 % MPI_CPU     =&amp;gt; $SYSTEM_NP,&lt;br /&gt;
 % PAR_MODE    =&amp;gt; &amp;quot;default&amp;quot;,&lt;br /&gt;
 %},&lt;br /&gt;
 %{&lt;br /&gt;
 % MPI_CPU     =&amp;gt; $SYSTEM_NP,&lt;br /&gt;
 % PAR_MODE    =&amp;gt; &amp;quot;random&amp;quot;,&lt;br /&gt;
 %},&lt;br /&gt;
 %{&lt;br /&gt;
 % MPI_CPU     =&amp;gt; $SYSTEM_NP_half,&lt;br /&gt;
 % PAR_MODE    =&amp;gt; &amp;quot;loop&amp;quot;,&lt;br /&gt;
 %},&lt;br /&gt;
 %{&lt;br /&gt;
 % THREADS     =&amp;gt; $SYSTEM_NP_half,&lt;br /&gt;
 %},&lt;br /&gt;
 %{&lt;br /&gt;
 % MPI_CPU     =&amp;gt; $SYSTEM_NP,&lt;br /&gt;
 % SLK_CPU     =&amp;gt; $SYSTEM_NP_half,&lt;br /&gt;
 % PAR_MODE    =&amp;gt; &amp;quot;default&amp;quot;,&lt;br /&gt;
 %},&lt;br /&gt;
 %{&lt;br /&gt;
 % MPI_CPU     =&amp;gt; $SYSTEM_NP_half,&lt;br /&gt;
 % THREADS     =&amp;gt; $SYSTEM_NP_half,&lt;br /&gt;
 % SLK_CPU     =&amp;gt; $SYSTEM_SLK,&lt;br /&gt;
 % PAR_MODE    =&amp;gt; &amp;quot;default&amp;quot;,&lt;br /&gt;
 %},&lt;br /&gt;
 %);&lt;br /&gt;
&lt;br /&gt;
When this flow is launched the driver.pl will run all tests of the &#039;&#039;&amp;quot;nopj elph sc hard&amp;quot;&#039;&#039; projects using: a serial run, all system CPU&#039;s with default parallelization, with random parallelization, cycling among all possible combinations and so so...&lt;br /&gt;
&lt;br /&gt;
Note that also the -autotest is just a simple calculation flow.&lt;br /&gt;
&lt;br /&gt;
== Robots ==&lt;br /&gt;
In version 5.0 the concept of Robots was introduced. In practice each time you run the driver.pl test-suite in any form (compilation, flow, manual tests and so on) the perl script will create a ROBOT. &lt;br /&gt;
&lt;br /&gt;
In practice this means that all operations will be labelled with a &amp;lt;ROBOT&amp;gt; string. Single tests, executables will be copied to a dedicated ROBOT folder and also the LOG and REPORT files will be labelled by the specific ROBOT they belong to.&lt;br /&gt;
&lt;br /&gt;
The benefits of this ROBOT structure is that multiple ROBOTS can be run simultaneously on the same test-suite!&lt;br /&gt;
&lt;br /&gt;
Try yourself by simply running two instances of driver.pl.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;WARNING: when you run more than 1 robot at the same time be sure to give time to the driver.pl to open all log files&#039;&#039;&#039;. &lt;br /&gt;
&lt;br /&gt;
In addition if you are compiling the same source leave the robot the time to compile it before running a second robot on the same source.&lt;br /&gt;
&lt;br /&gt;
=== Robot specific operations ===&lt;br /&gt;
&lt;br /&gt;
You can clean/kill only the robot ID by using&lt;br /&gt;
&lt;br /&gt;
 %./driver.pl -c -robot ID&lt;br /&gt;
 %./driver.pl -kill -robot ID&lt;br /&gt;
&lt;br /&gt;
You can also launch the driver.pl with a specific robot ID&lt;br /&gt;
&lt;br /&gt;
 %./driver.pl -flow validate -robot ID&lt;br /&gt;
&lt;br /&gt;
=== Robot branches ===&lt;br /&gt;
&lt;br /&gt;
When several robots are run at the same time it is often necessary to specify for each robot a branch to do. This can be easily done via the branch file. This is an example of robot dependent branch file (obtained via the ./driver.pl -e branches) command&lt;br /&gt;
&lt;br /&gt;
 /home/marini/yambo/master master R1&lt;br /&gt;
 /home/marini/yambo/master master R2&lt;br /&gt;
 /home/marini/yambo/gpl master R3&lt;br /&gt;
 /home/marini/yambo/gpl master R4&lt;br /&gt;
 /home/marini/yambo/gpl master R5&lt;br /&gt;
 /home/marini/yambo/gpl master R6&lt;br /&gt;
 /home/marini/yambo/branches/devel-rt-stable devel-rt-stable R7&lt;br /&gt;
 /home/marini/yambo/branches/devel-rt-stable devel-rt-stable R8&lt;br /&gt;
                                                                  &lt;br /&gt;
This file commands the driver.pl to run the master when the robot ID (-robot ID) is 1 or 2, the gpl for robots from 3 to 6 and so on.&lt;br /&gt;
&lt;br /&gt;
== Adding New Tests ==&lt;br /&gt;
&lt;br /&gt;
Adding a new test is easy.&lt;br /&gt;
&lt;br /&gt;
Let&#039;s use a simple example.&lt;br /&gt;
&lt;br /&gt;
Imagine I want to add the test hBN/PIPPO for which I have the SAVE and a list of input files. I copy everything in TESTS/MAIN/hBN creating a new directory, PIPPO&lt;br /&gt;
&lt;br /&gt;
 hBN&amp;gt;ls&lt;br /&gt;
 GW-OPTICS  hBN.tar.gz  NL  PIPPO  PL	RT  SC&lt;br /&gt;
&lt;br /&gt;
In PIPPO I have only the INPUTS and SAVE folders&lt;br /&gt;
&lt;br /&gt;
 PIPPO&amp;gt;ls -R&lt;br /&gt;
 .:&lt;br /&gt;
 INPUTS  SAVE  &lt;br /&gt;
&lt;br /&gt;
 ./INPUTS:&lt;br /&gt;
&lt;br /&gt;
 01_init  02_HF&lt;br /&gt;
&lt;br /&gt;
 ./SAVE:&lt;br /&gt;
 ns.db1	ns.kb_pp  ns.kb_pp_fragment_1  ns.kb_pp_fragment_2  ns.kb_pp_fragment_3  ns.kb_pp_fragment_4  ns.wf  ns.wf_fragments_1_1  &lt;br /&gt;
 ns.wf_fragments_2_1  ns.wf_fragments_3_1  ns.wf_fragments_4_1&lt;br /&gt;
&lt;br /&gt;
At this point I simply run&lt;br /&gt;
 &lt;br /&gt;
 ./driver.pl -update hBN/PIPPO&lt;br /&gt;
&lt;br /&gt;
The driver will run the inputs, create the REFERENCE folder, the .tar.gz of the new test which is uploaded on the ftp server. &lt;br /&gt;
&lt;br /&gt;
Remember to add -compile if your source is not compiled.&lt;br /&gt;
&lt;br /&gt;
At the end of the calculation the git status command should give&lt;br /&gt;
&lt;br /&gt;
 yambo-tests&amp;gt;git status&lt;br /&gt;
 On branch master&lt;br /&gt;
 Your branch is up-to-date with &#039;origin/master&#039;.&lt;br /&gt;
 Changes to be committed:&lt;br /&gt;
  (use &amp;quot;git reset HEAD &amp;lt;file&amp;gt;...&amp;quot; to unstage)&lt;br /&gt;
     new file:   TESTS/MAIN/hBN/PIPPO/INPUTS/01_init&lt;br /&gt;
     new file:   TESTS/MAIN/hBN/PIPPO/INPUTS/02_HF&lt;br /&gt;
     new file:   TESTS/MAIN/hBN/PIPPO/REFERENCE/l-02_HF_HF_and_locXC&lt;br /&gt;
     new file:   TESTS/MAIN/hBN/PIPPO/REFERENCE/o-02_HF.hf&lt;br /&gt;
     new file:   TESTS/MAIN/hBN/PIPPO/REFERENCE/o-02_HF.ndb.HF_and_locXC&lt;br /&gt;
     new file:   TESTS/MAIN/hBN/PIPPO/REFERENCE/r-02_HF_HF_and_locXC&lt;br /&gt;
     new file:   TESTS/MAIN/hBN/PIPPO/SAVE/.empty&lt;br /&gt;
&lt;br /&gt;
It&#039;s now enough that you push and the new test will be ready!&lt;/div&gt;</summary>
		<author><name>Fulvio</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=First_steps_in_Yambopy&amp;diff=7530</id>
		<title>First steps in Yambopy</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=First_steps_in_Yambopy&amp;diff=7530"/>
		<updated>2023-11-24T09:33:55Z</updated>

		<summary type="html">&lt;p&gt;Fulvio: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The yambopy project aims to develop python tools to: &lt;br /&gt;
&lt;br /&gt;
* Read and edit yambo and quantum espresso input files&lt;br /&gt;
* Easily perform pre- and post-processing of the simulation data for these two codes - including hard-to-get, database-encoded data beyond standard outputs&lt;br /&gt;
* Provide easy visualization and plotting options &lt;br /&gt;
* Set up simple automatization workflows (e.g., convergence tests)&lt;br /&gt;
&lt;br /&gt;
=== Setup ===&lt;br /&gt;
Make sure that you are using Python 3, and follow the  [https://www.yambo-code.eu/wiki/index.php/Setting_up_Yambo#Setting_up_Yambopy setup instructions for Yambopy]. The &amp;lt;code&amp;gt;abipy&amp;lt;/code&amp;gt; [[https://abinit.github.io/abipy/index.html]] package is optional. You may however want to have it installed for band structure interpolations.&lt;br /&gt;
&lt;br /&gt;
=== Tutorials ===&lt;br /&gt;
Now yambopy is ready to use! Just go to the tutorials folder and follow the docs!&lt;br /&gt;
&lt;br /&gt;
 cd tutorial/&lt;br /&gt;
&lt;br /&gt;
On this wiki, we provide steps for the following tutorials:&lt;br /&gt;
* [[GW tutorial. Convergence and approximations (BN)]]&lt;br /&gt;
* [[Bethe-Salpeter equation tutorial. Optical absorption (BN)]]&lt;br /&gt;
* [[Yambopy tutorial: band structures | Database and plotting tutorial for quantum espresso: qepy]] (Get the databases: [https://media.yambo-code.eu/educational/tutorials/files/databases_qepy.tar databases_qepy], 59MB)&lt;br /&gt;
* [[Yambopy tutorial: Yambo databases | Database and plotting tutorial for yambo: yambopy ]] (Get the databases: [https://media.yambo-code.eu/educational/tutorials/files/databases_yambopy.tar databases_yambopy], 226MB)&lt;br /&gt;
* [[Phonon-assisted luminescence by finite atomic displacements]]&lt;/div&gt;</summary>
		<author><name>Fulvio</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_band_structures&amp;diff=7082</id>
		<title>Yambopy tutorial: band structures</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Yambopy_tutorial:_band_structures&amp;diff=7082"/>
		<updated>2023-07-04T12:28:46Z</updated>

		<summary type="html">&lt;p&gt;Fulvio: /* Tutorial 3 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
This tutorial will show you how to visualise wave-function and band-structure related information following a DFT Quantum Espresso calculation using the &amp;quot;qepy&amp;quot; module of Yambopy.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Concerning the ICTP school: recall that for the yambopy tutorials you have to load the yambo, quantum-espresso and anaconda3 modules:&#039;&#039;&#039;&lt;br /&gt;
 spack load yambo&lt;br /&gt;
 spack load quantum-espresso&lt;br /&gt;
 spack load anaconda3&lt;br /&gt;
&#039;&#039;&#039;You can copy the tutorial databases as explained in the virtual machine setup page: &#039;&#039;&#039;&lt;br /&gt;
 cp -r /media/ictpuser/smr3694/ictptutor/YAMBOPY_TUTORIALS ~/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The full tutorial, including the Quantum espresso and Yambo databases that we will read, can be downloaded and extracted from the yambo website:&lt;br /&gt;
 $wget https://media.yambo-code.eu/educational/tutorials/files/databases_qepy.tar&lt;br /&gt;
 $tar -xvf databases_qepy.tar&lt;br /&gt;
 $cd databases_qepy&lt;br /&gt;
&lt;br /&gt;
==Tutorial 1. BN (semiconductor). Band structure==&lt;br /&gt;
&lt;br /&gt;
First enter in the folder &lt;br /&gt;
 cd databases_qepy/bn-semiconductor&lt;br /&gt;
and have a look to the &lt;br /&gt;
 vim plot-qe-bands.py&lt;br /&gt;
The qepy classes are useful both to execute Quantum Espresso and to analyze the results. Enter in the python environment, by typing &amp;lt;code&amp;gt;python&amp;lt;/code&amp;gt;, then the full qepy library is imported by simply doing:&lt;br /&gt;
&lt;br /&gt;
 from qepy import *&lt;br /&gt;
&lt;br /&gt;
===Plot Band structure===&lt;br /&gt;
&lt;br /&gt;
The qepy class &#039;&#039;&#039;PwXML&#039;&#039;&#039; reads the data file generated by Quantum Espresso and post-processes the data. The class is instanced by doing:&lt;br /&gt;
&lt;br /&gt;
 xml = PwXML(prefix=&#039;bn&#039;, path=&#039;bands&#039;)&lt;br /&gt;
&lt;br /&gt;
The variable prefix corresponds to the same variable of the QE input. The folder location is indicated by variable path. In order to plot the bands, we also define the k-points path (in crystal coordinates) using the function Path:&lt;br /&gt;
&lt;br /&gt;
 npoints = 50&lt;br /&gt;
 path_kpoints = Path([ [[0.0, 0.0, 0.0],&#039;$\Gamma$&#039;],&lt;br /&gt;
                       [[0.5, 0.0, 0.0],&#039;M&#039;],&lt;br /&gt;
                       [[1./3,1./3,0.0],&#039;K&#039;],&lt;br /&gt;
                       [[0.0, 0.0, 0.0],&#039;$\Gamma$&#039;]], [int(npoints*2),int(npoints),int(sqrt(5)*npoints)])&lt;br /&gt;
&lt;br /&gt;
It is worth to note that the path should coincide with the selected path for the QE band calculations.&lt;br /&gt;
&lt;br /&gt;
In order to show the plot we call the &#039;&#039;&#039;plot_eigen&#039;&#039;&#039; method of the &#039;&#039;&#039;PwXML&#039;&#039;&#039; class:&lt;br /&gt;
&lt;br /&gt;
 xml.plot_eigen(path_kpoints)&lt;br /&gt;
&lt;br /&gt;
This function will automatically plot the bands as shown below running the script:&lt;br /&gt;
&lt;br /&gt;
 python plot-qe-bands.py&lt;br /&gt;
&lt;br /&gt;
[[File:Bands BN 1.png| 400 px | center |Band structure of BN calculated at the level of DFT-LDA]]&lt;br /&gt;
&lt;br /&gt;
Alternatively, we can use the function &#039;&#039;&#039;plot_eigen_ax&#039;&#039;&#039;. This functions requires as input a matplotlib &#039;&#039;&#039;figure&#039;&#039;&#039; object with given axes, as you will see in the next example.&lt;br /&gt;
&lt;br /&gt;
===Plot atomic orbital projected Band structure===&lt;br /&gt;
&lt;br /&gt;
In addition to the band structure, useful information regarding the atomic orbital nature of the electronic wave functions can be displayed using the class &#039;&#039;&#039;ProjwfcXML&#039;&#039;&#039;. &lt;br /&gt;
In order to make quantum espresso calculate the relevant data, we need to use the QE executable &#039;&#039;&#039;projwfc.x&#039;&#039;&#039;, which will create the file &#039;&#039;&#039;atomic_proj.xml&#039;&#039;&#039;. This executable projects the Kohn-Sham wavefunctions onto orthogonalized atomic orbitals, among others functionalities. The orbital indexing  and ordering are explained in the input documentation of the projwfc.x function which you are invited to check (https://www.quantum-espresso.org/Doc/INPUT_PROJWFC.html#idm94). We can run &#039;&#039;&#039;projwf.x&#039;&#039;&#039; directly from the python script using the qepy class &#039;&#039;&#039;ProjwfcIn&#039;&#039;&#039;:&lt;br /&gt;
&lt;br /&gt;
 proj = ProjwfcIn(prefix=&#039;bn&#039;)&lt;br /&gt;
 proj.run(folder=&#039;bands&#039;)&lt;br /&gt;
&lt;br /&gt;
Be aware that this can take a while in a large system with many k-points. As in the class &#039;&#039;&#039;PwXML&#039;&#039;&#039;, we then define the path_kpoints and also the selected atomic orbitals to project our bands. We have chosen to represent the projection weight onto the nitrogen (1) and boron (2) orbitals, which according to the projection orderings is given by&lt;br /&gt;
&lt;br /&gt;
 atom_1 = list(range(16))&lt;br /&gt;
 atom_2 = list(range(16,32)) &lt;br /&gt;
&lt;br /&gt;
The full list of orbitals is written in the file &#039;&#039;&#039;bands/prowfc.log&#039;&#039;&#039;. We have also defined the figure box&lt;br /&gt;
&lt;br /&gt;
 import matplotlib.pyplot as plt&lt;br /&gt;
 fig = plt.figure(figsize=(5,7))&lt;br /&gt;
 ax  = fig.add_axes( [ 0.12, 0.10, 0.70, 0.80 ])&lt;br /&gt;
&lt;br /&gt;
The class &#039;&#039;&#039;ProjwfcXML&#039;&#039;&#039; then runs as in this example:&lt;br /&gt;
&lt;br /&gt;
 band = ProjwfcXML(prefix=&#039;bn&#039;,path=&#039;bands&#039;,qe_version=&#039;7.0&#039;)&lt;br /&gt;
 band.plot_eigen(ax,path_kpoints=path_kpoints,cmap=&#039;viridis&#039;,selected_orbitals=atom_1,selected_orbitals_2=atom_2)&lt;br /&gt;
&lt;br /&gt;
We can run now the file:&lt;br /&gt;
&lt;br /&gt;
 python plot-qe-orbitals.py&lt;br /&gt;
&lt;br /&gt;
[[File:Bands AOP BN 1.png| 400 px | center | Atomic orbital projected band structure of monolayer BN]]&lt;br /&gt;
&lt;br /&gt;
We have chosen the colormap &#039;viridis&#039; (variable cmap). You see that the colormap goes from maximum &#039;&#039;&#039;selected_orbitals&#039;&#039;&#039; content (in this case nitrogen) to the maximum &#039;&#039;&#039;selected_orbitals_2&#039;&#039;&#039; content (in this case boron). &lt;br /&gt;
The colormap can be represented in many ways and qepy does not include a particular function for this. An example is:&lt;br /&gt;
&lt;br /&gt;
 import matplotlib as mpl&lt;br /&gt;
 cmap=plt.get_cmap(&#039;viridis&#039;)&lt;br /&gt;
 bx  = fig.add_axes( [ 0.88, 0.10, 0.05, 0.80 ])&lt;br /&gt;
 norm = mpl.colors.Normalize(vmin=0.,vmax=1.)&lt;br /&gt;
 cb1 = mpl.colorbar.ColorbarBase(bx, cmap=cmap, norm=norm,orientation=&#039;vertical&#039;,ticks=[0,1])&lt;br /&gt;
 cb1.set_ticklabels([&#039;B&#039;, &#039;N&#039;])&lt;br /&gt;
&lt;br /&gt;
We can also plot the band orbital charater with size variation instead of a color scale. In this case we have to pass only the variable selected_orbitals (see the next tutorial).&lt;br /&gt;
&lt;br /&gt;
==Tutorial 2. Iron. Ferromagnetic metalic material==&lt;br /&gt;
&lt;br /&gt;
In the case of spin-polarized calculations we can plot the spin up and down band structures. We have included in the tutorial a small workflow example to run quantum espresso calculations from scratch. This is done using the classes Tasks and Flows developed in yambopy. You can check the file flow-iron.py for an example. &lt;br /&gt;
Yambopy includes basic predefined workflows to run the common QE and Yambo calculations. In this case we are using the class &#039;&#039;&#039;PwBandsTasks&#039;&#039;&#039;.&lt;br /&gt;
&lt;br /&gt;
 python flow-iron.py&lt;br /&gt;
&lt;br /&gt;
In order to plot the spin-polarized bands. After doing all the calculations from scratch with the flows (flow-iron.py), we can make the band plot by running the script:&lt;br /&gt;
&lt;br /&gt;
 python plot-qe-bands.py&lt;br /&gt;
&lt;br /&gt;
The class PwXML automatically detects the spin polarized case (nspin=2 in the QE input file). The spin up channel is displayed with red and the spin down channel with blue. In the case of iron we have selected this k-point path:&lt;br /&gt;
&lt;br /&gt;
 npoints = 50&lt;br /&gt;
 path_kpoints = Path([ [[0.0, 0.0, 0.0 ],&#039;G&#039;],&lt;br /&gt;
                       [[0.0, 0.0, 1.0 ],&#039;H&#039;],&lt;br /&gt;
                       [[1./2,0.0,1./2.],&#039;N&#039;],&lt;br /&gt;
                       [[0.0, 0.0, 0.0 ],&#039;G&#039;],&lt;br /&gt;
                       [[1./2, 1./2, 1./2 ],&#039;P&#039;],&lt;br /&gt;
                       [[1./2,0.0,1./2. ],&#039;N&#039;]], [npoints,npoints,npoints,npoints,npoints])&lt;br /&gt;
&lt;br /&gt;
 xml = PwXML(prefix=&#039;pw&#039;,path=&#039;bands/t0&#039;)&lt;br /&gt;
 xml.plot_eigen(path_kpoints)&lt;br /&gt;
&lt;br /&gt;
[[File:Figure 3-iron-bands.png| 600 px | center |Spin polarized band structure of iron calculated by DFT]]&lt;br /&gt;
&lt;br /&gt;
The analysis of the projected atomic orbitals is also implemented. In this case the results are more cumbersome because the projection is separated in spin up and down channels.&amp;lt;br&amp;gt; &lt;br /&gt;
Let us look first at the file &#039;&#039;&#039;plot-qe-orbitals-size&#039;&#039;&#039;. &amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;NB: If you generated the quantum espresso databases using the flows instead of relying on the precomputed databases, you also need to rerun the quantum espresso executable projwfc.x to recompute the orbital projections. In this case, please uncomment the following lines in the script&#039;&#039;&#039; (plot-qe-orbitals-size.py) :&lt;br /&gt;
 #proj = ProjwfcIn(prefix=&#039;pw&#039;)&lt;br /&gt;
 #proj.run(folder=&#039;bands/t0&#039;)&lt;br /&gt;
&lt;br /&gt;
Now, we can use the dot size as a function of the weight of the orbitals&lt;br /&gt;
 atom_s = [8]&lt;br /&gt;
 atom_p = [0,1,2]&lt;br /&gt;
 atom_d = [3,4,5,6,7]&lt;br /&gt;
&lt;br /&gt;
and the plots are done with&lt;br /&gt;
 band = ProjwfcXML(prefix=&#039;pw&#039;,path=&#039;bands/t0&#039;,qe_version=&#039;7.0&#039;)&lt;br /&gt;
 band.plot_eigen(ax,path_kpoints=path_kpoints,&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;selected_orbitals=atom_s,&amp;lt;/span&amp;gt;color=&#039;pink&#039;,color_2=&#039;black&#039;)&lt;br /&gt;
 band.plot_eigen(ax,path_kpoints=path_kpoints,&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;selected_orbitals=atom_p,&amp;lt;/span&amp;gt;color=&#039;green&#039;,color_2=&#039;orange&#039;)&lt;br /&gt;
 band.plot_eigen(ax,path_kpoints=path_kpoints,&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;selected_orbitals=atom_d,&amp;lt;/span&amp;gt;color=&#039;red&#039;,color_2=&#039;blue&#039;)&lt;br /&gt;
&lt;br /&gt;
As an example, we can select just the &#039;&#039;d&#039;&#039; orbitals by commenting the first two plots and then running the file:&lt;br /&gt;
&lt;br /&gt;
 plot-qe-orbitals-size.py&lt;br /&gt;
&lt;br /&gt;
[[File:Figure 4-iron-bands-size-d-orbitals.png|400px|center|Iron band structure. Size is proportional to the weights of the projection on atomic d-orbitals. Red (blue) is up (down) spin polarization.]]&lt;br /&gt;
&lt;br /&gt;
From the plot is clear that &#039;&#039;d&#039;&#039; orbitals are mainly localized around the Fermi energy. The plot above is in red and blue, while the default choice in your script should be pink and black. You can experiment with the colors and other &#039;&#039;matplotlib&#039;&#039; plot options and also plot the other orbital types.&lt;br /&gt;
&lt;br /&gt;
Another option is to plot the orbital composition as a colormap running the file:&lt;br /&gt;
&lt;br /&gt;
 plot-qe-orbitals-colormap.py&lt;br /&gt;
&lt;br /&gt;
[[File:Figure 5-iron-bands-colormap.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
Here we have added the p and d orbitals in the analysis:&lt;br /&gt;
&lt;br /&gt;
 atom_p = [0,1,2]&lt;br /&gt;
 atom_d = [3,4,5,6,7]&lt;br /&gt;
 band = ProjwfcXML(prefix=&#039;pw&#039;,path=&#039;bands/t0&#039;,qe_version=&#039;7.0&#039;)&lt;br /&gt;
 band.plot_eigen(ax,path_kpoints=path_kpoints,cmap=&#039;viridis&#039;,cmap2=&#039;rainbow&#039;,selected_orbitals=atom_p,selected_orbitals_2=atom_d)&lt;br /&gt;
&lt;br /&gt;
The colormap bar is added in the same way as in Tutorial 1 (see script), but this time we have a different colormap for each spin polarisation.&lt;br /&gt;
&lt;br /&gt;
==Tutorial 3: GW bands==&lt;br /&gt;
&lt;br /&gt;
Yambopy can be used either to run Yambo and QE calculations, or to analyse the results of QE and Yambo by dealing with their generated databases. This is done with a variety of classes included in the qepy (for QE) or yambopy (for Yambo) modules. &lt;br /&gt;
In the case of Yambo GW quasi-particle calculations, we can use the yambopy class &#039;&#039;&#039;YamboQPDB&#039;&#039;&#039; to read the database produced by the simulation.&lt;br /&gt;
Enter in the folder&lt;br /&gt;
 cd ../gw-bands&lt;br /&gt;
We can use this to find the scissor operator, plot the GW bands and to interpolate the GW bands on a smoother k-path. The example runs by typing:&lt;br /&gt;
&lt;br /&gt;
 python plot-qp.py&lt;br /&gt;
&lt;br /&gt;
See below for an explanation of the tutorial. As usual, we can import the qepy and yambopy libraries:&lt;br /&gt;
&lt;br /&gt;
  from qepy import *&lt;br /&gt;
  from yambopy import *&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
&lt;br /&gt;
We define the k-points path.&lt;br /&gt;
  npoints = 10&lt;br /&gt;
  path = Path([ [[  0.0,  0.0,  0.0],&#039;$\Gamma$&#039;],&lt;br /&gt;
                [[  0.5,  0.0,  0.0],&#039;M&#039;],&lt;br /&gt;
                [[1./3.,1./3.,  0.0],&#039;K&#039;],&lt;br /&gt;
                [[  0.0,  0.0,  0.0],&#039;$\Gamma$&#039;]], [int(npoints*2),int(npoints),int(sqrt(5)*npoints)] )&lt;br /&gt;
&lt;br /&gt;
Importantly, the number of points is a free choice. We can increase the variable npoints as we wish, it just means that the interpolation step will take more time. In order to analyse GW results we need to have the file related to the basic data of our Yambo calculation (&#039;&#039;&#039;SAVE/ns.db1&#039;&#039;&#039;) and the netcdf file with the quasi-particle results (&#039;&#039;&#039;ndb.QP&#039;&#039;&#039;). We load the data calling the respective classes:&lt;br /&gt;
&lt;br /&gt;
 # Read Lattice information from SAVE&lt;br /&gt;
 lat  = YamboSaveDB.from_db_file(folder=&#039;SAVE&#039;,filename=&#039;ns.db1&#039;)&lt;br /&gt;
 # Read QP database&lt;br /&gt;
 ydb  = YamboQPDB.from_db(filename=&#039;ndb.QP&#039;,folder=&#039;qp-gw&#039;)&lt;br /&gt;
(in the yambopy module, each class is specialised to read a specific Yambo database)&lt;br /&gt;
&lt;br /&gt;
The first option is to plot the energies and calculate the ideal Kohn-Sham to GW scissor operator. We need to select the index of the top valence band:&lt;br /&gt;
&lt;br /&gt;
 n_top_vb = 4&lt;br /&gt;
 ydb.plot_scissor_ax(ax,n_top_vb)&lt;br /&gt;
&lt;br /&gt;
Yambopy displays the fitting and also the data of the slope of each fitting. Notice that this is also a test if the GW calculations are running well. &#039;&#039;&#039;If the dependence is not linear you should double-check your results!&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[[File:Figure 6-slope-scissor.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
In this case the slope is:&lt;br /&gt;
&lt;br /&gt;
 valence bands:&lt;br /&gt;
 slope:     1.0515886598785766&lt;br /&gt;
 conduction bands:&lt;br /&gt;
 slope:     1.026524081134514&lt;br /&gt;
 scissor list (shift,c,v) [eV,adim,adim]: [1.8985204833551723, 1.026524081134514, 1.0515886598785766]&lt;br /&gt;
&lt;br /&gt;
In addition to the scissor operator, we can plot the GW (and DFT) band structure along the path. The first choice would be to plot the actual GW calculations, without interpolation, to check that the results are meaningful (or not). This plot is independent of the number of k-points (&#039;&#039;&#039;npoints&#039;&#039;&#039;) that we want to put in the interpolation. The class YamboQPDB finds the calculated points that belong to the path and plots them. Be aware that if we use coarse grids the class would not find any point and the function will not work.&lt;br /&gt;
&lt;br /&gt;
 ks_bs_0, qp_bs_0 = ydb.get_bs_path(lat,path)&lt;br /&gt;
 ks_bs_0.plot_ax(ax,legend=True,color_bands=&#039;r&#039;,label=&#039;KS&#039;)&lt;br /&gt;
 qp_bs_0.plot_ax(ax,legend=True,color_bands=&#039;b&#039;,label=&#039;QP-GW&#039;)&lt;br /&gt;
&lt;br /&gt;
[[File:Figure 7-GW-band-structure-non-interpolated.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
The interpolation of the DFT and GW band structures looks similar:&lt;br /&gt;
&lt;br /&gt;
 ks_bs, qp_bs = ydb.interpolate(lat,path,what=&#039;QP+KS&#039;,lpratio=20)&lt;br /&gt;
 ks_bs.plot_ax(ax,legend=True,color_bands=&#039;r&#039;,label=&#039;KS&#039;)&lt;br /&gt;
 qp_bs.plot_ax(ax,legend=True,color_bands=&#039;b&#039;,label=&#039;QP-GW&#039;)&lt;br /&gt;
&lt;br /&gt;
The &#039;&#039;&#039;lpratio&#039;&#039;&#039; can be increased if the interpolation does not work as well as intended. The interpolation is the same one implemented in abipy and currently requires abipy installed in order to work.&lt;br /&gt;
&lt;br /&gt;
[[File:Figure 8-GW-band-structure-interpolated.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
Finally, we can compare the calculated GW eigenvalues with the interpolation.&lt;br /&gt;
&lt;br /&gt;
[[File:Figure 8-GW-band-structure-comparison.png|400px|center]]&lt;br /&gt;
&lt;br /&gt;
==Links==&lt;br /&gt;
* Back to [[Rome 2023#Tutorials]]&lt;br /&gt;
* Back to [[ICTP 2022#Tutorials]]&lt;/div&gt;</summary>
		<author><name>Fulvio</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Tutorials&amp;diff=7057</id>
		<title>Tutorials</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Tutorials&amp;diff=7057"/>
		<updated>2023-06-15T14:34:24Z</updated>

		<summary type="html">&lt;p&gt;Fulvio: /* Post Processing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;If you are starting out with Yambo, or even an experienced user, we recommend that you complete the following tutorials before trying to use Yambo for your system.&lt;br /&gt;
&lt;br /&gt;
The tutorials are meant to give some introductory background to the key concepts behind Yambo. Practical topics such as convergence are also discussed. &lt;br /&gt;
Nonetheless, users are invited to first read and study the [[lectures|background material]] in order to get familiar with the fundamental physical quantities.&lt;br /&gt;
&lt;br /&gt;
Two kinds of tutorials are provided: &#039;&#039;&#039;stand-alone&#039;&#039;&#039; and &#039;&#039;&#039;modular&#039;&#039;&#039;. In addition you must have a working environment where both Yambo (and eventually QE) are installed.&lt;br /&gt;
&lt;br /&gt;
== Setting up Yambo (and eventually QE)  ==&lt;br /&gt;
To be able to follow the school you need a running version of the yambo/QE code.&lt;br /&gt;
&lt;br /&gt;
There are several different ways to prepare a working environment.&lt;br /&gt;
&lt;br /&gt;
=== Virtual Machine(s) ===&lt;br /&gt;
The easiest way is to access to a virtual machine which contains both (i) yambo/QE and (ii) the tutorials.&lt;br /&gt;
&lt;br /&gt;
You can do it in one of two ways:&lt;br /&gt;
* Virtual machine via [[ICTP cloud|ICTP cloud]] If the schools you are attending provided an ICTP virtual machine this is the preferred option. It works through internet connection inside a browser.&lt;br /&gt;
* Install the [[Yambo_Virtual_Machine|yambo virtual machine]] on your laptop / desktop. This requires Oracle virtual box. Pre-download of the Virtual machine. No internet connection needed.&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
URL of the machine : https://ins45100.ictp.it/&lt;br /&gt;
READ-ONLY PASSWORD for TUTOR (ictptutor) access:&lt;br /&gt;
NairibiTutor&lt;br /&gt;
READ-WRITE password for PARTICIPANT&#039;s (ictpuser) access:&lt;br /&gt;
NairobiUser&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== User installation  ===&lt;br /&gt;
You can also setup the yambo code on your on laptop / desktop using different methods.&lt;br /&gt;
&lt;br /&gt;
As far as the Yambo source is concerned you can:&lt;br /&gt;
* Install [[Yambo via Docker|Yambo via Docker]]&lt;br /&gt;
* [[download|Download]] and [[Installation|install]] yambo on your laptop / desktop (requires a linux machine).&lt;br /&gt;
* Install yambo on your laptop/desktop/cluster [https://github.com/nicspalla/my-repo via Spack].&lt;br /&gt;
* Install using  Anaconda.&lt;br /&gt;
&lt;br /&gt;
=== Yambo User Installation with Anaconda ===&lt;br /&gt;
It is possible to install Yambo (up to v5.0.4) and Quantum-ESPRESSO via conda-forge (a conda channel/repository):&lt;br /&gt;
To setup Anaconda, please start from installing [https://www.anaconda.com/products/distribution#Downloads Anaconda] or [https://docs.conda.io/en/latest/miniconda.html Miniconda].&lt;br /&gt;
&lt;br /&gt;
Then we suggest to create a conda environment and activate it:&lt;br /&gt;
 conda create --name yambopy -c conda-forge&lt;br /&gt;
 conda activate yambopy&lt;br /&gt;
Then you can install the prerequisites and the two codes:&lt;br /&gt;
 conda install numpy scipy netcdf4 matplotlib pyyaml lxml pandas&lt;br /&gt;
 conda install yambo &lt;br /&gt;
 conda install qe&lt;br /&gt;
&lt;br /&gt;
==Setting up Yambopy==&lt;br /&gt;
&lt;br /&gt;
===Quick installation===&lt;br /&gt;
&lt;br /&gt;
A quick way to start using Yambopy is described here.&lt;br /&gt;
&lt;br /&gt;
* Make sure that you are using Python 3 and that you have the following python packages: &amp;lt;code&amp;gt;numpy&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;scipy&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;matplotlib&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;netCDF4&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;lxml&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;pyyaml&amp;lt;/code&amp;gt;. Optionally, you may want to have abipy [[https://abinit.github.io/abipy/index.html]] installed for band structure interpolations.&lt;br /&gt;
&lt;br /&gt;
* Go to a directory of your choice and clone yambopy from the git repository&lt;br /&gt;
&lt;br /&gt;
 git clone https://github.com/yambo-code/yambopy.git&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t want to use git, you may download a tarball from the git repository instead.&lt;br /&gt;
&lt;br /&gt;
* Enter into the yambopy folder and install&lt;br /&gt;
&lt;br /&gt;
 cd yambopy&lt;br /&gt;
 sudo python setup.py install&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t have administrative privileges (for example on a computing cluster), type instead&lt;br /&gt;
&lt;br /&gt;
 cd yambopy&lt;br /&gt;
 python setup.py install --user&lt;br /&gt;
&lt;br /&gt;
===Installing dependencies with Anaconda===&lt;br /&gt;
We suggest installing yambopy using Anaconda [[https://www.anaconda.com/products/distribution]] to manage the various python packages.&lt;br /&gt;
&lt;br /&gt;
In this case, you can follow these steps.&lt;br /&gt;
&lt;br /&gt;
First, install the required dependencies:&lt;br /&gt;
 conda install numpy scipy netcdf4 lxml pyyaml&lt;br /&gt;
&lt;br /&gt;
Then we create a conda environment based on python 3.6 (this is to ensure compatibility with abipy if we want to install it later on):&lt;br /&gt;
 conda create --name NAME_ENV python=3.6&lt;br /&gt;
Here choose &amp;lt;code&amp;gt;NAME_ENV&amp;lt;/code&amp;gt; as you want, e.g. &amp;lt;code&amp;gt;yenv&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Now, we install abipy and its dependency pymatgen using &amp;lt;code&amp;gt;pip&amp;lt;/code&amp;gt;. Here make sure that you are using the &amp;lt;code&amp;gt;pip&amp;lt;/code&amp;gt; version provided by Anaconda and not your system version.&lt;br /&gt;
&lt;br /&gt;
 pip install pymatgen&lt;br /&gt;
 pip install abipy&lt;br /&gt;
&lt;br /&gt;
Finally, we are ready to install yambopy:&lt;br /&gt;
&lt;br /&gt;
 git clone https://github.com/yambo-code/yambopy.git &lt;br /&gt;
&lt;br /&gt;
(or download and extract tarball) and follow the steps outlined in the quick installation section.&lt;br /&gt;
&lt;br /&gt;
Now enter into the yambopy folder and install&lt;br /&gt;
&lt;br /&gt;
 cd yambopy&lt;br /&gt;
 sudo python setup.py install&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t have administrative privileges (for example on a computing cluster), type instead&lt;br /&gt;
&lt;br /&gt;
 cd yambopy&lt;br /&gt;
 python setup.py install --user&lt;br /&gt;
&lt;br /&gt;
===Frequent issues===&lt;br /&gt;
When running the installation you may get a &amp;lt;code&amp;gt;SyntaxError&amp;lt;/code&amp;gt; related to utf-8 encoding or it may complain that module &amp;lt;code&amp;gt;setuptools&amp;lt;/code&amp;gt; is not installed even though it is. In this case, it means that the &amp;lt;code&amp;gt;sudo&amp;lt;/code&amp;gt; command is not preserving the correct &amp;lt;code&amp;gt;PATH&amp;lt;/code&amp;gt; for your python executable.&lt;br /&gt;
&lt;br /&gt;
Solve the problem by running the installation step as&lt;br /&gt;
&lt;br /&gt;
 sudo /your/path/to/python setup.py install&lt;br /&gt;
or&lt;br /&gt;
 sudo env PATH=$PATH python setup.py install&lt;br /&gt;
&lt;br /&gt;
This applies only to the installation step and not to subsequent yambopy use.&lt;br /&gt;
&lt;br /&gt;
== Tutorial files ==&lt;br /&gt;
The tutorial CORE databases can be obtained&lt;br /&gt;
&lt;br /&gt;
* from the [[Yambo_Virtual_Machine|Yambo Virtual Machine]] &lt;br /&gt;
* from the Yambo web-page&lt;br /&gt;
* from the Yambo GIT tutorial repository &lt;br /&gt;
&lt;br /&gt;
=== From the Yambo Virtual Machine (VM)  ===&lt;br /&gt;
If you are using the VM, a recent version of the tutorial files is provided.Follow these [[Yambo_Virtual_Machine#Updating_the_Yambo_tutorial_files| instructions]] to update the tutorial files to the most recent version.&lt;br /&gt;
&lt;br /&gt;
=== From the Yambo website ===&lt;br /&gt;
If you are using your own installation or the docker, the files needed to run the tutorials can be downloaded from the lists below. &lt;br /&gt;
&lt;br /&gt;
After downloading the tar.gz files just unpack them in &#039;&#039;&#039;the YAMBO_TUTORIALS&#039;&#039;&#039; folder. For example&lt;br /&gt;
 $ mkdir YAMBO_TUTORIALS&lt;br /&gt;
 $ mv hBN.tar.gz YAMBO_TUTORIALS&lt;br /&gt;
 $ cd YAMBO_TUTORIALS&lt;br /&gt;
 $ tar -xvfz hBN.tar.gz&lt;br /&gt;
 $ ls YAMBO_TUTORIALS&lt;br /&gt;
   hBN&lt;br /&gt;
&lt;br /&gt;
====Files needed for modular tutorials====&lt;br /&gt;
All of the following should be downloaded prior to following the modular tutorials:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Tutorial !! File(s)&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;4&amp;quot;| hBN || [https://media.yambo-code.eu/educational/tutorials/files/hBN.tar.gz hBN.tar.gz] &lt;br /&gt;
|-&lt;br /&gt;
| [https://media.yambo-code.eu/educational/tutorials/files/hBN-convergence-kpoints.tar.gz hBN-convergence-kpoints.tar.gz]&lt;br /&gt;
|-&lt;br /&gt;
| [https://media.yambo-code.eu/educational/tutorials/files/hBN-2D.tar.gz hBN-2D.tar.gz] &lt;br /&gt;
|-&lt;br /&gt;
| [https://media.yambo-code.eu/educational/tutorials/files/hBN-2D-para.tar.gz hBN-2D-para.tar.gz]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
====Files needed for stand-alone tutorials====&lt;br /&gt;
At the start of each tutorial you will be told which specific file needs to be downloaded:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Tutorial !! File(s)&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot;| Silicon || [https://media.yambo-code.eu/educational/tutorials/files/Silicon.tar.gz Silicon.tar.gz]&lt;br /&gt;
|-&lt;br /&gt;
|[https://media.yambo-code.eu/educational/tutorials/files/Silicon_Electron-Phonon.tar.gz Silicon_Electron-Phonon.tar.gz]&lt;br /&gt;
|-&lt;br /&gt;
| LiF || [https://media.yambo-code.eu/educational/tutorials/files/LiF.tar.gz LiF.tar.gz]&lt;br /&gt;
|-&lt;br /&gt;
| Aluminum || [https://media.yambo-code.eu/educational/tutorials/files/Aluminum.tar.gz Aluminum.tar.gz]&lt;br /&gt;
|-&lt;br /&gt;
| GaSb || [https://media.yambo-code.eu/educational/tutorials/files/GaSb.tar.gz GaSb.tar.gz]&lt;br /&gt;
|-&lt;br /&gt;
| AlAs || [https://media.yambo-code.eu/educational/tutorials/files/AlAs.tar.gz AlAs.tar.gz]&lt;br /&gt;
|-&lt;br /&gt;
| Hydrogen_Chain || [https://media.yambo-code.eu/educational/tutorials/files/Hydrogen_Chain.tar.gz Hydrogen_Chain.tar.gz]&lt;br /&gt;
|-&lt;br /&gt;
| MoS2 for HPC || [https://media.yambo-code.eu/educational/tutorials/files/MoS2_HPC_tutorial.tar.gz MoS2_HPC_tutorial.tar.gz]&lt;br /&gt;
|-&lt;br /&gt;
| MoS2 for HPC shorter version || [https://media.yambo-code.eu/educational/tutorials/files/MoS2_2Dquasiparticle_tutorial.tar.gz MoS2_2Dquasiparticle_tutorial.tar.gz]&lt;br /&gt;
|-&lt;br /&gt;
| Yambopy for QE || [https://media.yambo-code.eu/educational/tutorials/files/databases_qepy.tar databases_qepy]&lt;br /&gt;
|-&lt;br /&gt;
| Yambopy for YAMBO || [https://media.yambo-code.eu/educational/tutorials/files/databases_yambopy.tar databases_yambopy]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== From the Git Tutorial Repository (advanced users) ===&lt;br /&gt;
If you are using your own installation or the docker, the [https://github.com/yambo-code/tutorials tutorials repository] contains the updated tutorials CORE databases. To use it&lt;br /&gt;
 $ git clone https://github.com/yambo-code/tutorials.git YAMBO_TUTORIALS&lt;br /&gt;
 $ cd YAMBO_TUTORIALS&lt;br /&gt;
 $ ./setup.pl -install&lt;br /&gt;
&lt;br /&gt;
== Stand-alone tutorials ==&lt;br /&gt;
These tutorials are self-contained and cover a variety of mixed topics, both physical and methodological. They are designed to be followed from start to finish in one page and do not require previous knowledge of yambo. 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;
* [[LiF|Linear Response in 3D. Excitons at work]]&lt;br /&gt;
* [[Silicon|GW convergence]]&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
* [[Si_Surface|Linear Response in 2D]]&lt;br /&gt;
* [[Si_wire|Linear Response in 1D]]&lt;br /&gt;
* [[H2|Linear Response in 0D]]&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
=== Post Processing ===&lt;br /&gt;
* [[Yambo Post Processing (ypp)]]&lt;br /&gt;
* [[First steps in Yambopy]]&lt;br /&gt;
* [[Yambopy tutorial: band structures]]&lt;br /&gt;
* [[Yambopy tutorial: Yambo databases]]&lt;br /&gt;
* [[GW tutorial. Convergence and approximations (BN)]] [yambopy tutorial]&lt;br /&gt;
* [[Bethe-Salpeter equation tutorial. Optical absorption (BN)]] [yambopy tutorial]&lt;br /&gt;
&lt;br /&gt;
=== Advanced ===&lt;br /&gt;
* [[Hydrogen chain|TDDFT Failure and long range correlations]]&lt;br /&gt;
* [[Linear response from real time simulations]]&lt;br /&gt;
&lt;br /&gt;
==== 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 tutorial on HPC]]&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;
==== Non linear response ====&lt;br /&gt;
* [http://www.attaccalite.com/lumen/linear_response.html Linear response using Dynamical Berry phase]&lt;br /&gt;
* [[Real time approach to non-linear response]]&lt;br /&gt;
* [[Correlation effects in the non-linear response]]&lt;br /&gt;
* [http://www.attaccalite.com/lumen/thg_in_silicon.html Third Harmonic Generation]&lt;br /&gt;
* [http://www.attaccalite.com/lumen/spin_orbit.html Spin-orbit coupling and non-linear response]&lt;br /&gt;
* [[Two-photon absorption]] &lt;br /&gt;
* [[Pump and Probe]]&lt;br /&gt;
* [[Parallelization for non-linear response calculations]]&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;
* [[Kerr|Kerr]]&lt;br /&gt;
* [[Real_Time|Real-Time]]&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;br /&gt;
&lt;br /&gt;
== Modular tutorials ==&lt;br /&gt;
These tutorials are designed to provide a deeper understanding of specific yambo tasks and runlevels. They are designed to avoid repetition of common procedures and physical concepts. As such, they make use of the same physical systems: bulk hexagonal boron nitride &#039;&#039;hBN&#039;&#039; and a hBN sheet &#039;&#039;hBN-2D&#039;&#039;.&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;
====Introduction====&lt;br /&gt;
* [[First steps: a walk through from DFT to optical properties]]&lt;br /&gt;
====Quasiparticles in the GW approximation====&lt;br /&gt;
* [[How to obtain the quasi-particle band structure of a bulk material: h-BN]]&lt;br /&gt;
====Using Yambo in Parallel====&lt;br /&gt;
This modules contains very general discussions of the parallel environment of Yambo. Still the actual run of the code is specific to the CECAM cluster. If you want to run these modules just replace the parallel queue instructions with simple MPI commands.&lt;br /&gt;
&lt;br /&gt;
* [[GW_parallel_strategies|Parallel GW (CECAM specific)]]: strategies for running Yambo in parallel&lt;br /&gt;
[[GW_parallel_strategies_CECAM]]&lt;br /&gt;
* [[Pushing_convergence_in_parallel|GW convergence (CECAM specific)]]: use Yambo in parallel to converge a GW calculation for a layer of hBN (hBN-2D)&lt;br /&gt;
&lt;br /&gt;
====Excitons and the Bethe-Salpeter Equation====&lt;br /&gt;
* [[How to obtain an optical spectrum|Calculating optical spectra including excitonic effects: a step-by-step guide]]&lt;br /&gt;
* [[How to choose the input parameters|Obtaining a converged optical spectrum]] &lt;br /&gt;
* [[How to treat low dimensional systems|Many-body effects in low-dimensional systems: numerical issues and remedies]] &lt;br /&gt;
* [[How to analyse excitons|Analysis of excitonic spectra in a 2D material]]&lt;br /&gt;
&amp;lt;!--* [[Two particle excitations]] (try to bypass this page) : Learn how to set up and run calculations to obtain and analyze an optical absorption spectrum of bulk and low dimension materials by using the Bethe-Salpeter equation--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Yambopy====&lt;br /&gt;
* [[First steps in Yambopy]]&lt;br /&gt;
* [[GW tutorial. Convergence and approximations (BN)]]&lt;br /&gt;
* [[Bethe-Salpeter equation tutorial. Optical absorption (BN)]]&lt;br /&gt;
* [[Yambopy tutorial: band structures | Database and plotting tutorial for quantum espresso: qepy]]&lt;br /&gt;
* [[Yambopy tutorial: Yambo databases | Database and plotting tutorial for yambo: yambopy ]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
====Real-time simulations====&lt;br /&gt;
* [[Breaking of symmetries]]&lt;br /&gt;
* [[Independent-Particle Approximation Dynamics. Delta Pulse]]&lt;br /&gt;
* [[Post-processing. Optical Response]]&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
=== Modules ===&lt;br /&gt;
Alternatively, users can learn more about a specific runlevel or task by looking at the individual &#039;&#039;&#039;[[Modules|documentation modules]]&#039;&#039;&#039;. These provide a focus on the input parameters, run time behaviour, and underlying physics. Although they can be followed separately, non-experts are urged to follow them as part of the more structured tutorials given above.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
== &amp;lt;span id=&amp;quot;Schools&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;Schools ==&lt;br /&gt;
* [[ICTP2020]]&lt;br /&gt;
* [[CECAM VIRTUAL 2021]]&lt;br /&gt;
* [https://www.yambo-code.org/wiki/index.php?title=ICTP_2022 ICTP2022]&lt;br /&gt;
--&amp;gt;&lt;/div&gt;</summary>
		<author><name>Fulvio</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Tutorials&amp;diff=7056</id>
		<title>Tutorials</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Tutorials&amp;diff=7056"/>
		<updated>2023-06-15T14:34:02Z</updated>

		<summary type="html">&lt;p&gt;Fulvio: /* Post Processing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;If you are starting out with Yambo, or even an experienced user, we recommend that you complete the following tutorials before trying to use Yambo for your system.&lt;br /&gt;
&lt;br /&gt;
The tutorials are meant to give some introductory background to the key concepts behind Yambo. Practical topics such as convergence are also discussed. &lt;br /&gt;
Nonetheless, users are invited to first read and study the [[lectures|background material]] in order to get familiar with the fundamental physical quantities.&lt;br /&gt;
&lt;br /&gt;
Two kinds of tutorials are provided: &#039;&#039;&#039;stand-alone&#039;&#039;&#039; and &#039;&#039;&#039;modular&#039;&#039;&#039;. In addition you must have a working environment where both Yambo (and eventually QE) are installed.&lt;br /&gt;
&lt;br /&gt;
== Setting up Yambo (and eventually QE)  ==&lt;br /&gt;
To be able to follow the school you need a running version of the yambo/QE code.&lt;br /&gt;
&lt;br /&gt;
There are several different ways to prepare a working environment.&lt;br /&gt;
&lt;br /&gt;
=== Virtual Machine(s) ===&lt;br /&gt;
The easiest way is to access to a virtual machine which contains both (i) yambo/QE and (ii) the tutorials.&lt;br /&gt;
&lt;br /&gt;
You can do it in one of two ways:&lt;br /&gt;
* Virtual machine via [[ICTP cloud|ICTP cloud]] If the schools you are attending provided an ICTP virtual machine this is the preferred option. It works through internet connection inside a browser.&lt;br /&gt;
* Install the [[Yambo_Virtual_Machine|yambo virtual machine]] on your laptop / desktop. This requires Oracle virtual box. Pre-download of the Virtual machine. No internet connection needed.&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
URL of the machine : https://ins45100.ictp.it/&lt;br /&gt;
READ-ONLY PASSWORD for TUTOR (ictptutor) access:&lt;br /&gt;
NairibiTutor&lt;br /&gt;
READ-WRITE password for PARTICIPANT&#039;s (ictpuser) access:&lt;br /&gt;
NairobiUser&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== User installation  ===&lt;br /&gt;
You can also setup the yambo code on your on laptop / desktop using different methods.&lt;br /&gt;
&lt;br /&gt;
As far as the Yambo source is concerned you can:&lt;br /&gt;
* Install [[Yambo via Docker|Yambo via Docker]]&lt;br /&gt;
* [[download|Download]] and [[Installation|install]] yambo on your laptop / desktop (requires a linux machine).&lt;br /&gt;
* Install yambo on your laptop/desktop/cluster [https://github.com/nicspalla/my-repo via Spack].&lt;br /&gt;
* Install using  Anaconda.&lt;br /&gt;
&lt;br /&gt;
=== Yambo User Installation with Anaconda ===&lt;br /&gt;
It is possible to install Yambo (up to v5.0.4) and Quantum-ESPRESSO via conda-forge (a conda channel/repository):&lt;br /&gt;
To setup Anaconda, please start from installing [https://www.anaconda.com/products/distribution#Downloads Anaconda] or [https://docs.conda.io/en/latest/miniconda.html Miniconda].&lt;br /&gt;
&lt;br /&gt;
Then we suggest to create a conda environment and activate it:&lt;br /&gt;
 conda create --name yambopy -c conda-forge&lt;br /&gt;
 conda activate yambopy&lt;br /&gt;
Then you can install the prerequisites and the two codes:&lt;br /&gt;
 conda install numpy scipy netcdf4 matplotlib pyyaml lxml pandas&lt;br /&gt;
 conda install yambo &lt;br /&gt;
 conda install qe&lt;br /&gt;
&lt;br /&gt;
==Setting up Yambopy==&lt;br /&gt;
&lt;br /&gt;
===Quick installation===&lt;br /&gt;
&lt;br /&gt;
A quick way to start using Yambopy is described here.&lt;br /&gt;
&lt;br /&gt;
* Make sure that you are using Python 3 and that you have the following python packages: &amp;lt;code&amp;gt;numpy&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;scipy&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;matplotlib&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;netCDF4&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;lxml&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;pyyaml&amp;lt;/code&amp;gt;. Optionally, you may want to have abipy [[https://abinit.github.io/abipy/index.html]] installed for band structure interpolations.&lt;br /&gt;
&lt;br /&gt;
* Go to a directory of your choice and clone yambopy from the git repository&lt;br /&gt;
&lt;br /&gt;
 git clone https://github.com/yambo-code/yambopy.git&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t want to use git, you may download a tarball from the git repository instead.&lt;br /&gt;
&lt;br /&gt;
* Enter into the yambopy folder and install&lt;br /&gt;
&lt;br /&gt;
 cd yambopy&lt;br /&gt;
 sudo python setup.py install&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t have administrative privileges (for example on a computing cluster), type instead&lt;br /&gt;
&lt;br /&gt;
 cd yambopy&lt;br /&gt;
 python setup.py install --user&lt;br /&gt;
&lt;br /&gt;
===Installing dependencies with Anaconda===&lt;br /&gt;
We suggest installing yambopy using Anaconda [[https://www.anaconda.com/products/distribution]] to manage the various python packages.&lt;br /&gt;
&lt;br /&gt;
In this case, you can follow these steps.&lt;br /&gt;
&lt;br /&gt;
First, install the required dependencies:&lt;br /&gt;
 conda install numpy scipy netcdf4 lxml pyyaml&lt;br /&gt;
&lt;br /&gt;
Then we create a conda environment based on python 3.6 (this is to ensure compatibility with abipy if we want to install it later on):&lt;br /&gt;
 conda create --name NAME_ENV python=3.6&lt;br /&gt;
Here choose &amp;lt;code&amp;gt;NAME_ENV&amp;lt;/code&amp;gt; as you want, e.g. &amp;lt;code&amp;gt;yenv&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Now, we install abipy and its dependency pymatgen using &amp;lt;code&amp;gt;pip&amp;lt;/code&amp;gt;. Here make sure that you are using the &amp;lt;code&amp;gt;pip&amp;lt;/code&amp;gt; version provided by Anaconda and not your system version.&lt;br /&gt;
&lt;br /&gt;
 pip install pymatgen&lt;br /&gt;
 pip install abipy&lt;br /&gt;
&lt;br /&gt;
Finally, we are ready to install yambopy:&lt;br /&gt;
&lt;br /&gt;
 git clone https://github.com/yambo-code/yambopy.git &lt;br /&gt;
&lt;br /&gt;
(or download and extract tarball) and follow the steps outlined in the quick installation section.&lt;br /&gt;
&lt;br /&gt;
Now enter into the yambopy folder and install&lt;br /&gt;
&lt;br /&gt;
 cd yambopy&lt;br /&gt;
 sudo python setup.py install&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t have administrative privileges (for example on a computing cluster), type instead&lt;br /&gt;
&lt;br /&gt;
 cd yambopy&lt;br /&gt;
 python setup.py install --user&lt;br /&gt;
&lt;br /&gt;
===Frequent issues===&lt;br /&gt;
When running the installation you may get a &amp;lt;code&amp;gt;SyntaxError&amp;lt;/code&amp;gt; related to utf-8 encoding or it may complain that module &amp;lt;code&amp;gt;setuptools&amp;lt;/code&amp;gt; is not installed even though it is. In this case, it means that the &amp;lt;code&amp;gt;sudo&amp;lt;/code&amp;gt; command is not preserving the correct &amp;lt;code&amp;gt;PATH&amp;lt;/code&amp;gt; for your python executable.&lt;br /&gt;
&lt;br /&gt;
Solve the problem by running the installation step as&lt;br /&gt;
&lt;br /&gt;
 sudo /your/path/to/python setup.py install&lt;br /&gt;
or&lt;br /&gt;
 sudo env PATH=$PATH python setup.py install&lt;br /&gt;
&lt;br /&gt;
This applies only to the installation step and not to subsequent yambopy use.&lt;br /&gt;
&lt;br /&gt;
== Tutorial files ==&lt;br /&gt;
The tutorial CORE databases can be obtained&lt;br /&gt;
&lt;br /&gt;
* from the [[Yambo_Virtual_Machine|Yambo Virtual Machine]] &lt;br /&gt;
* from the Yambo web-page&lt;br /&gt;
* from the Yambo GIT tutorial repository &lt;br /&gt;
&lt;br /&gt;
=== From the Yambo Virtual Machine (VM)  ===&lt;br /&gt;
If you are using the VM, a recent version of the tutorial files is provided.Follow these [[Yambo_Virtual_Machine#Updating_the_Yambo_tutorial_files| instructions]] to update the tutorial files to the most recent version.&lt;br /&gt;
&lt;br /&gt;
=== From the Yambo website ===&lt;br /&gt;
If you are using your own installation or the docker, the files needed to run the tutorials can be downloaded from the lists below. &lt;br /&gt;
&lt;br /&gt;
After downloading the tar.gz files just unpack them in &#039;&#039;&#039;the YAMBO_TUTORIALS&#039;&#039;&#039; folder. For example&lt;br /&gt;
 $ mkdir YAMBO_TUTORIALS&lt;br /&gt;
 $ mv hBN.tar.gz YAMBO_TUTORIALS&lt;br /&gt;
 $ cd YAMBO_TUTORIALS&lt;br /&gt;
 $ tar -xvfz hBN.tar.gz&lt;br /&gt;
 $ ls YAMBO_TUTORIALS&lt;br /&gt;
   hBN&lt;br /&gt;
&lt;br /&gt;
====Files needed for modular tutorials====&lt;br /&gt;
All of the following should be downloaded prior to following the modular tutorials:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Tutorial !! File(s)&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;4&amp;quot;| hBN || [https://media.yambo-code.eu/educational/tutorials/files/hBN.tar.gz hBN.tar.gz] &lt;br /&gt;
|-&lt;br /&gt;
| [https://media.yambo-code.eu/educational/tutorials/files/hBN-convergence-kpoints.tar.gz hBN-convergence-kpoints.tar.gz]&lt;br /&gt;
|-&lt;br /&gt;
| [https://media.yambo-code.eu/educational/tutorials/files/hBN-2D.tar.gz hBN-2D.tar.gz] &lt;br /&gt;
|-&lt;br /&gt;
| [https://media.yambo-code.eu/educational/tutorials/files/hBN-2D-para.tar.gz hBN-2D-para.tar.gz]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
====Files needed for stand-alone tutorials====&lt;br /&gt;
At the start of each tutorial you will be told which specific file needs to be downloaded:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Tutorial !! File(s)&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot;| Silicon || [https://media.yambo-code.eu/educational/tutorials/files/Silicon.tar.gz Silicon.tar.gz]&lt;br /&gt;
|-&lt;br /&gt;
|[https://media.yambo-code.eu/educational/tutorials/files/Silicon_Electron-Phonon.tar.gz Silicon_Electron-Phonon.tar.gz]&lt;br /&gt;
|-&lt;br /&gt;
| LiF || [https://media.yambo-code.eu/educational/tutorials/files/LiF.tar.gz LiF.tar.gz]&lt;br /&gt;
|-&lt;br /&gt;
| Aluminum || [https://media.yambo-code.eu/educational/tutorials/files/Aluminum.tar.gz Aluminum.tar.gz]&lt;br /&gt;
|-&lt;br /&gt;
| GaSb || [https://media.yambo-code.eu/educational/tutorials/files/GaSb.tar.gz GaSb.tar.gz]&lt;br /&gt;
|-&lt;br /&gt;
| AlAs || [https://media.yambo-code.eu/educational/tutorials/files/AlAs.tar.gz AlAs.tar.gz]&lt;br /&gt;
|-&lt;br /&gt;
| Hydrogen_Chain || [https://media.yambo-code.eu/educational/tutorials/files/Hydrogen_Chain.tar.gz Hydrogen_Chain.tar.gz]&lt;br /&gt;
|-&lt;br /&gt;
| MoS2 for HPC || [https://media.yambo-code.eu/educational/tutorials/files/MoS2_HPC_tutorial.tar.gz MoS2_HPC_tutorial.tar.gz]&lt;br /&gt;
|-&lt;br /&gt;
| MoS2 for HPC shorter version || [https://media.yambo-code.eu/educational/tutorials/files/MoS2_2Dquasiparticle_tutorial.tar.gz MoS2_2Dquasiparticle_tutorial.tar.gz]&lt;br /&gt;
|-&lt;br /&gt;
| Yambopy for QE || [https://media.yambo-code.eu/educational/tutorials/files/databases_qepy.tar databases_qepy]&lt;br /&gt;
|-&lt;br /&gt;
| Yambopy for YAMBO || [https://media.yambo-code.eu/educational/tutorials/files/databases_yambopy.tar databases_yambopy]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== From the Git Tutorial Repository (advanced users) ===&lt;br /&gt;
If you are using your own installation or the docker, the [https://github.com/yambo-code/tutorials tutorials repository] contains the updated tutorials CORE databases. To use it&lt;br /&gt;
 $ git clone https://github.com/yambo-code/tutorials.git YAMBO_TUTORIALS&lt;br /&gt;
 $ cd YAMBO_TUTORIALS&lt;br /&gt;
 $ ./setup.pl -install&lt;br /&gt;
&lt;br /&gt;
== Stand-alone tutorials ==&lt;br /&gt;
These tutorials are self-contained and cover a variety of mixed topics, both physical and methodological. They are designed to be followed from start to finish in one page and do not require previous knowledge of yambo. 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;
* [[LiF|Linear Response in 3D. Excitons at work]]&lt;br /&gt;
* [[Silicon|GW convergence]]&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
* [[Si_Surface|Linear Response in 2D]]&lt;br /&gt;
* [[Si_wire|Linear Response in 1D]]&lt;br /&gt;
* [[H2|Linear Response in 0D]]&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
=== Post Processing ===&lt;br /&gt;
* [[Yambo Post Processing (ypp)]]&lt;br /&gt;
* [[First steps in Yambopy]]&lt;br /&gt;
* [[Yambopy tutorial: band structures]]&lt;br /&gt;
* [[Yambopy tutorial: Yambo databases]]&lt;br /&gt;
* [[GW tutorial. Convergence and approximations (BN)]] (yambopy tutorial)&lt;br /&gt;
* [[Bethe-Salpeter equation tutorial. Optical absorption (BN)]] (yambopy tutorial)&lt;br /&gt;
&lt;br /&gt;
=== Advanced ===&lt;br /&gt;
* [[Hydrogen chain|TDDFT Failure and long range correlations]]&lt;br /&gt;
* [[Linear response from real time simulations]]&lt;br /&gt;
&lt;br /&gt;
==== 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 tutorial on HPC]]&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;
==== Non linear response ====&lt;br /&gt;
* [http://www.attaccalite.com/lumen/linear_response.html Linear response using Dynamical Berry phase]&lt;br /&gt;
* [[Real time approach to non-linear response]]&lt;br /&gt;
* [[Correlation effects in the non-linear response]]&lt;br /&gt;
* [http://www.attaccalite.com/lumen/thg_in_silicon.html Third Harmonic Generation]&lt;br /&gt;
* [http://www.attaccalite.com/lumen/spin_orbit.html Spin-orbit coupling and non-linear response]&lt;br /&gt;
* [[Two-photon absorption]] &lt;br /&gt;
* [[Pump and Probe]]&lt;br /&gt;
* [[Parallelization for non-linear response calculations]]&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;
* [[Kerr|Kerr]]&lt;br /&gt;
* [[Real_Time|Real-Time]]&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;br /&gt;
&lt;br /&gt;
== Modular tutorials ==&lt;br /&gt;
These tutorials are designed to provide a deeper understanding of specific yambo tasks and runlevels. They are designed to avoid repetition of common procedures and physical concepts. As such, they make use of the same physical systems: bulk hexagonal boron nitride &#039;&#039;hBN&#039;&#039; and a hBN sheet &#039;&#039;hBN-2D&#039;&#039;.&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;
====Introduction====&lt;br /&gt;
* [[First steps: a walk through from DFT to optical properties]]&lt;br /&gt;
====Quasiparticles in the GW approximation====&lt;br /&gt;
* [[How to obtain the quasi-particle band structure of a bulk material: h-BN]]&lt;br /&gt;
====Using Yambo in Parallel====&lt;br /&gt;
This modules contains very general discussions of the parallel environment of Yambo. Still the actual run of the code is specific to the CECAM cluster. If you want to run these modules just replace the parallel queue instructions with simple MPI commands.&lt;br /&gt;
&lt;br /&gt;
* [[GW_parallel_strategies|Parallel GW (CECAM specific)]]: strategies for running Yambo in parallel&lt;br /&gt;
[[GW_parallel_strategies_CECAM]]&lt;br /&gt;
* [[Pushing_convergence_in_parallel|GW convergence (CECAM specific)]]: use Yambo in parallel to converge a GW calculation for a layer of hBN (hBN-2D)&lt;br /&gt;
&lt;br /&gt;
====Excitons and the Bethe-Salpeter Equation====&lt;br /&gt;
* [[How to obtain an optical spectrum|Calculating optical spectra including excitonic effects: a step-by-step guide]]&lt;br /&gt;
* [[How to choose the input parameters|Obtaining a converged optical spectrum]] &lt;br /&gt;
* [[How to treat low dimensional systems|Many-body effects in low-dimensional systems: numerical issues and remedies]] &lt;br /&gt;
* [[How to analyse excitons|Analysis of excitonic spectra in a 2D material]]&lt;br /&gt;
&amp;lt;!--* [[Two particle excitations]] (try to bypass this page) : Learn how to set up and run calculations to obtain and analyze an optical absorption spectrum of bulk and low dimension materials by using the Bethe-Salpeter equation--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Yambopy====&lt;br /&gt;
* [[First steps in Yambopy]]&lt;br /&gt;
* [[GW tutorial. Convergence and approximations (BN)]]&lt;br /&gt;
* [[Bethe-Salpeter equation tutorial. Optical absorption (BN)]]&lt;br /&gt;
* [[Yambopy tutorial: band structures | Database and plotting tutorial for quantum espresso: qepy]]&lt;br /&gt;
* [[Yambopy tutorial: Yambo databases | Database and plotting tutorial for yambo: yambopy ]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
====Real-time simulations====&lt;br /&gt;
* [[Breaking of symmetries]]&lt;br /&gt;
* [[Independent-Particle Approximation Dynamics. Delta Pulse]]&lt;br /&gt;
* [[Post-processing. Optical Response]]&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
=== Modules ===&lt;br /&gt;
Alternatively, users can learn more about a specific runlevel or task by looking at the individual &#039;&#039;&#039;[[Modules|documentation modules]]&#039;&#039;&#039;. These provide a focus on the input parameters, run time behaviour, and underlying physics. Although they can be followed separately, non-experts are urged to follow them as part of the more structured tutorials given above.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
== &amp;lt;span id=&amp;quot;Schools&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;Schools ==&lt;br /&gt;
* [[ICTP2020]]&lt;br /&gt;
* [[CECAM VIRTUAL 2021]]&lt;br /&gt;
* [https://www.yambo-code.org/wiki/index.php?title=ICTP_2022 ICTP2022]&lt;br /&gt;
--&amp;gt;&lt;/div&gt;</summary>
		<author><name>Fulvio</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Tutorials&amp;diff=7055</id>
		<title>Tutorials</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Tutorials&amp;diff=7055"/>
		<updated>2023-06-15T14:32:55Z</updated>

		<summary type="html">&lt;p&gt;Fulvio: /* Post Processing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;If you are starting out with Yambo, or even an experienced user, we recommend that you complete the following tutorials before trying to use Yambo for your system.&lt;br /&gt;
&lt;br /&gt;
The tutorials are meant to give some introductory background to the key concepts behind Yambo. Practical topics such as convergence are also discussed. &lt;br /&gt;
Nonetheless, users are invited to first read and study the [[lectures|background material]] in order to get familiar with the fundamental physical quantities.&lt;br /&gt;
&lt;br /&gt;
Two kinds of tutorials are provided: &#039;&#039;&#039;stand-alone&#039;&#039;&#039; and &#039;&#039;&#039;modular&#039;&#039;&#039;. In addition you must have a working environment where both Yambo (and eventually QE) are installed.&lt;br /&gt;
&lt;br /&gt;
== Setting up Yambo (and eventually QE)  ==&lt;br /&gt;
To be able to follow the school you need a running version of the yambo/QE code.&lt;br /&gt;
&lt;br /&gt;
There are several different ways to prepare a working environment.&lt;br /&gt;
&lt;br /&gt;
=== Virtual Machine(s) ===&lt;br /&gt;
The easiest way is to access to a virtual machine which contains both (i) yambo/QE and (ii) the tutorials.&lt;br /&gt;
&lt;br /&gt;
You can do it in one of two ways:&lt;br /&gt;
* Virtual machine via [[ICTP cloud|ICTP cloud]] If the schools you are attending provided an ICTP virtual machine this is the preferred option. It works through internet connection inside a browser.&lt;br /&gt;
* Install the [[Yambo_Virtual_Machine|yambo virtual machine]] on your laptop / desktop. This requires Oracle virtual box. Pre-download of the Virtual machine. No internet connection needed.&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
URL of the machine : https://ins45100.ictp.it/&lt;br /&gt;
READ-ONLY PASSWORD for TUTOR (ictptutor) access:&lt;br /&gt;
NairibiTutor&lt;br /&gt;
READ-WRITE password for PARTICIPANT&#039;s (ictpuser) access:&lt;br /&gt;
NairobiUser&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== User installation  ===&lt;br /&gt;
You can also setup the yambo code on your on laptop / desktop using different methods.&lt;br /&gt;
&lt;br /&gt;
As far as the Yambo source is concerned you can:&lt;br /&gt;
* Install [[Yambo via Docker|Yambo via Docker]]&lt;br /&gt;
* [[download|Download]] and [[Installation|install]] yambo on your laptop / desktop (requires a linux machine).&lt;br /&gt;
* Install yambo on your laptop/desktop/cluster [https://github.com/nicspalla/my-repo via Spack].&lt;br /&gt;
* Install using  Anaconda.&lt;br /&gt;
&lt;br /&gt;
=== Yambo User Installation with Anaconda ===&lt;br /&gt;
It is possible to install Yambo (up to v5.0.4) and Quantum-ESPRESSO via conda-forge (a conda channel/repository):&lt;br /&gt;
To setup Anaconda, please start from installing [https://www.anaconda.com/products/distribution#Downloads Anaconda] or [https://docs.conda.io/en/latest/miniconda.html Miniconda].&lt;br /&gt;
&lt;br /&gt;
Then we suggest to create a conda environment and activate it:&lt;br /&gt;
 conda create --name yambopy -c conda-forge&lt;br /&gt;
 conda activate yambopy&lt;br /&gt;
Then you can install the prerequisites and the two codes:&lt;br /&gt;
 conda install numpy scipy netcdf4 matplotlib pyyaml lxml pandas&lt;br /&gt;
 conda install yambo &lt;br /&gt;
 conda install qe&lt;br /&gt;
&lt;br /&gt;
==Setting up Yambopy==&lt;br /&gt;
&lt;br /&gt;
===Quick installation===&lt;br /&gt;
&lt;br /&gt;
A quick way to start using Yambopy is described here.&lt;br /&gt;
&lt;br /&gt;
* Make sure that you are using Python 3 and that you have the following python packages: &amp;lt;code&amp;gt;numpy&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;scipy&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;matplotlib&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;netCDF4&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;lxml&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;pyyaml&amp;lt;/code&amp;gt;. Optionally, you may want to have abipy [[https://abinit.github.io/abipy/index.html]] installed for band structure interpolations.&lt;br /&gt;
&lt;br /&gt;
* Go to a directory of your choice and clone yambopy from the git repository&lt;br /&gt;
&lt;br /&gt;
 git clone https://github.com/yambo-code/yambopy.git&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t want to use git, you may download a tarball from the git repository instead.&lt;br /&gt;
&lt;br /&gt;
* Enter into the yambopy folder and install&lt;br /&gt;
&lt;br /&gt;
 cd yambopy&lt;br /&gt;
 sudo python setup.py install&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t have administrative privileges (for example on a computing cluster), type instead&lt;br /&gt;
&lt;br /&gt;
 cd yambopy&lt;br /&gt;
 python setup.py install --user&lt;br /&gt;
&lt;br /&gt;
===Installing dependencies with Anaconda===&lt;br /&gt;
We suggest installing yambopy using Anaconda [[https://www.anaconda.com/products/distribution]] to manage the various python packages.&lt;br /&gt;
&lt;br /&gt;
In this case, you can follow these steps.&lt;br /&gt;
&lt;br /&gt;
First, install the required dependencies:&lt;br /&gt;
 conda install numpy scipy netcdf4 lxml pyyaml&lt;br /&gt;
&lt;br /&gt;
Then we create a conda environment based on python 3.6 (this is to ensure compatibility with abipy if we want to install it later on):&lt;br /&gt;
 conda create --name NAME_ENV python=3.6&lt;br /&gt;
Here choose &amp;lt;code&amp;gt;NAME_ENV&amp;lt;/code&amp;gt; as you want, e.g. &amp;lt;code&amp;gt;yenv&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Now, we install abipy and its dependency pymatgen using &amp;lt;code&amp;gt;pip&amp;lt;/code&amp;gt;. Here make sure that you are using the &amp;lt;code&amp;gt;pip&amp;lt;/code&amp;gt; version provided by Anaconda and not your system version.&lt;br /&gt;
&lt;br /&gt;
 pip install pymatgen&lt;br /&gt;
 pip install abipy&lt;br /&gt;
&lt;br /&gt;
Finally, we are ready to install yambopy:&lt;br /&gt;
&lt;br /&gt;
 git clone https://github.com/yambo-code/yambopy.git &lt;br /&gt;
&lt;br /&gt;
(or download and extract tarball) and follow the steps outlined in the quick installation section.&lt;br /&gt;
&lt;br /&gt;
Now enter into the yambopy folder and install&lt;br /&gt;
&lt;br /&gt;
 cd yambopy&lt;br /&gt;
 sudo python setup.py install&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t have administrative privileges (for example on a computing cluster), type instead&lt;br /&gt;
&lt;br /&gt;
 cd yambopy&lt;br /&gt;
 python setup.py install --user&lt;br /&gt;
&lt;br /&gt;
===Frequent issues===&lt;br /&gt;
When running the installation you may get a &amp;lt;code&amp;gt;SyntaxError&amp;lt;/code&amp;gt; related to utf-8 encoding or it may complain that module &amp;lt;code&amp;gt;setuptools&amp;lt;/code&amp;gt; is not installed even though it is. In this case, it means that the &amp;lt;code&amp;gt;sudo&amp;lt;/code&amp;gt; command is not preserving the correct &amp;lt;code&amp;gt;PATH&amp;lt;/code&amp;gt; for your python executable.&lt;br /&gt;
&lt;br /&gt;
Solve the problem by running the installation step as&lt;br /&gt;
&lt;br /&gt;
 sudo /your/path/to/python setup.py install&lt;br /&gt;
or&lt;br /&gt;
 sudo env PATH=$PATH python setup.py install&lt;br /&gt;
&lt;br /&gt;
This applies only to the installation step and not to subsequent yambopy use.&lt;br /&gt;
&lt;br /&gt;
== Tutorial files ==&lt;br /&gt;
The tutorial CORE databases can be obtained&lt;br /&gt;
&lt;br /&gt;
* from the [[Yambo_Virtual_Machine|Yambo Virtual Machine]] &lt;br /&gt;
* from the Yambo web-page&lt;br /&gt;
* from the Yambo GIT tutorial repository &lt;br /&gt;
&lt;br /&gt;
=== From the Yambo Virtual Machine (VM)  ===&lt;br /&gt;
If you are using the VM, a recent version of the tutorial files is provided.Follow these [[Yambo_Virtual_Machine#Updating_the_Yambo_tutorial_files| instructions]] to update the tutorial files to the most recent version.&lt;br /&gt;
&lt;br /&gt;
=== From the Yambo website ===&lt;br /&gt;
If you are using your own installation or the docker, the files needed to run the tutorials can be downloaded from the lists below. &lt;br /&gt;
&lt;br /&gt;
After downloading the tar.gz files just unpack them in &#039;&#039;&#039;the YAMBO_TUTORIALS&#039;&#039;&#039; folder. For example&lt;br /&gt;
 $ mkdir YAMBO_TUTORIALS&lt;br /&gt;
 $ mv hBN.tar.gz YAMBO_TUTORIALS&lt;br /&gt;
 $ cd YAMBO_TUTORIALS&lt;br /&gt;
 $ tar -xvfz hBN.tar.gz&lt;br /&gt;
 $ ls YAMBO_TUTORIALS&lt;br /&gt;
   hBN&lt;br /&gt;
&lt;br /&gt;
====Files needed for modular tutorials====&lt;br /&gt;
All of the following should be downloaded prior to following the modular tutorials:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Tutorial !! File(s)&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;4&amp;quot;| hBN || [https://media.yambo-code.eu/educational/tutorials/files/hBN.tar.gz hBN.tar.gz] &lt;br /&gt;
|-&lt;br /&gt;
| [https://media.yambo-code.eu/educational/tutorials/files/hBN-convergence-kpoints.tar.gz hBN-convergence-kpoints.tar.gz]&lt;br /&gt;
|-&lt;br /&gt;
| [https://media.yambo-code.eu/educational/tutorials/files/hBN-2D.tar.gz hBN-2D.tar.gz] &lt;br /&gt;
|-&lt;br /&gt;
| [https://media.yambo-code.eu/educational/tutorials/files/hBN-2D-para.tar.gz hBN-2D-para.tar.gz]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
====Files needed for stand-alone tutorials====&lt;br /&gt;
At the start of each tutorial you will be told which specific file needs to be downloaded:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Tutorial !! File(s)&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot;| Silicon || [https://media.yambo-code.eu/educational/tutorials/files/Silicon.tar.gz Silicon.tar.gz]&lt;br /&gt;
|-&lt;br /&gt;
|[https://media.yambo-code.eu/educational/tutorials/files/Silicon_Electron-Phonon.tar.gz Silicon_Electron-Phonon.tar.gz]&lt;br /&gt;
|-&lt;br /&gt;
| LiF || [https://media.yambo-code.eu/educational/tutorials/files/LiF.tar.gz LiF.tar.gz]&lt;br /&gt;
|-&lt;br /&gt;
| Aluminum || [https://media.yambo-code.eu/educational/tutorials/files/Aluminum.tar.gz Aluminum.tar.gz]&lt;br /&gt;
|-&lt;br /&gt;
| GaSb || [https://media.yambo-code.eu/educational/tutorials/files/GaSb.tar.gz GaSb.tar.gz]&lt;br /&gt;
|-&lt;br /&gt;
| AlAs || [https://media.yambo-code.eu/educational/tutorials/files/AlAs.tar.gz AlAs.tar.gz]&lt;br /&gt;
|-&lt;br /&gt;
| Hydrogen_Chain || [https://media.yambo-code.eu/educational/tutorials/files/Hydrogen_Chain.tar.gz Hydrogen_Chain.tar.gz]&lt;br /&gt;
|-&lt;br /&gt;
| MoS2 for HPC || [https://media.yambo-code.eu/educational/tutorials/files/MoS2_HPC_tutorial.tar.gz MoS2_HPC_tutorial.tar.gz]&lt;br /&gt;
|-&lt;br /&gt;
| MoS2 for HPC shorter version || [https://media.yambo-code.eu/educational/tutorials/files/MoS2_2Dquasiparticle_tutorial.tar.gz MoS2_2Dquasiparticle_tutorial.tar.gz]&lt;br /&gt;
|-&lt;br /&gt;
| Yambopy for QE || [https://media.yambo-code.eu/educational/tutorials/files/databases_qepy.tar databases_qepy]&lt;br /&gt;
|-&lt;br /&gt;
| Yambopy for YAMBO || [https://media.yambo-code.eu/educational/tutorials/files/databases_yambopy.tar databases_yambopy]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== From the Git Tutorial Repository (advanced users) ===&lt;br /&gt;
If you are using your own installation or the docker, the [https://github.com/yambo-code/tutorials tutorials repository] contains the updated tutorials CORE databases. To use it&lt;br /&gt;
 $ git clone https://github.com/yambo-code/tutorials.git YAMBO_TUTORIALS&lt;br /&gt;
 $ cd YAMBO_TUTORIALS&lt;br /&gt;
 $ ./setup.pl -install&lt;br /&gt;
&lt;br /&gt;
== Stand-alone tutorials ==&lt;br /&gt;
These tutorials are self-contained and cover a variety of mixed topics, both physical and methodological. They are designed to be followed from start to finish in one page and do not require previous knowledge of yambo. 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;
* [[LiF|Linear Response in 3D. Excitons at work]]&lt;br /&gt;
* [[Silicon|GW convergence]]&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
* [[Si_Surface|Linear Response in 2D]]&lt;br /&gt;
* [[Si_wire|Linear Response in 1D]]&lt;br /&gt;
* [[H2|Linear Response in 0D]]&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
=== Post Processing ===&lt;br /&gt;
* [[Yambo Post Processing (ypp)]]&lt;br /&gt;
* [[First steps in Yambopy]]&lt;br /&gt;
* [[Yambopy tutorial: band structures]]&lt;br /&gt;
* [[Yambopy tutorial: Yambo databases]]&lt;br /&gt;
* [[Yambopy][GW tutorial. Convergence and approximations (BN)]]&lt;br /&gt;
* [[Bethe-Salpeter equation tutorial. Optical absorption (BN)]]&lt;br /&gt;
&lt;br /&gt;
=== Advanced ===&lt;br /&gt;
* [[Hydrogen chain|TDDFT Failure and long range correlations]]&lt;br /&gt;
* [[Linear response from real time simulations]]&lt;br /&gt;
&lt;br /&gt;
==== 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 tutorial on HPC]]&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;
==== Non linear response ====&lt;br /&gt;
* [http://www.attaccalite.com/lumen/linear_response.html Linear response using Dynamical Berry phase]&lt;br /&gt;
* [[Real time approach to non-linear response]]&lt;br /&gt;
* [[Correlation effects in the non-linear response]]&lt;br /&gt;
* [http://www.attaccalite.com/lumen/thg_in_silicon.html Third Harmonic Generation]&lt;br /&gt;
* [http://www.attaccalite.com/lumen/spin_orbit.html Spin-orbit coupling and non-linear response]&lt;br /&gt;
* [[Two-photon absorption]] &lt;br /&gt;
* [[Pump and Probe]]&lt;br /&gt;
* [[Parallelization for non-linear response calculations]]&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;
* [[Kerr|Kerr]]&lt;br /&gt;
* [[Real_Time|Real-Time]]&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;br /&gt;
&lt;br /&gt;
== Modular tutorials ==&lt;br /&gt;
These tutorials are designed to provide a deeper understanding of specific yambo tasks and runlevels. They are designed to avoid repetition of common procedures and physical concepts. As such, they make use of the same physical systems: bulk hexagonal boron nitride &#039;&#039;hBN&#039;&#039; and a hBN sheet &#039;&#039;hBN-2D&#039;&#039;.&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;
====Introduction====&lt;br /&gt;
* [[First steps: a walk through from DFT to optical properties]]&lt;br /&gt;
====Quasiparticles in the GW approximation====&lt;br /&gt;
* [[How to obtain the quasi-particle band structure of a bulk material: h-BN]]&lt;br /&gt;
====Using Yambo in Parallel====&lt;br /&gt;
This modules contains very general discussions of the parallel environment of Yambo. Still the actual run of the code is specific to the CECAM cluster. If you want to run these modules just replace the parallel queue instructions with simple MPI commands.&lt;br /&gt;
&lt;br /&gt;
* [[GW_parallel_strategies|Parallel GW (CECAM specific)]]: strategies for running Yambo in parallel&lt;br /&gt;
[[GW_parallel_strategies_CECAM]]&lt;br /&gt;
* [[Pushing_convergence_in_parallel|GW convergence (CECAM specific)]]: use Yambo in parallel to converge a GW calculation for a layer of hBN (hBN-2D)&lt;br /&gt;
&lt;br /&gt;
====Excitons and the Bethe-Salpeter Equation====&lt;br /&gt;
* [[How to obtain an optical spectrum|Calculating optical spectra including excitonic effects: a step-by-step guide]]&lt;br /&gt;
* [[How to choose the input parameters|Obtaining a converged optical spectrum]] &lt;br /&gt;
* [[How to treat low dimensional systems|Many-body effects in low-dimensional systems: numerical issues and remedies]] &lt;br /&gt;
* [[How to analyse excitons|Analysis of excitonic spectra in a 2D material]]&lt;br /&gt;
&amp;lt;!--* [[Two particle excitations]] (try to bypass this page) : Learn how to set up and run calculations to obtain and analyze an optical absorption spectrum of bulk and low dimension materials by using the Bethe-Salpeter equation--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Yambopy====&lt;br /&gt;
* [[First steps in Yambopy]]&lt;br /&gt;
* [[GW tutorial. Convergence and approximations (BN)]]&lt;br /&gt;
* [[Bethe-Salpeter equation tutorial. Optical absorption (BN)]]&lt;br /&gt;
* [[Yambopy tutorial: band structures | Database and plotting tutorial for quantum espresso: qepy]]&lt;br /&gt;
* [[Yambopy tutorial: Yambo databases | Database and plotting tutorial for yambo: yambopy ]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
====Real-time simulations====&lt;br /&gt;
* [[Breaking of symmetries]]&lt;br /&gt;
* [[Independent-Particle Approximation Dynamics. Delta Pulse]]&lt;br /&gt;
* [[Post-processing. Optical Response]]&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
=== Modules ===&lt;br /&gt;
Alternatively, users can learn more about a specific runlevel or task by looking at the individual &#039;&#039;&#039;[[Modules|documentation modules]]&#039;&#039;&#039;. These provide a focus on the input parameters, run time behaviour, and underlying physics. Although they can be followed separately, non-experts are urged to follow them as part of the more structured tutorials given above.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
== &amp;lt;span id=&amp;quot;Schools&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;Schools ==&lt;br /&gt;
* [[ICTP2020]]&lt;br /&gt;
* [[CECAM VIRTUAL 2021]]&lt;br /&gt;
* [https://www.yambo-code.org/wiki/index.php?title=ICTP_2022 ICTP2022]&lt;br /&gt;
--&amp;gt;&lt;/div&gt;</summary>
		<author><name>Fulvio</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Tutorials&amp;diff=7054</id>
		<title>Tutorials</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Tutorials&amp;diff=7054"/>
		<updated>2023-06-15T14:24:43Z</updated>

		<summary type="html">&lt;p&gt;Fulvio: /* Post Processing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;If you are starting out with Yambo, or even an experienced user, we recommend that you complete the following tutorials before trying to use Yambo for your system.&lt;br /&gt;
&lt;br /&gt;
The tutorials are meant to give some introductory background to the key concepts behind Yambo. Practical topics such as convergence are also discussed. &lt;br /&gt;
Nonetheless, users are invited to first read and study the [[lectures|background material]] in order to get familiar with the fundamental physical quantities.&lt;br /&gt;
&lt;br /&gt;
Two kinds of tutorials are provided: &#039;&#039;&#039;stand-alone&#039;&#039;&#039; and &#039;&#039;&#039;modular&#039;&#039;&#039;. In addition you must have a working environment where both Yambo (and eventually QE) are installed.&lt;br /&gt;
&lt;br /&gt;
== Setting up Yambo (and eventually QE)  ==&lt;br /&gt;
To be able to follow the school you need a running version of the yambo/QE code.&lt;br /&gt;
&lt;br /&gt;
There are several different ways to prepare a working environment.&lt;br /&gt;
&lt;br /&gt;
=== Virtual Machine(s) ===&lt;br /&gt;
The easiest way is to access to a virtual machine which contains both (i) yambo/QE and (ii) the tutorials.&lt;br /&gt;
&lt;br /&gt;
You can do it in one of two ways:&lt;br /&gt;
* Virtual machine via [[ICTP cloud|ICTP cloud]] If the schools you are attending provided an ICTP virtual machine this is the preferred option. It works through internet connection inside a browser.&lt;br /&gt;
* Install the [[Yambo_Virtual_Machine|yambo virtual machine]] on your laptop / desktop. This requires Oracle virtual box. Pre-download of the Virtual machine. No internet connection needed.&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
URL of the machine : https://ins45100.ictp.it/&lt;br /&gt;
READ-ONLY PASSWORD for TUTOR (ictptutor) access:&lt;br /&gt;
NairibiTutor&lt;br /&gt;
READ-WRITE password for PARTICIPANT&#039;s (ictpuser) access:&lt;br /&gt;
NairobiUser&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== User installation  ===&lt;br /&gt;
You can also setup the yambo code on your on laptop / desktop using different methods.&lt;br /&gt;
&lt;br /&gt;
As far as the Yambo source is concerned you can:&lt;br /&gt;
* Install [[Yambo via Docker|Yambo via Docker]]&lt;br /&gt;
* [[download|Download]] and [[Installation|install]] yambo on your laptop / desktop (requires a linux machine).&lt;br /&gt;
* Install yambo on your laptop/desktop/cluster [https://github.com/nicspalla/my-repo via Spack].&lt;br /&gt;
* Install using  Anaconda.&lt;br /&gt;
&lt;br /&gt;
=== Yambo User Installation with Anaconda ===&lt;br /&gt;
It is possible to install Yambo (up to v5.0.4) and Quantum-ESPRESSO via conda-forge (a conda channel/repository):&lt;br /&gt;
To setup Anaconda, please start from installing [https://www.anaconda.com/products/distribution#Downloads Anaconda] or [https://docs.conda.io/en/latest/miniconda.html Miniconda].&lt;br /&gt;
&lt;br /&gt;
Then we suggest to create a conda environment and activate it:&lt;br /&gt;
 conda create --name yambopy -c conda-forge&lt;br /&gt;
 conda activate yambopy&lt;br /&gt;
Then you can install the prerequisites and the two codes:&lt;br /&gt;
 conda install numpy scipy netcdf4 matplotlib pyyaml lxml pandas&lt;br /&gt;
 conda install yambo &lt;br /&gt;
 conda install qe&lt;br /&gt;
&lt;br /&gt;
==Setting up Yambopy==&lt;br /&gt;
&lt;br /&gt;
===Quick installation===&lt;br /&gt;
&lt;br /&gt;
A quick way to start using Yambopy is described here.&lt;br /&gt;
&lt;br /&gt;
* Make sure that you are using Python 3 and that you have the following python packages: &amp;lt;code&amp;gt;numpy&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;scipy&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;matplotlib&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;netCDF4&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;lxml&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;pyyaml&amp;lt;/code&amp;gt;. Optionally, you may want to have abipy [[https://abinit.github.io/abipy/index.html]] installed for band structure interpolations.&lt;br /&gt;
&lt;br /&gt;
* Go to a directory of your choice and clone yambopy from the git repository&lt;br /&gt;
&lt;br /&gt;
 git clone https://github.com/yambo-code/yambopy.git&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t want to use git, you may download a tarball from the git repository instead.&lt;br /&gt;
&lt;br /&gt;
* Enter into the yambopy folder and install&lt;br /&gt;
&lt;br /&gt;
 cd yambopy&lt;br /&gt;
 sudo python setup.py install&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t have administrative privileges (for example on a computing cluster), type instead&lt;br /&gt;
&lt;br /&gt;
 cd yambopy&lt;br /&gt;
 python setup.py install --user&lt;br /&gt;
&lt;br /&gt;
===Installing dependencies with Anaconda===&lt;br /&gt;
We suggest installing yambopy using Anaconda [[https://www.anaconda.com/products/distribution]] to manage the various python packages.&lt;br /&gt;
&lt;br /&gt;
In this case, you can follow these steps.&lt;br /&gt;
&lt;br /&gt;
First, install the required dependencies:&lt;br /&gt;
 conda install numpy scipy netcdf4 lxml pyyaml&lt;br /&gt;
&lt;br /&gt;
Then we create a conda environment based on python 3.6 (this is to ensure compatibility with abipy if we want to install it later on):&lt;br /&gt;
 conda create --name NAME_ENV python=3.6&lt;br /&gt;
Here choose &amp;lt;code&amp;gt;NAME_ENV&amp;lt;/code&amp;gt; as you want, e.g. &amp;lt;code&amp;gt;yenv&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Now, we install abipy and its dependency pymatgen using &amp;lt;code&amp;gt;pip&amp;lt;/code&amp;gt;. Here make sure that you are using the &amp;lt;code&amp;gt;pip&amp;lt;/code&amp;gt; version provided by Anaconda and not your system version.&lt;br /&gt;
&lt;br /&gt;
 pip install pymatgen&lt;br /&gt;
 pip install abipy&lt;br /&gt;
&lt;br /&gt;
Finally, we are ready to install yambopy:&lt;br /&gt;
&lt;br /&gt;
 git clone https://github.com/yambo-code/yambopy.git &lt;br /&gt;
&lt;br /&gt;
(or download and extract tarball) and follow the steps outlined in the quick installation section.&lt;br /&gt;
&lt;br /&gt;
Now enter into the yambopy folder and install&lt;br /&gt;
&lt;br /&gt;
 cd yambopy&lt;br /&gt;
 sudo python setup.py install&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t have administrative privileges (for example on a computing cluster), type instead&lt;br /&gt;
&lt;br /&gt;
 cd yambopy&lt;br /&gt;
 python setup.py install --user&lt;br /&gt;
&lt;br /&gt;
===Frequent issues===&lt;br /&gt;
When running the installation you may get a &amp;lt;code&amp;gt;SyntaxError&amp;lt;/code&amp;gt; related to utf-8 encoding or it may complain that module &amp;lt;code&amp;gt;setuptools&amp;lt;/code&amp;gt; is not installed even though it is. In this case, it means that the &amp;lt;code&amp;gt;sudo&amp;lt;/code&amp;gt; command is not preserving the correct &amp;lt;code&amp;gt;PATH&amp;lt;/code&amp;gt; for your python executable.&lt;br /&gt;
&lt;br /&gt;
Solve the problem by running the installation step as&lt;br /&gt;
&lt;br /&gt;
 sudo /your/path/to/python setup.py install&lt;br /&gt;
or&lt;br /&gt;
 sudo env PATH=$PATH python setup.py install&lt;br /&gt;
&lt;br /&gt;
This applies only to the installation step and not to subsequent yambopy use.&lt;br /&gt;
&lt;br /&gt;
== Tutorial files ==&lt;br /&gt;
The tutorial CORE databases can be obtained&lt;br /&gt;
&lt;br /&gt;
* from the [[Yambo_Virtual_Machine|Yambo Virtual Machine]] &lt;br /&gt;
* from the Yambo web-page&lt;br /&gt;
* from the Yambo GIT tutorial repository &lt;br /&gt;
&lt;br /&gt;
=== From the Yambo Virtual Machine (VM)  ===&lt;br /&gt;
If you are using the VM, a recent version of the tutorial files is provided.Follow these [[Yambo_Virtual_Machine#Updating_the_Yambo_tutorial_files| instructions]] to update the tutorial files to the most recent version.&lt;br /&gt;
&lt;br /&gt;
=== From the Yambo website ===&lt;br /&gt;
If you are using your own installation or the docker, the files needed to run the tutorials can be downloaded from the lists below. &lt;br /&gt;
&lt;br /&gt;
After downloading the tar.gz files just unpack them in &#039;&#039;&#039;the YAMBO_TUTORIALS&#039;&#039;&#039; folder. For example&lt;br /&gt;
 $ mkdir YAMBO_TUTORIALS&lt;br /&gt;
 $ mv hBN.tar.gz YAMBO_TUTORIALS&lt;br /&gt;
 $ cd YAMBO_TUTORIALS&lt;br /&gt;
 $ tar -xvfz hBN.tar.gz&lt;br /&gt;
 $ ls YAMBO_TUTORIALS&lt;br /&gt;
   hBN&lt;br /&gt;
&lt;br /&gt;
====Files needed for modular tutorials====&lt;br /&gt;
All of the following should be downloaded prior to following the modular tutorials:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Tutorial !! File(s)&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;4&amp;quot;| hBN || [https://media.yambo-code.eu/educational/tutorials/files/hBN.tar.gz hBN.tar.gz] &lt;br /&gt;
|-&lt;br /&gt;
| [https://media.yambo-code.eu/educational/tutorials/files/hBN-convergence-kpoints.tar.gz hBN-convergence-kpoints.tar.gz]&lt;br /&gt;
|-&lt;br /&gt;
| [https://media.yambo-code.eu/educational/tutorials/files/hBN-2D.tar.gz hBN-2D.tar.gz] &lt;br /&gt;
|-&lt;br /&gt;
| [https://media.yambo-code.eu/educational/tutorials/files/hBN-2D-para.tar.gz hBN-2D-para.tar.gz]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
====Files needed for stand-alone tutorials====&lt;br /&gt;
At the start of each tutorial you will be told which specific file needs to be downloaded:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Tutorial !! File(s)&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot;| Silicon || [https://media.yambo-code.eu/educational/tutorials/files/Silicon.tar.gz Silicon.tar.gz]&lt;br /&gt;
|-&lt;br /&gt;
|[https://media.yambo-code.eu/educational/tutorials/files/Silicon_Electron-Phonon.tar.gz Silicon_Electron-Phonon.tar.gz]&lt;br /&gt;
|-&lt;br /&gt;
| LiF || [https://media.yambo-code.eu/educational/tutorials/files/LiF.tar.gz LiF.tar.gz]&lt;br /&gt;
|-&lt;br /&gt;
| Aluminum || [https://media.yambo-code.eu/educational/tutorials/files/Aluminum.tar.gz Aluminum.tar.gz]&lt;br /&gt;
|-&lt;br /&gt;
| GaSb || [https://media.yambo-code.eu/educational/tutorials/files/GaSb.tar.gz GaSb.tar.gz]&lt;br /&gt;
|-&lt;br /&gt;
| AlAs || [https://media.yambo-code.eu/educational/tutorials/files/AlAs.tar.gz AlAs.tar.gz]&lt;br /&gt;
|-&lt;br /&gt;
| Hydrogen_Chain || [https://media.yambo-code.eu/educational/tutorials/files/Hydrogen_Chain.tar.gz Hydrogen_Chain.tar.gz]&lt;br /&gt;
|-&lt;br /&gt;
| MoS2 for HPC || [https://media.yambo-code.eu/educational/tutorials/files/MoS2_HPC_tutorial.tar.gz MoS2_HPC_tutorial.tar.gz]&lt;br /&gt;
|-&lt;br /&gt;
| MoS2 for HPC shorter version || [https://media.yambo-code.eu/educational/tutorials/files/MoS2_2Dquasiparticle_tutorial.tar.gz MoS2_2Dquasiparticle_tutorial.tar.gz]&lt;br /&gt;
|-&lt;br /&gt;
| Yambopy for QE || [https://media.yambo-code.eu/educational/tutorials/files/databases_qepy.tar databases_qepy]&lt;br /&gt;
|-&lt;br /&gt;
| Yambopy for YAMBO || [https://media.yambo-code.eu/educational/tutorials/files/databases_yambopy.tar databases_yambopy]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== From the Git Tutorial Repository (advanced users) ===&lt;br /&gt;
If you are using your own installation or the docker, the [https://github.com/yambo-code/tutorials tutorials repository] contains the updated tutorials CORE databases. To use it&lt;br /&gt;
 $ git clone https://github.com/yambo-code/tutorials.git YAMBO_TUTORIALS&lt;br /&gt;
 $ cd YAMBO_TUTORIALS&lt;br /&gt;
 $ ./setup.pl -install&lt;br /&gt;
&lt;br /&gt;
== Stand-alone tutorials ==&lt;br /&gt;
These tutorials are self-contained and cover a variety of mixed topics, both physical and methodological. They are designed to be followed from start to finish in one page and do not require previous knowledge of yambo. 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;
* [[LiF|Linear Response in 3D. Excitons at work]]&lt;br /&gt;
* [[Silicon|GW convergence]]&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
* [[Si_Surface|Linear Response in 2D]]&lt;br /&gt;
* [[Si_wire|Linear Response in 1D]]&lt;br /&gt;
* [[H2|Linear Response in 0D]]&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
=== Post Processing ===&lt;br /&gt;
* [[Yambo Post Processing (ypp)]]&lt;br /&gt;
* [[First steps in Yambopy]]&lt;br /&gt;
* [[Yambopy tutorial: band structures]]&lt;br /&gt;
* [[Yambopy tutorial: Yambo databases]]&lt;br /&gt;
* [[GW tutorial. Convergence and approximations (BN)]]&lt;br /&gt;
* [[Bethe-Salpeter equation tutorial. Optical absorption (BN)]]&lt;br /&gt;
&lt;br /&gt;
=== Advanced ===&lt;br /&gt;
* [[Hydrogen chain|TDDFT Failure and long range correlations]]&lt;br /&gt;
* [[Linear response from real time simulations]]&lt;br /&gt;
&lt;br /&gt;
==== 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 tutorial on HPC]]&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;
==== Non linear response ====&lt;br /&gt;
* [http://www.attaccalite.com/lumen/linear_response.html Linear response using Dynamical Berry phase]&lt;br /&gt;
* [[Real time approach to non-linear response]]&lt;br /&gt;
* [[Correlation effects in the non-linear response]]&lt;br /&gt;
* [http://www.attaccalite.com/lumen/thg_in_silicon.html Third Harmonic Generation]&lt;br /&gt;
* [http://www.attaccalite.com/lumen/spin_orbit.html Spin-orbit coupling and non-linear response]&lt;br /&gt;
* [[Two-photon absorption]] &lt;br /&gt;
* [[Pump and Probe]]&lt;br /&gt;
* [[Parallelization for non-linear response calculations]]&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;
* [[Kerr|Kerr]]&lt;br /&gt;
* [[Real_Time|Real-Time]]&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;br /&gt;
&lt;br /&gt;
== Modular tutorials ==&lt;br /&gt;
These tutorials are designed to provide a deeper understanding of specific yambo tasks and runlevels. They are designed to avoid repetition of common procedures and physical concepts. As such, they make use of the same physical systems: bulk hexagonal boron nitride &#039;&#039;hBN&#039;&#039; and a hBN sheet &#039;&#039;hBN-2D&#039;&#039;.&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;
====Introduction====&lt;br /&gt;
* [[First steps: a walk through from DFT to optical properties]]&lt;br /&gt;
====Quasiparticles in the GW approximation====&lt;br /&gt;
* [[How to obtain the quasi-particle band structure of a bulk material: h-BN]]&lt;br /&gt;
====Using Yambo in Parallel====&lt;br /&gt;
This modules contains very general discussions of the parallel environment of Yambo. Still the actual run of the code is specific to the CECAM cluster. If you want to run these modules just replace the parallel queue instructions with simple MPI commands.&lt;br /&gt;
&lt;br /&gt;
* [[GW_parallel_strategies|Parallel GW (CECAM specific)]]: strategies for running Yambo in parallel&lt;br /&gt;
[[GW_parallel_strategies_CECAM]]&lt;br /&gt;
* [[Pushing_convergence_in_parallel|GW convergence (CECAM specific)]]: use Yambo in parallel to converge a GW calculation for a layer of hBN (hBN-2D)&lt;br /&gt;
&lt;br /&gt;
====Excitons and the Bethe-Salpeter Equation====&lt;br /&gt;
* [[How to obtain an optical spectrum|Calculating optical spectra including excitonic effects: a step-by-step guide]]&lt;br /&gt;
* [[How to choose the input parameters|Obtaining a converged optical spectrum]] &lt;br /&gt;
* [[How to treat low dimensional systems|Many-body effects in low-dimensional systems: numerical issues and remedies]] &lt;br /&gt;
* [[How to analyse excitons|Analysis of excitonic spectra in a 2D material]]&lt;br /&gt;
&amp;lt;!--* [[Two particle excitations]] (try to bypass this page) : Learn how to set up and run calculations to obtain and analyze an optical absorption spectrum of bulk and low dimension materials by using the Bethe-Salpeter equation--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Yambopy====&lt;br /&gt;
* [[First steps in Yambopy]]&lt;br /&gt;
* [[GW tutorial. Convergence and approximations (BN)]]&lt;br /&gt;
* [[Bethe-Salpeter equation tutorial. Optical absorption (BN)]]&lt;br /&gt;
* [[Yambopy tutorial: band structures | Database and plotting tutorial for quantum espresso: qepy]]&lt;br /&gt;
* [[Yambopy tutorial: Yambo databases | Database and plotting tutorial for yambo: yambopy ]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
====Real-time simulations====&lt;br /&gt;
* [[Breaking of symmetries]]&lt;br /&gt;
* [[Independent-Particle Approximation Dynamics. Delta Pulse]]&lt;br /&gt;
* [[Post-processing. Optical Response]]&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
=== Modules ===&lt;br /&gt;
Alternatively, users can learn more about a specific runlevel or task by looking at the individual &#039;&#039;&#039;[[Modules|documentation modules]]&#039;&#039;&#039;. These provide a focus on the input parameters, run time behaviour, and underlying physics. Although they can be followed separately, non-experts are urged to follow them as part of the more structured tutorials given above.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
== &amp;lt;span id=&amp;quot;Schools&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;Schools ==&lt;br /&gt;
* [[ICTP2020]]&lt;br /&gt;
* [[CECAM VIRTUAL 2021]]&lt;br /&gt;
* [https://www.yambo-code.org/wiki/index.php?title=ICTP_2022 ICTP2022]&lt;br /&gt;
--&amp;gt;&lt;/div&gt;</summary>
		<author><name>Fulvio</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Tutorials&amp;diff=7053</id>
		<title>Tutorials</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Tutorials&amp;diff=7053"/>
		<updated>2023-06-15T14:24:07Z</updated>

		<summary type="html">&lt;p&gt;Fulvio: /* Post Processing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;If you are starting out with Yambo, or even an experienced user, we recommend that you complete the following tutorials before trying to use Yambo for your system.&lt;br /&gt;
&lt;br /&gt;
The tutorials are meant to give some introductory background to the key concepts behind Yambo. Practical topics such as convergence are also discussed. &lt;br /&gt;
Nonetheless, users are invited to first read and study the [[lectures|background material]] in order to get familiar with the fundamental physical quantities.&lt;br /&gt;
&lt;br /&gt;
Two kinds of tutorials are provided: &#039;&#039;&#039;stand-alone&#039;&#039;&#039; and &#039;&#039;&#039;modular&#039;&#039;&#039;. In addition you must have a working environment where both Yambo (and eventually QE) are installed.&lt;br /&gt;
&lt;br /&gt;
== Setting up Yambo (and eventually QE)  ==&lt;br /&gt;
To be able to follow the school you need a running version of the yambo/QE code.&lt;br /&gt;
&lt;br /&gt;
There are several different ways to prepare a working environment.&lt;br /&gt;
&lt;br /&gt;
=== Virtual Machine(s) ===&lt;br /&gt;
The easiest way is to access to a virtual machine which contains both (i) yambo/QE and (ii) the tutorials.&lt;br /&gt;
&lt;br /&gt;
You can do it in one of two ways:&lt;br /&gt;
* Virtual machine via [[ICTP cloud|ICTP cloud]] If the schools you are attending provided an ICTP virtual machine this is the preferred option. It works through internet connection inside a browser.&lt;br /&gt;
* Install the [[Yambo_Virtual_Machine|yambo virtual machine]] on your laptop / desktop. This requires Oracle virtual box. Pre-download of the Virtual machine. No internet connection needed.&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
URL of the machine : https://ins45100.ictp.it/&lt;br /&gt;
READ-ONLY PASSWORD for TUTOR (ictptutor) access:&lt;br /&gt;
NairibiTutor&lt;br /&gt;
READ-WRITE password for PARTICIPANT&#039;s (ictpuser) access:&lt;br /&gt;
NairobiUser&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== User installation  ===&lt;br /&gt;
You can also setup the yambo code on your on laptop / desktop using different methods.&lt;br /&gt;
&lt;br /&gt;
As far as the Yambo source is concerned you can:&lt;br /&gt;
* Install [[Yambo via Docker|Yambo via Docker]]&lt;br /&gt;
* [[download|Download]] and [[Installation|install]] yambo on your laptop / desktop (requires a linux machine).&lt;br /&gt;
* Install yambo on your laptop/desktop/cluster [https://github.com/nicspalla/my-repo via Spack].&lt;br /&gt;
* Install using  Anaconda.&lt;br /&gt;
&lt;br /&gt;
=== Yambo User Installation with Anaconda ===&lt;br /&gt;
It is possible to install Yambo (up to v5.0.4) and Quantum-ESPRESSO via conda-forge (a conda channel/repository):&lt;br /&gt;
To setup Anaconda, please start from installing [https://www.anaconda.com/products/distribution#Downloads Anaconda] or [https://docs.conda.io/en/latest/miniconda.html Miniconda].&lt;br /&gt;
&lt;br /&gt;
Then we suggest to create a conda environment and activate it:&lt;br /&gt;
 conda create --name yambopy -c conda-forge&lt;br /&gt;
 conda activate yambopy&lt;br /&gt;
Then you can install the prerequisites and the two codes:&lt;br /&gt;
 conda install numpy scipy netcdf4 matplotlib pyyaml lxml pandas&lt;br /&gt;
 conda install yambo &lt;br /&gt;
 conda install qe&lt;br /&gt;
&lt;br /&gt;
==Setting up Yambopy==&lt;br /&gt;
&lt;br /&gt;
===Quick installation===&lt;br /&gt;
&lt;br /&gt;
A quick way to start using Yambopy is described here.&lt;br /&gt;
&lt;br /&gt;
* Make sure that you are using Python 3 and that you have the following python packages: &amp;lt;code&amp;gt;numpy&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;scipy&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;matplotlib&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;netCDF4&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;lxml&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;pyyaml&amp;lt;/code&amp;gt;. Optionally, you may want to have abipy [[https://abinit.github.io/abipy/index.html]] installed for band structure interpolations.&lt;br /&gt;
&lt;br /&gt;
* Go to a directory of your choice and clone yambopy from the git repository&lt;br /&gt;
&lt;br /&gt;
 git clone https://github.com/yambo-code/yambopy.git&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t want to use git, you may download a tarball from the git repository instead.&lt;br /&gt;
&lt;br /&gt;
* Enter into the yambopy folder and install&lt;br /&gt;
&lt;br /&gt;
 cd yambopy&lt;br /&gt;
 sudo python setup.py install&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t have administrative privileges (for example on a computing cluster), type instead&lt;br /&gt;
&lt;br /&gt;
 cd yambopy&lt;br /&gt;
 python setup.py install --user&lt;br /&gt;
&lt;br /&gt;
===Installing dependencies with Anaconda===&lt;br /&gt;
We suggest installing yambopy using Anaconda [[https://www.anaconda.com/products/distribution]] to manage the various python packages.&lt;br /&gt;
&lt;br /&gt;
In this case, you can follow these steps.&lt;br /&gt;
&lt;br /&gt;
First, install the required dependencies:&lt;br /&gt;
 conda install numpy scipy netcdf4 lxml pyyaml&lt;br /&gt;
&lt;br /&gt;
Then we create a conda environment based on python 3.6 (this is to ensure compatibility with abipy if we want to install it later on):&lt;br /&gt;
 conda create --name NAME_ENV python=3.6&lt;br /&gt;
Here choose &amp;lt;code&amp;gt;NAME_ENV&amp;lt;/code&amp;gt; as you want, e.g. &amp;lt;code&amp;gt;yenv&amp;lt;/code&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Now, we install abipy and its dependency pymatgen using &amp;lt;code&amp;gt;pip&amp;lt;/code&amp;gt;. Here make sure that you are using the &amp;lt;code&amp;gt;pip&amp;lt;/code&amp;gt; version provided by Anaconda and not your system version.&lt;br /&gt;
&lt;br /&gt;
 pip install pymatgen&lt;br /&gt;
 pip install abipy&lt;br /&gt;
&lt;br /&gt;
Finally, we are ready to install yambopy:&lt;br /&gt;
&lt;br /&gt;
 git clone https://github.com/yambo-code/yambopy.git &lt;br /&gt;
&lt;br /&gt;
(or download and extract tarball) and follow the steps outlined in the quick installation section.&lt;br /&gt;
&lt;br /&gt;
Now enter into the yambopy folder and install&lt;br /&gt;
&lt;br /&gt;
 cd yambopy&lt;br /&gt;
 sudo python setup.py install&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t have administrative privileges (for example on a computing cluster), type instead&lt;br /&gt;
&lt;br /&gt;
 cd yambopy&lt;br /&gt;
 python setup.py install --user&lt;br /&gt;
&lt;br /&gt;
===Frequent issues===&lt;br /&gt;
When running the installation you may get a &amp;lt;code&amp;gt;SyntaxError&amp;lt;/code&amp;gt; related to utf-8 encoding or it may complain that module &amp;lt;code&amp;gt;setuptools&amp;lt;/code&amp;gt; is not installed even though it is. In this case, it means that the &amp;lt;code&amp;gt;sudo&amp;lt;/code&amp;gt; command is not preserving the correct &amp;lt;code&amp;gt;PATH&amp;lt;/code&amp;gt; for your python executable.&lt;br /&gt;
&lt;br /&gt;
Solve the problem by running the installation step as&lt;br /&gt;
&lt;br /&gt;
 sudo /your/path/to/python setup.py install&lt;br /&gt;
or&lt;br /&gt;
 sudo env PATH=$PATH python setup.py install&lt;br /&gt;
&lt;br /&gt;
This applies only to the installation step and not to subsequent yambopy use.&lt;br /&gt;
&lt;br /&gt;
== Tutorial files ==&lt;br /&gt;
The tutorial CORE databases can be obtained&lt;br /&gt;
&lt;br /&gt;
* from the [[Yambo_Virtual_Machine|Yambo Virtual Machine]] &lt;br /&gt;
* from the Yambo web-page&lt;br /&gt;
* from the Yambo GIT tutorial repository &lt;br /&gt;
&lt;br /&gt;
=== From the Yambo Virtual Machine (VM)  ===&lt;br /&gt;
If you are using the VM, a recent version of the tutorial files is provided.Follow these [[Yambo_Virtual_Machine#Updating_the_Yambo_tutorial_files| instructions]] to update the tutorial files to the most recent version.&lt;br /&gt;
&lt;br /&gt;
=== From the Yambo website ===&lt;br /&gt;
If you are using your own installation or the docker, the files needed to run the tutorials can be downloaded from the lists below. &lt;br /&gt;
&lt;br /&gt;
After downloading the tar.gz files just unpack them in &#039;&#039;&#039;the YAMBO_TUTORIALS&#039;&#039;&#039; folder. For example&lt;br /&gt;
 $ mkdir YAMBO_TUTORIALS&lt;br /&gt;
 $ mv hBN.tar.gz YAMBO_TUTORIALS&lt;br /&gt;
 $ cd YAMBO_TUTORIALS&lt;br /&gt;
 $ tar -xvfz hBN.tar.gz&lt;br /&gt;
 $ ls YAMBO_TUTORIALS&lt;br /&gt;
   hBN&lt;br /&gt;
&lt;br /&gt;
====Files needed for modular tutorials====&lt;br /&gt;
All of the following should be downloaded prior to following the modular tutorials:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Tutorial !! File(s)&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;4&amp;quot;| hBN || [https://media.yambo-code.eu/educational/tutorials/files/hBN.tar.gz hBN.tar.gz] &lt;br /&gt;
|-&lt;br /&gt;
| [https://media.yambo-code.eu/educational/tutorials/files/hBN-convergence-kpoints.tar.gz hBN-convergence-kpoints.tar.gz]&lt;br /&gt;
|-&lt;br /&gt;
| [https://media.yambo-code.eu/educational/tutorials/files/hBN-2D.tar.gz hBN-2D.tar.gz] &lt;br /&gt;
|-&lt;br /&gt;
| [https://media.yambo-code.eu/educational/tutorials/files/hBN-2D-para.tar.gz hBN-2D-para.tar.gz]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
====Files needed for stand-alone tutorials====&lt;br /&gt;
At the start of each tutorial you will be told which specific file needs to be downloaded:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Tutorial !! File(s)&lt;br /&gt;
|-&lt;br /&gt;
| rowspan=&amp;quot;2&amp;quot;| Silicon || [https://media.yambo-code.eu/educational/tutorials/files/Silicon.tar.gz Silicon.tar.gz]&lt;br /&gt;
|-&lt;br /&gt;
|[https://media.yambo-code.eu/educational/tutorials/files/Silicon_Electron-Phonon.tar.gz Silicon_Electron-Phonon.tar.gz]&lt;br /&gt;
|-&lt;br /&gt;
| LiF || [https://media.yambo-code.eu/educational/tutorials/files/LiF.tar.gz LiF.tar.gz]&lt;br /&gt;
|-&lt;br /&gt;
| Aluminum || [https://media.yambo-code.eu/educational/tutorials/files/Aluminum.tar.gz Aluminum.tar.gz]&lt;br /&gt;
|-&lt;br /&gt;
| GaSb || [https://media.yambo-code.eu/educational/tutorials/files/GaSb.tar.gz GaSb.tar.gz]&lt;br /&gt;
|-&lt;br /&gt;
| AlAs || [https://media.yambo-code.eu/educational/tutorials/files/AlAs.tar.gz AlAs.tar.gz]&lt;br /&gt;
|-&lt;br /&gt;
| Hydrogen_Chain || [https://media.yambo-code.eu/educational/tutorials/files/Hydrogen_Chain.tar.gz Hydrogen_Chain.tar.gz]&lt;br /&gt;
|-&lt;br /&gt;
| MoS2 for HPC || [https://media.yambo-code.eu/educational/tutorials/files/MoS2_HPC_tutorial.tar.gz MoS2_HPC_tutorial.tar.gz]&lt;br /&gt;
|-&lt;br /&gt;
| MoS2 for HPC shorter version || [https://media.yambo-code.eu/educational/tutorials/files/MoS2_2Dquasiparticle_tutorial.tar.gz MoS2_2Dquasiparticle_tutorial.tar.gz]&lt;br /&gt;
|-&lt;br /&gt;
| Yambopy for QE || [https://media.yambo-code.eu/educational/tutorials/files/databases_qepy.tar databases_qepy]&lt;br /&gt;
|-&lt;br /&gt;
| Yambopy for YAMBO || [https://media.yambo-code.eu/educational/tutorials/files/databases_yambopy.tar databases_yambopy]&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== From the Git Tutorial Repository (advanced users) ===&lt;br /&gt;
If you are using your own installation or the docker, the [https://github.com/yambo-code/tutorials tutorials repository] contains the updated tutorials CORE databases. To use it&lt;br /&gt;
 $ git clone https://github.com/yambo-code/tutorials.git YAMBO_TUTORIALS&lt;br /&gt;
 $ cd YAMBO_TUTORIALS&lt;br /&gt;
 $ ./setup.pl -install&lt;br /&gt;
&lt;br /&gt;
== Stand-alone tutorials ==&lt;br /&gt;
These tutorials are self-contained and cover a variety of mixed topics, both physical and methodological. They are designed to be followed from start to finish in one page and do not require previous knowledge of yambo. 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;
* [[LiF|Linear Response in 3D. Excitons at work]]&lt;br /&gt;
* [[Silicon|GW convergence]]&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
* [[Si_Surface|Linear Response in 2D]]&lt;br /&gt;
* [[Si_wire|Linear Response in 1D]]&lt;br /&gt;
* [[H2|Linear Response in 0D]]&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
=== Post Processing ===&lt;br /&gt;
* [[Yambo Post Processing (ypp)]]&lt;br /&gt;
* [[First Steps in YamboPy]]&lt;br /&gt;
* [[Yambopy tutorial: band structures]]&lt;br /&gt;
* [[Yambopy tutorial: Yambo databases]]&lt;br /&gt;
* [[GW tutorial. Convergence and approximations (BN)]]&lt;br /&gt;
* [[Bethe-Salpeter equation tutorial. Optical absorption (BN)]]&lt;br /&gt;
&lt;br /&gt;
=== Advanced ===&lt;br /&gt;
* [[Hydrogen chain|TDDFT Failure and long range correlations]]&lt;br /&gt;
* [[Linear response from real time simulations]]&lt;br /&gt;
&lt;br /&gt;
==== 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 tutorial on HPC]]&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;
==== Non linear response ====&lt;br /&gt;
* [http://www.attaccalite.com/lumen/linear_response.html Linear response using Dynamical Berry phase]&lt;br /&gt;
* [[Real time approach to non-linear response]]&lt;br /&gt;
* [[Correlation effects in the non-linear response]]&lt;br /&gt;
* [http://www.attaccalite.com/lumen/thg_in_silicon.html Third Harmonic Generation]&lt;br /&gt;
* [http://www.attaccalite.com/lumen/spin_orbit.html Spin-orbit coupling and non-linear response]&lt;br /&gt;
* [[Two-photon absorption]] &lt;br /&gt;
* [[Pump and Probe]]&lt;br /&gt;
* [[Parallelization for non-linear response calculations]]&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;
* [[Kerr|Kerr]]&lt;br /&gt;
* [[Real_Time|Real-Time]]&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;br /&gt;
&lt;br /&gt;
== Modular tutorials ==&lt;br /&gt;
These tutorials are designed to provide a deeper understanding of specific yambo tasks and runlevels. They are designed to avoid repetition of common procedures and physical concepts. As such, they make use of the same physical systems: bulk hexagonal boron nitride &#039;&#039;hBN&#039;&#039; and a hBN sheet &#039;&#039;hBN-2D&#039;&#039;.&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;
====Introduction====&lt;br /&gt;
* [[First steps: a walk through from DFT to optical properties]]&lt;br /&gt;
====Quasiparticles in the GW approximation====&lt;br /&gt;
* [[How to obtain the quasi-particle band structure of a bulk material: h-BN]]&lt;br /&gt;
====Using Yambo in Parallel====&lt;br /&gt;
This modules contains very general discussions of the parallel environment of Yambo. Still the actual run of the code is specific to the CECAM cluster. If you want to run these modules just replace the parallel queue instructions with simple MPI commands.&lt;br /&gt;
&lt;br /&gt;
* [[GW_parallel_strategies|Parallel GW (CECAM specific)]]: strategies for running Yambo in parallel&lt;br /&gt;
[[GW_parallel_strategies_CECAM]]&lt;br /&gt;
* [[Pushing_convergence_in_parallel|GW convergence (CECAM specific)]]: use Yambo in parallel to converge a GW calculation for a layer of hBN (hBN-2D)&lt;br /&gt;
&lt;br /&gt;
====Excitons and the Bethe-Salpeter Equation====&lt;br /&gt;
* [[How to obtain an optical spectrum|Calculating optical spectra including excitonic effects: a step-by-step guide]]&lt;br /&gt;
* [[How to choose the input parameters|Obtaining a converged optical spectrum]] &lt;br /&gt;
* [[How to treat low dimensional systems|Many-body effects in low-dimensional systems: numerical issues and remedies]] &lt;br /&gt;
* [[How to analyse excitons|Analysis of excitonic spectra in a 2D material]]&lt;br /&gt;
&amp;lt;!--* [[Two particle excitations]] (try to bypass this page) : Learn how to set up and run calculations to obtain and analyze an optical absorption spectrum of bulk and low dimension materials by using the Bethe-Salpeter equation--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Yambopy====&lt;br /&gt;
* [[First steps in Yambopy]]&lt;br /&gt;
* [[GW tutorial. Convergence and approximations (BN)]]&lt;br /&gt;
* [[Bethe-Salpeter equation tutorial. Optical absorption (BN)]]&lt;br /&gt;
* [[Yambopy tutorial: band structures | Database and plotting tutorial for quantum espresso: qepy]]&lt;br /&gt;
* [[Yambopy tutorial: Yambo databases | Database and plotting tutorial for yambo: yambopy ]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
====Real-time simulations====&lt;br /&gt;
* [[Breaking of symmetries]]&lt;br /&gt;
* [[Independent-Particle Approximation Dynamics. Delta Pulse]]&lt;br /&gt;
* [[Post-processing. Optical Response]]&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
=== Modules ===&lt;br /&gt;
Alternatively, users can learn more about a specific runlevel or task by looking at the individual &#039;&#039;&#039;[[Modules|documentation modules]]&#039;&#039;&#039;. These provide a focus on the input parameters, run time behaviour, and underlying physics. Although they can be followed separately, non-experts are urged to follow them as part of the more structured tutorials given above.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
== &amp;lt;span id=&amp;quot;Schools&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;Schools ==&lt;br /&gt;
* [[ICTP2020]]&lt;br /&gt;
* [[CECAM VIRTUAL 2021]]&lt;br /&gt;
* [https://www.yambo-code.org/wiki/index.php?title=ICTP_2022 ICTP2022]&lt;br /&gt;
--&amp;gt;&lt;/div&gt;</summary>
		<author><name>Fulvio</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Second-harmonic_generation_of_2D-hBN&amp;diff=7033</id>
		<title>Second-harmonic generation of 2D-hBN</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Second-harmonic_generation_of_2D-hBN&amp;diff=7033"/>
		<updated>2023-05-25T14:23:14Z</updated>

		<summary type="html">&lt;p&gt;Fulvio: /* Run the simulation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Step 0: Theoretical framework =&lt;br /&gt;
&lt;br /&gt;
In this tutorial, we compute the Second-harmonic generation (SHG) from the dynamics of the Bloch-states. The equation-of-motion of the Bloch-states is explained in the tutorial on [[Linear response from Bloch-states dynamics]]. Independently of the &#039;experiment&#039; we simulate, the part of the integration of motion stays the same. This means that any experiment, including non-linear optics, can be performed at the level of the theory listed for the computation of the dielectric function:&lt;br /&gt;
* independent (quasi)particle&lt;br /&gt;
* time-dependent Hartree (RPA level)&lt;br /&gt;
* time-dependent DFT (and DPFT)&lt;br /&gt;
* time-dependent Hartree+Screened exchange (BSE level)&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
What changes when we want to calculate the SHG (or higher harmonics) is:&lt;br /&gt;
* the time-dependence of the input electric field and&lt;br /&gt;
* the post-processing of the signal  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Time dependence of the electric Field&#039;&#039;&#039;: we choose a sinusoidal electric field, thus a monochromatic laser field. This allows one to expand the polarization in the form &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; through a coefficient depending on a power of the strength of the field (with the power depending on the order of the response).&lt;br /&gt;
&lt;br /&gt;
At difference with a delta-like perturbation, a real-time simulation gives the response at the laser-field only. Then, to obtain the spectrum for the desired range of frequency, we have to perform so many simulations as the frequencies in the desired range.  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Post-processing of the signal&#039;&#039;&#039;: The switch-on of the electric field corresponds to a weak delta-like kick. Thus, even if it may not be noticeable, the polarization results from both the sinusoidal field and the delta-like kick. The latter excites all eigenfrequencies of the system. Though weak, the resulting signal is comparable with the second-harmonic signal. To eliminate the signal from the eigenfrequencies, we apply a dephasing (&amp;lt;math&amp;gt;\gamma_{deph}&amp;lt;/math&amp;gt;). To have a signal useful to sample the second-harmonic signal, we need to wait a time &amp;lt;math&amp;gt;\bar t&amp;lt;/math&amp;gt;  much larger than the dephasing-time &amp;lt;math&amp;gt;1/\gamma_{deph} &amp;lt;/math&amp;gt;. Note that we cannot choose a too short dephasing time (to shorten the simulation time), as this would result in a too large broadening of the spectrum. After &amp;lt;math&amp;gt;\bar t&amp;lt;/math&amp;gt;, we sample 2N+1 times in a period and use discrete Fourier transform to extract &amp;lt;math&amp;gt;{p}_n&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt; n = 0,...,N&amp;lt;/math&amp;gt;, where n=2 gives the SHG. This is schematically illustrated in figure:&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;
The scheme from Ref. &amp;lt;ref name=&amp;quot;Attaccalite2013&amp;quot;&amp;gt;C. Attaccalite and M. Gruning [https://arxiv.org/abs/1309.4012v2 Phys. Rev. B, &#039;&#039;&#039;88&#039;&#039;&#039;, 235113 (2013)]&amp;lt;/ref&amp;gt; summarised the workflow for computing the SHG (or higher-harmonics) in a energy range &amp;lt;math&amp;gt;[\Omega_1,\Omega_2]&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
[[File:Scheme nl.png|350px|center|Schematic representation of real-time calculations]]&lt;br /&gt;
&lt;br /&gt;
= Step 1: Prerequisites =&lt;br /&gt;
You should be in the folder &amp;lt;code&amp;gt;YAMBO_TUTORIALS/hBN-2D/YAMBO/&amp;lt;/code&amp;gt;.&lt;br /&gt;
In this example, we will consider a single layer of hexagonal boron nitride (hBN). &lt;br /&gt;
Execute the commands (remember to ad -nompi if you run on marconi100)&lt;br /&gt;
 yambo_nl&lt;br /&gt;
 ypp_nl -fixsym -F 00_removesym.in  &lt;br /&gt;
to create the input, to remove the symmetries which are not compatible with the field: &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;1.000000 | 1.000000 | 0.000000 |&amp;lt;/span&amp;gt;        # First external Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 % Efield2&lt;br /&gt;
  0.000000 | 0.000000 | 0.000000 |        # 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;
 #KeepKGrid                     # Do not expand the k-grid&lt;br /&gt;
where we chose the field along the xy direction and we remove time-reversal symmetry.&lt;br /&gt;
&lt;br /&gt;
Then run the pre-processing job:&lt;br /&gt;
 ypp_nl -F 00_removesym.in&lt;br /&gt;
This creates the directory &amp;lt;code&amp;gt;FixSymm&amp;lt;/code&amp;gt;. Change directory to &amp;lt;code&amp;gt;FixSymm&amp;lt;/code&amp;gt;. This contains the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory with reduced symmetries, compatible with the direction of the field. Now run the setup again (&amp;lt;code&amp;gt;yambo_nl -nompi&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
= Step 2: Independent-particle approximation =&lt;br /&gt;
&lt;br /&gt;
Use the command:&lt;br /&gt;
  cd FixSymm&lt;br /&gt;
  yambo_nl&lt;br /&gt;
  yambo_nl -nl n -F 01_SHG_ip.in&lt;br /&gt;
to generate the input:&lt;br /&gt;
&lt;br /&gt;
 nloptics                         # [R] Non-linear spectroscopy&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=-1.000000           fs    # [NL] Simulation Time&lt;br /&gt;
 NLintegrator= &amp;quot;INVINT&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;
 % NLEnRange&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;0.5000000 |8.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;12&amp;lt;/span&amp;gt;                     # [NL] Energy steps&lt;br /&gt;
 NLDamping= 0.200000        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= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;1000            mHa&amp;lt;/span&amp;gt;   # [HA] Hartree     RL components&lt;br /&gt;
 EXXRLvcs= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;1000            mHa&amp;lt;/span&amp;gt;    # [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;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&amp;quot;SIN&amp;quot; &amp;lt;/span&amp;gt;          # [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 | 1.000000 | 0.000000 |&amp;lt;/span&amp;gt;        # [RT Field1] Versor&lt;br /&gt;
 %&lt;br /&gt;
 Field1_Tstart= 0.010000    fs    # [RT Field1] Initial Time&lt;br /&gt;
&lt;br /&gt;
To describe the Bloch-dynamics we will use as a basis the KS-states 3-6 for the k-grid used in the non-scf DFT calculations, that is a 6x6x1 (&amp;lt;code&amp;gt;NLBands&amp;lt;/code&amp;gt;). We choose 12 equally spaced frequencies (&amp;lt;code&amp;gt;NLEnSteps&amp;lt;/code&amp;gt;) for the applied field in the range  (&amp;lt;code&amp;gt;NLEnRange&amp;lt;/code&amp;gt;) between 0.5 and 8 eV. We choose a sinusoidal time-dependence (&amp;lt;code&amp;gt;Field1_kind&amp;lt;/code&amp;gt;) and set the field direction (&amp;lt;code&amp;gt;Field1_kind&amp;lt;/code&amp;gt;) along xy (in plane). The negative simulation time (&amp;lt;code&amp;gt;NLtime=-1.000000&amp;lt;/code&amp;gt;) means that the code will choose it based on the value of the &amp;lt;code&amp;gt;NLDamping&amp;lt;/code&amp;gt;. While this is a good lower bound for the simulation time, one should check it is sufficient to get accurate results. &lt;br /&gt;
&lt;br /&gt;
Run the simulation, possibly in parallel e. g. in a interactive session on 4 cores. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;[In order to get 4 cores while in an interacting node, exit your current allocation and rerun &amp;lt;code&amp;gt;salloc&amp;lt;/code&amp;gt; asking for the proper number of tasks:&#039;&#039;&#039;&lt;br /&gt;
 salloc -A tra23_Yambo -p m100_usr_prod -q m100_qos_dbg --nodes=1 --ntasks-per-node=&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;4&amp;lt;/span&amp;gt; --cpus-per-task=4 -t 02:00:00&lt;br /&gt;
&#039;&#039;&#039;Otherwise, you can submit the job with a slurm script as explained in the introductory page]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now execute the command:&lt;br /&gt;
  mpirun -n 4 yambo_nl -F 01_SHG_ip.in -J 01_SHG_ip -C 01_SHG_ip_files&lt;br /&gt;
&lt;br /&gt;
This run will take several minutes. While it is running, you can check the progress of one specific frequency:&lt;br /&gt;
 tail -f 01_SHG_ip_files/o-01_SHG_ip.polarization_F2&lt;br /&gt;
If you want to know how many fs the simulation will last (since this was decided by the code), you can get this information in the report file:&lt;br /&gt;
 $ grep Total 01_SHG_ip_files/r-01_SHG_ip_nloptics&lt;br /&gt;
 Total simulation time       :  41.23193 [fs]&lt;br /&gt;
If you instead want to track the progress of the full simulation, you should check the log file(s). If you are doing a parallel run, you can type&lt;br /&gt;
 tail -f 01_SHG_ip_files/LOG/l-01_SHG_ip_nloptics_CPU_1&lt;br /&gt;
&lt;br /&gt;
Once the run is finished, check the report &amp;lt;code&amp;gt;01_SHG_ip_files/r-01_SHG_ip_nloptics&amp;lt;/code&amp;gt;. In particular, in the appended input files, you can see the default parallelization applied by the code for calculating the dipoles and run the time-propagation. For the latter, the main parallelization is on the frequencies and then on the k-points (&amp;lt;code&amp;gt;NL_ROLEs= &amp;quot;w.k&amp;quot;&amp;lt;/code&amp;gt;).   &lt;br /&gt;
&lt;br /&gt;
 | NL_CPU= &amp;quot;2.2&amp;quot;                    # [PARALLEL] CPUs for each role&lt;br /&gt;
 | NL_ROLEs= &amp;quot;w.k&amp;quot;                  # [PARALLEL] CPUs roles (w,k)&lt;br /&gt;
 | DIP_CPU= &amp;quot;2.2.1&amp;quot;                 # [PARALLEL] CPUs for each role&lt;br /&gt;
 | DIP_ROLEs= &amp;quot;v.c.k&amp;quot;               # [PARALLEL] CPUs roles (k,c,v)&lt;br /&gt;
&lt;br /&gt;
Also, look at the simulation time. This is approximately 42 fs. &lt;br /&gt;
&lt;br /&gt;
Plot the polarization for a couple of frequencies, e.g. the first and last of the chosen range (the corresponding frequency can be read in the file, search for &amp;quot;Frequency value&amp;quot;):&lt;br /&gt;
 set ylabel &amp;quot;x-component polarization&amp;quot; offset -0.7&lt;br /&gt;
 set xlabel &amp;quot;time (fs)&amp;quot;&lt;br /&gt;
 plot &#039;01_SHG_ip_files/o-01_SHG_ip.polarization_F1&#039; u 1:2 w l lw 2 title &amp;quot;omega = 0.5 eV&amp;quot;&lt;br /&gt;
 replot &#039;01_SHG_ip_files/o-01_SHG_ip.polarization_F12&#039; u 1:2 w l lw 2  title &amp;quot;omega = 7.375 eV&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[File:Berry_phase_polarization_of_2D_h-BN_obtained_from_the_previous_run_for_two_laser_frequencies.png|Berry_phase_polarization_of_2D_h-BN_obtained from the run for two laser frequencies]]&lt;br /&gt;
&lt;br /&gt;
After the applied field is &#039;switched on&#039;, the polarization is oscillating at the frequency of the applied field and at the eigenfrequencies of the system as described above in the cartoon. This is visible particularly for the higher frequency. Due to the dephasing, after about 20 fs the polarization is oscillating (at least to the eye) at the frequency of the applied field. Nonlinear components are not visible since they are several orders of magnitude smaller than the first order.&lt;br /&gt;
&lt;br /&gt;
== Output post-processing: the dielectric function ==&lt;br /&gt;
&lt;br /&gt;
Once we obtained the polarization, we Fourier-transform the polarization to obtain the dielectric function.&lt;br /&gt;
&lt;br /&gt;
Use the command:&lt;br /&gt;
&lt;br /&gt;
  ypp_nl -nl -F 02_SHG_ip_pp.in -C 01_SHG_ip_files&lt;br /&gt;
&lt;br /&gt;
to generate the input file: &lt;br /&gt;
&lt;br /&gt;
 nonlinear                        # [R] Non-linear response analysis&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;Xorder= 4&amp;lt;/span&amp;gt; # 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;NONE&amp;quot;                 # Damping type ( NONE | LORENTZIAN | GAUSSIAN )&lt;br /&gt;
 DampFactor= 0.000000       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;
Where we changed the &amp;lt;code&amp;gt;Xorder&amp;lt;/code&amp;gt; to 4. This variable controls the terms in the Fourier expansion of the polarization. We choose up to expand up to the fourth order. This should ensure the second order to be accurate enough. As an exercise, you can change this value (e.g. choose 2,3,5,6) and see how the result below is changing. The time-window where processing is done is chosen automatically, since values are negative. The code chooses by default the last period to carry out the analysis. &lt;br /&gt;
&lt;br /&gt;
To run the post-processing, use the command:&lt;br /&gt;
 ypp_nl -F 02_SHG_ip_pp.in -J 01_SHG_ip -C 01_SHG_ip_files&lt;br /&gt;
   &lt;br /&gt;
In  &amp;lt;code&amp;gt;01_SHG_ip_files&amp;lt;/code&amp;gt; the following files were generated &lt;br /&gt;
 o-01_SHG_ip.YPP-X_probe_order_1&lt;br /&gt;
 o-01_SHG_ip.YPP-X_probe_order_2&lt;br /&gt;
 o-01_SHG_ip.YPP-X_probe_order_3&lt;br /&gt;
 o-01_SHG_ip.YPP-X_probe_order_4&lt;br /&gt;
 r-01_SHG_ip_nonlinear&lt;br /&gt;
&lt;br /&gt;
The output files contain respectively the first, second, third and fourth order response(corresponding to &amp;lt;code&amp;gt;Xorder=4&amp;lt;/code&amp;gt;)  at the 12 frequencies in the chosen range. &lt;br /&gt;
 &lt;br /&gt;
Inspect &amp;lt;code&amp;gt;o-01_SHG_ip.YPP-X_probe_order_2&amp;lt;/code&amp;gt;&lt;br /&gt;
 #     E [eV]            X/Im[cm/stV](x)    X/Re[cm/stV](x)    X/Im[cm/stV](y)    X/Re[cm/stV](y)    X/Im[cm/stV](z)    X/Re[cm/stV](z)&lt;br /&gt;
 #&lt;br /&gt;
      0.50000000        -0.35378838E-09    -0.19774796E-07     0.23591828E-09    -0.89405637E-09      0.0000000          0.0000000    &lt;br /&gt;
      1.1250000         -0.19356524E-08    -0.23160605E-07    -0.16052184E-09    -0.67662771E-09      0.0000000          0.0000000    &lt;br /&gt;
      1.7500000         -0.69446459E-08    -0.35586956E-07    -0.76025706E-09    -0.10205678E-08      0.0000000          0.0000000    &lt;br /&gt;
      2.37500000        -0.181606152E-7    -0.261823658E-8     0.438358596E-8     0.407915226E-8      0.00000000         0.00000000   &lt;br /&gt;
&lt;br /&gt;
The first column are the frequencies of the applied field, the second and third is the polarization along x (imaginary and real part), the fourth and fifth is the polarization along y (imaginary and real part)  &lt;br /&gt;
and the sixth and seventh is the polarization along z (imaginary and real part).&lt;br /&gt;
&lt;br /&gt;
Plot the absolute value of the SHG for the &amp;quot;xxy&amp;quot; component (that is, the applied field is in the x and y directions and one look at the polarization along x):&lt;br /&gt;
&lt;br /&gt;
 set ylabel &amp;quot;{/Symbol=26 \174}{/Symbol=26 c}_{xyx}^{(2)}{/Symbol=26 \174} (pm/V)&amp;quot; offset -0.7&lt;br /&gt;
 set xlabel &amp;quot;Energy (eV)&amp;quot;&lt;br /&gt;
 pmVm1toCGS=2.38721e-09&lt;br /&gt;
 plot &#039;01_SHG_ip_files/o-01_SHG_ip.YPP-X_probe_order_2&#039; u 1:(sqrt($2**2+$3**2)/pmVm1toCGS) w p title &amp;quot;calc&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[File: SHG_intensity_of_2D_h-BN_obtained_from_the_previous_run_(and_compared_with_a_run_on_112_frequencies).png | SHG_intensity_of_2D_h-BN obtained from the current run (12 frequencies) compared with a run with 112 frequencies]] &lt;br /&gt;
&lt;br /&gt;
In the figure above, the results of the current run are compared with those for a run with 112 frequencies (one can obtain these results by repeating the calculations, changing the number of frequencies in &amp;lt;code&amp;gt;NLEnSteps&amp;lt;/code&amp;gt; though this take about 10 times more computational time than the run with 12). One can notice some differences between the two runs. In fact, the two runs evaluate different frequnecies and the difference indicates spurious oscillations of the value of the polarizability due to the simulation time being too short and thus to the presence of &#039;noise&#039; due to the eigenfrecies.  &lt;br /&gt;
As an exercise, you can repeat the simulation for e,g, a time of &amp;lt;code&amp;gt;60 fs&amp;lt;/code&amp;gt;, that is setting &amp;lt;code&amp;gt;NLtime=60&amp;lt;/code&amp;gt;. The plot below compare the SHG extracted at 42 fs and 60 fs, where the latter gives clearly more accurate results. &lt;br /&gt;
&lt;br /&gt;
[[File:Comparison of the SHG intensity of 2D h-BN obtained with different simulation time.png|Comparison of the SHG intensity of 2D h-BN obtained with different simulation time]]&lt;br /&gt;
&lt;br /&gt;
As a final note, the SHG depends on the size of the vacuum added in the supercell. Instead, one should consider the surface SHG which obtained by considering an effective thickness for the layer. This is usually chosen to be similar to the layer separation in the bulk counterpart.&lt;br /&gt;
&lt;br /&gt;
= Step 3: Hartree+Screened exchange approximation (BSE level) =&lt;br /&gt;
&lt;br /&gt;
== Hartree+Screened exchange collisions ==&lt;br /&gt;
Similarly to the linear part, one needs to generate the Screened exchange collisions. The procedure is exactly the same.&lt;br /&gt;
&lt;br /&gt;
Create the input:&lt;br /&gt;
 yambo_nl -X s -e -v hsex -F 03_coll_hsex.in&lt;br /&gt;
modify the input ad follows&lt;br /&gt;
 em1s                             # [R][Xs] Statically Screened Interaction&lt;br /&gt;
 collisions                       # [R] Collisions&lt;br /&gt;
 dipoles                          # [R] Oscillator strenghts (or dipoles)&lt;br /&gt;
 Chimod= &amp;quot;HARTREE&amp;quot;                # [X] IP/Hartree/ALDA/LRC/PF/BSfxc&lt;br /&gt;
 % BndsRnXs&lt;br /&gt;
    1 |  20 |                         # [Xs] Polarization function bands&lt;br /&gt;
 %&lt;br /&gt;
 NGsBlkXs= 1000 mHa    # [Xs] Response block size&lt;br /&gt;
 % LongDrXs&lt;br /&gt;
  1.000000 | 1.000000 | 0.000000 |        # [Xs] [cc] Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 % COLLBands&lt;br /&gt;
    4 |  5 |                         # [COLL] Bands for the collisions&lt;br /&gt;
 %&lt;br /&gt;
 HXC_Potential= &amp;quot;SEX+HARTREE&amp;quot;     # [SC] SC HXC Potential&lt;br /&gt;
 HARRLvcs= 1000 mHa    # [HA] Hartree     RL components&lt;br /&gt;
 EXXRLvcs= 1000 mHa    # [XX] Exchange    RL components&lt;br /&gt;
 CORRLvcs= 1000 mHa    # [GW] Correlation RL components&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Calculate the collisions (you may want to run in parallel):&lt;br /&gt;
 yambo_nl -F 03_coll_hsex.in -J 03_coll -C 04_hsex_files&lt;br /&gt;
&lt;br /&gt;
== Run the simulation ==&lt;br /&gt;
&lt;br /&gt;
Create the input:&lt;br /&gt;
 yambo_nl -nl n -v hsex -V qp -F 04_SHG_hsex.in&lt;br /&gt;
&lt;br /&gt;
modify the following parts of the input (by this time all the innput variables should be known from the previous exercises):&lt;br /&gt;
&lt;br /&gt;
 % BndsRnXs&lt;br /&gt;
   1 |  20 |                         # [Xs] Polarization function bands&lt;br /&gt;
 %&lt;br /&gt;
 NGsBlkXs= 1000 mHa    # [Xs] Response block size&lt;br /&gt;
 % LongDrXs&lt;br /&gt;
  1.000000 | 1.000000 | 0.000000 |        # [Xs] [cc] Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 % NLBands&lt;br /&gt;
    4 |  5 |                         # [NL] Bands range&lt;br /&gt;
 %&lt;br /&gt;
&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;SEX&amp;quot;             # [NL] Correlation (&amp;quot;IPA/HARTREE/TDDFT/LRC/LRW/JGM/SEX&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 % NLEnRange&lt;br /&gt;
  0.500000 |8.000000 |         eV    # [NL] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 NLEnSteps= 12                   # [NL] Energy steps&lt;br /&gt;
&lt;br /&gt;
 % GfnQP_E&lt;br /&gt;
  3.000000 | 1.000000 | 1.000000 |        # [EXTQP G] E parameters  (c/v) eV|adim|adim&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
 Field1_kind= &amp;quot;SIN&amp;quot;           # [RT Field1] Kind(SIN|COS|RES|ANTIRES|GAUSS|DELTA|QSSIN)&lt;br /&gt;
&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
  1.000000 | 1.000000 | 0.000000 |        # [RT Field1] Versor&lt;br /&gt;
 %&lt;br /&gt;
 HARRLvcs= 1000            mHa    # [HA] Hartree     RL components&lt;br /&gt;
 EXXRLvcs= 1000            mHa    # [XX] Exchange    RL components&lt;br /&gt;
&lt;br /&gt;
Then run the simulation using e.g. mpi and 4 cores:&lt;br /&gt;
 mpirun -n 4 yambo_nl -F 04_SHG_hsex.in -J 04_SHG_hsex,03_coll -C 04_SHG_hsex_files&lt;br /&gt;
&lt;br /&gt;
== Postprocessing: obtain the nonlinear response ==&lt;br /&gt;
&lt;br /&gt;
Similarly to what we did for the independent particle case, we create the input:&lt;br /&gt;
 ypp_nl -nl -F 05_SHG_hsex_pp.in&lt;br /&gt;
 &lt;br /&gt;
we change &amp;lt;code&amp;gt;Xorder = 4 &amp;lt;/code&amp;gt; and then run:&lt;br /&gt;
 ypp_nl -F 05_SHG_hsex_pp.in -J 04_SHG_hsex -C 04_hsex_files&lt;br /&gt;
&lt;br /&gt;
Then we plot (as before we compare with a simulation ran for 112 frequencies).&lt;br /&gt;
&lt;br /&gt;
Plot the results:&lt;br /&gt;
&lt;br /&gt;
 set ylabel &amp;quot;{/Symbol=26 \174}{/Symbol=26 c}_{xyx}^{(2)}{/Symbol=26 \174} (pm/V)&amp;quot; offset -0.7&lt;br /&gt;
 set xlabel &amp;quot;Energy (eV)&amp;quot;&lt;br /&gt;
 pmVm1toCGS=2.38721e-09&lt;br /&gt;
 plot &#039;04_hsex_files/o-04_SHG_hsex.YPP-X_probe_order_2&#039; u 1:(sqrt($2**2+$3**2)/pmVm1toCGS) w p title &amp;quot;calc&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[File:SHG hsex.png|SHG at the Hartree + Screened exchange from the current run with 12 frequencies (crosses) and a run with 112 frequencies (keeping the other parameters the same)]]&lt;br /&gt;
&lt;br /&gt;
Also in this case, we note differences between the two simulations. As discussed for the independent particle approximation, this is due to the too short simulation time. Repeating the calculations with a longer time gives more accurate results. &lt;br /&gt;
In addition, note that in the interest of time, all parameters are under converged. In principle, to calculate the collisions one should use the same parameters of a converged BSE calculation. As well, to eliminate spurious interaction with the periodic images, one should use the Coulomb cut-off as it was used for this system in the [[Quasi-particles of a 2D system| tutorial on quasiparticle calculations]]. As a reference, a converged calculation for this system is in &amp;lt;ref name=&amp;quot;Gruning2014&amp;quot;&amp;gt;M. Grüning and C. Attaccalite, [https://journals.aps.org/prb/abstract/10.1103/PhysRevB.89.081102 Phys. Rev. B &#039;&#039;&#039;89&#039;&#039;&#039;, 081102]&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
= References = &lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Fulvio</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Second-harmonic_generation_of_2D-hBN&amp;diff=7029</id>
		<title>Second-harmonic generation of 2D-hBN</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Second-harmonic_generation_of_2D-hBN&amp;diff=7029"/>
		<updated>2023-05-25T13:31:44Z</updated>

		<summary type="html">&lt;p&gt;Fulvio: /* Output post-processing: the dielectric function */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Step 0: Theoretical framework =&lt;br /&gt;
&lt;br /&gt;
In this tutorial, we compute the Second-harmonic generation (SHG) from the dynamics of the Bloch-states. The equation-of-motion of the Bloch-states is explained in the tutorial on [[Linear response from Bloch-states dynamics]]. Independently of the &#039;experiment&#039; we simulate, the part of the integration of motion stays the same. This means that any experiment, including non-linear optics, can be performed at the level of the theory listed for the computation of the dielectric function:&lt;br /&gt;
* independent (quasi)particle&lt;br /&gt;
* time-dependent Hartree (RPA level)&lt;br /&gt;
* time-dependent DFT (and DPFT)&lt;br /&gt;
* time-dependent Hartree+Screened exchange (BSE level)&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
What changes when we want to calculate the SHG (or higher harmonics) is:&lt;br /&gt;
* the time-dependence of the input electric field and&lt;br /&gt;
* the post-processing of the signal  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Time dependence of the electric Field&#039;&#039;&#039;: we choose a sinusoidal electric field, thus a monochromatic laser field. This allows one to expand the polarization in the form &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; through a coefficient depending on a power of the strength of the field (with the power depending on the order of the response).&lt;br /&gt;
&lt;br /&gt;
At difference with a delta-like perturbation, a real-time simulation gives the response at the laser-field only. Then, to obtain the spectrum for the desired range of frequency, we have to perform so many simulations as the frequencies in the desired range.  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Post-processing of the signal&#039;&#039;&#039;: The switch-on of the electric field corresponds to a weak delta-like kick. Thus, even if it may not be noticeable, the polarization results from both the sinusoidal field and the delta-like kick. The latter excites all eigenfrequencies of the system. Though weak, the resulting signal is comparable with the second-harmonic signal. To eliminate the signal from the eigenfrequencies, we apply a dephasing (&amp;lt;math&amp;gt;\gamma_{deph}&amp;lt;/math&amp;gt;). To have a signal useful to sample the second-harmonic signal, we need to wait a time &amp;lt;math&amp;gt;\bar t&amp;lt;/math&amp;gt;  much larger than the dephasing-time &amp;lt;math&amp;gt;1/\gamma_{deph} &amp;lt;/math&amp;gt;. Note that we cannot choose a too short dephasing time (to shorten the simulation time), as this would result in a too large broadening of the spectrum. After &amp;lt;math&amp;gt;\bar t&amp;lt;/math&amp;gt;, we sample 2N+1 times in a period and use discrete Fourier transform to extract &amp;lt;math&amp;gt;{p}_n&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt; n = 0,...,N&amp;lt;/math&amp;gt;, where n=2 gives the SHG. This is schematically illustrated in figure:&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;
The scheme from Ref. &amp;lt;ref name=&amp;quot;Attaccalite2013&amp;quot;&amp;gt;C. Attaccalite and M. Gruning [https://arxiv.org/abs/1309.4012v2 Phys. Rev. B, &#039;&#039;&#039;88&#039;&#039;&#039;, 235113 (2013)]&amp;lt;/ref&amp;gt; summarised the workflow for computing the SHG (or higher-harmonics) in a energy range &amp;lt;math&amp;gt;[\Omega_1,\Omega_2]&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
[[File:Scheme nl.png|350px|center|Schematic representation of real-time calculations]]&lt;br /&gt;
&lt;br /&gt;
= Step 1: Prerequisites =&lt;br /&gt;
You should be in the folder &amp;lt;code&amp;gt;YAMBO_TUTORIALS/hBN-2D/YAMBO/&amp;lt;/code&amp;gt;.&lt;br /&gt;
In this example, we will consider a single layer of hexagonal boron nitride (hBN). &lt;br /&gt;
Execute the commands (remember to ad -nompi if you run on marconi100)&lt;br /&gt;
 yambo_nl&lt;br /&gt;
 ypp_nl -fixsym -F 00_removesym.in  &lt;br /&gt;
to create the input, to remove the symmetries which are not compatible with the field: &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;1.000000 | 1.000000 | 0.000000 |&amp;lt;/span&amp;gt;        # First external Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 % Efield2&lt;br /&gt;
  0.000000 | 0.000000 | 0.000000 |        # 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;
 #KeepKGrid                     # Do not expand the k-grid&lt;br /&gt;
where we chose the field along the xy direction and we remove time-reversal symmetry.&lt;br /&gt;
&lt;br /&gt;
Then run the pre-processing job:&lt;br /&gt;
 ypp_nl -F 00_removesym.in&lt;br /&gt;
This creates the directory &amp;lt;code&amp;gt;FixSymm&amp;lt;/code&amp;gt;. Change directory to &amp;lt;code&amp;gt;FixSymm&amp;lt;/code&amp;gt;. This contains the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory with reduced symmetries, compatible with the direction of the field. Now run the setup again (&amp;lt;code&amp;gt;yambo_nl -nompi&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
= Step 2: Independent-particle approximation =&lt;br /&gt;
&lt;br /&gt;
Use the command:&lt;br /&gt;
  cd FixSymm&lt;br /&gt;
  yambo_nl&lt;br /&gt;
  yambo_nl -nl n -F 01_SHG_ip.in&lt;br /&gt;
to generate the input:&lt;br /&gt;
&lt;br /&gt;
 nloptics                         # [R] Non-linear spectroscopy&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=-1.000000           fs    # [NL] Simulation Time&lt;br /&gt;
 NLintegrator= &amp;quot;INVINT&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;
 % NLEnRange&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;0.5000000 |8.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;12&amp;lt;/span&amp;gt;                     # [NL] Energy steps&lt;br /&gt;
 NLDamping= 0.200000        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= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;1000            mHa&amp;lt;/span&amp;gt;   # [HA] Hartree     RL components&lt;br /&gt;
 EXXRLvcs= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;1000            mHa&amp;lt;/span&amp;gt;    # [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;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&amp;quot;SIN&amp;quot; &amp;lt;/span&amp;gt;          # [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 | 1.000000 | 0.000000 |&amp;lt;/span&amp;gt;        # [RT Field1] Versor&lt;br /&gt;
 %&lt;br /&gt;
 Field1_Tstart= 0.010000    fs    # [RT Field1] Initial Time&lt;br /&gt;
&lt;br /&gt;
To describe the Bloch-dynamics we will use as a basis the KS-states 3-6 for the k-grid used in the non-scf DFT calculations, that is a 6x6x1 (&amp;lt;code&amp;gt;NLBands&amp;lt;/code&amp;gt;). We choose 12 equally spaced frequencies (&amp;lt;code&amp;gt;NLEnSteps&amp;lt;/code&amp;gt;) for the applied field in the range  (&amp;lt;code&amp;gt;NLEnRange&amp;lt;/code&amp;gt;) between 0.5 and 8 eV. We choose a sinusoidal time-dependence (&amp;lt;code&amp;gt;Field1_kind&amp;lt;/code&amp;gt;) and set the field direction (&amp;lt;code&amp;gt;Field1_kind&amp;lt;/code&amp;gt;) along xy (in plane). The negative simulation time (&amp;lt;code&amp;gt;NLtime=-1.000000&amp;lt;/code&amp;gt;) means that the code will choose it based on the value of the &amp;lt;code&amp;gt;NLDamping&amp;lt;/code&amp;gt;. While this is a good lower bound for the simulation time, one should check it is sufficient to get accurate results. &lt;br /&gt;
&lt;br /&gt;
Run the simulation, possibly in parallel e. g. in a interactive session on 4 cores. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;[In order to get 4 cores while in an interacting node, exit your current allocation and rerun &amp;lt;code&amp;gt;salloc&amp;lt;/code&amp;gt; asking for the proper number of tasks:&#039;&#039;&#039;&lt;br /&gt;
 salloc -A tra23_Yambo -p m100_usr_prod -q m100_qos_dbg --nodes=1 --ntasks-per-node=&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;4&amp;lt;/span&amp;gt; --cpus-per-task=4 -t 02:00:00&lt;br /&gt;
&#039;&#039;&#039;Otherwise, you can submit the job with a slurm script as explained in the introductory page]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now execute the command:&lt;br /&gt;
  mpirun -n 4 yambo_nl -F 01_SHG_ip.in -J 01_SHG_ip -C 01_SHG_ip_files&lt;br /&gt;
&lt;br /&gt;
This run will take several minutes. While it is running, you can check the progress of one specific frequency:&lt;br /&gt;
 tail -f 01_SHG_ip_files/o-01_SHG_ip.polarization_F2&lt;br /&gt;
If you want to know how many fs the simulation will last (since this was decided by the code), you can get this information in the report file:&lt;br /&gt;
 $ grep Total 01_SHG_ip_files/r-01_SHG_ip_nloptics&lt;br /&gt;
 Total simulation time       :  41.23193 [fs]&lt;br /&gt;
If you instead want to track the progress of the full simulation, you should check the log file(s). If you are doing a parallel run, you can type&lt;br /&gt;
 tail -f 01_SHG_ip_files/LOG/l-01_SHG_ip_nloptics_CPU_1&lt;br /&gt;
&lt;br /&gt;
Once the run is finished, check the report &amp;lt;code&amp;gt;01_SHG_ip_files/r-01_SHG_ip_nloptics&amp;lt;/code&amp;gt;. In particular, in the appended input files, you can see the default parallelization applied by the code for calculating the dipoles and run the time-propagation. For the latter, the main parallelization is on the frequencies and then on the k-points (&amp;lt;code&amp;gt;NL_ROLEs= &amp;quot;w.k&amp;quot;&amp;lt;/code&amp;gt;).   &lt;br /&gt;
&lt;br /&gt;
 | NL_CPU= &amp;quot;2.2&amp;quot;                    # [PARALLEL] CPUs for each role&lt;br /&gt;
 | NL_ROLEs= &amp;quot;w.k&amp;quot;                  # [PARALLEL] CPUs roles (w,k)&lt;br /&gt;
 | DIP_CPU= &amp;quot;2.2.1&amp;quot;                 # [PARALLEL] CPUs for each role&lt;br /&gt;
 | DIP_ROLEs= &amp;quot;v.c.k&amp;quot;               # [PARALLEL] CPUs roles (k,c,v)&lt;br /&gt;
&lt;br /&gt;
Also, look at the simulation time. This is approximately 42 fs. &lt;br /&gt;
&lt;br /&gt;
Plot the polarization for a couple of frequencies, e.g. the first and last of the chosen range (the corresponding frequency can be read in the file, search for &amp;quot;Frequency value&amp;quot;):&lt;br /&gt;
 set ylabel &amp;quot;x-component polarization&amp;quot; offset -0.7&lt;br /&gt;
 set xlabel &amp;quot;time (fs)&amp;quot;&lt;br /&gt;
 plot &#039;01_SHG_ip_files/o-01_SHG_ip.polarization_F1&#039; u 1:2 w l lw 2 title &amp;quot;omega = 0.5 eV&amp;quot;&lt;br /&gt;
 replot &#039;01_SHG_ip_files/o-01_SHG_ip.polarization_F12&#039; u 1:2 w l lw 2  title &amp;quot;omega = 7.375 eV&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[File:Berry_phase_polarization_of_2D_h-BN_obtained_from_the_previous_run_for_two_laser_frequencies.png|Berry_phase_polarization_of_2D_h-BN_obtained from the run for two laser frequencies]]&lt;br /&gt;
&lt;br /&gt;
After the applied field is &#039;switched on&#039;, the polarization is oscillating at the frequency of the applied field and at the eigenfrequencies of the system as described above in the cartoon. This is visible particularly for the higher frequency. Due to the dephasing, after about 20 fs the polarization is oscillating (at least to the eye) at the frequency of the applied field. Nonlinear components are not visible since they are several orders of magnitude smaller than the first order.&lt;br /&gt;
&lt;br /&gt;
== Output post-processing: the dielectric function ==&lt;br /&gt;
&lt;br /&gt;
Once we obtained the polarization, we Fourier-transform the polarization to obtain the dielectric function.&lt;br /&gt;
&lt;br /&gt;
Use the command:&lt;br /&gt;
&lt;br /&gt;
  ypp_nl -nl -F 02_SHG_ip_pp.in -C 01_SHG_ip_files&lt;br /&gt;
&lt;br /&gt;
to generate the input file: &lt;br /&gt;
&lt;br /&gt;
 nonlinear                        # [R] Non-linear response analysis&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;Xorder= 4&amp;lt;/span&amp;gt; # 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;NONE&amp;quot;                 # Damping type ( NONE | LORENTZIAN | GAUSSIAN )&lt;br /&gt;
 DampFactor= 0.000000       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;
Where we changed the &amp;lt;code&amp;gt;Xorder&amp;lt;/code&amp;gt; to 4. This variable controls the terms in the Fourier expansion of the polarization. We choose up to expand up to the fourth order. This should ensure the second order to be accurate enough. As an exercise, you can change this value (e.g. choose 2,3,5,6) and see how the result below is changing. The time-window where processing is done is chosen automatically, since values are negative. The code chooses by default the last period to carry out the analysis. &lt;br /&gt;
&lt;br /&gt;
To run the post-processing, use the command:&lt;br /&gt;
 ypp_nl -F 02_SHG_ip_pp.in -J 01_SHG_ip -C 01_SHG_ip_files&lt;br /&gt;
   &lt;br /&gt;
In  &amp;lt;code&amp;gt;01_SHG_ip_files&amp;lt;/code&amp;gt; the following files were generated &lt;br /&gt;
 o-01_SHG_ip.YPP-X_probe_order_1&lt;br /&gt;
 o-01_SHG_ip.YPP-X_probe_order_2&lt;br /&gt;
 o-01_SHG_ip.YPP-X_probe_order_3&lt;br /&gt;
 o-01_SHG_ip.YPP-X_probe_order_4&lt;br /&gt;
 r-01_SHG_ip_nonlinear&lt;br /&gt;
&lt;br /&gt;
The output files contain respectively the first, second, third and fourth order response(corresponding to &amp;lt;code&amp;gt;Xorder=4&amp;lt;/code&amp;gt;)  at the 12 frequencies in the chosen range. &lt;br /&gt;
 &lt;br /&gt;
Inspect &amp;lt;code&amp;gt;o-01_SHG_ip.YPP-X_probe_order_2&amp;lt;/code&amp;gt;&lt;br /&gt;
 #     E [eV]            X/Im[cm/stV](x)    X/Re[cm/stV](x)    X/Im[cm/stV](y)    X/Re[cm/stV](y)    X/Im[cm/stV](z)    X/Re[cm/stV](z)&lt;br /&gt;
 #&lt;br /&gt;
      0.50000000        -0.35378838E-09    -0.19774796E-07     0.23591828E-09    -0.89405637E-09      0.0000000          0.0000000    &lt;br /&gt;
      1.1250000         -0.19356524E-08    -0.23160605E-07    -0.16052184E-09    -0.67662771E-09      0.0000000          0.0000000    &lt;br /&gt;
      1.7500000         -0.69446459E-08    -0.35586956E-07    -0.76025706E-09    -0.10205678E-08      0.0000000          0.0000000    &lt;br /&gt;
      2.37500000        -0.181606152E-7    -0.261823658E-8     0.438358596E-8     0.407915226E-8      0.00000000         0.00000000   &lt;br /&gt;
&lt;br /&gt;
The first column are the frequencies of the applied field, the second and third is the polarization along x (imaginary and real part), the fourth and fifth is the polarization along y (imaginary and real part)  &lt;br /&gt;
and the sixth and seventh is the polarization along z (imaginary and real part).&lt;br /&gt;
&lt;br /&gt;
Plot the absolute value of the SHG for the &amp;quot;xxy&amp;quot; component (that is, the applied field is in the x and y directions and one look at the polarization along x):&lt;br /&gt;
&lt;br /&gt;
 set ylabel &amp;quot;{/Symbol=26 \174}{/Symbol=26 c}_{xyx}^{(2)}{/Symbol=26 \174} (pm/V)&amp;quot; offset -0.7&lt;br /&gt;
 set xlabel &amp;quot;Energy (eV)&amp;quot;&lt;br /&gt;
 pmVm1toCGS=2.38721e-09&lt;br /&gt;
 plot &#039;01_SHG_ip_files/o-01_SHG_ip.YPP-X_probe_order_2&#039; u 1:(sqrt($2**2+$3**2)/pmVm1toCGS) w p title &amp;quot;calc&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[File: SHG_intensity_of_2D_h-BN_obtained_from_the_previous_run_(and_compared_with_a_run_on_112_frequencies).png | SHG_intensity_of_2D_h-BN obtained from the current run (12 frequencies) compared with a run with 112 frequencies]] &lt;br /&gt;
&lt;br /&gt;
In the figure above, the results of the current run are compared with those for a run with 112 frequencies (one can obtain these results by repeating the calculations, changing the number of frequencies in &amp;lt;code&amp;gt;NLEnSteps&amp;lt;/code&amp;gt; though this take about 10 times more computational time than the run with 12). One can notice some differences between the two runs. In fact, the two runs evaluate different frequnecies and the difference indicates spurious oscillations of the value of the polarizability due to the simulation time being too short and thus to the presence of &#039;noise&#039; due to the eigenfrecies.  &lt;br /&gt;
As an exercise, you can repeat the simulation for e,g, a time of &amp;lt;code&amp;gt;60 fs&amp;lt;/code&amp;gt;, that is setting &amp;lt;code&amp;gt;NLtime=60&amp;lt;/code&amp;gt;. The plot below compare the SHG extracted at 42 fs and 60 fs, where the latter gives clearly more accurate results. &lt;br /&gt;
&lt;br /&gt;
[[File:Comparison of the SHG intensity of 2D h-BN obtained with different simulation time.png|Comparison of the SHG intensity of 2D h-BN obtained with different simulation time]]&lt;br /&gt;
&lt;br /&gt;
As a final note, the SHG depends on the size of the vacuum added in the supercell. Instead, one should consider the surface SHG which obtained by considering an effective thickness for the layer. This is usually chosen to be similar to the layer separation in the bulk counterpart.&lt;br /&gt;
&lt;br /&gt;
= Step 3: Hartree+Screened exchange approximation (BSE level) =&lt;br /&gt;
&lt;br /&gt;
== Hartree+Screened exchange collisions ==&lt;br /&gt;
Similarly to the linear part, one needs to generate the Screened exchange collisions. The procedure is exactly the same.&lt;br /&gt;
&lt;br /&gt;
Create the input:&lt;br /&gt;
 yambo_nl -X s -e -v hsex -F 03_coll_hsex.in&lt;br /&gt;
modify the input ad follows&lt;br /&gt;
 em1s                             # [R][Xs] Statically Screened Interaction&lt;br /&gt;
 collisions                       # [R] Collisions&lt;br /&gt;
 dipoles                          # [R] Oscillator strenghts (or dipoles)&lt;br /&gt;
 Chimod= &amp;quot;HARTREE&amp;quot;                # [X] IP/Hartree/ALDA/LRC/PF/BSfxc&lt;br /&gt;
 % BndsRnXs&lt;br /&gt;
    1 |  20 |                         # [Xs] Polarization function bands&lt;br /&gt;
 %&lt;br /&gt;
 NGsBlkXs= 1000 mHa    # [Xs] Response block size&lt;br /&gt;
 % LongDrXs&lt;br /&gt;
  1.000000 | 1.000000 | 0.000000 |        # [Xs] [cc] Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 % COLLBands&lt;br /&gt;
    4 |  5 |                         # [COLL] Bands for the collisions&lt;br /&gt;
 %&lt;br /&gt;
 HXC_Potential= &amp;quot;SEX+HARTREE&amp;quot;     # [SC] SC HXC Potential&lt;br /&gt;
 HARRLvcs= 1000 mHa    # [HA] Hartree     RL components&lt;br /&gt;
 EXXRLvcs= 1000 mHa    # [XX] Exchange    RL components&lt;br /&gt;
 CORRLvcs= 1000 mHa    # [GW] Correlation RL components&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Calculate the collisions (you may want to run in parallel):&lt;br /&gt;
 yambo_nl -F 03_coll_hsex.in -J 03_coll -C 04_hsex_files&lt;br /&gt;
&lt;br /&gt;
== Run the simulation ==&lt;br /&gt;
&lt;br /&gt;
Create the input:&lt;br /&gt;
 yambo_nl -nl n -v hsex -V qp -F 04_SHG_hsex.in&lt;br /&gt;
&lt;br /&gt;
modify the following parts of the input (by this time all the innput variables should be known from the previous exercises):&lt;br /&gt;
&lt;br /&gt;
 % BndsRnXs&lt;br /&gt;
   1 |  20 |                         # [Xs] Polarization function bands&lt;br /&gt;
 %&lt;br /&gt;
 NGsBlkXs= 1000 mHa    # [Xs] Response block size&lt;br /&gt;
 % LongDrXs&lt;br /&gt;
  1.000000 | 1.000000 | 0.000000 |        # [Xs] [cc] Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 % NLBands&lt;br /&gt;
    4 |  5 |                         # [NL] Bands range&lt;br /&gt;
 %&lt;br /&gt;
&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;SEX&amp;quot;             # [NL] Correlation (&amp;quot;IPA/HARTREE/TDDFT/LRC/LRW/JGM/SEX&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 % NLEnRange&lt;br /&gt;
  0.500000 |8.000000 |         eV    # [NL] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 NLEnSteps= 12                   # [NL] Energy steps&lt;br /&gt;
&lt;br /&gt;
 % GfnQP_E&lt;br /&gt;
  3.000000 | 1.000000 | 1.000000 |        # [EXTQP G] E parameters  (c/v) eV|adim|adim&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
 Field1_kind= &amp;quot;SIN&amp;quot;           # [RT Field1] Kind(SIN|COS|RES|ANTIRES|GAUSS|DELTA|QSSIN)&lt;br /&gt;
&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
  1.000000 | 1.000000 | 0.000000 |        # [RT Field1] Versor&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
Then run the simulation using e.g. mpi and 4 cores:&lt;br /&gt;
 mpirun -n 4 yambo_nl -F 04_SHG_hsex.in -J 04_SHG_hsex,03_coll -C 04_SHG_hsex_files&lt;br /&gt;
&lt;br /&gt;
== Postprocessing: obtain the nonlinear response ==&lt;br /&gt;
&lt;br /&gt;
Similarly to what we did for the independent particle case, we create the input:&lt;br /&gt;
 ypp_nl -nl -F 05_SHG_hsex_pp.in&lt;br /&gt;
 &lt;br /&gt;
we change &amp;lt;code&amp;gt;Xorder = 4 &amp;lt;/code&amp;gt; and then run:&lt;br /&gt;
 ypp_nl -F 05_SHG_hsex_pp.in -J 04_SHG_hsex -C 04_hsex_files&lt;br /&gt;
&lt;br /&gt;
Then we plot (as before we compare with a simulation ran for 112 frequencies).&lt;br /&gt;
&lt;br /&gt;
Plot the results:&lt;br /&gt;
&lt;br /&gt;
 set ylabel &amp;quot;{/Symbol=26 \174}{/Symbol=26 c}_{xyx}^{(2)}{/Symbol=26 \174} (pm/V)&amp;quot; offset -0.7&lt;br /&gt;
 set xlabel &amp;quot;Energy (eV)&amp;quot;&lt;br /&gt;
 pmVm1toCGS=2.38721e-09&lt;br /&gt;
 plot &#039;04_hsex_files/o-04_SHG_hsex.YPP-X_probe_order_2&#039; u 1:(sqrt($2**2+$3**2)/pmVm1toCGS) w p title &amp;quot;calc&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[File:SHG hsex.png|SHG at the Hartree + Screened exchange from the current run with 12 frequencies (crosses) and a run with 112 frequencies (keeping the other parameters the same)]]&lt;br /&gt;
&lt;br /&gt;
Also in this case, we note differences between the two simulations. As discussed for the independent particle approximation, this is due to the too short simulation time. Repeating the calculations with a longer time gives more accurate results. &lt;br /&gt;
In addition, note that in the interest of time, all parameters are under converged. In principle, to calculate the collisions one should use the same parameters of a converged BSE calculation. As well, to eliminate spurious interaction with the periodic images, one should use the Coulomb cut-off as it was used for this system in the [[Quasi-particles of a 2D system| tutorial on quasiparticle calculations]]. As a reference, a converged calculation for this system is in &amp;lt;ref name=&amp;quot;Gruning2014&amp;quot;&amp;gt;M. Grüning and C. Attaccalite, [https://journals.aps.org/prb/abstract/10.1103/PhysRevB.89.081102 Phys. Rev. B &#039;&#039;&#039;89&#039;&#039;&#039;, 081102]&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
= References = &lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Fulvio</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Second-harmonic_generation_of_2D-hBN&amp;diff=7027</id>
		<title>Second-harmonic generation of 2D-hBN</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Second-harmonic_generation_of_2D-hBN&amp;diff=7027"/>
		<updated>2023-05-25T13:23:43Z</updated>

		<summary type="html">&lt;p&gt;Fulvio: /* Output post-processing: the dielectric function */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Step 0: Theoretical framework =&lt;br /&gt;
&lt;br /&gt;
In this tutorial, we compute the Second-harmonic generation (SHG) from the dynamics of the Bloch-states. The equation-of-motion of the Bloch-states is explained in the tutorial on [[Linear response from Bloch-states dynamics]]. Independently of the &#039;experiment&#039; we simulate, the part of the integration of motion stays the same. This means that any experiment, including non-linear optics, can be performed at the level of the theory listed for the computation of the dielectric function:&lt;br /&gt;
* independent (quasi)particle&lt;br /&gt;
* time-dependent Hartree (RPA level)&lt;br /&gt;
* time-dependent DFT (and DPFT)&lt;br /&gt;
* time-dependent Hartree+Screened exchange (BSE level)&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
What changes when we want to calculate the SHG (or higher harmonics) is:&lt;br /&gt;
* the time-dependence of the input electric field and&lt;br /&gt;
* the post-processing of the signal  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Time dependence of the electric Field&#039;&#039;&#039;: we choose a sinusoidal electric field, thus a monochromatic laser field. This allows one to expand the polarization in the form &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; through a coefficient depending on a power of the strength of the field (with the power depending on the order of the response).&lt;br /&gt;
&lt;br /&gt;
At difference with a delta-like perturbation, a real-time simulation gives the response at the laser-field only. Then, to obtain the spectrum for the desired range of frequency, we have to perform so many simulations as the frequencies in the desired range.  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Post-processing of the signal&#039;&#039;&#039;: The switch-on of the electric field corresponds to a weak delta-like kick. Thus, even if it may not be noticeable, the polarization results from both the sinusoidal field and the delta-like kick. The latter excites all eigenfrequencies of the system. Though weak, the resulting signal is comparable with the second-harmonic signal. To eliminate the signal from the eigenfrequencies, we apply a dephasing (&amp;lt;math&amp;gt;\gamma_{deph}&amp;lt;/math&amp;gt;). To have a signal useful to sample the second-harmonic signal, we need to wait a time &amp;lt;math&amp;gt;\bar t&amp;lt;/math&amp;gt;  much larger than the dephasing-time &amp;lt;math&amp;gt;1/\gamma_{deph} &amp;lt;/math&amp;gt;. Note that we cannot choose a too short dephasing time (to shorten the simulation time), as this would result in a too large broadening of the spectrum. After &amp;lt;math&amp;gt;\bar t&amp;lt;/math&amp;gt;, we sample 2N+1 times in a period and use discrete Fourier transform to extract &amp;lt;math&amp;gt;{p}_n&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt; n = 0,...,N&amp;lt;/math&amp;gt;, where n=2 gives the SHG. This is schematically illustrated in figure:&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;
The scheme from Ref. &amp;lt;ref name=&amp;quot;Attaccalite2013&amp;quot;&amp;gt;C. Attaccalite and M. Gruning [https://arxiv.org/abs/1309.4012v2 Phys. Rev. B, &#039;&#039;&#039;88&#039;&#039;&#039;, 235113 (2013)]&amp;lt;/ref&amp;gt; summarised the workflow for computing the SHG (or higher-harmonics) in a energy range &amp;lt;math&amp;gt;[\Omega_1,\Omega_2]&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
[[File:Scheme nl.png|350px|center|Schematic representation of real-time calculations]]&lt;br /&gt;
&lt;br /&gt;
= Step 1: Prerequisites =&lt;br /&gt;
You should be in the folder &amp;lt;code&amp;gt;YAMBO_TUTORIALS/hBN-2D/YAMBO/&amp;lt;/code&amp;gt;.&lt;br /&gt;
In this example, we will consider a single layer of hexagonal boron nitride (hBN). &lt;br /&gt;
Execute the commands (remember to ad -nompi if you run on marconi100)&lt;br /&gt;
 yambo_nl&lt;br /&gt;
 ypp_nl -fixsym -F 00_removesym.in  &lt;br /&gt;
to create the input, to remove the symmetries which are not compatible with the field: &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;1.000000 | 1.000000 | 0.000000 |&amp;lt;/span&amp;gt;        # First external Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 % Efield2&lt;br /&gt;
  0.000000 | 0.000000 | 0.000000 |        # 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;
 #KeepKGrid                     # Do not expand the k-grid&lt;br /&gt;
where we chose the field along the xy direction and we remove time-reversal symmetry.&lt;br /&gt;
&lt;br /&gt;
Then run the pre-processing job:&lt;br /&gt;
 ypp_nl -F 00_removesym.in&lt;br /&gt;
This creates the directory &amp;lt;code&amp;gt;FixSymm&amp;lt;/code&amp;gt;. Change directory to &amp;lt;code&amp;gt;FixSymm&amp;lt;/code&amp;gt;. This contains the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory with reduced symmetries, compatible with the direction of the field. Now run the setup again (&amp;lt;code&amp;gt;yambo_nl -nompi&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
= Step 2: Independent-particle approximation =&lt;br /&gt;
&lt;br /&gt;
Use the command:&lt;br /&gt;
  cd FixSymm&lt;br /&gt;
  yambo_nl&lt;br /&gt;
  yambo_nl -nl n -F 01_SHG_ip.in&lt;br /&gt;
to generate the input:&lt;br /&gt;
&lt;br /&gt;
 nloptics                         # [R] Non-linear spectroscopy&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=-1.000000           fs    # [NL] Simulation Time&lt;br /&gt;
 NLintegrator= &amp;quot;INVINT&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;
 % NLEnRange&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;0.5000000 |8.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;12&amp;lt;/span&amp;gt;                     # [NL] Energy steps&lt;br /&gt;
 NLDamping= 0.200000        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= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;1000            mHa&amp;lt;/span&amp;gt;   # [HA] Hartree     RL components&lt;br /&gt;
 EXXRLvcs= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;1000            mHa&amp;lt;/span&amp;gt;    # [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;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&amp;quot;SIN&amp;quot; &amp;lt;/span&amp;gt;          # [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 | 1.000000 | 0.000000 |&amp;lt;/span&amp;gt;        # [RT Field1] Versor&lt;br /&gt;
 %&lt;br /&gt;
 Field1_Tstart= 0.010000    fs    # [RT Field1] Initial Time&lt;br /&gt;
&lt;br /&gt;
To describe the Bloch-dynamics we will use as a basis the KS-states 3-6 for the k-grid used in the non-scf DFT calculations, that is a 6x6x1 (&amp;lt;code&amp;gt;NLBands&amp;lt;/code&amp;gt;). We choose 12 equally spaced frequencies (&amp;lt;code&amp;gt;NLEnSteps&amp;lt;/code&amp;gt;) for the applied field in the range  (&amp;lt;code&amp;gt;NLEnRange&amp;lt;/code&amp;gt;) between 0.5 and 8 eV. We choose a sinusoidal time-dependence (&amp;lt;code&amp;gt;Field1_kind&amp;lt;/code&amp;gt;) and set the field direction (&amp;lt;code&amp;gt;Field1_kind&amp;lt;/code&amp;gt;) along xy (in plane). The negative simulation time (&amp;lt;code&amp;gt;NLtime=-1.000000&amp;lt;/code&amp;gt;) means that the code will choose it based on the value of the &amp;lt;code&amp;gt;NLDamping&amp;lt;/code&amp;gt;. While this is a good lower bound for the simulation time, one should check it is sufficient to get accurate results. &lt;br /&gt;
&lt;br /&gt;
Run the simulation, possibly in parallel e. g. in a interactive session on 4 cores. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;[In order to get 4 cores while in an interacting node, exit your current allocation and rerun &amp;lt;code&amp;gt;salloc&amp;lt;/code&amp;gt; asking for the proper number of tasks:&#039;&#039;&#039;&lt;br /&gt;
 salloc -A tra23_Yambo -p m100_usr_prod -q m100_qos_dbg --nodes=1 --ntasks-per-node=&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;4&amp;lt;/span&amp;gt; --cpus-per-task=4 -t 02:00:00&lt;br /&gt;
&#039;&#039;&#039;Otherwise, you can submit the job with a slurm script as explained in the introductory page]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now execute the command:&lt;br /&gt;
  mpirun -n 4 yambo_nl -F 01_SHG_ip.in -J 01_SHG_ip -C 01_SHG_ip_files&lt;br /&gt;
&lt;br /&gt;
This run will take several minutes. While it is running, you can check the progress of one specific frequency:&lt;br /&gt;
 tail -f 01_SHG_ip_files/o-01_SHG_ip.polarization_F2&lt;br /&gt;
If you want to know how many fs the simulation will last (since this was decided by the code), you can get this information in the report file:&lt;br /&gt;
 $ grep Total 01_SHG_ip_files/r-01_SHG_ip_nloptics&lt;br /&gt;
 Total simulation time       :  41.23193 [fs]&lt;br /&gt;
If you instead want to track the progress of the full simulation, you should check the log file(s). If you are doing a parallel run, you can type&lt;br /&gt;
 tail -f 01_SHG_ip_files/LOG/l-01_SHG_ip_nloptics_CPU_1&lt;br /&gt;
&lt;br /&gt;
Once the run is finished, check the report &amp;lt;code&amp;gt;01_SHG_ip_files/r-01_SHG_ip_nloptics&amp;lt;/code&amp;gt;. In particular, in the appended input files, you can see the default parallelization applied by the code for calculating the dipoles and run the time-propagation. For the latter, the main parallelization is on the frequencies and then on the k-points (&amp;lt;code&amp;gt;NL_ROLEs= &amp;quot;w.k&amp;quot;&amp;lt;/code&amp;gt;).   &lt;br /&gt;
&lt;br /&gt;
 | NL_CPU= &amp;quot;2.2&amp;quot;                    # [PARALLEL] CPUs for each role&lt;br /&gt;
 | NL_ROLEs= &amp;quot;w.k&amp;quot;                  # [PARALLEL] CPUs roles (w,k)&lt;br /&gt;
 | DIP_CPU= &amp;quot;2.2.1&amp;quot;                 # [PARALLEL] CPUs for each role&lt;br /&gt;
 | DIP_ROLEs= &amp;quot;v.c.k&amp;quot;               # [PARALLEL] CPUs roles (k,c,v)&lt;br /&gt;
&lt;br /&gt;
Also, look at the simulation time. This is approximately 42 fs. &lt;br /&gt;
&lt;br /&gt;
Plot the polarization for a couple of frequencies, e.g. the first and last of the chosen range (the corresponding frequency can be read in the file, search for &amp;quot;Frequency value&amp;quot;):&lt;br /&gt;
 set ylabel &amp;quot;x-component polarization&amp;quot; offset -0.7&lt;br /&gt;
 set xlabel &amp;quot;time (fs)&amp;quot;&lt;br /&gt;
 plot &#039;01_SHG_ip_files/o-01_SHG_ip.polarization_F1&#039; u 1:2 w l lw 2 title &amp;quot;omega = 0.5 eV&amp;quot;&lt;br /&gt;
 replot &#039;01_SHG_ip_files/o-01_SHG_ip.polarization_F12&#039; u 1:2 w l lw 2  title &amp;quot;omega = 7.375 eV&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[File:Berry_phase_polarization_of_2D_h-BN_obtained_from_the_previous_run_for_two_laser_frequencies.png|Berry_phase_polarization_of_2D_h-BN_obtained from the run for two laser frequencies]]&lt;br /&gt;
&lt;br /&gt;
After the applied field is &#039;switched on&#039;, the polarization is oscillating at the frequency of the applied field and at the eigenfrequencies of the system as described above in the cartoon. This is visible particularly for the higher frequency. Due to the dephasing, after about 20 fs the polarization is oscillating (at least to the eye) at the frequency of the applied field. Nonlinear components are not visible since they are several orders of magnitude smaller than the first order.&lt;br /&gt;
&lt;br /&gt;
== Output post-processing: the dielectric function ==&lt;br /&gt;
&lt;br /&gt;
Once we obtained the polarization, we Fourier-transform the polarization to obtain the dielectric function.&lt;br /&gt;
&lt;br /&gt;
Use the command:&lt;br /&gt;
&lt;br /&gt;
  ypp_nl -nl -F 02_SHG_ip_pp.in -C 01_SHG_ip_files&lt;br /&gt;
&lt;br /&gt;
to generate the input file: &lt;br /&gt;
&lt;br /&gt;
 nonlinear                        # [R] Non-linear response analysis&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;Xorder= 4&amp;lt;/span&amp;gt; # 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;NONE&amp;quot;                 # Damping type ( NONE | LORENTZIAN | GAUSSIAN )&lt;br /&gt;
 DampFactor= 0.000000       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;
Where we changed the &amp;lt;code&amp;gt;Xorder&amp;lt;/code&amp;gt; to 4. This variable controls the terms in the Fourier expansion of the polarization. We choose up to expand up to the fourth order. This should ensure the second order to be accurate enough. As an exercise, you can change this value (e.g. choose 2,3,5,6) and see how the result below is changing. The time-window where processing is done is chosen automatically, since values are negative. The code chooses by default the last period to carry out the analysis. &lt;br /&gt;
&lt;br /&gt;
To run the post-processing, use the command:&lt;br /&gt;
 ypp_nl -F 02_SHG_ip_pp.in -J 01_SHG_ip -C 01_SHG_ip_files. &lt;br /&gt;
   &lt;br /&gt;
In  &amp;lt;code&amp;gt;01_SHG_ip_files&amp;lt;/code&amp;gt; the following files were generated &lt;br /&gt;
 o-01_SHG_ip.YPP-X_probe_order_1&lt;br /&gt;
 o-01_SHG_ip.YPP-X_probe_order_2&lt;br /&gt;
 o-01_SHG_ip.YPP-X_probe_order_3&lt;br /&gt;
 o-01_SHG_ip.YPP-X_probe_order_4&lt;br /&gt;
 r-01_SHG_ip_nonlinear&lt;br /&gt;
&lt;br /&gt;
The output files contain respectively the first, second, third and fourth order response(corresponding to &amp;lt;code&amp;gt;Xorder=4&amp;lt;/code&amp;gt;)  at the 12 frequencies in the chosen range. &lt;br /&gt;
 &lt;br /&gt;
Inspect &amp;lt;code&amp;gt;o-01_SHG_ip.YPP-X_probe_order_2&amp;lt;/code&amp;gt;&lt;br /&gt;
 #     E [eV]            X/Im[cm/stV](x)    X/Re[cm/stV](x)    X/Im[cm/stV](y)    X/Re[cm/stV](y)    X/Im[cm/stV](z)    X/Re[cm/stV](z)&lt;br /&gt;
 #&lt;br /&gt;
      0.50000000        -0.35378838E-09    -0.19774796E-07     0.23591828E-09    -0.89405637E-09      0.0000000          0.0000000    &lt;br /&gt;
      1.1250000         -0.19356524E-08    -0.23160605E-07    -0.16052184E-09    -0.67662771E-09      0.0000000          0.0000000    &lt;br /&gt;
      1.7500000         -0.69446459E-08    -0.35586956E-07    -0.76025706E-09    -0.10205678E-08      0.0000000          0.0000000    &lt;br /&gt;
      2.37500000        -0.181606152E-7    -0.261823658E-8     0.438358596E-8     0.407915226E-8      0.00000000         0.00000000   &lt;br /&gt;
&lt;br /&gt;
The first column are the frequencies of the applied field, the second and third is the polarization along x (imaginary and real part), the fourth and fifth is the polarization along y (imaginary and real part)  &lt;br /&gt;
and the sixth and seventh is the polarization along z (imaginary and real part).&lt;br /&gt;
&lt;br /&gt;
Plot the absolute value of the SHG for the &amp;quot;xxy&amp;quot; component (that is, the applied field is in the x and y directions and one look at the polarization along x):&lt;br /&gt;
&lt;br /&gt;
 set ylabel &amp;quot;{/Symbol=26 \174}{/Symbol=26 c}_{xyx}^{(2)}{/Symbol=26 \174} (pm/V)&amp;quot; offset -0.7&lt;br /&gt;
 set xlabel &amp;quot;Energy (eV)&amp;quot;&lt;br /&gt;
 pmVm1toCGS=2.38721e-09&lt;br /&gt;
 plot &#039;01_SHG_ip_files/o-01_SHG_ip.YPP-X_probe_order_2&#039; u 1:(sqrt($2**2+$3**2)/pmVm1toCGS) w p title &amp;quot;calc&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[File: SHG_intensity_of_2D_h-BN_obtained_from_the_previous_run_(and_compared_with_a_run_on_112_frequencies).png | SHG_intensity_of_2D_h-BN obtained from the current run (12 frequencies) compared with a run with 112 frequencies]] &lt;br /&gt;
&lt;br /&gt;
In the figure above, the results of the current run are compared with those for a run with 112 frequencies (one can obtain these results by repeating the calculations, changing the number of frequencies in &amp;lt;code&amp;gt;NLEnSteps&amp;lt;/code&amp;gt; though this take about 10 times more computational time than the run with 12). One can notice some differences between the two runs. In fact, the two runs evaluate different frequnecies and the difference indicates spurious oscillations of the value of the polarizability due to the simulation time being too short and thus to the presence of &#039;noise&#039; due to the eigenfrecies.  &lt;br /&gt;
As an exercise, you can repeat the simulation for e,g, a time of &amp;lt;code&amp;gt;60 fs&amp;lt;/code&amp;gt;, that is setting &amp;lt;code&amp;gt;NLtime=60&amp;lt;/code&amp;gt;. The plot below compare the SHG extracted at 42 fs and 60 fs, where the latter gives clearly more accurate results. &lt;br /&gt;
&lt;br /&gt;
[[File:Comparison of the SHG intensity of 2D h-BN obtained with different simulation time.png|Comparison of the SHG intensity of 2D h-BN obtained with different simulation time]]&lt;br /&gt;
&lt;br /&gt;
As a final note, the SHG depends on the size of the vacuum added in the supercell. Instead, one should consider the surface SHG which obtained by considering an effective thickness for the layer. This is usually chosen to be similar to the layer separation in the bulk counterpart.&lt;br /&gt;
&lt;br /&gt;
= Step 3: Hartree+Screened exchange approximation (BSE level) =&lt;br /&gt;
&lt;br /&gt;
== Hartree+Screened exchange collisions ==&lt;br /&gt;
Similarly to the linear part, one needs to generate the Screened exchange collisions. The procedure is exactly the same.&lt;br /&gt;
&lt;br /&gt;
Create the input:&lt;br /&gt;
 yambo_nl -X s -e -v hsex -F 03_coll_hsex.in&lt;br /&gt;
modify the input ad follows&lt;br /&gt;
 em1s                             # [R][Xs] Statically Screened Interaction&lt;br /&gt;
 collisions                       # [R] Collisions&lt;br /&gt;
 dipoles                          # [R] Oscillator strenghts (or dipoles)&lt;br /&gt;
 Chimod= &amp;quot;HARTREE&amp;quot;                # [X] IP/Hartree/ALDA/LRC/PF/BSfxc&lt;br /&gt;
 % BndsRnXs&lt;br /&gt;
    1 |  20 |                         # [Xs] Polarization function bands&lt;br /&gt;
 %&lt;br /&gt;
 NGsBlkXs= 1000 mHa    # [Xs] Response block size&lt;br /&gt;
 % LongDrXs&lt;br /&gt;
  1.000000 | 1.000000 | 0.000000 |        # [Xs] [cc] Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 % COLLBands&lt;br /&gt;
    4 |  5 |                         # [COLL] Bands for the collisions&lt;br /&gt;
 %&lt;br /&gt;
 HXC_Potential= &amp;quot;SEX+HARTREE&amp;quot;     # [SC] SC HXC Potential&lt;br /&gt;
 HARRLvcs= 1000 mHa    # [HA] Hartree     RL components&lt;br /&gt;
 EXXRLvcs= 1000 mHa    # [XX] Exchange    RL components&lt;br /&gt;
 CORRLvcs= 1000 mHa    # [GW] Correlation RL components&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Calculate the collisions (you may want to run in parallel):&lt;br /&gt;
 yambo_nl -F 03_coll_hsex.in -J 03_coll -C 04_hsex_files&lt;br /&gt;
&lt;br /&gt;
== Run the simulation ==&lt;br /&gt;
&lt;br /&gt;
Create the input:&lt;br /&gt;
 yambo_nl -nl n -v hsex -V qp -F 04_SHG_hsex.in&lt;br /&gt;
&lt;br /&gt;
modify the following parts of the input (by this time all the innput variables should be known from the previous exercises):&lt;br /&gt;
&lt;br /&gt;
 % BndsRnXs&lt;br /&gt;
   1 |  20 |                         # [Xs] Polarization function bands&lt;br /&gt;
 %&lt;br /&gt;
 NGsBlkXs= 1000 mHa    # [Xs] Response block size&lt;br /&gt;
 % LongDrXs&lt;br /&gt;
  1.000000 | 1.000000 | 0.000000 |        # [Xs] [cc] Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 % NLBands&lt;br /&gt;
    4 |  5 |                         # [NL] Bands range&lt;br /&gt;
 %&lt;br /&gt;
&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;SEX&amp;quot;             # [NL] Correlation (&amp;quot;IPA/HARTREE/TDDFT/LRC/LRW/JGM/SEX&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 % NLEnRange&lt;br /&gt;
  0.500000 |8.000000 |         eV    # [NL] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 NLEnSteps= 12                   # [NL] Energy steps&lt;br /&gt;
&lt;br /&gt;
 % GfnQP_E&lt;br /&gt;
  3.000000 | 1.000000 | 1.000000 |        # [EXTQP G] E parameters  (c/v) eV|adim|adim&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
 Field1_kind= &amp;quot;SIN&amp;quot;           # [RT Field1] Kind(SIN|COS|RES|ANTIRES|GAUSS|DELTA|QSSIN)&lt;br /&gt;
&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
  1.000000 | 1.000000 | 0.000000 |        # [RT Field1] Versor&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
Then run the simulation using e.g. mpi and 4 cores:&lt;br /&gt;
 mpirun -n 4 yambo_nl -F 04_SHG_hsex.in -J 04_SHG_hsex,03_coll -C 04_SHG_hsex_files&lt;br /&gt;
&lt;br /&gt;
== Postprocessing: obtain the nonlinear response ==&lt;br /&gt;
&lt;br /&gt;
Similarly to what we did for the independent particle case, we create the input:&lt;br /&gt;
 ypp_nl -nl -F 05_SHG_hsex_pp.in&lt;br /&gt;
 &lt;br /&gt;
we change &amp;lt;code&amp;gt;Xorder = 4 &amp;lt;/code&amp;gt; and then run:&lt;br /&gt;
 ypp_nl -F 05_SHG_hsex_pp.in -J 04_SHG_hsex -C 04_hsex_files&lt;br /&gt;
&lt;br /&gt;
Then we plot (as before we compare with a simulation ran for 112 frequencies).&lt;br /&gt;
&lt;br /&gt;
Plot the results:&lt;br /&gt;
&lt;br /&gt;
 set ylabel &amp;quot;{/Symbol=26 \174}{/Symbol=26 c}_{xyx}^{(2)}{/Symbol=26 \174} (pm/V)&amp;quot; offset -0.7&lt;br /&gt;
 set xlabel &amp;quot;Energy (eV)&amp;quot;&lt;br /&gt;
 pmVm1toCGS=2.38721e-09&lt;br /&gt;
 plot &#039;04_hsex_files/o-04_SHG_hsex.YPP-X_probe_order_2&#039; u 1:(sqrt($2**2+$3**2)/pmVm1toCGS) w p title &amp;quot;calc&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[File:SHG hsex.png|SHG at the Hartree + Screened exchange from the current run with 12 frequencies (crosses) and a run with 112 frequencies (keeping the other parameters the same)]]&lt;br /&gt;
&lt;br /&gt;
Also in this case, we note differences between the two simulations. As discussed for the independent particle approximation, this is due to the too short simulation time. Repeating the calculations with a longer time gives more accurate results. &lt;br /&gt;
In addition, note that in the interest of time, all parameters are under converged. In principle, to calculate the collisions one should use the same parameters of a converged BSE calculation. As well, to eliminate spurious interaction with the periodic images, one should use the Coulomb cut-off as it was used for this system in the [[Quasi-particles of a 2D system| tutorial on quasiparticle calculations]]. As a reference, a converged calculation for this system is in &amp;lt;ref name=&amp;quot;Gruning2014&amp;quot;&amp;gt;M. Grüning and C. Attaccalite, [https://journals.aps.org/prb/abstract/10.1103/PhysRevB.89.081102 Phys. Rev. B &#039;&#039;&#039;89&#039;&#039;&#039;, 081102]&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
= References = &lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Fulvio</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Second-harmonic_generation_of_2D-hBN&amp;diff=7026</id>
		<title>Second-harmonic generation of 2D-hBN</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Second-harmonic_generation_of_2D-hBN&amp;diff=7026"/>
		<updated>2023-05-25T13:21:52Z</updated>

		<summary type="html">&lt;p&gt;Fulvio: /* Output post-processing: the dielectric function */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Step 0: Theoretical framework =&lt;br /&gt;
&lt;br /&gt;
In this tutorial, we compute the Second-harmonic generation (SHG) from the dynamics of the Bloch-states. The equation-of-motion of the Bloch-states is explained in the tutorial on [[Linear response from Bloch-states dynamics]]. Independently of the &#039;experiment&#039; we simulate, the part of the integration of motion stays the same. This means that any experiment, including non-linear optics, can be performed at the level of the theory listed for the computation of the dielectric function:&lt;br /&gt;
* independent (quasi)particle&lt;br /&gt;
* time-dependent Hartree (RPA level)&lt;br /&gt;
* time-dependent DFT (and DPFT)&lt;br /&gt;
* time-dependent Hartree+Screened exchange (BSE level)&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
What changes when we want to calculate the SHG (or higher harmonics) is:&lt;br /&gt;
* the time-dependence of the input electric field and&lt;br /&gt;
* the post-processing of the signal  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Time dependence of the electric Field&#039;&#039;&#039;: we choose a sinusoidal electric field, thus a monochromatic laser field. This allows one to expand the polarization in the form &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; through a coefficient depending on a power of the strength of the field (with the power depending on the order of the response).&lt;br /&gt;
&lt;br /&gt;
At difference with a delta-like perturbation, a real-time simulation gives the response at the laser-field only. Then, to obtain the spectrum for the desired range of frequency, we have to perform so many simulations as the frequencies in the desired range.  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Post-processing of the signal&#039;&#039;&#039;: The switch-on of the electric field corresponds to a weak delta-like kick. Thus, even if it may not be noticeable, the polarization results from both the sinusoidal field and the delta-like kick. The latter excites all eigenfrequencies of the system. Though weak, the resulting signal is comparable with the second-harmonic signal. To eliminate the signal from the eigenfrequencies, we apply a dephasing (&amp;lt;math&amp;gt;\gamma_{deph}&amp;lt;/math&amp;gt;). To have a signal useful to sample the second-harmonic signal, we need to wait a time &amp;lt;math&amp;gt;\bar t&amp;lt;/math&amp;gt;  much larger than the dephasing-time &amp;lt;math&amp;gt;1/\gamma_{deph} &amp;lt;/math&amp;gt;. Note that we cannot choose a too short dephasing time (to shorten the simulation time), as this would result in a too large broadening of the spectrum. After &amp;lt;math&amp;gt;\bar t&amp;lt;/math&amp;gt;, we sample 2N+1 times in a period and use discrete Fourier transform to extract &amp;lt;math&amp;gt;{p}_n&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt; n = 0,...,N&amp;lt;/math&amp;gt;, where n=2 gives the SHG. This is schematically illustrated in figure:&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;
The scheme from Ref. &amp;lt;ref name=&amp;quot;Attaccalite2013&amp;quot;&amp;gt;C. Attaccalite and M. Gruning [https://arxiv.org/abs/1309.4012v2 Phys. Rev. B, &#039;&#039;&#039;88&#039;&#039;&#039;, 235113 (2013)]&amp;lt;/ref&amp;gt; summarised the workflow for computing the SHG (or higher-harmonics) in a energy range &amp;lt;math&amp;gt;[\Omega_1,\Omega_2]&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
[[File:Scheme nl.png|350px|center|Schematic representation of real-time calculations]]&lt;br /&gt;
&lt;br /&gt;
= Step 1: Prerequisites =&lt;br /&gt;
You should be in the folder &amp;lt;code&amp;gt;YAMBO_TUTORIALS/hBN-2D/YAMBO/&amp;lt;/code&amp;gt;.&lt;br /&gt;
In this example, we will consider a single layer of hexagonal boron nitride (hBN). &lt;br /&gt;
Execute the commands (remember to ad -nompi if you run on marconi100)&lt;br /&gt;
 yambo_nl&lt;br /&gt;
 ypp_nl -fixsym -F 00_removesym.in  &lt;br /&gt;
to create the input, to remove the symmetries which are not compatible with the field: &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;1.000000 | 1.000000 | 0.000000 |&amp;lt;/span&amp;gt;        # First external Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 % Efield2&lt;br /&gt;
  0.000000 | 0.000000 | 0.000000 |        # 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;
 #KeepKGrid                     # Do not expand the k-grid&lt;br /&gt;
where we chose the field along the xy direction and we remove time-reversal symmetry.&lt;br /&gt;
&lt;br /&gt;
Then run the pre-processing job:&lt;br /&gt;
 ypp_nl -F 00_removesym.in&lt;br /&gt;
This creates the directory &amp;lt;code&amp;gt;FixSymm&amp;lt;/code&amp;gt;. Change directory to &amp;lt;code&amp;gt;FixSymm&amp;lt;/code&amp;gt;. This contains the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory with reduced symmetries, compatible with the direction of the field. Now run the setup again (&amp;lt;code&amp;gt;yambo_nl -nompi&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
= Step 2: Independent-particle approximation =&lt;br /&gt;
&lt;br /&gt;
Use the command:&lt;br /&gt;
  cd FixSymm&lt;br /&gt;
  yambo_nl&lt;br /&gt;
  yambo_nl -nl n -F 01_SHG_ip.in&lt;br /&gt;
to generate the input:&lt;br /&gt;
&lt;br /&gt;
 nloptics                         # [R] Non-linear spectroscopy&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=-1.000000           fs    # [NL] Simulation Time&lt;br /&gt;
 NLintegrator= &amp;quot;INVINT&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;
 % NLEnRange&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;0.5000000 |8.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;12&amp;lt;/span&amp;gt;                     # [NL] Energy steps&lt;br /&gt;
 NLDamping= 0.200000        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= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;1000            mHa&amp;lt;/span&amp;gt;   # [HA] Hartree     RL components&lt;br /&gt;
 EXXRLvcs= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;1000            mHa&amp;lt;/span&amp;gt;    # [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;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&amp;quot;SIN&amp;quot; &amp;lt;/span&amp;gt;          # [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 | 1.000000 | 0.000000 |&amp;lt;/span&amp;gt;        # [RT Field1] Versor&lt;br /&gt;
 %&lt;br /&gt;
 Field1_Tstart= 0.010000    fs    # [RT Field1] Initial Time&lt;br /&gt;
&lt;br /&gt;
To describe the Bloch-dynamics we will use as a basis the KS-states 3-6 for the k-grid used in the non-scf DFT calculations, that is a 6x6x1 (&amp;lt;code&amp;gt;NLBands&amp;lt;/code&amp;gt;). We choose 12 equally spaced frequencies (&amp;lt;code&amp;gt;NLEnSteps&amp;lt;/code&amp;gt;) for the applied field in the range  (&amp;lt;code&amp;gt;NLEnRange&amp;lt;/code&amp;gt;) between 0.5 and 8 eV. We choose a sinusoidal time-dependence (&amp;lt;code&amp;gt;Field1_kind&amp;lt;/code&amp;gt;) and set the field direction (&amp;lt;code&amp;gt;Field1_kind&amp;lt;/code&amp;gt;) along xy (in plane). The negative simulation time (&amp;lt;code&amp;gt;NLtime=-1.000000&amp;lt;/code&amp;gt;) means that the code will choose it based on the value of the &amp;lt;code&amp;gt;NLDamping&amp;lt;/code&amp;gt;. While this is a good lower bound for the simulation time, one should check it is sufficient to get accurate results. &lt;br /&gt;
&lt;br /&gt;
Run the simulation, possibly in parallel e. g. in a interactive session on 4 cores. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;[In order to get 4 cores while in an interacting node, exit your current allocation and rerun &amp;lt;code&amp;gt;salloc&amp;lt;/code&amp;gt; asking for the proper number of tasks:&#039;&#039;&#039;&lt;br /&gt;
 salloc -A tra23_Yambo -p m100_usr_prod -q m100_qos_dbg --nodes=1 --ntasks-per-node=&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;4&amp;lt;/span&amp;gt; --cpus-per-task=4 -t 02:00:00&lt;br /&gt;
&#039;&#039;&#039;Otherwise, you can submit the job with a slurm script as explained in the introductory page]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now execute the command:&lt;br /&gt;
  mpirun -n 4 yambo_nl -F 01_SHG_ip.in -J 01_SHG_ip -C 01_SHG_ip_files&lt;br /&gt;
&lt;br /&gt;
This run will take several minutes. While it is running, you can check the progress of one specific frequency:&lt;br /&gt;
 tail -f 01_SHG_ip_files/o-01_SHG_ip.polarization_F2&lt;br /&gt;
If you want to know how many fs the simulation will last (since this was decided by the code), you can get this information in the report file:&lt;br /&gt;
 $ grep Total 01_SHG_ip_files/r-01_SHG_ip_nloptics&lt;br /&gt;
 Total simulation time       :  41.23193 [fs]&lt;br /&gt;
If you instead want to track the progress of the full simulation, you should check the log file(s). If you are doing a parallel run, you can type&lt;br /&gt;
 tail -f 01_SHG_ip_files/LOG/l-01_SHG_ip_nloptics_CPU_1&lt;br /&gt;
&lt;br /&gt;
Once the run is finished, check the report &amp;lt;code&amp;gt;01_SHG_ip_files/r-01_SHG_ip_nloptics&amp;lt;/code&amp;gt;. In particular, in the appended input files, you can see the default parallelization applied by the code for calculating the dipoles and run the time-propagation. For the latter, the main parallelization is on the frequencies and then on the k-points (&amp;lt;code&amp;gt;NL_ROLEs= &amp;quot;w.k&amp;quot;&amp;lt;/code&amp;gt;).   &lt;br /&gt;
&lt;br /&gt;
 | NL_CPU= &amp;quot;2.2&amp;quot;                    # [PARALLEL] CPUs for each role&lt;br /&gt;
 | NL_ROLEs= &amp;quot;w.k&amp;quot;                  # [PARALLEL] CPUs roles (w,k)&lt;br /&gt;
 | DIP_CPU= &amp;quot;2.2.1&amp;quot;                 # [PARALLEL] CPUs for each role&lt;br /&gt;
 | DIP_ROLEs= &amp;quot;v.c.k&amp;quot;               # [PARALLEL] CPUs roles (k,c,v)&lt;br /&gt;
&lt;br /&gt;
Also, look at the simulation time. This is approximately 42 fs. &lt;br /&gt;
&lt;br /&gt;
Plot the polarization for a couple of frequencies, e.g. the first and last of the chosen range (the corresponding frequency can be read in the file, search for &amp;quot;Frequency value&amp;quot;):&lt;br /&gt;
 set ylabel &amp;quot;x-component polarization&amp;quot; offset -0.7&lt;br /&gt;
 set xlabel &amp;quot;time (fs)&amp;quot;&lt;br /&gt;
 plot &#039;01_SHG_ip_files/o-01_SHG_ip.polarization_F1&#039; u 1:2 w l lw 2 title &amp;quot;omega = 0.5 eV&amp;quot;&lt;br /&gt;
 replot &#039;01_SHG_ip_files/o-01_SHG_ip.polarization_F12&#039; u 1:2 w l lw 2  title &amp;quot;omega = 7.375 eV&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[File:Berry_phase_polarization_of_2D_h-BN_obtained_from_the_previous_run_for_two_laser_frequencies.png|Berry_phase_polarization_of_2D_h-BN_obtained from the run for two laser frequencies]]&lt;br /&gt;
&lt;br /&gt;
After the applied field is &#039;switched on&#039;, the polarization is oscillating at the frequency of the applied field and at the eigenfrequencies of the system as described above in the cartoon. This is visible particularly for the higher frequency. Due to the dephasing, after about 20 fs the polarization is oscillating (at least to the eye) at the frequency of the applied field. Nonlinear components are not visible since they are several orders of magnitude smaller than the first order.&lt;br /&gt;
&lt;br /&gt;
== Output post-processing: the dielectric function ==&lt;br /&gt;
&lt;br /&gt;
Once we obtained the polarization, we Fourier-transform the polarization to obtain the dielectric function.&lt;br /&gt;
&lt;br /&gt;
Use the command:&lt;br /&gt;
&lt;br /&gt;
  ypp_nl -nl -F 02_SHG_ip_pp.in -C 01_SHG_ip_files&lt;br /&gt;
&lt;br /&gt;
to generate the input file: &lt;br /&gt;
&lt;br /&gt;
 nonlinear                        # [R] Non-linear response analysis&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;Xorder= 4&amp;lt;/span&amp;gt; # 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;NONE&amp;quot;                 # Damping type ( NONE | LORENTZIAN | GAUSSIAN )&lt;br /&gt;
 DampFactor= 0.000000       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;
Where we changed the &amp;lt;code&amp;gt;Xorder&amp;lt;/code&amp;gt; to 4. This variable controls the terms in the Fourier expansion of the polarization. We choose up to expand up to the fourth order. This should ensure the second order to be accurate enough. As an exercise, you can change this value (e.g. choose 2,3,5,6) and see how the result below is changing. The time-window where processing is done is chosen automatically, since values are negative. The code chooses by default the last period to carry out the analysis. &lt;br /&gt;
&lt;br /&gt;
To run the post-processing, use the command:&lt;br /&gt;
 ypp_nl -F Inputs_shg/ypp_shg.in -J TD-IP_nl -C TD-IP_nl. &lt;br /&gt;
   &lt;br /&gt;
In  &amp;lt;code&amp;gt;01_SHG_ip_files&amp;lt;/code&amp;gt; the following files were generated &lt;br /&gt;
 o-01_SHG_ip.YPP-X_probe_order_1&lt;br /&gt;
 o-01_SHG_ip.YPP-X_probe_order_2&lt;br /&gt;
 o-01_SHG_ip.YPP-X_probe_order_3&lt;br /&gt;
 o-01_SHG_ip.YPP-X_probe_order_4&lt;br /&gt;
 r-01_SHG_ip_nonlinear&lt;br /&gt;
&lt;br /&gt;
The output files contain respectively the first, second, third and fourth order response(corresponding to &amp;lt;code&amp;gt;Xorder=4&amp;lt;/code&amp;gt;)  at the 12 frequencies in the chosen range. &lt;br /&gt;
 &lt;br /&gt;
Inspect &amp;lt;code&amp;gt;o-01_SHG_ip.YPP-X_probe_order_2&amp;lt;/code&amp;gt;&lt;br /&gt;
 #     E [eV]            X/Im[cm/stV](x)    X/Re[cm/stV](x)    X/Im[cm/stV](y)    X/Re[cm/stV](y)    X/Im[cm/stV](z)    X/Re[cm/stV](z)&lt;br /&gt;
 #&lt;br /&gt;
      0.50000000        -0.35378838E-09    -0.19774796E-07     0.23591828E-09    -0.89405637E-09      0.0000000          0.0000000    &lt;br /&gt;
      1.1250000         -0.19356524E-08    -0.23160605E-07    -0.16052184E-09    -0.67662771E-09      0.0000000          0.0000000    &lt;br /&gt;
      1.7500000         -0.69446459E-08    -0.35586956E-07    -0.76025706E-09    -0.10205678E-08      0.0000000          0.0000000    &lt;br /&gt;
      2.37500000        -0.181606152E-7    -0.261823658E-8     0.438358596E-8     0.407915226E-8      0.00000000         0.00000000   &lt;br /&gt;
&lt;br /&gt;
The first column are the frequencies of the applied field, the second and third is the polarization along x (imaginary and real part), the fourth and fifth is the polarization along y (imaginary and real part)  &lt;br /&gt;
and the sixth and seventh is the polarization along z (imaginary and real part).&lt;br /&gt;
&lt;br /&gt;
Plot the absolute value of the SHG for the &amp;quot;xxy&amp;quot; component (that is, the applied field is in the x and y directions and one look at the polarization along x):&lt;br /&gt;
&lt;br /&gt;
 set ylabel &amp;quot;{/Symbol=26 \174}{/Symbol=26 c}_{xyx}^{(2)}{/Symbol=26 \174} (pm/V)&amp;quot; offset -0.7&lt;br /&gt;
 set xlabel &amp;quot;Energy (eV)&amp;quot;&lt;br /&gt;
 pmVm1toCGS=2.38721e-09&lt;br /&gt;
 plot &#039;01_SHG_ip_files/o-01_SHG_ip.YPP-X_probe_order_2&#039; u 1:(sqrt($2**2+$3**2)/pmVm1toCGS) w p title &amp;quot;calc&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[File: SHG_intensity_of_2D_h-BN_obtained_from_the_previous_run_(and_compared_with_a_run_on_112_frequencies).png | SHG_intensity_of_2D_h-BN obtained from the current run (12 frequencies) compared with a run with 112 frequencies]] &lt;br /&gt;
&lt;br /&gt;
In the figure above, the results of the current run are compared with those for a run with 112 frequencies (one can obtain these results by repeating the calculations, changing the number of frequencies in &amp;lt;code&amp;gt;NLEnSteps&amp;lt;/code&amp;gt; though this take about 10 times more computational time than the run with 12). One can notice some differences between the two runs. In fact, the two runs evaluate different frequnecies and the difference indicates spurious oscillations of the value of the polarizability due to the simulation time being too short and thus to the presence of &#039;noise&#039; due to the eigenfrecies.  &lt;br /&gt;
As an exercise, you can repeat the simulation for e,g, a time of &amp;lt;code&amp;gt;60 fs&amp;lt;/code&amp;gt;, that is setting &amp;lt;code&amp;gt;NLtime=60&amp;lt;/code&amp;gt;. The plot below compare the SHG extracted at 42 fs and 60 fs, where the latter gives clearly more accurate results. &lt;br /&gt;
&lt;br /&gt;
[[File:Comparison of the SHG intensity of 2D h-BN obtained with different simulation time.png|Comparison of the SHG intensity of 2D h-BN obtained with different simulation time]]&lt;br /&gt;
&lt;br /&gt;
As a final note, the SHG depends on the size of the vacuum added in the supercell. Instead, one should consider the surface SHG which obtained by considering an effective thickness for the layer. This is usually chosen to be similar to the layer separation in the bulk counterpart.&lt;br /&gt;
&lt;br /&gt;
= Step 3: Hartree+Screened exchange approximation (BSE level) =&lt;br /&gt;
&lt;br /&gt;
== Hartree+Screened exchange collisions ==&lt;br /&gt;
Similarly to the linear part, one needs to generate the Screened exchange collisions. The procedure is exactly the same.&lt;br /&gt;
&lt;br /&gt;
Create the input:&lt;br /&gt;
 yambo_nl -X s -e -v hsex -F 03_coll_hsex.in&lt;br /&gt;
modify the input ad follows&lt;br /&gt;
 em1s                             # [R][Xs] Statically Screened Interaction&lt;br /&gt;
 collisions                       # [R] Collisions&lt;br /&gt;
 dipoles                          # [R] Oscillator strenghts (or dipoles)&lt;br /&gt;
 Chimod= &amp;quot;HARTREE&amp;quot;                # [X] IP/Hartree/ALDA/LRC/PF/BSfxc&lt;br /&gt;
 % BndsRnXs&lt;br /&gt;
    1 |  20 |                         # [Xs] Polarization function bands&lt;br /&gt;
 %&lt;br /&gt;
 NGsBlkXs= 1000 mHa    # [Xs] Response block size&lt;br /&gt;
 % LongDrXs&lt;br /&gt;
  1.000000 | 1.000000 | 0.000000 |        # [Xs] [cc] Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 % COLLBands&lt;br /&gt;
    4 |  5 |                         # [COLL] Bands for the collisions&lt;br /&gt;
 %&lt;br /&gt;
 HXC_Potential= &amp;quot;SEX+HARTREE&amp;quot;     # [SC] SC HXC Potential&lt;br /&gt;
 HARRLvcs= 1000 mHa    # [HA] Hartree     RL components&lt;br /&gt;
 EXXRLvcs= 1000 mHa    # [XX] Exchange    RL components&lt;br /&gt;
 CORRLvcs= 1000 mHa    # [GW] Correlation RL components&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Calculate the collisions (you may want to run in parallel):&lt;br /&gt;
 yambo_nl -F 03_coll_hsex.in -J 03_coll -C 04_hsex_files&lt;br /&gt;
&lt;br /&gt;
== Run the simulation ==&lt;br /&gt;
&lt;br /&gt;
Create the input:&lt;br /&gt;
 yambo_nl -nl n -v hsex -V qp -F 04_SHG_hsex.in&lt;br /&gt;
&lt;br /&gt;
modify the following parts of the input (by this time all the innput variables should be known from the previous exercises):&lt;br /&gt;
&lt;br /&gt;
 % BndsRnXs&lt;br /&gt;
   1 |  20 |                         # [Xs] Polarization function bands&lt;br /&gt;
 %&lt;br /&gt;
 NGsBlkXs= 1000 mHa    # [Xs] Response block size&lt;br /&gt;
 % LongDrXs&lt;br /&gt;
  1.000000 | 1.000000 | 0.000000 |        # [Xs] [cc] Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 % NLBands&lt;br /&gt;
    4 |  5 |                         # [NL] Bands range&lt;br /&gt;
 %&lt;br /&gt;
&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;SEX&amp;quot;             # [NL] Correlation (&amp;quot;IPA/HARTREE/TDDFT/LRC/LRW/JGM/SEX&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 % NLEnRange&lt;br /&gt;
  0.500000 |8.000000 |         eV    # [NL] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 NLEnSteps= 12                   # [NL] Energy steps&lt;br /&gt;
&lt;br /&gt;
 % GfnQP_E&lt;br /&gt;
  3.000000 | 1.000000 | 1.000000 |        # [EXTQP G] E parameters  (c/v) eV|adim|adim&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
 Field1_kind= &amp;quot;SIN&amp;quot;           # [RT Field1] Kind(SIN|COS|RES|ANTIRES|GAUSS|DELTA|QSSIN)&lt;br /&gt;
&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
  1.000000 | 1.000000 | 0.000000 |        # [RT Field1] Versor&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
Then run the simulation using e.g. mpi and 4 cores:&lt;br /&gt;
 mpirun -n 4 yambo_nl -F 04_SHG_hsex.in -J 04_SHG_hsex,03_coll -C 04_SHG_hsex_files&lt;br /&gt;
&lt;br /&gt;
== Postprocessing: obtain the nonlinear response ==&lt;br /&gt;
&lt;br /&gt;
Similarly to what we did for the independent particle case, we create the input:&lt;br /&gt;
 ypp_nl -nl -F 05_SHG_hsex_pp.in&lt;br /&gt;
 &lt;br /&gt;
we change &amp;lt;code&amp;gt;Xorder = 4 &amp;lt;/code&amp;gt; and then run:&lt;br /&gt;
 ypp_nl -F 05_SHG_hsex_pp.in -J 04_SHG_hsex -C 04_hsex_files&lt;br /&gt;
&lt;br /&gt;
Then we plot (as before we compare with a simulation ran for 112 frequencies).&lt;br /&gt;
&lt;br /&gt;
Plot the results:&lt;br /&gt;
&lt;br /&gt;
 set ylabel &amp;quot;{/Symbol=26 \174}{/Symbol=26 c}_{xyx}^{(2)}{/Symbol=26 \174} (pm/V)&amp;quot; offset -0.7&lt;br /&gt;
 set xlabel &amp;quot;Energy (eV)&amp;quot;&lt;br /&gt;
 pmVm1toCGS=2.38721e-09&lt;br /&gt;
 plot &#039;04_hsex_files/o-04_SHG_hsex.YPP-X_probe_order_2&#039; u 1:(sqrt($2**2+$3**2)/pmVm1toCGS) w p title &amp;quot;calc&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[File:SHG hsex.png|SHG at the Hartree + Screened exchange from the current run with 12 frequencies (crosses) and a run with 112 frequencies (keeping the other parameters the same)]]&lt;br /&gt;
&lt;br /&gt;
Also in this case, we note differences between the two simulations. As discussed for the independent particle approximation, this is due to the too short simulation time. Repeating the calculations with a longer time gives more accurate results. &lt;br /&gt;
In addition, note that in the interest of time, all parameters are under converged. In principle, to calculate the collisions one should use the same parameters of a converged BSE calculation. As well, to eliminate spurious interaction with the periodic images, one should use the Coulomb cut-off as it was used for this system in the [[Quasi-particles of a 2D system| tutorial on quasiparticle calculations]]. As a reference, a converged calculation for this system is in &amp;lt;ref name=&amp;quot;Gruning2014&amp;quot;&amp;gt;M. Grüning and C. Attaccalite, [https://journals.aps.org/prb/abstract/10.1103/PhysRevB.89.081102 Phys. Rev. B &#039;&#039;&#039;89&#039;&#039;&#039;, 081102]&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
= References = &lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Fulvio</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Second-harmonic_generation_of_2D-hBN&amp;diff=7002</id>
		<title>Second-harmonic generation of 2D-hBN</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Second-harmonic_generation_of_2D-hBN&amp;diff=7002"/>
		<updated>2023-05-25T09:41:18Z</updated>

		<summary type="html">&lt;p&gt;Fulvio: /* Step 2: Independent-particle approximation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Step 0: Theoretical framework =&lt;br /&gt;
&lt;br /&gt;
In this tutorial, we compute the Second-harmonic generation (SHG) from the dynamics of the Bloch-states. The equation-of-motion of the Bloch-states is explained in the tutorial on [[Linear response from Bloch-states dynamics]]. Independently of the &#039;experiment&#039; we simulate, the part of the integration of motion stays the same. This means that any experiment, including non-linear optics, can be performed at the level of the theory listed for the computation of the dielectric function:&lt;br /&gt;
* independent (quasi)particle&lt;br /&gt;
* time-dependent Hartree (RPA level)&lt;br /&gt;
* time-dependent DFT (and DPFT)&lt;br /&gt;
* time-dependent Hartree+Screened exchange (BSE level)&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
What changes when we want to calculate the SHG (or higher harmonics) is:&lt;br /&gt;
* the time-dependence of the input electric field and&lt;br /&gt;
* the post-processing of the signal  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Time dependence of the electric Field&#039;&#039;&#039;: we choose a sinusoidal electric field, thus a monochromatic laser field. This allows one to expand the polarization in the form &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; through a coefficient depending on a power of the strength of the field (with the power depending on the order of the response).&lt;br /&gt;
&lt;br /&gt;
At difference with a delta-like perturbation, a real-time simulation gives the response at the laser-field only. Then, to obtain the spectrum for the desired range of frequency, we have to perform so many simulations as the frequencies in the desired range.  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Post-processing of the signal&#039;&#039;&#039;: The switch-on of the electric field corresponds to a weak delta-like kick. Thus, even if it may not be noticeable, the polarization results from both the sinusoidal field and the delta-like kick. The latter excites all eigenfrequencies of the system. Though weak, the resulting signal is comparable with the second-harmonic signal. To eliminate the signal from the eigenfrequencies, we apply a dephasing (&amp;lt;math&amp;gt;\gamma_{deph}&amp;lt;/math&amp;gt;). To have a signal useful to sample the second-harmonic signal, we need to wait a time &amp;lt;math&amp;gt;\bar t&amp;lt;/math&amp;gt;  much larger than the dephasing-time &amp;lt;math&amp;gt;1/\gamma_{deph} &amp;lt;/math&amp;gt;. Note that we cannot choose a too short dephasing time (to shorten the simulation time), as this would result in a too large broadening of the spectrum. After &amp;lt;math&amp;gt;\bar t&amp;lt;/math&amp;gt;, we sample $2N+1$ times in a period and use discrete Fourier transform to extract &amp;lt;math&amp;gt;{p}_n&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt; n = 0,...,N&amp;lt;/math&amp;gt;, where n=2 gives the SHG. This is schematically illustrated in figure:&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;
The scheme from Ref. &amp;lt;ref name=&amp;quot;Attaccalite2013&amp;quot;&amp;gt;C. Attaccalite and M. Gruning [https://arxiv.org/abs/1309.4012v2 Rev. B, &#039;&#039;&#039;88&#039;&#039;&#039;, 235113 (2013)]&amp;lt;/ref&amp;gt; summarised the workflow for computing the SHG (or higher-harmonics) in a energy range &amp;lt;math&amp;gt;[\Omega_1,\Omega_2]&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
[[File:Scheme nl.png|350px|center|Schematic representation of real-time calculations]]&lt;br /&gt;
&lt;br /&gt;
= Step 1: Prerequisites =&lt;br /&gt;
&lt;br /&gt;
In this example, we will consider a single layer of hexagonal boron nitride (hBN). Before running real time simulations to compute the SHG in &amp;lt;code&amp;gt;yambo&amp;lt;/code&amp;gt; you need to download input files and Yambo databases for this tutorial here: [wget https://media.yambo-code.eu/educational/tutorials/files/hBN-2D.tar.gz hBN-2D.tar.gz].&lt;br /&gt;
Unzip the tarball and change directory to &amp;lt;code&amp;gt;YAMBO&amp;lt;/code&amp;gt; and run the setup (&amp;lt;code&amp;gt;yambo_nl -nompi&amp;lt;/code&amp;gt;). &lt;br /&gt;
Execute the command &lt;br /&gt;
 ypp_nl -fixsym -F 00_removesym.in  &lt;br /&gt;
to create the input, to remove the symmetries which are not compatible with the field: &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;1.000000 | 1.000000 | 0.000000 |&amp;lt;/span&amp;gt;        # First external Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 % Efield2&lt;br /&gt;
  0.000000 | 0.000000 | 0.000000 |        # 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;
 #KeepKGrid                     # Do not expand the k-grid&lt;br /&gt;
where we chose the field along the xy direction and we remove time-reversal symmetry.&lt;br /&gt;
&lt;br /&gt;
Then run the pre-processing job:&lt;br /&gt;
 ypp_nl -F 00_removesym.in J 00_removesym&lt;br /&gt;
This creates the directory &amp;lt;code&amp;gt;FixSymm&amp;lt;/code&amp;gt;. Change directory to &amp;lt;code&amp;gt;FixSymm&amp;lt;/code&amp;gt;. This contains the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory with reduced symmetries, compatible with the direction of the field. Now run the setup again (&amp;lt;code&amp;gt;yambo_nl -nompi&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
= Step 2: Independent-particle approximation =&lt;br /&gt;
&lt;br /&gt;
Use the command:&lt;br /&gt;
  yambo_nl -nl n -F 01_SHG_ip.in&lt;br /&gt;
to generate the input:&lt;br /&gt;
&lt;br /&gt;
 nloptics                         # [R] Non-linear spectroscopy&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=-1.000000           fs    # [NL] Simulation Time&lt;br /&gt;
 NLintegrator= &amp;quot;INVINT&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;
 % NLEnRange&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;0.5000000 |8.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;12&amp;lt;/span&amp;gt;                     # [NL] Energy steps&lt;br /&gt;
 NLDamping= 0.200000        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= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;1000            mHa&amp;lt;/span&amp;gt;   # [HA] Hartree     RL components&lt;br /&gt;
 EXXRLvcs= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;1000            mHa&amp;lt;/span&amp;gt;    # [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;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&amp;quot;SIN&amp;quot; &amp;lt;/span&amp;gt;          # [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 | 1.000000 | 0.000000 |&amp;lt;/span&amp;gt;        # [RT Field1] Versor&lt;br /&gt;
 %&lt;br /&gt;
 Field1_Tstart= 0.010000    fs    # [RT Field1] Initial Time&lt;br /&gt;
&lt;br /&gt;
To describe the Bloch-dynamics we will use as a basis the KS-states 3-6 for the k-grid used in the non-scf DFT calculations, that is a 6x6x1 (&amp;lt;code&amp;gt;NLBands&amp;lt;/code&amp;gt;). We choose 12 equally spaced frequencies (&amp;lt;code&amp;gt;NLEnSteps&amp;lt;/code&amp;gt;) for the applied field in the range  (&amp;lt;code&amp;gt;NLEnRange&amp;lt;/code&amp;gt;) between 0.5 and 8 eV. We choose a sinusoidal time-dependence (&amp;lt;code&amp;gt;Field1_kind&amp;lt;/code&amp;gt;) and set the field direction (&amp;lt;code&amp;gt;Field1_kind&amp;lt;/code&amp;gt;) along xy (in plane). The negative simulation time (&amp;lt;code&amp;gt;NLtime=-1.000000&amp;lt;/code&amp;gt;) means that the code will choose it based on the value of the &amp;lt;code&amp;gt;NLDamping&amp;lt;/code&amp;gt;. While this is a good lower bound for the simulation time, one should check it is sufficient to get accurate results. &lt;br /&gt;
&lt;br /&gt;
Run the simulation, possibly in parallel e. g. in a interactive session on 4 cores. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;[In order to get 4 cores while in an interacting node, exit your current allocation and rerun &amp;lt;code&amp;gt;salloc&amp;lt;/code&amp;gt; asking for the proper number of tasks:&#039;&#039;&#039;&lt;br /&gt;
 salloc -A tra23_Yambo -p m100_usr_prod -q m100_qos_dbg --nodes=1 --ntasks-per-node=&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;4&amp;lt;/span&amp;gt; --cpus-per-task=4 -t 02:00:00&lt;br /&gt;
&#039;&#039;&#039;Otherwise, you can submit the job with a slurm script as explained in the introductory page]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now execute the command:&lt;br /&gt;
  mpirun -n 4 yambo_nl -F 01_SHG_ip.in -J 01_SHG_ip -C 01_SHG_ip_files&lt;br /&gt;
&lt;br /&gt;
This run will take several minutes. While it is running, you can check the progress of one specific frequency:&lt;br /&gt;
 tail -f 01_SHG_ip_files/o-01_SHG_ip.polarization_F2&lt;br /&gt;
If you want to know how many fs the simulation will last (since this was decided by the code), you can get this information in the report file:&lt;br /&gt;
 $ grep Total 01_SHG_ip_files/r-01_SHG_ip_nloptics&lt;br /&gt;
 Total simulation time       :  41.23193 [fs]&lt;br /&gt;
If you instead want to track the progress of the full simulation, you should check the log file(s). If you are doing a parallel run, you can type&lt;br /&gt;
 tail -f 01_SHG_ip_files/LOG/l-01_SHG_ip_nloptics_CPU_1&lt;br /&gt;
&lt;br /&gt;
Once the run is finished, check the report &amp;lt;code&amp;gt;01_SHG_ip_files/r-01_SHG_ip_nloptics&amp;lt;/code&amp;gt;. In particular, in the appended input files, you can see the default parallelization applied by the code for calculating the dipoles and run the time-propagation. For the latter, the main parallelization is on the frequencies and then on the k-points (&amp;lt;code&amp;gt;NL_ROLEs= &amp;quot;w.k&amp;quot;&amp;lt;/code&amp;gt;).   &lt;br /&gt;
&lt;br /&gt;
 | NL_CPU= &amp;quot;2.2&amp;quot;                    # [PARALLEL] CPUs for each role&lt;br /&gt;
 | NL_ROLEs= &amp;quot;w.k&amp;quot;                  # [PARALLEL] CPUs roles (w,k)&lt;br /&gt;
 | DIP_CPU= &amp;quot;2.2.1&amp;quot;                 # [PARALLEL] CPUs for each role&lt;br /&gt;
 | DIP_ROLEs= &amp;quot;v.c.k&amp;quot;               # [PARALLEL] CPUs roles (k,c,v)&lt;br /&gt;
&lt;br /&gt;
Also, look at the simulation time. This is approximately 42 fs. &lt;br /&gt;
&lt;br /&gt;
Plot the polarization for a couple of frequencies, e.g. the first and last of the chosen range (the corresponding frequency can be read in the file, search for &amp;quot;Frequency value&amp;quot;):&lt;br /&gt;
 set ylabel &amp;quot;x-component polarization&amp;quot; offset -0.7&lt;br /&gt;
 set xlabel &amp;quot;time (fs)&amp;quot;&lt;br /&gt;
 plot &#039;01_SHG_ip_files/o-01_SHG_ip.polarization_F1&#039; u 1:2 w l lw 2 title &amp;quot;omega = 0.5 eV&amp;quot;&lt;br /&gt;
 replot &#039;01_SHG_ip_files/o-01_SHG_ip.polarization_F12&#039; u 1:2 w l lw 2  title &amp;quot;omega = 7.375 eV&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[File:Berry_phase_polarization_of_2D_h-BN_obtained_from_the_previous_run_for_two_laser_frequencies.png|Berry_phase_polarization_of_2D_h-BN_obtained from the run for two laser frequencies]]&lt;br /&gt;
&lt;br /&gt;
After the applied field is &#039;switched on&#039;, the polarization is oscillating at the frequency of the applied field and at the eigenfrequencies of the system as described above in the cartoon. This is visible particularly for the higher frequency. Due to the dephasing, after about 20 fs the polarization is oscillating (at least to the eye) at the frequency of the applied field. Nonlinear components are not visible since they are several orders of magnitude smaller than the first order.&lt;br /&gt;
&lt;br /&gt;
== Output post-processing: the dielectric function ==&lt;br /&gt;
&lt;br /&gt;
Once we obtained the polarization, we Fourier-transform the polarization to obtain the dielectric function.&lt;br /&gt;
&lt;br /&gt;
Use the command:&lt;br /&gt;
&lt;br /&gt;
  ypp_nl -nl -F 02_SHG_ip_pp.in -C 01_SHG_ip_files&lt;br /&gt;
&lt;br /&gt;
to generate the input file: &lt;br /&gt;
&lt;br /&gt;
 nonlinear                        # [R] Non-linear response analysis&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;Xorder= 4&amp;lt;/span&amp;gt; # 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;NONE&amp;quot;                 # Damping type ( NONE | LORENTZIAN | GAUSSIAN )&lt;br /&gt;
 DampFactor= 0.000000       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;
Where we changed the &amp;lt;code&amp;gt;Xorder&amp;lt;/code&amp;gt; to 4. This variable controls the terms in the Fourier expansion of the polarization. We choose up to expand up to the fourth order. This should ensure the second order to be accurate enough. As an exercise, you can change this value (e.g. choose 2,3,5,6) and see how the result below is changing. The time-window where processing is done is chosen automatically, since values are negative. The code chooses by default the last period to carry out the analysis. &lt;br /&gt;
&lt;br /&gt;
To run the post-processing, use the command:&lt;br /&gt;
 ypp_nl -F Inputs_shg/ypp_shg.in -J TD-IP_nl -C TD-IP_nl. &lt;br /&gt;
   &lt;br /&gt;
In  &amp;lt;code&amp;gt;01_SHG_ip_files&amp;lt;/code&amp;gt; the following files were generated &lt;br /&gt;
 o-01_SHG_ip.YPP-X_probe_order_1&lt;br /&gt;
 o-01_SHG_ip.YPP-X_probe_order_2&lt;br /&gt;
 o-01_SHG_ip.YPP-X_probe_order_3&lt;br /&gt;
 o-01_SHG_ip.YPP-X_probe_order_4&lt;br /&gt;
 r-01_SHG_ip_nonlinear&lt;br /&gt;
&lt;br /&gt;
The output files contain respectively the first, second, third and fourth order response(corresponding to &amp;lt;code&amp;gt;Xorder=4&amp;lt;/code&amp;gt;)  at the 12 frequencies in the chosen range. &lt;br /&gt;
 &lt;br /&gt;
Inspect &amp;lt;code&amp;gt;o-01_SHG_ip.YPP-X_probe_order_2&amp;lt;/code&amp;gt;&lt;br /&gt;
 #     E [eV]            X/Im[cm/stV](x)    X/Re[cm/stV](x)    X/Im[cm/stV](y)    X/Re[cm/stV](y)    X/Im[cm/stV](z)    X/Re[cm/stV](z)&lt;br /&gt;
 #&lt;br /&gt;
      0.50000000        -0.35378838E-09    -0.19774796E-07     0.23591828E-09    -0.89405637E-09      0.0000000          0.0000000    &lt;br /&gt;
      1.1250000         -0.19356524E-08    -0.23160605E-07    -0.16052184E-09    -0.67662771E-09      0.0000000          0.0000000    &lt;br /&gt;
      1.7500000         -0.69446459E-08    -0.35586956E-07    -0.76025706E-09    -0.10205678E-08      0.0000000          0.0000000    &lt;br /&gt;
      2.37500000        -0.181606152E-7    -0.261823658E-8     0.438358596E-8     0.407915226E-8      0.00000000         0.00000000   &lt;br /&gt;
&lt;br /&gt;
The first column are the frequencies of the applied field, the second and third is the polarization along x (imaginary and real part), the fourth and fifth is the polarization along y (imaginary and real part)  &lt;br /&gt;
and the sixth and seventh is the polarization along z (imaginary and real part).&lt;br /&gt;
&lt;br /&gt;
Plot the absolute value of the SHG for the &amp;quot;xxy&amp;quot; component (that is, the applied field is in the x and y directions and one look at the polarization along x):&lt;br /&gt;
&lt;br /&gt;
 set ylabel &amp;quot;{/Symbol=26 \174}{/Symbol=26 c}_{xyx}^{(2)}{/Symbol=26 \174} (pm/V)&amp;quot; offset -0.7&lt;br /&gt;
 set xlabel &amp;quot;Energy (eV)&amp;quot;&lt;br /&gt;
 pmVm1toCGS=2.38721e-09&lt;br /&gt;
 plot &#039;01_SHG_ip_files/o-01_SHG_ip.YPP-X_probe_order_2&#039; u 1:(sqrt($2**2+$3**2)/pmVm1toCGS) w p title &amp;quot;calc&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[File: SHG_intensity_of_2D_h-BN_obtained_from_the_previous_run_(and_compared_with_a_run_on_112_frequencies).png | SHG_intensity_of_2D_h-BN obtained from the current run (12 frequencies) compared with a run with 112 frequencies]] &lt;br /&gt;
&lt;br /&gt;
In the figure above, the results of the current run are compared with those for a run with 112 frequencies (one can obtain these results by repeating the calculations, changing the number of frequencies in &amp;lt;code&amp;gt;NLEnSteps&amp;lt;/code&amp;gt; though this take about 10 times more computational time than the run with 12). One can notice some differences between the two runs. In fact, the two runs evaluate different frequnecies and the difference indicates spurious oscillations of the value of the polarizability due to the simulation time being too short and thus to the presence of &#039;noise&#039; due to the eigenfrecies.  &lt;br /&gt;
As an exercise, you can repeat the simulation for e,g, a time of &amp;lt;code&amp;gt;60 fs&amp;lt;/code&amp;gt;, that is setting &amp;lt;code&amp;gt;NLtime=60&amp;lt;/code&amp;gt;. The plot below compare the SHG extracted at 42 fs and 60 fs, where the latter gives clearly more accurate results. &lt;br /&gt;
&lt;br /&gt;
[[File:Comparison of the SHG intensity of 2D h-BN obtained with different simulation time.png|Comparison of the SHG intensity of 2D h-BN obtained with different simulation time]]&lt;br /&gt;
&lt;br /&gt;
As a final note, the SHG depends on the size of the vacuum added in the supercell. Instead, one should consider the surface SHG which obtained by considering an effective thickness for the layer. This is usually chosen to be similar to the layer separation in the bulk counterpart.&lt;br /&gt;
&lt;br /&gt;
= Step 3: Hartree+Screened exchange approximation (BSE level) =&lt;br /&gt;
&lt;br /&gt;
== Hartree+Screened exchange collisions ==&lt;br /&gt;
Similarly to the linear part, one needs to generate the Screened exchange collisions. The procedure is exactly the same.&lt;br /&gt;
&lt;br /&gt;
Create the input:&lt;br /&gt;
 yambo_nl -X s -e -v hsex -F 03_coll_hsex.in&lt;br /&gt;
modify the input ad follows&lt;br /&gt;
 em1s                             # [R][Xs] Statically Screened Interaction&lt;br /&gt;
 collisions                       # [R] Collisions&lt;br /&gt;
 dipoles                          # [R] Oscillator strenghts (or dipoles)&lt;br /&gt;
 Chimod= &amp;quot;HARTREE&amp;quot;                # [X] IP/Hartree/ALDA/LRC/PF/BSfxc&lt;br /&gt;
 % BndsRnXs&lt;br /&gt;
    1 |  20 |                         # [Xs] Polarization function bands&lt;br /&gt;
 %&lt;br /&gt;
 NGsBlkXs= 1000 mHa    # [Xs] Response block size&lt;br /&gt;
 % LongDrXs&lt;br /&gt;
  1.000000 | 1.000000 | 0.000000 |        # [Xs] [cc] Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 % COLLBands&lt;br /&gt;
    4 |  5 |                         # [COLL] Bands for the collisions&lt;br /&gt;
 %&lt;br /&gt;
 HXC_Potential= &amp;quot;SEX+HARTREE&amp;quot;     # [SC] SC HXC Potential&lt;br /&gt;
 HARRLvcs= 1000 mHa    # [HA] Hartree     RL components&lt;br /&gt;
 EXXRLvcs= 1000 mHa    # [XX] Exchange    RL components&lt;br /&gt;
 CORRLvcs= 1000 mHa    # [GW] Correlation RL components&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Calculate the collisions (you may want to run in parallel):&lt;br /&gt;
 yambo_nl -F 03_coll_hsex.in -J 03_coll -C 04_hsex_files&lt;br /&gt;
&lt;br /&gt;
== Run the simulation ==&lt;br /&gt;
&lt;br /&gt;
Create the input:&lt;br /&gt;
 yambo_nl -nl n -v hsex -V qp -F 04_SHG_hsex.in&lt;br /&gt;
&lt;br /&gt;
modify the following parts of the input (by this time all the innput variables should be known from the previous exercises):&lt;br /&gt;
&lt;br /&gt;
 % BndsRnXs&lt;br /&gt;
   1 |  20 |                         # [Xs] Polarization function bands&lt;br /&gt;
 %&lt;br /&gt;
 NGsBlkXs= 1000 mHa    # [Xs] Response block size&lt;br /&gt;
 % LongDrXs&lt;br /&gt;
  1.000000 | 1.000000 | 0.000000 |        # [Xs] [cc] Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 % NLBands&lt;br /&gt;
    4 |  5 |                         # [NL] Bands range&lt;br /&gt;
 %&lt;br /&gt;
&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;SEX&amp;quot;             # [NL] Correlation (&amp;quot;IPA/HARTREE/TDDFT/LRC/LRW/JGM/SEX&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 % NLEnRange&lt;br /&gt;
  0.500000 |8.000000 |         eV    # [NL] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 NLEnSteps= 12                   # [NL] Energy steps&lt;br /&gt;
&lt;br /&gt;
 % GfnQP_E&lt;br /&gt;
  3.000000 | 1.000000 | 1.000000 |        # [EXTQP G] E parameters  (c/v) eV|adim|adim&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
 Field1_kind= &amp;quot;SIN&amp;quot;           # [RT Field1] Kind(SIN|COS|RES|ANTIRES|GAUSS|DELTA|QSSIN)&lt;br /&gt;
&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
  1.000000 | 1.000000 | 0.000000 |        # [RT Field1] Versor&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
Then run the simulation using e.g. mpi and 4 cores:&lt;br /&gt;
 mpirun -n 4 yambo_nl -F 04_SHG_hsex.in -J 04_SHG_hsex,03_coll -C 04_SHG_hsex_files&lt;br /&gt;
&lt;br /&gt;
== Postprocessing: obtain the nonlinear response ==&lt;br /&gt;
&lt;br /&gt;
Similarly to what we did for the independent particle case, we create the input:&lt;br /&gt;
 ypp_nl -nl -F 05_SHG_hsex_pp.in&lt;br /&gt;
 &lt;br /&gt;
we change &amp;lt;code&amp;gt;Xorder = 4 &amp;lt;/code&amp;gt; and then run:&lt;br /&gt;
 ypp_nl -F 05_SHG_hsex_pp.in -J 04_SHG_hsex -C 04_hsex_files&lt;br /&gt;
&lt;br /&gt;
Then we plot (as before we compare with a simulation ran for 112 frequnecies).&lt;br /&gt;
&lt;br /&gt;
Plot the results:&lt;br /&gt;
&lt;br /&gt;
 set ylabel &amp;quot;{/Symbol=26 \174}{/Symbol=26 c}_{xyx}^{(2)}{/Symbol=26 \174} (pm/V)&amp;quot; offset -0.7&lt;br /&gt;
 set xlabel &amp;quot;Energy (eV)&amp;quot;&lt;br /&gt;
 pmVm1toCGS=2.38721e-09&lt;br /&gt;
 plot &#039;04_hsex_files/o-04_SHG_hsex.YPP-X_probe_order_2&#039; u 1:(sqrt($2**2+$3**2)/pmVm1toCGS) w p title &amp;quot;calc&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[File:SHG hsex.png|SHG at the Hartree + Screened exchange from current run with 12 frequencies (crosses) and a run with 112 frequencies (keeping the other parameters the same)]]&lt;br /&gt;
&lt;br /&gt;
also in this case we note differences between the two simulations. This is due to the too short simulation time. Repeating the calculations with a longer time gives more accurate results. &lt;br /&gt;
In addition, note that in the interest of time, all parameters are underconverged. In principle, to calculate the collisions one should use the same parameters of a converged BSE calculation. As well, one should use the Coulomb cutoff as it was used for this system in the  BSE case.&lt;br /&gt;
&lt;br /&gt;
= References = &lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Fulvio</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Second-harmonic_generation_of_2D-hBN&amp;diff=7001</id>
		<title>Second-harmonic generation of 2D-hBN</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Second-harmonic_generation_of_2D-hBN&amp;diff=7001"/>
		<updated>2023-05-25T09:05:54Z</updated>

		<summary type="html">&lt;p&gt;Fulvio: /* Step 2: Independent-particle approximation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Step 0: Theoretical framework =&lt;br /&gt;
&lt;br /&gt;
In this tutorial, we compute the Second-harmonic generation (SHG) from the dynamics of the Bloch-states. The equation-of-motion of the Bloch-states is explained in the tutorial on [[Linear response from Bloch-states dynamics]]. Independently of the &#039;experiment&#039; we simulate, the part of the integration of motion stays the same. This means that any experiment, including non-linear optics, can be performed at the level of the theory listed for the computation of the dielectric function:&lt;br /&gt;
* independent (quasi)particle&lt;br /&gt;
* time-dependent Hartree (RPA level)&lt;br /&gt;
* time-dependent DFT (and DPFT)&lt;br /&gt;
* time-dependent Hartree+Screened exchange (BSE level)&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
What changes when we want to calculate the SHG (or higher harmonics) is:&lt;br /&gt;
* the time-dependence of the input electric field and&lt;br /&gt;
* the post-processing of the signal  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Time dependence of the electric Field&#039;&#039;&#039;: we choose a sinusoidal electric field, thus a monochromatic laser field. This allows one to expand the polarization in the form &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; through a coefficient depending on a power of the strength of the field (with the power depending on the order of the response).&lt;br /&gt;
&lt;br /&gt;
At difference with a delta-like perturbation, a real-time simulation gives the response at the laser-field only. Then, to obtain the spectrum for the desired range of frequency, we have to perform so many simulations as the frequencies in the desired range.  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Post-processing of the signal&#039;&#039;&#039;: The switch-on of the electric field corresponds to a weak delta-like kick. Thus, even if it may not be noticeable, the polarization results from both the sinusoidal field and the delta-like kick. The latter excites all eigenfrequencies of the system. Though weak, the resulting signal is comparable with the second-harmonic signal. To eliminate the signal from the eigenfrequencies, we apply a dephasing (&amp;lt;math&amp;gt;\gamma_{deph}&amp;lt;/math&amp;gt;). To have a signal useful to sample the second-harmonic signal, we need to wait a time &amp;lt;math&amp;gt;\bar t&amp;lt;/math&amp;gt;  much larger than the dephasing-time &amp;lt;math&amp;gt;1/\gamma_{deph} &amp;lt;/math&amp;gt;. Note that we cannot choose a too short dephasing time (to shorten the simulation time), as this would result in a too large broadening of the spectrum. After &amp;lt;math&amp;gt;\bar t&amp;lt;/math&amp;gt;, we sample $2N+1$ times in a period and use discrete Fourier transform to extract &amp;lt;math&amp;gt;{p}_n&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt; n = 0,...,N&amp;lt;/math&amp;gt;, where n=2 gives the SHG. This is schematically illustrated in figure:&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;
The scheme from Ref. &amp;lt;ref name=&amp;quot;Attaccalite2013&amp;quot;&amp;gt;C. Attaccalite and M. Gruning [https://arxiv.org/abs/1309.4012v2 Rev. B, &#039;&#039;&#039;88&#039;&#039;&#039;, 235113 (2013)]&amp;lt;/ref&amp;gt; summarised the workflow for computing the SHG (or higher-harmonics) in a energy range &amp;lt;math&amp;gt;[\Omega_1,\Omega_2]&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
[[File:Scheme nl.png|350px|center|Schematic representation of real-time calculations]]&lt;br /&gt;
&lt;br /&gt;
= Step 1: Prerequisites =&lt;br /&gt;
&lt;br /&gt;
In this example, we will consider a single layer of hexagonal boron nitride (hBN). Before running real time simulations to compute the SHG in &amp;lt;code&amp;gt;yambo&amp;lt;/code&amp;gt; you need to download input files and Yambo databases for this tutorial here: [wget https://media.yambo-code.eu/educational/tutorials/files/hBN-2D.tar.gz hBN-2D.tar.gz].&lt;br /&gt;
Unzip the tarball and change directory to &amp;lt;code&amp;gt;YAMBO&amp;lt;/code&amp;gt; and run the setup (&amp;lt;code&amp;gt;yambo_nl -nompi&amp;lt;/code&amp;gt;). &lt;br /&gt;
Execute the command &lt;br /&gt;
 ypp_nl -fixsym -F 00_removesym.in  &lt;br /&gt;
to create the input, to remove the symmetries which are not compatible with the field: &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;1.000000 | 1.000000 | 0.000000 |&amp;lt;/span&amp;gt;        # First external Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 % Efield2&lt;br /&gt;
  0.000000 | 0.000000 | 0.000000 |        # 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;
 #KeepKGrid                     # Do not expand the k-grid&lt;br /&gt;
where we chose the field along the xy direction and we remove time-reversal symmetry.&lt;br /&gt;
&lt;br /&gt;
Then run the pre-processing job:&lt;br /&gt;
 ypp_nl -F 00_removesym.in J 00_removesym&lt;br /&gt;
This creates the directory &amp;lt;code&amp;gt;FixSymm&amp;lt;/code&amp;gt;. Change directory to &amp;lt;code&amp;gt;FixSymm&amp;lt;/code&amp;gt;. This contains the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory with reduced symmetries, compatible with the direction of the field. Now run the setup again (&amp;lt;code&amp;gt;yambo_nl -nompi&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
= Step 2: Independent-particle approximation =&lt;br /&gt;
&lt;br /&gt;
Use the command:&lt;br /&gt;
  yambo_nl -nl n -F 01_SHG_ip.in&lt;br /&gt;
to generate the input:&lt;br /&gt;
&lt;br /&gt;
 nloptics                         # [R] Non-linear spectroscopy&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=-1.000000           fs    # [NL] Simulation Time&lt;br /&gt;
 NLintegrator= &amp;quot;INVINT&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;
 % NLEnRange&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;0.5000000 |8.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;12&amp;lt;/span&amp;gt;                     # [NL] Energy steps&lt;br /&gt;
 NLDamping= 0.200000        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;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&amp;quot;SIN&amp;quot; &amp;lt;/span&amp;gt;          # [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 | 1.000000 | 0.000000 |&amp;lt;/span&amp;gt;        # [RT Field1] Versor&lt;br /&gt;
 %&lt;br /&gt;
 Field1_Tstart= 0.010000    fs    # [RT Field1] Initial Time&lt;br /&gt;
&lt;br /&gt;
To describe the Bloch-dynamics we will use as a basis the KS-states 3-6 for the k-grid used in the non-scf DFT calculations, that is a 6x6x1 (&amp;lt;code&amp;gt;NLBands&amp;lt;/code&amp;gt;). We choose 12 equally spaced frequencies (&amp;lt;code&amp;gt;NLEnSteps&amp;lt;/code&amp;gt;) for the applied field in the range  (&amp;lt;code&amp;gt;NLEnRange&amp;lt;/code&amp;gt;) between 0.5 and 8 eV. We choose a sinusoidal time-dependence (&amp;lt;code&amp;gt;Field1_kind&amp;lt;/code&amp;gt;) and set the field direction (&amp;lt;code&amp;gt;Field1_kind&amp;lt;/code&amp;gt;) along xy (in plane). The negative simulation time (&amp;lt;code&amp;gt;NLtime=-1.000000&amp;lt;/code&amp;gt;) means that the code will choose it based on the value of the &amp;lt;code&amp;gt;NLDamping&amp;lt;/code&amp;gt;. While this is a good lower bound for the simulation time, one should check it is sufficient to get accurate results. &lt;br /&gt;
&lt;br /&gt;
Run the simulation, possibly in parallel e. g. in a interactive session on 4 cores. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;[In order to get 4 cores while in an interacting node, exit your current allocation and rerun &amp;lt;code&amp;gt;salloc&amp;lt;/code&amp;gt; asking for the proper number of tasks:&#039;&#039;&#039;&lt;br /&gt;
 salloc -A tra23_Yambo -p m100_usr_prod -q m100_qos_dbg --nodes=1 --ntasks-per-node=&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;4&amp;lt;/span&amp;gt; --cpus-per-task=4 -t 02:00:00&lt;br /&gt;
&#039;&#039;&#039;Otherwise, you can submit the job with a slurm script as explained in the introductory page]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now execute the command:&lt;br /&gt;
  mpirun -n 4 yambo_nl -F 01_SHG_ip.in -J 01_SHG_ip -C 01_SHG_ip_files&lt;br /&gt;
&lt;br /&gt;
This run will take several minutes. While it is running, you can check the progress of one specific frequency:&lt;br /&gt;
 tail -f 01_SHG_ip_files/o-01_SHG_ip.polarization_F2&lt;br /&gt;
If you want to know how many fs the simulation will last (since this was decided by the code), you can get this information in the report file:&lt;br /&gt;
 $ grep Total 01_SHG_ip_files/r-01_SHG_ip_nloptics&lt;br /&gt;
 Total simulation time       :  41.23193 [fs]&lt;br /&gt;
If you instead want to track the progress of the full simulation, you should check the log file(s). If you are doing a parallel run, you can type&lt;br /&gt;
 tail -f 01_SHG_ip_files/LOG/l-01_SHG_ip_nloptics_CPU_1&lt;br /&gt;
&lt;br /&gt;
Once the run is finished, check the report &amp;lt;code&amp;gt;01_SHG_ip_files/r-01_SHG_ip_nloptics&amp;lt;/code&amp;gt;. In particular, in the appended input files, you can see the default parallelization applied by the code for calculating the dipoles and run the time-propagation. For the latter, the main parallelization is on the frequencies and then on the k-points (&amp;lt;code&amp;gt;NL_ROLEs= &amp;quot;w.k&amp;quot;&amp;lt;/code&amp;gt;).   &lt;br /&gt;
&lt;br /&gt;
 | NL_CPU= &amp;quot;2.2&amp;quot;                    # [PARALLEL] CPUs for each role&lt;br /&gt;
 | NL_ROLEs= &amp;quot;w.k&amp;quot;                  # [PARALLEL] CPUs roles (w,k)&lt;br /&gt;
 | DIP_CPU= &amp;quot;2.2.1&amp;quot;                 # [PARALLEL] CPUs for each role&lt;br /&gt;
 | DIP_ROLEs= &amp;quot;v.c.k&amp;quot;               # [PARALLEL] CPUs roles (k,c,v)&lt;br /&gt;
&lt;br /&gt;
Also, look at the simulation time. This is approximately 42 fs. &lt;br /&gt;
&lt;br /&gt;
Plot the polarization for a couple of frequencies, e.g. the first and last of the chosen range (the corresponding frequency can be read in the file, search for &amp;quot;Frequency value&amp;quot;):&lt;br /&gt;
 set ylabel &amp;quot;x-component polarization&amp;quot; offset -0.7&lt;br /&gt;
 set xlabel &amp;quot;time (fs)&amp;quot;&lt;br /&gt;
 plot &#039;01_SHG_ip_files/o-01_SHG_ip.polarization_F1&#039; u 1:2 w l lw 2 title &amp;quot;omega = 0.5 eV&amp;quot;&lt;br /&gt;
 replot &#039;01_SHG_ip_files/o-01_SHG_ip.polarization_F12&#039; u 1:2 w l lw 2  title &amp;quot;omega = 7.375 eV&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[File:Berry_phase_polarization_of_2D_h-BN_obtained_from_the_previous_run_for_two_laser_frequencies.png|Berry_phase_polarization_of_2D_h-BN_obtained from the run for two laser frequencies]]&lt;br /&gt;
&lt;br /&gt;
After the applied field is &#039;switched on&#039;, the polarization is oscillating at the frequency of the applied field and at the eigenfrequencies of the system as described above in the cartoon. This is visible particularly for the higher frequency. Due to the dephasing, after about 20 fs the polarization is oscillating (at least to the eye) at the frequency of the applied field. Nonlinear components are not visible since they are several orders of magnitude smaller than the first order.&lt;br /&gt;
&lt;br /&gt;
== Output post-processing: the dielectric function ==&lt;br /&gt;
&lt;br /&gt;
Once we obtained the polarization, we Fourier-transform the polarization to obtain the dielectric function.&lt;br /&gt;
&lt;br /&gt;
Use the command:&lt;br /&gt;
&lt;br /&gt;
  ypp_nl -nl -F 02_SHG_ip_pp.in -C 01_SHG_ip_files&lt;br /&gt;
&lt;br /&gt;
to generate the input file: &lt;br /&gt;
&lt;br /&gt;
 nonlinear                        # [R] Non-linear response analysis&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;Xorder= 4&amp;lt;/span&amp;gt; # 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;NONE&amp;quot;                 # Damping type ( NONE | LORENTZIAN | GAUSSIAN )&lt;br /&gt;
 DampFactor= 0.000000       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;
Where we changed the &amp;lt;code&amp;gt;Xorder&amp;lt;/code&amp;gt; to 4. This variable controls the terms in the Fourier expansion of the polarization. We choose up to expand up to the fourth order. This should ensure the second order to be accurate enough. As an exercise, you can change this value (e.g. choose 2,3,5,6) and see how the result below is changing. The time-window where processing is done is chosen automatically, since values are negative. The code chooses by default the last period to carry out the analysis. &lt;br /&gt;
&lt;br /&gt;
To run the post-processing, use the command:&lt;br /&gt;
 ypp_nl -F Inputs_shg/ypp_shg.in -J TD-IP_nl -C TD-IP_nl. &lt;br /&gt;
   &lt;br /&gt;
In  &amp;lt;code&amp;gt;01_SHG_ip_files&amp;lt;/code&amp;gt; the following files were generated &lt;br /&gt;
 o-01_SHG_ip.YPP-X_probe_order_1&lt;br /&gt;
 o-01_SHG_ip.YPP-X_probe_order_2&lt;br /&gt;
 o-01_SHG_ip.YPP-X_probe_order_3&lt;br /&gt;
 o-01_SHG_ip.YPP-X_probe_order_4&lt;br /&gt;
 r-01_SHG_ip_nonlinear&lt;br /&gt;
&lt;br /&gt;
The output files contain respectively the first, second, third and fourth order response(corresponding to &amp;lt;code&amp;gt;Xorder=4&amp;lt;/code&amp;gt;)  at the 12 frequencies in the chosen range. &lt;br /&gt;
 &lt;br /&gt;
Inspect &amp;lt;code&amp;gt;o-01_SHG_ip.YPP-X_probe_order_2&amp;lt;/code&amp;gt;&lt;br /&gt;
 #     E [eV]            X/Im[cm/stV](x)    X/Re[cm/stV](x)    X/Im[cm/stV](y)    X/Re[cm/stV](y)    X/Im[cm/stV](z)    X/Re[cm/stV](z)&lt;br /&gt;
 #&lt;br /&gt;
      0.50000000        -0.35378838E-09    -0.19774796E-07     0.23591828E-09    -0.89405637E-09      0.0000000          0.0000000    &lt;br /&gt;
      1.1250000         -0.19356524E-08    -0.23160605E-07    -0.16052184E-09    -0.67662771E-09      0.0000000          0.0000000    &lt;br /&gt;
      1.7500000         -0.69446459E-08    -0.35586956E-07    -0.76025706E-09    -0.10205678E-08      0.0000000          0.0000000    &lt;br /&gt;
      2.37500000        -0.181606152E-7    -0.261823658E-8     0.438358596E-8     0.407915226E-8      0.00000000         0.00000000   &lt;br /&gt;
&lt;br /&gt;
The first column are the frequencies of the applied field, the second and third is the polarization along x (imaginary and real part), the fourth and fifth is the polarization along y (imaginary and real part)  &lt;br /&gt;
and the sixth and seventh is the polarization along z (imaginary and real part).&lt;br /&gt;
&lt;br /&gt;
Plot the absolute value of the SHG for the &amp;quot;xxy&amp;quot; component (that is, the applied field is in the x and y directions and one look at the polarization along x):&lt;br /&gt;
&lt;br /&gt;
 set ylabel &amp;quot;{/Symbol=26 \174}{/Symbol=26 c}_{xyx}^{(2)}{/Symbol=26 \174} (pm/V)&amp;quot; offset -0.7&lt;br /&gt;
 set xlabel &amp;quot;Energy (eV)&amp;quot;&lt;br /&gt;
 pmVm1toCGS=2.38721e-09&lt;br /&gt;
 plot &#039;01_SHG_ip_files/o-01_SHG_ip.YPP-X_probe_order_2&#039; u 1:(sqrt($2**2+$3**2)/pmVm1toCGS) w p title &amp;quot;calc&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[File: SHG_intensity_of_2D_h-BN_obtained_from_the_previous_run_(and_compared_with_a_run_on_112_frequencies).png | SHG_intensity_of_2D_h-BN obtained from the current run (12 frequencies) compared with a run with 112 frequencies]] &lt;br /&gt;
&lt;br /&gt;
In the figure above, the results of the current run are compared with those for a run with 112 frequencies (one can obtain these results by repeating the calculations, changing the number of frequencies in &amp;lt;code&amp;gt;NLEnSteps&amp;lt;/code&amp;gt; though this take about 10 times more computational time than the run with 12). One can notice some differences between the two runs. In fact, the two runs evaluate different frequnecies and the difference indicates spurious oscillations of the value of the polarizability due to the simulation time being too short and thus to the presence of &#039;noise&#039; due to the eigenfrecies.  &lt;br /&gt;
As an exercise, you can repeat the simulation for e,g, a time of &amp;lt;code&amp;gt;60 fs&amp;lt;/code&amp;gt;, that is setting &amp;lt;code&amp;gt;NLtime=60&amp;lt;/code&amp;gt;. The plot below compare the SHG extracted at 42 fs and 60 fs, where the latter gives clearly more accurate results. &lt;br /&gt;
&lt;br /&gt;
[[File:Comparison of the SHG intensity of 2D h-BN obtained with different simulation time.png|Comparison of the SHG intensity of 2D h-BN obtained with different simulation time]]&lt;br /&gt;
&lt;br /&gt;
As a final note, the SHG depends on the size of the vacuum added in the supercell. Instead, one should consider the surface SHG which obtained by considering an effective thickness for the layer. This is usually chosen to be similar to the layer separation in the bulk counterpart.&lt;br /&gt;
&lt;br /&gt;
= Step 3: Hartree+Screened exchange approximation (BSE level) =&lt;br /&gt;
&lt;br /&gt;
== Hartree+Screened exchange collisions ==&lt;br /&gt;
Similarly to the linear part, one needs to generate the Screened exchange collisions. The procedure is exactly the same.&lt;br /&gt;
&lt;br /&gt;
Create the input:&lt;br /&gt;
 yambo_nl -X s -e -v hsex -F 03_coll_hsex.in&lt;br /&gt;
modify the input ad follows&lt;br /&gt;
 em1s                             # [R][Xs] Statically Screened Interaction&lt;br /&gt;
 collisions                       # [R] Collisions&lt;br /&gt;
 dipoles                          # [R] Oscillator strenghts (or dipoles)&lt;br /&gt;
 Chimod= &amp;quot;HARTREE&amp;quot;                # [X] IP/Hartree/ALDA/LRC/PF/BSfxc&lt;br /&gt;
 % BndsRnXs&lt;br /&gt;
    1 |  20 |                         # [Xs] Polarization function bands&lt;br /&gt;
 %&lt;br /&gt;
 NGsBlkXs= 1000 mHa    # [Xs] Response block size&lt;br /&gt;
 % LongDrXs&lt;br /&gt;
  1.000000 | 1.000000 | 0.000000 |        # [Xs] [cc] Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 % COLLBands&lt;br /&gt;
    4 |  5 |                         # [COLL] Bands for the collisions&lt;br /&gt;
 %&lt;br /&gt;
 HXC_Potential= &amp;quot;SEX+HARTREE&amp;quot;     # [SC] SC HXC Potential&lt;br /&gt;
 HARRLvcs= 1000 mHa    # [HA] Hartree     RL components&lt;br /&gt;
 EXXRLvcs= 1000 mHa    # [XX] Exchange    RL components&lt;br /&gt;
 CORRLvcs= 1000 mHa    # [GW] Correlation RL components&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Calculate the collisions (you may want to run in parallel):&lt;br /&gt;
 yambo_nl -F 03_coll_hsex.in -J 03_coll -C 04_hsex_files&lt;br /&gt;
&lt;br /&gt;
== Run the simulation ==&lt;br /&gt;
&lt;br /&gt;
Create the input:&lt;br /&gt;
 yambo_nl -nl n -v hsex -V qp -F 04_SHG_hsex.in&lt;br /&gt;
&lt;br /&gt;
modify the following parts of the input (by this time all the innput variables should be known from the previous exercises):&lt;br /&gt;
&lt;br /&gt;
 % BndsRnXs&lt;br /&gt;
   1 |  20 |                         # [Xs] Polarization function bands&lt;br /&gt;
 %&lt;br /&gt;
 NGsBlkXs= 1000 mHa    # [Xs] Response block size&lt;br /&gt;
 % LongDrXs&lt;br /&gt;
  1.000000 | 1.000000 | 0.000000 |        # [Xs] [cc] Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 % NLBands&lt;br /&gt;
    4 |  5 |                         # [NL] Bands range&lt;br /&gt;
 %&lt;br /&gt;
&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;SEX&amp;quot;             # [NL] Correlation (&amp;quot;IPA/HARTREE/TDDFT/LRC/LRW/JGM/SEX&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 % NLEnRange&lt;br /&gt;
  0.500000 |8.000000 |         eV    # [NL] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 NLEnSteps= 12                   # [NL] Energy steps&lt;br /&gt;
&lt;br /&gt;
 % GfnQP_E&lt;br /&gt;
  3.000000 | 1.000000 | 1.000000 |        # [EXTQP G] E parameters  (c/v) eV|adim|adim&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
 Field1_kind= &amp;quot;SIN&amp;quot;           # [RT Field1] Kind(SIN|COS|RES|ANTIRES|GAUSS|DELTA|QSSIN)&lt;br /&gt;
&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
  1.000000 | 1.000000 | 0.000000 |        # [RT Field1] Versor&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
Then run the simulation using e.g. mpi and 4 cores:&lt;br /&gt;
 mpirun -n 4 yambo_nl -F 04_SHG_hsex.in -J 04_SHG_hsex,03_coll -C 04_SHG_hsex_files&lt;br /&gt;
&lt;br /&gt;
== Postprocessing: obtain the nonlinear response ==&lt;br /&gt;
&lt;br /&gt;
Similarly to what we did for the independent particle case, we create the input:&lt;br /&gt;
 ypp_nl -nl -F 05_SHG_hsex_pp.in&lt;br /&gt;
 &lt;br /&gt;
we change &amp;lt;code&amp;gt;Xorder = 4 &amp;lt;/code&amp;gt; and then run:&lt;br /&gt;
 ypp_nl -F 05_SHG_hsex_pp.in -J 04_SHG_hsex -C 04_hsex_files&lt;br /&gt;
&lt;br /&gt;
Then we plot (as before we compare with a simulation ran for 112 frequnecies).&lt;br /&gt;
&lt;br /&gt;
Plot the results:&lt;br /&gt;
&lt;br /&gt;
 set ylabel &amp;quot;{/Symbol=26 \174}{/Symbol=26 c}_{xyx}^{(2)}{/Symbol=26 \174} (pm/V)&amp;quot; offset -0.7&lt;br /&gt;
 set xlabel &amp;quot;Energy (eV)&amp;quot;&lt;br /&gt;
 pmVm1toCGS=2.38721e-09&lt;br /&gt;
 plot &#039;04_hsex_files/o-04_SHG_hsex.YPP-X_probe_order_2&#039; u 1:(sqrt($2**2+$3**2)/pmVm1toCGS) w p title &amp;quot;calc&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[File:SHG hsex.png|SHG at the Hartree + Screened exchange from current run with 12 frequencies (crosses) and a run with 112 frequencies (keeping the other parameters the same)]]&lt;br /&gt;
&lt;br /&gt;
also in this case we note differences between the two simulations. This is due to the too short simulation time. Repeating the calculations with a longer time gives more accurate results. &lt;br /&gt;
In addition, note that in the interest of time, all parameters are underconverged. In principle, to calculate the collisions one should use the same parameters of a converged BSE calculation. As well, one should use the Coulomb cutoff as it was used for this system in the  BSE case.&lt;br /&gt;
&lt;br /&gt;
= References = &lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Fulvio</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Second-harmonic_generation_of_2D-hBN&amp;diff=7000</id>
		<title>Second-harmonic generation of 2D-hBN</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Second-harmonic_generation_of_2D-hBN&amp;diff=7000"/>
		<updated>2023-05-25T09:03:48Z</updated>

		<summary type="html">&lt;p&gt;Fulvio: /* Step 2: Independent-particle approximation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Step 0: Theoretical framework =&lt;br /&gt;
&lt;br /&gt;
In this tutorial, we compute the Second-harmonic generation (SHG) from the dynamics of the Bloch-states. The equation-of-motion of the Bloch-states is explained in the tutorial on [[Linear response from Bloch-states dynamics]]. Independently of the &#039;experiment&#039; we simulate, the part of the integration of motion stays the same. This means that any experiment, including non-linear optics, can be performed at the level of the theory listed for the computation of the dielectric function:&lt;br /&gt;
* independent (quasi)particle&lt;br /&gt;
* time-dependent Hartree (RPA level)&lt;br /&gt;
* time-dependent DFT (and DPFT)&lt;br /&gt;
* time-dependent Hartree+Screened exchange (BSE level)&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
What changes when we want to calculate the SHG (or higher harmonics) is:&lt;br /&gt;
* the time-dependence of the input electric field and&lt;br /&gt;
* the post-processing of the signal  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Time dependence of the electric Field&#039;&#039;&#039;: we choose a sinusoidal electric field, thus a monochromatic laser field. This allows one to expand the polarization in the form &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; through a coefficient depending on a power of the strength of the field (with the power depending on the order of the response).&lt;br /&gt;
&lt;br /&gt;
At difference with a delta-like perturbation, a real-time simulation gives the response at the laser-field only. Then, to obtain the spectrum for the desired range of frequency, we have to perform so many simulations as the frequencies in the desired range.  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Post-processing of the signal&#039;&#039;&#039;: The switch-on of the electric field corresponds to a weak delta-like kick. Thus, even if it may not be noticeable, the polarization results from both the sinusoidal field and the delta-like kick. The latter excites all eigenfrequencies of the system. Though weak, the resulting signal is comparable with the second-harmonic signal. To eliminate the signal from the eigenfrequencies, we apply a dephasing (&amp;lt;math&amp;gt;\gamma_{deph}&amp;lt;/math&amp;gt;). To have a signal useful to sample the second-harmonic signal, we need to wait a time &amp;lt;math&amp;gt;\bar t&amp;lt;/math&amp;gt;  much larger than the dephasing-time &amp;lt;math&amp;gt;1/\gamma_{deph} &amp;lt;/math&amp;gt;. Note that we cannot choose a too short dephasing time (to shorten the simulation time), as this would result in a too large broadening of the spectrum. After &amp;lt;math&amp;gt;\bar t&amp;lt;/math&amp;gt;, we sample $2N+1$ times in a period and use discrete Fourier transform to extract &amp;lt;math&amp;gt;{p}_n&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt; n = 0,...,N&amp;lt;/math&amp;gt;, where n=2 gives the SHG. This is schematically illustrated in figure:&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;
The scheme from Ref. &amp;lt;ref name=&amp;quot;Attaccalite2013&amp;quot;&amp;gt;C. Attaccalite and M. Gruning [https://arxiv.org/abs/1309.4012v2 Rev. B, &#039;&#039;&#039;88&#039;&#039;&#039;, 235113 (2013)]&amp;lt;/ref&amp;gt; summarised the workflow for computing the SHG (or higher-harmonics) in a energy range &amp;lt;math&amp;gt;[\Omega_1,\Omega_2]&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
[[File:Scheme nl.png|350px|center|Schematic representation of real-time calculations]]&lt;br /&gt;
&lt;br /&gt;
= Step 1: Prerequisites =&lt;br /&gt;
&lt;br /&gt;
In this example, we will consider a single layer of hexagonal boron nitride (hBN). Before running real time simulations to compute the SHG in &amp;lt;code&amp;gt;yambo&amp;lt;/code&amp;gt; you need to download input files and Yambo databases for this tutorial here: [wget https://media.yambo-code.eu/educational/tutorials/files/hBN-2D.tar.gz hBN-2D.tar.gz].&lt;br /&gt;
Unzip the tarball and change directory to &amp;lt;code&amp;gt;YAMBO&amp;lt;/code&amp;gt; and run the setup (&amp;lt;code&amp;gt;yambo_nl -nompi&amp;lt;/code&amp;gt;). &lt;br /&gt;
Execute the command &lt;br /&gt;
 ypp_nl -fixsym -F 00_removesym.in  &lt;br /&gt;
to create the input, to remove the symmetries which are not compatible with the field: &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;1.000000 | 1.000000 | 0.000000 |&amp;lt;/span&amp;gt;        # First external Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 % Efield2&lt;br /&gt;
  0.000000 | 0.000000 | 0.000000 |        # 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;
 #KeepKGrid                     # Do not expand the k-grid&lt;br /&gt;
where we chose the field along the xy direction and we remove time-reversal symmetry.&lt;br /&gt;
&lt;br /&gt;
Then run the pre-processing job:&lt;br /&gt;
 ypp_nl -F 00_removesym.in J 00_removesym&lt;br /&gt;
This creates the directory &amp;lt;code&amp;gt;FixSymm&amp;lt;/code&amp;gt;. Change directory to &amp;lt;code&amp;gt;FixSymm&amp;lt;/code&amp;gt;. This contains the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory with reduced symmetries, compatible with the direction of the field. Now run the setup again (&amp;lt;code&amp;gt;yambo_nl -nompi&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
= Step 2: Independent-particle approximation =&lt;br /&gt;
&lt;br /&gt;
Use the command:&lt;br /&gt;
  yambo_nl -nl n -F 01_SHG_ip.in&lt;br /&gt;
to generate the input:&lt;br /&gt;
&lt;br /&gt;
 nloptics                         # [R] Non-linear spectroscopy&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=-1.000000           fs    # [NL] Simulation Time&lt;br /&gt;
 NLintegrator= &amp;quot;INVINT&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;
 % NLEnRange&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;0.5000000 |8.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;12&amp;lt;/span&amp;gt;                     # [NL] Energy steps&lt;br /&gt;
 NLDamping= 0.200000        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;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&amp;quot;SIN&amp;quot; &amp;lt;/span&amp;gt;          # [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 | 1.000000 | 0.000000 |&amp;lt;/span&amp;gt;        # [RT Field1] Versor&lt;br /&gt;
 %&lt;br /&gt;
 Field1_Tstart= 0.010000    fs    # [RT Field1] Initial Time&lt;br /&gt;
&lt;br /&gt;
To describe the Bloch-dynamics we will use as a basis the KS-states 3-6 for the k-grid used in the non-scf DFT calculations, that is a 6x6x1 (&amp;lt;code&amp;gt;NLBands&amp;lt;/code&amp;gt;). We choose 12 equally spaced frequencies (&amp;lt;code&amp;gt;NLEnSteps&amp;lt;/code&amp;gt;) for the applied field in the range  (&amp;lt;code&amp;gt;NLEnRange&amp;lt;/code&amp;gt;) between 0.5 and 8 eV. We choose a sinusoidal time-dependence (&amp;lt;code&amp;gt;Field1_kind&amp;lt;/code&amp;gt;) and set the field direction (&amp;lt;code&amp;gt;Field1_kind&amp;lt;/code&amp;gt;) along xy (in plane). The negative simulation time (&amp;lt;code&amp;gt;NLtime=-1.000000&amp;lt;/code&amp;gt;) means that the code will choose it based on the value of the &amp;lt;code&amp;gt;NLDamping&amp;lt;/code&amp;gt;. While this is a good lower bound for the simulation time, one should check it is sufficient to get accurate results. &lt;br /&gt;
&lt;br /&gt;
Run the simulation, possibly in parallel e. g. in a interactive session on 4 cores. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;[In order to get 4 cores while in an interacting node, exit your current allocation and rerun &amp;lt;code&amp;gt;salloc&amp;lt;/code&amp;gt; asking for the proper number of tasks:&#039;&#039;&#039;&lt;br /&gt;
 salloc -A tra23_Yambo -p m100_usr_prod -q m100_qos_dbg --nodes=1 --ntasks-per-node=&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;4&amp;lt;/span&amp;gt; --cpus-per-task=4 -t 02:00:00&lt;br /&gt;
&#039;&#039;&#039;Otherwise, you can submit the job with a slurm script as explained in the introductory page]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now execute the command:&lt;br /&gt;
  mpirun -n 4 yambo_nl -F 01_SHG_ip.in -J 01_SHG_ip -C 01_SHG_ip_files&lt;br /&gt;
&lt;br /&gt;
This run will take several minutes. While it is running, you can check the progress of one specific frequency:&lt;br /&gt;
 tail -f 01_SHG_ip_files/o-01_SHG_ip.polarization_F2&lt;br /&gt;
If you want to know how many fs the simulation will last (since this was decided by the code), you can get this information in the report file:&lt;br /&gt;
 $ grep Total 01_SHG_ip_files/r-01_SHG_ip_nloptics&lt;br /&gt;
 Total simulation time       :  41.23193 [fs]&lt;br /&gt;
 &lt;br /&gt;
Once the run is finished, check the report &amp;lt;code&amp;gt;01_SHG_ip_files/r-01_SHG_ip_nloptics&amp;lt;/code&amp;gt;. In particular, in the appended input files, you can see the default parallelization applied by the code for calculating the dipoles and run the time-propagation. For the latter, the main parallelization is on the frequencies and then on the k-points (&amp;lt;code&amp;gt;NL_ROLEs= &amp;quot;w.k&amp;quot;&amp;lt;/code&amp;gt;).   &lt;br /&gt;
&lt;br /&gt;
 | NL_CPU= &amp;quot;2.2&amp;quot;                    # [PARALLEL] CPUs for each role&lt;br /&gt;
 | NL_ROLEs= &amp;quot;w.k&amp;quot;                  # [PARALLEL] CPUs roles (w,k)&lt;br /&gt;
 | DIP_CPU= &amp;quot;2.2.1&amp;quot;                 # [PARALLEL] CPUs for each role&lt;br /&gt;
 | DIP_ROLEs= &amp;quot;v.c.k&amp;quot;               # [PARALLEL] CPUs roles (k,c,v)&lt;br /&gt;
&lt;br /&gt;
Also, look at the simulation time. This is approximately 42 fs. &lt;br /&gt;
&lt;br /&gt;
Plot the polarization for a couple of frequencies, e.g. the first and last of the chosen range (the corresponding frequency can be read in the file, search for &amp;quot;Frequency value&amp;quot;):&lt;br /&gt;
 set ylabel &amp;quot;x-component polarization&amp;quot; offset -0.7&lt;br /&gt;
 set xlabel &amp;quot;time (fs)&amp;quot;&lt;br /&gt;
 plot &#039;01_SHG_ip_files/o-01_SHG_ip.polarization_F1&#039; u 1:2 w l lw 2 title &amp;quot;omega = 0.5 eV&amp;quot;&lt;br /&gt;
 replot &#039;01_SHG_ip_files/o-01_SHG_ip.polarization_F12&#039; u 1:2 w l lw 2  title &amp;quot;omega = 7.375 eV&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[File:Berry_phase_polarization_of_2D_h-BN_obtained_from_the_previous_run_for_two_laser_frequencies.png|Berry_phase_polarization_of_2D_h-BN_obtained from the run for two laser frequencies]]&lt;br /&gt;
&lt;br /&gt;
After the applied field is &#039;switched on&#039;, the polarization is oscillating at the frequency of the applied field and at the eigenfrequencies of the system as described above in the cartoon. This is visible particularly for the higher frequency. Due to the dephasing, after about 20 fs the polarization is oscillating (at least to the eye) at the frequency of the applied field. Nonlinear components are not visible since they are several orders of magnitude smaller than the first order.&lt;br /&gt;
&lt;br /&gt;
== Output post-processing: the dielectric function ==&lt;br /&gt;
&lt;br /&gt;
Once we obtained the polarization, we Fourier-transform the polarization to obtain the dielectric function.&lt;br /&gt;
&lt;br /&gt;
Use the command:&lt;br /&gt;
&lt;br /&gt;
  ypp_nl -nl -F 02_SHG_ip_pp.in -C 01_SHG_ip_files&lt;br /&gt;
&lt;br /&gt;
to generate the input file: &lt;br /&gt;
&lt;br /&gt;
 nonlinear                        # [R] Non-linear response analysis&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;Xorder= 4&amp;lt;/span&amp;gt; # 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;NONE&amp;quot;                 # Damping type ( NONE | LORENTZIAN | GAUSSIAN )&lt;br /&gt;
 DampFactor= 0.000000       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;
Where we changed the &amp;lt;code&amp;gt;Xorder&amp;lt;/code&amp;gt; to 4. This variable controls the terms in the Fourier expansion of the polarization. We choose up to expand up to the fourth order. This should ensure the second order to be accurate enough. As an exercise, you can change this value (e.g. choose 2,3,5,6) and see how the result below is changing. The time-window where processing is done is chosen automatically, since values are negative. The code chooses by default the last period to carry out the analysis. &lt;br /&gt;
&lt;br /&gt;
To run the post-processing, use the command:&lt;br /&gt;
 ypp_nl -F Inputs_shg/ypp_shg.in -J TD-IP_nl -C TD-IP_nl. &lt;br /&gt;
   &lt;br /&gt;
In  &amp;lt;code&amp;gt;01_SHG_ip_files&amp;lt;/code&amp;gt; the following files were generated &lt;br /&gt;
 o-01_SHG_ip.YPP-X_probe_order_1&lt;br /&gt;
 o-01_SHG_ip.YPP-X_probe_order_2&lt;br /&gt;
 o-01_SHG_ip.YPP-X_probe_order_3&lt;br /&gt;
 o-01_SHG_ip.YPP-X_probe_order_4&lt;br /&gt;
 r-01_SHG_ip_nonlinear&lt;br /&gt;
&lt;br /&gt;
The output files contain respectively the first, second, third and fourth order response(corresponding to &amp;lt;code&amp;gt;Xorder=4&amp;lt;/code&amp;gt;)  at the 12 frequencies in the chosen range. &lt;br /&gt;
 &lt;br /&gt;
Inspect &amp;lt;code&amp;gt;o-01_SHG_ip.YPP-X_probe_order_2&amp;lt;/code&amp;gt;&lt;br /&gt;
 #     E [eV]            X/Im[cm/stV](x)    X/Re[cm/stV](x)    X/Im[cm/stV](y)    X/Re[cm/stV](y)    X/Im[cm/stV](z)    X/Re[cm/stV](z)&lt;br /&gt;
 #&lt;br /&gt;
      0.50000000        -0.35378838E-09    -0.19774796E-07     0.23591828E-09    -0.89405637E-09      0.0000000          0.0000000    &lt;br /&gt;
      1.1250000         -0.19356524E-08    -0.23160605E-07    -0.16052184E-09    -0.67662771E-09      0.0000000          0.0000000    &lt;br /&gt;
      1.7500000         -0.69446459E-08    -0.35586956E-07    -0.76025706E-09    -0.10205678E-08      0.0000000          0.0000000    &lt;br /&gt;
      2.37500000        -0.181606152E-7    -0.261823658E-8     0.438358596E-8     0.407915226E-8      0.00000000         0.00000000   &lt;br /&gt;
&lt;br /&gt;
The first column are the frequencies of the applied field, the second and third is the polarization along x (imaginary and real part), the fourth and fifth is the polarization along y (imaginary and real part)  &lt;br /&gt;
and the sixth and seventh is the polarization along z (imaginary and real part).&lt;br /&gt;
&lt;br /&gt;
Plot the absolute value of the SHG for the &amp;quot;xxy&amp;quot; component (that is, the applied field is in the x and y directions and one look at the polarization along x):&lt;br /&gt;
&lt;br /&gt;
 set ylabel &amp;quot;{/Symbol=26 \174}{/Symbol=26 c}_{xyx}^{(2)}{/Symbol=26 \174} (pm/V)&amp;quot; offset -0.7&lt;br /&gt;
 set xlabel &amp;quot;Energy (eV)&amp;quot;&lt;br /&gt;
 pmVm1toCGS=2.38721e-09&lt;br /&gt;
 plot &#039;01_SHG_ip_files/o-01_SHG_ip.YPP-X_probe_order_2&#039; u 1:(sqrt($2**2+$3**2)/pmVm1toCGS) w p title &amp;quot;calc&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[File: SHG_intensity_of_2D_h-BN_obtained_from_the_previous_run_(and_compared_with_a_run_on_112_frequencies).png | SHG_intensity_of_2D_h-BN obtained from the current run (12 frequencies) compared with a run with 112 frequencies]] &lt;br /&gt;
&lt;br /&gt;
In the figure above, the results of the current run are compared with those for a run with 112 frequencies (one can obtain these results by repeating the calculations, changing the number of frequencies in &amp;lt;code&amp;gt;NLEnSteps&amp;lt;/code&amp;gt; though this take about 10 times more computational time than the run with 12). One can notice some differences between the two runs. In fact, the two runs evaluate different frequnecies and the difference indicates spurious oscillations of the value of the polarizability due to the simulation time being too short and thus to the presence of &#039;noise&#039; due to the eigenfrecies.  &lt;br /&gt;
As an exercise, you can repeat the simulation for e,g, a time of &amp;lt;code&amp;gt;60 fs&amp;lt;/code&amp;gt;, that is setting &amp;lt;code&amp;gt;NLtime=60&amp;lt;/code&amp;gt;. The plot below compare the SHG extracted at 42 fs and 60 fs, where the latter gives clearly more accurate results. &lt;br /&gt;
&lt;br /&gt;
[[File:Comparison of the SHG intensity of 2D h-BN obtained with different simulation time.png|Comparison of the SHG intensity of 2D h-BN obtained with different simulation time]]&lt;br /&gt;
&lt;br /&gt;
As a final note, the SHG depends on the size of the vacuum added in the supercell. Instead, one should consider the surface SHG which obtained by considering an effective thickness for the layer. This is usually chosen to be similar to the layer separation in the bulk counterpart.&lt;br /&gt;
&lt;br /&gt;
= Step 3: Hartree+Screened exchange approximation (BSE level) =&lt;br /&gt;
&lt;br /&gt;
== Hartree+Screened exchange collisions ==&lt;br /&gt;
Similarly to the linear part, one needs to generate the Screened exchange collisions. The procedure is exactly the same.&lt;br /&gt;
&lt;br /&gt;
Create the input:&lt;br /&gt;
 yambo_nl -X s -e -v hsex -F 03_coll_hsex.in&lt;br /&gt;
modify the input ad follows&lt;br /&gt;
 em1s                             # [R][Xs] Statically Screened Interaction&lt;br /&gt;
 collisions                       # [R] Collisions&lt;br /&gt;
 dipoles                          # [R] Oscillator strenghts (or dipoles)&lt;br /&gt;
 Chimod= &amp;quot;HARTREE&amp;quot;                # [X] IP/Hartree/ALDA/LRC/PF/BSfxc&lt;br /&gt;
 % BndsRnXs&lt;br /&gt;
    1 |  20 |                         # [Xs] Polarization function bands&lt;br /&gt;
 %&lt;br /&gt;
 NGsBlkXs= 1000 mHa    # [Xs] Response block size&lt;br /&gt;
 % LongDrXs&lt;br /&gt;
  1.000000 | 1.000000 | 0.000000 |        # [Xs] [cc] Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 % COLLBands&lt;br /&gt;
    4 |  5 |                         # [COLL] Bands for the collisions&lt;br /&gt;
 %&lt;br /&gt;
 HXC_Potential= &amp;quot;SEX+HARTREE&amp;quot;     # [SC] SC HXC Potential&lt;br /&gt;
 HARRLvcs= 1000 mHa    # [HA] Hartree     RL components&lt;br /&gt;
 EXXRLvcs= 1000 mHa    # [XX] Exchange    RL components&lt;br /&gt;
 CORRLvcs= 1000 mHa    # [GW] Correlation RL components&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Calculate the collisions (you may want to run in parallel):&lt;br /&gt;
 yambo_nl -F 03_coll_hsex.in -J 03_coll -C 04_hsex_files&lt;br /&gt;
&lt;br /&gt;
== Run the simulation ==&lt;br /&gt;
&lt;br /&gt;
Create the input:&lt;br /&gt;
 yambo_nl -nl n -v hsex -V qp -F 04_SHG_hsex.in&lt;br /&gt;
&lt;br /&gt;
modify the following parts of the input (by this time all the innput variables should be known from the previous exercises):&lt;br /&gt;
&lt;br /&gt;
 % BndsRnXs&lt;br /&gt;
   1 |  20 |                         # [Xs] Polarization function bands&lt;br /&gt;
 %&lt;br /&gt;
 NGsBlkXs= 1000 mHa    # [Xs] Response block size&lt;br /&gt;
 % LongDrXs&lt;br /&gt;
  1.000000 | 1.000000 | 0.000000 |        # [Xs] [cc] Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 % NLBands&lt;br /&gt;
    4 |  5 |                         # [NL] Bands range&lt;br /&gt;
 %&lt;br /&gt;
&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;SEX&amp;quot;             # [NL] Correlation (&amp;quot;IPA/HARTREE/TDDFT/LRC/LRW/JGM/SEX&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 % NLEnRange&lt;br /&gt;
  0.500000 |8.000000 |         eV    # [NL] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 NLEnSteps= 12                   # [NL] Energy steps&lt;br /&gt;
&lt;br /&gt;
 % GfnQP_E&lt;br /&gt;
  3.000000 | 1.000000 | 1.000000 |        # [EXTQP G] E parameters  (c/v) eV|adim|adim&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
 Field1_kind= &amp;quot;SIN&amp;quot;           # [RT Field1] Kind(SIN|COS|RES|ANTIRES|GAUSS|DELTA|QSSIN)&lt;br /&gt;
&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
  1.000000 | 1.000000 | 0.000000 |        # [RT Field1] Versor&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
Then run the simulation using e.g. mpi and 4 cores:&lt;br /&gt;
 mpirun -n 4 yambo_nl -F 04_SHG_hsex.in -J 04_SHG_hsex,03_coll -C 04_SHG_hsex_files&lt;br /&gt;
&lt;br /&gt;
== Postprocessing: obtain the nonlinear response ==&lt;br /&gt;
&lt;br /&gt;
Similarly to what we did for the independent particle case, we create the input:&lt;br /&gt;
 ypp_nl -nl -F 05_SHG_hsex_pp.in&lt;br /&gt;
 &lt;br /&gt;
we change &amp;lt;code&amp;gt;Xorder = 4 &amp;lt;/code&amp;gt; and then run:&lt;br /&gt;
 ypp_nl -F 05_SHG_hsex_pp.in -J 04_SHG_hsex -C 04_hsex_files&lt;br /&gt;
&lt;br /&gt;
Then we plot (as before we compare with a simulation ran for 112 frequnecies).&lt;br /&gt;
&lt;br /&gt;
Plot the results:&lt;br /&gt;
&lt;br /&gt;
 set ylabel &amp;quot;{/Symbol=26 \174}{/Symbol=26 c}_{xyx}^{(2)}{/Symbol=26 \174} (pm/V)&amp;quot; offset -0.7&lt;br /&gt;
 set xlabel &amp;quot;Energy (eV)&amp;quot;&lt;br /&gt;
 pmVm1toCGS=2.38721e-09&lt;br /&gt;
 plot &#039;04_hsex_files/o-04_SHG_hsex.YPP-X_probe_order_2&#039; u 1:(sqrt($2**2+$3**2)/pmVm1toCGS) w p title &amp;quot;calc&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[File:SHG hsex.png|SHG at the Hartree + Screened exchange from current run with 12 frequencies (crosses) and a run with 112 frequencies (keeping the other parameters the same)]]&lt;br /&gt;
&lt;br /&gt;
also in this case we note differences between the two simulations. This is due to the too short simulation time. Repeating the calculations with a longer time gives more accurate results. &lt;br /&gt;
In addition, note that in the interest of time, all parameters are underconverged. In principle, to calculate the collisions one should use the same parameters of a converged BSE calculation. As well, one should use the Coulomb cutoff as it was used for this system in the  BSE case.&lt;br /&gt;
&lt;br /&gt;
= References = &lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Fulvio</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Second-harmonic_generation_of_2D-hBN&amp;diff=6999</id>
		<title>Second-harmonic generation of 2D-hBN</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Second-harmonic_generation_of_2D-hBN&amp;diff=6999"/>
		<updated>2023-05-25T08:55:40Z</updated>

		<summary type="html">&lt;p&gt;Fulvio: /* Step 2: Independent-particle approximation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Step 0: Theoretical framework =&lt;br /&gt;
&lt;br /&gt;
In this tutorial, we compute the Second-harmonic generation (SHG) from the dynamics of the Bloch-states. The equation-of-motion of the Bloch-states is explained in the tutorial on [[Linear response from Bloch-states dynamics]]. Independently of the &#039;experiment&#039; we simulate, the part of the integration of motion stays the same. This means that any experiment, including non-linear optics, can be performed at the level of the theory listed for the computation of the dielectric function:&lt;br /&gt;
* independent (quasi)particle&lt;br /&gt;
* time-dependent Hartree (RPA level)&lt;br /&gt;
* time-dependent DFT (and DPFT)&lt;br /&gt;
* time-dependent Hartree+Screened exchange (BSE level)&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
What changes when we want to calculate the SHG (or higher harmonics) is:&lt;br /&gt;
* the time-dependence of the input electric field and&lt;br /&gt;
* the post-processing of the signal  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Time dependence of the electric Field&#039;&#039;&#039;: we choose a sinusoidal electric field, thus a monochromatic laser field. This allows one to expand the polarization in the form &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; through a coefficient depending on a power of the strength of the field (with the power depending on the order of the response).&lt;br /&gt;
&lt;br /&gt;
At difference with a delta-like perturbation, a real-time simulation gives the response at the laser-field only. Then, to obtain the spectrum for the desired range of frequency, we have to perform so many simulations as the frequencies in the desired range.  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Post-processing of the signal&#039;&#039;&#039;: The switch-on of the electric field corresponds to a weak delta-like kick. Thus, even if it may not be noticeable, the polarization results from both the sinusoidal field and the delta-like kick. The latter excites all eigenfrequencies of the system. Though weak, the resulting signal is comparable with the second-harmonic signal. To eliminate the signal from the eigenfrequencies, we apply a dephasing (&amp;lt;math&amp;gt;\gamma_{deph}&amp;lt;/math&amp;gt;). To have a signal useful to sample the second-harmonic signal, we need to wait a time &amp;lt;math&amp;gt;\bar t&amp;lt;/math&amp;gt;  much larger than the dephasing-time &amp;lt;math&amp;gt;1/\gamma_{deph} &amp;lt;/math&amp;gt;. Note that we cannot choose a too short dephasing time (to shorten the simulation time), as this would result in a too large broadening of the spectrum. After &amp;lt;math&amp;gt;\bar t&amp;lt;/math&amp;gt;, we sample $2N+1$ times in a period and use discrete Fourier transform to extract &amp;lt;math&amp;gt;{p}_n&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt; n = 0,...,N&amp;lt;/math&amp;gt;, where n=2 gives the SHG. This is schematically illustrated in figure:&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;
The scheme from Ref. &amp;lt;ref name=&amp;quot;Attaccalite2013&amp;quot;&amp;gt;C. Attaccalite and M. Gruning [https://arxiv.org/abs/1309.4012v2 Rev. B, &#039;&#039;&#039;88&#039;&#039;&#039;, 235113 (2013)]&amp;lt;/ref&amp;gt; summarised the workflow for computing the SHG (or higher-harmonics) in a energy range &amp;lt;math&amp;gt;[\Omega_1,\Omega_2]&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
[[File:Scheme nl.png|350px|center|Schematic representation of real-time calculations]]&lt;br /&gt;
&lt;br /&gt;
= Step 1: Prerequisites =&lt;br /&gt;
&lt;br /&gt;
In this example, we will consider a single layer of hexagonal boron nitride (hBN). Before running real time simulations to compute the SHG in &amp;lt;code&amp;gt;yambo&amp;lt;/code&amp;gt; you need to download input files and Yambo databases for this tutorial here: [wget https://media.yambo-code.eu/educational/tutorials/files/hBN-2D.tar.gz hBN-2D.tar.gz].&lt;br /&gt;
Unzip the tarball and change directory to &amp;lt;code&amp;gt;YAMBO&amp;lt;/code&amp;gt; and run the setup (&amp;lt;code&amp;gt;yambo_nl -nompi&amp;lt;/code&amp;gt;). &lt;br /&gt;
Execute the command &lt;br /&gt;
 ypp_nl -fixsym -F 00_removesym.in  &lt;br /&gt;
to create the input, to remove the symmetries which are not compatible with the field: &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;1.000000 | 1.000000 | 0.000000 |&amp;lt;/span&amp;gt;        # First external Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 % Efield2&lt;br /&gt;
  0.000000 | 0.000000 | 0.000000 |        # 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;
 #KeepKGrid                     # Do not expand the k-grid&lt;br /&gt;
where we chose the field along the xy direction and we remove time-reversal symmetry.&lt;br /&gt;
&lt;br /&gt;
Then run the pre-processing job:&lt;br /&gt;
 ypp_nl -F 00_removesym.in J 00_removesym&lt;br /&gt;
This creates the directory &amp;lt;code&amp;gt;FixSymm&amp;lt;/code&amp;gt;. Change directory to &amp;lt;code&amp;gt;FixSymm&amp;lt;/code&amp;gt;. This contains the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory with reduced symmetries, compatible with the direction of the field. Now run the setup again (&amp;lt;code&amp;gt;yambo_nl -nompi&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
= Step 2: Independent-particle approximation =&lt;br /&gt;
&lt;br /&gt;
Use the command:&lt;br /&gt;
  yambo_nl -nl n -F 01_SHG_ip.in&lt;br /&gt;
to generate the input:&lt;br /&gt;
&lt;br /&gt;
 nloptics                         # [R] Non-linear spectroscopy&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=-1.000000           fs    # [NL] Simulation Time&lt;br /&gt;
 NLintegrator= &amp;quot;INVINT&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;
 % NLEnRange&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;0.5000000 |8.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;12&amp;lt;/span&amp;gt;                     # [NL] Energy steps&lt;br /&gt;
 NLDamping= 0.200000        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;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&amp;quot;SIN&amp;quot; &amp;lt;/span&amp;gt;          # [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 | 1.000000 | 0.000000 |&amp;lt;/span&amp;gt;        # [RT Field1] Versor&lt;br /&gt;
 %&lt;br /&gt;
 Field1_Tstart= 0.010000    fs    # [RT Field1] Initial Time&lt;br /&gt;
&lt;br /&gt;
To describe the Bloch-dynamics we will use as a basis the KS-states 3-6 for the k-grid used in the non-scf DFT calculations, that is a 6x6x1 (&amp;lt;code&amp;gt;NLBands&amp;lt;/code&amp;gt;). We choose 12 equally spaced frequencies (&amp;lt;code&amp;gt;NLEnSteps&amp;lt;/code&amp;gt;) for the applied field in the range  (&amp;lt;code&amp;gt;NLEnRange&amp;lt;/code&amp;gt;) between 0.5 and 8 eV. We choose a sinusoidal time-dependence (&amp;lt;code&amp;gt;Field1_kind&amp;lt;/code&amp;gt;) and set the field direction (&amp;lt;code&amp;gt;Field1_kind&amp;lt;/code&amp;gt;) along xy (in plane). The negative simulation time (&amp;lt;code&amp;gt;NLtime=-1.000000&amp;lt;/code&amp;gt;) means that the code will choose it based on the value of the &amp;lt;code&amp;gt;NLDamping&amp;lt;/code&amp;gt;. While this is a good lower bound for the simulation time, one should check it is sufficient to get accurate results. &lt;br /&gt;
&lt;br /&gt;
Run the simulation, possibly in parallel e. g. in a interactive session on 4 cores. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;[In order to get 4 cores while in an interacting node, exit your current allocation and rerun &amp;lt;code&amp;gt;salloc&amp;lt;/code&amp;gt; asking for the proper number of tasks:&#039;&#039;&#039;&lt;br /&gt;
 salloc -A tra23_Yambo -p m100_usr_prod -q m100_qos_dbg --nodes=1 --ntasks-per-node=&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;4&amp;lt;/span&amp;gt; --cpus-per-task=4 -t 02:00:00&lt;br /&gt;
&#039;&#039;&#039;Otherwise, you can submit the job with a slurm script as explained in the introductory page]&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Now execute the command:&lt;br /&gt;
  mpirun -n 4 yambo_nl -F 01_SHG_ip.in -J 01_SHG_ip -C 01_SHG_ip_files&lt;br /&gt;
&lt;br /&gt;
This run will take several minutes. While it is running, you can check one of the outputs to track completion:&lt;br /&gt;
 tail -f 01_SHG_ip_files/o-01_SHG_ip.polarization_F1&lt;br /&gt;
If you want to know how many fs the run will last (since this was decided by the code), you can get this information in the report file:&lt;br /&gt;
 $ grep Total 01_SHG_ip_files/r-01_SHG_ip_nloptics&lt;br /&gt;
 Total simulation time       :  41.23193 [fs]&lt;br /&gt;
 &lt;br /&gt;
Once the run is finished, check the report &amp;lt;code&amp;gt;01_SHG_ip_files/r-01_SHG_ip_nloptics&amp;lt;/code&amp;gt;. In particular, in the appended input files, you can see the default parallelization applied by the code for calculating the dipoles and run the time-propagation. For the latter, the main parallelization is on the frequencies and then on the k-points (&amp;lt;code&amp;gt;NL_ROLEs= &amp;quot;w.k&amp;quot;&amp;lt;/code&amp;gt;).   &lt;br /&gt;
&lt;br /&gt;
 | NL_CPU= &amp;quot;2.2&amp;quot;                    # [PARALLEL] CPUs for each role&lt;br /&gt;
 | NL_ROLEs= &amp;quot;w.k&amp;quot;                  # [PARALLEL] CPUs roles (w,k)&lt;br /&gt;
 | DIP_CPU= &amp;quot;2.2.1&amp;quot;                 # [PARALLEL] CPUs for each role&lt;br /&gt;
 | DIP_ROLEs= &amp;quot;v.c.k&amp;quot;               # [PARALLEL] CPUs roles (k,c,v)&lt;br /&gt;
&lt;br /&gt;
Also, look at the simulation time. This is approximately 42 fs. &lt;br /&gt;
&lt;br /&gt;
Plot the polarization for a couple of frequencies, e.g. the first and last of the chosen range (the corresponding frequency can be read in the file, search for &amp;quot;Frequency value&amp;quot;):&lt;br /&gt;
 set ylabel &amp;quot;x-component polarization&amp;quot; offset -0.7&lt;br /&gt;
 set xlabel &amp;quot;time (fs)&amp;quot;&lt;br /&gt;
 plot &#039;01_SHG_ip_files/o-01_SHG_ip.polarization_F1&#039; u 1:2 w l lw 2 title &amp;quot;omega = 0.5 eV&amp;quot;&lt;br /&gt;
 replot &#039;01_SHG_ip_files/o-01_SHG_ip.polarization_F12&#039; u 1:2 w l lw 2  title &amp;quot;omega = 7.375 eV&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[File:Berry_phase_polarization_of_2D_h-BN_obtained_from_the_previous_run_for_two_laser_frequencies.png|Berry_phase_polarization_of_2D_h-BN_obtained from the run for two laser frequencies]]&lt;br /&gt;
&lt;br /&gt;
After the applied field is &#039;switched on&#039;, the polarization is oscillating at the frequency of the applied field and at the eigenfrequencies of the system as described above in the cartoon. This is visible particularly for the higher frequency. Due to the dephasing, after about 20 fs the polarization is oscillating (at least to the eye) at the frequency of the applied field. Nonlinear components are not visible since they are several orders of magnitude smaller than the first order.&lt;br /&gt;
&lt;br /&gt;
== Output post-processing: the dielectric function ==&lt;br /&gt;
&lt;br /&gt;
Once we obtained the polarization, we Fourier-transform the polarization to obtain the dielectric function.&lt;br /&gt;
&lt;br /&gt;
Use the command:&lt;br /&gt;
&lt;br /&gt;
  ypp_nl -nl -F 02_SHG_ip_pp.in -C 01_SHG_ip_files&lt;br /&gt;
&lt;br /&gt;
to generate the input file: &lt;br /&gt;
&lt;br /&gt;
 nonlinear                        # [R] Non-linear response analysis&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;Xorder= 4&amp;lt;/span&amp;gt; # 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;NONE&amp;quot;                 # Damping type ( NONE | LORENTZIAN | GAUSSIAN )&lt;br /&gt;
 DampFactor= 0.000000       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;
Where we changed the &amp;lt;code&amp;gt;Xorder&amp;lt;/code&amp;gt; to 4. This variable controls the terms in the Fourier expansion of the polarization. We choose up to expand up to the fourth order. This should ensure the second order to be accurate enough. As an exercise, you can change this value (e.g. choose 2,3,5,6) and see how the result below is changing. The time-window where processing is done is chosen automatically, since values are negative. The code chooses by default the last period to carry out the analysis. &lt;br /&gt;
&lt;br /&gt;
To run the post-processing, use the command:&lt;br /&gt;
 ypp_nl -F Inputs_shg/ypp_shg.in -J TD-IP_nl -C TD-IP_nl. &lt;br /&gt;
   &lt;br /&gt;
In  &amp;lt;code&amp;gt;01_SHG_ip_files&amp;lt;/code&amp;gt; the following files were generated &lt;br /&gt;
 o-01_SHG_ip.YPP-X_probe_order_1&lt;br /&gt;
 o-01_SHG_ip.YPP-X_probe_order_2&lt;br /&gt;
 o-01_SHG_ip.YPP-X_probe_order_3&lt;br /&gt;
 o-01_SHG_ip.YPP-X_probe_order_4&lt;br /&gt;
 r-01_SHG_ip_nonlinear&lt;br /&gt;
&lt;br /&gt;
The output files contain respectively the first, second, third and fourth order response(corresponding to &amp;lt;code&amp;gt;Xorder=4&amp;lt;/code&amp;gt;)  at the 12 frequencies in the chosen range. &lt;br /&gt;
 &lt;br /&gt;
Inspect &amp;lt;code&amp;gt;o-01_SHG_ip.YPP-X_probe_order_2&amp;lt;/code&amp;gt;&lt;br /&gt;
 #     E [eV]            X/Im[cm/stV](x)    X/Re[cm/stV](x)    X/Im[cm/stV](y)    X/Re[cm/stV](y)    X/Im[cm/stV](z)    X/Re[cm/stV](z)&lt;br /&gt;
 #&lt;br /&gt;
      0.50000000        -0.35378838E-09    -0.19774796E-07     0.23591828E-09    -0.89405637E-09      0.0000000          0.0000000    &lt;br /&gt;
      1.1250000         -0.19356524E-08    -0.23160605E-07    -0.16052184E-09    -0.67662771E-09      0.0000000          0.0000000    &lt;br /&gt;
      1.7500000         -0.69446459E-08    -0.35586956E-07    -0.76025706E-09    -0.10205678E-08      0.0000000          0.0000000    &lt;br /&gt;
      2.37500000        -0.181606152E-7    -0.261823658E-8     0.438358596E-8     0.407915226E-8      0.00000000         0.00000000   &lt;br /&gt;
&lt;br /&gt;
The first column are the frequencies of the applied field, the second and third is the polarization along x (imaginary and real part), the fourth and fifth is the polarization along y (imaginary and real part)  &lt;br /&gt;
and the sixth and seventh is the polarization along z (imaginary and real part).&lt;br /&gt;
&lt;br /&gt;
Plot the absolute value of the SHG for the &amp;quot;xxy&amp;quot; component (that is, the applied field is in the x and y directions and one look at the polarization along x):&lt;br /&gt;
&lt;br /&gt;
 set ylabel &amp;quot;{/Symbol=26 \174}{/Symbol=26 c}_{xyx}^{(2)}{/Symbol=26 \174} (pm/V)&amp;quot; offset -0.7&lt;br /&gt;
 set xlabel &amp;quot;Energy (eV)&amp;quot;&lt;br /&gt;
 pmVm1toCGS=2.38721e-09&lt;br /&gt;
 plot &#039;01_SHG_ip_files/o-01_SHG_ip.YPP-X_probe_order_2&#039; u 1:(sqrt($2**2+$3**2)/pmVm1toCGS) w p title &amp;quot;calc&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[File: SHG_intensity_of_2D_h-BN_obtained_from_the_previous_run_(and_compared_with_a_run_on_112_frequencies).png | SHG_intensity_of_2D_h-BN obtained from the current run (12 frequencies) compared with a run with 112 frequencies]] &lt;br /&gt;
&lt;br /&gt;
In the figure above, the results of the current run are compared with those for a run with 112 frequencies (one can obtain these results by repeating the calculations, changing the number of frequencies in &amp;lt;code&amp;gt;NLEnSteps&amp;lt;/code&amp;gt; though this take about 10 times more computational time than the run with 12). One can notice some differences between the two runs. In fact, the two runs evaluate different frequnecies and the difference indicates spurious oscillations of the value of the polarizability due to the simulation time being too short and thus to the presence of &#039;noise&#039; due to the eigenfrecies.  &lt;br /&gt;
As an exercise, you can repeat the simulation for e,g, a time of &amp;lt;code&amp;gt;60 fs&amp;lt;/code&amp;gt;, that is setting &amp;lt;code&amp;gt;NLtime=60&amp;lt;/code&amp;gt;. The plot below compare the SHG extracted at 42 fs and 60 fs, where the latter gives clearly more accurate results. &lt;br /&gt;
&lt;br /&gt;
[[File:Comparison of the SHG intensity of 2D h-BN obtained with different simulation time.png|Comparison of the SHG intensity of 2D h-BN obtained with different simulation time]]&lt;br /&gt;
&lt;br /&gt;
As a final note, the SHG depends on the size of the vacuum added in the supercell. Instead, one should consider the surface SHG which obtained by considering an effective thickness for the layer. This is usually chosen to be similar to the layer separation in the bulk counterpart.&lt;br /&gt;
&lt;br /&gt;
= Step 3: Hartree+Screened exchange approximation (BSE level) =&lt;br /&gt;
&lt;br /&gt;
== Hartree+Screened exchange collisions ==&lt;br /&gt;
Similarly to the linear part, one needs to generate the Screened exchange collisions. The procedure is exactly the same.&lt;br /&gt;
&lt;br /&gt;
Create the input:&lt;br /&gt;
 yambo_nl -X s -e -v hsex -F 03_coll_hsex.in&lt;br /&gt;
modify the input ad follows&lt;br /&gt;
 em1s                             # [R][Xs] Statically Screened Interaction&lt;br /&gt;
 collisions                       # [R] Collisions&lt;br /&gt;
 dipoles                          # [R] Oscillator strenghts (or dipoles)&lt;br /&gt;
 Chimod= &amp;quot;HARTREE&amp;quot;                # [X] IP/Hartree/ALDA/LRC/PF/BSfxc&lt;br /&gt;
 % BndsRnXs&lt;br /&gt;
    1 |  20 |                         # [Xs] Polarization function bands&lt;br /&gt;
 %&lt;br /&gt;
 NGsBlkXs= 1000 mHa    # [Xs] Response block size&lt;br /&gt;
 % LongDrXs&lt;br /&gt;
  1.000000 | 1.000000 | 0.000000 |        # [Xs] [cc] Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 % COLLBands&lt;br /&gt;
    4 |  5 |                         # [COLL] Bands for the collisions&lt;br /&gt;
 %&lt;br /&gt;
 HXC_Potential= &amp;quot;SEX+HARTREE&amp;quot;     # [SC] SC HXC Potential&lt;br /&gt;
 HARRLvcs= 1000 mHa    # [HA] Hartree     RL components&lt;br /&gt;
 EXXRLvcs= 1000 mHa    # [XX] Exchange    RL components&lt;br /&gt;
 CORRLvcs= 1000 mHa    # [GW] Correlation RL components&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Calculate the collisions (you may want to run in parallel):&lt;br /&gt;
 yambo_nl -F 03_coll_hsex.in -J 03_coll -C 04_hsex_files&lt;br /&gt;
&lt;br /&gt;
== Run the simulation ==&lt;br /&gt;
&lt;br /&gt;
Create the input:&lt;br /&gt;
 yambo_nl -nl n -v hsex -V qp -F 04_SHG_hsex.in&lt;br /&gt;
&lt;br /&gt;
modify the following parts of the input (by this time all the innput variables should be known from the previous exercises):&lt;br /&gt;
&lt;br /&gt;
 % BndsRnXs&lt;br /&gt;
   1 |  20 |                         # [Xs] Polarization function bands&lt;br /&gt;
 %&lt;br /&gt;
 NGsBlkXs= 1000 mHa    # [Xs] Response block size&lt;br /&gt;
 % LongDrXs&lt;br /&gt;
  1.000000 | 1.000000 | 0.000000 |        # [Xs] [cc] Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 % NLBands&lt;br /&gt;
    4 |  5 |                         # [NL] Bands range&lt;br /&gt;
 %&lt;br /&gt;
&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;SEX&amp;quot;             # [NL] Correlation (&amp;quot;IPA/HARTREE/TDDFT/LRC/LRW/JGM/SEX&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 % NLEnRange&lt;br /&gt;
  0.500000 |8.000000 |         eV    # [NL] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 NLEnSteps= 12                   # [NL] Energy steps&lt;br /&gt;
&lt;br /&gt;
 % GfnQP_E&lt;br /&gt;
  3.000000 | 1.000000 | 1.000000 |        # [EXTQP G] E parameters  (c/v) eV|adim|adim&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
 Field1_kind= &amp;quot;SIN&amp;quot;           # [RT Field1] Kind(SIN|COS|RES|ANTIRES|GAUSS|DELTA|QSSIN)&lt;br /&gt;
&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
  1.000000 | 1.000000 | 0.000000 |        # [RT Field1] Versor&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
Then run the simulation using e.g. mpi and 4 cores:&lt;br /&gt;
 mpirun -n 4 yambo_nl -F 04_SHG_hsex.in -J 04_SHG_hsex,03_coll -C 04_SHG_hsex_files&lt;br /&gt;
&lt;br /&gt;
== Postprocessing: obtain the nonlinear response ==&lt;br /&gt;
&lt;br /&gt;
Similarly to what we did for the independent particle case, we create the input:&lt;br /&gt;
 ypp_nl -nl -F 05_SHG_hsex_pp.in&lt;br /&gt;
 &lt;br /&gt;
we change &amp;lt;code&amp;gt;Xorder = 4 &amp;lt;/code&amp;gt; and then run:&lt;br /&gt;
 ypp_nl -F 05_SHG_hsex_pp.in -J 04_SHG_hsex -C 04_hsex_files&lt;br /&gt;
&lt;br /&gt;
Then we plot (as before we compare with a simulation ran for 112 frequnecies).&lt;br /&gt;
&lt;br /&gt;
Plot the results:&lt;br /&gt;
&lt;br /&gt;
 set ylabel &amp;quot;{/Symbol=26 \174}{/Symbol=26 c}_{xyx}^{(2)}{/Symbol=26 \174} (pm/V)&amp;quot; offset -0.7&lt;br /&gt;
 set xlabel &amp;quot;Energy (eV)&amp;quot;&lt;br /&gt;
 pmVm1toCGS=2.38721e-09&lt;br /&gt;
 plot &#039;04_hsex_files/o-04_SHG_hsex.YPP-X_probe_order_2&#039; u 1:(sqrt($2**2+$3**2)/pmVm1toCGS) w p title &amp;quot;calc&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[File:SHG hsex.png|SHG at the Hartree + Screened exchange from current run with 12 frequencies (crosses) and a run with 112 frequencies (keeping the other parameters the same)]]&lt;br /&gt;
&lt;br /&gt;
also in this case we note differences between the two simulations. This is due to the too short simulation time. Repeating the calculations with a longer time gives more accurate results. &lt;br /&gt;
In addition, note that in the interest of time, all parameters are underconverged. In principle, to calculate the collisions one should use the same parameters of a converged BSE calculation. As well, one should use the Coulomb cutoff as it was used for this system in the  BSE case.&lt;br /&gt;
&lt;br /&gt;
= References = &lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Fulvio</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Second-harmonic_generation_of_2D-hBN&amp;diff=6998</id>
		<title>Second-harmonic generation of 2D-hBN</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Second-harmonic_generation_of_2D-hBN&amp;diff=6998"/>
		<updated>2023-05-25T08:51:48Z</updated>

		<summary type="html">&lt;p&gt;Fulvio: /* Step 1: Prerequisites */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Step 0: Theoretical framework =&lt;br /&gt;
&lt;br /&gt;
In this tutorial, we compute the Second-harmonic generation (SHG) from the dynamics of the Bloch-states. The equation-of-motion of the Bloch-states is explained in the tutorial on [[Linear response from Bloch-states dynamics]]. Independently of the &#039;experiment&#039; we simulate, the part of the integration of motion stays the same. This means that any experiment, including non-linear optics, can be performed at the level of the theory listed for the computation of the dielectric function:&lt;br /&gt;
* independent (quasi)particle&lt;br /&gt;
* time-dependent Hartree (RPA level)&lt;br /&gt;
* time-dependent DFT (and DPFT)&lt;br /&gt;
* time-dependent Hartree+Screened exchange (BSE level)&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
What changes when we want to calculate the SHG (or higher harmonics) is:&lt;br /&gt;
* the time-dependence of the input electric field and&lt;br /&gt;
* the post-processing of the signal  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Time dependence of the electric Field&#039;&#039;&#039;: we choose a sinusoidal electric field, thus a monochromatic laser field. This allows one to expand the polarization in the form &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; through a coefficient depending on a power of the strength of the field (with the power depending on the order of the response).&lt;br /&gt;
&lt;br /&gt;
At difference with a delta-like perturbation, a real-time simulation gives the response at the laser-field only. Then, to obtain the spectrum for the desired range of frequency, we have to perform so many simulations as the frequencies in the desired range.  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Post-processing of the signal&#039;&#039;&#039;: The switch-on of the electric field corresponds to a weak delta-like kick. Thus, even if it may not be noticeable, the polarization results from both the sinusoidal field and the delta-like kick. The latter excites all eigenfrequencies of the system. Though weak, the resulting signal is comparable with the second-harmonic signal. To eliminate the signal from the eigenfrequencies, we apply a dephasing (&amp;lt;math&amp;gt;\gamma_{deph}&amp;lt;/math&amp;gt;). To have a signal useful to sample the second-harmonic signal, we need to wait a time &amp;lt;math&amp;gt;\bar t&amp;lt;/math&amp;gt;  much larger than the dephasing-time &amp;lt;math&amp;gt;1/\gamma_{deph} &amp;lt;/math&amp;gt;. Note that we cannot choose a too short dephasing time (to shorten the simulation time), as this would result in a too large broadening of the spectrum. After &amp;lt;math&amp;gt;\bar t&amp;lt;/math&amp;gt;, we sample $2N+1$ times in a period and use discrete Fourier transform to extract &amp;lt;math&amp;gt;{p}_n&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt; n = 0,...,N&amp;lt;/math&amp;gt;, where n=2 gives the SHG. This is schematically illustrated in figure:&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;
The scheme from Ref. &amp;lt;ref name=&amp;quot;Attaccalite2013&amp;quot;&amp;gt;C. Attaccalite and M. Gruning [https://arxiv.org/abs/1309.4012v2 Rev. B, &#039;&#039;&#039;88&#039;&#039;&#039;, 235113 (2013)]&amp;lt;/ref&amp;gt; summarised the workflow for computing the SHG (or higher-harmonics) in a energy range &amp;lt;math&amp;gt;[\Omega_1,\Omega_2]&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
[[File:Scheme nl.png|350px|center|Schematic representation of real-time calculations]]&lt;br /&gt;
&lt;br /&gt;
= Step 1: Prerequisites =&lt;br /&gt;
&lt;br /&gt;
In this example, we will consider a single layer of hexagonal boron nitride (hBN). Before running real time simulations to compute the SHG in &amp;lt;code&amp;gt;yambo&amp;lt;/code&amp;gt; you need to download input files and Yambo databases for this tutorial here: [wget https://media.yambo-code.eu/educational/tutorials/files/hBN-2D.tar.gz hBN-2D.tar.gz].&lt;br /&gt;
Unzip the tarball and change directory to &amp;lt;code&amp;gt;YAMBO&amp;lt;/code&amp;gt; and run the setup (&amp;lt;code&amp;gt;yambo_nl -nompi&amp;lt;/code&amp;gt;). &lt;br /&gt;
Execute the command &lt;br /&gt;
 ypp_nl -fixsym -F 00_removesym.in  &lt;br /&gt;
to create the input, to remove the symmetries which are not compatible with the field: &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;1.000000 | 1.000000 | 0.000000 |&amp;lt;/span&amp;gt;        # First external Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 % Efield2&lt;br /&gt;
  0.000000 | 0.000000 | 0.000000 |        # 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;
 #KeepKGrid                     # Do not expand the k-grid&lt;br /&gt;
where we chose the field along the xy direction and we remove time-reversal symmetry.&lt;br /&gt;
&lt;br /&gt;
Then run the pre-processing job:&lt;br /&gt;
 ypp_nl -F 00_removesym.in J 00_removesym&lt;br /&gt;
This creates the directory &amp;lt;code&amp;gt;FixSymm&amp;lt;/code&amp;gt;. Change directory to &amp;lt;code&amp;gt;FixSymm&amp;lt;/code&amp;gt;. This contains the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory with reduced symmetries, compatible with the direction of the field. Now run the setup again (&amp;lt;code&amp;gt;yambo_nl -nompi&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
= Step 2: Independent-particle approximation =&lt;br /&gt;
&lt;br /&gt;
Use the command:&lt;br /&gt;
  yambo_nl -nl n -F 01_SHG_ip.in&lt;br /&gt;
to generate the input:&lt;br /&gt;
&lt;br /&gt;
 nloptics                         # [R] Non-linear spectroscopy&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=-1.000000           fs    # [NL] Simulation Time&lt;br /&gt;
 NLintegrator= &amp;quot;INVINT&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;
 % NLEnRange&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;0.5000000 |8.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;12&amp;lt;/span&amp;gt;                     # [NL] Energy steps&lt;br /&gt;
 NLDamping= 0.200000        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;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&amp;quot;SIN&amp;quot; &amp;lt;/span&amp;gt;          # [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 | 1.000000 | 0.000000 |&amp;lt;/span&amp;gt;        # [RT Field1] Versor&lt;br /&gt;
 %&lt;br /&gt;
 Field1_Tstart= 0.010000    fs    # [RT Field1] Initial Time&lt;br /&gt;
&lt;br /&gt;
To describe the Bloch-dynamics we will use as a basis the KS-states 3-6 for the k-grid used in the non-scf DFT calculations, that is a 6x6x1 (&amp;lt;code&amp;gt;NLBands&amp;lt;/code&amp;gt;). We choose 12 equally spaced frequencies (&amp;lt;code&amp;gt;NLEnSteps&amp;lt;/code&amp;gt;) for the applied field in the range  (&amp;lt;code&amp;gt;NLEnRange&amp;lt;/code&amp;gt;) between 0.5 and 8 eV. We choose a sinusoidal time-dependence (&amp;lt;code&amp;gt;Field1_kind&amp;lt;/code&amp;gt;) and set the field direction (&amp;lt;code&amp;gt;Field1_kind&amp;lt;/code&amp;gt;) along xy (in plane). The negative simulation time (&amp;lt;code&amp;gt;NLtime=-1.000000&amp;lt;/code&amp;gt;) means that the code will choose it based on the value of the &amp;lt;code&amp;gt;NLDamping&amp;lt;/code&amp;gt;. While this is a good lower bound for the simulation time, one should check it is sufficient to get accurate results. &lt;br /&gt;
&lt;br /&gt;
Run the simulation, possibly in parallel e. g. in a interactive session on 4 cores. &lt;br /&gt;
&lt;br /&gt;
[In order to get 4 cores while in an interacting node, exit your current allocation and rerun &amp;lt;code&amp;gt;salloc&amp;lt;/code&amp;gt; asking for the proper number of tasks:&lt;br /&gt;
 salloc -A tra23_Yambo -p m100_usr_prod -q m100_qos_dbg --nodes=1 --ntasks-per-node=&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;4&amp;lt;/span&amp;gt; --cpus-per-task=4 -t 02:00:00&lt;br /&gt;
Otherwise, you can submit the job with a slurm script as explained in the introductory page]&lt;br /&gt;
&lt;br /&gt;
Now execute the command:&lt;br /&gt;
  mpirun -n 4 yambo_nl -F 01_SHG_ip.in -J 01_SHG_ip -C 01_SHG_ip_files&lt;br /&gt;
&lt;br /&gt;
Once the run is finished, check the report &amp;lt;code&amp;gt;01_SHG_ip_files/r-01_SHG_ip_nloptics&amp;lt;/code&amp;gt;. In particular, in the appended input files, you can see the default parallelization applied by the code for calculating the dipoles and run the time-propagation. For the latter, the main parallelization is on the frequencies and then on the k-points (&amp;lt;code&amp;gt;NL_ROLEs= &amp;quot;w.k&amp;quot;&amp;lt;/code&amp;gt;).   &lt;br /&gt;
&lt;br /&gt;
 | NL_CPU= &amp;quot;2.2&amp;quot;                    # [PARALLEL] CPUs for each role&lt;br /&gt;
 | NL_ROLEs= &amp;quot;w.k&amp;quot;                  # [PARALLEL] CPUs roles (w,k)&lt;br /&gt;
 | DIP_CPU= &amp;quot;2.2.1&amp;quot;                 # [PARALLEL] CPUs for each role&lt;br /&gt;
 | DIP_ROLEs= &amp;quot;v.c.k&amp;quot;               # [PARALLEL] CPUs roles (k,c,v)&lt;br /&gt;
&lt;br /&gt;
Also, look at the simulation time. This is approximately 42 fs. &lt;br /&gt;
&lt;br /&gt;
Plot the polarization for a couple of frequencies, e.g. the first and last of the chosen range (the corresponding frequency can be read in the file, search for &amp;quot;Frequency value&amp;quot;):&lt;br /&gt;
 set ylabel &amp;quot;x-component polarization&amp;quot; offset -0.7&lt;br /&gt;
 set xlabel &amp;quot;time (fs)&amp;quot;&lt;br /&gt;
 plot &#039;01_SHG_ip_files/o-01_SHG_ip.polarization_F1&#039; u 1:2 w l lw 2 title &amp;quot;omega = 0.5 eV&amp;quot;&lt;br /&gt;
 replot &#039;01_SHG_ip_files/o-01_SHG_ip.polarization_F12&#039; u 1:2 w l lw 2  title &amp;quot;omega = 7.375 eV&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[File:Berry_phase_polarization_of_2D_h-BN_obtained_from_the_previous_run_for_two_laser_frequencies.png|Berry_phase_polarization_of_2D_h-BN_obtained from the run for two laser frequencies]]&lt;br /&gt;
&lt;br /&gt;
After the applied field is &#039;switched on&#039;, the polarization is oscillating at the frequency of the applied field and at the eigenfrequencies of the system as described above in the cartoon. This is visible particularly for the higher frequency. Due to the dephasing, after about 20 fs the polarization is oscillating (at least to the eye) at the frequency of the applied field. Nonlinear components are not visible since they are several orders of magnitude smaller than the first order.&lt;br /&gt;
&lt;br /&gt;
== Output post-processing: the dielectric function ==&lt;br /&gt;
&lt;br /&gt;
Once we obtained the polarization, we Fourier-transform the polarization to obtain the dielectric function.&lt;br /&gt;
&lt;br /&gt;
Use the command:&lt;br /&gt;
&lt;br /&gt;
  ypp_nl -nl -F 02_SHG_ip_pp.in -C 01_SHG_ip_files&lt;br /&gt;
&lt;br /&gt;
to generate the input file: &lt;br /&gt;
&lt;br /&gt;
 nonlinear                        # [R] Non-linear response analysis&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;Xorder= 4&amp;lt;/span&amp;gt; # 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;NONE&amp;quot;                 # Damping type ( NONE | LORENTZIAN | GAUSSIAN )&lt;br /&gt;
 DampFactor= 0.000000       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;
Where we changed the &amp;lt;code&amp;gt;Xorder&amp;lt;/code&amp;gt; to 4. This variable controls the terms in the Fourier expansion of the polarization. We choose up to expand up to the fourth order. This should ensure the second order to be accurate enough. As an exercise, you can change this value (e.g. choose 2,3,5,6) and see how the result below is changing. The time-window where processing is done is chosen automatically, since values are negative. The code chooses by default the last period to carry out the analysis. &lt;br /&gt;
&lt;br /&gt;
To run the post-processing, use the command:&lt;br /&gt;
 ypp_nl -F Inputs_shg/ypp_shg.in -J TD-IP_nl -C TD-IP_nl. &lt;br /&gt;
   &lt;br /&gt;
In  &amp;lt;code&amp;gt;01_SHG_ip_files&amp;lt;/code&amp;gt; the following files were generated &lt;br /&gt;
 o-01_SHG_ip.YPP-X_probe_order_1&lt;br /&gt;
 o-01_SHG_ip.YPP-X_probe_order_2&lt;br /&gt;
 o-01_SHG_ip.YPP-X_probe_order_3&lt;br /&gt;
 o-01_SHG_ip.YPP-X_probe_order_4&lt;br /&gt;
 r-01_SHG_ip_nonlinear&lt;br /&gt;
&lt;br /&gt;
The output files contain respectively the first, second, third and fourth order response(corresponding to &amp;lt;code&amp;gt;Xorder=4&amp;lt;/code&amp;gt;)  at the 12 frequencies in the chosen range. &lt;br /&gt;
 &lt;br /&gt;
Inspect &amp;lt;code&amp;gt;o-01_SHG_ip.YPP-X_probe_order_2&amp;lt;/code&amp;gt;&lt;br /&gt;
 #     E [eV]            X/Im[cm/stV](x)    X/Re[cm/stV](x)    X/Im[cm/stV](y)    X/Re[cm/stV](y)    X/Im[cm/stV](z)    X/Re[cm/stV](z)&lt;br /&gt;
 #&lt;br /&gt;
      0.50000000        -0.35378838E-09    -0.19774796E-07     0.23591828E-09    -0.89405637E-09      0.0000000          0.0000000    &lt;br /&gt;
      1.1250000         -0.19356524E-08    -0.23160605E-07    -0.16052184E-09    -0.67662771E-09      0.0000000          0.0000000    &lt;br /&gt;
      1.7500000         -0.69446459E-08    -0.35586956E-07    -0.76025706E-09    -0.10205678E-08      0.0000000          0.0000000    &lt;br /&gt;
      2.37500000        -0.181606152E-7    -0.261823658E-8     0.438358596E-8     0.407915226E-8      0.00000000         0.00000000   &lt;br /&gt;
&lt;br /&gt;
The first column are the frequencies of the applied field, the second and third is the polarization along x (imaginary and real part), the fourth and fifth is the polarization along y (imaginary and real part)  &lt;br /&gt;
and the sixth and seventh is the polarization along z (imaginary and real part).&lt;br /&gt;
&lt;br /&gt;
Plot the absolute value of the SHG for the &amp;quot;xxy&amp;quot; component (that is, the applied field is in the x and y directions and one look at the polarization along x):&lt;br /&gt;
&lt;br /&gt;
 set ylabel &amp;quot;{/Symbol=26 \174}{/Symbol=26 c}_{xyx}^{(2)}{/Symbol=26 \174} (pm/V)&amp;quot; offset -0.7&lt;br /&gt;
 set xlabel &amp;quot;Energy (eV)&amp;quot;&lt;br /&gt;
 pmVm1toCGS=2.38721e-09&lt;br /&gt;
 plot &#039;01_SHG_ip_files/o-01_SHG_ip.YPP-X_probe_order_2&#039; u 1:(sqrt($2**2+$3**2)/pmVm1toCGS) w p title &amp;quot;calc&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[File: SHG_intensity_of_2D_h-BN_obtained_from_the_previous_run_(and_compared_with_a_run_on_112_frequencies).png | SHG_intensity_of_2D_h-BN obtained from the current run (12 frequencies) compared with a run with 112 frequencies]] &lt;br /&gt;
&lt;br /&gt;
In the figure above, the results of the current run are compared with those for a run with 112 frequencies (one can obtain these results by repeating the calculations, changing the number of frequencies in &amp;lt;code&amp;gt;NLEnSteps&amp;lt;/code&amp;gt; though this take about 10 times more computational time than the run with 12). One can notice some differences between the two runs. In fact, the two runs evaluate different frequnecies and the difference indicates spurious oscillations of the value of the polarizability due to the simulation time being too short and thus to the presence of &#039;noise&#039; due to the eigenfrecies.  &lt;br /&gt;
As an exercise, you can repeat the simulation for e,g, a time of &amp;lt;code&amp;gt;60 fs&amp;lt;/code&amp;gt;, that is setting &amp;lt;code&amp;gt;NLtime=60&amp;lt;/code&amp;gt;. The plot below compare the SHG extracted at 42 fs and 60 fs, where the latter gives clearly more accurate results. &lt;br /&gt;
&lt;br /&gt;
[[File:Comparison of the SHG intensity of 2D h-BN obtained with different simulation time.png|Comparison of the SHG intensity of 2D h-BN obtained with different simulation time]]&lt;br /&gt;
&lt;br /&gt;
As a final note, the SHG depends on the size of the vacuum added in the supercell. Instead, one should consider the surface SHG which obtained by considering an effective thickness for the layer. This is usually chosen to be similar to the layer separation in the bulk counterpart.&lt;br /&gt;
&lt;br /&gt;
= Step 3: Hartree+Screened exchange approximation (BSE level) =&lt;br /&gt;
&lt;br /&gt;
== Hartree+Screened exchange collisions ==&lt;br /&gt;
Similarly to the linear part, one needs to generate the Screened exchange collisions. The procedure is exactly the same.&lt;br /&gt;
&lt;br /&gt;
Create the input:&lt;br /&gt;
 yambo_nl -X s -e -v hsex -F 03_coll_hsex.in&lt;br /&gt;
modify the input ad follows&lt;br /&gt;
 em1s                             # [R][Xs] Statically Screened Interaction&lt;br /&gt;
 collisions                       # [R] Collisions&lt;br /&gt;
 dipoles                          # [R] Oscillator strenghts (or dipoles)&lt;br /&gt;
 Chimod= &amp;quot;HARTREE&amp;quot;                # [X] IP/Hartree/ALDA/LRC/PF/BSfxc&lt;br /&gt;
 % BndsRnXs&lt;br /&gt;
    1 |  20 |                         # [Xs] Polarization function bands&lt;br /&gt;
 %&lt;br /&gt;
 NGsBlkXs= 1000 mHa    # [Xs] Response block size&lt;br /&gt;
 % LongDrXs&lt;br /&gt;
  1.000000 | 1.000000 | 0.000000 |        # [Xs] [cc] Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 % COLLBands&lt;br /&gt;
    4 |  5 |                         # [COLL] Bands for the collisions&lt;br /&gt;
 %&lt;br /&gt;
 HXC_Potential= &amp;quot;SEX+HARTREE&amp;quot;     # [SC] SC HXC Potential&lt;br /&gt;
 HARRLvcs= 1000 mHa    # [HA] Hartree     RL components&lt;br /&gt;
 EXXRLvcs= 1000 mHa    # [XX] Exchange    RL components&lt;br /&gt;
 CORRLvcs= 1000 mHa    # [GW] Correlation RL components&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Calculate the collisions (you may want to run in parallel):&lt;br /&gt;
 yambo_nl -F 03_coll_hsex.in -J 03_coll -C 04_hsex_files&lt;br /&gt;
&lt;br /&gt;
== Run the simulation ==&lt;br /&gt;
&lt;br /&gt;
Create the input:&lt;br /&gt;
 yambo_nl -nl n -v hsex -V qp -F 04_SHG_hsex.in&lt;br /&gt;
&lt;br /&gt;
modify the following parts of the input (by this time all the innput variables should be known from the previous exercises):&lt;br /&gt;
&lt;br /&gt;
 % BndsRnXs&lt;br /&gt;
   1 |  20 |                         # [Xs] Polarization function bands&lt;br /&gt;
 %&lt;br /&gt;
 NGsBlkXs= 1000 mHa    # [Xs] Response block size&lt;br /&gt;
 % LongDrXs&lt;br /&gt;
  1.000000 | 1.000000 | 0.000000 |        # [Xs] [cc] Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 % NLBands&lt;br /&gt;
    4 |  5 |                         # [NL] Bands range&lt;br /&gt;
 %&lt;br /&gt;
&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;SEX&amp;quot;             # [NL] Correlation (&amp;quot;IPA/HARTREE/TDDFT/LRC/LRW/JGM/SEX&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 % NLEnRange&lt;br /&gt;
  0.500000 |8.000000 |         eV    # [NL] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 NLEnSteps= 12                   # [NL] Energy steps&lt;br /&gt;
&lt;br /&gt;
 % GfnQP_E&lt;br /&gt;
  3.000000 | 1.000000 | 1.000000 |        # [EXTQP G] E parameters  (c/v) eV|adim|adim&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
 Field1_kind= &amp;quot;SIN&amp;quot;           # [RT Field1] Kind(SIN|COS|RES|ANTIRES|GAUSS|DELTA|QSSIN)&lt;br /&gt;
&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
  1.000000 | 1.000000 | 0.000000 |        # [RT Field1] Versor&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
Then run the simulation using e.g. mpi and 4 cores:&lt;br /&gt;
 mpirun -n 4 yambo_nl -F 04_SHG_hsex.in -J 04_SHG_hsex,03_coll -C 04_SHG_hsex_files&lt;br /&gt;
&lt;br /&gt;
== Postprocessing: obtain the nonlinear response ==&lt;br /&gt;
&lt;br /&gt;
Similarly to what we did for the independent particle case, we create the input:&lt;br /&gt;
 ypp_nl -nl -F 05_SHG_hsex_pp.in&lt;br /&gt;
 &lt;br /&gt;
we change &amp;lt;code&amp;gt;Xorder = 4 &amp;lt;/code&amp;gt; and then run:&lt;br /&gt;
 ypp_nl -F 05_SHG_hsex_pp.in -J 04_SHG_hsex -C 04_hsex_files&lt;br /&gt;
&lt;br /&gt;
Then we plot (as before we compare with a simulation ran for 112 frequnecies).&lt;br /&gt;
&lt;br /&gt;
Plot the results:&lt;br /&gt;
&lt;br /&gt;
 set ylabel &amp;quot;{/Symbol=26 \174}{/Symbol=26 c}_{xyx}^{(2)}{/Symbol=26 \174} (pm/V)&amp;quot; offset -0.7&lt;br /&gt;
 set xlabel &amp;quot;Energy (eV)&amp;quot;&lt;br /&gt;
 pmVm1toCGS=2.38721e-09&lt;br /&gt;
 plot &#039;04_hsex_files/o-04_SHG_hsex.YPP-X_probe_order_2&#039; u 1:(sqrt($2**2+$3**2)/pmVm1toCGS) w p title &amp;quot;calc&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[File:SHG hsex.png|SHG at the Hartree + Screened exchange from current run with 12 frequencies (crosses) and a run with 112 frequencies (keeping the other parameters the same)]]&lt;br /&gt;
&lt;br /&gt;
also in this case we note differences between the two simulations. This is due to the too short simulation time. Repeating the calculations with a longer time gives more accurate results. &lt;br /&gt;
In addition, note that in the interest of time, all parameters are underconverged. In principle, to calculate the collisions one should use the same parameters of a converged BSE calculation. As well, one should use the Coulomb cutoff as it was used for this system in the  BSE case.&lt;br /&gt;
&lt;br /&gt;
= References = &lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Fulvio</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Rome_2023&amp;diff=6997</id>
		<title>Rome 2023</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Rome_2023&amp;diff=6997"/>
		<updated>2023-05-25T08:51:19Z</updated>

		<summary type="html">&lt;p&gt;Fulvio: /* DAY 4 - Thursday, May 25 */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;A general description of the goal(s) of the school can be found on the [https://www.yambo-code.eu/2023/02/18/yambo-school-2023/ Yambo main website]&lt;br /&gt;
&lt;br /&gt;
== Use CINECA computational resources ==&lt;br /&gt;
Yambo tutorials will be run on the MARCONI100 (M100) accelerated cluster. You can find info about M100 [https://wiki.u-gov.it/confluence/display/SCAIUS/UG3.2%3A+MARCONI100+UserGuide#UG3.2:MARCONI100UserGuide here].&lt;br /&gt;
In order to access computational resources provided by CINECA you need your personal username and password that were sent you by the organizers.&lt;br /&gt;
&lt;br /&gt;
=== Connect to the cluster using ssh ===&lt;br /&gt;
&lt;br /&gt;
You can access M100 via &amp;lt;code&amp;gt;ssh&amp;lt;/code&amp;gt; protocol in different ways.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; - Connect using username and password &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
Use the following command replacing your username:&lt;br /&gt;
 $ ssh username@login.m100.cineca.it&lt;br /&gt;
&lt;br /&gt;
However, in this way you have to type your password each time you want to connect.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; - Connect using ssh key &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
You can setup a ssh key pair to avoid typing the password each time you want to connect to M100. To do so, go to your &amp;lt;code&amp;gt;.ssh&amp;lt;/code&amp;gt; directory (usually located in the &amp;lt;code&amp;gt;home&amp;lt;/code&amp;gt; directory):&lt;br /&gt;
 $ cd $HOME/.ssh&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t have this directory, you can create it with &amp;lt;code&amp;gt;mkdir $HOME/.ssh&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Once you are in the &amp;lt;code&amp;gt;.ssh&amp;lt;/code&amp;gt; directory, run the &amp;lt;code&amp;gt;ssh-keygen&amp;lt;/code&amp;gt; command to generate a private/public key pair:&lt;br /&gt;
 $ ssh-keygen&lt;br /&gt;
 Generating public/private rsa key pair.&lt;br /&gt;
 Enter file in which to save the key: m100_id_rsa&lt;br /&gt;
 Enter passphrase (empty for no passphrase): &lt;br /&gt;
 Enter same passphrase again: &lt;br /&gt;
 Your identification has been saved in &amp;lt;your_.ssh_dir&amp;gt;/m100_id_rsa&lt;br /&gt;
 Your public key has been saved in &amp;lt;your_.ssh_dir&amp;gt;/m100_id_rsa.pub&lt;br /&gt;
 The key fingerprint is:&lt;br /&gt;
 &amp;lt;...&amp;gt;&lt;br /&gt;
 The key&#039;s randomart image is:&lt;br /&gt;
 &amp;lt;...&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now you need to copy the &#039;&#039;&#039;public&#039;&#039;&#039; key to M100. You can do that with the following command (for this step you need to type your password):&lt;br /&gt;
 $ ssh-copy-id -i &amp;lt;your_.ssh_dir&amp;gt;/m100_id_rsa.pub &amp;lt;username&amp;gt;@login.m100.cineca.it&lt;br /&gt;
&lt;br /&gt;
Once the public key has been copied, you can connect to M100 without having to type the password using the &amp;lt;code&amp;gt;-i&amp;lt;/code&amp;gt; option:&lt;br /&gt;
 $ ssh -i &amp;lt;your_.ssh_dir&amp;gt;/m100_id_rsa username@login.m100.cineca.it&lt;br /&gt;
&lt;br /&gt;
To simplify even more, you can paste the following lines in a file named &amp;lt;code&amp;gt;config&amp;lt;/code&amp;gt; located inside the &amp;lt;code&amp;gt;.ssh&amp;lt;/code&amp;gt; directory adjusting username and path:&lt;br /&gt;
 Host m100 &lt;br /&gt;
  HostName login.m100.cineca.it&lt;br /&gt;
  User username&lt;br /&gt;
  IdentityFile &amp;lt;your_.ssh_dir&amp;gt;/m100_id_rsa&lt;br /&gt;
&lt;br /&gt;
With the &amp;lt;code&amp;gt;config&amp;lt;/code&amp;gt; file setup you can connect simply with&lt;br /&gt;
 $ ssh m100&lt;br /&gt;
&lt;br /&gt;
=== General instructions to run tutorials ===&lt;br /&gt;
&lt;br /&gt;
Before proceeding, it is useful to know the different workspaces you have available on M100, which can be accessed using environment variables. The main ones are:&lt;br /&gt;
* &amp;lt;code&amp;gt;$HOME&amp;lt;/code&amp;gt;: it&#039;s the &amp;lt;code&amp;gt;home&amp;lt;/code&amp;gt; directory associated to your username; &lt;br /&gt;
* &amp;lt;code&amp;gt;$WORK&amp;lt;/code&amp;gt;: it&#039;s the &amp;lt;code&amp;gt;work&amp;lt;/code&amp;gt; directory associated to the account where the computational resources dedicated to this school are allocated;&lt;br /&gt;
* &amp;lt;code&amp;gt;$CINECA_SCRATCH&amp;lt;/code&amp;gt;: it&#039;s the &amp;lt;code&amp;gt;scratch&amp;lt;/code&amp;gt; directory associated to your username.&lt;br /&gt;
You can find more details about storage and FileSystems [https://wiki.u-gov.it/confluence/display/SCAIUS/UG2.5%3A+Data+storage+and+FileSystems here].&lt;br /&gt;
&lt;br /&gt;
Please don&#039;t forget to &#039;&#039;&#039;run all tutorials in your scratch directory&#039;&#039;&#039;:&lt;br /&gt;
 $ echo $CINECA_SCRATCH&lt;br /&gt;
 /m100_scratch/userexternal/username&lt;br /&gt;
 $ cd $CINECA_SCRATCH&lt;br /&gt;
&lt;br /&gt;
Computational resources on M100 are managed by the job scheduling system [https://slurm.schedmd.com/overview.html Slurm]. Most part of Yambo tutorials during this school can be run in serial, except some that need to be executed on multiple processors. Generally, Slurm batch jobs are submitted using a script, but the tutorials here are better understood if run interactively. The two procedures that we will use to submit interactive and non interactive jobs are explained below.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; - Run a job using a batch script &#039;&#039;&#039;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
This procedure is suggested for the tutorials and examples that need to be run in parallel. In these cases you need to submit the job using a batch script &amp;lt;code&amp;gt;job.sh&amp;lt;/code&amp;gt;, whose generic structure is the following:&lt;br /&gt;
 $ more job.sh&lt;br /&gt;
 #!/bin/bash&lt;br /&gt;
 #SBATCH --account=tra23_Yambo           # Charge resources used by this job to specified account&lt;br /&gt;
 #SBATCH --time=00:10:00                 # Set a limit on the total run time of the job allocation in hh:mm:ss&lt;br /&gt;
 #SBATCH --job-name=JOB                  # Specify a name for the job allocation&lt;br /&gt;
 #SBATCH --partition= m100_sys_test      # Request a specific partition for the resource allocation&lt;br /&gt;
 #SBATCH --qos=qos_test                  # qos = quality of service &lt;br /&gt;
 #SBATCH --reservation=s_tra_yambo       # Reservation specific to this school &lt;br /&gt;
 #          &lt;br /&gt;
 #SBATCH --nodes=&amp;lt;N&amp;gt;                     # Number of nodes to be allocated for the job&lt;br /&gt;
 #SBATCH --ntasks-per-node=&amp;lt;nt&amp;gt;          # Number of MPI tasks invoked per node&lt;br /&gt;
 #SBATCH --ntasks-per-socket=&amp;lt;nt/2&amp;gt;      # Tasks invoked on each socket&lt;br /&gt;
 #SBATCH --cpus-per-task=&amp;lt;nc&amp;gt;            # Number of OMP threads per task&lt;br /&gt;
 &lt;br /&gt;
 module purge&lt;br /&gt;
 module load hpc-sdk/2022--binary&lt;br /&gt;
 module load spectrum_mpi/10.4.0--binary&lt;br /&gt;
 export PATH=/m100_work/tra23_Yambo/softwares/YAMBO/5.2-mpi/bin:$PATH&lt;br /&gt;
 &lt;br /&gt;
 export OMP_NUM_THREADS=&amp;lt;nc&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 mpirun --rank-by core -np ${SLURM_NTASKS} \&lt;br /&gt;
        yambo -F &amp;lt;input&amp;gt; -J &amp;lt;output&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This procedure is suggested for the tutorials and examples that need to be run in parallel. In these cases you need to submit the job using a batch script &amp;lt;code&amp;gt;job.sh&amp;lt;/code&amp;gt;. Please note that the instructions in the batch script must be compatible with the specific M100 [https://wiki.u-gov.it/confluence/display/SCAIUS/UG3.2%3A+MARCONI100+UserGuide#UG3.2:MARCONI100UserGuide-SystemArchitecture architecture] and [https://wiki.u-gov.it/confluence/display/SCAIUS/UG3.2%3A+MARCONI100+UserGuide#UG3.2:MARCONI100UserGuide-Accounting accounting] systems. The complete list of Slurm options can be found [https://slurm.schedmd.com/sbatch.html here]. However you will find &#039;&#039;&#039;ready-to-use&#039;&#039;&#039; batch scripts in locations specified during the tutorials. &lt;br /&gt;
&lt;br /&gt;
To submit the job, use the &amp;lt;code&amp;gt;sbatch&amp;lt;/code&amp;gt; command:&lt;br /&gt;
 $ sbatch job.sh&lt;br /&gt;
 Submitted batch job &amp;lt;JOBID&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To check the job status, use the &amp;lt;code&amp;gt;squeue&amp;lt;/code&amp;gt; command:&lt;br /&gt;
 $ squeue -u &amp;lt;username&amp;gt;&lt;br /&gt;
              JOBID PARTITION     NAME     USER ST       TIME  NODES NODELIST(REASON)&lt;br /&gt;
              &amp;lt;...&amp;gt;  m100_...      JOB username  R       0:01    &amp;lt;N&amp;gt; &amp;lt;...&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you need to cancel your job, do:&lt;br /&gt;
 $ scancel &amp;lt;JOBID&amp;gt; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; - Open an interactive session &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This procedure is suggested for most of the tutorials, since the majority of these is meant to be run in serial (relatively to MPI parallelization) from the command line. Use the command below to open an interactive session of 1 hour (complete documentation [https://slurm.schedmd.com/salloc.html here]):&lt;br /&gt;
 $ salloc -A tra23_Yambo -p m100_sys_test -q qos_test --reservation=s_tra_yambo --nodes=1 --ntasks-per-node=1 --cpus-per-task=4 -t 01:00:00&lt;br /&gt;
 salloc: Granted job allocation 10164647&lt;br /&gt;
 salloc: Waiting for resource configuration&lt;br /&gt;
 salloc: Nodes r256n01 are ready for job&lt;br /&gt;
&lt;br /&gt;
We ask for 4 cpus-per-task because we can exploit OpenMP parallelization with the available resources.&lt;br /&gt;
&lt;br /&gt;
With &amp;lt;code&amp;gt;squeue&amp;lt;/code&amp;gt; you can see that there is now a job running:&lt;br /&gt;
 $ squeue -u username&lt;br /&gt;
              JOBID PARTITION     NAME     USER ST       TIME  NODES NODELIST(REASON)&lt;br /&gt;
           10164647 m100_usr_ interact username  R       0:02      1 r256n01&lt;br /&gt;
&lt;br /&gt;
To run the tutorial, &amp;lt;code&amp;gt;ssh&amp;lt;/code&amp;gt; into the node specified by the job allocation and &amp;lt;code&amp;gt;cd&amp;lt;/code&amp;gt; to your scratch directory:&lt;br /&gt;
 username@&#039;&#039;&#039;login02&#039;&#039;&#039;$ ssh r256n01&lt;br /&gt;
 ...&lt;br /&gt;
 username@&#039;&#039;&#039;r256n01&#039;&#039;&#039;$ cd $CINECA_SCRATCH&lt;br /&gt;
&lt;br /&gt;
Then, you need to manually load &amp;lt;code&amp;gt;yambo&amp;lt;/code&amp;gt; as in the batch script above. Please note that the serial version of the code is in a different directory and does not need &amp;lt;code&amp;gt;spectrum_mpi&amp;lt;/code&amp;gt;:&lt;br /&gt;
 $ module purge&lt;br /&gt;
 $ module load hpc-sdk/2022--binary spectrum_mpi/10.4.0--binary&lt;br /&gt;
 $ export PATH=/m100_work/tra23_Yambo/softwares/YAMBO/5.2-cpu/bin:$PATH&lt;br /&gt;
&lt;br /&gt;
Finally, set the &amp;lt;code&amp;gt;OMP_NUM_THREADS&amp;lt;/code&amp;gt; environment variable to 4 (as in the &amp;lt;code&amp;gt;--cpus-per-task&amp;lt;/code&amp;gt; option):&lt;br /&gt;
 $ export OMP_NUM_THREADS=4&lt;br /&gt;
&lt;br /&gt;
To close the interactive session when you have finished, log out of the compute node with the &amp;lt;code&amp;gt;exit&amp;lt;/code&amp;gt; command, and then cancel the job:&lt;br /&gt;
 $ exit&lt;br /&gt;
 $ scancel &amp;lt;JOBID&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; - Plot results with gnuplot &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
During the tutorials you will often need to plot the results of the calculations. In order to do so on M100, &#039;&#039;&#039;open a new terminal window&#039;&#039;&#039; and connect to M100 enabling X11 forwarding with the &amp;lt;code&amp;gt;-X&amp;lt;/code&amp;gt; option:&lt;br /&gt;
 $ ssh -X m100&lt;br /&gt;
&lt;br /&gt;
Please note that &amp;lt;code&amp;gt;gnuplot&amp;lt;/code&amp;gt; can be used in this way only from the login nodes:&lt;br /&gt;
 username@&#039;&#039;&#039;login01&#039;&#039;&#039;$ cd &amp;lt;directory_with_data&amp;gt;&lt;br /&gt;
 username@&#039;&#039;&#039;login01&#039;&#039;&#039;$ gnuplot&lt;br /&gt;
 ...&lt;br /&gt;
 Terminal type is now &#039;...&#039;&lt;br /&gt;
 gnuplot&amp;gt; plot &amp;lt;...&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039; - Set up yambopy &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
In order to run yambopy on m100, you must first setup the conda environment (to be done only once):&lt;br /&gt;
 $ cd&lt;br /&gt;
 $ module load anaconda/2020.11&lt;br /&gt;
 $ conda init bash&lt;br /&gt;
 $ source .bashrc&lt;br /&gt;
&lt;br /&gt;
After this, every time you want to use yambopy you need to load its module and environment:&lt;br /&gt;
 $ module load anaconda/2020.11&lt;br /&gt;
 $ conda activate /m100_work/tra23_Yambo/softwares/YAMBO/env_yambopy&lt;br /&gt;
&lt;br /&gt;
== Tutorials ==&lt;br /&gt;
&lt;br /&gt;
Quick recap.&lt;br /&gt;
Before every tutorial do the following steps&lt;br /&gt;
&lt;br /&gt;
 $ ssh m100&lt;br /&gt;
 $ cd $CINECA_SCRATCH&lt;br /&gt;
 $ mkdir YAMBO_TUTORIALS &#039;&#039;&#039;(Only if you didn&#039;t before)&#039;&#039;&#039;&lt;br /&gt;
 $ cd YAMBO_TUTORIALS&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== DAY 1 - Monday, 22 May === &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;16:15 - 18:30 From the DFT ground state to the complete setup of a Many Body calculation using Yambo&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
To get the tutorial files needed for the following tutorials, follow these steps:&lt;br /&gt;
 $ wget https://media.yambo-code.eu/educational/tutorials/files/hBN.tar.gz&lt;br /&gt;
 $ wget https://media.yambo-code.eu/educational/tutorials/files/hBN-2D.tar.gz&lt;br /&gt;
 $ ls&lt;br /&gt;
 hBN-2D.tar.gz  hBN.tar.gz&lt;br /&gt;
 $ tar -xvf hBN-2D.tar.gz&lt;br /&gt;
 $ tar -xvf hBN.tar.gz&lt;br /&gt;
 $ ls&lt;br /&gt;
 &#039;&#039;&#039;hBN-2D&#039;&#039;&#039; &#039;&#039;&#039;hBN&#039;&#039;&#039; hBN-2D.tar.gz  hBN.tar.gz&lt;br /&gt;
&lt;br /&gt;
Now that you have all the files, you may open the interactive job session with &amp;lt;code&amp;gt;salloc&amp;lt;/code&amp;gt; as explained above and proceed with the tutorials.&lt;br /&gt;
&lt;br /&gt;
* [[First steps: walk through from DFT(standalone)|First steps: Initialization and more ]]&lt;br /&gt;
* [[Next steps: RPA calculations (standalone)|Next steps: RPA calculations ]]&lt;br /&gt;
&lt;br /&gt;
At this point, you may learn about the python pre-postprocessing capabilities offered by yambopy, our python interface to yambo and QE. First of all, let&#039;s create a dedicated directory, download and extract the related files.&lt;br /&gt;
 &lt;br /&gt;
 $ cd $CINECA_SCRATCH&lt;br /&gt;
 $ mkdir YAMBOPY_TUTORIALS&lt;br /&gt;
 $ cd YAMBOPY_TUTORIALS&lt;br /&gt;
 $ wget https://media.yambo-code.eu/educational/tutorials/files/databases_yambopy.tar&lt;br /&gt;
 $ tar -xvf databases_yambopy.tar&lt;br /&gt;
 $ cd databases_yambopy&lt;br /&gt;
&lt;br /&gt;
Then, follow &#039;&#039;&#039;the first three sections&#039;&#039;&#039; of this link, which are related to initialization and linear response.&lt;br /&gt;
* [[Yambopy tutorial: Yambo databases|Reading databases with yambopy]]&lt;br /&gt;
&lt;br /&gt;
=== DAY 2 - Tuesday, 23 May ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;14:00 - 16:30 A tour through GW simulation in a complex material (from the blackboard to numerical computation: convergence, algorithms, parallel usage)&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
To get all the tutorial files needed for the following tutorials, follow these steps:&lt;br /&gt;
&lt;br /&gt;
 wget https://media.yambo-code.eu/educational/tutorials/files/hBN.tar.gz&lt;br /&gt;
 wget https://media.yambo-code.eu/educational/tutorials/files/MoS2_2Dquasiparticle_tutorial.tar.gz&lt;br /&gt;
 tar -xvf hBN.tar.gz&lt;br /&gt;
 tar -xvf MoS2_2Dquasiparticle_tutorial.tar.gz&lt;br /&gt;
 cd hBN&lt;br /&gt;
&lt;br /&gt;
Now you can start the first tutorial:&lt;br /&gt;
&lt;br /&gt;
* [[GW tutorial Rome 2023 | GW computations on practice: how to obtain the quasi-particle band structure of a bulk material ]]&lt;br /&gt;
&lt;br /&gt;
If you have gone through the first tutorial, pass now to the second one:&lt;br /&gt;
 &lt;br /&gt;
 cd $CINECA_SCRATCH&lt;br /&gt;
 cd YAMBO_TUTORIALS&lt;br /&gt;
 cd MoS2_HPC_tutorial&lt;br /&gt;
&lt;br /&gt;
* [[Quasi-particles of a 2D system | Quasi-particles of a 2D system ]]&lt;br /&gt;
&lt;br /&gt;
To conclude, you can learn an other method to plot the band structure in Yambo&lt;br /&gt;
&lt;br /&gt;
* [[Yambopy tutorial: band structures| Yambopy tutorial: band structures]]&lt;br /&gt;
&lt;br /&gt;
=== DAY 3 - Wednesday, 24 May ===&lt;br /&gt;
&#039;&#039;&#039;14:00 - 16:30 Bethe-Salpeter equation (BSE)&#039;&#039;&#039; Fulvio Paleari (CNR-Nano, Italy), Davide Sangalli (CNR-ISM, Italy)&lt;br /&gt;
&lt;br /&gt;
To get the tutorial files needed for the following tutorials, follow these steps:&lt;br /&gt;
 $ wget https://media.yambo-code.eu/educational/tutorials/files/hBN.tar.gz # NOTE: YOU SHOULD ALREADY HAVE THIS FROM DAY 1&lt;br /&gt;
 $ wget https://media.yambo-code.eu/educational/tutorials/files/hBN-convergence-kpoints.tar.gz &lt;br /&gt;
 $ tar -xvf hBN-convergence-kpoints.tar.gz&lt;br /&gt;
 $ tar -xvf hBN.tar.gz&lt;br /&gt;
&lt;br /&gt;
Now, you may open the interactive job session with &amp;lt;code&amp;gt;salloc&amp;lt;/code&amp;gt; and proceed with the following tutorials.&lt;br /&gt;
&lt;br /&gt;
* [[Calculating optical spectra including excitonic effects: a step-by-step guide|Perform a BSE calculation from beginning to end ]]&lt;br /&gt;
* [[How to analyse excitons - ICTP 2022 school|Analyse your results (exciton wavefunctions in real and reciprocal space, etc.) ]]&lt;br /&gt;
* [[BSE solvers overview|Solve the BSE eigenvalue problem with different numerical methods]]&lt;br /&gt;
* [[How to choose the input parameters|Choose the input parameters for a meaningful converged calculation]]&lt;br /&gt;
Now, go into the yambopy tutorial directory to learn about python analysis tools for the BSE:&lt;br /&gt;
 $ cd $CINECA_SCRATCH&lt;br /&gt;
 $ cd YAMBOPY_TUTORIALS/databases_yambopy&lt;br /&gt;
&lt;br /&gt;
* [[Yambopy_tutorial:_Yambo_databases#Exciton_intro_1:_read_and_sort_data|Visualization of excitonic properties with yambopy]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;17:00 - 18:30 Bethe-Salpeter equation in real time (TD-HSEX)&#039;&#039;&#039; Fulvio Paleari (CNR-Nano, Italy), Davide Sangalli (CNR-ISM, Italy)&lt;br /&gt;
&lt;br /&gt;
The files needed for the following tutorials can be downloaded following these steps:&lt;br /&gt;
 $ wget https://media.yambo-code.eu/educational/tutorials/files/hBN-2D-RT.tar.gz&lt;br /&gt;
 $ tar -xvf hBN-2D-RT.tar.gz&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* [[Introduction_to_Real_Time_propagation_in_Yambo#Time_Dependent_Equation_for_the_Reduced_One--Body_Density--Matrix|Read the introductive section to real-time propagation for the one-body density matrix]] (the part about time-dependent Schrödinger equation will be covered on DAY 4 and you can skip it for now)&lt;br /&gt;
* [[Prerequisites for Real Time propagation with Yambo|Perform the setup for a real-time calculation]]&lt;br /&gt;
* [[Linear response from real time simulations (density matrix only)|Calculate the linear response in real time]]&lt;br /&gt;
* [[Real time Bethe-Salpeter Equation (density matrix only)|Calculate the BSE in real time]]&lt;br /&gt;
&lt;br /&gt;
=== DAY 4 - Thursday, May 25 ===&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;14:00 - 16:30 Real-time approach with the time dependent berry phase&#039;&#039;&#039; Myrta Gruning (Queen&#039;s University Belfast), Davide Sangalli (CNR-ISM, Italy)&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;16:15 - 18:30 From the DFT ground state to the complete setup of a Many Body calculation using Yambo&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
For the tutorials we will use first the &amp;lt;code&amp;gt;hBN-2D-RT&amp;lt;/code&amp;gt; folder (k-sampling 10x10x1) and then the &amp;lt;code&amp;gt;hBN-2D&amp;lt;/code&amp;gt; folder (k-sampling 6x6x1)&lt;br /&gt;
You may already have them in the &amp;lt;code&amp;gt;YAMBO_TUTORIALS&amp;lt;/code&amp;gt; folder&lt;br /&gt;
 $ ls&lt;br /&gt;
 &#039;&#039;&#039;hBN-2D&#039;&#039;&#039; &#039;&#039;&#039;hBN-2D-RT&#039;&#039;&#039; hBN-2D.tar.gz  hBN-2D-RT.tar.gz&lt;br /&gt;
&lt;br /&gt;
If you need to downoload again the tutorial files, follow these steps:&lt;br /&gt;
 $ wget https://media.yambo-code.eu/educational/tutorials/files/hBN-2D.tar.gz&lt;br /&gt;
 $ wget https://media.yambo-code.eu/educational/tutorials/files/hBN-2D-RT.tar.gz&lt;br /&gt;
 $ tar -xvf hBN-2D.tar.gz&lt;br /&gt;
 $ tar -xvf hBN-2D-RT.tar.gz&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* [[Linear response from Bloch-states dynamics]]&lt;br /&gt;
* [[Second-harmonic generation of 2D-hBN]]&lt;br /&gt;
&lt;br /&gt;
* [[Real time approach to non-linear response]] (additional tutorial)&lt;br /&gt;
* [[Correlation effects in the non-linear response]] (additional tutorial)&lt;br /&gt;
&lt;br /&gt;
=== DAY 5 - Friday, 26 May ===&lt;br /&gt;
&lt;br /&gt;
== Lectures ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== DAY 1 - Monday, 22 May ===&lt;br /&gt;
&lt;br /&gt;
* D. Varsano, [https://media.yambo-code.eu/educational/Schools/ROME2023/scuola_intro.pdf Description and goal of the school].&lt;br /&gt;
* G. Stefanucci, [https://media.yambo-code.eu/educational/Schools/ROME2023/Stefanucci.pdf The Many-Body Problem: Key concepts of the Many-Body Perturbation Theory]&lt;br /&gt;
* M. Marsili, [https://media.yambo-code.eu/educational/Schools/ROME2023/marghe_linear_response.pdf Beyond the independent particle scheme: The linear response theory]&lt;br /&gt;
&lt;br /&gt;
=== DAY 2 - Tuesday, 23 May ===&lt;br /&gt;
&lt;br /&gt;
* E. Perfetto, [https://media.yambo-code.eu/educational/Schools/ROME2023/Talk_Perfetto.pdf An overview on non-equilibrium Green Functions]&lt;br /&gt;
* R. Frisenda, [https://media.yambo-code.eu/educational/Schools/ROME2023/FRISENDA%20-%20ARPES%20spectroscopy,%20an%20experimental%20overview.pdf ARPES spectroscopy, an experimental overview]&lt;br /&gt;
* A. Marini, [https://media.yambo-code.eu/educational/Schools/ROME2023/GW_marini.pdf The Quasi Particle concept and the GW method]&lt;br /&gt;
* A. Guandalini, [https://media.yambo-code.eu/educational/Schools/ROME2023/alberto_guandalini.pdf The GW method: approximations and algorithms]&lt;br /&gt;
* D.A. Leon, C. Cardoso, [https://media.yambo-code.eu/educational/Schools/ROME2023/Cardoso_YamboSchool2023_Rome.pdf Frequency dependence in GW: origin, modelling and practical implementations]&lt;br /&gt;
&lt;br /&gt;
=== DAY 3 - Wednesday, 24 May ===&lt;br /&gt;
&lt;br /&gt;
* A. Molina-Sánchez, Modelling excitons: from 2D materials to Pump and Probe experiments&lt;br /&gt;
* M. Palummo, The Bethe-Salpeter equation: derivations and main physical concepts&lt;br /&gt;
* F. Paleari, Real time approach to the Bethe-Salpeter equation&lt;br /&gt;
* D. Sangalli, TD-HSEX and real-time dynamics&lt;br /&gt;
&lt;br /&gt;
=== DAY 4 - Thursday, 25 May ===&lt;br /&gt;
&lt;br /&gt;
* S. Mor, Time resolved spectroscopy: an  experimental overview&lt;br /&gt;
* M. Grüning, Nonlinear optics within Many-Body Perturbation Theory&lt;br /&gt;
* N. Tancogne-Dejean, Theory and simulation of High Harmonics Generation&lt;br /&gt;
* Y. Pavlyukh, Coherent electron-phonon dynamics within a time-linear GKBA scheme&lt;/div&gt;</summary>
		<author><name>Fulvio</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Second-harmonic_generation_of_2D-hBN&amp;diff=6996</id>
		<title>Second-harmonic generation of 2D-hBN</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Second-harmonic_generation_of_2D-hBN&amp;diff=6996"/>
		<updated>2023-05-25T08:50:15Z</updated>

		<summary type="html">&lt;p&gt;Fulvio: /* Step 2: Independent-particle approximation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Step 0: Theoretical framework =&lt;br /&gt;
&lt;br /&gt;
In this tutorial, we compute the Second-harmonic generation (SHG) from the dynamics of the Bloch-states. The equation-of-motion of the Bloch-states is explained in the tutorial on [[Linear response from Bloch-states dynamics]]. Independently of the &#039;experiment&#039; we simulate, the part of the integration of motion stays the same. This means that any experiment, including non-linear optics, can be performed at the level of the theory listed for the computation of the dielectric function:&lt;br /&gt;
* independent (quasi)particle&lt;br /&gt;
* time-dependent Hartree (RPA level)&lt;br /&gt;
* time-dependent DFT (and DPFT)&lt;br /&gt;
* time-dependent Hartree+Screened exchange (BSE level)&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
What changes when we want to calculate the SHG (or higher harmonics) is:&lt;br /&gt;
* the time-dependence of the input electric field and&lt;br /&gt;
* the post-processing of the signal  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Time dependence of the electric Field&#039;&#039;&#039;: we choose a sinusoidal electric field, thus a monochromatic laser field. This allows one to expand the polarization in the form &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; through a coefficient depending on a power of the strength of the field (with the power depending on the order of the response).&lt;br /&gt;
&lt;br /&gt;
At difference with a delta-like perturbation, a real-time simulation gives the response at the laser-field only. Then, to obtain the spectrum for the desired range of frequency, we have to perform so many simulations as the frequencies in the desired range.  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Post-processing of the signal&#039;&#039;&#039;: The switch-on of the electric field corresponds to a weak delta-like kick. Thus, even if it may not be noticeable, the polarization results from both the sinusoidal field and the delta-like kick. The latter excites all eigenfrequencies of the system. Though weak, the resulting signal is comparable with the second-harmonic signal. To eliminate the signal from the eigenfrequencies, we apply a dephasing (&amp;lt;math&amp;gt;\gamma_{deph}&amp;lt;/math&amp;gt;). To have a signal useful to sample the second-harmonic signal, we need to wait a time &amp;lt;math&amp;gt;\bar t&amp;lt;/math&amp;gt;  much larger than the dephasing-time &amp;lt;math&amp;gt;1/\gamma_{deph} &amp;lt;/math&amp;gt;. Note that we cannot choose a too short dephasing time (to shorten the simulation time), as this would result in a too large broadening of the spectrum. After &amp;lt;math&amp;gt;\bar t&amp;lt;/math&amp;gt;, we sample $2N+1$ times in a period and use discrete Fourier transform to extract &amp;lt;math&amp;gt;{p}_n&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt; n = 0,...,N&amp;lt;/math&amp;gt;, where n=2 gives the SHG. This is schematically illustrated in figure:&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;
The scheme from Ref. &amp;lt;ref name=&amp;quot;Attaccalite2013&amp;quot;&amp;gt;C. Attaccalite and M. Gruning [https://arxiv.org/abs/1309.4012v2 Rev. B, &#039;&#039;&#039;88&#039;&#039;&#039;, 235113 (2013)]&amp;lt;/ref&amp;gt; summarised the workflow for computing the SHG (or higher-harmonics) in a energy range &amp;lt;math&amp;gt;[\Omega_1,\Omega_2]&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
[[File:Scheme nl.png|350px|center|Schematic representation of real-time calculations]]&lt;br /&gt;
&lt;br /&gt;
= Step 1: Prerequisites =&lt;br /&gt;
&lt;br /&gt;
In this example, we will consider a single layer of hexagonal boron nitride (hBN). Before running real time simulations to compute the SHG in &amp;lt;code&amp;gt;yambo&amp;lt;/code&amp;gt; you need to download input files and Yambo databases for this tutorial here: [https://media.yambo-code.eu/educational/tutorials/files/hBN-2D-RT.tar.gz hBN-2D-RT.tar.gz].&lt;br /&gt;
Unzip the tarball and change directory to &amp;lt;code&amp;gt;YAMBO&amp;lt;/code&amp;gt; and run the setup (&amp;lt;code&amp;gt;yambo_nl -nompi&amp;lt;/code&amp;gt;). &lt;br /&gt;
Execute the command &lt;br /&gt;
 ypp_nl -fixsym -F 00_removesym.in  &lt;br /&gt;
to create the input, to remove the symmetries which are not compatible with the field: &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;1.000000 | 1.000000 | 0.000000 |&amp;lt;/span&amp;gt;        # First external Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 % Efield2&lt;br /&gt;
  0.000000 | 0.000000 | 0.000000 |        # 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;
 #KeepKGrid                     # Do not expand the k-grid&lt;br /&gt;
where we chose the field along the xy direction and we remove time-reversal symmetry.&lt;br /&gt;
&lt;br /&gt;
Then run the pre-processing job:&lt;br /&gt;
 ypp_nl -F 00_removesym.in J 00_removesym&lt;br /&gt;
This creates the directory &amp;lt;code&amp;gt;FixSymm&amp;lt;/code&amp;gt;. Change directory to &amp;lt;code&amp;gt;FixSymm&amp;lt;/code&amp;gt;. This contains the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory with reduced symmetries, compatible with the direction of the field. Now run the setup again (&amp;lt;code&amp;gt;yambo_nl -nompi&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
= Step 2: Independent-particle approximation =&lt;br /&gt;
&lt;br /&gt;
Use the command:&lt;br /&gt;
  yambo_nl -nl n -F 01_SHG_ip.in&lt;br /&gt;
to generate the input:&lt;br /&gt;
&lt;br /&gt;
 nloptics                         # [R] Non-linear spectroscopy&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=-1.000000           fs    # [NL] Simulation Time&lt;br /&gt;
 NLintegrator= &amp;quot;INVINT&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;
 % NLEnRange&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;0.5000000 |8.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;12&amp;lt;/span&amp;gt;                     # [NL] Energy steps&lt;br /&gt;
 NLDamping= 0.200000        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;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&amp;quot;SIN&amp;quot; &amp;lt;/span&amp;gt;          # [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 | 1.000000 | 0.000000 |&amp;lt;/span&amp;gt;        # [RT Field1] Versor&lt;br /&gt;
 %&lt;br /&gt;
 Field1_Tstart= 0.010000    fs    # [RT Field1] Initial Time&lt;br /&gt;
&lt;br /&gt;
To describe the Bloch-dynamics we will use as a basis the KS-states 3-6 for the k-grid used in the non-scf DFT calculations, that is a 6x6x1 (&amp;lt;code&amp;gt;NLBands&amp;lt;/code&amp;gt;). We choose 12 equally spaced frequencies (&amp;lt;code&amp;gt;NLEnSteps&amp;lt;/code&amp;gt;) for the applied field in the range  (&amp;lt;code&amp;gt;NLEnRange&amp;lt;/code&amp;gt;) between 0.5 and 8 eV. We choose a sinusoidal time-dependence (&amp;lt;code&amp;gt;Field1_kind&amp;lt;/code&amp;gt;) and set the field direction (&amp;lt;code&amp;gt;Field1_kind&amp;lt;/code&amp;gt;) along xy (in plane). The negative simulation time (&amp;lt;code&amp;gt;NLtime=-1.000000&amp;lt;/code&amp;gt;) means that the code will choose it based on the value of the &amp;lt;code&amp;gt;NLDamping&amp;lt;/code&amp;gt;. While this is a good lower bound for the simulation time, one should check it is sufficient to get accurate results. &lt;br /&gt;
&lt;br /&gt;
Run the simulation, possibly in parallel e. g. in a interactive session on 4 cores. &lt;br /&gt;
&lt;br /&gt;
[In order to get 4 cores while in an interacting node, exit your current allocation and rerun &amp;lt;code&amp;gt;salloc&amp;lt;/code&amp;gt; asking for the proper number of tasks:&lt;br /&gt;
 salloc -A tra23_Yambo -p m100_usr_prod -q m100_qos_dbg --nodes=1 --ntasks-per-node=&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;4&amp;lt;/span&amp;gt; --cpus-per-task=4 -t 02:00:00&lt;br /&gt;
Otherwise, you can submit the job with a slurm script as explained in the introductory page]&lt;br /&gt;
&lt;br /&gt;
Now execute the command:&lt;br /&gt;
  mpirun -n 4 yambo_nl -F 01_SHG_ip.in -J 01_SHG_ip -C 01_SHG_ip_files&lt;br /&gt;
&lt;br /&gt;
Once the run is finished, check the report &amp;lt;code&amp;gt;01_SHG_ip_files/r-01_SHG_ip_nloptics&amp;lt;/code&amp;gt;. In particular, in the appended input files, you can see the default parallelization applied by the code for calculating the dipoles and run the time-propagation. For the latter, the main parallelization is on the frequencies and then on the k-points (&amp;lt;code&amp;gt;NL_ROLEs= &amp;quot;w.k&amp;quot;&amp;lt;/code&amp;gt;).   &lt;br /&gt;
&lt;br /&gt;
 | NL_CPU= &amp;quot;2.2&amp;quot;                    # [PARALLEL] CPUs for each role&lt;br /&gt;
 | NL_ROLEs= &amp;quot;w.k&amp;quot;                  # [PARALLEL] CPUs roles (w,k)&lt;br /&gt;
 | DIP_CPU= &amp;quot;2.2.1&amp;quot;                 # [PARALLEL] CPUs for each role&lt;br /&gt;
 | DIP_ROLEs= &amp;quot;v.c.k&amp;quot;               # [PARALLEL] CPUs roles (k,c,v)&lt;br /&gt;
&lt;br /&gt;
Also, look at the simulation time. This is approximately 42 fs. &lt;br /&gt;
&lt;br /&gt;
Plot the polarization for a couple of frequencies, e.g. the first and last of the chosen range (the corresponding frequency can be read in the file, search for &amp;quot;Frequency value&amp;quot;):&lt;br /&gt;
 set ylabel &amp;quot;x-component polarization&amp;quot; offset -0.7&lt;br /&gt;
 set xlabel &amp;quot;time (fs)&amp;quot;&lt;br /&gt;
 plot &#039;01_SHG_ip_files/o-01_SHG_ip.polarization_F1&#039; u 1:2 w l lw 2 title &amp;quot;omega = 0.5 eV&amp;quot;&lt;br /&gt;
 replot &#039;01_SHG_ip_files/o-01_SHG_ip.polarization_F12&#039; u 1:2 w l lw 2  title &amp;quot;omega = 7.375 eV&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[File:Berry_phase_polarization_of_2D_h-BN_obtained_from_the_previous_run_for_two_laser_frequencies.png|Berry_phase_polarization_of_2D_h-BN_obtained from the run for two laser frequencies]]&lt;br /&gt;
&lt;br /&gt;
After the applied field is &#039;switched on&#039;, the polarization is oscillating at the frequency of the applied field and at the eigenfrequencies of the system as described above in the cartoon. This is visible particularly for the higher frequency. Due to the dephasing, after about 20 fs the polarization is oscillating (at least to the eye) at the frequency of the applied field. Nonlinear components are not visible since they are several orders of magnitude smaller than the first order.&lt;br /&gt;
&lt;br /&gt;
== Output post-processing: the dielectric function ==&lt;br /&gt;
&lt;br /&gt;
Once we obtained the polarization, we Fourier-transform the polarization to obtain the dielectric function.&lt;br /&gt;
&lt;br /&gt;
Use the command:&lt;br /&gt;
&lt;br /&gt;
  ypp_nl -nl -F 02_SHG_ip_pp.in -C 01_SHG_ip_files&lt;br /&gt;
&lt;br /&gt;
to generate the input file: &lt;br /&gt;
&lt;br /&gt;
 nonlinear                        # [R] Non-linear response analysis&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;Xorder= 4&amp;lt;/span&amp;gt; # 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;NONE&amp;quot;                 # Damping type ( NONE | LORENTZIAN | GAUSSIAN )&lt;br /&gt;
 DampFactor= 0.000000       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;
Where we changed the &amp;lt;code&amp;gt;Xorder&amp;lt;/code&amp;gt; to 4. This variable controls the terms in the Fourier expansion of the polarization. We choose up to expand up to the fourth order. This should ensure the second order to be accurate enough. As an exercise, you can change this value (e.g. choose 2,3,5,6) and see how the result below is changing. The time-window where processing is done is chosen automatically, since values are negative. The code chooses by default the last period to carry out the analysis. &lt;br /&gt;
&lt;br /&gt;
To run the post-processing, use the command:&lt;br /&gt;
 ypp_nl -F Inputs_shg/ypp_shg.in -J TD-IP_nl -C TD-IP_nl. &lt;br /&gt;
   &lt;br /&gt;
In  &amp;lt;code&amp;gt;01_SHG_ip_files&amp;lt;/code&amp;gt; the following files were generated &lt;br /&gt;
 o-01_SHG_ip.YPP-X_probe_order_1&lt;br /&gt;
 o-01_SHG_ip.YPP-X_probe_order_2&lt;br /&gt;
 o-01_SHG_ip.YPP-X_probe_order_3&lt;br /&gt;
 o-01_SHG_ip.YPP-X_probe_order_4&lt;br /&gt;
 r-01_SHG_ip_nonlinear&lt;br /&gt;
&lt;br /&gt;
The output files contain respectively the first, second, third and fourth order response(corresponding to &amp;lt;code&amp;gt;Xorder=4&amp;lt;/code&amp;gt;)  at the 12 frequencies in the chosen range. &lt;br /&gt;
 &lt;br /&gt;
Inspect &amp;lt;code&amp;gt;o-01_SHG_ip.YPP-X_probe_order_2&amp;lt;/code&amp;gt;&lt;br /&gt;
 #     E [eV]            X/Im[cm/stV](x)    X/Re[cm/stV](x)    X/Im[cm/stV](y)    X/Re[cm/stV](y)    X/Im[cm/stV](z)    X/Re[cm/stV](z)&lt;br /&gt;
 #&lt;br /&gt;
      0.50000000        -0.35378838E-09    -0.19774796E-07     0.23591828E-09    -0.89405637E-09      0.0000000          0.0000000    &lt;br /&gt;
      1.1250000         -0.19356524E-08    -0.23160605E-07    -0.16052184E-09    -0.67662771E-09      0.0000000          0.0000000    &lt;br /&gt;
      1.7500000         -0.69446459E-08    -0.35586956E-07    -0.76025706E-09    -0.10205678E-08      0.0000000          0.0000000    &lt;br /&gt;
      2.37500000        -0.181606152E-7    -0.261823658E-8     0.438358596E-8     0.407915226E-8      0.00000000         0.00000000   &lt;br /&gt;
&lt;br /&gt;
The first column are the frequencies of the applied field, the second and third is the polarization along x (imaginary and real part), the fourth and fifth is the polarization along y (imaginary and real part)  &lt;br /&gt;
and the sixth and seventh is the polarization along z (imaginary and real part).&lt;br /&gt;
&lt;br /&gt;
Plot the absolute value of the SHG for the &amp;quot;xxy&amp;quot; component (that is, the applied field is in the x and y directions and one look at the polarization along x):&lt;br /&gt;
&lt;br /&gt;
 set ylabel &amp;quot;{/Symbol=26 \174}{/Symbol=26 c}_{xyx}^{(2)}{/Symbol=26 \174} (pm/V)&amp;quot; offset -0.7&lt;br /&gt;
 set xlabel &amp;quot;Energy (eV)&amp;quot;&lt;br /&gt;
 pmVm1toCGS=2.38721e-09&lt;br /&gt;
 plot &#039;01_SHG_ip_files/o-01_SHG_ip.YPP-X_probe_order_2&#039; u 1:(sqrt($2**2+$3**2)/pmVm1toCGS) w p title &amp;quot;calc&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[File: SHG_intensity_of_2D_h-BN_obtained_from_the_previous_run_(and_compared_with_a_run_on_112_frequencies).png | SHG_intensity_of_2D_h-BN obtained from the current run (12 frequencies) compared with a run with 112 frequencies]] &lt;br /&gt;
&lt;br /&gt;
In the figure above, the results of the current run are compared with those for a run with 112 frequencies (one can obtain these results by repeating the calculations, changing the number of frequencies in &amp;lt;code&amp;gt;NLEnSteps&amp;lt;/code&amp;gt; though this take about 10 times more computational time than the run with 12). One can notice some differences between the two runs. In fact, the two runs evaluate different frequnecies and the difference indicates spurious oscillations of the value of the polarizability due to the simulation time being too short and thus to the presence of &#039;noise&#039; due to the eigenfrecies.  &lt;br /&gt;
As an exercise, you can repeat the simulation for e,g, a time of &amp;lt;code&amp;gt;60 fs&amp;lt;/code&amp;gt;, that is setting &amp;lt;code&amp;gt;NLtime=60&amp;lt;/code&amp;gt;. The plot below compare the SHG extracted at 42 fs and 60 fs, where the latter gives clearly more accurate results. &lt;br /&gt;
&lt;br /&gt;
[[File:Comparison of the SHG intensity of 2D h-BN obtained with different simulation time.png|Comparison of the SHG intensity of 2D h-BN obtained with different simulation time]]&lt;br /&gt;
&lt;br /&gt;
As a final note, the SHG depends on the size of the vacuum added in the supercell. Instead, one should consider the surface SHG which obtained by considering an effective thickness for the layer. This is usually chosen to be similar to the layer separation in the bulk counterpart.&lt;br /&gt;
&lt;br /&gt;
= Step 3: Hartree+Screened exchange approximation (BSE level) =&lt;br /&gt;
&lt;br /&gt;
== Hartree+Screened exchange collisions ==&lt;br /&gt;
Similarly to the linear part, one needs to generate the Screened exchange collisions. The procedure is exactly the same.&lt;br /&gt;
&lt;br /&gt;
Create the input:&lt;br /&gt;
 yambo_nl -X s -e -v hsex -F 03_coll_hsex.in&lt;br /&gt;
modify the input ad follows&lt;br /&gt;
 em1s                             # [R][Xs] Statically Screened Interaction&lt;br /&gt;
 collisions                       # [R] Collisions&lt;br /&gt;
 dipoles                          # [R] Oscillator strenghts (or dipoles)&lt;br /&gt;
 Chimod= &amp;quot;HARTREE&amp;quot;                # [X] IP/Hartree/ALDA/LRC/PF/BSfxc&lt;br /&gt;
 % BndsRnXs&lt;br /&gt;
    1 |  20 |                         # [Xs] Polarization function bands&lt;br /&gt;
 %&lt;br /&gt;
 NGsBlkXs= 1000 mHa    # [Xs] Response block size&lt;br /&gt;
 % LongDrXs&lt;br /&gt;
  1.000000 | 1.000000 | 0.000000 |        # [Xs] [cc] Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 % COLLBands&lt;br /&gt;
    4 |  5 |                         # [COLL] Bands for the collisions&lt;br /&gt;
 %&lt;br /&gt;
 HXC_Potential= &amp;quot;SEX+HARTREE&amp;quot;     # [SC] SC HXC Potential&lt;br /&gt;
 HARRLvcs= 1000 mHa    # [HA] Hartree     RL components&lt;br /&gt;
 EXXRLvcs= 1000 mHa    # [XX] Exchange    RL components&lt;br /&gt;
 CORRLvcs= 1000 mHa    # [GW] Correlation RL components&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Calculate the collisions (you may want to run in parallel):&lt;br /&gt;
 yambo_nl -F 03_coll_hsex.in -J 03_coll -C 04_hsex_files&lt;br /&gt;
&lt;br /&gt;
== Run the simulation ==&lt;br /&gt;
&lt;br /&gt;
Create the input:&lt;br /&gt;
 yambo_nl -nl n -v hsex -V qp -F 04_SHG_hsex.in&lt;br /&gt;
&lt;br /&gt;
modify the following parts of the input (by this time all the innput variables should be known from the previous exercises):&lt;br /&gt;
&lt;br /&gt;
 % BndsRnXs&lt;br /&gt;
   1 |  20 |                         # [Xs] Polarization function bands&lt;br /&gt;
 %&lt;br /&gt;
 NGsBlkXs= 1000 mHa    # [Xs] Response block size&lt;br /&gt;
 % LongDrXs&lt;br /&gt;
  1.000000 | 1.000000 | 0.000000 |        # [Xs] [cc] Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 % NLBands&lt;br /&gt;
    4 |  5 |                         # [NL] Bands range&lt;br /&gt;
 %&lt;br /&gt;
&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;SEX&amp;quot;             # [NL] Correlation (&amp;quot;IPA/HARTREE/TDDFT/LRC/LRW/JGM/SEX&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 % NLEnRange&lt;br /&gt;
  0.500000 |8.000000 |         eV    # [NL] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 NLEnSteps= 12                   # [NL] Energy steps&lt;br /&gt;
&lt;br /&gt;
 % GfnQP_E&lt;br /&gt;
  3.000000 | 1.000000 | 1.000000 |        # [EXTQP G] E parameters  (c/v) eV|adim|adim&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
 Field1_kind= &amp;quot;SIN&amp;quot;           # [RT Field1] Kind(SIN|COS|RES|ANTIRES|GAUSS|DELTA|QSSIN)&lt;br /&gt;
&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
  1.000000 | 1.000000 | 0.000000 |        # [RT Field1] Versor&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
Then run the simulation using e.g. mpi and 4 cores:&lt;br /&gt;
 mpirun -n 4 yambo_nl -F 04_SHG_hsex.in -J 04_SHG_hsex,03_coll -C 04_SHG_hsex_files&lt;br /&gt;
&lt;br /&gt;
== Postprocessing: obtain the nonlinear response ==&lt;br /&gt;
&lt;br /&gt;
Similarly to what we did for the independent particle case, we create the input:&lt;br /&gt;
 ypp_nl -nl -F 05_SHG_hsex_pp.in&lt;br /&gt;
 &lt;br /&gt;
we change &amp;lt;code&amp;gt;Xorder = 4 &amp;lt;/code&amp;gt; and then run:&lt;br /&gt;
 ypp_nl -F 05_SHG_hsex_pp.in -J 04_SHG_hsex -C 04_hsex_files&lt;br /&gt;
&lt;br /&gt;
Then we plot (as before we compare with a simulation ran for 112 frequnecies).&lt;br /&gt;
&lt;br /&gt;
Plot the results:&lt;br /&gt;
&lt;br /&gt;
 set ylabel &amp;quot;{/Symbol=26 \174}{/Symbol=26 c}_{xyx}^{(2)}{/Symbol=26 \174} (pm/V)&amp;quot; offset -0.7&lt;br /&gt;
 set xlabel &amp;quot;Energy (eV)&amp;quot;&lt;br /&gt;
 pmVm1toCGS=2.38721e-09&lt;br /&gt;
 plot &#039;04_hsex_files/o-04_SHG_hsex.YPP-X_probe_order_2&#039; u 1:(sqrt($2**2+$3**2)/pmVm1toCGS) w p title &amp;quot;calc&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[File:SHG hsex.png|SHG at the Hartree + Screened exchange from current run with 12 frequencies (crosses) and a run with 112 frequencies (keeping the other parameters the same)]]&lt;br /&gt;
&lt;br /&gt;
also in this case we note differences between the two simulations. This is due to the too short simulation time. Repeating the calculations with a longer time gives more accurate results. &lt;br /&gt;
In addition, note that in the interest of time, all parameters are underconverged. In principle, to calculate the collisions one should use the same parameters of a converged BSE calculation. As well, one should use the Coulomb cutoff as it was used for this system in the  BSE case.&lt;br /&gt;
&lt;br /&gt;
= References = &lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Fulvio</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Second-harmonic_generation_of_2D-hBN&amp;diff=6995</id>
		<title>Second-harmonic generation of 2D-hBN</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Second-harmonic_generation_of_2D-hBN&amp;diff=6995"/>
		<updated>2023-05-25T08:35:06Z</updated>

		<summary type="html">&lt;p&gt;Fulvio: /* Step 1: Prerequisites */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Step 0: Theoretical framework =&lt;br /&gt;
&lt;br /&gt;
In this tutorial, we compute the Second-harmonic generation (SHG) from the dynamics of the Bloch-states. The equation-of-motion of the Bloch-states is explained in the tutorial on [[Linear response from Bloch-states dynamics]]. Independently of the &#039;experiment&#039; we simulate, the part of the integration of motion stays the same. This means that any experiment, including non-linear optics, can be performed at the level of the theory listed for the computation of the dielectric function:&lt;br /&gt;
* independent (quasi)particle&lt;br /&gt;
* time-dependent Hartree (RPA level)&lt;br /&gt;
* time-dependent DFT (and DPFT)&lt;br /&gt;
* time-dependent Hartree+Screened exchange (BSE level)&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
What changes when we want to calculate the SHG (or higher harmonics) is:&lt;br /&gt;
* the time-dependence of the input electric field and&lt;br /&gt;
* the post-processing of the signal  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Time dependence of the electric Field&#039;&#039;&#039;: we choose a sinusoidal electric field, thus a monochromatic laser field. This allows one to expand the polarization in the form &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; through a coefficient depending on a power of the strength of the field (with the power depending on the order of the response).&lt;br /&gt;
&lt;br /&gt;
At difference with a delta-like perturbation, a real-time simulation gives the response at the laser-field only. Then, to obtain the spectrum for the desired range of frequency, we have to perform so many simulations as the frequencies in the desired range.  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Post-processing of the signal&#039;&#039;&#039;: The switch-on of the electric field corresponds to a weak delta-like kick. Thus, even if it may not be noticeable, the polarization results from both the sinusoidal field and the delta-like kick. The latter excites all eigenfrequencies of the system. Though weak, the resulting signal is comparable with the second-harmonic signal. To eliminate the signal from the eigenfrequencies, we apply a dephasing (&amp;lt;math&amp;gt;\gamma_{deph}&amp;lt;/math&amp;gt;). To have a signal useful to sample the second-harmonic signal, we need to wait a time &amp;lt;math&amp;gt;\bar t&amp;lt;/math&amp;gt;  much larger than the dephasing-time &amp;lt;math&amp;gt;1/\gamma_{deph} &amp;lt;/math&amp;gt;. Note that we cannot choose a too short dephasing time (to shorten the simulation time), as this would result in a too large broadening of the spectrum. After &amp;lt;math&amp;gt;\bar t&amp;lt;/math&amp;gt;, we sample $2N+1$ times in a period and use discrete Fourier transform to extract &amp;lt;math&amp;gt;{p}_n&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt; n = 0,...,N&amp;lt;/math&amp;gt;, where n=2 gives the SHG. This is schematically illustrated in figure:&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;
The scheme from Ref. &amp;lt;ref name=&amp;quot;Attaccalite2013&amp;quot;&amp;gt;C. Attaccalite and M. Gruning [https://arxiv.org/abs/1309.4012v2 Rev. B, &#039;&#039;&#039;88&#039;&#039;&#039;, 235113 (2013)]&amp;lt;/ref&amp;gt; summarised the workflow for computing the SHG (or higher-harmonics) in a energy range &amp;lt;math&amp;gt;[\Omega_1,\Omega_2]&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
[[File:Scheme nl.png|350px|center|Schematic representation of real-time calculations]]&lt;br /&gt;
&lt;br /&gt;
= Step 1: Prerequisites =&lt;br /&gt;
&lt;br /&gt;
In this example, we will consider a single layer of hexagonal boron nitride (hBN). Before running real time simulations to compute the SHG in &amp;lt;code&amp;gt;yambo&amp;lt;/code&amp;gt; you need to download input files and Yambo databases for this tutorial here: [https://media.yambo-code.eu/educational/tutorials/files/hBN-2D-RT.tar.gz hBN-2D-RT.tar.gz].&lt;br /&gt;
Unzip the tarball and change directory to &amp;lt;code&amp;gt;YAMBO&amp;lt;/code&amp;gt; and run the setup (&amp;lt;code&amp;gt;yambo_nl -nompi&amp;lt;/code&amp;gt;). &lt;br /&gt;
Execute the command &lt;br /&gt;
 ypp_nl -fixsym -F 00_removesym.in  &lt;br /&gt;
to create the input, to remove the symmetries which are not compatible with the field: &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;1.000000 | 1.000000 | 0.000000 |&amp;lt;/span&amp;gt;        # First external Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 % Efield2&lt;br /&gt;
  0.000000 | 0.000000 | 0.000000 |        # 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;
 #KeepKGrid                     # Do not expand the k-grid&lt;br /&gt;
where we chose the field along the xy direction and we remove time-reversal symmetry.&lt;br /&gt;
&lt;br /&gt;
Then run the pre-processing job:&lt;br /&gt;
 ypp_nl -F 00_removesym.in J 00_removesym&lt;br /&gt;
This creates the directory &amp;lt;code&amp;gt;FixSymm&amp;lt;/code&amp;gt;. Change directory to &amp;lt;code&amp;gt;FixSymm&amp;lt;/code&amp;gt;. This contains the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory with reduced symmetries, compatible with the direction of the field. Now run the setup again (&amp;lt;code&amp;gt;yambo_nl -nompi&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
= Step 2: Independent-particle approximation =&lt;br /&gt;
&lt;br /&gt;
Use the command:&lt;br /&gt;
  yambo_nl -nl n -F 01_SHG_ip.in&lt;br /&gt;
to generate the input:&lt;br /&gt;
&lt;br /&gt;
 nloptics                         # [R] Non-linear spectroscopy&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=-1.000000           fs    # [NL] Simulation Time&lt;br /&gt;
 NLintegrator= &amp;quot;INVINT&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;
 % NLEnRange&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;0.5000000 |8.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;12&amp;lt;/span&amp;gt;                     # [NL] Energy steps&lt;br /&gt;
 NLDamping= 0.200000        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;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&amp;quot;SIN&amp;quot; &amp;lt;/span&amp;gt;          # [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 | 1.000000 | 0.000000 |&amp;lt;/span&amp;gt;        # [RT Field1] Versor&lt;br /&gt;
 %&lt;br /&gt;
 Field1_Tstart= 0.010000    fs    # [RT Field1] Initial Time&lt;br /&gt;
&lt;br /&gt;
To describe the Bloch-dynamics we will use as a basis the KS-states 3-6 for the k-grid used in the non-scf DFT calculations, that is a 6x6x1 (&amp;lt;code&amp;gt;NLBands&amp;lt;/code&amp;gt;). We choose 12 equally spaced frequencies (&amp;lt;code&amp;gt;NLEnSteps&amp;lt;/code&amp;gt;) for the applied field in the range  (&amp;lt;code&amp;gt;NLEnRange&amp;lt;/code&amp;gt;) between 0.5 and 8 eV. We choose a sinusoidal time-dependence (&amp;lt;code&amp;gt;Field1_kind&amp;lt;/code&amp;gt;) and set the field direction (&amp;lt;code&amp;gt;Field1_kind&amp;lt;/code&amp;gt;) along xy (in plane). The negative simulation time (&amp;lt;code&amp;gt;NLtime=-1.000000&amp;lt;/code&amp;gt;) means that the code will choose it based on the value of the &amp;lt;code&amp;gt;NLDamping&amp;lt;/code&amp;gt;. While this is a good lower bound for the simulation time, one should check it is sufficient to get accurate results. &lt;br /&gt;
&lt;br /&gt;
Run the simulation, possibly in parallel e. g. in a interactive session on 4 cores, execute the command:&lt;br /&gt;
  mpirun -n 4 yambo_nl -F 01_SHG_ip.in -J 01_SHG_ip -C 01_SHG_ip_files&lt;br /&gt;
&lt;br /&gt;
Once the run is finished, check the report &amp;lt;code&amp;gt;01_SHG_ip_files/r-01_SHG_ip_nloptics&amp;lt;/code&amp;gt;. In particular, in the appended input files, you can see the default parallelization applied by the code for calculating the dipoles and run the time-propagation. For the latter, the main parallelization is on the frequencies and then on the k-points (&amp;lt;code&amp;gt;NL_ROLEs= &amp;quot;w.k&amp;quot;&amp;lt;/code&amp;gt;).   &lt;br /&gt;
&lt;br /&gt;
 | NL_CPU= &amp;quot;2.2&amp;quot;                    # [PARALLEL] CPUs for each role&lt;br /&gt;
 | NL_ROLEs= &amp;quot;w.k&amp;quot;                  # [PARALLEL] CPUs roles (w,k)&lt;br /&gt;
 | DIP_CPU= &amp;quot;2.2.1&amp;quot;                 # [PARALLEL] CPUs for each role&lt;br /&gt;
 | DIP_ROLEs= &amp;quot;v.c.k&amp;quot;               # [PARALLEL] CPUs roles (k,c,v)&lt;br /&gt;
&lt;br /&gt;
Also, look at the simulation time. This is approximately 42 fs. &lt;br /&gt;
&lt;br /&gt;
Plot the polarization for a couple of frequencies, e.g. the first and last of the chosen range (the corresponding frequency can be read in the file, search for &amp;quot;Frequency value&amp;quot;):&lt;br /&gt;
 set ylabel &amp;quot;x-component polarization&amp;quot; offset -0.7&lt;br /&gt;
 set xlabel &amp;quot;time (fs)&amp;quot;&lt;br /&gt;
 plot &#039;01_SHG_ip_files/o-01_SHG_ip.polarization_F1&#039; u 1:2 w l lw 2 title &amp;quot;omega = 0.5 eV&amp;quot;&lt;br /&gt;
 replot &#039;01_SHG_ip_files/o-01_SHG_ip.polarization_F12&#039; u 1:2 w l lw 2  title &amp;quot;omega = 7.375 eV&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[File:Berry_phase_polarization_of_2D_h-BN_obtained_from_the_previous_run_for_two_laser_frequencies.png|Berry_phase_polarization_of_2D_h-BN_obtained from the run for two laser frequencies]]&lt;br /&gt;
&lt;br /&gt;
After the applied field is &#039;switched on&#039;, the polarization is oscillating at the frequency of the applied field and at the eigenfrequencies of the system as described above in the cartoon. This is visible particularly for the higher frequency. Due to the dephasing, after about 20 fs the polarization is oscillating (at least to the eye) at the frequency of the applied field. Nonlinear components are not visible since they are several orders of magnitude smaller than the first order.&lt;br /&gt;
&lt;br /&gt;
== Output post-processing: the dielectric function ==&lt;br /&gt;
&lt;br /&gt;
Once we obtained the polarization, we Fourier-transform the polarization to obtain the dielectric function.&lt;br /&gt;
&lt;br /&gt;
Use the command:&lt;br /&gt;
&lt;br /&gt;
  ypp_nl -nl -F 02_SHG_ip_pp.in -C 01_SHG_ip_files&lt;br /&gt;
&lt;br /&gt;
to generate the input file: &lt;br /&gt;
&lt;br /&gt;
 nonlinear                        # [R] Non-linear response analysis&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;Xorder= 4&amp;lt;/span&amp;gt; # 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;NONE&amp;quot;                 # Damping type ( NONE | LORENTZIAN | GAUSSIAN )&lt;br /&gt;
 DampFactor= 0.000000       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;
Where we changed the &amp;lt;code&amp;gt;Xorder&amp;lt;/code&amp;gt; to 4. This variable controls the terms in the Fourier expansion of the polarization. We choose up to expand up to the fourth order. This should ensure the second order to be accurate enough. As an exercise, you can change this value (e.g. choose 2,3,5,6) and see how the result below is changing. The time-window where processing is done is chosen automatically, since values are negative. The code chooses by default the last period to carry out the analysis. &lt;br /&gt;
&lt;br /&gt;
To run the post-processing, use the command:&lt;br /&gt;
 ypp_nl -F Inputs_shg/ypp_shg.in -J TD-IP_nl -C TD-IP_nl. &lt;br /&gt;
   &lt;br /&gt;
In  &amp;lt;code&amp;gt;01_SHG_ip_files&amp;lt;/code&amp;gt; the following files were generated &lt;br /&gt;
 o-01_SHG_ip.YPP-X_probe_order_1&lt;br /&gt;
 o-01_SHG_ip.YPP-X_probe_order_2&lt;br /&gt;
 o-01_SHG_ip.YPP-X_probe_order_3&lt;br /&gt;
 o-01_SHG_ip.YPP-X_probe_order_4&lt;br /&gt;
 r-01_SHG_ip_nonlinear&lt;br /&gt;
&lt;br /&gt;
The output files contain respectively the first, second, third and fourth order response(corresponding to &amp;lt;code&amp;gt;Xorder=4&amp;lt;/code&amp;gt;)  at the 12 frequencies in the chosen range. &lt;br /&gt;
 &lt;br /&gt;
Inspect &amp;lt;code&amp;gt;o-01_SHG_ip.YPP-X_probe_order_2&amp;lt;/code&amp;gt;&lt;br /&gt;
 #     E [eV]            X/Im[cm/stV](x)    X/Re[cm/stV](x)    X/Im[cm/stV](y)    X/Re[cm/stV](y)    X/Im[cm/stV](z)    X/Re[cm/stV](z)&lt;br /&gt;
 #&lt;br /&gt;
      0.50000000        -0.35378838E-09    -0.19774796E-07     0.23591828E-09    -0.89405637E-09      0.0000000          0.0000000    &lt;br /&gt;
      1.1250000         -0.19356524E-08    -0.23160605E-07    -0.16052184E-09    -0.67662771E-09      0.0000000          0.0000000    &lt;br /&gt;
      1.7500000         -0.69446459E-08    -0.35586956E-07    -0.76025706E-09    -0.10205678E-08      0.0000000          0.0000000    &lt;br /&gt;
      2.37500000        -0.181606152E-7    -0.261823658E-8     0.438358596E-8     0.407915226E-8      0.00000000         0.00000000   &lt;br /&gt;
&lt;br /&gt;
The first column are the frequencies of the applied field, the second and third is the polarization along x (imaginary and real part), the fourth and fifth is the polarization along y (imaginary and real part)  &lt;br /&gt;
and the sixth and seventh is the polarization along z (imaginary and real part).&lt;br /&gt;
&lt;br /&gt;
Plot the absolute value of the SHG for the &amp;quot;xxy&amp;quot; component (that is, the applied field is in the x and y directions and one look at the polarization along x):&lt;br /&gt;
&lt;br /&gt;
 set ylabel &amp;quot;{/Symbol=26 \174}{/Symbol=26 c}_{xyx}^{(2)}{/Symbol=26 \174} (pm/V)&amp;quot; offset -0.7&lt;br /&gt;
 set xlabel &amp;quot;Energy (eV)&amp;quot;&lt;br /&gt;
 pmVm1toCGS=2.38721e-09&lt;br /&gt;
 plot &#039;01_SHG_ip_files/o-01_SHG_ip.YPP-X_probe_order_2&#039; u 1:(sqrt($2**2+$3**2)/pmVm1toCGS) w p title &amp;quot;calc&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[File: SHG_intensity_of_2D_h-BN_obtained_from_the_previous_run_(and_compared_with_a_run_on_112_frequencies).png | SHG_intensity_of_2D_h-BN obtained from the current run (12 frequencies) compared with a run with 112 frequencies]] &lt;br /&gt;
&lt;br /&gt;
In the figure above, the results of the current run are compared with those for a run with 112 frequencies (one can obtain these results by repeating the calculations, changing the number of frequencies in &amp;lt;code&amp;gt;NLEnSteps&amp;lt;/code&amp;gt; though this take about 10 times more computational time than the run with 12). One can notice some differences between the two runs. In fact, the two runs evaluate different frequnecies and the difference indicates spurious oscillations of the value of the polarizability due to the simulation time being too short and thus to the presence of &#039;noise&#039; due to the eigenfrecies.  &lt;br /&gt;
As an exercise, you can repeat the simulation for e,g, a time of &amp;lt;code&amp;gt;60 fs&amp;lt;/code&amp;gt;, that is setting &amp;lt;code&amp;gt;NLtime=60&amp;lt;/code&amp;gt;. The plot below compare the SHG extracted at 42 fs and 60 fs, where the latter gives clearly more accurate results. &lt;br /&gt;
&lt;br /&gt;
[[File:Comparison of the SHG intensity of 2D h-BN obtained with different simulation time.png|Comparison of the SHG intensity of 2D h-BN obtained with different simulation time]]&lt;br /&gt;
&lt;br /&gt;
As a final note, the SHG depends on the size of the vacuum added in the supercell. Instead, one should consider the surface SHG which obtained by considering an effective thickness for the layer. This is usually chosen to be similar to the layer separation in the bulk counterpart.&lt;br /&gt;
&lt;br /&gt;
= Step 3: Hartree+Screened exchange approximation (BSE level) =&lt;br /&gt;
&lt;br /&gt;
== Hartree+Screened exchange collisions ==&lt;br /&gt;
Similarly to the linear part, one needs to generate the Screened exchange collisions. The procedure is exactly the same.&lt;br /&gt;
&lt;br /&gt;
Create the input:&lt;br /&gt;
 yambo_nl -X s -e -v hsex -F 03_coll_hsex.in&lt;br /&gt;
modify the input ad follows&lt;br /&gt;
 em1s                             # [R][Xs] Statically Screened Interaction&lt;br /&gt;
 collisions                       # [R] Collisions&lt;br /&gt;
 dipoles                          # [R] Oscillator strenghts (or dipoles)&lt;br /&gt;
 Chimod= &amp;quot;HARTREE&amp;quot;                # [X] IP/Hartree/ALDA/LRC/PF/BSfxc&lt;br /&gt;
 % BndsRnXs&lt;br /&gt;
    1 |  20 |                         # [Xs] Polarization function bands&lt;br /&gt;
 %&lt;br /&gt;
 NGsBlkXs= 1000 mHa    # [Xs] Response block size&lt;br /&gt;
 % LongDrXs&lt;br /&gt;
  1.000000 | 1.000000 | 0.000000 |        # [Xs] [cc] Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 % COLLBands&lt;br /&gt;
    4 |  5 |                         # [COLL] Bands for the collisions&lt;br /&gt;
 %&lt;br /&gt;
 HXC_Potential= &amp;quot;SEX+HARTREE&amp;quot;     # [SC] SC HXC Potential&lt;br /&gt;
 HARRLvcs= 1000 mHa    # [HA] Hartree     RL components&lt;br /&gt;
 EXXRLvcs= 1000 mHa    # [XX] Exchange    RL components&lt;br /&gt;
 CORRLvcs= 1000 mHa    # [GW] Correlation RL components&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Calculate the collisions (you may want to run in parallel):&lt;br /&gt;
 yambo_nl -F 03_coll_hsex.in -J 03_coll -C 04_hsex_files&lt;br /&gt;
&lt;br /&gt;
== Run the simulation ==&lt;br /&gt;
&lt;br /&gt;
Create the input:&lt;br /&gt;
 yambo_nl -nl n -v hsex -V qp -F 04_SHG_hsex.in&lt;br /&gt;
&lt;br /&gt;
modify the following parts of the input (by this time all the innput variables should be known from the previous exercises):&lt;br /&gt;
&lt;br /&gt;
 % BndsRnXs&lt;br /&gt;
   1 |  20 |                         # [Xs] Polarization function bands&lt;br /&gt;
 %&lt;br /&gt;
 NGsBlkXs= 1000 mHa    # [Xs] Response block size&lt;br /&gt;
 % LongDrXs&lt;br /&gt;
  1.000000 | 1.000000 | 0.000000 |        # [Xs] [cc] Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 % NLBands&lt;br /&gt;
    4 |  5 |                         # [NL] Bands range&lt;br /&gt;
 %&lt;br /&gt;
&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;SEX&amp;quot;             # [NL] Correlation (&amp;quot;IPA/HARTREE/TDDFT/LRC/LRW/JGM/SEX&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 % NLEnRange&lt;br /&gt;
  0.500000 |8.000000 |         eV    # [NL] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 NLEnSteps= 12                   # [NL] Energy steps&lt;br /&gt;
&lt;br /&gt;
 % GfnQP_E&lt;br /&gt;
  3.000000 | 1.000000 | 1.000000 |        # [EXTQP G] E parameters  (c/v) eV|adim|adim&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
 Field1_kind= &amp;quot;SIN&amp;quot;           # [RT Field1] Kind(SIN|COS|RES|ANTIRES|GAUSS|DELTA|QSSIN)&lt;br /&gt;
&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
  1.000000 | 1.000000 | 0.000000 |        # [RT Field1] Versor&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
Then run the simulation using e.g. mpi and 4 cores:&lt;br /&gt;
 mpirun -n 4 yambo_nl -F 04_SHG_hsex.in -J 04_SHG_hsex,03_coll -C 04_SHG_hsex_files&lt;br /&gt;
&lt;br /&gt;
== Postprocessing: obtain the nonlinear response ==&lt;br /&gt;
&lt;br /&gt;
Similarly to what we did for the independent particle case, we create the input:&lt;br /&gt;
 ypp_nl -nl -F 05_SHG_hsex_pp.in&lt;br /&gt;
 &lt;br /&gt;
we change &amp;lt;code&amp;gt;Xorder = 4 &amp;lt;/code&amp;gt; and then run:&lt;br /&gt;
 ypp_nl -F 05_SHG_hsex_pp.in -J 04_SHG_hsex -C 04_hsex_files&lt;br /&gt;
&lt;br /&gt;
Then we plot (as before we compare with a simulation ran for 112 frequnecies).&lt;br /&gt;
&lt;br /&gt;
Plot the results:&lt;br /&gt;
&lt;br /&gt;
 set ylabel &amp;quot;{/Symbol=26 \174}{/Symbol=26 c}_{xyx}^{(2)}{/Symbol=26 \174} (pm/V)&amp;quot; offset -0.7&lt;br /&gt;
 set xlabel &amp;quot;Energy (eV)&amp;quot;&lt;br /&gt;
 pmVm1toCGS=2.38721e-09&lt;br /&gt;
 plot &#039;04_hsex_files/o-04_SHG_hsex.YPP-X_probe_order_2&#039; u 1:(sqrt($2**2+$3**2)/pmVm1toCGS) w p title &amp;quot;calc&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[File:SHG hsex.png|SHG at the Hartree + Screened exchange from current run with 12 frequencies (crosses) and a run with 112 frequencies (keeping the other parameters the same)]]&lt;br /&gt;
&lt;br /&gt;
also in this case we note differences between the two simulations. This is due to the too short simulation time. Repeating the calculations with a longer time gives more accurate results. &lt;br /&gt;
In addition, note that in the interest of time, all parameters are underconverged. In principle, to calculate the collisions one should use the same parameters of a converged BSE calculation. As well, one should use the Coulomb cutoff as it was used for this system in the  BSE case.&lt;br /&gt;
&lt;br /&gt;
= References = &lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Fulvio</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Second-harmonic_generation_of_2D-hBN&amp;diff=6994</id>
		<title>Second-harmonic generation of 2D-hBN</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Second-harmonic_generation_of_2D-hBN&amp;diff=6994"/>
		<updated>2023-05-25T08:34:51Z</updated>

		<summary type="html">&lt;p&gt;Fulvio: /* Step 1: Prerequisites */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Step 0: Theoretical framework =&lt;br /&gt;
&lt;br /&gt;
In this tutorial, we compute the Second-harmonic generation (SHG) from the dynamics of the Bloch-states. The equation-of-motion of the Bloch-states is explained in the tutorial on [[Linear response from Bloch-states dynamics]]. Independently of the &#039;experiment&#039; we simulate, the part of the integration of motion stays the same. This means that any experiment, including non-linear optics, can be performed at the level of the theory listed for the computation of the dielectric function:&lt;br /&gt;
* independent (quasi)particle&lt;br /&gt;
* time-dependent Hartree (RPA level)&lt;br /&gt;
* time-dependent DFT (and DPFT)&lt;br /&gt;
* time-dependent Hartree+Screened exchange (BSE level)&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
What changes when we want to calculate the SHG (or higher harmonics) is:&lt;br /&gt;
* the time-dependence of the input electric field and&lt;br /&gt;
* the post-processing of the signal  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Time dependence of the electric Field&#039;&#039;&#039;: we choose a sinusoidal electric field, thus a monochromatic laser field. This allows one to expand the polarization in the form &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; through a coefficient depending on a power of the strength of the field (with the power depending on the order of the response).&lt;br /&gt;
&lt;br /&gt;
At difference with a delta-like perturbation, a real-time simulation gives the response at the laser-field only. Then, to obtain the spectrum for the desired range of frequency, we have to perform so many simulations as the frequencies in the desired range.  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Post-processing of the signal&#039;&#039;&#039;: The switch-on of the electric field corresponds to a weak delta-like kick. Thus, even if it may not be noticeable, the polarization results from both the sinusoidal field and the delta-like kick. The latter excites all eigenfrequencies of the system. Though weak, the resulting signal is comparable with the second-harmonic signal. To eliminate the signal from the eigenfrequencies, we apply a dephasing (&amp;lt;math&amp;gt;\gamma_{deph}&amp;lt;/math&amp;gt;). To have a signal useful to sample the second-harmonic signal, we need to wait a time &amp;lt;math&amp;gt;\bar t&amp;lt;/math&amp;gt;  much larger than the dephasing-time &amp;lt;math&amp;gt;1/\gamma_{deph} &amp;lt;/math&amp;gt;. Note that we cannot choose a too short dephasing time (to shorten the simulation time), as this would result in a too large broadening of the spectrum. After &amp;lt;math&amp;gt;\bar t&amp;lt;/math&amp;gt;, we sample $2N+1$ times in a period and use discrete Fourier transform to extract &amp;lt;math&amp;gt;{p}_n&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt; n = 0,...,N&amp;lt;/math&amp;gt;, where n=2 gives the SHG. This is schematically illustrated in figure:&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;
The scheme from Ref. &amp;lt;ref name=&amp;quot;Attaccalite2013&amp;quot;&amp;gt;C. Attaccalite and M. Gruning [https://arxiv.org/abs/1309.4012v2 Rev. B, &#039;&#039;&#039;88&#039;&#039;&#039;, 235113 (2013)]&amp;lt;/ref&amp;gt; summarised the workflow for computing the SHG (or higher-harmonics) in a energy range &amp;lt;math&amp;gt;[\Omega_1,\Omega_2]&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
[[File:Scheme nl.png|350px|center|Schematic representation of real-time calculations]]&lt;br /&gt;
&lt;br /&gt;
= Step 1: Prerequisites =&lt;br /&gt;
&lt;br /&gt;
In this example, we will consider a single layer of hexagonal boron nitride (hBN). Before running real time simulations to compute the SHG in &amp;lt;code&amp;gt;yambo&amp;lt;/code&amp;gt; you need to download input files and Yambo databases for this tutorial here: [https://media.yambo-code.eu/educational/tutorials/files/hBN-2D-RT.tar.gz hBN-2D-RT.tar.gz].&lt;br /&gt;
Unzip the tarball and change directory to &amp;lt;code&amp;gt;YAMBO&amp;lt;/code&amp;gt; and run the setup (&amp;lt;code&amp;gt;yambo_nl -nompi&amp;lt;/code&amp;gt;). &lt;br /&gt;
Execute the command &lt;br /&gt;
 ypp_nl -fixsym -F 00_removesym.in  &lt;br /&gt;
to create the input, to remove the symmetries which are not compatible with the field: &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;1.000000 | 1.000000 | 0.000000 |&amp;lt;/span&amp;gt;        # First external Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 % Efield2&lt;br /&gt;
  0.000000 | 0.000000 | 0.000000 |        # 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;
 #KeepKGrid                     # Do not expand the k-grid&lt;br /&gt;
where we chose the field along the xy direction and we remove time-reversal symmetry.&lt;br /&gt;
&lt;br /&gt;
Then run the pre-processing job:&lt;br /&gt;
 ypp_nl -F 00_removesym.in J 00_removesym&lt;br /&gt;
This creates the directory &amp;lt;code&amp;gt;FixSymm&amp;lt;/code&amp;gt;. Change directory to &amp;lt;code&amp;gt;FixSymm&amp;lt;/code&amp;gt;. This contains the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory with reduced symmetries, compatible with the direction of the field. Now run the setup again ((&amp;lt;code&amp;gt;yambo_nl -nompi&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
= Step 2: Independent-particle approximation =&lt;br /&gt;
&lt;br /&gt;
Use the command:&lt;br /&gt;
  yambo_nl -nl n -F 01_SHG_ip.in&lt;br /&gt;
to generate the input:&lt;br /&gt;
&lt;br /&gt;
 nloptics                         # [R] Non-linear spectroscopy&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=-1.000000           fs    # [NL] Simulation Time&lt;br /&gt;
 NLintegrator= &amp;quot;INVINT&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;
 % NLEnRange&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;0.5000000 |8.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;12&amp;lt;/span&amp;gt;                     # [NL] Energy steps&lt;br /&gt;
 NLDamping= 0.200000        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;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&amp;quot;SIN&amp;quot; &amp;lt;/span&amp;gt;          # [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 | 1.000000 | 0.000000 |&amp;lt;/span&amp;gt;        # [RT Field1] Versor&lt;br /&gt;
 %&lt;br /&gt;
 Field1_Tstart= 0.010000    fs    # [RT Field1] Initial Time&lt;br /&gt;
&lt;br /&gt;
To describe the Bloch-dynamics we will use as a basis the KS-states 3-6 for the k-grid used in the non-scf DFT calculations, that is a 6x6x1 (&amp;lt;code&amp;gt;NLBands&amp;lt;/code&amp;gt;). We choose 12 equally spaced frequencies (&amp;lt;code&amp;gt;NLEnSteps&amp;lt;/code&amp;gt;) for the applied field in the range  (&amp;lt;code&amp;gt;NLEnRange&amp;lt;/code&amp;gt;) between 0.5 and 8 eV. We choose a sinusoidal time-dependence (&amp;lt;code&amp;gt;Field1_kind&amp;lt;/code&amp;gt;) and set the field direction (&amp;lt;code&amp;gt;Field1_kind&amp;lt;/code&amp;gt;) along xy (in plane). The negative simulation time (&amp;lt;code&amp;gt;NLtime=-1.000000&amp;lt;/code&amp;gt;) means that the code will choose it based on the value of the &amp;lt;code&amp;gt;NLDamping&amp;lt;/code&amp;gt;. While this is a good lower bound for the simulation time, one should check it is sufficient to get accurate results. &lt;br /&gt;
&lt;br /&gt;
Run the simulation, possibly in parallel e. g. in a interactive session on 4 cores, execute the command:&lt;br /&gt;
  mpirun -n 4 yambo_nl -F 01_SHG_ip.in -J 01_SHG_ip -C 01_SHG_ip_files&lt;br /&gt;
&lt;br /&gt;
Once the run is finished, check the report &amp;lt;code&amp;gt;01_SHG_ip_files/r-01_SHG_ip_nloptics&amp;lt;/code&amp;gt;. In particular, in the appended input files, you can see the default parallelization applied by the code for calculating the dipoles and run the time-propagation. For the latter, the main parallelization is on the frequencies and then on the k-points (&amp;lt;code&amp;gt;NL_ROLEs= &amp;quot;w.k&amp;quot;&amp;lt;/code&amp;gt;).   &lt;br /&gt;
&lt;br /&gt;
 | NL_CPU= &amp;quot;2.2&amp;quot;                    # [PARALLEL] CPUs for each role&lt;br /&gt;
 | NL_ROLEs= &amp;quot;w.k&amp;quot;                  # [PARALLEL] CPUs roles (w,k)&lt;br /&gt;
 | DIP_CPU= &amp;quot;2.2.1&amp;quot;                 # [PARALLEL] CPUs for each role&lt;br /&gt;
 | DIP_ROLEs= &amp;quot;v.c.k&amp;quot;               # [PARALLEL] CPUs roles (k,c,v)&lt;br /&gt;
&lt;br /&gt;
Also, look at the simulation time. This is approximately 42 fs. &lt;br /&gt;
&lt;br /&gt;
Plot the polarization for a couple of frequencies, e.g. the first and last of the chosen range (the corresponding frequency can be read in the file, search for &amp;quot;Frequency value&amp;quot;):&lt;br /&gt;
 set ylabel &amp;quot;x-component polarization&amp;quot; offset -0.7&lt;br /&gt;
 set xlabel &amp;quot;time (fs)&amp;quot;&lt;br /&gt;
 plot &#039;01_SHG_ip_files/o-01_SHG_ip.polarization_F1&#039; u 1:2 w l lw 2 title &amp;quot;omega = 0.5 eV&amp;quot;&lt;br /&gt;
 replot &#039;01_SHG_ip_files/o-01_SHG_ip.polarization_F12&#039; u 1:2 w l lw 2  title &amp;quot;omega = 7.375 eV&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[File:Berry_phase_polarization_of_2D_h-BN_obtained_from_the_previous_run_for_two_laser_frequencies.png|Berry_phase_polarization_of_2D_h-BN_obtained from the run for two laser frequencies]]&lt;br /&gt;
&lt;br /&gt;
After the applied field is &#039;switched on&#039;, the polarization is oscillating at the frequency of the applied field and at the eigenfrequencies of the system as described above in the cartoon. This is visible particularly for the higher frequency. Due to the dephasing, after about 20 fs the polarization is oscillating (at least to the eye) at the frequency of the applied field. Nonlinear components are not visible since they are several orders of magnitude smaller than the first order.&lt;br /&gt;
&lt;br /&gt;
== Output post-processing: the dielectric function ==&lt;br /&gt;
&lt;br /&gt;
Once we obtained the polarization, we Fourier-transform the polarization to obtain the dielectric function.&lt;br /&gt;
&lt;br /&gt;
Use the command:&lt;br /&gt;
&lt;br /&gt;
  ypp_nl -nl -F 02_SHG_ip_pp.in -C 01_SHG_ip_files&lt;br /&gt;
&lt;br /&gt;
to generate the input file: &lt;br /&gt;
&lt;br /&gt;
 nonlinear                        # [R] Non-linear response analysis&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;Xorder= 4&amp;lt;/span&amp;gt; # 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;NONE&amp;quot;                 # Damping type ( NONE | LORENTZIAN | GAUSSIAN )&lt;br /&gt;
 DampFactor= 0.000000       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;
Where we changed the &amp;lt;code&amp;gt;Xorder&amp;lt;/code&amp;gt; to 4. This variable controls the terms in the Fourier expansion of the polarization. We choose up to expand up to the fourth order. This should ensure the second order to be accurate enough. As an exercise, you can change this value (e.g. choose 2,3,5,6) and see how the result below is changing. The time-window where processing is done is chosen automatically, since values are negative. The code chooses by default the last period to carry out the analysis. &lt;br /&gt;
&lt;br /&gt;
To run the post-processing, use the command:&lt;br /&gt;
 ypp_nl -F Inputs_shg/ypp_shg.in -J TD-IP_nl -C TD-IP_nl. &lt;br /&gt;
   &lt;br /&gt;
In  &amp;lt;code&amp;gt;01_SHG_ip_files&amp;lt;/code&amp;gt; the following files were generated &lt;br /&gt;
 o-01_SHG_ip.YPP-X_probe_order_1&lt;br /&gt;
 o-01_SHG_ip.YPP-X_probe_order_2&lt;br /&gt;
 o-01_SHG_ip.YPP-X_probe_order_3&lt;br /&gt;
 o-01_SHG_ip.YPP-X_probe_order_4&lt;br /&gt;
 r-01_SHG_ip_nonlinear&lt;br /&gt;
&lt;br /&gt;
The output files contain respectively the first, second, third and fourth order response(corresponding to &amp;lt;code&amp;gt;Xorder=4&amp;lt;/code&amp;gt;)  at the 12 frequencies in the chosen range. &lt;br /&gt;
 &lt;br /&gt;
Inspect &amp;lt;code&amp;gt;o-01_SHG_ip.YPP-X_probe_order_2&amp;lt;/code&amp;gt;&lt;br /&gt;
 #     E [eV]            X/Im[cm/stV](x)    X/Re[cm/stV](x)    X/Im[cm/stV](y)    X/Re[cm/stV](y)    X/Im[cm/stV](z)    X/Re[cm/stV](z)&lt;br /&gt;
 #&lt;br /&gt;
      0.50000000        -0.35378838E-09    -0.19774796E-07     0.23591828E-09    -0.89405637E-09      0.0000000          0.0000000    &lt;br /&gt;
      1.1250000         -0.19356524E-08    -0.23160605E-07    -0.16052184E-09    -0.67662771E-09      0.0000000          0.0000000    &lt;br /&gt;
      1.7500000         -0.69446459E-08    -0.35586956E-07    -0.76025706E-09    -0.10205678E-08      0.0000000          0.0000000    &lt;br /&gt;
      2.37500000        -0.181606152E-7    -0.261823658E-8     0.438358596E-8     0.407915226E-8      0.00000000         0.00000000   &lt;br /&gt;
&lt;br /&gt;
The first column are the frequencies of the applied field, the second and third is the polarization along x (imaginary and real part), the fourth and fifth is the polarization along y (imaginary and real part)  &lt;br /&gt;
and the sixth and seventh is the polarization along z (imaginary and real part).&lt;br /&gt;
&lt;br /&gt;
Plot the absolute value of the SHG for the &amp;quot;xxy&amp;quot; component (that is, the applied field is in the x and y directions and one look at the polarization along x):&lt;br /&gt;
&lt;br /&gt;
 set ylabel &amp;quot;{/Symbol=26 \174}{/Symbol=26 c}_{xyx}^{(2)}{/Symbol=26 \174} (pm/V)&amp;quot; offset -0.7&lt;br /&gt;
 set xlabel &amp;quot;Energy (eV)&amp;quot;&lt;br /&gt;
 pmVm1toCGS=2.38721e-09&lt;br /&gt;
 plot &#039;01_SHG_ip_files/o-01_SHG_ip.YPP-X_probe_order_2&#039; u 1:(sqrt($2**2+$3**2)/pmVm1toCGS) w p title &amp;quot;calc&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[File: SHG_intensity_of_2D_h-BN_obtained_from_the_previous_run_(and_compared_with_a_run_on_112_frequencies).png | SHG_intensity_of_2D_h-BN obtained from the current run (12 frequencies) compared with a run with 112 frequencies]] &lt;br /&gt;
&lt;br /&gt;
In the figure above, the results of the current run are compared with those for a run with 112 frequencies (one can obtain these results by repeating the calculations, changing the number of frequencies in &amp;lt;code&amp;gt;NLEnSteps&amp;lt;/code&amp;gt; though this take about 10 times more computational time than the run with 12). One can notice some differences between the two runs. In fact, the two runs evaluate different frequnecies and the difference indicates spurious oscillations of the value of the polarizability due to the simulation time being too short and thus to the presence of &#039;noise&#039; due to the eigenfrecies.  &lt;br /&gt;
As an exercise, you can repeat the simulation for e,g, a time of &amp;lt;code&amp;gt;60 fs&amp;lt;/code&amp;gt;, that is setting &amp;lt;code&amp;gt;NLtime=60&amp;lt;/code&amp;gt;. The plot below compare the SHG extracted at 42 fs and 60 fs, where the latter gives clearly more accurate results. &lt;br /&gt;
&lt;br /&gt;
[[File:Comparison of the SHG intensity of 2D h-BN obtained with different simulation time.png|Comparison of the SHG intensity of 2D h-BN obtained with different simulation time]]&lt;br /&gt;
&lt;br /&gt;
As a final note, the SHG depends on the size of the vacuum added in the supercell. Instead, one should consider the surface SHG which obtained by considering an effective thickness for the layer. This is usually chosen to be similar to the layer separation in the bulk counterpart.&lt;br /&gt;
&lt;br /&gt;
= Step 3: Hartree+Screened exchange approximation (BSE level) =&lt;br /&gt;
&lt;br /&gt;
== Hartree+Screened exchange collisions ==&lt;br /&gt;
Similarly to the linear part, one needs to generate the Screened exchange collisions. The procedure is exactly the same.&lt;br /&gt;
&lt;br /&gt;
Create the input:&lt;br /&gt;
 yambo_nl -X s -e -v hsex -F 03_coll_hsex.in&lt;br /&gt;
modify the input ad follows&lt;br /&gt;
 em1s                             # [R][Xs] Statically Screened Interaction&lt;br /&gt;
 collisions                       # [R] Collisions&lt;br /&gt;
 dipoles                          # [R] Oscillator strenghts (or dipoles)&lt;br /&gt;
 Chimod= &amp;quot;HARTREE&amp;quot;                # [X] IP/Hartree/ALDA/LRC/PF/BSfxc&lt;br /&gt;
 % BndsRnXs&lt;br /&gt;
    1 |  20 |                         # [Xs] Polarization function bands&lt;br /&gt;
 %&lt;br /&gt;
 NGsBlkXs= 1000 mHa    # [Xs] Response block size&lt;br /&gt;
 % LongDrXs&lt;br /&gt;
  1.000000 | 1.000000 | 0.000000 |        # [Xs] [cc] Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 % COLLBands&lt;br /&gt;
    4 |  5 |                         # [COLL] Bands for the collisions&lt;br /&gt;
 %&lt;br /&gt;
 HXC_Potential= &amp;quot;SEX+HARTREE&amp;quot;     # [SC] SC HXC Potential&lt;br /&gt;
 HARRLvcs= 1000 mHa    # [HA] Hartree     RL components&lt;br /&gt;
 EXXRLvcs= 1000 mHa    # [XX] Exchange    RL components&lt;br /&gt;
 CORRLvcs= 1000 mHa    # [GW] Correlation RL components&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Calculate the collisions (you may want to run in parallel):&lt;br /&gt;
 yambo_nl -F 03_coll_hsex.in -J 03_coll -C 04_hsex_files&lt;br /&gt;
&lt;br /&gt;
== Run the simulation ==&lt;br /&gt;
&lt;br /&gt;
Create the input:&lt;br /&gt;
 yambo_nl -nl n -v hsex -V qp -F 04_SHG_hsex.in&lt;br /&gt;
&lt;br /&gt;
modify the following parts of the input (by this time all the innput variables should be known from the previous exercises):&lt;br /&gt;
&lt;br /&gt;
 % BndsRnXs&lt;br /&gt;
   1 |  20 |                         # [Xs] Polarization function bands&lt;br /&gt;
 %&lt;br /&gt;
 NGsBlkXs= 1000 mHa    # [Xs] Response block size&lt;br /&gt;
 % LongDrXs&lt;br /&gt;
  1.000000 | 1.000000 | 0.000000 |        # [Xs] [cc] Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 % NLBands&lt;br /&gt;
    4 |  5 |                         # [NL] Bands range&lt;br /&gt;
 %&lt;br /&gt;
&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;SEX&amp;quot;             # [NL] Correlation (&amp;quot;IPA/HARTREE/TDDFT/LRC/LRW/JGM/SEX&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 % NLEnRange&lt;br /&gt;
  0.500000 |8.000000 |         eV    # [NL] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 NLEnSteps= 12                   # [NL] Energy steps&lt;br /&gt;
&lt;br /&gt;
 % GfnQP_E&lt;br /&gt;
  3.000000 | 1.000000 | 1.000000 |        # [EXTQP G] E parameters  (c/v) eV|adim|adim&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
 Field1_kind= &amp;quot;SIN&amp;quot;           # [RT Field1] Kind(SIN|COS|RES|ANTIRES|GAUSS|DELTA|QSSIN)&lt;br /&gt;
&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
  1.000000 | 1.000000 | 0.000000 |        # [RT Field1] Versor&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
Then run the simulation using e.g. mpi and 4 cores:&lt;br /&gt;
 mpirun -n 4 yambo_nl -F 04_SHG_hsex.in -J 04_SHG_hsex,03_coll -C 04_SHG_hsex_files&lt;br /&gt;
&lt;br /&gt;
== Postprocessing: obtain the nonlinear response ==&lt;br /&gt;
&lt;br /&gt;
Similarly to what we did for the independent particle case, we create the input:&lt;br /&gt;
 ypp_nl -nl -F 05_SHG_hsex_pp.in&lt;br /&gt;
 &lt;br /&gt;
we change &amp;lt;code&amp;gt;Xorder = 4 &amp;lt;/code&amp;gt; and then run:&lt;br /&gt;
 ypp_nl -F 05_SHG_hsex_pp.in -J 04_SHG_hsex -C 04_hsex_files&lt;br /&gt;
&lt;br /&gt;
Then we plot (as before we compare with a simulation ran for 112 frequnecies).&lt;br /&gt;
&lt;br /&gt;
Plot the results:&lt;br /&gt;
&lt;br /&gt;
 set ylabel &amp;quot;{/Symbol=26 \174}{/Symbol=26 c}_{xyx}^{(2)}{/Symbol=26 \174} (pm/V)&amp;quot; offset -0.7&lt;br /&gt;
 set xlabel &amp;quot;Energy (eV)&amp;quot;&lt;br /&gt;
 pmVm1toCGS=2.38721e-09&lt;br /&gt;
 plot &#039;04_hsex_files/o-04_SHG_hsex.YPP-X_probe_order_2&#039; u 1:(sqrt($2**2+$3**2)/pmVm1toCGS) w p title &amp;quot;calc&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[File:SHG hsex.png|SHG at the Hartree + Screened exchange from current run with 12 frequencies (crosses) and a run with 112 frequencies (keeping the other parameters the same)]]&lt;br /&gt;
&lt;br /&gt;
also in this case we note differences between the two simulations. This is due to the too short simulation time. Repeating the calculations with a longer time gives more accurate results. &lt;br /&gt;
In addition, note that in the interest of time, all parameters are underconverged. In principle, to calculate the collisions one should use the same parameters of a converged BSE calculation. As well, one should use the Coulomb cutoff as it was used for this system in the  BSE case.&lt;br /&gt;
&lt;br /&gt;
= References = &lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Fulvio</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Dielectric_function_from_Bloch-states_dynamics&amp;diff=6993</id>
		<title>Dielectric function from Bloch-states dynamics</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Dielectric_function_from_Bloch-states_dynamics&amp;diff=6993"/>
		<updated>2023-05-25T08:26:40Z</updated>

		<summary type="html">&lt;p&gt;Fulvio: /* Step 1: Prerequisites */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Step 0: Theoretical background =&lt;br /&gt;
&lt;br /&gt;
The dynamics of Bloch-states is found by integrating a set of Time Dependent Effective Schrödinger Equations (TD-ESEs). Effective means that an effective Hamiltonian is considered. We consider the many-body effective Hamiltonians seen in the [[Linear response from real time simulations]]. In addition, one can also consider effective Hamiltonians based on density-functional theory. The latter choice gives time-dependent density-functional theory.&lt;br /&gt;
&lt;br /&gt;
At difference with what seen in [[Linear response from real time simulations]], the coupling between electrons and the external field is described by means of the [http://www.theochem.unito.it/didattica/tec-comp_sdm/note1.pdf Modern Theory of Polarization]:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Tdse new.png|center|400px|Time-Dependent Schrödinger Equation]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Where  &amp;lt;math&amp;gt; | v_{i \mathbf{k}} \rangle &amp;lt;/math&amp;gt; are the time-dependent Bloch states (corresponding to the filled Bloch-states at zero-field), &amp;lt;math&amp;gt;\mathcal E(t)&amp;lt;/math&amp;gt; is the external field and the term &amp;lt;math&amp;gt; i e \partial k&amp;lt;/math&amp;gt; is the dipole operator consistent with periodic boundary condition. For more details on this last term, see Ref. &amp;lt;ref&amp;gt;I. Souza, J. Íñiguez, and D. Vanderbilt, [https://cfm.ehu.es/ivo/publications/souza_prb04.pdf PRB 69, 085106 (2004)]&amp;lt;/ref&amp;gt; and &amp;lt;ref name=&amp;quot;Attaccalite2013&amp;quot;&amp;gt;C. Attaccalite and M. Gruning [https://arxiv.org/abs/1309.4012v2 Rev. B, &#039;&#039;&#039;88&#039;&#039;&#039;, 235113 (2013)]&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;h_{rt}&amp;lt;/math&amp;gt; is the Hamiltonian,&lt;br /&gt;
[[File:H mb.png|400px|center|Many-Body Hamiltonian]].&lt;br /&gt;
This contains the equilibrium Hamiltonian, that is the zero-field eigenvalues evaluated through DFT; the quasiparticle corrections, evaluated from GW or estimated from experiment, and the variation of the self-energy. The latter is a functional of the density matrix &amp;lt;math&amp;gt;\rho&amp;lt;/math&amp;gt;, which is obtained from the Bloch states.   &lt;br /&gt;
&lt;br /&gt;
From the solution of the equation of motion for the Bloch states, the polarization is calculated by means of Berry&#039;s phase&lt;br /&gt;
&lt;br /&gt;
[[File:Berry polarization.png|center|350px|Berry&#039;s polarization]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
One can decide the level of theory by selecting the terms to include in the Hamiltonian:&lt;br /&gt;
&lt;br /&gt;
* by including only the first term, one selects the &#039;&#039;independent-particle approximation&#039;&#039;&lt;br /&gt;
* by including the first and second terms, one selects the &#039;&#039;independent-quasiparticle approximation&#039;&#039;&lt;br /&gt;
* by including the first, second terms and the Hartree part of the self-energy, one selects the &#039;&#039;time-dependent Hartree or random-phase approximation&#039;&#039;&lt;br /&gt;
* by including all terms, one selects the &#039;&#039;time-dependent Screened-exchange or Bethe-Salpeter equation&#039;&#039; level of theory.&lt;br /&gt;
&lt;br /&gt;
The type of &amp;quot;experiment&amp;quot; to perform, or of the response one would like to extract, depend on the time-dependent field in input and the post-processing of the Berry&#039;s phase polarization.  The induced polarization is the sum of the responses of the system to all orders in the external field:&lt;br /&gt;
&amp;lt;math&amp;gt;\bf{P}(t) = \sum_{n=-\infty}^{+\infty} \bf{P}_n (t) &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
In the case we are interested in linear response only, we use a delta-like electric field that excites all frequencies of the system. We choose the intensity of the field &amp;lt;math&amp;gt;E&amp;lt;/math&amp;gt; to be weak enough so that the response is dominated by the first order term. The response at all frequencies is obtained by taking the Fourier-transform of the polarization as&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \chi(\omega) = \frac{P(\omega)}{E} &amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
The response &amp;lt;math&amp;gt; \chi&amp;lt;/math&amp;gt;  is related to the dielectric function through the relation &amp;lt;math&amp;gt;\epsilon(\omega) = 1 + 4 \pi \chi(\omega) &amp;lt;/math&amp;gt;.&lt;br /&gt;
See also Ref. &amp;lt;ref name=&amp;quot;Attaccalite2013&amp;quot;&amp;gt;&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Notes: ==&lt;br /&gt;
* Length vs Velocity gauge: &#039;&#039;the equations of motion of Yambo are in the length gauge. Other codes choose instead to work in the velocity gauge. If you want to know more about the advantages and disadvantages of the two gauges read section 2.7 of Ref. &amp;lt;ref&amp;gt;C. Attaccalite, [https://arxiv.org/abs/1609.09639 arXiv 1609.09639 (2017)]&amp;lt;/ref&amp;gt;.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Advantages and disadvantages with respect to the density-matrix based formalism: &#039;&#039;Yambo implements two distinct formalisms for studying the real-time response, the one based on density-matrix and the one based on Boch states. Which formalism is best to use depends on what one wants to simulate. The dynamics formulation in terms of density matrix or non-equilibrium Green&#039;s functions allows a systematic treatment of correlation effects and electron-phonon coupling&amp;lt;ref name=&amp;quot;DavideEPL&amp;quot;&amp;gt;[https://arxiv.org/abs/1409.1706 D. Sangalli, and A. Marini EPL &#039;&#039;&#039;110&#039;&#039;&#039;, 47004 (2015)]&amp;lt;/ref&amp;gt;, but the price to pay is that the coupling with the external field is correct only to the linear order. This formalism is important in all those phenomena where electronic relaxation plays a major role.  On the other hand, the formulation in terms of the Bloch states treats coupling with the external field in an exact way even beyond the linear regime, and for this reason, it allows the description of phenomena coherent with the external fields and to access, for example, non-linear responses.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
= Step 1: Prerequisites =&lt;br /&gt;
In this example, we will consider a single layer of hexagonal boron nitride (hBN). Before running real time simulations in yambo you need to: &lt;br /&gt;
* download input files and Yambo databases for this tutorial here: [https://media.yambo-code.eu/educational/tutorials/files/hBN-2D-RT.tar.gz hBN-2D-RT.tar.gz].&lt;br /&gt;
* perform the steps described in [[Prerequisites for Real Time propagation with Yambo]].&lt;br /&gt;
&lt;br /&gt;
= Step 2: Independent-particle approximation =&lt;br /&gt;
&lt;br /&gt;
Similar to what you have seen in the tutorial for the density matrix formalism ([[Real time approach to linear response]]) we start from the lowest level of theory. Here it is assumed you ran the tutorial on the density-matrix formalism and so you are familiar with the optical spectrum of 2D h-BN at this level of theory. You will recognise that the input and output for the Bloch-state formalism are very similar to those for the density-matrix formalism.&lt;br /&gt;
&lt;br /&gt;
== Run the simulations ==&lt;br /&gt;
First of all, create a directory for the inputs to be run by &amp;lt;code&amp;gt;yambo_nl&amp;lt;/code&amp;gt;:&lt;br /&gt;
 mkdir Inputs_nl&lt;br /&gt;
&lt;br /&gt;
Then, use the command:&lt;br /&gt;
  yambo_nl -nl n -F Inputs_nl/01_td_ip.in&lt;br /&gt;
&lt;br /&gt;
to generate the input:&lt;br /&gt;
 &lt;br /&gt;
 nloptics                         # [R] Non-linear spectroscopy&lt;br /&gt;
 % NLBands&lt;br /&gt;
   &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;3&amp;lt;/span&amp;gt; | &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;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;55.000000&amp;lt;/span&amp;gt;           fs    # [NL] Simulation Time&lt;br /&gt;
 NLintegrator= &amp;quot;INVINT&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;
 % NLEnRange&lt;br /&gt;
  -1.000000 |-1.000000 |      eV    # [NL] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 NLEnSteps= 1                     # [NL] Energy steps&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= 18475            RL    # [HA] Hartree     RL components&lt;br /&gt;
 EXXRLvcs= 18475            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;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&amp;quot;DELTA&amp;quot;&amp;lt;/span&amp;gt;           # [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 | &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;1.000000&amp;lt;/span&amp;gt; | 0.000000 |        # [RT Field1] Versor&lt;br /&gt;
 %&lt;br /&gt;
 Field1_Tstart= 0.010000    fs    # [RT Field1] Initial Time&lt;br /&gt;
        &lt;br /&gt;
Note that the standard input of &amp;lt;code&amp;gt;yambo_nl&amp;lt;/code&amp;gt; has default settings for nonlinear response (e.g. the &amp;lt;code&amp;gt;SOFTSIN&amp;lt;/code&amp;gt; for the &amp;lt;code&amp;gt;Field1_kind&amp;lt;/code&amp;gt; (that set the time-dependence &#039;kind&#039; of the field).&lt;br /&gt;
Set the field direction &amp;lt;code&amp;gt;Field1_Dir&amp;lt;/code&amp;gt; along y, the field kind to &amp;lt;code&amp;gt;DELTA&amp;lt;/code&amp;gt;, the length of the simulation &amp;lt;code&amp;gt;NLtime&amp;lt;/code&amp;gt; to 55 fs, select the bands from 3 to 6 (&amp;lt;code&amp;gt;NLBands&amp;lt;/code&amp;gt;) and set the &amp;lt;code&amp;gt;NLDamping&amp;lt;/code&amp;gt; to zero. The fields you need to change with respect to the default settings are shown above in red. &lt;br /&gt;
&lt;br /&gt;
Now run&lt;br /&gt;
  yambo_nl -F Inputs_nl/01_td_ip.in -J TD-IP_nl -C TD-IP_nl&lt;br /&gt;
&lt;br /&gt;
The code produces different files (in the &amp;lt;code&amp;gt;TD-IP_nl&amp;lt;/code&amp;gt; directory, all with the suffix &amp;lt;code&amp;gt;TD-IP_nl&amp;lt;/code&amp;gt;: &amp;lt;code&amp;gt;o.polarization_F1&amp;lt;/code&amp;gt; that contains the polarization, &amp;lt;code&amp;gt;o.external_potential_F1&amp;lt;/code&amp;gt; the external field we used, and finally &amp;lt;code&amp;gt;r_optics_nloptics&amp;lt;/code&amp;gt; a report with all information about the simulation.&lt;br /&gt;
The simulation takes longer than the density-matrix counterpart. This is the price to pay for computing the polarization as a Berry Phase. While there is no gain for calculating the linear response, this allows computing nonlinear coefficients, which cannot be obtained within the density based approach. Have a look at the time profile of the run towards the end of the  &amp;lt;code&amp;gt;r_optics_nloptics&amp;lt;/code&amp;gt; (absolute time may differ):&lt;br /&gt;
 NL Berry Pol NEQ :      2.2409s CPU ( 5502 calls,   0.000 sec avg)&lt;br /&gt;
 io_WF :      3.8788s CPU (  757 calls,   0.005 sec avg)&lt;br /&gt;
 DIPOLE_overlaps :      4.1834s CPU&lt;br /&gt;
 DIPOLE_buil_covariants :      5.5611s CPU&lt;br /&gt;
 Dipoles :      7.3264s CPU&lt;br /&gt;
Most of the time is spent computing the covariant dipoles and the non-equilibrium Berry Polarization, which involves the inversion of small matrices via the Lapack inversion routine.&lt;br /&gt;
Some time is also required by the integrator &amp;lt;code&amp;gt;NL_Integrator&amp;lt;/code&amp;gt; of the equation of motion inversion, which is coded via the solution of a linear system of equations as implemented in the Lapack library. This integrator is more accurate than the Runge-Kutta 2nd order employed for the corresponding calculation within the density matrix formalism. &lt;br /&gt;
&lt;br /&gt;
Plot the third column of &amp;lt;code&amp;gt;o-TD-IP_nl.polarization_F1&amp;lt;/code&amp;gt; versus the first one (time-variable) to get the time-dependent polarization along the y-direction:&lt;br /&gt;
 gnuplot&amp;gt; p &#039;TD-IP_nl/o-TD-IP_nl.polarization_F1&#039; u 1:3 w l&lt;br /&gt;
&lt;br /&gt;
[[File:Bn polarization.png|thumb|center|900px|Real-time polarization in the y-direction]]&lt;br /&gt;
&lt;br /&gt;
For comparison, in the figure above, the polarization is obtained either through the Bloch-states or the density-matrix.&lt;br /&gt;
There are few differences which could be due to the following reasons:&lt;br /&gt;
* Coupling with the external field: the &amp;lt;code&amp;gt;yambo_rt&amp;lt;/code&amp;gt; evaluates the coupling with the external field through the dipoles (by default computing the commutator [x,Hnl]; the &amp;lt;code&amp;gt;yambo_nl&amp;lt;/code&amp;gt; evaluates the coupling using an expression based on the Berry Phase. For the latter, a numerical differentiation in reciprocal space is performed. The 10x10 2D k-mesh may not be fine enough. For denser k-mesh, the Berry phase approach converges to the one based on the dipoles. To avoid this one can use &amp;lt;code&amp;gt;DipApproach=&amp;quot;Covariant&amp;quot;&amp;lt;/code&amp;gt; in the scheme used by yambo_rt.     &lt;br /&gt;
* Integrator: the integrator used for the &amp;lt;code&amp;gt;yambo_nl&amp;lt;/code&amp;gt; is more accurate. The fact that the differences are more pronounced for long times may hint to inaccuracies in the integration of the equation of motions in &amp;lt;code&amp;gt;yambo_rt&amp;lt;/code&amp;gt;. One can use a similar integrator with yambo_rt, by setting in input &amp;lt;code&amp;gt;Integrator= &amp;quot;INV RK2&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Output postprocessing: the dielectric function ==&lt;br /&gt;
&lt;br /&gt;
Once we obtained the polarization, we Fourier transform the polarization to obtain the dielectric function.&lt;br /&gt;
&lt;br /&gt;
Use the command:&lt;br /&gt;
&lt;br /&gt;
  ypp_nl -nl -F Inputs_nl/ypp_abs.in&lt;br /&gt;
&lt;br /&gt;
to generate the input file:&lt;br /&gt;
&lt;br /&gt;
 nonlinear                    # [R] NonLinear Optics Post-Processing&lt;br /&gt;
 Xorder= 1                    # Max order of the response 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;1001&amp;lt;/span&amp;gt;                # Total Energy steps&lt;br /&gt;
 % EnRngeRt&lt;br /&gt;
   0.00000 | &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;10.00000&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;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.10000&amp;lt;/span&amp;gt;   eV    # Damping parameter&lt;br /&gt;
&lt;br /&gt;
          &lt;br /&gt;
where we set a Lorentzian smearing corresponding to 0.1 eV. Note that due to the finite time of our simulation, we need to introduce a finite smearing to Fourier transform the result.&lt;br /&gt;
&lt;br /&gt;
To run the post-processing, use the command:&lt;br /&gt;
 ypp_nl -F Inputs_nl/ypp_abs.in -J TD-IP_nl -C TD-IP_nl &lt;br /&gt;
and obtain the files for the dielectric constant along with the field direction, the EELS along with the same direction, and the damped polarization.&lt;br /&gt;
 o-TD-IP_nl.YPP-eps_along_E&lt;br /&gt;
 o-TD-IP_nl.YPP-eels_along_E&lt;br /&gt;
 o-TD-IP_nl.YPP-damped_polarization&lt;br /&gt;
inside the folder &amp;lt;code&amp;gt;TD-IP_nl&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Plot the dielectric constant and compare it with the linear response and the density-matrix formalism (available from the [[Real time approach to linear response]] tutorial):&lt;br /&gt;
 gnuplot&lt;br /&gt;
 plot &amp;quot;CHI_IP/o-CHI_IP.eps_q1_ip&amp;quot; u 1:2 w l&lt;br /&gt;
 rep &amp;quot;TD-IP_rt/o-TD-IP_rt.YPP-eps_along_E&amp;quot; u 1:2 w l&lt;br /&gt;
 rep &amp;quot;TD-IP_nl/o-TD-IP_nl.YPP-eps_along_E&amp;quot; u 1:2 w l&lt;br /&gt;
&lt;br /&gt;
[[File:Bn optics.png|thumb|900px|center|Imaginary part of the dielectric constant]]&lt;br /&gt;
&lt;br /&gt;
The differences observed with the spectra obtained from either the density-matrix and linear-response formalisms are due to how the dipoles are evaluated. Within the density-matrix and linear-response formalisms, dipoles are computed in the same way. The Bloch-states formalism uses instead covariant dipoles evaluated numerically on the k-mesh. The differences are due to numerical errors in evaluating the covariant dipoles. These differences disappear with a denser k-mesh. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;It is a good practice to converge the dielectric function obtained from the Bloch-state dynamics with respect to the k-points using the linear-response spectrum as a reference. This gives the minimum number of k-points to be used to obtain accurate results.         &lt;br /&gt;
&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
= Step 3: Hartree+Screened exchange approximation =&lt;br /&gt;
&lt;br /&gt;
== Evaluating the collisions==&lt;br /&gt;
&lt;br /&gt;
The evaluation of the collisions. (see [[Introduction to Real Time propagation in Yambo]] to remember what are the collisions)&lt;br /&gt;
This part is common in between the &amp;lt;code&amp;gt;yambo_nl&amp;lt;/code&amp;gt; and the &amp;lt;code&amp;gt;yambo_rt&amp;lt;/code&amp;gt;. If you have computed the collisions for the corresponding &amp;lt;code&amp;gt;yambo_rt&amp;lt;/code&amp;gt;, you can re-used those results. If not, follow the related steps in [[Real time Bethe-Salpeter Equation (density matrix only)#The_Real_Time_Collisions| the real-time BSE tutorial]].&lt;br /&gt;
&lt;br /&gt;
== Run the simulations ==&lt;br /&gt;
To generate the input for the real-time simulation you can run&lt;br /&gt;
 yambo_nl -nl n -V qp -F Inputs_nl/04_td-sex.in&lt;br /&gt;
&lt;br /&gt;
The input file is&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; 4 |  5 | &amp;lt;/span&amp;gt;                    # [NL] Bands&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;20.00000&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;&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;SEX&amp;lt;/span&amp;gt;&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;
 % NLEnRange&lt;br /&gt;
  -1.000000 | -1.000000 | eV      # [NL] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 NLEnSteps= 1                   # [NL] Energy steps&lt;br /&gt;
 NLDamping=  &amp;quot;&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;0.10000&amp;lt;/span&amp;gt;    eV      # [NL] Damping&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= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;1000         mHa&amp;lt;/span&amp;gt;     # [HA] Hartree     RL components&lt;br /&gt;
 EXXRLvcs= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;1000         mHa&amp;lt;/span&amp;gt;     # [XX] Exchange    RL components&lt;br /&gt;
&lt;br /&gt;
The next section of the input is about external quasiparticle corrections (&amp;lt;code&amp;gt;EXTQP G&amp;lt;/code&amp;gt;). There change only &lt;br /&gt;
&lt;br /&gt;
 % GfnQP_E&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;3.000000 &amp;lt;/span&amp;gt;| 1.000000 | 1.000000 |        # [EXTQP G] E parameters  (c/v) eV|adim|adim&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
The latter line introduces a scissor operator (a rigid shift of the conduction bands) of 3.0 eV. In principle, it is possible to perform a G&amp;lt;sub&amp;gt;0&amp;lt;/sub&amp;gt;W&amp;lt;sub&amp;gt;0&amp;lt;/sub&amp;gt; calculation with Yambo and use the Quasi-particle band structure instead of the rigid shift.&lt;br /&gt;
&lt;br /&gt;
The last section regards the applied field (&amp;lt;code&amp;gt;RT Field1&amp;lt;/code&amp;gt;). There change these two lines:   &lt;br /&gt;
&lt;br /&gt;
 % Field1_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 Field1] Versor&lt;br /&gt;
 %&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|SOFTSIN|RES|ANTIRES|GAUSS|DELTA|QSSIN)&lt;br /&gt;
 &lt;br /&gt;
Run the calculation:&lt;br /&gt;
&lt;br /&gt;
 nohup yambo_nl -F Inputs_nl/04_td_sex.in -J &amp;quot;TD-SEX_nl,COLL_HSEX&amp;quot; -C TD-SEX_nl&lt;br /&gt;
&lt;br /&gt;
== Output postprocessing: dielectric function ==&lt;br /&gt;
&lt;br /&gt;
The post-processing of the output does not depend on the level of approximation. The same steps are taken as in the independent-particle approximation.&lt;br /&gt;
&lt;br /&gt;
Use the command:&lt;br /&gt;
 ypp_nl -F Inputs_nl/ypp_abs.in -J TD-SEX_nl -C TD-SEX_nl&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Plot the results (compare with results obtained from the density-matrix formalism):&lt;br /&gt;
 gnuplot&amp;gt; set xrange [3:10]&lt;br /&gt;
 gnuplot&amp;gt; set yrange [0:12]&lt;br /&gt;
 gnuplot&amp;gt; plot &amp;quot;TD-SEX_rt/o-TD-SEX_rt.YPP-eps_along_E&amp;quot; u 1:2 w l&lt;br /&gt;
 gnuplot&amp;gt; rep &amp;quot;TD-SEX_nl/o-TD-SEX_nl.YPP-eps_along_E&amp;quot; u 1:2 w l&lt;br /&gt;
 gnuplot&amp;gt; rep &amp;quot;TD-IP_rt/o-TD-IP_rt.YPP-eps_along_E&amp;quot; u ($1+3):2 w l &lt;br /&gt;
&lt;br /&gt;
[[File:HBN HSEX absorption.png|thumb|900px|center|In plane absorption of hBN at the TD-HSEX level compared with IP absorption]]&lt;br /&gt;
&lt;br /&gt;
Similarly to what we have seen in the independent-particle case, the differences between the two approaches are due to the accuracy in evaluating numerically the covariant dipoles in the Bloch-state dynamics approach. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;For comparison, the linear response results at the BSE level can be obtained following the [[How to obtain an optical spectrum|BSE tutorial]]. &#039;&#039;&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Fulvio</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Second-harmonic_generation_of_2D-hBN&amp;diff=6992</id>
		<title>Second-harmonic generation of 2D-hBN</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Second-harmonic_generation_of_2D-hBN&amp;diff=6992"/>
		<updated>2023-05-25T08:26:25Z</updated>

		<summary type="html">&lt;p&gt;Fulvio: /* Step 1: Prerequisites */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Step 0: Theoretical framework =&lt;br /&gt;
&lt;br /&gt;
In this tutorial, we compute the Second-harmonic generation (SHG) from the dynamics of the Bloch-states. The equation-of-motion of the Bloch-states is explained in the tutorial on [[Linear response from Bloch-states dynamics]]. Independently of the &#039;experiment&#039; we simulate, the part of the integration of motion stays the same. This means that any experiment, including non-linear optics, can be performed at the level of the theory listed for the computation of the dielectric function:&lt;br /&gt;
* independent (quasi)particle&lt;br /&gt;
* time-dependent Hartree (RPA level)&lt;br /&gt;
* time-dependent DFT (and DPFT)&lt;br /&gt;
* time-dependent Hartree+Screened exchange (BSE level)&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
What changes when we want to calculate the SHG (or higher harmonics) is:&lt;br /&gt;
* the time-dependence of the input electric field and&lt;br /&gt;
* the post-processing of the signal  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Time dependence of the electric Field&#039;&#039;&#039;: we choose a sinusoidal electric field, thus a monochromatic laser field. This allows one to expand the polarization in the form &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; through a coefficient depending on a power of the strength of the field (with the power depending on the order of the response).&lt;br /&gt;
&lt;br /&gt;
At difference with a delta-like perturbation, a real-time simulation gives the response at the laser-field only. Then, to obtain the spectrum for the desired range of frequency, we have to perform so many simulations as the frequencies in the desired range.  &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Post-processing of the signal&#039;&#039;&#039;: The switch-on of the electric field corresponds to a weak delta-like kick. Thus, even if it may not be noticeable, the polarization results from both the sinusoidal field and the delta-like kick. The latter excites all eigenfrequencies of the system. Though weak, the resulting signal is comparable with the second-harmonic signal. To eliminate the signal from the eigenfrequencies, we apply a dephasing (&amp;lt;math&amp;gt;\gamma_{deph}&amp;lt;/math&amp;gt;). To have a signal useful to sample the second-harmonic signal, we need to wait a time &amp;lt;math&amp;gt;\bar t&amp;lt;/math&amp;gt;  much larger than the dephasing-time &amp;lt;math&amp;gt;1/\gamma_{deph} &amp;lt;/math&amp;gt;. Note that we cannot choose a too short dephasing time (to shorten the simulation time), as this would result in a too large broadening of the spectrum. After &amp;lt;math&amp;gt;\bar t&amp;lt;/math&amp;gt;, we sample $2N+1$ times in a period and use discrete Fourier transform to extract &amp;lt;math&amp;gt;{p}_n&amp;lt;/math&amp;gt; for &amp;lt;math&amp;gt; n = 0,...,N&amp;lt;/math&amp;gt;, where n=2 gives the SHG. This is schematically illustrated in figure:&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;
The scheme from Ref. &amp;lt;ref name=&amp;quot;Attaccalite2013&amp;quot;&amp;gt;C. Attaccalite and M. Gruning [https://arxiv.org/abs/1309.4012v2 Rev. B, &#039;&#039;&#039;88&#039;&#039;&#039;, 235113 (2013)]&amp;lt;/ref&amp;gt; summarised the workflow for computing the SHG (or higher-harmonics) in a energy range &amp;lt;math&amp;gt;[\Omega_1,\Omega_2]&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
[[File:Scheme nl.png|350px|center|Schematic representation of real-time calculations]]&lt;br /&gt;
&lt;br /&gt;
= Step 1: Prerequisites =&lt;br /&gt;
&lt;br /&gt;
In this example, we will consider a single layer of hexagonal boron nitride (hBN). Before running real time simulations to compute the SHG in &amp;lt;code&amp;gt;yambo&amp;lt;/code&amp;gt; you need to download input files and Yambo databases for this tutorial here: [https://media.yambo-code.eu/educational/tutorials/files/hBN-2D-RT.tar.gz hBN-2D-RT.tar.gz].&lt;br /&gt;
Unzip the tarball and change directory to &amp;lt;code&amp;gt;YAMBO&amp;lt;/code&amp;gt; and run the setup (&amp;lt;code&amp;gt;yambo_nl -nompi&amp;lt;/code&amp;gt;). &lt;br /&gt;
Execute the command &lt;br /&gt;
 ypp_nl -fixsym -F 00_removesym.in  &lt;br /&gt;
to create the input, to remove the symmetries which are not compatible with the field: &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;1.000000 | 1.000000 | 0.000000 |&amp;lt;/span&amp;gt;        # First external Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 % Efield2&lt;br /&gt;
  0.000000 | 0.000000 | 0.000000 |        # 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;
 #KeepKGrid                     # Do not expand the k-grid&lt;br /&gt;
where we chose the field along the xy direction and we remove time-reversal symmetry.&lt;br /&gt;
&lt;br /&gt;
Then run the pre-processing job:&lt;br /&gt;
 ypp_nl -F 00_removesym.in J 00_removesym&lt;br /&gt;
This creates the directory &amp;lt;code&amp;gt;FixSymm&amp;lt;/code&amp;gt;. Change directory to &amp;lt;code&amp;gt;FixSymm&amp;lt;/code&amp;gt;. This contains the &amp;lt;code&amp;gt;SAVE&amp;lt;/code&amp;gt; directory with reduced symmetries, compatible with the direction of the field.&lt;br /&gt;
&lt;br /&gt;
= Step 2: Independent-particle approximation =&lt;br /&gt;
&lt;br /&gt;
Use the command:&lt;br /&gt;
  yambo_nl -nl n -F 01_SHG_ip.in&lt;br /&gt;
to generate the input:&lt;br /&gt;
&lt;br /&gt;
 nloptics                         # [R] Non-linear spectroscopy&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=-1.000000           fs    # [NL] Simulation Time&lt;br /&gt;
 NLintegrator= &amp;quot;INVINT&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;
 % NLEnRange&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;0.5000000 |8.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;12&amp;lt;/span&amp;gt;                     # [NL] Energy steps&lt;br /&gt;
 NLDamping= 0.200000        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;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&amp;quot;SIN&amp;quot; &amp;lt;/span&amp;gt;          # [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 | 1.000000 | 0.000000 |&amp;lt;/span&amp;gt;        # [RT Field1] Versor&lt;br /&gt;
 %&lt;br /&gt;
 Field1_Tstart= 0.010000    fs    # [RT Field1] Initial Time&lt;br /&gt;
&lt;br /&gt;
To describe the Bloch-dynamics we will use as a basis the KS-states 3-6 for the k-grid used in the non-scf DFT calculations, that is a 6x6x1 (&amp;lt;code&amp;gt;NLBands&amp;lt;/code&amp;gt;). We choose 12 equally spaced frequencies (&amp;lt;code&amp;gt;NLEnSteps&amp;lt;/code&amp;gt;) for the applied field in the range  (&amp;lt;code&amp;gt;NLEnRange&amp;lt;/code&amp;gt;) between 0.5 and 8 eV. We choose a sinusoidal time-dependence (&amp;lt;code&amp;gt;Field1_kind&amp;lt;/code&amp;gt;) and set the field direction (&amp;lt;code&amp;gt;Field1_kind&amp;lt;/code&amp;gt;) along xy (in plane). The negative simulation time (&amp;lt;code&amp;gt;NLtime=-1.000000&amp;lt;/code&amp;gt;) means that the code will choose it based on the value of the &amp;lt;code&amp;gt;NLDamping&amp;lt;/code&amp;gt;. While this is a good lower bound for the simulation time, one should check it is sufficient to get accurate results. &lt;br /&gt;
&lt;br /&gt;
Run the simulation, possibly in parallel e. g. in a interactive session on 4 cores, execute the command:&lt;br /&gt;
  mpirun -n 4 yambo_nl -F 01_SHG_ip.in -J 01_SHG_ip -C 01_SHG_ip_files&lt;br /&gt;
&lt;br /&gt;
Once the run is finished, check the report &amp;lt;code&amp;gt;01_SHG_ip_files/r-01_SHG_ip_nloptics&amp;lt;/code&amp;gt;. In particular, in the appended input files, you can see the default parallelization applied by the code for calculating the dipoles and run the time-propagation. For the latter, the main parallelization is on the frequencies and then on the k-points (&amp;lt;code&amp;gt;NL_ROLEs= &amp;quot;w.k&amp;quot;&amp;lt;/code&amp;gt;).   &lt;br /&gt;
&lt;br /&gt;
 | NL_CPU= &amp;quot;2.2&amp;quot;                    # [PARALLEL] CPUs for each role&lt;br /&gt;
 | NL_ROLEs= &amp;quot;w.k&amp;quot;                  # [PARALLEL] CPUs roles (w,k)&lt;br /&gt;
 | DIP_CPU= &amp;quot;2.2.1&amp;quot;                 # [PARALLEL] CPUs for each role&lt;br /&gt;
 | DIP_ROLEs= &amp;quot;v.c.k&amp;quot;               # [PARALLEL] CPUs roles (k,c,v)&lt;br /&gt;
&lt;br /&gt;
Also, look at the simulation time. This is approximately 42 fs. &lt;br /&gt;
&lt;br /&gt;
Plot the polarization for a couple of frequencies, e.g. the first and last of the chosen range (the corresponding frequency can be read in the file, search for &amp;quot;Frequency value&amp;quot;):&lt;br /&gt;
 set ylabel &amp;quot;x-component polarization&amp;quot; offset -0.7&lt;br /&gt;
 set xlabel &amp;quot;time (fs)&amp;quot;&lt;br /&gt;
 plot &#039;01_SHG_ip_files/o-01_SHG_ip.polarization_F1&#039; u 1:2 w l lw 2 title &amp;quot;omega = 0.5 eV&amp;quot;&lt;br /&gt;
 replot &#039;01_SHG_ip_files/o-01_SHG_ip.polarization_F12&#039; u 1:2 w l lw 2  title &amp;quot;omega = 7.375 eV&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[File:Berry_phase_polarization_of_2D_h-BN_obtained_from_the_previous_run_for_two_laser_frequencies.png|Berry_phase_polarization_of_2D_h-BN_obtained from the run for two laser frequencies]]&lt;br /&gt;
&lt;br /&gt;
After the applied field is &#039;switched on&#039;, the polarization is oscillating at the frequency of the applied field and at the eigenfrequencies of the system as described above in the cartoon. This is visible particularly for the higher frequency. Due to the dephasing, after about 20 fs the polarization is oscillating (at least to the eye) at the frequency of the applied field. Nonlinear components are not visible since they are several orders of magnitude smaller than the first order.&lt;br /&gt;
&lt;br /&gt;
== Output post-processing: the dielectric function ==&lt;br /&gt;
&lt;br /&gt;
Once we obtained the polarization, we Fourier-transform the polarization to obtain the dielectric function.&lt;br /&gt;
&lt;br /&gt;
Use the command:&lt;br /&gt;
&lt;br /&gt;
  ypp_nl -nl -F 02_SHG_ip_pp.in -C 01_SHG_ip_files&lt;br /&gt;
&lt;br /&gt;
to generate the input file: &lt;br /&gt;
&lt;br /&gt;
 nonlinear                        # [R] Non-linear response analysis&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:red&amp;quot;Xorder= 4&amp;lt;/span&amp;gt; # 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;NONE&amp;quot;                 # Damping type ( NONE | LORENTZIAN | GAUSSIAN )&lt;br /&gt;
 DampFactor= 0.000000       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;
Where we changed the &amp;lt;code&amp;gt;Xorder&amp;lt;/code&amp;gt; to 4. This variable controls the terms in the Fourier expansion of the polarization. We choose up to expand up to the fourth order. This should ensure the second order to be accurate enough. As an exercise, you can change this value (e.g. choose 2,3,5,6) and see how the result below is changing. The time-window where processing is done is chosen automatically, since values are negative. The code chooses by default the last period to carry out the analysis. &lt;br /&gt;
&lt;br /&gt;
To run the post-processing, use the command:&lt;br /&gt;
 ypp_nl -F Inputs_shg/ypp_shg.in -J TD-IP_nl -C TD-IP_nl. &lt;br /&gt;
   &lt;br /&gt;
In  &amp;lt;code&amp;gt;01_SHG_ip_files&amp;lt;/code&amp;gt; the following files were generated &lt;br /&gt;
 o-01_SHG_ip.YPP-X_probe_order_1&lt;br /&gt;
 o-01_SHG_ip.YPP-X_probe_order_2&lt;br /&gt;
 o-01_SHG_ip.YPP-X_probe_order_3&lt;br /&gt;
 o-01_SHG_ip.YPP-X_probe_order_4&lt;br /&gt;
 r-01_SHG_ip_nonlinear&lt;br /&gt;
&lt;br /&gt;
The output files contain respectively the first, second, third and fourth order response(corresponding to &amp;lt;code&amp;gt;Xorder=4&amp;lt;/code&amp;gt;)  at the 12 frequencies in the chosen range. &lt;br /&gt;
 &lt;br /&gt;
Inspect &amp;lt;code&amp;gt;o-01_SHG_ip.YPP-X_probe_order_2&amp;lt;/code&amp;gt;&lt;br /&gt;
 #     E [eV]            X/Im[cm/stV](x)    X/Re[cm/stV](x)    X/Im[cm/stV](y)    X/Re[cm/stV](y)    X/Im[cm/stV](z)    X/Re[cm/stV](z)&lt;br /&gt;
 #&lt;br /&gt;
      0.50000000        -0.35378838E-09    -0.19774796E-07     0.23591828E-09    -0.89405637E-09      0.0000000          0.0000000    &lt;br /&gt;
      1.1250000         -0.19356524E-08    -0.23160605E-07    -0.16052184E-09    -0.67662771E-09      0.0000000          0.0000000    &lt;br /&gt;
      1.7500000         -0.69446459E-08    -0.35586956E-07    -0.76025706E-09    -0.10205678E-08      0.0000000          0.0000000    &lt;br /&gt;
      2.37500000        -0.181606152E-7    -0.261823658E-8     0.438358596E-8     0.407915226E-8      0.00000000         0.00000000   &lt;br /&gt;
&lt;br /&gt;
The first column are the frequencies of the applied field, the second and third is the polarization along x (imaginary and real part), the fourth and fifth is the polarization along y (imaginary and real part)  &lt;br /&gt;
and the sixth and seventh is the polarization along z (imaginary and real part).&lt;br /&gt;
&lt;br /&gt;
Plot the absolute value of the SHG for the &amp;quot;xxy&amp;quot; component (that is, the applied field is in the x and y directions and one look at the polarization along x):&lt;br /&gt;
&lt;br /&gt;
 set ylabel &amp;quot;{/Symbol=26 \174}{/Symbol=26 c}_{xyx}^{(2)}{/Symbol=26 \174} (pm/V)&amp;quot; offset -0.7&lt;br /&gt;
 set xlabel &amp;quot;Energy (eV)&amp;quot;&lt;br /&gt;
 pmVm1toCGS=2.38721e-09&lt;br /&gt;
 plot &#039;01_SHG_ip_files/o-01_SHG_ip.YPP-X_probe_order_2&#039; u 1:(sqrt($2**2+$3**2)/pmVm1toCGS) w p title &amp;quot;calc&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[File: SHG_intensity_of_2D_h-BN_obtained_from_the_previous_run_(and_compared_with_a_run_on_112_frequencies).png | SHG_intensity_of_2D_h-BN obtained from the current run (12 frequencies) compared with a run with 112 frequencies]] &lt;br /&gt;
&lt;br /&gt;
In the figure above, the results of the current run are compared with those for a run with 112 frequencies (one can obtain these results by repeating the calculations, changing the number of frequencies in &amp;lt;code&amp;gt;NLEnSteps&amp;lt;/code&amp;gt; though this take about 10 times more computational time than the run with 12). One can notice some differences between the two runs. In fact, the two runs evaluate different frequnecies and the difference indicates spurious oscillations of the value of the polarizability due to the simulation time being too short and thus to the presence of &#039;noise&#039; due to the eigenfrecies.  &lt;br /&gt;
As an exercise, you can repeat the simulation for e,g, a time of &amp;lt;code&amp;gt;60 fs&amp;lt;/code&amp;gt;, that is setting &amp;lt;code&amp;gt;NLtime=60&amp;lt;/code&amp;gt;. The plot below compare the SHG extracted at 42 fs and 60 fs, where the latter gives clearly more accurate results. &lt;br /&gt;
&lt;br /&gt;
[[File:Comparison of the SHG intensity of 2D h-BN obtained with different simulation time.png|Comparison of the SHG intensity of 2D h-BN obtained with different simulation time]]&lt;br /&gt;
&lt;br /&gt;
As a final note, the SHG depends on the size of the vacuum added in the supercell. Instead, one should consider the surface SHG which obtained by considering an effective thickness for the layer. This is usually chosen to be similar to the layer separation in the bulk counterpart.&lt;br /&gt;
&lt;br /&gt;
= Step 3: Hartree+Screened exchange approximation (BSE level) =&lt;br /&gt;
&lt;br /&gt;
== Hartree+Screened exchange collisions ==&lt;br /&gt;
Similarly to the linear part, one needs to generate the Screened exchange collisions. The procedure is exactly the same.&lt;br /&gt;
&lt;br /&gt;
Create the input:&lt;br /&gt;
 yambo_nl -X s -e -v hsex -F 03_coll_hsex.in&lt;br /&gt;
modify the input ad follows&lt;br /&gt;
 em1s                             # [R][Xs] Statically Screened Interaction&lt;br /&gt;
 collisions                       # [R] Collisions&lt;br /&gt;
 dipoles                          # [R] Oscillator strenghts (or dipoles)&lt;br /&gt;
 Chimod= &amp;quot;HARTREE&amp;quot;                # [X] IP/Hartree/ALDA/LRC/PF/BSfxc&lt;br /&gt;
 % BndsRnXs&lt;br /&gt;
    1 |  20 |                         # [Xs] Polarization function bands&lt;br /&gt;
 %&lt;br /&gt;
 NGsBlkXs= 1000 mHa    # [Xs] Response block size&lt;br /&gt;
 % LongDrXs&lt;br /&gt;
  1.000000 | 1.000000 | 0.000000 |        # [Xs] [cc] Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 % COLLBands&lt;br /&gt;
    4 |  5 |                         # [COLL] Bands for the collisions&lt;br /&gt;
 %&lt;br /&gt;
 HXC_Potential= &amp;quot;SEX+HARTREE&amp;quot;     # [SC] SC HXC Potential&lt;br /&gt;
 HARRLvcs= 1000 mHa    # [HA] Hartree     RL components&lt;br /&gt;
 EXXRLvcs= 1000 mHa    # [XX] Exchange    RL components&lt;br /&gt;
 CORRLvcs= 1000 mHa    # [GW] Correlation RL components&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Calculate the collisions (you may want to run in parallel):&lt;br /&gt;
 yambo_nl -F 03_coll_hsex.in -J 03_coll -C 04_hsex_files&lt;br /&gt;
&lt;br /&gt;
== Run the simulation ==&lt;br /&gt;
&lt;br /&gt;
Create the input:&lt;br /&gt;
 yambo_nl -nl n -v hsex -V qp -F 04_SHG_hsex.in&lt;br /&gt;
&lt;br /&gt;
modify the following parts of the input (by this time all the innput variables should be known from the previous exercises):&lt;br /&gt;
&lt;br /&gt;
 % BndsRnXs&lt;br /&gt;
   1 |  20 |                         # [Xs] Polarization function bands&lt;br /&gt;
 %&lt;br /&gt;
 NGsBlkXs= 1000 mHa    # [Xs] Response block size&lt;br /&gt;
 % LongDrXs&lt;br /&gt;
  1.000000 | 1.000000 | 0.000000 |        # [Xs] [cc] Electric Field&lt;br /&gt;
 %&lt;br /&gt;
 % NLBands&lt;br /&gt;
    4 |  5 |                         # [NL] Bands range&lt;br /&gt;
 %&lt;br /&gt;
&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;SEX&amp;quot;             # [NL] Correlation (&amp;quot;IPA/HARTREE/TDDFT/LRC/LRW/JGM/SEX&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
 % NLEnRange&lt;br /&gt;
  0.500000 |8.000000 |         eV    # [NL] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 NLEnSteps= 12                   # [NL] Energy steps&lt;br /&gt;
&lt;br /&gt;
 % GfnQP_E&lt;br /&gt;
  3.000000 | 1.000000 | 1.000000 |        # [EXTQP G] E parameters  (c/v) eV|adim|adim&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
 Field1_kind= &amp;quot;SIN&amp;quot;           # [RT Field1] Kind(SIN|COS|RES|ANTIRES|GAUSS|DELTA|QSSIN)&lt;br /&gt;
&lt;br /&gt;
 % Field1_Dir&lt;br /&gt;
  1.000000 | 1.000000 | 0.000000 |        # [RT Field1] Versor&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
Then run the simulation using e.g. mpi and 4 cores:&lt;br /&gt;
 mpirun -n 4 yambo_nl -F 04_SHG_hsex.in -J 04_SHG_hsex,03_coll -C 04_SHG_hsex_files&lt;br /&gt;
&lt;br /&gt;
== Postprocessing: obtain the nonlinear response ==&lt;br /&gt;
&lt;br /&gt;
Similarly to what we did for the independent particle case, we create the input:&lt;br /&gt;
 ypp_nl -nl -F 05_SHG_hsex_pp.in&lt;br /&gt;
 &lt;br /&gt;
we change &amp;lt;code&amp;gt;Xorder = 4 &amp;lt;/code&amp;gt; and then run:&lt;br /&gt;
 ypp_nl -F 05_SHG_hsex_pp.in -J 04_SHG_hsex -C 04_hsex_files&lt;br /&gt;
&lt;br /&gt;
Then we plot (as before we compare with a simulation ran for 112 frequnecies).&lt;br /&gt;
&lt;br /&gt;
Plot the results:&lt;br /&gt;
&lt;br /&gt;
 set ylabel &amp;quot;{/Symbol=26 \174}{/Symbol=26 c}_{xyx}^{(2)}{/Symbol=26 \174} (pm/V)&amp;quot; offset -0.7&lt;br /&gt;
 set xlabel &amp;quot;Energy (eV)&amp;quot;&lt;br /&gt;
 pmVm1toCGS=2.38721e-09&lt;br /&gt;
 plot &#039;04_hsex_files/o-04_SHG_hsex.YPP-X_probe_order_2&#039; u 1:(sqrt($2**2+$3**2)/pmVm1toCGS) w p title &amp;quot;calc&amp;quot;&lt;br /&gt;
&lt;br /&gt;
[[File:SHG hsex.png|SHG at the Hartree + Screened exchange from current run with 12 frequencies (crosses) and a run with 112 frequencies (keeping the other parameters the same)]]&lt;br /&gt;
&lt;br /&gt;
also in this case we note differences between the two simulations. This is due to the too short simulation time. Repeating the calculations with a longer time gives more accurate results. &lt;br /&gt;
In addition, note that in the interest of time, all parameters are underconverged. In principle, to calculate the collisions one should use the same parameters of a converged BSE calculation. As well, one should use the Coulomb cutoff as it was used for this system in the  BSE case.&lt;br /&gt;
&lt;br /&gt;
= References = &lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Fulvio</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Dielectric_function_from_Bloch-states_dynamics&amp;diff=6991</id>
		<title>Dielectric function from Bloch-states dynamics</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Dielectric_function_from_Bloch-states_dynamics&amp;diff=6991"/>
		<updated>2023-05-25T08:25:54Z</updated>

		<summary type="html">&lt;p&gt;Fulvio: /* Step 1: Prerequisites */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Step 0: Theoretical background =&lt;br /&gt;
&lt;br /&gt;
The dynamics of Bloch-states is found by integrating a set of Time Dependent Effective Schrödinger Equations (TD-ESEs). Effective means that an effective Hamiltonian is considered. We consider the many-body effective Hamiltonians seen in the [[Linear response from real time simulations]]. In addition, one can also consider effective Hamiltonians based on density-functional theory. The latter choice gives time-dependent density-functional theory.&lt;br /&gt;
&lt;br /&gt;
At difference with what seen in [[Linear response from real time simulations]], the coupling between electrons and the external field is described by means of the [http://www.theochem.unito.it/didattica/tec-comp_sdm/note1.pdf Modern Theory of Polarization]:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Tdse new.png|center|400px|Time-Dependent Schrödinger Equation]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Where  &amp;lt;math&amp;gt; | v_{i \mathbf{k}} \rangle &amp;lt;/math&amp;gt; are the time-dependent Bloch states (corresponding to the filled Bloch-states at zero-field), &amp;lt;math&amp;gt;\mathcal E(t)&amp;lt;/math&amp;gt; is the external field and the term &amp;lt;math&amp;gt; i e \partial k&amp;lt;/math&amp;gt; is the dipole operator consistent with periodic boundary condition. For more details on this last term, see Ref. &amp;lt;ref&amp;gt;I. Souza, J. Íñiguez, and D. Vanderbilt, [https://cfm.ehu.es/ivo/publications/souza_prb04.pdf PRB 69, 085106 (2004)]&amp;lt;/ref&amp;gt; and &amp;lt;ref name=&amp;quot;Attaccalite2013&amp;quot;&amp;gt;C. Attaccalite and M. Gruning [https://arxiv.org/abs/1309.4012v2 Rev. B, &#039;&#039;&#039;88&#039;&#039;&#039;, 235113 (2013)]&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;h_{rt}&amp;lt;/math&amp;gt; is the Hamiltonian,&lt;br /&gt;
[[File:H mb.png|400px|center|Many-Body Hamiltonian]].&lt;br /&gt;
This contains the equilibrium Hamiltonian, that is the zero-field eigenvalues evaluated through DFT; the quasiparticle corrections, evaluated from GW or estimated from experiment, and the variation of the self-energy. The latter is a functional of the density matrix &amp;lt;math&amp;gt;\rho&amp;lt;/math&amp;gt;, which is obtained from the Bloch states.   &lt;br /&gt;
&lt;br /&gt;
From the solution of the equation of motion for the Bloch states, the polarization is calculated by means of Berry&#039;s phase&lt;br /&gt;
&lt;br /&gt;
[[File:Berry polarization.png|center|350px|Berry&#039;s polarization]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
One can decide the level of theory by selecting the terms to include in the Hamiltonian:&lt;br /&gt;
&lt;br /&gt;
* by including only the first term, one selects the &#039;&#039;independent-particle approximation&#039;&#039;&lt;br /&gt;
* by including the first and second terms, one selects the &#039;&#039;independent-quasiparticle approximation&#039;&#039;&lt;br /&gt;
* by including the first, second terms and the Hartree part of the self-energy, one selects the &#039;&#039;time-dependent Hartree or random-phase approximation&#039;&#039;&lt;br /&gt;
* by including all terms, one selects the &#039;&#039;time-dependent Screened-exchange or Bethe-Salpeter equation&#039;&#039; level of theory.&lt;br /&gt;
&lt;br /&gt;
The type of &amp;quot;experiment&amp;quot; to perform, or of the response one would like to extract, depend on the time-dependent field in input and the post-processing of the Berry&#039;s phase polarization.  The induced polarization is the sum of the responses of the system to all orders in the external field:&lt;br /&gt;
&amp;lt;math&amp;gt;\bf{P}(t) = \sum_{n=-\infty}^{+\infty} \bf{P}_n (t) &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
In the case we are interested in linear response only, we use a delta-like electric field that excites all frequencies of the system. We choose the intensity of the field &amp;lt;math&amp;gt;E&amp;lt;/math&amp;gt; to be weak enough so that the response is dominated by the first order term. The response at all frequencies is obtained by taking the Fourier-transform of the polarization as&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \chi(\omega) = \frac{P(\omega)}{E} &amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
The response &amp;lt;math&amp;gt; \chi&amp;lt;/math&amp;gt;  is related to the dielectric function through the relation &amp;lt;math&amp;gt;\epsilon(\omega) = 1 + 4 \pi \chi(\omega) &amp;lt;/math&amp;gt;.&lt;br /&gt;
See also Ref. &amp;lt;ref name=&amp;quot;Attaccalite2013&amp;quot;&amp;gt;&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Notes: ==&lt;br /&gt;
* Length vs Velocity gauge: &#039;&#039;the equations of motion of Yambo are in the length gauge. Other codes choose instead to work in the velocity gauge. If you want to know more about the advantages and disadvantages of the two gauges read section 2.7 of Ref. &amp;lt;ref&amp;gt;C. Attaccalite, [https://arxiv.org/abs/1609.09639 arXiv 1609.09639 (2017)]&amp;lt;/ref&amp;gt;.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Advantages and disadvantages with respect to the density-matrix based formalism: &#039;&#039;Yambo implements two distinct formalisms for studying the real-time response, the one based on density-matrix and the one based on Boch states. Which formalism is best to use depends on what one wants to simulate. The dynamics formulation in terms of density matrix or non-equilibrium Green&#039;s functions allows a systematic treatment of correlation effects and electron-phonon coupling&amp;lt;ref name=&amp;quot;DavideEPL&amp;quot;&amp;gt;[https://arxiv.org/abs/1409.1706 D. Sangalli, and A. Marini EPL &#039;&#039;&#039;110&#039;&#039;&#039;, 47004 (2015)]&amp;lt;/ref&amp;gt;, but the price to pay is that the coupling with the external field is correct only to the linear order. This formalism is important in all those phenomena where electronic relaxation plays a major role.  On the other hand, the formulation in terms of the Bloch states treats coupling with the external field in an exact way even beyond the linear regime, and for this reason, it allows the description of phenomena coherent with the external fields and to access, for example, non-linear responses.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
= Step 1: Prerequisites =&lt;br /&gt;
In this example, we will consider a single layer of hexagonal boron nitride (hBN). Before running real time simulations in yambo you need to: &lt;br /&gt;
* download input files and Yambo databases for this tutorial here: [https://media.yambo-code.eu/educational/tutorials/files/hBN-2D-RT.tar.gz].&lt;br /&gt;
* perform the steps described in [[Prerequisites for Real Time propagation with Yambo]].&lt;br /&gt;
&lt;br /&gt;
= Step 2: Independent-particle approximation =&lt;br /&gt;
&lt;br /&gt;
Similar to what you have seen in the tutorial for the density matrix formalism ([[Real time approach to linear response]]) we start from the lowest level of theory. Here it is assumed you ran the tutorial on the density-matrix formalism and so you are familiar with the optical spectrum of 2D h-BN at this level of theory. You will recognise that the input and output for the Bloch-state formalism are very similar to those for the density-matrix formalism.&lt;br /&gt;
&lt;br /&gt;
== Run the simulations ==&lt;br /&gt;
First of all, create a directory for the inputs to be run by &amp;lt;code&amp;gt;yambo_nl&amp;lt;/code&amp;gt;:&lt;br /&gt;
 mkdir Inputs_nl&lt;br /&gt;
&lt;br /&gt;
Then, use the command:&lt;br /&gt;
  yambo_nl -nl n -F Inputs_nl/01_td_ip.in&lt;br /&gt;
&lt;br /&gt;
to generate the input:&lt;br /&gt;
 &lt;br /&gt;
 nloptics                         # [R] Non-linear spectroscopy&lt;br /&gt;
 % NLBands&lt;br /&gt;
   &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;3&amp;lt;/span&amp;gt; | &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;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;55.000000&amp;lt;/span&amp;gt;           fs    # [NL] Simulation Time&lt;br /&gt;
 NLintegrator= &amp;quot;INVINT&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;
 % NLEnRange&lt;br /&gt;
  -1.000000 |-1.000000 |      eV    # [NL] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 NLEnSteps= 1                     # [NL] Energy steps&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= 18475            RL    # [HA] Hartree     RL components&lt;br /&gt;
 EXXRLvcs= 18475            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;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&amp;quot;DELTA&amp;quot;&amp;lt;/span&amp;gt;           # [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 | &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;1.000000&amp;lt;/span&amp;gt; | 0.000000 |        # [RT Field1] Versor&lt;br /&gt;
 %&lt;br /&gt;
 Field1_Tstart= 0.010000    fs    # [RT Field1] Initial Time&lt;br /&gt;
        &lt;br /&gt;
Note that the standard input of &amp;lt;code&amp;gt;yambo_nl&amp;lt;/code&amp;gt; has default settings for nonlinear response (e.g. the &amp;lt;code&amp;gt;SOFTSIN&amp;lt;/code&amp;gt; for the &amp;lt;code&amp;gt;Field1_kind&amp;lt;/code&amp;gt; (that set the time-dependence &#039;kind&#039; of the field).&lt;br /&gt;
Set the field direction &amp;lt;code&amp;gt;Field1_Dir&amp;lt;/code&amp;gt; along y, the field kind to &amp;lt;code&amp;gt;DELTA&amp;lt;/code&amp;gt;, the length of the simulation &amp;lt;code&amp;gt;NLtime&amp;lt;/code&amp;gt; to 55 fs, select the bands from 3 to 6 (&amp;lt;code&amp;gt;NLBands&amp;lt;/code&amp;gt;) and set the &amp;lt;code&amp;gt;NLDamping&amp;lt;/code&amp;gt; to zero. The fields you need to change with respect to the default settings are shown above in red. &lt;br /&gt;
&lt;br /&gt;
Now run&lt;br /&gt;
  yambo_nl -F Inputs_nl/01_td_ip.in -J TD-IP_nl -C TD-IP_nl&lt;br /&gt;
&lt;br /&gt;
The code produces different files (in the &amp;lt;code&amp;gt;TD-IP_nl&amp;lt;/code&amp;gt; directory, all with the suffix &amp;lt;code&amp;gt;TD-IP_nl&amp;lt;/code&amp;gt;: &amp;lt;code&amp;gt;o.polarization_F1&amp;lt;/code&amp;gt; that contains the polarization, &amp;lt;code&amp;gt;o.external_potential_F1&amp;lt;/code&amp;gt; the external field we used, and finally &amp;lt;code&amp;gt;r_optics_nloptics&amp;lt;/code&amp;gt; a report with all information about the simulation.&lt;br /&gt;
The simulation takes longer than the density-matrix counterpart. This is the price to pay for computing the polarization as a Berry Phase. While there is no gain for calculating the linear response, this allows computing nonlinear coefficients, which cannot be obtained within the density based approach. Have a look at the time profile of the run towards the end of the  &amp;lt;code&amp;gt;r_optics_nloptics&amp;lt;/code&amp;gt; (absolute time may differ):&lt;br /&gt;
 NL Berry Pol NEQ :      2.2409s CPU ( 5502 calls,   0.000 sec avg)&lt;br /&gt;
 io_WF :      3.8788s CPU (  757 calls,   0.005 sec avg)&lt;br /&gt;
 DIPOLE_overlaps :      4.1834s CPU&lt;br /&gt;
 DIPOLE_buil_covariants :      5.5611s CPU&lt;br /&gt;
 Dipoles :      7.3264s CPU&lt;br /&gt;
Most of the time is spent computing the covariant dipoles and the non-equilibrium Berry Polarization, which involves the inversion of small matrices via the Lapack inversion routine.&lt;br /&gt;
Some time is also required by the integrator &amp;lt;code&amp;gt;NL_Integrator&amp;lt;/code&amp;gt; of the equation of motion inversion, which is coded via the solution of a linear system of equations as implemented in the Lapack library. This integrator is more accurate than the Runge-Kutta 2nd order employed for the corresponding calculation within the density matrix formalism. &lt;br /&gt;
&lt;br /&gt;
Plot the third column of &amp;lt;code&amp;gt;o-TD-IP_nl.polarization_F1&amp;lt;/code&amp;gt; versus the first one (time-variable) to get the time-dependent polarization along the y-direction:&lt;br /&gt;
 gnuplot&amp;gt; p &#039;TD-IP_nl/o-TD-IP_nl.polarization_F1&#039; u 1:3 w l&lt;br /&gt;
&lt;br /&gt;
[[File:Bn polarization.png|thumb|center|900px|Real-time polarization in the y-direction]]&lt;br /&gt;
&lt;br /&gt;
For comparison, in the figure above, the polarization is obtained either through the Bloch-states or the density-matrix.&lt;br /&gt;
There are few differences which could be due to the following reasons:&lt;br /&gt;
* Coupling with the external field: the &amp;lt;code&amp;gt;yambo_rt&amp;lt;/code&amp;gt; evaluates the coupling with the external field through the dipoles (by default computing the commutator [x,Hnl]; the &amp;lt;code&amp;gt;yambo_nl&amp;lt;/code&amp;gt; evaluates the coupling using an expression based on the Berry Phase. For the latter, a numerical differentiation in reciprocal space is performed. The 10x10 2D k-mesh may not be fine enough. For denser k-mesh, the Berry phase approach converges to the one based on the dipoles. To avoid this one can use &amp;lt;code&amp;gt;DipApproach=&amp;quot;Covariant&amp;quot;&amp;lt;/code&amp;gt; in the scheme used by yambo_rt.     &lt;br /&gt;
* Integrator: the integrator used for the &amp;lt;code&amp;gt;yambo_nl&amp;lt;/code&amp;gt; is more accurate. The fact that the differences are more pronounced for long times may hint to inaccuracies in the integration of the equation of motions in &amp;lt;code&amp;gt;yambo_rt&amp;lt;/code&amp;gt;. One can use a similar integrator with yambo_rt, by setting in input &amp;lt;code&amp;gt;Integrator= &amp;quot;INV RK2&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Output postprocessing: the dielectric function ==&lt;br /&gt;
&lt;br /&gt;
Once we obtained the polarization, we Fourier transform the polarization to obtain the dielectric function.&lt;br /&gt;
&lt;br /&gt;
Use the command:&lt;br /&gt;
&lt;br /&gt;
  ypp_nl -nl -F Inputs_nl/ypp_abs.in&lt;br /&gt;
&lt;br /&gt;
to generate the input file:&lt;br /&gt;
&lt;br /&gt;
 nonlinear                    # [R] NonLinear Optics Post-Processing&lt;br /&gt;
 Xorder= 1                    # Max order of the response 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;1001&amp;lt;/span&amp;gt;                # Total Energy steps&lt;br /&gt;
 % EnRngeRt&lt;br /&gt;
   0.00000 | &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;10.00000&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;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.10000&amp;lt;/span&amp;gt;   eV    # Damping parameter&lt;br /&gt;
&lt;br /&gt;
          &lt;br /&gt;
where we set a Lorentzian smearing corresponding to 0.1 eV. Note that due to the finite time of our simulation, we need to introduce a finite smearing to Fourier transform the result.&lt;br /&gt;
&lt;br /&gt;
To run the post-processing, use the command:&lt;br /&gt;
 ypp_nl -F Inputs_nl/ypp_abs.in -J TD-IP_nl -C TD-IP_nl &lt;br /&gt;
and obtain the files for the dielectric constant along with the field direction, the EELS along with the same direction, and the damped polarization.&lt;br /&gt;
 o-TD-IP_nl.YPP-eps_along_E&lt;br /&gt;
 o-TD-IP_nl.YPP-eels_along_E&lt;br /&gt;
 o-TD-IP_nl.YPP-damped_polarization&lt;br /&gt;
inside the folder &amp;lt;code&amp;gt;TD-IP_nl&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Plot the dielectric constant and compare it with the linear response and the density-matrix formalism (available from the [[Real time approach to linear response]] tutorial):&lt;br /&gt;
 gnuplot&lt;br /&gt;
 plot &amp;quot;CHI_IP/o-CHI_IP.eps_q1_ip&amp;quot; u 1:2 w l&lt;br /&gt;
 rep &amp;quot;TD-IP_rt/o-TD-IP_rt.YPP-eps_along_E&amp;quot; u 1:2 w l&lt;br /&gt;
 rep &amp;quot;TD-IP_nl/o-TD-IP_nl.YPP-eps_along_E&amp;quot; u 1:2 w l&lt;br /&gt;
&lt;br /&gt;
[[File:Bn optics.png|thumb|900px|center|Imaginary part of the dielectric constant]]&lt;br /&gt;
&lt;br /&gt;
The differences observed with the spectra obtained from either the density-matrix and linear-response formalisms are due to how the dipoles are evaluated. Within the density-matrix and linear-response formalisms, dipoles are computed in the same way. The Bloch-states formalism uses instead covariant dipoles evaluated numerically on the k-mesh. The differences are due to numerical errors in evaluating the covariant dipoles. These differences disappear with a denser k-mesh. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;It is a good practice to converge the dielectric function obtained from the Bloch-state dynamics with respect to the k-points using the linear-response spectrum as a reference. This gives the minimum number of k-points to be used to obtain accurate results.         &lt;br /&gt;
&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
= Step 3: Hartree+Screened exchange approximation =&lt;br /&gt;
&lt;br /&gt;
== Evaluating the collisions==&lt;br /&gt;
&lt;br /&gt;
The evaluation of the collisions. (see [[Introduction to Real Time propagation in Yambo]] to remember what are the collisions)&lt;br /&gt;
This part is common in between the &amp;lt;code&amp;gt;yambo_nl&amp;lt;/code&amp;gt; and the &amp;lt;code&amp;gt;yambo_rt&amp;lt;/code&amp;gt;. If you have computed the collisions for the corresponding &amp;lt;code&amp;gt;yambo_rt&amp;lt;/code&amp;gt;, you can re-used those results. If not, follow the related steps in [[Real time Bethe-Salpeter Equation (density matrix only)#The_Real_Time_Collisions| the real-time BSE tutorial]].&lt;br /&gt;
&lt;br /&gt;
== Run the simulations ==&lt;br /&gt;
To generate the input for the real-time simulation you can run&lt;br /&gt;
 yambo_nl -nl n -V qp -F Inputs_nl/04_td-sex.in&lt;br /&gt;
&lt;br /&gt;
The input file is&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; 4 |  5 | &amp;lt;/span&amp;gt;                    # [NL] Bands&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;20.00000&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;&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;SEX&amp;lt;/span&amp;gt;&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;
 % NLEnRange&lt;br /&gt;
  -1.000000 | -1.000000 | eV      # [NL] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 NLEnSteps= 1                   # [NL] Energy steps&lt;br /&gt;
 NLDamping=  &amp;quot;&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;0.10000&amp;lt;/span&amp;gt;    eV      # [NL] Damping&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= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;1000         mHa&amp;lt;/span&amp;gt;     # [HA] Hartree     RL components&lt;br /&gt;
 EXXRLvcs= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;1000         mHa&amp;lt;/span&amp;gt;     # [XX] Exchange    RL components&lt;br /&gt;
&lt;br /&gt;
The next section of the input is about external quasiparticle corrections (&amp;lt;code&amp;gt;EXTQP G&amp;lt;/code&amp;gt;). There change only &lt;br /&gt;
&lt;br /&gt;
 % GfnQP_E&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;3.000000 &amp;lt;/span&amp;gt;| 1.000000 | 1.000000 |        # [EXTQP G] E parameters  (c/v) eV|adim|adim&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
The latter line introduces a scissor operator (a rigid shift of the conduction bands) of 3.0 eV. In principle, it is possible to perform a G&amp;lt;sub&amp;gt;0&amp;lt;/sub&amp;gt;W&amp;lt;sub&amp;gt;0&amp;lt;/sub&amp;gt; calculation with Yambo and use the Quasi-particle band structure instead of the rigid shift.&lt;br /&gt;
&lt;br /&gt;
The last section regards the applied field (&amp;lt;code&amp;gt;RT Field1&amp;lt;/code&amp;gt;). There change these two lines:   &lt;br /&gt;
&lt;br /&gt;
 % Field1_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 Field1] Versor&lt;br /&gt;
 %&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|SOFTSIN|RES|ANTIRES|GAUSS|DELTA|QSSIN)&lt;br /&gt;
 &lt;br /&gt;
Run the calculation:&lt;br /&gt;
&lt;br /&gt;
 nohup yambo_nl -F Inputs_nl/04_td_sex.in -J &amp;quot;TD-SEX_nl,COLL_HSEX&amp;quot; -C TD-SEX_nl&lt;br /&gt;
&lt;br /&gt;
== Output postprocessing: dielectric function ==&lt;br /&gt;
&lt;br /&gt;
The post-processing of the output does not depend on the level of approximation. The same steps are taken as in the independent-particle approximation.&lt;br /&gt;
&lt;br /&gt;
Use the command:&lt;br /&gt;
 ypp_nl -F Inputs_nl/ypp_abs.in -J TD-SEX_nl -C TD-SEX_nl&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Plot the results (compare with results obtained from the density-matrix formalism):&lt;br /&gt;
 gnuplot&amp;gt; set xrange [3:10]&lt;br /&gt;
 gnuplot&amp;gt; set yrange [0:12]&lt;br /&gt;
 gnuplot&amp;gt; plot &amp;quot;TD-SEX_rt/o-TD-SEX_rt.YPP-eps_along_E&amp;quot; u 1:2 w l&lt;br /&gt;
 gnuplot&amp;gt; rep &amp;quot;TD-SEX_nl/o-TD-SEX_nl.YPP-eps_along_E&amp;quot; u 1:2 w l&lt;br /&gt;
 gnuplot&amp;gt; rep &amp;quot;TD-IP_rt/o-TD-IP_rt.YPP-eps_along_E&amp;quot; u ($1+3):2 w l &lt;br /&gt;
&lt;br /&gt;
[[File:HBN HSEX absorption.png|thumb|900px|center|In plane absorption of hBN at the TD-HSEX level compared with IP absorption]]&lt;br /&gt;
&lt;br /&gt;
Similarly to what we have seen in the independent-particle case, the differences between the two approaches are due to the accuracy in evaluating numerically the covariant dipoles in the Bloch-state dynamics approach. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;For comparison, the linear response results at the BSE level can be obtained following the [[How to obtain an optical spectrum|BSE tutorial]]. &#039;&#039;&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Fulvio</name></author>
	</entry>
	<entry>
		<id>https://wiki.yambo-code.eu/wiki/index.php?title=Dielectric_function_from_Bloch-states_dynamics&amp;diff=6990</id>
		<title>Dielectric function from Bloch-states dynamics</title>
		<link rel="alternate" type="text/html" href="https://wiki.yambo-code.eu/wiki/index.php?title=Dielectric_function_from_Bloch-states_dynamics&amp;diff=6990"/>
		<updated>2023-05-25T08:19:36Z</updated>

		<summary type="html">&lt;p&gt;Fulvio: /* Output postprocessing: dielectric function */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Step 0: Theoretical background =&lt;br /&gt;
&lt;br /&gt;
The dynamics of Bloch-states is found by integrating a set of Time Dependent Effective Schrödinger Equations (TD-ESEs). Effective means that an effective Hamiltonian is considered. We consider the many-body effective Hamiltonians seen in the [[Linear response from real time simulations]]. In addition, one can also consider effective Hamiltonians based on density-functional theory. The latter choice gives time-dependent density-functional theory.&lt;br /&gt;
&lt;br /&gt;
At difference with what seen in [[Linear response from real time simulations]], the coupling between electrons and the external field is described by means of the [http://www.theochem.unito.it/didattica/tec-comp_sdm/note1.pdf Modern Theory of Polarization]:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Tdse new.png|center|400px|Time-Dependent Schrödinger Equation]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Where  &amp;lt;math&amp;gt; | v_{i \mathbf{k}} \rangle &amp;lt;/math&amp;gt; are the time-dependent Bloch states (corresponding to the filled Bloch-states at zero-field), &amp;lt;math&amp;gt;\mathcal E(t)&amp;lt;/math&amp;gt; is the external field and the term &amp;lt;math&amp;gt; i e \partial k&amp;lt;/math&amp;gt; is the dipole operator consistent with periodic boundary condition. For more details on this last term, see Ref. &amp;lt;ref&amp;gt;I. Souza, J. Íñiguez, and D. Vanderbilt, [https://cfm.ehu.es/ivo/publications/souza_prb04.pdf PRB 69, 085106 (2004)]&amp;lt;/ref&amp;gt; and &amp;lt;ref name=&amp;quot;Attaccalite2013&amp;quot;&amp;gt;C. Attaccalite and M. Gruning [https://arxiv.org/abs/1309.4012v2 Rev. B, &#039;&#039;&#039;88&#039;&#039;&#039;, 235113 (2013)]&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;h_{rt}&amp;lt;/math&amp;gt; is the Hamiltonian,&lt;br /&gt;
[[File:H mb.png|400px|center|Many-Body Hamiltonian]].&lt;br /&gt;
This contains the equilibrium Hamiltonian, that is the zero-field eigenvalues evaluated through DFT; the quasiparticle corrections, evaluated from GW or estimated from experiment, and the variation of the self-energy. The latter is a functional of the density matrix &amp;lt;math&amp;gt;\rho&amp;lt;/math&amp;gt;, which is obtained from the Bloch states.   &lt;br /&gt;
&lt;br /&gt;
From the solution of the equation of motion for the Bloch states, the polarization is calculated by means of Berry&#039;s phase&lt;br /&gt;
&lt;br /&gt;
[[File:Berry polarization.png|center|350px|Berry&#039;s polarization]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
One can decide the level of theory by selecting the terms to include in the Hamiltonian:&lt;br /&gt;
&lt;br /&gt;
* by including only the first term, one selects the &#039;&#039;independent-particle approximation&#039;&#039;&lt;br /&gt;
* by including the first and second terms, one selects the &#039;&#039;independent-quasiparticle approximation&#039;&#039;&lt;br /&gt;
* by including the first, second terms and the Hartree part of the self-energy, one selects the &#039;&#039;time-dependent Hartree or random-phase approximation&#039;&#039;&lt;br /&gt;
* by including all terms, one selects the &#039;&#039;time-dependent Screened-exchange or Bethe-Salpeter equation&#039;&#039; level of theory.&lt;br /&gt;
&lt;br /&gt;
The type of &amp;quot;experiment&amp;quot; to perform, or of the response one would like to extract, depend on the time-dependent field in input and the post-processing of the Berry&#039;s phase polarization.  The induced polarization is the sum of the responses of the system to all orders in the external field:&lt;br /&gt;
&amp;lt;math&amp;gt;\bf{P}(t) = \sum_{n=-\infty}^{+\infty} \bf{P}_n (t) &amp;lt;/math&amp;gt; &lt;br /&gt;
&lt;br /&gt;
In the case we are interested in linear response only, we use a delta-like electric field that excites all frequencies of the system. We choose the intensity of the field &amp;lt;math&amp;gt;E&amp;lt;/math&amp;gt; to be weak enough so that the response is dominated by the first order term. The response at all frequencies is obtained by taking the Fourier-transform of the polarization as&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \chi(\omega) = \frac{P(\omega)}{E} &amp;lt;/math&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
The response &amp;lt;math&amp;gt; \chi&amp;lt;/math&amp;gt;  is related to the dielectric function through the relation &amp;lt;math&amp;gt;\epsilon(\omega) = 1 + 4 \pi \chi(\omega) &amp;lt;/math&amp;gt;.&lt;br /&gt;
See also Ref. &amp;lt;ref name=&amp;quot;Attaccalite2013&amp;quot;&amp;gt;&amp;lt;/ref&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Notes: ==&lt;br /&gt;
* Length vs Velocity gauge: &#039;&#039;the equations of motion of Yambo are in the length gauge. Other codes choose instead to work in the velocity gauge. If you want to know more about the advantages and disadvantages of the two gauges read section 2.7 of Ref. &amp;lt;ref&amp;gt;C. Attaccalite, [https://arxiv.org/abs/1609.09639 arXiv 1609.09639 (2017)]&amp;lt;/ref&amp;gt;.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
* Advantages and disadvantages with respect to the density-matrix based formalism: &#039;&#039;Yambo implements two distinct formalisms for studying the real-time response, the one based on density-matrix and the one based on Boch states. Which formalism is best to use depends on what one wants to simulate. The dynamics formulation in terms of density matrix or non-equilibrium Green&#039;s functions allows a systematic treatment of correlation effects and electron-phonon coupling&amp;lt;ref name=&amp;quot;DavideEPL&amp;quot;&amp;gt;[https://arxiv.org/abs/1409.1706 D. Sangalli, and A. Marini EPL &#039;&#039;&#039;110&#039;&#039;&#039;, 47004 (2015)]&amp;lt;/ref&amp;gt;, but the price to pay is that the coupling with the external field is correct only to the linear order. This formalism is important in all those phenomena where electronic relaxation plays a major role.  On the other hand, the formulation in terms of the Bloch states treats coupling with the external field in an exact way even beyond the linear regime, and for this reason, it allows the description of phenomena coherent with the external fields and to access, for example, non-linear responses.&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
= Step 1: Prerequisites =&lt;br /&gt;
In this example, we will consider a single layer of hexagonal boron nitride (hBN). Before running real time simulations in yambo you need to: &lt;br /&gt;
* download input files and Yambo databases for this tutorial here: [http://www.yambo-code.org/educational/tutorials/files/hBN-2D-RT.tar.gz hBN-2D-RT.tar.gz].&lt;br /&gt;
* perform the steps described in [[Prerequisites for Real Time propagation with Yambo]].&lt;br /&gt;
&lt;br /&gt;
= Step 2: Independent-particle approximation =&lt;br /&gt;
&lt;br /&gt;
Similar to what you have seen in the tutorial for the density matrix formalism ([[Real time approach to linear response]]) we start from the lowest level of theory. Here it is assumed you ran the tutorial on the density-matrix formalism and so you are familiar with the optical spectrum of 2D h-BN at this level of theory. You will recognise that the input and output for the Bloch-state formalism are very similar to those for the density-matrix formalism.&lt;br /&gt;
&lt;br /&gt;
== Run the simulations ==&lt;br /&gt;
First of all, create a directory for the inputs to be run by &amp;lt;code&amp;gt;yambo_nl&amp;lt;/code&amp;gt;:&lt;br /&gt;
 mkdir Inputs_nl&lt;br /&gt;
&lt;br /&gt;
Then, use the command:&lt;br /&gt;
  yambo_nl -nl n -F Inputs_nl/01_td_ip.in&lt;br /&gt;
&lt;br /&gt;
to generate the input:&lt;br /&gt;
 &lt;br /&gt;
 nloptics                         # [R] Non-linear spectroscopy&lt;br /&gt;
 % NLBands&lt;br /&gt;
   &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;3&amp;lt;/span&amp;gt; | &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;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;55.000000&amp;lt;/span&amp;gt;           fs    # [NL] Simulation Time&lt;br /&gt;
 NLintegrator= &amp;quot;INVINT&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;
 % NLEnRange&lt;br /&gt;
  -1.000000 |-1.000000 |      eV    # [NL] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 NLEnSteps= 1                     # [NL] Energy steps&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= 18475            RL    # [HA] Hartree     RL components&lt;br /&gt;
 EXXRLvcs= 18475            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;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;&amp;quot;DELTA&amp;quot;&amp;lt;/span&amp;gt;           # [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 | &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;1.000000&amp;lt;/span&amp;gt; | 0.000000 |        # [RT Field1] Versor&lt;br /&gt;
 %&lt;br /&gt;
 Field1_Tstart= 0.010000    fs    # [RT Field1] Initial Time&lt;br /&gt;
        &lt;br /&gt;
Note that the standard input of &amp;lt;code&amp;gt;yambo_nl&amp;lt;/code&amp;gt; has default settings for nonlinear response (e.g. the &amp;lt;code&amp;gt;SOFTSIN&amp;lt;/code&amp;gt; for the &amp;lt;code&amp;gt;Field1_kind&amp;lt;/code&amp;gt; (that set the time-dependence &#039;kind&#039; of the field).&lt;br /&gt;
Set the field direction &amp;lt;code&amp;gt;Field1_Dir&amp;lt;/code&amp;gt; along y, the field kind to &amp;lt;code&amp;gt;DELTA&amp;lt;/code&amp;gt;, the length of the simulation &amp;lt;code&amp;gt;NLtime&amp;lt;/code&amp;gt; to 55 fs, select the bands from 3 to 6 (&amp;lt;code&amp;gt;NLBands&amp;lt;/code&amp;gt;) and set the &amp;lt;code&amp;gt;NLDamping&amp;lt;/code&amp;gt; to zero. The fields you need to change with respect to the default settings are shown above in red. &lt;br /&gt;
&lt;br /&gt;
Now run&lt;br /&gt;
  yambo_nl -F Inputs_nl/01_td_ip.in -J TD-IP_nl -C TD-IP_nl&lt;br /&gt;
&lt;br /&gt;
The code produces different files (in the &amp;lt;code&amp;gt;TD-IP_nl&amp;lt;/code&amp;gt; directory, all with the suffix &amp;lt;code&amp;gt;TD-IP_nl&amp;lt;/code&amp;gt;: &amp;lt;code&amp;gt;o.polarization_F1&amp;lt;/code&amp;gt; that contains the polarization, &amp;lt;code&amp;gt;o.external_potential_F1&amp;lt;/code&amp;gt; the external field we used, and finally &amp;lt;code&amp;gt;r_optics_nloptics&amp;lt;/code&amp;gt; a report with all information about the simulation.&lt;br /&gt;
The simulation takes longer than the density-matrix counterpart. This is the price to pay for computing the polarization as a Berry Phase. While there is no gain for calculating the linear response, this allows computing nonlinear coefficients, which cannot be obtained within the density based approach. Have a look at the time profile of the run towards the end of the  &amp;lt;code&amp;gt;r_optics_nloptics&amp;lt;/code&amp;gt; (absolute time may differ):&lt;br /&gt;
 NL Berry Pol NEQ :      2.2409s CPU ( 5502 calls,   0.000 sec avg)&lt;br /&gt;
 io_WF :      3.8788s CPU (  757 calls,   0.005 sec avg)&lt;br /&gt;
 DIPOLE_overlaps :      4.1834s CPU&lt;br /&gt;
 DIPOLE_buil_covariants :      5.5611s CPU&lt;br /&gt;
 Dipoles :      7.3264s CPU&lt;br /&gt;
Most of the time is spent computing the covariant dipoles and the non-equilibrium Berry Polarization, which involves the inversion of small matrices via the Lapack inversion routine.&lt;br /&gt;
Some time is also required by the integrator &amp;lt;code&amp;gt;NL_Integrator&amp;lt;/code&amp;gt; of the equation of motion inversion, which is coded via the solution of a linear system of equations as implemented in the Lapack library. This integrator is more accurate than the Runge-Kutta 2nd order employed for the corresponding calculation within the density matrix formalism. &lt;br /&gt;
&lt;br /&gt;
Plot the third column of &amp;lt;code&amp;gt;o-TD-IP_nl.polarization_F1&amp;lt;/code&amp;gt; versus the first one (time-variable) to get the time-dependent polarization along the y-direction:&lt;br /&gt;
 gnuplot&amp;gt; p &#039;TD-IP_nl/o-TD-IP_nl.polarization_F1&#039; u 1:3 w l&lt;br /&gt;
&lt;br /&gt;
[[File:Bn polarization.png|thumb|center|900px|Real-time polarization in the y-direction]]&lt;br /&gt;
&lt;br /&gt;
For comparison, in the figure above, the polarization is obtained either through the Bloch-states or the density-matrix.&lt;br /&gt;
There are few differences which could be due to the following reasons:&lt;br /&gt;
* Coupling with the external field: the &amp;lt;code&amp;gt;yambo_rt&amp;lt;/code&amp;gt; evaluates the coupling with the external field through the dipoles (by default computing the commutator [x,Hnl]; the &amp;lt;code&amp;gt;yambo_nl&amp;lt;/code&amp;gt; evaluates the coupling using an expression based on the Berry Phase. For the latter, a numerical differentiation in reciprocal space is performed. The 10x10 2D k-mesh may not be fine enough. For denser k-mesh, the Berry phase approach converges to the one based on the dipoles. To avoid this one can use &amp;lt;code&amp;gt;DipApproach=&amp;quot;Covariant&amp;quot;&amp;lt;/code&amp;gt; in the scheme used by yambo_rt.     &lt;br /&gt;
* Integrator: the integrator used for the &amp;lt;code&amp;gt;yambo_nl&amp;lt;/code&amp;gt; is more accurate. The fact that the differences are more pronounced for long times may hint to inaccuracies in the integration of the equation of motions in &amp;lt;code&amp;gt;yambo_rt&amp;lt;/code&amp;gt;. One can use a similar integrator with yambo_rt, by setting in input &amp;lt;code&amp;gt;Integrator= &amp;quot;INV RK2&amp;quot;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Output postprocessing: the dielectric function ==&lt;br /&gt;
&lt;br /&gt;
Once we obtained the polarization, we Fourier transform the polarization to obtain the dielectric function.&lt;br /&gt;
&lt;br /&gt;
Use the command:&lt;br /&gt;
&lt;br /&gt;
  ypp_nl -nl -F Inputs_nl/ypp_abs.in&lt;br /&gt;
&lt;br /&gt;
to generate the input file:&lt;br /&gt;
&lt;br /&gt;
 nonlinear                    # [R] NonLinear Optics Post-Processing&lt;br /&gt;
 Xorder= 1                    # Max order of the response 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;1001&amp;lt;/span&amp;gt;                # Total Energy steps&lt;br /&gt;
 % EnRngeRt&lt;br /&gt;
   0.00000 | &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;10.00000&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;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.10000&amp;lt;/span&amp;gt;   eV    # Damping parameter&lt;br /&gt;
&lt;br /&gt;
          &lt;br /&gt;
where we set a Lorentzian smearing corresponding to 0.1 eV. Note that due to the finite time of our simulation, we need to introduce a finite smearing to Fourier transform the result.&lt;br /&gt;
&lt;br /&gt;
To run the post-processing, use the command:&lt;br /&gt;
 ypp_nl -F Inputs_nl/ypp_abs.in -J TD-IP_nl -C TD-IP_nl &lt;br /&gt;
and obtain the files for the dielectric constant along with the field direction, the EELS along with the same direction, and the damped polarization.&lt;br /&gt;
 o-TD-IP_nl.YPP-eps_along_E&lt;br /&gt;
 o-TD-IP_nl.YPP-eels_along_E&lt;br /&gt;
 o-TD-IP_nl.YPP-damped_polarization&lt;br /&gt;
inside the folder &amp;lt;code&amp;gt;TD-IP_nl&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Plot the dielectric constant and compare it with the linear response and the density-matrix formalism (available from the [[Real time approach to linear response]] tutorial):&lt;br /&gt;
 gnuplot&lt;br /&gt;
 plot &amp;quot;CHI_IP/o-CHI_IP.eps_q1_ip&amp;quot; u 1:2 w l&lt;br /&gt;
 rep &amp;quot;TD-IP_rt/o-TD-IP_rt.YPP-eps_along_E&amp;quot; u 1:2 w l&lt;br /&gt;
 rep &amp;quot;TD-IP_nl/o-TD-IP_nl.YPP-eps_along_E&amp;quot; u 1:2 w l&lt;br /&gt;
&lt;br /&gt;
[[File:Bn optics.png|thumb|900px|center|Imaginary part of the dielectric constant]]&lt;br /&gt;
&lt;br /&gt;
The differences observed with the spectra obtained from either the density-matrix and linear-response formalisms are due to how the dipoles are evaluated. Within the density-matrix and linear-response formalisms, dipoles are computed in the same way. The Bloch-states formalism uses instead covariant dipoles evaluated numerically on the k-mesh. The differences are due to numerical errors in evaluating the covariant dipoles. These differences disappear with a denser k-mesh. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;It is a good practice to converge the dielectric function obtained from the Bloch-state dynamics with respect to the k-points using the linear-response spectrum as a reference. This gives the minimum number of k-points to be used to obtain accurate results.         &lt;br /&gt;
&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
= Step 3: Hartree+Screened exchange approximation =&lt;br /&gt;
&lt;br /&gt;
== Evaluating the collisions==&lt;br /&gt;
&lt;br /&gt;
The evaluation of the collisions. (see [[Introduction to Real Time propagation in Yambo]] to remember what are the collisions)&lt;br /&gt;
This part is common in between the &amp;lt;code&amp;gt;yambo_nl&amp;lt;/code&amp;gt; and the &amp;lt;code&amp;gt;yambo_rt&amp;lt;/code&amp;gt;. If you have computed the collisions for the corresponding &amp;lt;code&amp;gt;yambo_rt&amp;lt;/code&amp;gt;, you can re-used those results. If not, follow the related steps in [[Real time Bethe-Salpeter Equation (density matrix only)#The_Real_Time_Collisions| the real-time BSE tutorial]].&lt;br /&gt;
&lt;br /&gt;
== Run the simulations ==&lt;br /&gt;
To generate the input for the real-time simulation you can run&lt;br /&gt;
 yambo_nl -nl n -V qp -F Inputs_nl/04_td-sex.in&lt;br /&gt;
&lt;br /&gt;
The input file is&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; 4 |  5 | &amp;lt;/span&amp;gt;                    # [NL] Bands&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;20.00000&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;&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;SEX&amp;lt;/span&amp;gt;&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;
 % NLEnRange&lt;br /&gt;
  -1.000000 | -1.000000 | eV      # [NL] Energy range&lt;br /&gt;
 %&lt;br /&gt;
 NLEnSteps= 1                   # [NL] Energy steps&lt;br /&gt;
 NLDamping=  &amp;quot;&amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;0.10000&amp;lt;/span&amp;gt;    eV      # [NL] Damping&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= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;1000         mHa&amp;lt;/span&amp;gt;     # [HA] Hartree     RL components&lt;br /&gt;
 EXXRLvcs= &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;1000         mHa&amp;lt;/span&amp;gt;     # [XX] Exchange    RL components&lt;br /&gt;
&lt;br /&gt;
The next section of the input is about external quasiparticle corrections (&amp;lt;code&amp;gt;EXTQP G&amp;lt;/code&amp;gt;). There change only &lt;br /&gt;
&lt;br /&gt;
 % GfnQP_E&lt;br /&gt;
  &amp;lt;span style=&amp;quot;color:red&amp;quot;&amp;gt;3.000000 &amp;lt;/span&amp;gt;| 1.000000 | 1.000000 |        # [EXTQP G] E parameters  (c/v) eV|adim|adim&lt;br /&gt;
 %&lt;br /&gt;
&lt;br /&gt;
The latter line introduces a scissor operator (a rigid shift of the conduction bands) of 3.0 eV. In principle, it is possible to perform a G&amp;lt;sub&amp;gt;0&amp;lt;/sub&amp;gt;W&amp;lt;sub&amp;gt;0&amp;lt;/sub&amp;gt; calculation with Yambo and use the Quasi-particle band structure instead of the rigid shift.&lt;br /&gt;
&lt;br /&gt;
The last section regards the applied field (&amp;lt;code&amp;gt;RT Field1&amp;lt;/code&amp;gt;). There change these two lines:   &lt;br /&gt;
&lt;br /&gt;
 % Field1_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 Field1] Versor&lt;br /&gt;
 %&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|SOFTSIN|RES|ANTIRES|GAUSS|DELTA|QSSIN)&lt;br /&gt;
 &lt;br /&gt;
Run the calculation:&lt;br /&gt;
&lt;br /&gt;
 nohup yambo_nl -F Inputs_nl/04_td_sex.in -J &amp;quot;TD-SEX_nl,COLL_HSEX&amp;quot; -C TD-SEX_nl&lt;br /&gt;
&lt;br /&gt;
== Output postprocessing: dielectric function ==&lt;br /&gt;
&lt;br /&gt;
The post-processing of the output does not depend on the level of approximation. The same steps are taken as in the independent-particle approximation.&lt;br /&gt;
&lt;br /&gt;
Use the command:&lt;br /&gt;
 ypp_nl -F Inputs_nl/ypp_abs.in -J TD-SEX_nl -C TD-SEX_nl&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Plot the results (compare with results obtained from the density-matrix formalism):&lt;br /&gt;
 gnuplot&amp;gt; set xrange [3:10]&lt;br /&gt;
 gnuplot&amp;gt; set yrange [0:12]&lt;br /&gt;
 gnuplot&amp;gt; plot &amp;quot;TD-SEX_rt/o-TD-SEX_rt.YPP-eps_along_E&amp;quot; u 1:2 w l&lt;br /&gt;
 gnuplot&amp;gt; rep &amp;quot;TD-SEX_nl/o-TD-SEX_nl.YPP-eps_along_E&amp;quot; u 1:2 w l&lt;br /&gt;
 gnuplot&amp;gt; rep &amp;quot;TD-IP_rt/o-TD-IP_rt.YPP-eps_along_E&amp;quot; u ($1+3):2 w l &lt;br /&gt;
&lt;br /&gt;
[[File:HBN HSEX absorption.png|thumb|900px|center|In plane absorption of hBN at the TD-HSEX level compared with IP absorption]]&lt;br /&gt;
&lt;br /&gt;
Similarly to what we have seen in the independent-particle case, the differences between the two approaches are due to the accuracy in evaluating numerically the covariant dipoles in the Bloch-state dynamics approach. &lt;br /&gt;
&lt;br /&gt;
&#039;&#039;For comparison, the linear response results at the BSE level can be obtained following the [[How to obtain an optical spectrum|BSE tutorial]]. &#039;&#039;&lt;br /&gt;
&lt;br /&gt;
= References =&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;/div&gt;</summary>
		<author><name>Fulvio</name></author>
	</entry>
</feed>