epw_readin.f90 33.4 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 23 24 25 26 27 28
  USE ions_base,     ONLY : nat, ntyp => nsp
  USE mp,            ONLY : mp_bcast 
  USE pwcom,         ONLY : xqq
  USE wvfct,         ONLY : nbnd
  USE klist,         ONLY : nks 
  USE lsda_mod,      ONLY : lsda
  USE fixed_occ,     ONLY : tfixed_occ
29
  USE phcom,         ONLY : time_max => max_seconds
sponce's avatar
sponce committed
30 31 32
  USE qpoint,        ONLY : xq
  USE disp,          ONLY : nq1, nq2, nq3
  USE output,        ONLY : fildvscf, fildrho
33
  USE epwcom,        ONLY : delta_smear, nsmear, dis_win_min, dis_win_max, wannierize, &
34
                            ngaussw, dvscf_dir, eptemp, wdata, &
sponce's avatar
sponce committed
35 36 37
                            num_iter, dis_froz_max, fsthick, dis_froz_min, &
                            vme, degaussw, epexst, eig_read, kmaps, &
                            epwwrite, epbread, phonselfen, elecselfen, &
38 39
                            a2f, rand_k, rand_nq, rand_q, plselfen, &
                            parallel_q, parallel_k, nkf1, specfun_pl, &
40
                            nkf2, nkf3, nqf1, nqf2, nqf3, rand_nk, &
41
                            nest_fn, eps_acustic, nw, wmax, wmin, &
sponce's avatar
sponce committed
42
                            mp_mesh_q, filqf, filkf, delta_qsmear, degaussq, &
43
                            band_plot, ephwrite, mp_mesh_k, nstemp, broyden_beta, &
sponce's avatar
sponce committed
44 45
                            conv_thr_raxis, tempsmax, tempsmin, temps, broyden_ndim, &
                            wscut, wsfc, nqstep, limag, lreal, muc, gap_edge, &
46
                            conv_thr_iaxis, nqsmear, iprint, wepexst, epwread, & 
47
                            eliashberg, imag_read, kerread, kerwrite, lunif, &
sponce's avatar
sponce committed
48 49
                            fermi_energy, efermi_read, max_memlt, fila2f, &
                            ep_coupling, nw_specfun, wmax_specfun, &
50
                            wmin_specfun, laniso, lpolar, lifc, asr_typ, &
51 52
                            lscreen, scr_typ, fermi_diff, smear_rpa, & 
                            cumulant, bnd_cum, proj, write_wfn, iswitch, ntempxx, &
53
                            liso, lacon, lpade, etf_mem, epbwrite, &
54
                            nsiter, conv_thr_racon, specfun_el, specfun_ph, &
55
                            pwc, nswc, nswfc, nswi, filukq, filukk, &
56 57
                            nbndsub, nbndskip, system_2d, delta_approx, &
                            title, int_mob, scissor, iterative_bte, scattering, &
58
                            ncarrier, carrier, scattering_serta, &
59
                            scattering_0rta, longrange, shortrange,restart, &
60
                            restart_freq, prtgkk, nel, meff, epsiHEG
sponce's avatar
sponce committed
61 62 63 64 65 66 67 68 69 70
  USE elph2,         ONLY : elph
  USE start_k,       ONLY : nk1, nk2, nk3
  USE constants_epw, ONLY : ryd2mev, ryd2ev, ev2cmm1, kelvin2eV
  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
71
  USE io_global,     ONLY : meta_ionode, meta_ionode_id, ionode, ionode_id, stdout
72
#if defined(__NAG)
sponce's avatar
sponce committed
73 74
  USE F90_UNIX_ENV,  ONLY : iargc, getarg
#endif
75
  !
sponce's avatar
sponce committed
76
  implicit none
77
  !
78
#if ! defined(__NAG)
sponce's avatar
sponce committed
79 80
  integer :: iargc
#endif
81 82 83 84 85 86 87 88
  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
89 90
  INTEGER :: i
  !! Counter for loops
