epw_readin.f90 34.9 KB
Newer Older
sponce's avatar
sponce committed
1 2 3 4 5 6 7 8 9 10 11 12
  !                                                                            
  ! Copyright (C) 2010-2016 Samuel Ponce', Roxana Margine, Carla Verdi, Feliciano Giustino 
  ! Copyright (C) 2007-2009 Jesse Noffsinger, Brad Malone, Feliciano Giustino  
  !                                                                            
  ! This file is distributed under the terms of the GNU General Public         
  ! License. See the file `LICENSE' in the root directory of the               
  ! present distribution, or http://www.gnu.org/copyleft.gpl.txt .             
  !                                                                            
  ! Adapted from the code PH/phq_readin - Quantum-ESPRESSO group               
  !-----------------------------------------------------------------------
  SUBROUTINE epw_readin
  !-----------------------------------------------------------------------
13 14 15 16 17 18
  !!
  !!    This routine reads the control variables for the program epw.
  !!    from standard input (unit 5).
  !!    A second routine readfile reads the variables saved on a file
  !!    by the self-consistent program.
  !!
19 20 21
  !!   @Note:
  !!     SP: Image parallelization added
  !!
sponce's avatar
sponce committed
22
  USE ions_base,     ONLY : nat, ntyp => nsp
23
  USE cell_base,     ONLY : at
sponce's avatar
sponce committed
24 25
  USE mp,            ONLY : mp_bcast 
  USE wvfct,         ONLY : nbnd
26
  USE klist,         ONLY : nks, xk, nkstot 
sponce's avatar
sponce committed
27 28 29 30 31
  USE lsda_mod,      ONLY : lsda
  USE fixed_occ,     ONLY : tfixed_occ
  USE qpoint,        ONLY : xq
  USE disp,          ONLY : nq1, nq2, nq3
  USE output,        ONLY : fildvscf, fildrho
32
  USE epwcom,        ONLY : delta_smear, nsmear, dis_win_min, dis_win_max, wannierize, &
Samuel Poncé's avatar
Samuel Poncé committed
33
                            ngaussw, dvscf_dir, eptemp, bands_skipped, wdata, &
sponce's avatar
sponce committed
34 35 36
                            num_iter, dis_froz_max, fsthick, dis_froz_min, &
                            vme, degaussw, epexst, eig_read, kmaps, &
                            epwwrite, epbread, phonselfen, elecselfen, &
Samuel Poncé's avatar
Samuel Poncé committed
37 38 39 40 41 42
                            a2f, plselfen, specfun_pl, nest_fn, & 
                            rand_nk, rand_k, rand_nq, rand_q,  &
                            nkf1, nkf2, nkf3, nqf1, nqf2, nqf3, &
                            eps_acustic, nw, wmax, wmin, &
                            mp_mesh_q, mp_mesh_k, filqf, filkf, delta_qsmear, degaussq, &
                            band_plot, ephwrite, nstemp, broyden_beta, &
sponce's avatar
sponce committed
43 44
                            conv_thr_raxis, tempsmax, tempsmin, temps, broyden_ndim, &
                            wscut, wsfc, nqstep, limag, lreal, muc, gap_edge, &
45
                            conv_thr_iaxis, nqsmear, iprint, wepexst, epwread, & 
46
                            eliashberg, imag_read, kerread, kerwrite, lunif, &
sponce's avatar
sponce committed
47 48
                            fermi_energy, efermi_read, max_memlt, fila2f, &
                            ep_coupling, nw_specfun, wmax_specfun, &
49
                            wmin_specfun, laniso, lpolar, lifc, asr_typ, &
50 51
                            lscreen, scr_typ, fermi_diff, smear_rpa, & 
                            cumulant, bnd_cum, proj, write_wfn, iswitch, ntempxx, &
52
                            liso, lacon, lpade, etf_mem, epbwrite, &
53
                            nsiter, conv_thr_racon, specfun_el, specfun_ph, &
54
                            pwc, nswc, nswfc, nswi, filukq, filukk, &
55 56
                            nbndsub, nbndskip, system_2d, delta_approx, &
                            title, int_mob, scissor, iterative_bte, scattering, &
57 58
                            ncarrier, carrier, scattering_serta, restart, restart_freq, &
                            scattering_0rta, longrange, shortrange, scatread, &
59
                            restart_filq, prtgkk, nel, meff, epsiHEG, lphase, &
60
                            omegamin, omegamax, omegastep, n_r, lindabs, &
61
                            mob_maxiter, use_ws, epmatkqread, selecqread
62
  USE klist_epw,     ONLY : xk_all, xk_loc, xk_cryst
sponce's avatar
sponce committed
63 64
  USE elph2,         ONLY : elph
  USE start_k,       ONLY : nk1, nk2, nk3
Samuel Poncé's avatar
Samuel Poncé committed
65
  USE constants_epw, ONLY : ryd2mev, ryd2ev, ev2cmm1, kelvin2eV, zero
sponce's avatar
sponce committed
66 67 68 69 70 71 72
  USE io_files,      ONLY : tmp_dir, prefix
  USE control_flags, ONLY : iverbosity, modenum, gamma_only
  USE ions_base,     ONLY : amass
  USE mp_world,      ONLY : world_comm
  USE partial,       ONLY : atomo, nat_todo
  USE constants,     ONLY : AMU_RY
  USE mp_global,     ONLY : my_pool_id, me_pool
73
  USE io_global,     ONLY : meta_ionode, meta_ionode_id, ionode_id
74
  USE io_epw,        ONLY : iunkf, iunqf
75
#if defined(__NAG)
sponce's avatar
sponce committed
76 77
  USE F90_UNIX_ENV,  ONLY : iargc, getarg
#endif
78
  !
Samuel Poncé's avatar
Samuel Poncé committed
79
  IMPLICIT NONE
80
  !
81
#if ! defined(__NAG)
sponce's avatar
sponce committed
82 83
  integer :: iargc
#endif
84 85 86 87 88 89 90 91
  INTEGER :: ios
  !! integer variable for I/O control
  INTEGER :: na
  !! counter on polarizations
  INTEGER :: it
  !! counter on iterations
  INTEGER :: modenum_aux
  !! auxilary variable for saving the modenum
92 93
  INTEGER :: i
  !! Counter for loops
94 95
  INTEGER :: ik
  !! Counter on k-points
96 97 98 99 100 101
  INTEGER :: nk1tmp
  !! temp vars for saving kgrid info
  INTEGER :: nk2tmp
  !! temp vars for saving kgrid info
  INTEGER :: nk3tmp  
  !! temp vars for saving kgrid info
102
  LOGICAL, EXTERNAL  :: imatches
Samuel Poncé's avatar
Samuel Poncé committed
103
  CHARACTER(len=256) :: outdir
sponce's avatar
sponce committed
104
  namelist / inputepw / &
105
       amass, outdir, prefix, iverbosity, fildvscf,                            &
sponce's avatar
sponce committed
106
       elph, nq1, nq2, nq3, nk1, nk2, nk3, nbndskip,  nbndsub,                 &
107
       filukk, filukq, epbread, epbwrite, epwread, epwwrite, etf_mem, kmaps,   &
sponce's avatar
sponce committed
108
       eig_read, wepexst, epexst, vme,                                         &
109
       degaussw, fsthick, eptemp,  nsmear, delta_smear,                        &
110
       dvscf_dir, ngaussw, epmatkqread, selecqread,                            &
sponce's avatar
sponce committed
111
       wannierize, dis_win_max, dis_win_min, dis_froz_min, dis_froz_max,       &
Samuel Poncé's avatar
Samuel Poncé committed
112 113
       num_iter, proj, bands_skipped, wdata, iprint, write_wfn,                &
       wmin, wmax, nw, eps_acustic, a2f, nest_fn, plselfen,                    & 
114
       elecselfen, phonselfen, use_ws,                                         &
115
       rand_q, rand_nq, rand_k, rand_nk, specfun_pl,                           &
sponce's avatar
sponce committed
116
       nqf1, nqf2, nqf3, nkf1, nkf2, nkf3,                                     &
117
       mp_mesh_k, mp_mesh_q, filqf, filkf, ephwrite,                           & 
sponce's avatar
sponce committed
118
       band_plot, degaussq, delta_qsmear, nqsmear, nqstep,                     &
119
       nswfc, nswc, nswi, pwc, wsfc, wscut, system_2d,                         &
sponce's avatar
sponce committed
120 121 122
       broyden_beta, broyden_ndim, nstemp, tempsmin, tempsmax, temps,          &
       conv_thr_raxis, conv_thr_iaxis, conv_thr_racon,                         &
       gap_edge, nsiter, muc, lreal, limag, lpade, lacon, liso, laniso, lpolar,& 
123
       lscreen, scr_typ, fermi_diff, smear_rpa, cumulant, bnd_cum,             &
124
       lifc, asr_typ, lunif, kerwrite, kerread, imag_read, eliashberg,         & 
sponce's avatar
sponce committed
125
       ep_coupling, fila2f, max_memlt, efermi_read, fermi_energy,              &
126
       specfun_el, specfun_ph, wmin_specfun, wmax_specfun, nw_specfun,         & 
127
       delta_approx, scattering, int_mob, scissor, ncarrier, carrier,          &
128
       iterative_bte, scattering_serta, scattering_0rta, longrange, shortrange,&
129
       scatread, restart, restart_freq, restart_filq, prtgkk, nel, meff,       &
130
       epsiHEG, lphase, omegamin, omegamax, omegastep, n_r, lindabs, mob_maxiter
131

132
  ! tphases, fildvscf0
sponce's avatar
sponce committed
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
  !
  ! amass    : atomic masses
  ! iverbosity   : verbosity control
  ! outdir   : directory where input, output, temporary files reside
  ! elph     : if true calculate electron-phonon coefficients
  ! prefix   : the prefix of files produced by pwscf
  ! fildvscf : output file containing deltavsc
  ! fildrho  : output file containing deltarho
  !
  ! added by @ FG
  !
  ! ngaussw  : smearing type for FS average after wann interp
  ! degaussw : corresponding width (units of eV)
  ! filqf    : file with fine q kmesh for interpolation
  ! filkf    : file with fine kmesh for interpolation
  ! filukk   : file with rotation matrix U(k) for interpolation
  ! filukq   : file with rotation matrix U(k+q) for interpolation
  ! tphases  : if true set absolute unitary gauge for eigenvectors
151
  ! epstrict : if true use strict selection rule for phonon linewidht calculation
sponce's avatar
sponce committed
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
  ! fsthick  : the thickness of the Fermi shell for averaging the e-ph matrix elements (units of eV)
  ! eptemp   : temperature for the electronic Fermi occupations in the e-p calculation (units of Kelvin)
  ! fildvscf0: file containing deltavscf to be used as fake perturbation to set phases
  ! nw       : nr. of bins for frequency scan in \delta( e_k - e_k+q - w ) (units of eV)
  ! wmin     : min frequency for frequency scan in \delta( e_k - e_k+q - w ) (units of eV)
  ! wmax     : max    "  "  "                                    (units of eV)                   
  ! nbndsub  : number of bands in the optimal subspace (when disentanglement is used)
  ! elecselfen: if .TRUE. calculate imaginary part of electron selfenergy due to e-p interaction
  ! phonselfen: if .TRUE. calculate imaginary part of phonon selfenergy due to e-p interaction
  ! dvscf_dir: the dir containing all the .dvscf and .dyn files
  ! epbread  : read epmatq array from .epb files
  ! epbwrite : write epmatq array to .epb files
  ! nbndskip : number of bands to be skipped from the original Hamitonian (nfirstwin-1 in Marzari's notation)
  ! epwread  : read all quantities in Wannier representation from file epwdata.fmt
  ! epwwrite : write all quantities in Wannier representation to file epwdata.fmt
  !
  !  added by @jn
  !
  ! wannierize : if .TRUE. run the wannier90 code to maximally localize the WFs
  ! dis_win_min : lower bound on wannier90 disentanglement window
  ! dis_win_max : upper bound on wannier90 disentanglement window
  ! dis_froz_min : lower bound on frozen wannier90 disentanglement window
  ! dis_froz_max : upper bound on frozen wannier90 disentanglement window
  ! num_iter     : number of iterations used in the wannier90 minimisation
  ! proj         : initial projections (states) of the wannier functions before minimization
Samuel Poncé's avatar
Samuel Poncé committed
177
  ! bands_skipped: k-point independent list of bands excluded from the calculation of overlap and projection matrices in W90
sponce's avatar
sponce committed
178 179 180 181 182 183 184 185 186 187 188 189 190 191
  ! wdata        : Empty array that can be used to pass extra info to prefix.win file, for things not explicitly declared here 
  ! iprint       : verbosity of the wannier90 code
  ! write_wfn    : writes out UNK files from pwscf run for plotting of XSF files
  ! kmaps        : if true, read kmap and kgmap from disk (prior run)
  ! eig_read     : if .true. then readin a set of electronic eigenvalues in eV to replace the calcualted ones
  ! wepexst      : if .TRUE. prefix.epmatwe files are already on disk. don't recalculate. debugging param
  ! epexst       : if .TRUE. prefix.epmatwp files are already on disk. don't recalculate  debugging param
  ! vme          : if .TRUE. calculate velocity matrix elements
  ! nest_fn      : if true, calculate the nesting function for a given set of q's
  ! nsmear       : number of smearing values to use for the selfen_phon call
  ! delta_smear  : change in energy for each additional nsmear ( units of eV)
  !
  ! added by @ RM
  !
192
  ! ephwrite    : if true write el-phonon matrix elements on the fine mesh to file
sponce's avatar
sponce committed
193
  ! eps_acustic : min phonon frequency for e-p and a2f calculations (units of cm-1)
194 195 196 197 198
  ! band_plot   : if true write files to plot band structure and phonon dispersion
  ! degaussq    : smearing for sum over q in e-ph coupling (units of meV)
  ! delta_qsmear: change in energy for each additional smearing in the a2f (units of meV)
  ! nqsmear     : number of smearings used to calculate a2f
  ! nqstep   : number of bins for frequency used to calculate a2f
sponce's avatar
sponce committed
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
  ! nswfc    : nr. of grid points between (0,wsfc) in Eliashberg equations 
  ! nswc     : nr. of grid points between (wsfc,wscut)
  ! pwc      : power used to define nswc for non-uniform grid real-axis calculations
  ! wsfc     : intermediate freqeuncy used for integration in Eliashberg equations (at least 2-3 times wsphmax) 
  ! wscut    : upper limit for frequency integration in Eliashberg equations (at least 5 times wsphmax) (units of eV)
  ! broyden_beta : mixing factor for broyden mixing
  ! broyden_ndim : number of iterations used in mixing scheme
  ! nstemp   : number of temperature points for which the Eliashberg equations are solved
  ! tempsmin : minimum temperature for which the Eliashberg equations are solved
  ! tempsmax : maximum temperature " "
  ! conv_thr_raxis : convergence threshold for iterative solution of real-axis Eliashberg equations
  ! conv_thr_iaxis : convergence threshold for iterative solution of imag-axis Eliashberg equations 
  ! conv_thr_racon : convergence threshold for iterative solution of analytic continuation of  
  !                  Eliashberg equations from imag- to real-axis
  ! gap_edge : initial guess of the superconducting gap (in eV)
  ! nsiter   : nr of iterations for self-consitency cycle
  ! muc     : effective Coulomb potential
  ! lreal   : if .true. solve the real-axis Eliashberg eqautions
  ! limag   : if .true. solve the imag-axis Eliashberg eqautions
  ! lpade   : if .true. use pade approximants to continue imag-axis 
  !           Eliashberg equtions to real-axis
  ! lacon   : if .true. use analytic continuation to continue imag-axis 
  !           Eliashberg equtions to real-axis
  ! liso    : if .true. solve isotropic case
  ! laniso  : if .true. solve anisotropic case
  ! lunif   : if .true. a uniform grid is defined between wsfc and wscut for real-axis calculations
  ! kerwrite: if .true. write Kp and Km to files .ker for real-axis calculations
  ! kerread : if .true. read Kp and Km from files .ker for real-axis calculations
227 228 229 230 231 232
  ! imag_read    : if .true. read from files Delta and Znorm on the imaginary-axis
  ! eliashberg   : if .true. solve the Eliashberg equations
  ! ep_coupling  : if .true. run e-p coupling calculation
  ! fila2f       : input file with eliashberg spectral function 
  ! max_memlt    : maximum memory that can be allocated per pool 
  ! efermi_read  : if. true. read from input file
sponce's avatar
sponce committed
233 234 235 236
  ! fermi_energy : fermi eneergy read from input file (units of eV)
  ! wmin_specfun : min frequency in electron spectral function due to e-p interaction (units of eV)
  ! wmax_specfun : max frequency in electron spectral function due to e-p interaction (units of eV)
  ! nw_specfun   : nr. of bins for frequency in electron spectral function due to e-p interaction 
237 238
  ! system_2d    : if .true. two-dimensional system (vaccum is in z-direction)  
  ! delta_approx : if .true. the double delta approximation is used to compute the phonon self-energy 
sponce's avatar
sponce committed
239
  !
240
  ! added by CV & SP
241 242
  ! lpolar  : if .true. enable the correct Wannier interpolation in the case of polar material.  
  ! lifc    : if .true. reads interatomic force constants produced by q2r.x for phonon interpolation
243
  ! asr_typ : select type of ASR if lifc=.true. (as in matdyn); otherwise it is the usual simple sum rule
244 245 246 247 248 249 250 251 252
  ! lscreen : if .true. the e-ph matrix elements are screened by the RPA or TF dielectric function
  ! scr_typ : if 0 calculates the Lindhard screening, if 1 the Thomas-Fermi screening
  ! fermi_diff : difference between Fermi energy and band edge (in eV)
  ! smear_rpa  : smearing for the calculation of the Lindhard function (in eV)
  ! cumulant   : if .true. calculates the electron spectral function using the cumulant expansion method
  !              (can be used as independent postprocessing by setting ep_coupling=.false.)
  ! bnd_cum    : band index for which the cumulant calculation is done 
  !              (for more than one band, perform multiple calculations and add the results together)
  !
sponce's avatar
sponce committed
253
  ! 
254 255
  ! Added by SP
  !
256 257
  ! specfun_el      : if .TRUE. calculate electron spectral function due to e-p interaction
  ! specfun_ph      : if .TRUE. calculate phonon spectral function due to e-p interaction
258
  ! specfun_pl      : if .TRUE. calculate plason spectral function 
259 260
  ! restart         : if .true. a run can be restarted from the interpolation level
  ! restart_freq    : Create a restart point every restart_freq q/k-points
261
  ! restart_filq    : Use to merge different q-grid scattering rates (name of the file)
262 263
  ! scattering      : if .true. scattering rates are calculated
  ! scattering_serta: if .true. scattering rates are calculated using self-energy relaxation-time-approx
264
  ! scatread        : if .true. the current scattering rate file is read from file. 
265 266 267 268 269 270 271 272 273
  ! scattering_0rta : if .true. scattering rates are calculated using 0th order relaxation-time-approx
  ! int_mob         : if .true. computes the intrinsic mobilities. This means that the
  !                   electron and hole carrier density is equal. 
  ! iterative_bte   : if .true. computes the iterative solution to the BTE. Need a
  !                   prior run with ERTA. 
  ! scissor         : Value of the scissor shitf in eV. This only affects the CBM of etf. Do you use in
  !                   metals obviously.
  ! carrier         : if .true. computes the doped carrier mobilities. 
  ! ncarrier        : Set the Fermi level so that the carrier concentration is
274
  !                   " ncarrier". If ncarrier > 0, electron doping, hole doping otherwise
275 276 277 278
  ! longrange       : if .true. computes the long-range part of the el-ph (can
  !                   only be used with lpolar = .true. )
  ! shortrange      : if .true. computes the short-range part of the el-ph (can
  !                   only be used with lpolar = .true. )
279
  ! prtgkk          : Print the vertex |g| [meV]. This generates huge outputs.   
280
  ! etf_mem         : if 0 no optimization, if 1 less memory is used for the fine grid interpolation
281 282
  !                   When etf_mem == 2, an additional loop is done on mode for the fine grid interpolation
  !                   part. This reduces the memory further by a factor "nmodes".    
283
  ! plselfen        : Calculate the electron-plasmon self-energy.
284 285
  ! nel             : Fractional number of electrons in the unit cell
  ! meff            : Density of state effective mass (in unit of the electron mass)
286
  ! epsiHEG         : Dielectric constant at zero doping
287
  ! lphase          : If .true., fix the gauge on the phonon eigenvectors and electronic eigenvectors - DS 
288
  ! mob_maxiter     : Maximum number of iteration for the IBTE. 
289
  ! use_ws          : If .true., use the Wannier-center to create the Wigner-Seitz cell. 
290 291
  ! epmatkqread     : If .true., restart an IBTE calculation from scattering written to files. 
  ! selecqread      : If .true., restart from the selecq.fmt file
292
  !  
293 294 295 296 297 298
  ! Added by Manos Kioupakis
  ! omegamin  : Photon energy minimum
  ! omegamax  : Photon energy maximum
  ! omegastep : Photon energy step in evaluating phonon-assisted absorption spectra (in eV)
  ! n_r       :  constant refractive index
  ! lindabs   : do phonon-assisted absorption
299
  ! 
sponce's avatar
sponce committed
300 301 302 303
  nk1tmp = 0
  nk2tmp = 0
  nk3tmp = 0
  !
304
  IF (meta_ionode) THEN
sponce's avatar
sponce committed
305 306
  !
  ! ... Input from file ?
Samuel Poncé's avatar
Samuel Poncé committed
307
    CALL input_from_file( )
sponce's avatar
sponce committed
308
  !
309
  ! ... Read the first line of the input file
sponce's avatar
sponce committed
310
  !
Samuel Poncé's avatar
Samuel Poncé committed
311
    READ( 5, '(A)', IOSTAT = ios ) title
sponce's avatar
sponce committed
312
  !
313 314
  ENDIF
  ! 
315 316 317
  CALL mp_bcast(ios, meta_ionode_id, world_comm)
  CALL errore('epw_readin', 'reading title ', ABS( ios ))
  CALL mp_bcast(title, meta_ionode_id, world_comm)
318 319 320
  !
  ! Rewind the input if the title is actually the beginning of inputph namelist
  !
321
  IF(imatches("&inputepw", title)) THEN
322 323 324 325 326 327
    WRITE(*, '(6x,a)') "Title line not specified: using 'default'."
    title='default'
    IF (meta_ionode) REWIND(5, iostat=ios)
    CALL mp_bcast(ios, meta_ionode_id, world_comm  )
    CALL errore('epw_readin', 'Title line missing from input.', abs(ios))
  ENDIF
sponce's avatar
sponce committed
328
  !
329
  IF (.NOT. meta_ionode) goto 400
sponce's avatar
sponce committed
330 331 332 333 334 335 336 337
  !
  !   set default values for variables in namelist
  !
  amass(:)     = 0.d0
  iverbosity   = 0
  elph         = .false.
  elecselfen   = .false.
  phonselfen   = .false.
338
  plselfen     = .false.
339 340
  specfun_el   = .false.
  specfun_ph   = .false.
341
  specfun_pl   = .false.
sponce's avatar
sponce committed
342 343 344
  epbread      = .false.
  epbwrite     = .false.
  epwread      = .false.
345
  epwwrite     = .true.
346 347
  restart      = .false.
  restart_freq = 100
sponce's avatar
sponce committed
348 349 350 351 352 353 354 355 356
  wannierize   = .false.
  write_wfn    = .false.
  kmaps        = .false.
  nest_fn      = .false.
  wepexst      = .false.
  epexst       = .false.
  eig_read     = .false.
  dis_win_max  = 1d3
  dis_win_min  = -1d3
357
  dis_froz_max =  1d3
sponce's avatar
sponce committed
358 359 360
  dis_froz_min = -1d3
  num_iter     = 200
  proj(:)      = ''
Samuel Poncé's avatar
Samuel Poncé committed
361
  bands_skipped= ''
sponce's avatar
sponce committed
362 363 364 365 366 367 368
  wdata(:)     = ''
  iprint       = 2
  wmin         = 0.d0
  wmax         = 0.3d0
  eps_acustic  = 5.d0 ! cm-1
  nw           = 10
  fsthick      = 1.d10 ! eV
369
  eptemp       = 300.0d0
sponce's avatar
sponce committed
370
  degaussw     = 0.025d0 ! eV
371
!  tphases      = .false.
sponce's avatar
sponce committed
372
  a2f          = .false.
373
  etf_mem      = 1 
374
!  fildvscf0    = ' '
sponce's avatar
sponce committed
375 376 377 378 379
  ngaussw      = 1
  outdir       = '.'
  dvscf_dir    = '.'
  prefix       = 'pwscf'
  filqf        = ' '
380
  restart_filq = ' '
sponce's avatar
sponce committed
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426
  filkf        = ' '
  fildrho      = ' '
  fildvscf     = ' '
  filukk       = ' '
  rand_q       = .false.
  delta_approx = .false.
  rand_nq      = 1
  rand_k       = .false.
  rand_nk      = 1
  nq1          = 0
  nq2          = 0
  nq3          = 0
  nk1          = 0
  nk2          = 0
  nk3          = 0
  nqf1         = 0
  nqf2         = 0
  nqf3         = 0
  nkf1         = 0
  nkf2         = 0
  nkf3         = 0
  mp_mesh_k    = .false.
  mp_mesh_q    = .false.
  nbndsub      = 0
  nbndskip     = 0
  nsmear       = 1
  delta_smear  = 0.01d0 ! eV
  modenum = 0 ! Was -1 previously and read from Modules/input_parameters.f90
              ! INTEGER :: modenum = 0. In QE 5, modenum variable does not exist
              ! anymore. Change the default EPW value to match the previous QE
              ! one. 
  vme = .false.
  ephwrite = .false.
  band_plot = .false.
  nqsmear = 10
  nqstep = 500
  delta_qsmear = 0.05d0 ! meV 
  degaussq = 0.05d0 ! meV
  lreal   = .false.
  lunif   = .true.
  limag   = .false.
  lpade   = .false.
  lacon   = .false.
  liso    = .false.
  laniso  = .false.
  lpolar  = .false.
427 428
  lifc    = .false.
  asr_typ = 'simple'
429 430 431 432 433 434 435 436 437 438
  lscreen = .false. 
  scr_typ = 0
  fermi_diff  = 1.d0
  smear_rpa   = 0.05d0
  cumulant    = .false.
  bnd_cum     = 1
  kerwrite    = .false.
  kerread     = .false.
  imag_read   = .false.
  eliashberg  = .false.
sponce's avatar
sponce committed
439 440 441 442 443 444 445 446 447 448 449 450 451
  ep_coupling = .true.
  nswfc    = 0
  nswc     = 0
  nswi     = 0 
  pwc      = 1.d0
  wscut    = 0.d0
  wsfc     = 0.5d0 * wscut 
  broyden_beta = 0.7d0
  broyden_ndim = 8
  conv_thr_raxis = 5.d-04
  conv_thr_iaxis = 1.d-05
  conv_thr_racon = 5.d-04
  gap_edge = 0.d0
452 453 454 455
  nstemp   = 1
  tempsmin = 0.d0
  tempsmax = 0.d0
  temps(:) = 0.d0
sponce's avatar
sponce committed
456 457 458 459 460 461 462 463 464 465
  nsiter   = 40
  muc     = 0.d0
  fila2f  = ' '
  max_memlt = 2.85d0
  efermi_read = .false.
  fermi_energy = 0.d0
  wmin_specfun = 0.d0 ! eV
  wmax_specfun = 0.3d0 ! eV
  nw_specfun = 100
  system_2d = .false.
466 467
  scattering = .false.
  scattering_serta = .false.
468
  scatread = .false.
469
  scattering_0rta = .false.
470
  int_mob    = .false.
471
  iterative_bte = .false.
472 473 474 475
  scissor    = 0.d0 ! eV
  carrier    = .false.
  ncarrier   = 0.d0 ! cm^-3
  longrange  = .false.
476
  shortrange = .false.  
477
  prtgkk     = .false.
478 479
  nel        = 0.0d0
  meff       = 1.d0
480 481
  epsiHEG    = 1.d0 
  lphase     = .false. 
482 483
  omegamin   = 0.d0  ! eV
  omegamax   = 10.d0 ! eV
484 485
  omegastep  = 1.d0  ! eV
  n_r        = 1.d0
486
  lindabs    = .false.
487
  mob_maxiter= 50
488
  use_ws     = .false.
489 490
  epmatkqread = .false.
  selecqread = .false.
sponce's avatar
sponce committed
491 492 493
  !
  !     reading the namelist inputepw
  !
494
#if defined(__CRAYY) 
sponce's avatar
sponce committed
495 496 497 498 499
  !   The Cray does not accept "err" and "iostat" together with a namelist
  READ (5, inputepw)
  ios = 0
#else
  !
500
  IF (meta_ionode) READ (5, inputepw, err = 200, iostat = ios)
sponce's avatar
sponce committed
501 502 503 504 505 506 507 508 509 510 511 512
#endif
200 CALL errore ('epw_readin', 'reading input_epw namelist', abs (ios) )
  !
  nk1tmp = nk1
  nk2tmp = nk2
  nk3tmp = nk3
  !
  !     Check all namelist variables
  !
  IF (filukk.eq.' ') filukk=trim(prefix)//'.ukk'
  IF (nsmear .lt. 1) CALL errore ('epw_readin', &
       & 'Wrong number of nsmears',1)
Samuel Poncé's avatar
Samuel Poncé committed
513 514 515
  IF (iverbosity.ne.0 .and. iverbosity.ne.1 .and. iverbosity.ne.2 .and. iverbosity.ne.3) & 
     CALL errore ('epw_readin', ' Wrong  iverbosity ', 1)
!  IF (tphases .and. fildvscf0.eq.' ') CALL errore ('epw_readin', &
516
!       &' tphases requires fildvscf0', 1)
Samuel Poncé's avatar
Samuel Poncé committed
517
  IF (epbread .and. epbwrite) CALL errore ('epw_readin', &
sponce's avatar
sponce committed
518
       &' epbread cannot be used with epbwrite', 1)
Samuel Poncé's avatar
Samuel Poncé committed
519
  IF (degaussw*4.d0 > fsthick) CALL errore ('epw_readin', &
sponce's avatar
sponce committed
520 521 522
       &' degaussw too close to fsthick', 1)
  IF ( nbndskip .lt. 0) CALL errore('epw_readin', &
       &' nbndskip must not be less than 0', 1)
Samuel Poncé's avatar
Samuel Poncé committed
523
  IF ((nw.lt.1) .or. (nw.gt.1000)) CALL errore ('epw_readin', &
sponce's avatar
sponce committed
524
       &' unreasonable nw', 1)
525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540
  IF (elecselfen .and. plselfen) CALL errore('epw_readin', &
       &'Electron-plasmon self-energy cannot be computed with electron-phonon',1)
  IF (phonselfen .and. plselfen) CALL errore('epw_readin', &
       &'Electron-plasmon self-energy cannot be computed with electron-phonon',1)
  IF (specfun_el .and. plselfen) CALL errore('epw_readin', &
       &'Electron-plasmon self-energy cannot be computed with el-ph spectral function',1)
  IF (specfun_ph .and. plselfen) CALL errore('epw_readin', &
       &'Electron-plasmon self-energy cannot be computed with el-ph spectral function',1)
  IF (elecselfen .and. specfun_pl ) CALL errore('epw_readin', &
       &'Electron-plasmon spectral function cannot be computed with electron-phonon',1)
  IF (phonselfen .and. specfun_pl) CALL errore('epw_readin', &
       &'Electron-plasmon spectral function cannot be computed with electron-phonon',1)
  IF (specfun_el .and. specfun_pl) CALL errore('epw_readin', &
       &'Electron-plasmon spectral function cannot be computed with el-ph spectral function',1)
  IF (specfun_ph .and. specfun_pl) CALL errore('epw_readin', &
       &'Electron-plasmon spectral function cannot be computed with el-ph spectral function',1)
Samuel Poncé's avatar
Samuel Poncé committed
541
  IF (a2f .AND. .not.phonselfen) CALL errore('epw_readin', &
sponce's avatar
sponce committed
542
       &'a2f requires phonoselfen',1)
Samuel Poncé's avatar
Samuel Poncé committed
543
  IF (elph .AND. .not.ep_coupling ) CALL errore('epw_readin', &
sponce's avatar
sponce committed
544
      &'elph requires ep_coupling=.true.',1)
Samuel Poncé's avatar
Samuel Poncé committed
545
  IF ( (elph .AND. wannierize) .AND. (epwread) ) CALL errore('epw_readin', &
sponce's avatar
sponce committed
546
       & 'must use same w90 rotation matrix for entire run', 1)
Samuel Poncé's avatar
Samuel Poncé committed
547
  IF (wannierize .AND. .not.ep_coupling ) CALL errore('epw_readin', &
sponce's avatar
sponce committed
548
      &'wannierize requires ep_coupling=.true.',1)
Samuel Poncé's avatar
Samuel Poncé committed
549
  IF ((wmin > wmax)) &
sponce's avatar
sponce committed
550 551 552 553 554 555 556
       CALL errore ('epw_readin', ' check wmin, wmax ', 1)
  IF ((wmin_specfun.gt.wmax_specfun)) &
       CALL errore ('epw_readin', ' check wmin_specfun, wmax_specfun ', 1)
  IF ((nw_specfun.lt.2)) CALL errore ('epw_readin', &
       &' nw_specfun must be at least 2', 1)
  IF ((nqstep.lt.2)) CALL errore ('epw_readin', &
       &' nqstep must be at least 2', 1)
Samuel Poncé's avatar
Samuel Poncé committed
557
  IF ((nbndsub > 200)) CALL errore ('epw_readin', & 
sponce's avatar
sponce committed
558
       ' too many wannier functions increase size of projx', 1)
Samuel Poncé's avatar
Samuel Poncé committed
559
  IF (( phonselfen .OR. elecselfen .or. specfun_el .or. specfun_ph ) .and. ( mp_mesh_k .or. mp_mesh_q )) & 
sponce's avatar
sponce committed
560
     CALL errore('epw_readin', 'can only work with full uniform mesh',1)
Samuel Poncé's avatar
Samuel Poncé committed
561
  IF (ephwrite .AND. .NOT. ep_coupling .and. .not.elph ) CALL errore('epw_readin', &
sponce's avatar
sponce committed
562
      &'ephwrite requires ep_coupling=.true., elph=.true.',1)
Samuel Poncé's avatar
Samuel Poncé committed
563
  IF (ephwrite .AND. (rand_k .OR. rand_q ) ) &
sponce's avatar
sponce committed
564
     CALL errore('epw_readin', 'ephwrite requires a uniform grid',1) 
Samuel Poncé's avatar
Samuel Poncé committed
565
  IF (ephwrite .AND. (mod(nkf1,nqf1) .ne. 0 .OR. mod(nkf2,nqf2) .ne. 0 .OR. mod(nkf3,nqf3) .ne. 0 ) ) &
sponce's avatar
sponce committed
566
     CALL errore('epw_readin', 'ephwrite requires nkf1,nkf2,nkf3 to be multiple of nqf1,nqf2,nqf3',1)
Samuel Poncé's avatar
Samuel Poncé committed
567
  IF (band_plot .AND. filkf .eq. ' ' .and. filqf .eq. ' ') CALL errore('epw_readin', &
sponce's avatar
sponce committed
568
      &'plot band structure and phonon dispersion requires k- and q-points read from filkf and filqf files',1)
Samuel Poncé's avatar
Samuel Poncé committed
569
  IF (band_plot .AND. filkf .ne. ' ' .and. (nkf1 > 0 .or. nkf2 > 0 .or. nkf3 > 0) ) CALL errore('epw_readin', &
570
                &'You should define either filkf or nkf when band_plot = .true.',1)
Samuel Poncé's avatar
Samuel Poncé committed
571
  IF (band_plot .AND. filqf .ne. ' ' .and. (nqf1 > 0 .or. nqf2 > 0 .or. nqf3 > 0) ) CALL errore('epw_readin', &
572
                &'You should define either filqf or nqf when band_plot = .true.',1)
Samuel Poncé's avatar
Samuel Poncé committed
573
  IF ( filkf .ne. ' ' .AND. .NOT. efermi_read ) CALL errore('epw_readin', &
sponce's avatar
sponce committed
574
      &'WARNING: if k-points are along a line, then efermi_read=.true. and fermi_energy must be given in the input file',-1)
575
  IF ( scattering .AND. nstemp < 1 ) CALL errore('epw_readin', &
576 577
       'wrong number of nstemp',1)
  IF ( scattering .AND. maxval(temps(:)) > 0.d0 .AND. tempsmin > 0.d0 .AND. tempsmax > 0.d0 ) &
578
       CALL errore('epw_readin', 'define either (tempsmin and tempsmax) or temps(:)',1)
579
  IF ( scattering .AND. tempsmax < tempsmin ) &
580
       CALL errore('epw_readin', 'tempsmax should be greater than tempsmin',1)
581 582
!  IF ( int_mob .AND. efermi_read)  CALL errore('epw_init', &
!       'Fermi level can not be set (efermi_read) when computing intrinsic mobilities',1)
583 584
!  IF ( int_mob .AND. (ABS(ncarrier) > 1E+5) )  CALL errore('epw_init', &
!       'You cannot compute intrinsic mobilities and doped mobilities at the same time',1)
585
  IF ( (ABS(ncarrier) > 1E+5) .AND. .NOT. carrier ) CALL errore('epw_readin', &
586
       'carrier must be .true. if you specify ncarrier.',1)
587
  IF ( carrier .AND. (ABS(ncarrier) < 1E+5) )  CALL errore('epw_readin', &
588
       'The absolute value of the doping carrier concentration must be larger than 1E5 cm^-3',1)
589 590
!  IF ( (iterative_bte .AND. scattering_serta) .OR. (iterative_bte .AND.scattering_0rta)  ) CALL errore('epw_init', &
!       'You should first do a run in the SRTA to get the initial scattering_rate files.',1)
591
  IF ( (longrange .OR. shortrange) .AND. (.NOT. lpolar)) CALL errore('epw_readin',&
592 593 594
       &'Error: longrange or shortrange can only be true if lpolar is true as well.',1)
  IF ( longrange .AND. shortrange) CALL errore('epw_init',&
       &'Error: longrange and shortrange cannot be both true.',1)
595
  IF ( epwread .AND. .NOT. kmaps .AND. .NOT. epbread) CALL errore('epw_readin',&
596
       &'Error: kmaps has to be true for a restart run. ',1)
597
  IF ( .not. epwread .AND. .NOT. epwwrite) CALL errore('epw_readin',&
598
       &'Error: Either epwread or epwwrite needs to be true. ',1)
599
  IF ( lscreen .AND. etf_mem == 2) CALL errore('epw_readin',&
600
       &'Error: lscreen not implemented with etf_mem=2 ',1)
601 602 603 604 605 606 607 608 609 610 611 612
  ! Make sure the files exists
  IF ( filkf .ne. ' ' ) THEN
    OPEN( unit = iunkf, file = filkf, status = 'old', form = 'formatted',err=100, iostat=ios)
100 CALL errore('epw_readin','opening file '//filkf,abs(ios))
    CLOSE(iunkf)
  ENDIF
  IF ( filqf .ne. ' ' ) THEN
    OPEN( unit = iunqf, file = filqf, status = 'old', form = 'formatted',err=101, iostat=ios)
101 CALL errore('epw_readin','opening file '//filqf,abs(ios))
    CLOSE(iunqf)
  ENDIF  

613 614 615
!#ifndef __MPI
!  IF ( etf_mem == 2 ) CALL errore('epw_init','Error: etf_mem == 2 only works with MPI.',1)
!#endif
sponce's avatar
sponce committed
616 617 618
  !
  ! thickness and smearing width of the Fermi surface  
  ! from eV to Ryd
619 620
  fsthick     = fsthick / ryd2ev 
  degaussw    = degaussw / ryd2ev 
sponce's avatar
sponce committed
621 622 623 624 625 626 627 628 629 630
  delta_smear = delta_smear / ryd2ev 
  !
  ! smearing of phonon in a2f
  ! from meV to Ryd 
  degaussq = degaussq / ryd2mev
  delta_qsmear = delta_qsmear / ryd2mev
  !
  ! fermi_energy read from the input file
  ! from eV to Ryd
  IF ( efermi_read ) THEN
631
    fermi_energy = fermi_energy / ryd2ev
sponce's avatar
sponce committed
632 633
  ENDIF
  ! eptemp : temperature for the electronic Fermi occupations in the e-p calculation (units of Kelvin)
634 635 636 637 638 639 640 641 642 643 644
  ! 1 K in eV = 8.6173423e-5
  ! from K to Ryd
  ! Out-of bound issue with GCC compiler. Multiple Fermi temp is not used anyway.
  eptemp = eptemp * kelvin2eV / ryd2ev
  !DO i = 1, ntempxx
  !   IF (eptemp(i) .gt. 0.d0) THEN
  !      ! 1 K in eV = 8.6173423e-5
  !      ! from K to Ryd
  !      eptemp(i) = eptemp(i) * kelvin2eV / ryd2ev
  !   ENDIF
  !ENDDO
sponce's avatar
sponce committed
645 646 647 648 649 650 651 652 653 654 655 656 657 658
  !
  ! from cm-1 to Ryd
  eps_acustic = eps_acustic / ev2cmm1 / ryd2ev 
  !
  !    reads the q point (just if ldisp = .false.)
  !
  ! wmin and wmax from eV to Ryd
  wmin = wmin / ryd2ev
  wmax = wmax / ryd2ev
  !
  ! wmin_specfun and wmax_specfun from eV to Ryd
  wmin_specfun = wmin_specfun / ryd2ev
  wmax_specfun = wmax_specfun / ryd2ev
  !
659 660 661
  ! scissor going from eV to Ryd
  scissor = scissor / ryd2ev
  ! 
662 663 664 665 666
  ! Photon energies for indirect absorption from eV to Ryd
  omegamin = omegamin / ryd2ev
  omegamax = omegamax / ryd2ev
  omegastep = omegastep / ryd2ev
  
667 668 669 670 671 672 673 674 675 676 677 678 679 680
  IF ( scattering ) THEN
    DO i = 1, ntempxx
      IF (temps(i) .gt. 0.d0) THEN
        nstemp = i
      ENDIF
    ENDDO
    !
    ! go from K to Ry
    temps(:) = temps(:) * kelvin2eV / ryd2ev
    tempsmin = tempsmin * kelvin2eV / ryd2ev
    tempsmax = tempsmax * kelvin2eV / ryd2ev
    !
  ENDIF
  ! 
Samuel Poncé's avatar
Samuel Poncé committed
681
  xq(:) = zero
sponce's avatar
sponce committed
682 683 684 685
  !
  tmp_dir = trim(outdir)
  dvscf_dir = trim(dvscf_dir)//'/'
  !
Samuel Poncé's avatar
Samuel Poncé committed
686
400 CONTINUE
687
  CALL bcast_epw_input
sponce's avatar
sponce committed
688 689 690 691 692 693
  !
  !   Here we finished the reading of the input file.
  !   Now allocate space for pwscf variables, read and check them.
  !
  modenum_aux = modenum
  !
694 695
  ! SP: This initialized xk, nspin and nspin_mag
  IF (epwread .AND. .NOT. epbread) THEN
Samuel Poncé's avatar
Samuel Poncé committed
696
    CONTINUE
697
  ELSE
698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721
    CALL read_file()
    ! 
    ! We define the global list of coarse grid k-points (cart and cryst)
    ALLOCATE (xk_all(3, nkstot))
    ALLOCATE (xk_cryst(3, nkstot))
    xk_all(:,:)   = zero
    xk_cryst(:,:) = zero
    DO ik=1, nkstot
      xk_all(:, ik)   = xk(:, ik)
      xk_cryst(:, ik) = xk(:, ik)
    ENDDO
    !  bring k-points from cartesian to crystal coordinates
    CALL cryst_to_cart(nkstot, xk_cryst, at, -1)
    ! Only master has the correct full list of kpt. Therefore bcast to all cores
    CALL mp_bcast(xk_all, ionode_id, world_comm)
    CALL mp_bcast(xk_cryst, ionode_id, world_comm)
    ! 
    ! We define the local list of kpt
    ALLOCATE (xk_loc(3, nks))
    xk_loc(:,:) = zero
    DO ik=1, nks
      xk_loc(:, ik) = xk(:, ik)
    ENDDO 
    ! 
722
  ENDIF
sponce's avatar
sponce committed
723 724
  !
  ! nbnd comes out of readfile
725
  IF (nbndsub == 0) nbndsub = nbnd
sponce's avatar
sponce committed
726
  !
727
#if defined(__MPI)
728
  IF (.NOT. (me_pool /=0 .OR. my_pool_id /=0)) THEN
sponce's avatar
sponce committed
729 730 731 732 733 734 735 736 737 738 739 740 741
     nk1 = nk1tmp
     nk2 = nk2tmp
     nk3 = nk3tmp
  ENDIF
#else
     nk1 = nk1tmp
     nk2 = nk2tmp
     nk3 = nk3tmp
#endif
  !
  IF (gamma_only) CALL errore('epw_readin',&
     'cannot start from pw.x data file using Gamma-point tricks',1)
  !
742
  IF (modenum_aux /= -1) THEN
sponce's avatar
sponce committed
743 744
     modenum = modenum_aux
     iswitch = -4
745
  ELSEIF (modenum == 0) THEN
sponce's avatar
sponce committed
746 747 748
     iswitch = -2
  ELSE
     iswitch = -4
Samuel Poncé's avatar
Samuel Poncé committed
749
  ENDIF
sponce's avatar
sponce committed
750
  !
Samuel Poncé's avatar
Samuel Poncé committed
751 752
  CALL mp_bcast( iswitch, meta_ionode_id, world_comm )
  CALL mp_bcast( modenum, meta_ionode_id, world_comm )
sponce's avatar
sponce committed
753 754 755 756
  !
  IF (tfixed_occ) &
     CALL errore('epw_readin','phonon with arbitrary occupations not tested',1)
  !
Samuel Poncé's avatar
Samuel Poncé committed
757
  IF (elph.and.lsda) CALL errore('epw_readin', 'El-ph and spin not implemented', 1)
sponce's avatar
sponce committed
758 759 760 761
  !
  !   There might be other variables in the input file which describe
  !   partial computation of the dynamical matrix. Read them here
  !
Samuel Poncé's avatar
Samuel Poncé committed
762
  CALL allocate_part( nat )
sponce's avatar
sponce committed
763
  IF (me_pool /= 0 .or. my_pool_id /=0) goto 800 
Samuel Poncé's avatar
Samuel Poncé committed
764 765
  IF (nat_todo < 0 .OR. nat_todo > nat) & 
     CALL errore('epw_readin', 'nat_todo is wrong', 1)
sponce's avatar
sponce committed
766
  IF (nat_todo.NE.0) THEN
Samuel Poncé's avatar
Samuel Poncé committed
767 768 769
     IF (meta_ionode) READ(5, *, iostat = ios) (atomo(na), na = 1, nat_todo)
     CALL mp_bcast( ios, meta_ionode_id, world_comm)
     CALL mp_bcast( atomo, meta_ionode_id, world_comm )
sponce's avatar
sponce committed
770
  ENDIF
Samuel Poncé's avatar
Samuel Poncé committed
771
800 CONTINUE
772
  CALL bcast_epw_input1
773
  !
sponce's avatar
sponce committed
774
  DO it = 1, ntyp
Samuel Poncé's avatar
Samuel Poncé committed
775
     IF (amass(it) <= 0.d0) CALL errore('epw_readin', 'Wrong masses', it)
sponce's avatar
sponce committed
776
  ENDDO
777
  ! 
Samuel Poncé's avatar
Samuel Poncé committed
778 779 780
! No k+q anymore, can we cut?
!  IF (mod(nks,2) .ne. 0) CALL errore('epw_readin', &
!      'k-points are odd', 0)
sponce's avatar
sponce committed
781 782 783
  !
  !  broadcast the values of nq1, nq2, nq3
  !
784 785 786 787 788 789
  CALL mp_bcast( nq1, meta_ionode_id, world_comm )
  CALL mp_bcast( nq2, meta_ionode_id, world_comm )
  CALL mp_bcast( nq3, meta_ionode_id, world_comm )
  CALL mp_bcast( nk1, meta_ionode_id, world_comm )
  CALL mp_bcast( nk2, meta_ionode_id, world_comm )
  CALL mp_bcast( nk3, meta_ionode_id, world_comm )
sponce's avatar
sponce committed
790 791 792 793
  !
  amass = AMU_RY * amass
  !
  END SUBROUTINE epw_readin