(database-generation-tutorial-target)= # Database generation In this tutorial you will learn how to generate the `SAVE` folder starting from a [Quantum ESPRESSO](https://www.quantum-espresso.org) calculation. Notice that beyond Quantum ESPRESSO other DFT codes can be used to generate wave-functions for Yambo, namely [Abinit](https://www.abinit.org) and [PWmat](https://www.pwmat.com/pwmat-introduce). ```{admonition} Requirements - `hBN` folder: download and extract `hBN.tar.gz` from the [Tutorial files](#tutorial-files-target) page - `pw.x` executable (version 5.0 or newer) - `p2y` and `yambo` executables ``` After you have downloaded the required files, move to the `hBN` folder: ```{code-block} none $ cd hBN/ $ ls COPYING PWSCF README.tutorials YAMBO ``` The following structure is common to various tutorials: a `PWSCF` folder containing all the files related to the starting DFT calculation (including pseudopotentials and reference output files) and a `YAMBO` folder for the Yambo calculations. Before we begin with the tutorial, here are some useful information specific to the example of bulk hBN: `````{grid} 2 ````{grid-item} - HCP lattice, ABAB stacking - Four atoms per cell, B and N (16 electrons) - Lattice constants: a = 4.716 [a.u.], c/a = 2.582 - Plane wave cutoff: 40 Ry (~1500 RL vectors in wavefunctions) - SCF: shifted 6x6x2 grid (12 k-points), 8 bands - Non-SCF run: gamma-centered 6x6x2 grid (14 k-points), 100 bands ```` ````{grid-item} ```{figure} ./images/hBN-bulk-3x3.png Atomic structure of bulk hexagonal boron nitride (hBN). ``` ```` ````` ``````{note} :class: dropdown `````{grid} 2 ````{grid-item} - 2D hexagonal lattice - Two atoms per cell, B and N (8 electrons) - Lattice constants: a = 4.716 [a.u.], c/a = 7 - Plane wave cutoff: 40 Ry (~5000 RL vectors in wavefunctions) - SCF: shifted 6x6x1 grid (12 k-points), 4 bands - Non-SCF run: gamma-centered 6x6x1 grid (7 k-points), 60 bands ```` ````{grid-item} ```{figure} ./images/hBN-2D-3x3.png :width: 50% Atomic structure of 2D hBN. ``` ```` ````` In the case of 2D hBN there is only one layer and the lattice constant along z is set to c/a = 7 (to add sufficient vacuum). Notice that because of the added vacuum the same plane wave energy cutoff of 40 Ry will correspond to ~5000 RL vectors. This is relevant because in Yambo you can specify energy cutoff values either in Ry or RL. `````` ## DFT calculations Go to the `PWSCF` folder: ```{code-block} none $ cd hBN/PWSCF $ ls Inputs Pseudos References hBN_nscf.in hBN_nscf_bands.in hBN_plot_bands.in hBN_scf.in hBN_scf_bands.in ``` ```{warning} :class: dropdown The output of `ls` may be different in case the tutorial files are updated. ``` Now run the SCF calculation to generate the ground-state charge density, occupations, and so on: ```{code-block} none $ pw.x < hBN_scf.in > hBN_scf.out ``` Looking at the output file we can see that the valence band maximum lies at 5.06 eV. Next run a non-SCF calculation to generate a set of Kohn-Sham eigenvalues and eigenvectors for both occupied and unoccupied states: ```{code-block} none $ pw.x < hBN_nscf.in > hBN_nscf.out ``` In this calculation we computed a total of 100 bands (`nbnd = 100` in the input file) and used a 6x6x2 grid (corresponding to 14 k-points). Notice the presence of the following flags in the input file: ```{code-block} none wf_collect = .true. force_symmorphic = .true. diago_thr_init = 5.0e-6, diago_full_acc = .true. ``` These are needed for generating the Yambo databases accurately. If you are not familiar with `pw.x` input variables you can find a full and detailed explanation on the [pw.x input description page](https://www.quantum-espresso.org/Doc/INPUT_PW.html). ```{note} :class: dropdown The `wf_collect` input variable is actually deprecated, but its inclusion in the input does not give any problems. ``` These calculations produce the `hBN.save` folder, which is needed by `p2y`: ```{code-block} none $ ls hBN.save B.pz-vbc.UPF N.pz-vbc.UPF charge-density.dat data-file-schema.xml wfc1.dat wfc2.dat wfc3.dat wfc4.dat ... wfc14.dat ``` ## Conversion to Yambo format The `hBN.save` output folder is converted to the Yambo format using the `p2y` executable (_pwscf to yambo_). Launch `p2y` **from inside** the `hBN.save` folder: ```{code-block} none $ cd hBN.save $ p2y ``` ````{dropdown} p2y output ```{code-block} none ____ ____ ___ .___ ___. .______ ______ \ \ / / / \ | \/ | | _ \ / __ \ \ \/ / / ^ \ | \ / | | |_) | | | | | \_ _/ / /_\ \ | |\/| | | _ < | | | | | | / _____ \ | | | | | |_) | | `--" | |__| /__/ \__\ |__| |__| |______/ \______/ <---> DBs path set to : . <---> detected QE data format : qexsd <---> == PWscf v.6.x generated data (QEXSD fmt) == <---> Header/K-points/Energies... <---> Cell data... ... <02s> == DB1 (Gvecs and more) ... <02s> ... Database done <02s> == DB2 (wavefunctions) ... <02s> [p2y] WF I/O | | [000%] --(E) --(X) <02s> [p2y] WF I/O |########################################| [100%] --(E) --(X) <02s> == DB3 (PseudoPotential) ... <02s> == P2Y completed == ``` ```` ```{tip} :class: dropdown If you run `p2y` in background or via some job submission script the log information will be printed in a `l_p2y` file. ``` You can see that `p2y` has generated the `SAVE` folder: ```{code-block} none $ ls SAVE ns.db1 ns.wf ns.kb_pp_pwscf ns.kb_pp_pwscf_fragment_1 ns.kb_pp_pwscf_fragment_2 ... ns.kb_pp_pwscf_fragment_14 ns.wf_fragments_1_1 ... ns.wf_fragments_14_1 ``` These files, with an `n` prefix, indicate that they are in [netCDF](https://www.unidata.ucar.edu/software/netcdf) format, and thus not human readable. However they are perfectly transferable across different architectures. You can check that the databases contain the information you expect by launching `yambo` using the `-D` option: ```{code-block} none $ yambo -D ``` ````{dropdown} yambo -D output ```{code-block} none [RD./SAVE//ns.db1]-------------------------------------------------------------- Bands : 100 K-points : 14 G-vectors : 8029 [RL space] Components : 1016 [wavefunctions] Symmetries : 24 [spatial+T-reV] Spinor components : 1 Spin polarizations : 1 Temperature : 0.000000 [eV] Electrons : 16.00000 WF G-vectors : 1477 Max atoms/species : 2 No. of atom species : 2 Exact exchange fraction in XC : 0.000000 Exact exchange screening in XC : 0.000000 Magnetic symmetries : no - S/N 000755 ---------------------------------------------- v.05.03.00 r.23927 - [RD./SAVE//ns.wf]--------------------------------------------------------------- Fragmentation : yes Bands in each block : 100 Blocks : 1 - S/N 000755 ---------------------------------------------- v.05.03.00 r.23927 - [RD./SAVE//ns.kb_pp_pwscf]------------------------------------------------------ Fragmentation : yes - S/N 000755 ---------------------------------------------- v.05.03.00 r.23927 - ``` ```` ```{note} :class: dropdown The layout of the text may be different in other versions of Yambo. ``` When you do your calculations we suggest to move the `SAVE` folder into a new clean folder. Concerning the tutorials, typically there is already a `SAVE` folder in the `YAMBO` directory.