91 92 93 94 95 96
  INTEGER :: nk1tmp
  !! temp vars for saving kgrid info
  INTEGER :: nk2tmp
  !! temp vars for saving kgrid info
  INTEGER :: nk3tmp  
  !! temp vars for saving kgrid info
97
  LOGICAL, EXTERNAL  :: imatches
sponce's avatar
sponce committed
98 99 100 101
  character(len=256) :: outdir
  namelist / inputepw / &
       amass, outdir, prefix, iverbosity, time_max, fildvscf,                  &
       elph, nq1, nq2, nq3, nk1, nk2, nk3, nbndskip,  nbndsub,                 &
102
       filukk, filukq, epbread, epbwrite, epwread, epwwrite, etf_mem, kmaps,   &
sponce's avatar
sponce committed
103
       eig_read, wepexst, epexst, vme,                                         &
104 105
       degaussw, fsthick, eptemp,  nsmear, delta_smear,                        &
       dvscf_dir, ngaussw,                                                     &
sponce's avatar
sponce committed
106
       wannierize, dis_win_max, dis_win_min, dis_froz_min, dis_froz_max,       &
107
       num_iter, proj,  wdata, iprint, write_wfn, wmin, wmax, nw,              &
108
       eps_acustic, a2f, nest_fn, plselfen,                                    & 
109
       elecselfen, phonselfen, parallel_k, parallel_q,                         &
110
       rand_q, rand_nq, rand_k, rand_nk, specfun_pl,                           &
sponce's avatar
sponce committed
111
       nqf1, nqf2, nqf3, nkf1, nkf2, nkf3,                                     &
112
       mp_mesh_k, mp_mesh_q, filqf, filkf, ephwrite,                           & 
sponce's avatar
sponce committed
113
       band_plot, degaussq, delta_qsmear, nqsmear, nqstep,                     &
114
       nswfc, nswc, nswi, pwc, wsfc, wscut, system_2d,                         &
sponce's avatar
sponce committed
115 116 117
       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,& 
118
       lscreen, scr_typ, fermi_diff, smear_rpa, cumulant, bnd_cum,             &
119
       lifc, asr_typ, lunif, kerwrite, kerread, imag_read, eliashberg,         & 
sponce's avatar
sponce committed
120
       ep_coupling, fila2f, max_memlt, efermi_read, fermi_energy,              &
121
       specfun_el, specfun_ph, wmin_specfun, wmax_specfun, nw_specfun,         & 
122
       delta_approx, scattering, int_mob, scissor, ncarrier, carrier,          &
123
       iterative_bte, scattering_serta, scattering_0rta, longrange, shortrange,&
124
       restart, restart_freq, prtgkk, nel, meff, epsiHEG
125

126
  ! tphases, fildvscf0
sponce's avatar
sponce committed
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
  !
  ! amass    : atomic masses
  ! iverbosity   : verbosity control
  ! outdir   : directory where input, output, temporary files reside
  ! elph     : if true calculate electron-phonon coefficients
  ! time_max : maximum cputime for this run
  ! 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
146
  ! epstrict : if true use strict selection rule for phonon linewidht calculation
sponce's avatar
sponce committed
147 148 149 150 151 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 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
  ! 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
  ! 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
  !
  ! ephwrite : if true write el-phonon matrix elements on the fine mesh to file
  ! eps_acustic : min phonon frequency for e-p and a2f calculations (units of cm-1)
  ! 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
  ! 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
221 222 223 224 225 226
  ! 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
227 228 229 230
  ! 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 
231 232
  ! 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
233
  !
234
  ! added by CV & SP
235 236
  ! 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
237
  ! asr_typ : select type of ASR if lifc=.true. (as in matdyn); otherwise it is the usual simple sum rule
238 239 240 241 242 243 244 245 246
  ! 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
247
  ! 
248 249
  ! Added by SP
  !
250 251
  ! 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
252
  ! specfun_pl      : if .TRUE. calculate plason spectral function 
253 254
  ! restart         : if .true. a run can be restarted from the interpolation level
  ! restart_freq    : Create a restart point every restart_freq q/k-points
255 256 257 258 259 260 261 262 263 264 265
  ! scattering      : if .true. scattering rates are calculated
  ! scattering_serta: if .true. scattering rates are calculated using self-energy relaxation-time-approx
  ! 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
