69 #include "./base/base_uses.f90"
74 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'wannier90'
78 CHARACTER(len=20) :: length_unit
83 REAL(kind=
dp) :: real_lattice(3, 3)
84 REAL(kind=
dp) :: recip_lattice(3, 3)
85 REAL(kind=
dp) :: cell_volume
86 REAL(kind=
dp),
ALLOCATABLE ::kpt_cart(:, :)
87 REAL(kind=
dp) :: lenconfac
88 INTEGER :: num_exclude_bands
90 REAL(kind=
dp) :: kmesh_tol
93 INTEGER :: search_shells
94 INTEGER,
ALLOCATABLE :: shell_list(:)
95 REAL(kind=
dp),
ALLOCATABLE :: kpt_latt(:, :)
100 INTEGER,
ALLOCATABLE :: nnlist(:, :)
101 INTEGER,
ALLOCATABLE :: neigh(:, :)
102 INTEGER,
ALLOCATABLE :: nncell(:, :, :)
103 REAL(kind=
dp) :: wbtot
104 REAL(kind=
dp),
ALLOCATABLE :: wb(:)
105 REAL(kind=
dp),
ALLOCATABLE :: bk(:, :, :)
106 REAL(kind=
dp),
ALLOCATABLE :: bka(:, :)
109 INTEGER,
PARAMETER :: max_shells = 6
110 INTEGER,
PARAMETER :: num_nnmax = 12
112 INTEGER,
PARAMETER :: nsupcell = 5
113 INTEGER :: lmn(3, (2*nsupcell + 1)**3)
115 REAL(kind=
dp),
PARAMETER :: eps5 = 1.0e-5_dp
116 REAL(kind=
dp),
PARAMETER :: eps6 = 1.0e-6_dp
117 REAL(kind=
dp),
PARAMETER :: eps8 = 1.0e-8_dp
138 real_lattice_loc, recip_lattice_loc, kpt_latt_loc, &
139 nntot_loc, nnlist_loc, nncell_loc, iounit)
141 INTEGER,
DIMENSION(3),
INTENT(in) :: mp_grid_loc
142 INTEGER,
INTENT(in) :: num_kpts_loc
143 REAL(kind=
dp),
DIMENSION(3, 3),
INTENT(in) :: real_lattice_loc, recip_lattice_loc
144 REAL(kind=
dp),
DIMENSION(3, num_kpts_loc), &
145 INTENT(in) :: kpt_latt_loc
146 INTEGER,
INTENT(out) :: nntot_loc
147 INTEGER,
DIMENSION(num_kpts_loc, num_nnmax), &
148 INTENT(out) :: nnlist_loc
149 INTEGER,
DIMENSION(3, num_kpts_loc, num_nnmax), &
150 INTENT(out) :: nncell_loc
151 INTEGER,
INTENT(in) :: iounit
157 lenconfac = 1.0_dp/
bohr
162 WRITE (stdout,
'(a/)')
' Setting up k-point neighbours...'
165 mp_grid = mp_grid_loc
166 num_kpts = num_kpts_loc
167 real_lattice = real_lattice_loc
168 recip_lattice = recip_lattice_loc
169 ALLOCATE (kpt_latt(3, num_kpts))
170 ALLOCATE (kpt_cart(3, num_kpts))
171 kpt_latt(1:3, 1:num_kpts) = kpt_latt_loc(1:3, 1:num_kpts)
173 kpt_cart(:, nkp) = matmul(kpt_latt(:, nkp), recip_lattice(:, :))
177 ALLOCATE (shell_list(max_shells))
179 cell_volume = real_lattice(1, 1)*(real_lattice(2, 2)*real_lattice(3, 3) - real_lattice(3, 2)*real_lattice(2, 3)) + &
180 real_lattice(1, 2)*(real_lattice(2, 3)*real_lattice(3, 1) - real_lattice(3, 3)*real_lattice(2, 1)) + &
181 real_lattice(1, 3)*(real_lattice(2, 1)*real_lattice(3, 2) - real_lattice(3, 1)*real_lattice(2, 2))
184 kmesh_tol = 0.000001_dp
185 num_exclude_bands = 0
187 CALL w90_param_write(stdout)
193 nnlist_loc(:, 1:nntot) = nnlist(:, 1:nntot)
195 nncell_loc(:, :, 1:nntot) = nncell(:, :, 1:nntot)
197 DEALLOCATE (bk, bka, wb)
198 DEALLOCATE (nncell, neigh, nnlist)
199 DEALLOCATE (kpt_latt, kpt_cart, shell_list)
201 WRITE (stdout,
'(/a/)')
' Finished setting up k-point neighbours.'
209 INTEGER,
INTENT(IN) :: stdout
212 WRITE (stdout, *)
' +---------------------------------------------------+'
213 WRITE (stdout, *)
' | |'
214 WRITE (stdout, *)
' | WANNIER90 |'
215 WRITE (stdout, *)
' | |'
216 WRITE (stdout, *)
' +---------------------------------------------------+'
217 WRITE (stdout, *)
' | |'
218 WRITE (stdout, *)
' | Welcome to the Maximally-Localized |'
219 WRITE (stdout, *)
' | Generalized Wannier Functions code |'
220 WRITE (stdout, *)
' | http://www.wannier.org |'
221 WRITE (stdout, *)
' | |'
222 WRITE (stdout, *)
' | Wannier90 v2.0 Authors: |'
223 WRITE (stdout, *)
' | Arash A. Mostofi (Imperial College London) |'
224 WRITE (stdout, *)
' | Giovanni Pizzi (EPFL) |'
225 WRITE (stdout, *)
' | Ivo Souza (Universidad del Pais Vasco) |'
226 WRITE (stdout, *)
' | Jonathan R. Yates (University of Oxford) |'
227 WRITE (stdout, *)
' | |'
228 WRITE (stdout, *)
' | Wannier90 Contributors: |'
229 WRITE (stdout, *)
' | Young-Su Lee (KIST, S. Korea) |'
230 WRITE (stdout, *)
' | Matthew Shelley (Imperial College London) |'
231 WRITE (stdout, *)
' | Nicolas Poilvert (Penn State University) |'
232 WRITE (stdout, *)
' | Raffaello Bianco (Paris 6 and CNRS) |'
233 WRITE (stdout, *)
' | Gabriele Sclauzero (ETH Zurich) |'
234 WRITE (stdout, *)
' | |'
235 WRITE (stdout, *)
' | Wannier77 Authors: |'
236 WRITE (stdout, *)
' | Nicola Marzari (EPFL) |'
237 WRITE (stdout, *)
' | Ivo Souza (Universidad del Pais Vasco) |'
238 WRITE (stdout, *)
' | David Vanderbilt (Rutgers University) |'
239 WRITE (stdout, *)
' | |'
240 WRITE (stdout, *)
' | Please cite |'
241 WRITE (stdout, *)
' | |'
242 WRITE (stdout, *)
' | [ref] "Wannier90: A Tool for Obtaining Maximally |'
243 WRITE (stdout, *)
' | Localised Wannier Functions" |'
244 WRITE (stdout, *)
' | A. A. Mostofi, J. R. Yates, Y.-S. Lee, |'
245 WRITE (stdout, *)
' | I. Souza, D. Vanderbilt and N. Marzari |'
246 WRITE (stdout, *)
' | Comput. Phys. Commun. 178, 685 (2008) |'
247 WRITE (stdout, *)
' | |'
248 WRITE (stdout, *)
' | in any publications arising from the use of |'
249 WRITE (stdout, *)
' | this code. For the method please cite |'
250 WRITE (stdout, *)
' | |'
251 WRITE (stdout, *)
' | [ref] "Maximally Localized Generalised Wannier |'
252 WRITE (stdout, *)
' | Functions for Composite Energy Bands" |'
253 WRITE (stdout, *)
' | N. Marzari and D. Vanderbilt |'
254 WRITE (stdout, *)
' | Phys. Rev. B 56 12847 (1997) |'
255 WRITE (stdout, *)
' | |'
256 WRITE (stdout, *)
' | [ref] "Maximally Localized Wannier Functions |'
257 WRITE (stdout, *)
' | for Entangled Energy Bands" |'
258 WRITE (stdout, *)
' | I. Souza, N. Marzari and D. Vanderbilt |'
259 WRITE (stdout, *)
' | Phys. Rev. B 65 035109 (2001) |'
260 WRITE (stdout, *)
' | |'
261 WRITE (stdout, *)
' | |'
262 WRITE (stdout, *)
' | Copyright (c) 1996-2015 |'
263 WRITE (stdout, *)
' | Arash A. Mostofi, Jonathan R. Yates, |'
264 WRITE (stdout, *)
' | Young-Su Lee, Giovanni Pizzi, Ivo Souza, |'
265 WRITE (stdout, *)
' | David Vanderbilt and Nicola Marzari |'
266 WRITE (stdout, *)
' | |'
267 WRITE (stdout, *)
' | Release: 2.0.1 2nd April 2015 |'
268 WRITE (stdout, *)
' | |'
269 WRITE (stdout, *)
' | This program is free software; you can |'
270 WRITE (stdout, *)
' | redistribute it and/or modify it under the terms |'
271 WRITE (stdout, *)
' | of the GNU General Public License as published by |'
272 WRITE (stdout, *)
' | the Free Software Foundation; either version 2 of |'
273 WRITE (stdout, *)
' | the License, or (at your option) any later version|'
274 WRITE (stdout, *)
' | |'
275 WRITE (stdout, *)
' | This program is distributed in the hope that it |'
276 WRITE (stdout, *)
' | will be useful, but WITHOUT ANY WARRANTY; without |'
277 WRITE (stdout, *)
' | even the implied warranty of MERCHANTABILITY or |'
278 WRITE (stdout, *)
' | FITNESS FOR A PARTICULAR PURPOSE. See the GNU |'
279 WRITE (stdout, *)
' | General Public License for more details. |'
280 WRITE (stdout, *)
' | |'
281 WRITE (stdout, *)
' | You should have received a copy of the GNU General|'
282 WRITE (stdout, *)
' | Public License along with this program; if not, |'
283 WRITE (stdout, *)
' | write to the Free Software Foundation, Inc., |'
284 WRITE (stdout, *)
' | 675 Mass Ave, Cambridge, MA 02139, USA. |'
285 WRITE (stdout, *)
' | |'
286 WRITE (stdout, *)
' +---------------------------------------------------+'
295 SUBROUTINE w90_param_write(stdout)
296 INTEGER,
INTENT(IN) :: stdout
301 WRITE (stdout,
'(36x,a6)')
'------'
302 WRITE (stdout,
'(36x,a6)')
'SYSTEM'
303 WRITE (stdout,
'(36x,a6)')
'------'
305 WRITE (stdout,
'(28x,a22)')
'Lattice Vectors (Bohr)'
306 WRITE (stdout,
'(20x,a3,2x,3F11.6)')
'a_1', (real_lattice(1, i)*lenconfac, i=1, 3)
307 WRITE (stdout,
'(20x,a3,2x,3F11.6)')
'a_2', (real_lattice(2, i)*lenconfac, i=1, 3)
308 WRITE (stdout,
'(20x,a3,2x,3F11.6)')
'a_3', (real_lattice(3, i)*lenconfac, i=1, 3)
310 WRITE (stdout,
'(19x,a17,3x,f11.5)', advance=
'no') &
311 'Unit Cell Volume:', cell_volume*lenconfac**3
312 WRITE (stdout,
'(2x,a8)')
'(Bohr^3)'
314 WRITE (stdout,
'(22x,a34)')
'Reciprocal-Space Vectors (Bohr^-1)'
315 WRITE (stdout,
'(20x,a3,2x,3F11.6)')
'b_1', (recip_lattice(1, i)/lenconfac, i=1, 3)
316 WRITE (stdout,
'(20x,a3,2x,3F11.6)')
'b_2', (recip_lattice(2, i)/lenconfac, i=1, 3)
317 WRITE (stdout,
'(20x,a3,2x,3F11.6)')
'b_3', (recip_lattice(3, i)/lenconfac, i=1, 3)
318 WRITE (stdout, *)
' '
319 WRITE (stdout, *)
' '
321 WRITE (stdout,
'(32x,a)')
'------------'
322 WRITE (stdout,
'(32x,a)')
'K-POINT GRID'
323 WRITE (stdout,
'(32x,a)')
'------------'
324 WRITE (stdout, *)
' '
325 WRITE (stdout,
'(13x,a,i3,1x,a1,i3,1x,a1,i3,6x,a,i5)')
'Grid size =', mp_grid(1),
'x', mp_grid(2),
'x', mp_grid(3), &
326 'Total points =', num_kpts
327 WRITE (stdout, *)
' '
328 WRITE (stdout,
'(1x,a)')
'*----------------------------------------------------------------------------*'
329 WRITE (stdout,
'(1x,a)')
'| k-point Fractional Coordinate Cartesian Coordinate (Bohr^-1) |'
330 WRITE (stdout,
'(1x,a)')
'+----------------------------------------------------------------------------+'
332 WRITE (stdout,
'(1x,a1,i6,1x,3F10.5,3x,a1,1x,3F10.5,4x,a1)')
'|', &
333 nkp, kpt_latt(:, nkp),
'|', kpt_cart(:, nkp)/lenconfac,
'|'
335 WRITE (stdout,
'(1x,a)')
'*----------------------------------------------------------------------------*'
336 WRITE (stdout, *)
' '
338 END SUBROUTINE w90_param_write
343 SUBROUTINE w90_kmesh_get()
347 REAL(kind=
dp),
PARAMETER :: eta = 99999999.0_dp
349 INTEGER :: counter, i, ifound, j, l, loop, loop_b, loop_s, m, multi(search_shells), n, na, &
350 nap, ndnn, ndnntot, ndnnx, nkp, nkp2, nlist, nn, nnsh, nnshell(num_kpts, search_shells), &
352 LOGICAL :: isneg, ispos
353 REAL(kind=
dp) :: bb1, bbn, bk_local(3, num_nnmax, num_kpts), bweight(max_shells), ddelta, &
354 dist, dnn(search_shells), dnn0, dnn1, vkpp(3), vkpp2(3), wb_local(num_nnmax)
355 REAL(kind=
dp),
ALLOCATABLE :: bvec_tmp(:, :)
357 WRITE (stdout,
'(/1x,a)') &
358 '*---------------------------------- K-MESH ----------------------------------*'
361 CALL w90_kmesh_supercell_sort
369 DO nlist = 1, search_shells
371 DO loop = 1, (2*nsupcell + 1)**3
372 l = lmn(1, loop); m = lmn(2, loop); n = lmn(3, loop)
374 vkpp = kpt_cart(:, nkp) + matmul(lmn(:, loop), recip_lattice)
375 dist = sqrt((kpt_cart(1, 1) - vkpp(1))**2 &
376 + (kpt_cart(2, 1) - vkpp(2))**2 + (kpt_cart(3, 1) - vkpp(3))**2)
378 IF ((dist .GT. kmesh_tol) .AND. (dist .GT. dnn0 + kmesh_tol))
THEN
379 IF (dist .LT. dnn1 - kmesh_tol)
THEN
383 IF (dist .GT. (dnn1 - kmesh_tol) .AND. dist .LT. (dnn1 + kmesh_tol))
THEN
384 counter = counter + 1
389 IF (dnn1 .LT. eta - kmesh_tol) ndnntot = ndnntot + 1
391 multi(nlist) = counter
396 WRITE (stdout,
'(1x,a)')
'+----------------------------------------------------------------------------+'
397 WRITE (stdout,
'(1x,a)')
'| Distance to Nearest-Neighbour Shells |'
398 WRITE (stdout,
'(1x,a)')
'| ------------------------------------ |'
399 WRITE (stdout,
'(1x,a)')
'| Shell Distance (Bohr^-1) Multiplicity |'
400 WRITE (stdout,
'(1x,a)')
'| ----- ------------------ ------------ |'
402 WRITE (stdout,
'(1x,a,11x,i3,17x,f10.6,19x,i4,12x,a)')
'|', ndnn, dnn(ndnn)/lenconfac, multi(ndnn),
'|'
404 WRITE (stdout,
'(1x,a)')
'+----------------------------------------------------------------------------+'
407 CALL kmesh_shell_automatic(multi, dnn, bweight)
409 WRITE (stdout,
'(1x,a)', advance=
'no')
'| The following shells are used: '
410 DO ndnn = 1, num_shells
411 IF (ndnn .EQ. num_shells)
THEN
412 WRITE (stdout,
'(i3,1x)', advance=
'no') shell_list(ndnn)
414 WRITE (stdout,
'(i3,",")', advance=
'no') shell_list(ndnn)
417 DO l = 1, 11 - num_shells
418 WRITE (stdout,
'(4x)', advance=
'no')
420 WRITE (stdout,
'("|")')
423 DO loop_s = 1, num_shells
424 nntot = nntot + multi(shell_list(loop_s))
426 IF (nntot > num_nnmax)
THEN
427 WRITE (stdout,
'(a,i2,a)')
' **WARNING: kmesh has found >', num_nnmax,
' nearest neighbours**'
428 WRITE (stdout,
'(a)')
' '
429 WRITE (stdout,
'(a)')
' This is probably caused by an error in your unit cell specification'
430 WRITE (stdout,
'(a)')
' '
432 ALLOCATE (bvec_tmp(3, maxval(multi)))
435 DO shell = 1, search_shells
436 CALL kmesh_get_bvectors(multi(shell), 1, dnn(shell), bvec_tmp(:, 1:multi(shell)))
437 DO loop = 1, multi(shell)
438 counter = counter + 1
439 WRITE (stdout,
'(a,I4,1x,a,2x,3f12.6,2x,a,2x,f12.6,a)')
' | b-vector ', counter,
': (', &
440 bvec_tmp(:, loop)/lenconfac,
')', dnn(shell)/lenconfac,
' |'
443 WRITE (stdout,
'(a)')
' '
444 DEALLOCATE (bvec_tmp)
445 cpabort(
'kmesh_get: something wrong, found too many nearest neighbours')
448 ALLOCATE (nnlist(num_kpts, nntot))
449 ALLOCATE (neigh(num_kpts, nntot/2))
450 ALLOCATE (nncell(3, num_kpts, nntot))
453 ALLOCATE (bka(3, nntot/2))
454 ALLOCATE (bk(3, nntot, num_kpts))
457 DO loop_s = 1, num_shells
458 DO loop_b = 1, multi(shell_list(loop_s))
460 wb_local(nnx) = bweight(loop_s)
471 WRITE (stdout,
'(1x,a)')
'+----------------------------------------------------------------------------+'
472 WRITE (stdout,
'(1x,a)')
'| Shell # Nearest-Neighbours |'
473 WRITE (stdout,
'(1x,a)')
'| ----- -------------------- |'
480 ok:
DO ndnnx = 1, num_shells
481 ndnn = shell_list(ndnnx)
482 DO loop = 1, (2*nsupcell + 1)**3
483 l = lmn(1, loop); m = lmn(2, loop); n = lmn(3, loop)
484 vkpp2 = matmul(lmn(:, loop), recip_lattice)
485 DO nkp2 = 1, num_kpts
486 vkpp = vkpp2 + kpt_cart(:, nkp2)
487 dist = sqrt((kpt_cart(1, nkp) - vkpp(1))**2 &
488 + (kpt_cart(2, nkp) - vkpp(2))**2 + (kpt_cart(3, nkp) - vkpp(3))**2)
489 IF ((dist .GE. dnn(ndnn)*(1 - kmesh_tol)) .AND. (dist .LE. dnn(ndnn)*(1 + kmesh_tol)))
THEN
491 nnshell(nkp, ndnn) = nnshell(nkp, ndnn) + 1
492 nnlist(nkp, nnx) = nkp2
493 nncell(1, nkp, nnx) = l
494 nncell(2, nkp, nnx) = m
495 nncell(3, nkp, nnx) = n
496 bk_local(:, nnx, nkp) = vkpp(:) - kpt_cart(:, nkp)
499 IF (nnshell(nkp, ndnn) == multi(ndnn)) cycle ok
507 DO ndnnx = 1, num_shells
508 ndnn = shell_list(ndnnx)
509 WRITE (stdout,
'(1x,a,24x,i3,13x,i3,33x,a)')
'|', ndnn, nnshell(1, ndnn),
'|'
511 WRITE (stdout,
'(1x,"+",76("-"),"+")')
515 DO ndnnx = 1, num_shells
516 ndnn = shell_list(ndnnx)
517 DO nnsh = 1, nnshell(nkp, ndnn)
522 bb1 = bb1 + bk_local(i, nnx, 1)*bk_local(i, nnx, 1)
523 bbn = bbn + bk_local(i, nnx, nkp)*bk_local(i, nnx, nkp)
525 IF (abs(sqrt(bb1) - sqrt(bbn)) .GT. kmesh_tol)
THEN
526 WRITE (stdout,
'(1x,2f10.6)') bb1, bbn
527 cpabort(
'Non-symmetric k-point neighbours!')
542 DO ndnnx = 1, num_shells
543 ndnn = shell_list(ndnnx)
544 DO nnsh = 1, nnshell(1, ndnn)
546 ddelta = ddelta + wb_local(nnx)*bk_local(i, nnx, nkp)*bk_local(j, nnx, nkp)
549 IF ((i .EQ. j) .AND. (abs(ddelta - 1.0_dp) .GT. kmesh_tol))
THEN
550 WRITE (stdout,
'(1x,2i3,f12.8)') i, j, ddelta
551 cpabort(
'Eq. (B1) not satisfied in kmesh_get (1)')
553 IF ((i .NE. j) .AND. (abs(ddelta) .GT. kmesh_tol))
THEN
554 WRITE (stdout,
'(1x,2i3,f12.8)') i, j, ddelta
555 cpabort(
'Eq. (B1) not satisfied in kmesh_get (2)')
561 WRITE (stdout,
'(1x,a)')
'| Completeness relation is fully satisfied [Eq. (B1), PRB 56, 12847 (1997)] |'
562 WRITE (stdout,
'(1x,"+",76("-"),"+")')
567 DO ndnnx = 1, num_shells
568 ndnn = shell_list(ndnnx)
569 DO nnsh = 1, nnshell(1, ndnn)
571 wbtot = wbtot + wb_local(nnx)
583 CALL utility_compar(bka(1, nap), bk_local(1, nn, 1), ispos, isneg)
584 IF (isneg) ifound = 1
587 IF (ifound .EQ. 0)
THEN
590 bka(1, na) = bk_local(1, nn, 1)
591 bka(2, na) = bk_local(2, nn, 1)
592 bka(3, na) = bk_local(3, nn, 1)
595 IF (na .NE. nnh) cpabort(
'Did not find right number of bk directions')
597 WRITE (stdout,
'(1x,a)')
'| b_k Vectors (Bohr^-1) and Weights (Bohr^2) |'
598 WRITE (stdout,
'(1x,a)')
'| ------------------------------------------ |'
599 WRITE (stdout,
'(1x,a)')
'| No. b_k(x) b_k(y) b_k(z) w_b |'
600 WRITE (stdout,
'(1x,a)')
'| --- -------------------------------- -------- |'
602 WRITE (stdout,
'(1x,"|",11x,i3,5x,3f12.6,3x,f10.6,8x,"|")') &
603 i, (bk_local(j, i, 1)/lenconfac, j=1, 3), wb_local(i)*lenconfac**2
605 WRITE (stdout,
'(1x,"+",76("-"),"+")')
606 WRITE (stdout,
'(1x,a)')
'| b_k Directions (Bohr^-1) |'
607 WRITE (stdout,
'(1x,a)')
'| ------------------------ |'
608 WRITE (stdout,
'(1x,a)')
'| No. x y z |'
609 WRITE (stdout,
'(1x,a)')
'| --- -------------------------------- |'
611 WRITE (stdout,
'(1x,"|",11x,i3,5x,3f12.6,21x,"|")') i, (bka(j, i)/lenconfac, j=1, 3)
613 WRITE (stdout,
'(1x,"+",76("-"),"+")')
614 WRITE (stdout, *)
' '
623 CALL utility_compar(bka(1, na), bk_local(1, nn, nkp), ispos, isneg)
624 IF (ispos) neigh(nkp, na) = nn
627 IF (neigh(nkp, na) .EQ. 0)
THEN
628 WRITE (stdout, *)
' nkp,na=', nkp, na
629 cpabort(
'kmesh_get: failed to find neighbours for this kpoint')
636 wb(loop) = wb_local(loop)
639 DO loop_s = 1, num_kpts
641 bk(:, loop, loop_s) = bk_local(:, loop, loop_s)
645 END SUBROUTINE w90_kmesh_get
650 SUBROUTINE w90_kmesh_supercell_sort
659 INTEGER :: counter, indx(1), l, &
660 lmn_cp(3, (2*nsupcell + 1)**3), loop, &
662 REAL(kind=
dp) :: dist((2*nsupcell + 1)**3), &
663 dist_cp((2*nsupcell + 1)**3), pos(3)
667 dist(counter) = 0.0_dp
668 DO l = -nsupcell, nsupcell
669 DO m = -nsupcell, nsupcell
670 DO n = -nsupcell, nsupcell
671 IF (l == 0 .AND. m == 0 .AND. n == 0) cycle
672 counter = counter + 1
673 lmn(1, counter) = l; lmn(2, counter) = m; lmn(3, counter) = n
674 pos = matmul(lmn(:, counter), recip_lattice)
675 dist(counter) = sqrt(dot_product(pos, pos))
680 DO loop = (2*nsupcell + 1)**3, 1, -1
681 indx = internal_maxloc(dist)
682 dist_cp(loop) = dist(indx(1))
683 lmn_cp(:, loop) = lmn(:, indx(1))
684 dist(indx(1)) = -1.0_dp
690 END SUBROUTINE w90_kmesh_supercell_sort
697 FUNCTION internal_maxloc(dist)
704 REAL(kind=
dp),
INTENT(in) :: dist((2*nsupcell + 1)**3)
705 INTEGER :: internal_maxloc
707 INTEGER :: counter, guess(1), &
708 list((2*nsupcell + 1)**3), loop
716 DO loop = 1, (2*nsupcell + 1)**3
717 IF (loop == guess(1)) cycle
718 IF (abs(dist(loop) - dist(guess(1))) < eps8)
THEN
719 counter = counter + 1
724 internal_maxloc = minval(
list(1:counter))
726 END FUNCTION internal_maxloc
734 SUBROUTINE kmesh_shell_automatic(multi, dnn, bweight)
745 INTEGER,
INTENT(in) :: multi(search_shells)
746 REAL(kind=
dp),
INTENT(in) :: dnn(search_shells)
747 REAL(kind=
dp),
INTENT(out) :: bweight(max_shells)
749 INTEGER,
PARAMETER :: lwork = max_shells*10
750 REAL(kind=
dp),
PARAMETER :: target(6) = (/1.0_dp, 1.0_dp, 1.0_dp, 0.0_dp, 0.0_dp, 0.0_dp/)
752 INTEGER :: cur_shell, info, loop_b, loop_bn, &
753 loop_i, loop_j, loop_s, shell
754 LOGICAL :: b1sat, lpar
755 REAL(kind=
dp) :: delta, work(lwork)
756 REAL(kind=
dp),
ALLOCATABLE :: bvector(:, :, :)
757 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: singv
758 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: amat, smat, umat, vmat
760 ALLOCATE (bvector(3, maxval(multi), max_shells))
761 bvector = 0.0_dp; bweight = 0.0_dp
763 WRITE (stdout,
'(1x,a)')
'| The b-vectors are chosen automatically |'
766 DO shell = 1, search_shells
767 cur_shell = num_shells + 1
770 CALL kmesh_get_bvectors(multi(shell), 1, dnn(shell), bvector(:, 1:multi(shell), cur_shell))
774 IF (num_shells > 0)
THEN
775 DO loop_bn = 1, multi(shell)
776 DO loop_s = 1, num_shells
777 DO loop_b = 1, multi(shell_list(loop_s))
778 delta = dot_product(bvector(:, loop_bn, cur_shell), bvector(:, loop_b, loop_s))/ &
779 sqrt(dot_product(bvector(:, loop_bn, cur_shell), bvector(:, loop_bn, cur_shell))* &
780 dot_product(bvector(:, loop_b, loop_s), bvector(:, loop_b, loop_s)))
781 IF (abs(abs(delta) - 1.0_dp) < eps6) lpar = .true.
788 IF (iprint >= 3)
THEN
789 WRITE (stdout,
'(1x,a)')
'| This shell is linearly dependent on existing shells: Trying next shell |'
794 num_shells = num_shells + 1
795 shell_list(num_shells) = shell
797 ALLOCATE (amat(max_shells, num_shells))
798 ALLOCATE (umat(max_shells, max_shells))
799 ALLOCATE (vmat(num_shells, num_shells))
800 ALLOCATE (smat(num_shells, max_shells))
801 ALLOCATE (singv(num_shells))
802 amat = 0.0_dp; umat = 0.0_dp; vmat = 0.0_dp; smat = 0.0_dp; singv = 0.0_dp
805 DO loop_s = 1, num_shells
806 DO loop_b = 1, multi(shell_list(loop_s))
807 amat(1, loop_s) = amat(1, loop_s) + bvector(1, loop_b, loop_s)*bvector(1, loop_b, loop_s)
808 amat(2, loop_s) = amat(2, loop_s) + bvector(2, loop_b, loop_s)*bvector(2, loop_b, loop_s)
809 amat(3, loop_s) = amat(3, loop_s) + bvector(3, loop_b, loop_s)*bvector(3, loop_b, loop_s)
810 amat(4, loop_s) = amat(4, loop_s) + bvector(1, loop_b, loop_s)*bvector(2, loop_b, loop_s)
811 amat(5, loop_s) = amat(5, loop_s) + bvector(2, loop_b, loop_s)*bvector(3, loop_b, loop_s)
812 amat(6, loop_s) = amat(6, loop_s) + bvector(3, loop_b, loop_s)*bvector(1, loop_b, loop_s)
817 CALL dgesvd(
'A',
'A', max_shells, num_shells, amat, max_shells, singv, umat, &
818 max_shells, vmat, num_shells, work, lwork, info)
820 WRITE (stdout,
'(1x,a,1x,I1,1x,a)')
'kmesh_shell_automatic: Argument', abs(info),
'of dgesvd is incorrect'
821 cpabort(
'kmesh_shell_automatic: Problem with Singular Value Decomposition')
822 ELSE IF (info > 0)
THEN
823 cpabort(
'kmesh_shell_automatic: Singular Value Decomposition did not converge')
826 IF (any(abs(singv) < eps5))
THEN
827 IF (num_shells == 1)
THEN
828 CALL cp_abort(__location__,
"kmesh_shell_automatic: "// &
829 "Singular Value Decomposition has found a very small singular value.")
831 WRITE (stdout,
'(1x,a)')
'| SVD found small singular value, Rejecting this shell and trying the next |'
833 num_shells = num_shells - 1
834 DEALLOCATE (amat, umat, vmat, smat, singv)
840 DO loop_s = 1, num_shells
841 smat(loop_s, loop_s) = 1/singv(loop_s)
844 bweight(1:num_shells) = matmul(transpose(vmat), matmul(smat, matmul(transpose(umat),
TARGET)))
845 IF (iprint >= 2)
THEN
846 DO loop_s = 1, num_shells
847 WRITE (stdout,
'(1x,a,I2,a,f12.7,5x,a8,36x,a)')
'| Shell: ', loop_s, &
848 ' w_b ', bweight(loop_s)*lenconfac**2,
'('//trim(length_unit)//
'^2)',
'|'
855 DO loop_j = loop_i, 3
857 DO loop_s = 1, num_shells
858 DO loop_b = 1, multi(shell_list(loop_s))
859 delta = delta + bweight(loop_s)*bvector(loop_i, loop_b, loop_s)*bvector(loop_j, loop_b, loop_s)
862 IF (loop_i == loop_j)
THEN
863 IF (abs(delta - 1.0_dp) > kmesh_tol) b1sat = .false.
865 IF (loop_i /= loop_j)
THEN
866 IF (abs(delta) > kmesh_tol) b1sat = .false.
871 IF (.NOT. b1sat)
THEN
872 IF (shell < search_shells .AND. iprint >= 3)
THEN
873 WRITE (stdout,
'(1x,a,24x,a1)')
'| B1 condition is not satisfied: Adding another shell',
'|'
874 ELSEIF (shell == search_shells)
THEN
875 WRITE (stdout, *)
' '
876 WRITE (stdout,
'(1x,a,i3,a)')
'Unable to satisfy B1 with any of the first ', search_shells,
' shells'
877 WRITE (stdout,
'(1x,a)')
'Your cell might be very long, or you may have an irregular MP grid'
878 WRITE (stdout,
'(1x,a)')
'Try increasing the parameter search_shells in the win file (default=12)'
879 WRITE (stdout, *)
' '
880 cpabort(
'kmesh_get_automatic')
884 DEALLOCATE (amat, umat, vmat, smat, singv)
890 IF (.NOT. b1sat)
THEN
891 WRITE (stdout, *)
' '
892 WRITE (stdout,
'(1x,a,i3,a)')
'Unable to satisfy B1 with any of the first ', search_shells,
' shells'
893 WRITE (stdout,
'(1x,a)')
'Your cell might be very long, or you may have an irregular MP grid'
894 WRITE (stdout,
'(1x,a)')
'Try increasing the parameter search_shells in the win file (default=12)'
895 WRITE (stdout, *)
' '
896 cpabort(
'kmesh_get_automatic')
899 END SUBROUTINE kmesh_shell_automatic
908 SUBROUTINE kmesh_get_bvectors(multi, kpt, shell_dist, bvector)
915 INTEGER,
INTENT(in) :: multi, kpt
916 REAL(kind=
dp),
INTENT(in) :: shell_dist
917 REAL(kind=
dp),
INTENT(out) :: bvector(3, multi)
919 INTEGER :: loop, nkp2, num_bvec
920 REAL(kind=
dp) :: dist, vkpp(3), vkpp2(3)
925 ok:
DO loop = 1, (2*nsupcell + 1)**3
926 vkpp2 = matmul(lmn(:, loop), recip_lattice)
927 DO nkp2 = 1, num_kpts
928 vkpp = vkpp2 + kpt_cart(:, nkp2)
929 dist = sqrt((kpt_cart(1, kpt) - vkpp(1))**2 &
930 + (kpt_cart(2, kpt) - vkpp(2))**2 + (kpt_cart(3, kpt) - vkpp(3))**2)
931 IF ((dist .GE. shell_dist*(1.0_dp - kmesh_tol)) .AND. dist .LE. shell_dist*(1.0_dp + kmesh_tol))
THEN
932 num_bvec = num_bvec + 1
933 bvector(:, num_bvec) = vkpp(:) - kpt_cart(:, kpt)
936 IF (num_bvec == multi) cycle ok
940 IF (num_bvec < multi) cpabort(
'kmesh_get_bvector: Not enough bvectors found')
942 END SUBROUTINE kmesh_get_bvectors
951 PURE SUBROUTINE utility_compar(a, b, ispos, isneg)
952 REAL(kind=
dp),
DIMENSION(3),
INTENT(in) :: a, b
953 LOGICAL,
INTENT(out) :: ispos, isneg
955 ispos = sum((a - b)**2) .LT. eps8
956 isneg = sum((a + b)**2) .LT. eps8
957 END SUBROUTINE utility_compar
Defines the basic variable types.
integer, parameter, public dp
An array-based list which grows on demand. When the internal array is full, a new array of twice the ...
Definition of physical constants:
real(kind=dp), parameter, public bohr
Outtakes from Wannier90 code.
subroutine, public wannier_setup(mp_grid_loc, num_kpts_loc, real_lattice_loc, recip_lattice_loc, kpt_latt_loc, nntot_loc, nnlist_loc, nncell_loc, iounit)
...
subroutine, public w90_write_header(stdout)
...