/PP/projwfc.f90

http://github.com/NNemec/quantum-espresso · Fortran Modern · 3396 lines · 2435 code · 88 blank · 873 comment · 76 complexity · c6d124e28c2f01f15117431d03835acc MD5 · raw file

Large files are truncated click here to view the full file

  1. !
  2. ! Copyright (C) 2001-2009 Quantum ESPRESSO group
  3. ! This file is distributed under the terms of the
  4. ! GNU General Public License. See the file `License'
  5. ! in the root directory of the present distribution,
  6. ! or http://www.gnu.org/copyleft/gpl.txt .
  7. !
  8. !-----------------------------------------------------------------------
  9. PROGRAM projwfc
  10. !-----------------------------------------------------------------------
  11. !
  12. ! projects wavefunctions onto orthogonalized atomic wavefunctions,
  13. ! calculates Lowdin charges, spilling parameter, projected DOS
  14. ! or computes the LDOS in a volume given in input as function of energy
  15. !
  16. !
  17. ! Input (namelist &inputpp ... / ): Default value
  18. !
  19. ! prefix prefix of input file produced by pw.x 'pwscf'
  20. ! (wavefunctions are needed)
  21. ! outdir directory containing the input file ./
  22. ! ngauss type of gaussian broadening (optional) 0
  23. ! = 0 Simple Gaussian (default)
  24. ! = 1 Methfessel-Paxton of order 1
  25. ! = -1 Marzari-Vanderbilt "cold smearing"
  26. ! =-99 Fermi-Dirac function
  27. ! degauss gaussian broadening, Ry (not eV!) 0.0
  28. ! Emin, Emax min, max energy (eV) for DOS plot band extrema
  29. ! DeltaE energy grid step (eV) none
  30. ! lsym if true the projections are symmetrized .true.
  31. ! filproj file containing the projections none
  32. ! filpdos prefix for output files containing PDOS(E) prefix
  33. ! lgww if .true. take energies from previous GWW calculation
  34. ! (file bands.dat)
  35. ! kresolveddos if .true. the DOS is written as function .false.
  36. ! of the k-point (not summed over all of them)
  37. ! all k-points but results
  38. ! tdosinboxes if .true., the local DOS in specified .false.
  39. ! volumes (boxes) is computed
  40. ! n_proj_boxes number of volumes for the local DOS 0
  41. ! irmin, irmax first and last point of the FFT grid 1, 0
  42. ! included in the volume
  43. ! plotboxes if .true., the volumes are given in output .false.
  44. !
  45. !
  46. ! Output:
  47. !
  48. ! Projections are written to standard output,
  49. ! and also to file filproj if given as input.
  50. ! The total DOS and the sum of projected DOS are written to file
  51. ! "filpdos".pdos_tot.
  52. ! The format for the collinear, spin-unpolarized case and the
  53. ! non-collinear, spin-orbit case is
  54. ! E DOS(E) PDOS(E)
  55. ! The format for the collinear, spin-polarized case is
  56. ! E DOSup(E) DOSdw(E) PDOSup(E) PDOSdw(E)
  57. ! The format for the non-collinear, non spin-orbit case is
  58. ! E DOS(E) PDOSup(E) PDOSdw(E)
  59. !
  60. ! In the collinear case and the non-collinear, non spin-orbit case
  61. ! projected DOS are written to file "filpdos".pdos_atm#N(X)_wfc#M(l),
  62. ! where N = atom number , X = atom symbol, M = wfc number, l=s,p,d,f
  63. ! (one file per atomic wavefunction found in the pseudopotential file)
  64. ! - The format for the collinear, spin-unpolarized case is
  65. ! E LDOS(E) PDOS_1(E) ... PDOS_2l+1(E)
  66. ! where LDOS = \sum m=1,2l+1 PDOS_m(E)
  67. ! and PDOS_m(E) = projected DOS on atomic wfc with component m
  68. ! - The format for the collinear, spin-polarized case and the
  69. ! non-collinear, non spin-orbit case is as above with
  70. ! two components for both LDOS(E) and PDOS_m(E)
  71. !
  72. ! In the non-collinear, spin-orbit case (i.e. if there is at least one
  73. ! fully relativistic pseudopotential) wavefunctions are projected
  74. ! onto eigenstates of the total angular-momentum.
  75. ! Projected DOS are written to file "filpdos".pdos_atm#N(X)_wfc#M(l_j),
  76. ! where N = atom number , X = atom symbol, M = wfc number, l=s,p,d,f
  77. ! and j is the value of the total angular momentum.
  78. ! In this case the format is
  79. ! E LDOS(E) PDOS_1(E) ... PDOS_2j+1(E)
  80. !
  81. ! All DOS(E) are in states/eV plotted vs E in eV
  82. !
  83. ! If the kresolveddos option is used, the k-point index is prepended
  84. ! to the formats above, e.g. (collinear, spin-unpolarized case)
  85. ! ik E DOS(E) PDOS(E)
  86. !
  87. ! If the local DOS(E) is computed (tdosinboxes),
  88. ! projections are written to file "filproj" if given as input.
  89. ! Volumes are written as xsf files with 3D datagrids, valued 1.0
  90. ! inside the box volume and 0 outside, named filpdos.box#n.xsf
  91. ! The local DOS(E) is written to file "filpdos".ldos_boxes, with format
  92. ! E totDOS(E) SumLDOS(E) LDOS_1(E) ... LDOS_n(E)
  93. !
  94. ! Order of m-components for each l in the output:
  95. !
  96. ! 1, cos(phi), sin(phi), cos(2*phi), sin(2*phi), .., cos(l*phi), sin(l*phi)
  97. !
  98. ! where phi is the polar angle:x=r cos(theta)cos(phi), y=r cos(theta)sin(phi)
  99. ! This is determined in file flib/ylmr2.f90 that calculates spherical harm.
  100. ! L=1 :
  101. ! 1 pz (m=0)
  102. ! 2 px (real combination of m=+/-1 with cosine)
  103. ! 3 py (real combination of m=+/-1 with sine)
  104. ! L=2 :
  105. ! 1 dz2 (m=0)
  106. ! 2 dzx (real combination of m=+/-1 with cosine)
  107. ! 3 dzy (real combination of m=+/-1 with sine)
  108. ! 4 dx2-y2 (real combination of m=+/-2 with cosine)
  109. ! 5 dxy (real combination of m=+/-1 with sine)
  110. !
  111. ! Important notice:
  112. !
  113. ! The tetrahedron method is presently not implemented.
  114. ! Gaussian broadening is used in all cases:
  115. ! - if degauss is set to some value in namelist &inputpp, that value
  116. ! (and the optional value for ngauss) is used
  117. ! - if degauss is NOT set to any value in namelist &inputpp, the
  118. ! value of degauss and of ngauss are read from the input data
  119. ! file (they will be the same used in the pw.x calculations)
  120. ! - if degauss is NOT set to any value in namelist &inputpp, AND
  121. ! there is no value of degauss and of ngauss in the input data
  122. ! file, degauss=DeltaE (in Ry) and ngauss=0 will be used
  123. ! Obsolete variables, ignored:
  124. ! io_choice
  125. ! smoothing
  126. !
  127. USE io_global, ONLY : stdout, ionode, ionode_id
  128. USE constants, ONLY : rytoev
  129. USE kinds, ONLY : DP
  130. USE klist, ONLY : degauss, ngauss, lgauss
  131. USE io_files, ONLY : nd_nmbr, prefix, tmp_dir, trimcheck
  132. USE noncollin_module, ONLY : noncolin
  133. USE mp, ONLY : mp_bcast
  134. USE mp_global, ONLY : mp_startup, nproc_ortho
  135. USE environment, ONLY : environment_start
  136. !
  137. ! for GWW
  138. USE io_files, ONLY : find_free_unit
  139. !
  140. !
  141. IMPLICIT NONE
  142. CHARACTER (len=256) :: filpdos, filproj, io_choice, outdir
  143. REAL (DP) :: Emin, Emax, DeltaE, degauss1, smoothing
  144. INTEGER :: ngauss1, ios
  145. LOGICAL :: lsym, kresolveddos, tdosinboxes, plotboxes
  146. INTEGER, PARAMETER :: N_MAX_BOXES = 999
  147. INTEGER :: n_proj_boxes, irmin(3,N_MAX_BOXES), irmax(3,N_MAX_BOXES)
  148. !
  149. ! for GWW
  150. INTEGER :: iun, idum
  151. REAL(DP) :: rdum1,rdum2,rdum3
  152. LOGICAL :: lex, lgww
  153. !
  154. !
  155. NAMELIST / inputpp / outdir, prefix, ngauss, degauss, lsym, &
  156. Emin, Emax, DeltaE, io_choice, smoothing, filpdos, filproj, &
  157. lgww, & !if .true. use GW QP energies from file bands.dat
  158. kresolveddos, tdosinboxes, n_proj_boxes, irmin, irmax, plotboxes
  159. !
  160. ! initialise environment
  161. !
  162. #ifdef __PARA
  163. CALL mp_startup ( )
  164. #endif
  165. CALL environment_start ( 'PROJWFC' )
  166. !
  167. ! set default values for variables in namelist
  168. !
  169. prefix = 'pwscf'
  170. CALL get_env( 'ESPRESSO_TMPDIR', outdir )
  171. IF ( trim( outdir ) == ' ' ) outdir = './'
  172. filproj= ' '
  173. filpdos= ' '
  174. Emin =-1000000.d0
  175. Emax =+1000000.d0
  176. DeltaE = 0.01d0
  177. ngauss = 0
  178. lsym = .true.
  179. degauss= 0.d0
  180. lgww = .false.
  181. kresolveddos = .false.
  182. tdosinboxes = .false.
  183. plotboxes = .false.
  184. n_proj_boxes= 1
  185. irmin(:,:) = 1
  186. irmax(:,:) = 0
  187. !
  188. ios = 0
  189. !
  190. IF ( ionode ) THEN
  191. !
  192. CALL input_from_file ( )
  193. !
  194. READ (5, inputpp, iostat = ios)
  195. !
  196. tmp_dir = trimcheck (outdir)
  197. ! save the value of degauss and ngauss: they are read from file
  198. degauss1=degauss
  199. ngauss1 = ngauss
  200. !
  201. ENDIF
  202. !
  203. CALL mp_bcast (ios, ionode_id )
  204. !
  205. IF (ios /= 0) CALL errore ('projwfc', 'reading inputpp namelist', abs (ios) )
  206. !
  207. ! ... Broadcast variables
  208. !
  209. CALL mp_bcast( tmp_dir, ionode_id )
  210. CALL mp_bcast( prefix, ionode_id )
  211. CALL mp_bcast( filproj, ionode_id )
  212. CALL mp_bcast( ngauss1, ionode_id )
  213. CALL mp_bcast( degauss1,ionode_id )
  214. CALL mp_bcast( DeltaE, ionode_id )
  215. CALL mp_bcast( lsym, ionode_id )
  216. CALL mp_bcast( Emin, ionode_id )
  217. CALL mp_bcast( Emax, ionode_id )
  218. ! for GWW
  219. CALL mp_bcast( lgww, ionode_id )
  220. ! for projection on boxes
  221. CALL mp_bcast( tdosinboxes, ionode_id )
  222. CALL mp_bcast( n_proj_boxes, ionode_id )
  223. CALL mp_bcast( irmin, ionode_id )
  224. CALL mp_bcast( irmax, ionode_id )
  225. !
  226. ! Now allocate space for pwscf variables, read and check them.
  227. !
  228. CALL read_file ( )
  229. !
  230. CALL openfil_pp ( )
  231. !
  232. ! decide Gaussian broadening
  233. !
  234. IF (degauss1/=0.d0) THEN
  235. degauss=degauss1
  236. ngauss =ngauss1
  237. WRITE( stdout,'(/5x,"Gaussian broadening (read from input): ",&
  238. & "ngauss,degauss=",i4,f12.6/)') ngauss,degauss
  239. lgauss=.true.
  240. ELSEIF (lgauss) THEN
  241. WRITE( stdout,'(/5x,"Gaussian broadening (read from file): ",&
  242. & "ngauss,degauss=",i4,f12.6/)') ngauss,degauss
  243. ELSE
  244. degauss=DeltaE/rytoev
  245. ngauss =0
  246. WRITE( stdout,'(/5x,"Gaussian broadening (default values): ",&
  247. & "ngauss,degauss=",i4,f12.6/)') ngauss,degauss
  248. lgauss=.true.
  249. ENDIF
  250. !
  251. IF ( filpdos == ' ') filpdos = prefix
  252. !
  253. IF ( tdosinboxes ) THEN
  254. IF( nproc_ortho > 1 ) THEN
  255. CALL errore ('projwfc', 'nproc_ortho > 1 not yet implemented', 1)
  256. ELSE
  257. CALL projwave_boxes (filpdos, filproj, n_proj_boxes, irmin, irmax, plotboxes)
  258. ENDIF
  259. ELSE
  260. IF (noncolin) THEN
  261. CALL projwave_nc(filproj, lsym )
  262. ELSE
  263. IF( nproc_ortho > 1 ) THEN
  264. CALL pprojwave (filproj, lsym)
  265. ELSE
  266. CALL projwave (filproj, lsym, lgww)
  267. ENDIF
  268. ENDIF
  269. ENDIF
  270. !
  271. IF ( ionode ) THEN
  272. IF ( tdosinboxes ) THEN
  273. CALL partialdos_boxes (Emin, Emax, DeltaE, kresolveddos, filpdos, n_proj_boxes)
  274. ELSE
  275. IF ( lsym ) THEN
  276. !
  277. IF (noncolin) THEN
  278. CALL partialdos_nc (Emin, Emax, DeltaE, kresolveddos, filpdos)
  279. ELSE
  280. CALL partialdos (Emin, Emax, DeltaE, kresolveddos, filpdos)
  281. ENDIF
  282. !
  283. ENDIF
  284. ENDIF
  285. ENDIF
  286. !
  287. CALL stop_pp
  288. !
  289. END PROGRAM projwfc
  290. !
  291. MODULE projections
  292. USE kinds, ONLY : DP
  293. TYPE wfc_label
  294. INTEGER na, n, l, m
  295. END TYPE wfc_label
  296. TYPE(wfc_label), ALLOCATABLE :: nlmchi(:)
  297. REAL (DP), ALLOCATABLE :: proj (:,:,:)
  298. COMPLEX (DP), ALLOCATABLE :: proj_aux (:,:,:)
  299. END MODULE projections
  300. !
  301. MODULE projections_nc
  302. USE kinds, ONLY : DP
  303. TYPE wfc_label_nc
  304. INTEGER na, n, l, m, ind
  305. REAL (DP) jj
  306. END TYPE wfc_label_nc
  307. TYPE(wfc_label_nc), ALLOCATABLE :: nlmchi(:)
  308. REAL (DP), ALLOCATABLE :: proj (:,:,:)
  309. COMPLEX (DP), ALLOCATABLE :: proj_aux (:,:,:)
  310. END MODULE projections_nc
  311. !
  312. MODULE projections_ldos
  313. USE kinds, ONLY : DP
  314. REAL (DP), ALLOCATABLE :: proj (:,:,:)
  315. END MODULE projections_ldos
  316. !
  317. !-----------------------------------------------------------------------
  318. SUBROUTINE projwave( filproj, lsym, lgww )
  319. !-----------------------------------------------------------------------
  320. !
  321. USE io_global, ONLY : stdout, ionode
  322. USE printout_base, ONLY: title
  323. USE ions_base, ONLY : zv, tau, nat, ntyp => nsp, ityp, atm
  324. USE basis, ONLY : natomwfc
  325. USE cell_base
  326. USE constants, ONLY: rytoev, eps4
  327. USE gvect
  328. USE grid_dimensions, ONLY : nr1, nr2, nr3, nr1x, nr2x, nr3x
  329. USE klist, ONLY: xk, nks, nkstot, nelec
  330. USE ldaU
  331. USE lsda_mod, ONLY: nspin, isk, current_spin
  332. USE symm_base, ONLY: nsym, irt, d1, d2, d3
  333. USE wvfct
  334. USE control_flags, ONLY: gamma_only
  335. USE uspp, ONLY: nkb, vkb
  336. USE uspp_param, ONLY: upf
  337. USE becmod, ONLY: bec_type, becp, calbec, allocate_bec_type, deallocate_bec_type
  338. USE io_files, ONLY: nd_nmbr, prefix, tmp_dir, nwordwfc, iunwfc, find_free_unit
  339. USE spin_orb, ONLY: lspinorb
  340. USE wavefunctions_module, ONLY: evc
  341. !
  342. USE projections
  343. !
  344. IMPLICIT NONE
  345. !
  346. CHARACTER (len=*) :: filproj
  347. INTEGER :: ik, ibnd, i, j, k, na, nb, nt, isym, n, m, m1, l, nwfc,&
  348. nwfc1, lmax_wfc, is, ios, iunproj
  349. REAL(DP), ALLOCATABLE :: e (:)
  350. COMPLEX(DP), ALLOCATABLE :: wfcatom (:,:)
  351. COMPLEX(DP), ALLOCATABLE :: overlap(:,:), work(:,:),work1(:), proj0(:,:)
  352. ! Some workspace for k-point calculation ...
  353. REAL (DP), ALLOCATABLE ::roverlap(:,:), rwork1(:),rproj0(:,:)
  354. ! ... or for gamma-point.
  355. REAL(DP), ALLOCATABLE :: charges(:,:,:), proj1 (:)
  356. REAL(DP) :: psum, totcharge(2)
  357. INTEGER :: nksinit, nkslast
  358. CHARACTER(len=256) :: filename
  359. CHARACTER (len=1) :: l_label(0:3)=(/'s','p','d','f'/)
  360. INTEGER, ALLOCATABLE :: idx(:)
  361. LOGICAL :: lsym
  362. !
  363. !
  364. ! for GWW
  365. INTEGER :: iun, idum
  366. REAL(DP) :: rdum1,rdum2,rdum3
  367. LOGICAL :: lex, lgww
  368. !
  369. !
  370. WRITE( stdout, '(/5x,"Calling projwave .... ")')
  371. IF ( gamma_only ) THEN
  372. WRITE( stdout, '(5x,"gamma-point specific algorithms are used")')
  373. ENDIF
  374. !
  375. ! initialize D_Sl for l=1, l=2 and l=3, for l=0 D_S0 is 1
  376. !
  377. CALL d_matrix (d1, d2, d3)
  378. !
  379. ! fill structure nlmchi
  380. !
  381. ALLOCATE (nlmchi(natomwfc))
  382. nwfc=0
  383. lmax_wfc = 0
  384. DO na = 1, nat
  385. nt = ityp (na)
  386. DO n = 1, upf(nt)%nwfc
  387. IF (upf(nt)%oc (n) >= 0.d0) THEN
  388. l = upf(nt)%lchi (n)
  389. lmax_wfc = max (lmax_wfc, l )
  390. DO m = 1, 2 * l + 1
  391. nwfc=nwfc+1
  392. nlmchi(nwfc)%na = na
  393. nlmchi(nwfc)%n = n
  394. nlmchi(nwfc)%l = l
  395. nlmchi(nwfc)%m = m
  396. ENDDO
  397. ENDIF
  398. ENDDO
  399. ENDDO
  400. !
  401. IF (lmax_wfc > 3) CALL errore ('projwave', 'l > 3 not yet implemented', 1)
  402. IF (nwfc /= natomwfc) CALL errore ('projwave', 'wrong # of atomic wfcs?', 1)
  403. !
  404. ALLOCATE( proj (natomwfc, nbnd, nkstot) )
  405. ALLOCATE( proj_aux (natomwfc, nbnd, nkstot) )
  406. proj = 0.d0
  407. proj_aux = (0.d0, 0.d0)
  408. !
  409. IF (.not. lda_plus_u) ALLOCATE(swfcatom (npwx , natomwfc ) )
  410. ALLOCATE(wfcatom (npwx, natomwfc) )
  411. ALLOCATE(overlap (natomwfc, natomwfc) )
  412. overlap= (0.d0,0.d0)
  413. !
  414. IF ( gamma_only ) THEN
  415. ALLOCATE(roverlap (natomwfc, natomwfc) )
  416. roverlap= 0.d0
  417. ENDIF
  418. CALL allocate_bec_type (nkb, natomwfc, becp )
  419. ALLOCATE(e (natomwfc) )
  420. !
  421. ! loop on k points
  422. !
  423. CALL init_us_1
  424. CALL init_at_1
  425. !
  426. DO ik = 1, nks
  427. CALL gk_sort (xk (1, ik), ngm, g, ecutwfc / tpiba2, npw, igk, g2kin)
  428. CALL davcio (evc, nwordwfc, iunwfc, ik, - 1)
  429. CALL atomic_wfc (ik, wfcatom)
  430. CALL init_us_2 (npw, igk, xk (1, ik), vkb)
  431. CALL calbec ( npw, vkb, wfcatom, becp)
  432. CALL s_psi (npwx, npw, natomwfc, wfcatom, swfcatom)
  433. !
  434. ! wfcatom = |phi_i> , swfcatom = \hat S |phi_i>
  435. ! calculate overlap matrix O_ij = <phi_i|\hat S|\phi_j>
  436. !
  437. IF ( gamma_only ) THEN
  438. CALL calbec ( npw, wfcatom, swfcatom, roverlap )
  439. overlap(:,:)=cmplx(roverlap(:,:),0.0_dp, kind=dp)
  440. ! TEMP: diagonalization routine for real matrix should be used instead
  441. ELSE
  442. CALL calbec ( npw, wfcatom, swfcatom, overlap )
  443. ENDIF
  444. !
  445. ! calculate O^{-1/2}
  446. !
  447. ALLOCATE(work (natomwfc, natomwfc) )
  448. CALL cdiagh (natomwfc, overlap, natomwfc, e, work)
  449. DO i = 1, natomwfc
  450. e (i) = 1.d0 / dsqrt (e (i) )
  451. ENDDO
  452. DO i = 1, natomwfc
  453. DO j = i, natomwfc
  454. overlap (i, j) = (0.d0, 0.d0)
  455. DO k = 1, natomwfc
  456. overlap (i, j) = overlap (i, j) + e (k) * work (j, k) * conjg (work (i, k) )
  457. ENDDO
  458. IF (j /= i) overlap (j, i) = conjg (overlap (i, j))
  459. ENDDO
  460. ENDDO
  461. DEALLOCATE (work)
  462. !
  463. ! calculate wfcatom = O^{-1/2} \hat S | phi>
  464. !
  465. IF ( gamma_only ) THEN
  466. roverlap(:,:)=REAL(overlap(:,:),DP)
  467. ! TEMP: diagonalization routine for real matrix should be used instead
  468. CALL DGEMM ('n', 't', 2*npw, natomwfc, natomwfc, 1.d0 , &
  469. swfcatom, 2*npwx, roverlap, natomwfc, 0.d0, wfcatom, 2*npwx)
  470. ELSE
  471. CALL ZGEMM ('n', 't', npw, natomwfc, natomwfc, (1.d0, 0.d0) , &
  472. swfcatom, npwx, overlap, natomwfc, (0.d0, 0.d0), wfcatom, npwx)
  473. ENDIF
  474. !
  475. ! make the projection <psi_i| O^{-1/2} \hat S | phi_j>
  476. !
  477. IF ( gamma_only ) THEN
  478. !
  479. ALLOCATE(rproj0(natomwfc,nbnd), rwork1 (nbnd) )
  480. CALL calbec ( npw, wfcatom, evc, rproj0)
  481. !
  482. proj_aux(:,:,ik) = cmplx( rproj0(:,:), 0.0_dp, kind=dp )
  483. !
  484. ELSE
  485. !
  486. ALLOCATE(proj0(natomwfc,nbnd), work1 (nbnd) )
  487. CALL calbec ( npw, wfcatom, evc, proj0)
  488. !
  489. proj_aux(:,:,ik) = proj0(:,:)
  490. !
  491. ENDIF
  492. !
  493. ! symmetrize the projections
  494. !
  495. IF (lsym) THEN
  496. DO nwfc = 1, natomwfc
  497. !
  498. ! atomic wavefunction nwfc is on atom na
  499. !
  500. na= nlmchi(nwfc)%na
  501. n = nlmchi(nwfc)%n
  502. l = nlmchi(nwfc)%l
  503. m = nlmchi(nwfc)%m
  504. !
  505. DO isym = 1, nsym
  506. nb = irt (isym, na)
  507. DO nwfc1 =1, natomwfc
  508. IF (nlmchi(nwfc1)%na == nb .and. &
  509. nlmchi(nwfc1)%n == nlmchi(nwfc)%n .and. &
  510. nlmchi(nwfc1)%l == nlmchi(nwfc)%l .and. &
  511. nlmchi(nwfc1)%m == 1 ) GOTO 10
  512. ENDDO
  513. CALL errore('projwave','cannot symmetrize',1)
  514. 10 nwfc1=nwfc1-1
  515. !
  516. ! nwfc1 is the first rotated atomic wfc corresponding to nwfc
  517. !
  518. IF ( gamma_only ) THEN
  519. IF (l == 0) THEN
  520. rwork1(:) = rproj0 (nwfc1 + 1,:)
  521. ELSEIF (l == 1) THEN
  522. rwork1(:) = 0.d0
  523. DO m1 = 1, 3
  524. rwork1(:)=rwork1(:)+d1(m1,m,isym)*rproj0(nwfc1+m1,:)
  525. ENDDO
  526. ELSEIF (l == 2) THEN
  527. rwork1(:) = 0.d0
  528. DO m1 = 1, 5
  529. rwork1(:)=rwork1(:)+d2(m1,m,isym)*rproj0(nwfc1+m1,:)
  530. ENDDO
  531. ELSEIF (l == 3) THEN
  532. rwork1(:) = 0.d0
  533. DO m1 = 1, 7
  534. rwork1(:)=rwork1(:)+d3(m1,m,isym)*rproj0(nwfc1+m1,:)
  535. ENDDO
  536. ENDIF
  537. DO ibnd = 1, nbnd
  538. proj (nwfc, ibnd, ik) = proj (nwfc, ibnd, ik) + &
  539. rwork1(ibnd) * rwork1(ibnd) / nsym
  540. ENDDO
  541. ELSE
  542. IF (l == 0) THEN
  543. work1(:) = proj0 (nwfc1 + 1,:)
  544. ELSEIF (l == 1) THEN
  545. work1(:) = 0.d0
  546. DO m1 = 1, 3
  547. work1(:)=work1(:)+d1(m1,m,isym)*proj0(nwfc1+m1,:)
  548. ENDDO
  549. ELSEIF (l == 2) THEN
  550. work1(:) = 0.d0
  551. DO m1 = 1, 5
  552. work1(:)=work1(:)+d2(m1,m,isym)*proj0(nwfc1+m1,:)
  553. ENDDO
  554. ELSEIF (l == 3) THEN
  555. work1(:) = 0.d0
  556. DO m1 = 1, 7
  557. work1(:)=work1(:)+d3(m1,m,isym)*proj0(nwfc1+m1,:)
  558. ENDDO
  559. ENDIF
  560. DO ibnd = 1, nbnd
  561. proj (nwfc, ibnd, ik) = proj (nwfc, ibnd, ik) + &
  562. work1(ibnd) * conjg (work1(ibnd)) / nsym
  563. ENDDO
  564. ENDIF
  565. ENDDO
  566. ENDDO
  567. ELSE
  568. IF ( gamma_only ) THEN
  569. DO nwfc=1,natomwfc
  570. DO ibnd=1,nbnd
  571. proj(nwfc,ibnd,ik)=abs(rproj0(nwfc,ibnd))**2
  572. ENDDO
  573. ENDDO
  574. ELSE
  575. DO nwfc=1,natomwfc
  576. DO ibnd=1,nbnd
  577. proj(nwfc,ibnd,ik)=abs(proj0(nwfc,ibnd))**2
  578. ENDDO
  579. ENDDO
  580. ENDIF
  581. ENDIF
  582. IF ( gamma_only ) THEN
  583. DEALLOCATE (rwork1)
  584. DEALLOCATE (rproj0)
  585. ELSE
  586. DEALLOCATE (work1)
  587. DEALLOCATE (proj0)
  588. ENDIF
  589. ! on k-points
  590. ENDDO
  591. !
  592. DEALLOCATE (e)
  593. IF ( gamma_only ) THEN
  594. DEALLOCATE (roverlap)
  595. ENDIF
  596. CALL deallocate_bec_type (becp)
  597. DEALLOCATE (overlap)
  598. DEALLOCATE (wfcatom)
  599. IF (.not. lda_plus_u) DEALLOCATE (swfcatom)
  600. !
  601. ! vectors et and proj are distributed across the pools
  602. ! collect data for all k-points to the first pool
  603. !
  604. CALL poolrecover (et, nbnd, nkstot, nks)
  605. CALL poolrecover (proj, nbnd * natomwfc, nkstot, nks)
  606. CALL poolrecover (proj_aux, 2 * nbnd * natomwfc, nkstot, nks)
  607. !
  608. !!!! for GWW
  609. IF(lgww) THEN
  610. INQUIRE ( file='bands.dat', EXIST=lex )
  611. WRITE(stdout,*) 'lex=', lex
  612. CALL flush_unit(stdout)
  613. !
  614. IF(lex) THEN
  615. WRITE(stdout,*) 'Read the file bands.dat => GWA Eigenvalues used.'
  616. CALL flush_unit(stdout)
  617. iun = find_free_unit()
  618. OPEN(unit=iun, file='bands.dat', status='unknown', form='formatted', IOSTAT=ios)
  619. READ(iun,*) idum
  620. DO i=1, nbnd
  621. READ(iun,*) idum,rdum1,rdum2,et(i,1),rdum3
  622. ENDDO
  623. et(:,1)=et(:,1)/rytoev !! because in bands.dat file, the QP energies are in eV
  624. ELSE
  625. WRITE(stdout,*) 'The file bands.dat does not exist.'
  626. WRITE(stdout,*) 'Eigenergies are not modified'
  627. CALL flush_unit(stdout)
  628. ENDIF
  629. !!!! end GWW
  630. !
  631. ENDIF
  632. IF ( ionode ) THEN
  633. !
  634. ! write on the file filproj
  635. !
  636. IF (filproj/=' ') THEN
  637. DO is=1,nspin
  638. IF (nspin==2) THEN
  639. IF (is==1) filename=trim(filproj)//'.up'
  640. IF (is==2) filename=trim(filproj)//'.down'
  641. nksinit=(nkstot/2)*(is-1)+1
  642. nkslast=(nkstot/2)*is
  643. ELSE
  644. filename=trim(filproj)
  645. nksinit=1
  646. nkslast=nkstot
  647. ENDIF
  648. iunproj=33
  649. CALL write_io_header(filename, iunproj, title, nr1x, nr2x, nr3x, &
  650. nr1, nr2, nr3, nat, ntyp, ibrav, celldm, at, gcutm, dual, &
  651. ecutwfc, nkstot/nspin, nbnd, natomwfc)
  652. DO nwfc = 1, natomwfc
  653. WRITE(iunproj,'(2i5,a3,3i5)') &
  654. nwfc, nlmchi(nwfc)%na, atm(ityp(nlmchi(nwfc)%na)), &
  655. nlmchi(nwfc)%n, nlmchi(nwfc)%l, nlmchi(nwfc)%m
  656. DO ik=nksinit,nkslast
  657. DO ibnd=1,nbnd
  658. WRITE(iunproj,'(2i8,f20.10)') ik,ibnd, &
  659. abs(proj(nwfc,ibnd,ik))
  660. ENDDO
  661. ENDDO
  662. ENDDO
  663. CLOSE(iunproj)
  664. ENDDO
  665. ENDIF
  666. !
  667. ! write projections to file using iotk
  668. !
  669. CALL write_proj( "atomic_proj.xml", proj_aux )
  670. !
  671. ! write on the standard output file
  672. !
  673. WRITE( stdout,'(/5x,"Atomic states used for projection")')
  674. WRITE( stdout,'( 5x,"(read from pseudopotential files):"/)')
  675. DO nwfc = 1, natomwfc
  676. WRITE(stdout,1000) &
  677. nwfc, nlmchi(nwfc)%na, atm(ityp(nlmchi(nwfc)%na)), &
  678. nlmchi(nwfc)%n, nlmchi(nwfc)%l, nlmchi(nwfc)%m
  679. ENDDO
  680. 1000 FORMAT (5x,"state #",i4,": atom ",i3," (",a3,"), wfc ",i2, &
  681. " (l=",i1," m=",i2,")")
  682. !
  683. ALLOCATE(idx(natomwfc), proj1 (natomwfc) )
  684. DO ik = 1, nkstot
  685. WRITE( stdout, '(/" k = ",3f14.10)') (xk (i, ik) , i = 1, 3)
  686. DO ibnd = 1, nbnd
  687. WRITE( stdout, '("==== e(",i4,") = ",f11.5," eV ==== ")') &
  688. ibnd, et (ibnd, ik) * rytoev
  689. !
  690. ! sort projections by magnitude, in decreasing order
  691. !
  692. DO nwfc = 1, natomwfc
  693. idx (nwfc) = 0
  694. proj1 (nwfc) = - proj (nwfc, ibnd, ik)
  695. ENDDO
  696. !
  697. ! projections differing by less than 1.d-4 are considered equal
  698. !
  699. CALL hpsort_eps (natomwfc, proj1, idx, eps4)
  700. !
  701. ! only projections that are larger than 0.001 are written
  702. !
  703. DO nwfc = 1, natomwfc
  704. proj1 (nwfc) = - proj1(nwfc)
  705. IF ( abs (proj1(nwfc)) < 0.001d0 ) GOTO 20
  706. ENDDO
  707. nwfc = natomwfc + 1
  708. 20 nwfc = nwfc -1
  709. !
  710. ! fancy (?!?) formatting
  711. !
  712. WRITE( stdout, '(5x,"psi = ",5(f5.3,"*[#",i4,"]+"))') &
  713. (proj1 (i), idx(i), i = 1, min(5,nwfc))
  714. DO j = 1, (nwfc-1)/5
  715. WRITE( stdout, '(10x,"+",5(f5.3,"*[#",i4,"]+"))') &
  716. (proj1 (i), idx(i), i = 5*j+1, min(5*(j+1),nwfc))
  717. ENDDO
  718. psum = 0.d0
  719. DO nwfc = 1, natomwfc
  720. psum = psum + proj (nwfc, ibnd, ik)
  721. ENDDO
  722. WRITE( stdout, '(4x,"|psi|^2 = ",f5.3)') psum
  723. !
  724. ENDDO
  725. ENDDO
  726. DEALLOCATE (idx, proj1)
  727. !
  728. ! estimate partial charges (Loewdin) on each atom
  729. !
  730. ALLOCATE ( charges (nat, 0:lmax_wfc, nspin ) )
  731. charges = 0.0d0
  732. DO ik = 1, nkstot
  733. IF ( nspin == 1 ) THEN
  734. current_spin = 1
  735. ELSEIF ( nspin == 2 ) THEN
  736. current_spin = isk ( ik )
  737. ELSE
  738. CALL errore ('projwfc_nc',' called in the wrong case ',1)
  739. ENDIF
  740. DO ibnd = 1, nbnd
  741. DO nwfc = 1, natomwfc
  742. na= nlmchi(nwfc)%na
  743. l = nlmchi(nwfc)%l
  744. charges(na,l,current_spin) = charges(na,l,current_spin) + &
  745. wg (ibnd,ik) * proj (nwfc, ibnd, ik)
  746. ENDDO
  747. ENDDO
  748. ENDDO
  749. !
  750. WRITE( stdout, '(/"Lowdin Charges: "/)')
  751. !
  752. DO na = 1, nat
  753. DO is = 1, nspin
  754. totcharge(is) = sum(charges(na,0:lmax_wfc,is))
  755. ENDDO
  756. IF ( nspin == 1) THEN
  757. WRITE( stdout, 2000) na, totcharge(1), &
  758. ( l_label(l), charges(na,l,1), l= 0,lmax_wfc)
  759. ELSEIF ( nspin == 2) THEN
  760. WRITE( stdout, 2000) na, totcharge(1) + totcharge(2), &
  761. ( l_label(l), charges(na,l,1) + charges(na,l,2), l=0,lmax_wfc)
  762. WRITE( stdout, 2001) totcharge(1), &
  763. ( l_label(l), charges(na,l,1), l= 0,lmax_wfc)
  764. WRITE( stdout, 2002) totcharge(2), &
  765. ( l_label(l), charges(na,l,2), l= 0,lmax_wfc)
  766. WRITE( stdout, 2003) totcharge(1) - totcharge(2), &
  767. ( l_label(l), charges(na,l,1) - charges(na,l,2), l=0,lmax_wfc)
  768. ENDIF
  769. ENDDO
  770. 2000 FORMAT (5x,"Atom # ",i3,": total charge = ",f8.4,4(", ",a1," =",f8.4))
  771. 2001 FORMAT (15x," spin up = ",f8.4,4(", ",a1," =",f8.4))
  772. 2002 FORMAT (15x," spin down = ",f8.4,4(", ",a1," =",f8.4))
  773. 2003 FORMAT (15x," polarization = ",f8.4,4(", ",a1," =",f8.4))
  774. !
  775. psum = sum(charges(:,:,:)) / nelec
  776. WRITE( stdout, '(5x,"Spilling Parameter: ",f8.4)') 1.0d0 - psum
  777. !
  778. ! Sanchez-Portal et al., Sol. State Commun. 95, 685 (1995).
  779. ! The spilling parameter measures the ability of the basis provided by
  780. ! the pseudo-atomic wfc to represent the PW eigenstates,
  781. ! by measuring how much of the subspace of the Hamiltonian
  782. ! eigenstates falls outside the subspace spanned by the atomic basis
  783. !
  784. DEALLOCATE (charges)
  785. !
  786. ENDIF
  787. !
  788. RETURN
  789. !
  790. END SUBROUTINE projwave
  791. !
  792. !-----------------------------------------------------------------------
  793. SUBROUTINE projwave_nc(filproj, lsym )
  794. !-----------------------------------------------------------------------
  795. !
  796. USE io_global, ONLY : stdout, ionode
  797. USE ions_base, ONLY : zv, tau, nat, ntyp => nsp, ityp, atm
  798. USE basis, ONLY : natomwfc
  799. USE printout_base, ONLY: title
  800. USE cell_base
  801. USE constants, ONLY: rytoev, eps4
  802. USE gvect
  803. USE grid_dimensions, ONLY : nr1, nr2, nr3, nr1x, nr2x, nr3x
  804. USE klist, ONLY: xk, nks, nkstot, nelec
  805. USE ldaU
  806. USE lsda_mod, ONLY: nspin
  807. USE noncollin_module, ONLY: noncolin, npol, angle1, angle2
  808. USE symm_base, ONLY: nsym, irt, t_rev
  809. USE wvfct
  810. USE control_flags, ONLY: gamma_only
  811. USE uspp, ONLY: nkb, vkb
  812. USE uspp_param, ONLY: upf
  813. USE becmod, ONLY: bec_type, becp, calbec, allocate_bec_type, deallocate_bec_type
  814. USE io_files, ONLY: nd_nmbr, prefix, tmp_dir, nwordwfc, iunwfc
  815. USE wavefunctions_module, ONLY: evc
  816. USE mp_global, ONLY : intra_pool_comm
  817. USE mp, ONLY : mp_sum
  818. !
  819. USE spin_orb, ONLY: lspinorb, domag
  820. USE projections_nc
  821. !
  822. IMPLICIT NONE
  823. !
  824. CHARACTER(len=*) :: filproj
  825. LOGICAL :: lsym
  826. INTEGER :: ik, ibnd, i, j, k, na, nb, nt, isym, ind, n, m, m1, n1, &
  827. n2, l, nwfc, nwfc1, lmax_wfc, is, nspin0, iunproj, &
  828. ind0
  829. REAL(DP) :: jj
  830. REAL(DP), ALLOCATABLE :: e (:)
  831. COMPLEX(DP), ALLOCATABLE :: wfcatom (:,:)
  832. COMPLEX(DP), ALLOCATABLE :: overlap(:,:), work(:,:),work1(:), proj0(:,:)
  833. ! Some workspace for k-point calculation ...
  834. REAL(DP), ALLOCATABLE :: charges(:,:,:), proj1 (:)
  835. REAL(DP) :: psum, totcharge(2), fact(2), spinor, compute_mj
  836. INTEGER, ALLOCATABLE :: idx(:)
  837. !
  838. COMPLEX(DP) :: d12(2, 2, 48), d32(4, 4, 48), d52(6, 6, 48), &
  839. d72(8, 8, 48)
  840. COMPLEX(DP) :: d012(2, 2, 48), d112(6, 6, 48), d212(10, 10, 48), &
  841. d312(14, 14, 48)
  842. !
  843. !
  844. !
  845. IF (.not.noncolin) CALL errore('projwave_nc','called in the wrong case',1)
  846. IF (gamma_only) CALL errore('projwave_nc','gamma_only not yet implemented',1)
  847. WRITE( stdout, '(/5x,"Calling projwave_nc .... ")')
  848. !
  849. ! fill structure nlmchi
  850. !
  851. ALLOCATE (nlmchi(natomwfc))
  852. nwfc=0
  853. lmax_wfc = 0
  854. DO na = 1, nat
  855. nt = ityp (na)
  856. n2 = 0
  857. DO n = 1, upf(nt)%nwfc
  858. IF (upf(nt)%oc (n) >= 0.d0) THEN
  859. l = upf(nt)%lchi (n)
  860. lmax_wfc = max (lmax_wfc, l )
  861. IF (lspinorb) THEN
  862. IF (upf(nt)%has_so) THEN
  863. jj = upf(nt)%jchi (n)
  864. ind = 0
  865. DO m = -l-1, l
  866. fact(1) = spinor(l,jj,m,1)
  867. fact(2) = spinor(l,jj,m,2)
  868. IF (abs(fact(1)) > 1.d-8 .or. abs(fact(2)) > 1.d-8) THEN
  869. nwfc = nwfc + 1
  870. ind = ind + 1
  871. nlmchi(nwfc)%na = na
  872. nlmchi(nwfc)%n = n
  873. nlmchi(nwfc)%l = l
  874. nlmchi(nwfc)%m = m
  875. nlmchi(nwfc)%ind = ind
  876. nlmchi(nwfc)%jj = jj
  877. ENDIF
  878. ENDDO
  879. ELSE
  880. DO n1 = l, l+1
  881. jj= dble(n1) - 0.5d0
  882. ind = 0
  883. IF (jj>0.d0) THEN
  884. n2 = n2 + 1
  885. DO m = -l-1, l
  886. fact(1) = spinor(l,jj,m,1)
  887. fact(2) = spinor(l,jj,m,2)
  888. IF (abs(fact(1)) > 1.d-8 .or. abs(fact(2)) > 1.d-8) THEN
  889. nwfc = nwfc + 1
  890. ind = ind + 1
  891. nlmchi(nwfc)%na = na
  892. nlmchi(nwfc)%n = n2
  893. nlmchi(nwfc)%l = l
  894. nlmchi(nwfc)%m = m
  895. nlmchi(nwfc)%ind = ind
  896. nlmchi(nwfc)%jj = jj
  897. ENDIF
  898. ENDDO
  899. ENDIF
  900. ENDDO
  901. ENDIF
  902. ELSE
  903. DO m = 1, 2 * l + 1
  904. nwfc=nwfc+1
  905. nlmchi(nwfc)%na = na
  906. nlmchi(nwfc)%n = n
  907. nlmchi(nwfc)%l = l
  908. nlmchi(nwfc)%m = m
  909. nlmchi(nwfc)%ind = m
  910. nlmchi(nwfc)%jj = 0.d0
  911. nlmchi(nwfc+2*l+1)%na = na
  912. nlmchi(nwfc+2*l+1)%n = n
  913. nlmchi(nwfc+2*l+1)%l = l
  914. nlmchi(nwfc+2*l+1)%m = m
  915. nlmchi(nwfc+2*l+1)%ind = m+2*l+1
  916. nlmchi(nwfc+2*l+1)%jj = 0.d0
  917. ENDDO
  918. nwfc=nwfc+2*l+1
  919. ENDIF
  920. ENDIF
  921. ENDDO
  922. ENDDO
  923. !
  924. IF (lmax_wfc > 3) CALL errore ('projwave_nc', 'l > 3 not yet implemented', 1)
  925. IF (nwfc /= natomwfc) CALL errore ('projwave_nc','wrong # of atomic wfcs?',1)
  926. !
  927. ALLOCATE(wfcatom (npwx*npol,natomwfc) )
  928. IF (.not. lda_plus_u) ALLOCATE(swfcatom (npwx*npol, natomwfc ) )
  929. CALL allocate_bec_type (nkb, natomwfc, becp )
  930. ALLOCATE(e (natomwfc) )
  931. ALLOCATE(work (natomwfc, natomwfc) )
  932. !
  933. ALLOCATE(overlap (natomwfc, natomwfc) )
  934. ALLOCATE(proj0(natomwfc,nbnd), work1 (nbnd) )
  935. ALLOCATE(proj (natomwfc, nbnd, nkstot) )
  936. ALLOCATE(proj_aux (natomwfc, nbnd, nkstot) )
  937. overlap = (0.d0,0.d0)
  938. proj0 = (0.d0,0.d0)
  939. proj = 0.d0
  940. proj_aux = (0.d0,0.d0)
  941. !
  942. ! loop on k points
  943. !
  944. CALL init_us_1
  945. CALL init_at_1
  946. !
  947. IF (lspinorb) THEN
  948. !
  949. ! initialize D_Sj for j=1/2, j=3/2, j=5/2 and j=7/2
  950. !
  951. CALL d_matrix_so (d12, d32, d52, d72)
  952. !
  953. ELSE
  954. !
  955. ! initialize D_Sl for l=0, l=1, l=2 and l=3
  956. !
  957. CALL d_matrix_nc (d012, d112, d212, d312)
  958. !
  959. ENDIF
  960. !
  961. DO ik = 1, nks
  962. wfcatom = (0.d0,0.d0)
  963. swfcatom= (0.d0,0.d0)
  964. CALL gk_sort (xk (1, ik), ngm, g, ecutwfc / tpiba2, npw, igk, g2kin)
  965. CALL davcio (evc, nwordwfc, iunwfc, ik, - 1)
  966. !
  967. CALL atomic_wfc_nc_proj (ik, wfcatom)
  968. !
  969. CALL init_us_2 (npw, igk, xk (1, ik), vkb)
  970. CALL calbec ( npw, vkb, wfcatom, becp )
  971. CALL s_psi (npwx, npw, natomwfc, wfcatom, swfcatom)
  972. !
  973. ! wfcatom = |phi_i> , swfcatom = \hat S |phi_i>
  974. ! calculate overlap matrix O_ij = <phi_i|\hat S|\phi_j>
  975. !
  976. CALL ZGEMM ('C', 'N', natomwfc, natomwfc, npwx*npol, (1.d0, 0.d0), wfcatom, &
  977. npwx*npol, swfcatom, npwx*npol, (0.d0, 0.d0), overlap, natomwfc)
  978. CALL mp_sum ( overlap, intra_pool_comm )
  979. !
  980. ! calculate O^{-1/2}
  981. !
  982. CALL cdiagh (natomwfc, overlap, natomwfc, e, work)
  983. DO i = 1, natomwfc
  984. e (i) = 1.d0 / dsqrt (e (i) )
  985. ENDDO
  986. DO i = 1, natomwfc
  987. DO j = i, natomwfc
  988. overlap (i, j) = (0.d0, 0.d0)
  989. DO k = 1, natomwfc
  990. overlap(i, j) = overlap(i, j) + e(k) * work(j, k) * conjg(work (i, k) )
  991. ENDDO
  992. IF (j /= i) overlap (j, i) = conjg (overlap (i, j))
  993. ENDDO
  994. ENDDO
  995. !
  996. ! calculate wfcatom = O^{-1/2} \hat S | phi>
  997. !
  998. CALL ZGEMM ('n', 't', npwx*npol, natomwfc, natomwfc, (1.d0, 0.d0) , &
  999. swfcatom, npwx*npol, overlap, natomwfc, (0.d0, 0.d0), wfcatom, npwx*npol)
  1000. !
  1001. ! make the projection <psi_i| O^{-1/2} \hat S | phi_j>
  1002. !
  1003. CALL ZGEMM ('C','N',natomwfc, nbnd, npwx*npol, (1.d0, 0.d0), wfcatom, &
  1004. npwx*npol, evc, npwx*npol, (0.d0, 0.d0), proj0, natomwfc)
  1005. CALL mp_sum ( proj0( :, 1:nbnd ), intra_pool_comm )
  1006. !
  1007. proj_aux(:,:,ik) = proj0(:,:)
  1008. !
  1009. IF (lsym) THEN
  1010. DO nwfc = 1, natomwfc
  1011. !
  1012. ! atomic wavefunction nwfc is on atom na
  1013. !
  1014. IF (lspinorb) THEN
  1015. na= nlmchi(nwfc)%na
  1016. n = nlmchi(nwfc)%n
  1017. l = nlmchi(nwfc)%l
  1018. m = nlmchi(nwfc)%m
  1019. ind0 = nlmchi(nwfc)%ind
  1020. jj = nlmchi(nwfc)%jj
  1021. !
  1022. DO isym = 1, nsym
  1023. !-- check for the time reversal
  1024. IF (t_rev(isym) == 1) THEN
  1025. ind = 2*jj + 2 - ind0
  1026. ELSE
  1027. ind = ind0
  1028. ENDIF
  1029. !--
  1030. nb = irt (isym, na)
  1031. DO nwfc1 =1, natomwfc
  1032. IF (nlmchi(nwfc1)%na == nb .and. &
  1033. nlmchi(nwfc1)%n == nlmchi(nwfc)%n .and. &
  1034. nlmchi(nwfc1)%l == nlmchi(nwfc)%l .and. &
  1035. nlmchi(nwfc1)%jj == nlmchi(nwfc)%jj .and. &
  1036. nlmchi(nwfc1)%ind == 1 ) GOTO 10
  1037. ENDDO
  1038. CALL errore('projwave_nc','cannot symmetrize',1)
  1039. 10 nwfc1=nwfc1-1
  1040. !
  1041. ! nwfc1 is the first rotated atomic wfc corresponding to nwfc
  1042. !
  1043. IF (abs(jj-0.5d0)<1.d-8) THEN
  1044. work1(:) = 0.d0
  1045. DO m1 = 1, 2
  1046. work1(:)=work1(:)+d12(m1,ind,isym)*proj0(nwfc1+m1,:)
  1047. ENDDO
  1048. ELSEIF (abs(jj-1.5d0)<1.d-8) THEN
  1049. work1(:) = 0.d0
  1050. DO m1 = 1, 4
  1051. work1(:)=work1(:)+d32(m1,ind,isym)*proj0(nwfc1 + m1,:)
  1052. ENDDO
  1053. ELSEIF (abs(jj-2.5d0)<1.d-8) THEN
  1054. work1(:) = 0.d0
  1055. DO m1 = 1, 6
  1056. work1(:)=work1(:)+d52(m1,ind,isym)*proj0(nwfc1+m1,:)
  1057. ENDDO
  1058. ELSEIF (abs(jj-3.5d0)<1.d-8) THEN
  1059. work1(:) = 0.d0
  1060. DO m1 = 1, 8
  1061. work1(:)=work1(:)+d72(m1,ind,isym)*proj0(nwfc1+m1,:)
  1062. ENDDO
  1063. ENDIF
  1064. DO ibnd = 1, nbnd
  1065. proj (nwfc, ibnd, ik) = proj (nwfc, ibnd, ik) + &
  1066. work1(ibnd) * conjg (work1(ibnd)) / nsym
  1067. ENDDO
  1068. ! on symmetries
  1069. !-- in a nonmagnetic case - another loop with the time reversal
  1070. IF (.not.domag.and.ind==ind0) THEN
  1071. ind = 2*jj + 2 - ind0
  1072. nwfc1 = nwfc1 + 1
  1073. GOTO 10
  1074. ENDIF
  1075. !--
  1076. ENDDO
  1077. !-- in a nonmagnetic case - rescale
  1078. IF (.not.domag) THEN
  1079. DO ibnd = 1, nbnd
  1080. proj(nwfc,ibnd,ik) = 0.5d0*proj(nwfc,ibnd,ik)
  1081. ENDDO
  1082. ENDIF
  1083. !--
  1084. ELSE
  1085. na= nlmchi(nwfc)%na
  1086. n = nlmchi(nwfc)%n
  1087. l = nlmchi(nwfc)%l
  1088. m = nlmchi(nwfc)%m
  1089. ind0 = nlmchi(nwfc)%ind
  1090. !
  1091. DO isym = 1, nsym
  1092. !-- check for the time reversal
  1093. IF (t_rev(isym) == 1) THEN
  1094. ind = 2*m - ind0 + 2*l + 1
  1095. ELSE
  1096. ind = ind0
  1097. ENDIF
  1098. !--
  1099. nb = irt (isym, na)
  1100. DO nwfc1 =1, natomwfc
  1101. IF (nlmchi(nwfc1)%na == nb .and. &
  1102. nlmchi(nwfc1)%n == nlmchi(nwfc)%n .and. &
  1103. nlmchi(nwfc1)%l == nlmchi(nwfc)%l .and. &
  1104. nlmchi(nwfc1)%m == 1 .and. &
  1105. nlmchi(nwfc1)%ind == 1) GOTO 15
  1106. ENDDO
  1107. CALL errore('projwave_nc','cannot symmetrize',1)
  1108. 15 nwfc1=nwfc1-1
  1109. IF (l == 0) THEN
  1110. work1(:) = 0.d0
  1111. DO m1 = 1, 2
  1112. work1(:) = work1(:) + d012 (m1, ind, isym) * &
  1113. proj0 (nwfc1 + m1,:)
  1114. ENDDO
  1115. ELSEIF (l == 1) THEN
  1116. work1(:) = 0.d0
  1117. DO m1 = 1, 6
  1118. work1(:) = work1(:) + d112 (m1, ind, isym) * &
  1119. proj0 (nwfc1 + m1,:)
  1120. ENDDO
  1121. ELSEIF (l == 2) THEN
  1122. work1(:) = 0.d0
  1123. DO m1 = 1, 10
  1124. work1(:) = work1(:) + d212 (m1, ind, isym) * &
  1125. proj0 (nwfc1 + m1,:)
  1126. ENDDO
  1127. ELSEIF (l == 3) THEN
  1128. work1(:) = 0.d0
  1129. DO m1 = 1, 14
  1130. work1(:) = work1(:) + d312 (m1, ind, isym) * &
  1131. proj0 (nwfc1 + m1,:)
  1132. ENDDO
  1133. ENDIF
  1134. DO ibnd = 1, nbnd
  1135. proj (nwfc, ibnd, ik) = proj (nwfc, ibnd, ik) + &
  1136. work1(ibnd) * conjg (work1(ibnd)) / nsym
  1137. ENDDO
  1138. ! on symmetries
  1139. ENDDO
  1140. ENDIF
  1141. ! on atomic wavefunctions
  1142. ENDDO
  1143. ELSE
  1144. DO nwfc=1,natomwfc
  1145. DO ibnd=1,nbnd
  1146. proj(nwfc,ibnd,ik)=abs(proj0(nwfc,ibnd))**2
  1147. ENDDO
  1148. ENDDO
  1149. ENDIF
  1150. ! on k-points
  1151. ENDDO
  1152. !
  1153. DEALLOCATE (work)
  1154. DEALLOCATE (work1)
  1155. DEALLOCATE (proj0)
  1156. DEALLOCATE (e)
  1157. CALL deallocate_bec_type (becp)
  1158. DEALLOCATE (overlap)
  1159. DEALLOCATE (wfcatom)
  1160. IF (.not. lda_plus_u) DEALLOCATE (swfcatom)
  1161. !
  1162. ! vectors et and proj are distributed across the pools
  1163. ! collect data for all k-points to the first pool
  1164. !
  1165. CALL poolrecover (et, nbnd, nkstot, nks)
  1166. CALL poolrecover (proj, nbnd * natomwfc, nkstot, nks)
  1167. CALL poolrecover (proj_aux, 2 * nbnd * natomwfc, nkstot, nks)
  1168. !
  1169. IF ( ionode ) THEN
  1170. !
  1171. ! write on the file filproj
  1172. !
  1173. IF (filproj/=' ') THEN
  1174. iunproj=33
  1175. CALL write_io_header(filproj, iunproj, title, nr1x, nr2x, nr3x, &
  1176. nr1, nr2, nr3, nat, ntyp, ibrav, celldm, at, gcutm, dual, ecutwfc, &
  1177. nkstot,nbnd,natomwfc)
  1178. DO nwfc = 1, natomwfc
  1179. IF (lspinorb) THEN
  1180. WRITE(iunproj,1000) &
  1181. nwfc, nlmchi(nwfc)%na,atm(ityp(nlmchi(nwfc)%na)), &
  1182. nlmchi(nwfc)%n,nlmchi(nwfc)%jj,nlmchi(nwfc)%l, &
  1183. compute_mj(nlmchi(nwfc)%jj,nlmchi(nwfc)%l,nlmchi(nwfc)%m)
  1184. ELSE
  1185. WRITE(iunproj,1500) &
  1186. nwfc, nlmchi(nwfc)%na, atm(ityp(nlmchi(nwfc)%na)), &
  1187. nlmchi(nwfc)%n, nlmchi(nwfc)%l, nlmchi(nwfc)%m, &
  1188. 0.5d0-int(nlmchi(nwfc)%ind/(2*nlmchi(nwfc)%l+2))
  1189. ENDIF
  1190. DO ik=1,nkstot
  1191. DO ibnd=1,nbnd
  1192. WRITE(iunproj,'(2i8,f20.10)') ik,ibnd,abs(proj(nwfc,ibnd,ik))
  1193. ENDDO
  1194. ENDDO
  1195. ENDDO
  1196. CLOSE(iunproj)
  1197. ENDIF
  1198. !
  1199. ! write projections to file using iotk
  1200. !
  1201. CALL write_proj( "atomic_proj.xml", proj_aux )
  1202. !
  1203. ! write on the standard output file
  1204. !
  1205. WRITE( stdout,'(/5x,"Atomic states used for projection")')
  1206. WRITE( stdout,'( 5x,"(read from pseudopotential files):"/)')
  1207. IF (lspinorb) THEN
  1208. DO nwfc = 1, natomwfc
  1209. WRITE(stdout,1000) &
  1210. nwfc, nlmchi(nwfc)%na, atm(ityp(nlmchi(nwfc)%na)), &
  1211. nlmchi(nwfc)%n, nlmchi(nwfc)%jj, nlmchi(nwfc)%l, &
  1212. compute_mj(nlmchi(nwfc)%jj,nlmchi(nwfc)%l,nlmchi(nwfc)%m)
  1213. ENDDO
  1214. 1000 FORMAT (5x,"state #",i3,": atom ",i3," (",a3,"), wfc ",i2, &
  1215. " (j=",f3.1," l=",i1," m_j=",f4.1,")")
  1216. ELSE
  1217. DO nwfc = 1, natomwfc
  1218. WRITE(stdout,1500) &
  1219. nwfc, nlmchi(nwfc)%na, atm(ityp(nlmchi(nwfc)%na)), &
  1220. nlmchi(nwfc)%n, nlmchi(nwfc)%l, nlmchi(nwfc)%m, &
  1221. 0.5d0-int(nlmchi(nwfc)%ind/(2*nlmchi(nwfc)%l+2))
  1222. ENDDO
  1223. 1500 FORMAT (5x,"state #",i3,": atom ",i3," (",a3,"), wfc ",i2, &
  1224. " (l=",i1," m=",i2," s_z=",f4.1,")")
  1225. ENDIF
  1226. !
  1227. ALLOCATE(idx (natomwfc), proj1 (natomwfc) )
  1228. DO ik = 1, nkstot
  1229. WRITE( stdout, '(/" k = ",3f14.10)') (xk (i, ik) , i = 1, 3)
  1230. DO ibnd = 1, nbnd
  1231. WRITE( stdout, '("==== e(",i4,") = ",f11.5," eV ==== ")') &
  1232. ibnd, et (ibnd, ik) * rytoev
  1233. !
  1234. ! sort projections by magnitude, in decreasing order
  1235. !
  1236. DO nwfc = 1, natomwfc
  1237. idx (nwfc) = 0
  1238. proj1 (nwfc) = - proj (nwfc, ibnd, ik)
  1239. ENDDO
  1240. CALL hpsort_eps (natomwfc, proj1, idx, eps4)
  1241. !
  1242. ! only projections that are larger than 0.001 are written
  1243. !
  1244. DO nwfc = 1, natomwfc
  1245. proj1 (nwfc) = - proj1(nwfc)
  1246. IF ( abs (proj1(nwfc)) < 0.001d0 ) GOTO 20
  1247. ENDDO
  1248. nwfc = natomwfc + 1
  1249. 20 nwfc = nwfc -1
  1250. !
  1251. ! fancy (?!?) formatting
  1252. !
  1253. WRITE( stdout, '(5x,"psi = ",5(f5.3,"*[#",i3,"]+"))') &
  1254. (proj1 (i), idx(i), i = 1, min(5,nwfc))
  1255. DO j = 1, (nwfc-1)/5
  1256. WRITE( stdout, '(10x,"+",5(f5.3,"*[#",i3,"]+"))') &
  1257. (proj1 (i), idx(i), i = 5*j+1, min(5*(j+1),nwfc))
  1258. ENDDO
  1259. psum = 0.d0
  1260. DO nwfc = 1, natomwfc
  1261. psum = psum + proj (nwfc, ibnd, ik)
  1262. ENDDO
  1263. WRITE( stdout, '(4x,"|psi|^2 = ",f5.3)') psum
  1264. !
  1265. ENDDO
  1266. ENDDO
  1267. DEALLOCATE (idx, proj1)
  1268. !
  1269. ! estimate partial charges (Loewdin) on each atom
  1270. !
  1271. IF (lspinorb) THEN
  1272. nspin0 = 1
  1273. ELSE
  1274. nspin0 = 2
  1275. ENDIF
  1276. ALLOCATE ( charges (nat, 0:lmax_wfc, nspin0 ) )
  1277. charges = 0.0d0
  1278. IF (lspinorb) THEN
  1279. DO ik = 1, nkstot
  1280. DO ibnd = 1, nbnd
  1281. DO nwfc = 1, natomwfc
  1282. na= nlmchi(nwfc)%na
  1283. l = nlmchi(nwfc)%l
  1284. charges(na,l,1) = charges(na,l,1) + &
  1285. wg (ibnd,ik) * proj (nwfc, ibnd, ik)
  1286. ENDDO
  1287. ENDDO
  1288. ENDDO
  1289. ELSE
  1290. DO ik = 1, nkstot
  1291. DO ibnd = 1, nbnd
  1292. DO nwfc = 1, natomwfc
  1293. na= nlmchi(nwfc)%na
  1294. l = nlmchi(nwfc)%l
  1295. IF ( nlmchi(nwfc)%ind<=(2*l+1)) THEN
  1296. charges(na,l,1) = charges(na,l,1) + &
  1297. wg (ibnd,ik) * proj (nwfc, ibnd, ik)
  1298. ELSE
  1299. charges(na,l,2) = charges(na,l,2) + &
  1300. wg (ibnd,ik) * proj (nwfc, ibnd, ik)
  1301. ENDIF
  1302. ENDDO
  1303. ENDDO
  1304. ENDDO
  1305. ENDIF
  1306. !
  1307. WRITE( stdout, '(/"Lowdin Charges: "/)')
  1308. !
  1309. DO na = 1, nat
  1310. DO is = 1, nspin0
  1311. totcharge(is) = sum(charges(na,0:lmax_wfc,is))
  1312. ENDDO
  1313. IF ( nspin0 == 1) THEN
  1314. WRITE( stdout, 2000) na, totcharge(1), &
  1315. ( charges(na,l,1), l= 0,lmax_wfc)
  1316. ELSEIF ( nspin0 == 2) THEN
  1317. WRITE( stdout, 2000) na, totcharge(1) + totcharge(2), &
  1318. ( charges(na,l,1) + charges(na,l,2), l=0,lmax_wfc)
  1319. WRITE( stdout, 2001) totcharge(1), &
  1320. ( charges(na,l,1), l= 0,lmax_wfc)
  1321. WRITE( stdout, 2002) totcharge(2), &
  1322. ( charges(na,l,2), l= 0,lmax_wfc)
  1323. WRITE( stdout, 2003) totcharge(1) - totcharge(2), &
  1324. ( charges(na,l,1) - charges(na,l,2), l=0,lmax_wfc)
  1325. ENDIF
  1326. ENDDO
  1327. 2000 FORMAT (5x,"Atom # ",i3,": total charge = ",f8.4 ,&
  1328. & ", s, p, d, f = ",4f8.4)
  1329. 2001 FORMAT (15x," spin up = ",f8.4 , &
  1330. & ", s, p, d, f = ",4f8.4)
  1331. 2002 FORMAT (15x," spin down = ",f8.4 , &
  1332. & ", s, p, d, f = ",4f8.4)
  1333. 2003 FORMAT (15x," polarization = ",f8.4 , &
  1334. & ", s, p, d, f = ",4f8.4)
  1335. !
  1336. psum = sum(charges(:,:,:)) / nelec
  1337. WRITE( stdout, '(5x,"Spilling Parameter: ",f8.4)') 1.0d0 - psum
  1338. !
  1339. ! Sanchez-Portal et al., Sol. State Commun. 95, 685 (1995).
  1340. ! The spilling parameter measures the ability of the basis provided by
  1341. ! the pseudo-atomic wfc to represent the PW eigenstates,
  1342. ! by measuring how much of the subspace of the Hamiltonian
  1343. ! eigenstates falls outside the subspace spanned by the atomic basis
  1344. !
  1345. DEALLOCATE (charges)
  1346. !
  1347. ENDIF
  1348. !
  1349. RETURN
  1350. !
  1351. END SUBROUTINE projwave_nc
  1352. !
  1353. !-----------------------------------------------------------------------
  1354. SUBROUTINE partialdos (Emin, Emax, DeltaE, kresolveddos, filpdos)
  1355. !-----------------------------------------------------------------------
  1356. !
  1357. USE io_global, ONLY : stdout
  1358. USE basis, ONLY : natomwfc
  1359. USE ions_base, ONLY : ityp, atm
  1360. USE klist, ONLY: wk, nkstot, degauss, ngauss, lgauss
  1361. USE lsda_mod, ONLY: nspin, isk, current_spin
  1362. USE wvfct, ONLY: et, nbnd
  1363. USE constants, ONLY: rytoev
  1364. !
  1365. USE projections
  1366. !
  1367. IMPLICIT NONE
  1368. CHARACTER (len=256) :: filpdos
  1369. REAL(DP) :: Emin, Emax, DeltaE
  1370. LOGICAL :: kresolveddos
  1371. !
  1372. CHARACTER (len=33) :: filextension
  1373. CHARACTER (len=256):: fileout
  1374. CHARACTER (len=1) :: l_label(0:3)=(/'s','p','d','f'/)
  1375. !
  1376. INTEGER :: ik, ibnd, m, &
  1377. c_tab, nwfc, ne, ie_mid, ie_delta, ie, is, nkseff, ikeff
  1378. REAL(DP) :: etev, delta, Elw, Eup, wkeff
  1379. REAL(DP), ALLOCATABLE :: dostot(:,:,:), pdos(:,:,:,:), pdostot(:,:,:), &
  1380. ldos(:,:,:)
  1381. REAL(DP), EXTERNAL :: w0gauss
  1382. !
  1383. !
  1384. ! find band extrema
  1385. !
  1386. Elw = et (1, 1)
  1387. Eup = et (nbnd, 1)
  1388. DO ik = 2, nkstot
  1389. Elw = min (Elw, et (1, ik) )
  1390. Eup = max (Eup, et (nbnd, ik) )
  1391. ENDDO
  1392. IF (degauss/=0.d0) THEN
  1393. Eup = Eup + 3d0 * degauss
  1394. Elw = Elw - 3d0 * degauss
  1395. ENDIF
  1396. Emin = max (Emin/rytoev, Elw)
  1397. Emax = min (Emax/rytoev, Eup)
  1398. DeltaE = DeltaE/rytoev
  1399. ne = nint ( (Emax - Emin) / DeltaE+0.500001d0)
  1400. !
  1401. IF (kresolveddos) THEN
  1402. IF ( nspin==2 ) THEN
  1403. nkseff=nkstot/2
  1404. ELSE
  1405. nkseff=nkstot
  1406. ENDIF
  1407. ELSE
  1408. nkseff=1
  1409. ENDIF
  1410. !
  1411. ALLOCATE (pdos(0:ne,natomwfc,nspin,nkseff))
  1412. ALLOCATE (dostot(0:ne,nspin,nkseff), pdostot(0:ne,nspin,nkseff), ldos(0:ne,nspin,nkseff) )
  1413. pdos(:,:,:,:) = 0.d0
  1414. dostot(:,:,:) = 0.d0
  1415. pdostot(:,:,:)= 0.d0
  1416. !
  1417. current_spin = 1
  1418. ie_delta = 5 * degauss / DeltaE + 1
  1419. DO ik = 1,nkstot
  1420. !
  1421. IF (kresolveddos) THEN
  1422. ! set equal weight to all k-points
  1423. wkeff=1.D0
  1424. !
  1425. IF (( nspin==2 ).AND.( isk(ik)==2 )) THEN
  1426. ikeff=ik-nkstot/2
  1427. ELSE
  1428. ikeff=ik
  1429. ENDIF
  1430. ELSE
  1431. ! use true weights
  1432. wkeff=wk(ik)
  1433. ! contributions from all k-points are summed in pdos(:,:,:,ikeff)
  1434. ikeff=1
  1435. ENDIF
  1436. !
  1437. IF ( nspin == 2 ) current_spin = isk ( ik )
  1438. DO ibnd = 1, nbnd
  1439. etev = et(ibnd,ik)
  1440. ie_mid = nint( (etev-Emin)/DeltaE )
  1441. DO ie = max(ie_mid-ie_delta, 0), min(ie_mid+ie_delta, ne)
  1442. delta = w0gauss((Emin+DeltaE*ie-etev)/degauss,ngauss) &
  1443. / degauss / rytoev
  1444. !…