266
  !                   " ncarrier". If ncarrier > 0, electron doping, hole doping otherwise
267 268 269 270
  ! 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. )
271
  ! prtgkk          : Print the vertex |g| [meV]. This generates huge outputs.   
272
  ! etf_mem         : if 0 no optimization, if 1 less memory is used for the fine grid interpolation
273 274
  !                   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".    
275
  ! plselfen        : Calculate the electron-plasmon self-energy.
276 277
  ! nel             : Fractional number of electrons in the unit cell
  ! meff            : Density of state effective mass (in unit of the electron mass)
278
  ! epsiHEG         : Dielectric constant at zero doping
279
  !  
sponce's avatar
sponce committed
280 281 282 283 284 285 286
  CHARACTER (LEN=80)  :: input_file
  INTEGER             :: nargs, iiarg, ierr
  !
  nk1tmp = 0
  nk2tmp = 0
  nk3tmp = 0
  !
287
  IF (meta_ionode) THEN
sponce's avatar
sponce committed
288 289
  !
  ! ... Input from file ?
290
     CALL input_from_file ( )
sponce's avatar
sponce committed
291
  !
292
  ! ... Read the first line of the input file
sponce's avatar
sponce committed
293
  !
294
     READ( 5, '(A)', IOSTAT = ios ) title
sponce's avatar
sponce committed
295
  !
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310
  ENDIF
  ! 
  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  )
  !
  ! Rewind the input if the title is actually the beginning of inputph namelist
  !
  IF( imatches("&inputepw", title) ) THEN
    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
311
  !
312
  IF (.NOT. meta_ionode) goto 400
sponce's avatar
sponce committed
313 314 315 316 317 318 319 320
  !
  !   set default values for variables in namelist
  !
  amass(:)     = 0.d0
  iverbosity   = 0
  elph         = .false.
  elecselfen   = .false.
  phonselfen   = .false.
321
  plselfen     = .false.
322 323
  specfun_el   = .false.
  specfun_ph   = .false.
324
  specfun_pl   = .false.
sponce's avatar
sponce committed
325 326 327 328
  epbread      = .false.
  epbwrite     = .false.
  epwread      = .false.
  epwwrite     = .false.
329 330
  restart      = .false.
  restart_freq = 100
sponce's avatar
sponce committed
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350
  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
  dis_froz_max = -0.9d3
  dis_froz_min = -1d3
  num_iter     = 200
  proj(:)      = ''
  wdata(:)     = ''
  iprint       = 2
  wmin         = 0.d0
  wmax         = 0.3d0
  eps_acustic  = 5.d0 ! cm-1
  nw           = 10
  fsthick      = 1.d10 ! eV
351
  eptemp       = 300.0d0
sponce's avatar
sponce committed
352
  degaussw     = 0.025d0 ! eV
353
!  tphases      = .false.
sponce's avatar
sponce committed
354 355 356
  parallel_k   = .true.
  parallel_q   = .false.
  a2f          = .false.
357
  etf_mem      = 1 
358
!  fildvscf0    = ' '
sponce's avatar
sponce committed
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 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
  ngaussw      = 1
  time_max     = 10000000.d0
  outdir       = '.'
  dvscf_dir    = '.'
  prefix       = 'pwscf'
  filqf        = ' '
  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.
411 412
  lifc    = .false.
  asr_typ = 'simple'
413 414 415 416 417 418 419 420 421 422
  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
423 424 425 426 427 428 429 430 431 432 433 434 435
  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
436 437 438 439
  nstemp   = 1
  tempsmin = 0.d0
  tempsmax = 0.d0
  temps(:) = 0.d0
sponce's avatar
sponce committed
440 441 442 443 444 445 446 447 448 449
  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.
450 451 452
  scattering = .false.
  scattering_serta = .false.
  scattering_0rta = .false.
453
  int_mob    = .false.
454
  iterative_bte = .false.
455 456 457 458
  scissor    = 0.d0 ! eV
  carrier    = .false.
  ncarrier   = 0.d0 ! cm^-3
  longrange  = .false.
459
  shortrange = .false.  
460
  prtgkk     = .false.
461 462 463
  nel        = 0.0d0
  meff       = 1.d0
  epsiHEG    = 1.d0
sponce's avatar
sponce committed
464 465 466
  !
  !     reading the namelist inputepw
  !
467
#if defined(__CRAYY) 
sponce's avatar
sponce committed
468 469 470 471 472
  !   The Cray does not accept "err" and "iostat" together with a namelist
  READ (5, inputepw)
  ios = 0
#else
  !
473
  IF (meta_ionode) READ (5, inputepw, err = 200, iostat = ios)
sponce's avatar
sponce committed
474 475 476 477 478 479 480 481 482 483 484 485
#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)
486
  IF (iverbosity.ne.0.and.iverbosity.ne.1.and.iverbosity.ne.2.and.iverbosity.ne.3) CALL errore ('epw_readin', &
sponce's avatar
sponce committed
487 488
       &' Wrong  iverbosity ', 1)
  IF (time_max.lt.1.d0) CALL errore ('epw_readin', ' Wrong time_max', 1)
489 490
!  IF (tphases.and.fildvscf0.eq.' ') CALL errore ('epw_readin', &
!       &' tphases requires fildvscf0', 1)
sponce's avatar
sponce committed
491 492 493 494 495 496 497 498 499 500 501 502 503 504
  IF (epbread.and.epbwrite) CALL errore ('epw_readin', &
       &' epbread cannot be used with epbwrite', 1)
  IF (degaussw*4.d0.gt.fsthick) CALL errore ('epw_readin', &
       &' degaussw too close to fsthick', 1)
  IF ( nbndskip .lt. 0) CALL errore('epw_readin', &
       &' nbndskip must not be less than 0', 1)
  IF ((nw.lt.1).or.(nw.gt.1000)) CALL errore ('epw_readin', &
       &' unreasonable nw', 1)
  IF (parallel_k .and. parallel_q) CALL errore('epw_readin', &
       &'can only parallelize over k OR q',1)
  IF (.not.(parallel_k .or. parallel_q)) CALL errore('epw_readin', &
       &'must parallelize over k OR q',1)
  IF (parallel_k .and. elecselfen) CALL errore('epw_readin', &
       &'Electron selfenergy is more efficient with k_para',-1)
505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524
  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 (parallel_q .and. plselfen) CALL errore('epw_readin', &
       &'Electron-plasmon self-energy cannot be computed with q-parallelization',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)
  IF (parallel_q .and. specfun_pl) CALL errore('epw_readin', &
       &'Electron-plasmon spectral function cannot be computed with q-parallelization',1)
sponce's avatar
sponce committed
525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546
  IF (a2f .and. .not.phonselfen) CALL errore('epw_readin', &
       &'a2f requires phonoselfen',1)
  IF (parallel_q .and. phonselfen) CALL errore('epw_readin', &
       &'Phonon selfenergy is more efficient with q_para',-1)
  IF (parallel_q) CALL errore('epw_readin', &
       &'WARNING: Parallel q not tested!', -1)
  IF (elph .and. .not.ep_coupling ) CALL errore('epw_readin', &
      &'elph requires ep_coupling=.true.',1)
  IF ( (elph.and.wannierize) .and. (epwread) ) CALL errore('epw_readin', &
       & 'must use same w90 rotation matrix for entire run', 1)
  IF (wannierize .and. .not.ep_coupling ) CALL errore('epw_readin', &
      &'wannierize requires ep_coupling=.true.',1)
  IF ((wmin.gt.wmax)) &
       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)
  IF ((nbndsub.gt.200)) CALL errore ('epw_readin', & 
       ' too many wannier functions increase size of projx', 1)
547
  IF (( phonselfen .or. elecselfen .or. specfun_el .or. specfun_ph ) .and. ( mp_mesh_k .or. mp_mesh_q )) & 
sponce's avatar
sponce committed
548 549 550 551 552 553 554 555 556
     CALL errore('epw_readin', 'can only work with full uniform mesh',1)
  IF (ephwrite .and. .not.ep_coupling .and. .not.elph ) CALL errore('epw_readin', &
      &'ephwrite requires ep_coupling=.true., elph=.true.',1)
  IF (ephwrite .and. (rand_k .OR. rand_q ) ) &
     CALL errore('epw_readin', 'ephwrite requires a uniform grid',1) 
  IF (ephwrite .and. (mod(nkf1,nqf1) .ne. 0 .OR. mod(nkf2,nqf2) .ne. 0 .OR. mod(nkf3,nqf3) .ne. 0 ) ) &
     CALL errore('epw_readin', 'ephwrite requires nkf1,nkf2,nkf3 to be multiple of nqf1,nqf2,nqf3',1)
  IF (band_plot .and. filkf .eq. ' ' .and. filqf .eq. ' ') CALL errore('epw_readin', &
      &'plot band structure and phonon dispersion requires k- and q-points read from filkf and filqf files',1)
557 558
  IF (band_plot .and. parallel_q ) CALL errore('epw_readin', &
      &'band_plot can only be used with parallel_k',1)    
559 560 561 562
  IF (band_plot .and. filkf .ne. ' ' .and. (nkf1 > 0 .or. nkf2 > 0 .or. nkf3 > 0) ) CALL errore('epw_readin', &
                &'You should define either filkf or nkf when band_plot = .true.',1)
  IF (band_plot .and. filqf .ne. ' ' .and. (nqf1 > 0 .or. nqf2 > 0 .or. nqf3 > 0) ) CALL errore('epw_readin', &
                &'You should define either filqf or nqf when band_plot = .true.',1)
sponce's avatar
sponce committed
563 564
  IF ( filkf .ne. ' ' .and. .not.efermi_read ) CALL errore('epw_readin', &
      &'WARNING: if k-points are along a line, then efermi_read=.true. and fermi_energy must be given in the input file',-1)
565 566 567 568 569 570 571 572 573 574 575 576 577 578
  IF ( scattering .AND. nstemp < 1 ) CALL errore('epw_init', &
       'wrong number of nstemp',1)
  IF ( scattering .AND. maxval(temps(:)) > 0.d0 .AND. tempsmin > 0.d0 .AND. tempsmax > 0.d0 ) &
       CALL errore('epw_init', 'define either (tempsmin and tempsmax) or temps(:)',1)
  IF ( scattering .AND. tempsmax < tempsmin ) &
       CALL errore('epw_init', 'tempsmax should be greater than tempsmin',1)
  IF ( int_mob .AND. efermi_read)  CALL errore('epw_init', &
       'Fermi level can not be set (efermi_read) when computing intrinsic mobilities',1)
  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)
  IF ( carrier .AND. (ABS(ncarrier) < 1E+5) )  CALL errore('epw_init', &
       'The absolute value of the doping carrier concentration must be larger than 1E5 cm^-3',1)
  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)
579 580 581 582
  IF ( (longrange .OR. shortrange) .AND. (.not. lpolar)) CALL errore('epw_init',&
       &'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)
583 584
  IF ( epwread .AND. .not. kmaps .AND. .not. epbread) CALL errore('epw_init',&
       &'Error: kmaps has to be true for a restart run. ',1)
585 586
  IF ( etf_mem == 2 .AND. parallel_q) CALL errore('epw_init',&
       &'Error: Memory optimized version and q-parallelization not implemented. ',1)
587 588 589 590 591 592
  IF ( lscreen .AND. parallel_q) CALL errore('epw_init',&
       &'Error: lscreen can only be used with parallel_k ',1)
  IF ( lscreen .AND. etf_mem == 2) CALL errore('epw_init',&
       &'Error: lscreen not implemented with etf_mem=2 ',1)
  IF ( cumulant .AND. parallel_q ) CALL errore('epw_init',&
       &'Error: Cumulant and parallel_q is not implemented ',1)
593 594 595
!#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
596 597 598 599 600 601 602 603 604 605 606 607 608 609 610
  !
  ! thickness and smearing width of the Fermi surface  
  ! from eV to Ryd
  fsthick = fsthick / ryd2ev 
  degaussw = degaussw / ryd2ev 
  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
611
    fermi_energy = fermi_energy / ryd2ev
sponce's avatar
sponce committed
612 613
  ENDIF
  ! eptemp : temperature for the electronic Fermi occupations in the e-p calculation (units of Kelvin)
614 615 616 617 618 619 620 621 622 623 624
  ! 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
625 626 627 628 629 630 631 632 633 634 635 636 637 638
  !
  ! 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
  !
639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655
  ! scissor going from eV to Ryd
  scissor = scissor / ryd2ev
  ! 
  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
  ! 
sponce's avatar
sponce committed
656 657 658 659 660 661
  xq(:) = 0.d0
  !
  tmp_dir = trim(outdir)
  dvscf_dir = trim(dvscf_dir)//'/'
  !
400 continue
662
  CALL bcast_epw_input
sponce's avatar
sponce committed
663 664 665 666 667 668 669 670
  xqq(:) = xq(:) 
  !
  !   Here we finished the reading of the input file.
  !   Now allocate space for pwscf variables, read and check them.
  !
  modenum_aux = modenum
  !
  ! SP: This initialized nspin and nspin_mag
671 672 673 674 675
  IF ( epwread .and. .not. epbread ) then
    continue
  ELSE
    CALL read_file
  ENDIF
sponce's avatar
sponce committed
676 677 678 679
  !
  ! nbnd comes out of readfile
  IF (nbndsub.eq.0) nbndsub = nbnd
  !
680
#if defined(__MPI)
sponce's avatar
sponce committed
681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703
  IF (.not.(me_pool /=0 .or. my_pool_id /=0)) THEN
     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)
  !
  IF (modenum_aux .ne. -1) THEN
     modenum = modenum_aux
     iswitch = -4
  ELSE IF (modenum .eq. 0) THEN
     iswitch = -2
  ELSE
     iswitch = -4
  END IF
  !
704 705
  CALL mp_bcast ( iswitch, meta_ionode_id, world_comm )
  CALL mp_bcast ( modenum, meta_ionode_id, world_comm)
sponce's avatar
sponce committed
706 707 708 709
  !
  IF (tfixed_occ) &
     CALL errore('epw_readin','phonon with arbitrary occupations not tested',1)
  !
710
  IF (elph.and.lsda) CALL errore ('epw_readin', 'El-ph and spin not implemented', 1)
sponce's avatar
sponce committed
711 712 713 714 715
  !
  !   There might be other variables in the input file which describe
  !   partial computation of the dynamical matrix. Read them here
  !
  CALL allocate_part ( nat )
sponce's avatar
sponce committed
716
  IF (me_pool /= 0 .or. my_pool_id /=0) goto 800 
sponce's avatar
sponce committed
717 718 719
  IF (nat_todo < 0 .OR. nat_todo > nat) CALL errore ('epw_readin', &
       'nat_todo is wrong', 1)
  IF (nat_todo.NE.0) THEN
720 721
     IF (meta_ionode)read (5, *, iostat = ios) (atomo (na), na = 1, nat_todo)
     CALL mp_bcast(ios, meta_ionode_id, world_comm  )
sponce's avatar
sponce committed
722
700  CALL errore ('epw_readin', 'reading atomo', abs (ios) )
723
     CALL mp_bcast(atomo, meta_ionode_id, world_comm )
sponce's avatar
sponce committed
724 725
  ENDIF
800 continue
726
  CALL bcast_epw_input1
727
  !
sponce's avatar
sponce committed
728 729 730
  DO it = 1, ntyp
     IF (amass (it) <= 0.d0) CALL errore ('epw_readin', 'Wrong masses', it)
  ENDDO
731
  ! 
sponce's avatar
sponce committed
732 733 734 735 736 737
! No k+q anymore, can we cut?
  IF (mod (nks, 2) .ne.0) CALL errore ('epw_readin', &
      'k-points are odd', 0)
  !
  !  broadcast the values of nq1, nq2, nq3
  !
738 739 740 741 742 743
  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
744 745 746 747
  !
  amass = AMU_RY * amass
  !
  END SUBROUTINE epw_readin