37 use,
intrinsic :: iso_fortran_env
71 integer :: w90_what, w90_mode, w90_what_default
75 integer :: ii, nik, iter, nst
77 type(restart_t) :: restart
78 type(electrons_t),
pointer :: sys
79 logical :: w90_spinors, scdm_proj, w90_scdm
80 integer :: w90_nntot, w90_num_bands, w90_num_kpts
81 integer,
allocatable :: w90_nnk_list(:,:)
82 character(len=80) :: w90_prefix
83 integer :: w90_num_wann
84 real(real64),
allocatable :: w90_proj_centers(:,:)
85 integer,
allocatable :: w90_proj_lmr(:,:)
87 integer,
allocatable :: w90_spin_proj_component(:)
88 real(real64),
allocatable :: w90_spin_proj_axis(:,:)
89 integer :: w90_num_exclude
90 logical,
allocatable :: exclude_list(:)
91 integer,
allocatable :: band_index(:)
92 logical :: read_td_states
93 integer :: w90_spin_channel
96 integer,
allocatable :: jpvt(:)
97 complex(real64),
allocatable :: uk(:,:,:)
98 complex(real64),
allocatable :: psi(:,:)
99 complex(real64),
allocatable :: chi(:,:), chi_diag(:,:),chi2(:,:)
100 real(real64),
allocatable :: chi_eigenval(:), occ_temp(:)
101 real(real64) :: scdm_mu, scdm_sigma, smear, kvec(3), factor(3)
102 integer :: ist, jst, ik, idir
104 integer(int64) :: how
131 if (w90_prefix ==
'w90')
then
132 message(1) =
"oct-wannier90: the prefix is set by default to w90"
162 if (w90_mode == 0)
then
163 message(1) =
"Wannier90Mode must be set to a value different from 0."
183 w90_what_default = option__wannier90files__w90_mmn + option__wannier90files__w90_amn + option__wannier90files__w90_eig
224 if (sys%kpoints%use_symmetries)
then
225 message(1) =
'oct-wannier90: k-points symmetries are not allowed'
228 if (sys%kpoints%use_time_reversal)
then
229 message(1) =
'oct-wannier90: time-reversal symmetry is not allowed'
232 if (sys%kpoints%reduced%nshifts > 1)
then
233 message(1) =
'oct-wannier90: Wannier90 does not allow for multiple shifts of the k-point grid'
242 w90_spinors = .false.
247 do idir = sys%space%periodic_dim+1, sys%space%dim
248 factor(idir) =
m_two * sys%gr%box%bounding_box_l(idir)
250 call sys%ions%latt%scale(factor)
253 select case (w90_mode)
254 case (option__wannier90mode__w90_setup)
258 case (option__wannier90mode__w90_output)
261 case (option__wannier90mode__w90_wannier)
266 if (read_td_states)
then
268 sys%mc, ierr, sys%gr)
271 sys%mc, ierr, sys%gr)
276 if (dim == sys%st%d%dim .and. nik == sys%kpoints%reduced%npoints .and. nst == sys%st%nst)
then
278 ierr, iter, label =
": wannier90", skip=exclude_list)
280 write(
message(1),
'(a)')
'Restart structure not commensurate.'
288 message(1) =
"Wannier90Mode is set to an unsupported value."
292 safe_deallocate_a(exclude_list)
293 safe_deallocate_a(band_index)
294 safe_deallocate_a(w90_nnk_list)
295 safe_deallocate_a(w90_proj_centers)
296 safe_deallocate_a(w90_proj_lmr)
298 safe_deallocate_p(sys)
310 type(
ions_t),
intent(in) :: ions
312 class(
space_t),
intent(in) :: space
314 character(len=80) :: filename
315 integer :: w90_win, ia, axis(3), npath
319 assert(space%dim == 3)
322 filename = trim(adjustl(w90_prefix)) //
'.win'
325 write(w90_win,
'(a)')
'# this file has been created by the Octopus wannier90 utility'
326 write(w90_win,
'(a)')
' '
329 write(w90_win,
'(a)')
'begin unit_cell_cart'
330 write(w90_win,
'(a)')
'Ang'
334 write(w90_win,
'(a)')
'end unit_cell_cart'
335 write(w90_win,
'(a)')
' '
337 write(w90_win,
'(a)')
'begin atoms_frac'
338 do ia = 1, ions%natoms
339 write(w90_win,
'(a,2x,f13.8,f13.8,f13.8)') trim(ions%atom(ia)%label), ions%latt%cart_to_red(ions%pos(:, ia))
341 write(w90_win,
'(a)')
'end atoms_frac'
342 write(w90_win,
'(a)')
' '
345 write(w90_win,
'(a)')
'use_bloch_phases = .true.'
346 write(w90_win,
'(a)')
' '
348 write(w90_win,
'(a10,i4)')
'num_bands ', sys%st%nst
349 write(w90_win,
'(a9,i4)')
'num_wann ', sys%st%nst
350 write(w90_win,
'(a)')
' '
352 if (sys%st%d%ispin ==
spinors)
then
353 write(w90_win,
'(a)')
'spinors = .true.'
356 write(w90_win,
'(a)')
'spin = up'
360 write(w90_win,
'(a)')
'write_u_matrices = .true.'
361 write(w90_win,
'(a)')
'write_xyz = .true.'
362 write(w90_win,
'(a)')
' '
364 if (kpoints%reduced%npoints == 1)
then
365 write(w90_win,
'(a)')
'gamma_only = .true.'
366 write(w90_win,
'(a)')
' '
369 message(1) =
'oct-wannier90: need Monkhorst-Pack grid. Please specify %KPointsGrid'
374 npath = kpoints%nkpt_in_path()
376 axis(1:3) = kpoints%nik_axis(1:3)
377 assert(product(kpoints%nik_axis(1:3)) == kpoints%reduced%npoints - npath)
379 write(w90_win,
'(a8,i4,i4,i4)')
'mp_grid =', axis(1:3)
380 write(w90_win,
'(a)')
' '
381 write(w90_win,
'(a)')
'begin kpoints '
384 do ii = 1, kpoints%reduced%npoints-npath
385 write(w90_win,
'(f13.8,f13.8,f13.8)') - kpoints%reduced%red_point(1:3,ii)
387 write(w90_win,
'(a)')
'end kpoints '
406 if (read_td_states)
then
408 sys%mc, ierr, sys%gr)
411 sys%mc, ierr, sys%gr)
419 if (dim == sys%st%d%dim .and. nik == sys%kpoints%reduced%npoints .and. nst == sys%st%nst)
then
421 ierr, iter, label =
": wannier90", skip=exclude_list)
423 write(
message(1),
'(a)')
'Restart structure not commensurate.'
431 safe_allocate(jpvt(1:sys%gr%np_global))
432 safe_allocate(psi(1:sys%gr%np, 1:sys%st%d%dim))
433 safe_allocate(occ_temp(1:w90_num_bands))
436 do ist = 1, w90_num_bands
437 occ_temp(ist)= sys%st%occ(ist, 1)
438 sys%st%occ(ist, 1)=
m_half*
loct_erfc((sys%st%eigenval(ist, 1)-scdm_mu) / scdm_sigma)
444 do ist = 1, w90_num_bands
445 sys%st%occ(ist, 1) = occ_temp(ist)
448 safe_allocate(uk(1:w90_num_bands, 1:w90_num_bands, 1:nik))
451 safe_allocate(chi(1:w90_num_bands, 1:w90_num_bands))
452 safe_allocate(chi_diag(1:w90_num_bands, 1:w90_num_bands))
453 safe_allocate(chi2(1:w90_num_bands, 1:w90_num_bands))
454 safe_allocate(chi_eigenval(1:w90_num_bands))
456 chi(1:w90_num_bands, 1:w90_num_bands) =
m_zero
459 kvec(:) = sys%kpoints%reduced%point(:, ik)
462 ik_real = (ik-1)*2 + w90_spin_channel
467 do ist = 1, w90_num_bands
469 smear=
m_half *
loct_erfc((sys%st%eigenval(ist, ik_real) - scdm_mu) / scdm_sigma)
471 do jst = 1, w90_num_bands
472 chi(ist, jst) = smear * conjg(psi(jpvt(jst), 1)) &
473 *
exp(
m_zi * dot_product(sys%gr%x(jpvt(jst), 1:3), kvec(1:3)))
479 chi_diag = matmul(conjg(transpose(chi)), chi)
481 chi2 = conjg(transpose(chi_diag))
484 if (any(chi_eigenval(:) .lt.
m_zero))
then
485 message(1) =
'SCDM Wannierization failed because chi matrix is'
486 message(2) =
'ill conditioned. Try increasingin scdm_sigma and/or'
491 do ist = 1, w90_num_bands
492 chi_eigenval(ist) =
m_one /
sqrt(chi_eigenval(ist))
493 chi2(ist, 1:w90_num_bands) = chi_eigenval(ist) * chi2(ist, 1:w90_num_bands)
497 uk(:,:,ik) = matmul(chi, matmul(chi_diag,chi2))
501 safe_deallocate_a(chi)
502 safe_deallocate_a(psi)
503 safe_deallocate_a(chi_diag)
504 safe_deallocate_a(chi2)
505 safe_deallocate_a(chi_eigenval)
506 safe_deallocate_a(jpvt)
507 safe_deallocate_a(psi)
508 safe_deallocate_a(occ_temp)
512 if (
bitand(w90_what, option__wannier90files__w90_mmn) /= 0)
then
516 if (
bitand(w90_what, option__wannier90files__w90_unk) /= 0)
then
517 call write_unk(sys%space, sys%gr, sys%st)
520 if (
bitand(w90_what, option__wannier90files__w90_amn) /= 0)
then
524 if (
bitand(w90_what, option__wannier90files__w90_eig) /= 0)
then
528 safe_deallocate_a(uk)
529 safe_deallocate_a(w90_spin_proj_component)
530 safe_deallocate_a(w90_spin_proj_axis)
537 integer :: w90_nnkp, itemp, dummyint, io
538 character(len=80) :: filename, dummy, dummy1, dummy2, line
539 logical :: exist, parse_is_ok
540 real(real64) :: dummyr(7)
544 w90_num_kpts = product(sys%kpoints%nik_axis(1:3))
548 filename = trim(adjustl(w90_prefix)) //
'.nnkp'
550 message(1) =
"oct-wannier90: Parsing "//filename
553 inquire(file=filename,exist=exist)
554 if (.not. exist)
then
555 message(1) =
'oct-wannier90: Cannot find specified Wannier90 nnkp file.'
556 write(
message(2),
'(a)')
'Please run wannier90.x -pp '// trim(adjustl(w90_prefix)) //
' first.'
560 parse_is_ok = .false.
565 read(w90_nnkp, *, iostat=io) dummy, dummy1
566 if (io == iostat_end)
exit
568 if (dummy ==
'begin' .and. dummy1 ==
'kpoints')
then
569 read(w90_nnkp,*) itemp
570 if (itemp /= w90_num_kpts)
then
571 message(1) =
'oct-wannier90: wannier90 setup seems to have been done with a different number of k-points.'
581 if (.not. parse_is_ok)
then
582 message(1) =
'oct-wannier90: Did not find the kpoints block in nnkp file'
585 parse_is_ok = .false.
591 read(w90_nnkp, *, iostat=io) dummy, dummy1
592 if (io == iostat_end)
exit
594 if (dummy ==
'begin' .and. dummy1 ==
'nnkpts')
then
595 read(w90_nnkp,*) w90_nntot
596 safe_allocate(w90_nnk_list(1:5, 1:w90_num_kpts * w90_nntot))
597 do ii = 1, w90_num_kpts * w90_nntot
598 read(w90_nnkp,*) w90_nnk_list(1:5, ii)
601 read(w90_nnkp,*) dummy
602 if (dummy /=
'end')
then
603 message(1) =
'oct-wannier90: There dont seem to be enough k-points in nnkpts file to.'
611 if (.not. parse_is_ok)
then
612 message(1) =
'oct-wannier90: Did not find nnkpts block in nnkp file'
618 safe_allocate(exclude_list(1:sys%st%nst))
620 exclude_list(1:sys%st%nst) = .false.
623 read(w90_nnkp, *, iostat=io) dummy, dummy1
624 if (io == iostat_end)
exit
625 if (dummy ==
'begin' .and. dummy1 ==
'exclude_bands')
then
626 read(w90_nnkp, *) w90_num_exclude
627 do ii = 1, w90_num_exclude
628 read(w90_nnkp, *) itemp
629 if(itemp > sys%st%nst)
then
630 message(1) =
'oct-wannier90: The exclude_bands list contains a state index higher than the number of states.'
633 exclude_list(itemp) = .
true.
636 read(w90_nnkp, *) dummy
637 if (dummy /=
'end')
then
638 message(1) =
'oct-wannier90: There dont seem to be enough bands in exclude_bands list.'
647 w90_num_bands = sys%st%nst - w90_num_exclude
649 safe_allocate(band_index(1:sys%st%nst))
651 do ii = 1, sys%st%nst
652 if (exclude_list(ii)) cycle
654 band_index(ii) = itemp
657 if (
bitand(w90_what, option__wannier90files__w90_amn) /= 0 &
658 .or. w90_mode == option__wannier90mode__w90_wannier )
then
663 read(w90_nnkp, *, iostat=io) dummy, dummy1
664 if (io == iostat_end)
then
665 message(1) =
'oct-wannier90: Did not find projections block in w90.nnkp file'
669 if (dummy ==
'begin' .and. (dummy1 ==
'projections' .or. dummy1 ==
'spinor_projections'))
then
671 if (dummy1 ==
'spinor_projections')
then
673 if (sys%st%d%ispin /=
spinors)
then
674 message(1) =
'oct-wannier90: Spinor = .true. is only valid with spinors wavefunctions.'
678 message(1) =
'oct-wannier90: Spinor interface incomplete. Note there is no quantization axis implemented'
681 if (sys%st%d%ispin ==
spinors)
then
682 message(1) =
'oct-wannier90: Octopus has spinors wavefunctions but spinor_projections is not defined.'
683 message(2) =
'oct-wannier90: Please check the input file for wannier 90.'
688 read(w90_nnkp, *) w90_nproj
691 w90_num_wann = w90_nproj
693 if(w90_nproj == 0) w90_num_wann = w90_num_bands
695 safe_allocate(w90_proj_centers(1:3, 1:w90_nproj))
696 safe_allocate(w90_proj_lmr(1:w90_nproj, 1:3))
697 if (w90_spinors)
then
698 safe_allocate(w90_spin_proj_component(1:w90_nproj))
700 if (w90_spinors)
then
701 safe_allocate(w90_spin_proj_axis(1:w90_nproj, 1:3))
705 read(w90_nnkp, *) w90_proj_centers(1:3, ii), w90_proj_lmr(ii, 1:3)
707 read(w90_nnkp, *) dummyr(1:7)
708 if (w90_spinors)
then
709 read(w90_nnkp, *) w90_spin_proj_component(ii), w90_spin_proj_axis(ii, 1:3)
711 if (w90_spin_proj_component(ii) == -1) w90_spin_proj_component(ii) = 2
715 read(w90_nnkp, *) dummy
716 if (dummy /=
'end')
then
717 message(1) =
'oct-wannier90: There dont seem to be enough projections in nnkpts file to.'
727 read(w90_nnkp, *, iostat=io) dummy, dummy1
728 if (io == iostat_end)
exit
730 if (dummy ==
'begin' .and. dummy1 ==
'auto_projections')
then
732 read(w90_nnkp, *) w90_nproj
733 w90_num_wann = w90_nproj
735 if (.not. w90_scdm)
then
736 message(1) =
'oct-wannier90: Found auto_projections block. Currently the only implemented automatic way'
737 message(2) =
'oct-wannier90: to compute projections is the SCDM method.'
738 message(3) =
'oct-wannier90: Please set Wannier90UseSCDM = yes in the inp file.'
742 if (w90_nproj /= w90_num_bands)
then
743 message(1) =
'oct-wannier90: In auto_projections block first row needs to be equal to num_bands.'
746 read(w90_nnkp, *) dummyint
747 if (dummyint /= 0)
then
748 message(1) =
'oct-wannier90: The second row in auto_projections has to be 0, per Wannier90 documentation.'
757 message(1) =
"oct-wannier90: Finished parsing "//filename
762 filename = trim(adjustl(w90_prefix)) //
'.win'
763 message(1) =
"oct-wannier90: Parsing "//filename
767 read(w90_nnkp, fmt=
'(a)', iostat=io) line
768 if (io == iostat_end)
exit
769 if (index(line,
'=') > 0)
then
770 read(line, *, iostat=io) dummy, dummy2, dummy1
772 read(line, *, iostat=io) dummy, dummy1
776 if (dummy ==
'spin')
then
778 message(1) =
'oct-wannier90: The variable spin is set for a non spin-polarized calculation.'
782 if (dummy1 ==
'up')
then
784 else if (dummy1 ==
'down')
then
787 message(1) =
'oct-wannier90: Error parsing the variable spin.'
795 write(
message(1),
'(a,i1)')
'oct-wannier90: Using spin channel ', w90_spin_channel
799 message(1) =
"oct-wannier90: Finished parsing "//filename
808 class(
mesh_t),
intent(in) :: mesh
811 integer :: ist, jst, ik, ip, w90_mmn, iknn, idim, ibind
812 real(real64) :: Gcart(3)
814 character(len=80) :: filename
815 complex(real64),
allocatable :: overlap(:)
816 complex(real64),
allocatable :: psim(:,:), psin(:,:), phase(:)
818 integer :: inode, node_fr, node_to
819 type(mpi_request) :: send_req
825 if (st%parallel_in_states)
then
829 message(1) =
"Info: Computing the overlap matrix"
833 filename =
'./'// trim(adjustl(w90_prefix))//
'.mmn'
838 write(w90_mmn,*)
'Created by oct-wannier90'
839 write(w90_mmn,*) w90_num_bands, w90_num_kpts, w90_nntot
842 safe_allocate(psim(1:mesh%np, 1:st%d%dim))
843 safe_allocate(psin(1:mesh%np, 1:st%d%dim))
844 safe_allocate(phase(1:mesh%np))
845 safe_allocate(overlap(1:w90_num_bands))
849 do ii = 1, w90_num_kpts * w90_nntot
850 ik = w90_nnk_list(1, ii)
851 iknn = w90_nnk_list(2, ii)
852 g(1:3) = w90_nnk_list(3:5, ii)
853 if (
mpi_grp_is_root(
mpi_world))
write(w90_mmn,
'(I10,2x,I10,2x,I3,2x,I3,2x,I3)') ik, iknn, g
857 ik = (ik-1)*2 + w90_spin_channel
858 iknn = (iknn-1)*2 + w90_spin_channel
863 if(ik >= st%d%kpt%start .and. ik <= st%d%kpt%end)
then
872 if (any(g /= 0))
then
874 phase(ip) =
exp(-
m_zi*dot_product(mesh%x(ip,1:3), gcart(1:3)))
882 if (exclude_list(jst)) cycle
885 if ( .not. st%d%kpt%parallel .and. .not. st%parallel_in_states)
then
890 do inode = 0, st%d%kpt%mpi_grp%size-1
891 if(iknn >= st%st_kpt_task(inode,3) .and. iknn <= st%st_kpt_task(inode,4))
then
894 if(ik >= st%st_kpt_task(inode,3) .and. ik <= st%st_kpt_task(inode,4))
then
901 send_req = mpi_request_null
906 if(node_to /= st%d%kpt%mpi_grp%rank)
then
907 call st%d%kpt%mpi_grp%isend(psin, mesh%np*st%d%dim, mpi_double_complex, node_to, send_req)
911 if(node_to == st%d%kpt%mpi_grp%rank .and. node_to /= node_fr)
then
912 call st%d%kpt%mpi_grp%recv(psin, mesh%np*st%d%dim, mpi_double_complex, node_fr)
914 if (send_req /= mpi_request_null)
then
915 call st%d%kpt%mpi_grp%wait(send_req)
921 if(ik >= st%d%kpt%start .and. ik <= st%d%kpt%end)
then
924 if (any(g /= 0))
then
926 do idim = 1, st%d%dim
928 psin(ip, idim) = psin(ip, idim) * phase(ip)
937 if (exclude_list(ist)) cycle
939 batch => st%group%psib(st%group%iblock(ist), ik)
941 select case (batch%status())
943 overlap(band_index(ist)) =
m_z0
944 do idim = 1, st%d%dim
945 ibind = batch%inv_index((/ist, idim/))
946 overlap(band_index(ist)) = overlap(band_index(ist)) + &
947 zmf_dotp(mesh, batch%zff_linear(:, ibind), psin(:,idim), reduce = .false.)
952 overlap(band_index(ist)) =
zmf_dotp(mesh, st%d%dim, psim, psin, reduce = .false.)
957 if (mesh%parallel_in_domains)
then
959 call mesh%allreduce(overlap)
963 if(st%d%kpt%parallel)
then
970 if (exclude_list(ist)) cycle
971 write(w90_mmn,
'(e18.10,2x,e18.10)') overlap(band_index(ist))
980 safe_deallocate_a(psim)
981 safe_deallocate_a(psin)
982 safe_deallocate_a(phase)
983 safe_deallocate_a(overlap)
993 integer :: ist, ik, w90_eig
994 character(len=80) :: filename
998 if (sys%st%parallel_in_states)
then
1003 filename =
'./'//trim(adjustl(w90_prefix))//
'.eig'
1005 do ik = 1, w90_num_kpts
1006 do ist = 1, sys%st%nst
1007 if (exclude_list(ist)) cycle
1009 write(w90_eig,
'(I5,2x,I8,2x,e18.10)') band_index(ist), ik, &
1012 write(w90_eig,
'(I5,2x,I8,2x,e18.10)') band_index(ist), ik, &
1026 class(
space_t),
intent(in) :: space
1027 class(
mesh_t),
intent(in) :: mesh
1030 integer :: ist, ik, unk_file, ispin
1031 integer :: ix, iy, iz
1032 character(len=80) :: filename
1033 complex(real64),
allocatable :: psi(:)
1039 if (st%d%kpt%parallel)
then
1043 if (sys%gr%parallel_in_domains)
then
1047 if (st%parallel_in_states)
then
1054 safe_allocate(psi(1:mesh%np))
1057 mesh%coord_system, need_partition=.not.mesh%parallel_in_domains)
1062 do ik = 1, w90_num_kpts
1063 do ispin = 1, st%d%dim
1065 write(filename,
'(a,i5.5,a1,i1)')
'./UNK', ik,
'.', ispin
1068 write(unk_file) mesh%idx%ll(1:mesh%idx%dim), ik, w90_num_bands
1073 if (exclude_list(ist)) cycle
1083 if (cube%parallel_in_domains)
then
1084 assert(.not. cube%parallel_in_domains)
1090 write(unk_file) (((cf%zrs(ix,iy,iz), ix=1,cube%rs_n_global(1)), iy=1,cube%rs_n_global(2)), iz=1,cube%rs_n_global(3))
1100 safe_deallocate_a(psi)
1108 class(
space_t),
intent(in) :: space
1109 class(
mesh_t),
intent(in) :: mesh
1114 integer :: ist, ik, w90_amn, idim, iw, ip, ik_real
1115 real(real64) :: center(3), kpoint(3), threshold
1116 character(len=80) :: filename
1117 complex(real64),
allocatable :: psi(:,:), phase(:), projection(:)
1118 real(real64),
allocatable :: ylm(:)
1124 if (st%parallel_in_states)
then
1128 filename =
'./'// trim(adjustl(w90_prefix))//
'.amn'
1133 write(w90_amn,*)
'Created by oct-wannier90'
1134 write(w90_amn,*) w90_num_bands, w90_num_kpts, w90_num_wann
1139 message(1) =
"Info: Writing projections obtained from SCDM."
1142 if (st%d%kpt%parallel)
then
1147 do ik = 1, w90_num_kpts
1149 if (exclude_list(ist)) cycle
1151 do iw = 1, w90_nproj
1152 write (w90_amn,
'(I5,2x,I5,2x,I5,2x,e18.10,2x,e18.10)') band_index(ist), iw, ik, uk(band_index(ist),iw,ik)
1160 message(1) =
"Info: Computing the projection matrix"
1166 safe_allocate(orbitals(1:w90_nproj))
1171 orbitals(iw)%norbs = 1
1172 orbitals(iw)%ndim = 1
1173 orbitals(iw)%radius = -
log(threshold)
1174 orbitals(iw)%use_submesh = .false.
1177 center(1:3) = latt%red_to_cart(w90_proj_centers(1:3, iw))
1178 call submesh_init(orbitals(iw)%sphere, space, mesh, latt, center, orbitals(iw)%radius)
1181 safe_allocate(ylm(1:orbitals(iw)%sphere%np))
1183 call ylm_wannier(ylm, w90_proj_lmr(iw,1), w90_proj_lmr(iw,2), &
1184 orbitals(iw)%sphere%r, orbitals(iw)%sphere%rel_x, orbitals(iw)%sphere%np)
1187 if (w90_proj_lmr(iw,3) == 1)
then
1188 do ip = 1,orbitals(iw)%sphere%np
1189 ylm(ip) = ylm(ip)*
m_two*
exp(-orbitals(iw)%sphere%r(ip))
1195 safe_allocate(orbitals(iw)%zorb(1:orbitals(iw)%sphere%np, 1, 1))
1196 orbitals(iw)%zorb(1:orbitals(iw)%sphere%np, 1, 1) = ylm(1:orbitals(iw)%sphere%np)
1197 safe_deallocate_a(ylm)
1199 safe_allocate(orbitals(iw)%phase(1:orbitals(iw)%sphere%np, st%d%kpt%start:st%d%kpt%end))
1201 safe_allocate(orbitals(iw)%eorb_mesh(1:mesh%np, 1, 1, st%d%kpt%start:st%d%kpt%end))
1202 orbitals(iw)%eorb_mesh(:,:,:,:) =
m_z0
1205 kpt_max = w90_num_kpts)
1209 safe_allocate(psi(1:mesh%np, 1:st%d%dim))
1210 safe_allocate(phase(1:mesh%np))
1211 safe_allocate(projection(1:w90_nproj))
1213 do ik = 1, w90_num_kpts
1214 kpoint(1:space%dim) = kpoints%get_point(ik)
1216 phase(ip) =
exp(-
m_zi* sum(mesh%x(ip, 1:space%dim) * kpoint(1:space%dim)))
1221 ik_real = (ik-1)*2 + w90_spin_channel
1228 if (exclude_list(ist)) cycle
1232 if(ik_real >= st%d%kpt%start .and. ik_real <= st%d%kpt%end)
then
1235 do idim = 1, st%d%dim
1238 psi(ip, idim) = psi(ip, idim)*phase(ip)
1242 do iw = 1, w90_nproj
1244 if (w90_spinors) idim = w90_spin_proj_component(iw)
1248 projection(iw) =
zmf_dotp(mesh, psi(1:mesh%np,idim), &
1249 orbitals(iw)%eorb_mesh(1:mesh%np,1,1,ik_real), reduce = .false.)
1252 if (mesh%parallel_in_domains)
then
1254 call mesh%allreduce(projection)
1259 if(st%d%kpt%parallel)
then
1264 do iw = 1, w90_nproj
1265 write (w90_amn,
'(I5,2x,I5,2x,I5,2x,e18.10,2x,e18.10)') band_index(ist), iw, ik, projection(iw)
1271 safe_deallocate_a(psi)
1272 safe_deallocate_a(phase)
1273 safe_deallocate_a(projection)
1275 do iw = 1, w90_nproj
1278 safe_deallocate_a(orbitals)
1291 class(space_t),
intent(in) :: space
1292 class(mesh_t),
intent(in) :: mesh
1293 type(ions_t),
intent(in) :: ions
1294 type(states_elec_t),
intent(in) :: st
1295 type(kpoints_t),
intent(in) :: kpoints
1297 integer :: w90_u_mat, w90_xyz, nwann, nik
1298 integer :: ik, iw, iw2, ip, ipmax, rankmax
1299 real(real64),
allocatable :: centers(:,:)
1300 complex(real64),
allocatable :: Umnk(:,:,:)
1301 complex(real64),
allocatable :: zwn(:), psi(:,:), phase(:)
1302 character(len=MAX_PATH_LEN) :: fname
1303 real(real64) :: kpoint(3), wmod, wmodmax, xx(space%dim)
1304 character(len=2) :: dum
1306 type(unit_t) :: fn_unit
1307 complex(real64) :: scal
1311 assert(st%d%ispin /= spinors)
1313 message(1) =
"oct-wannier90: Constructing the Wannier states from the U matrix."
1314 call messages_info(1)
1316 inquire(file=trim(trim(adjustl(w90_prefix))//
'_centres.xyz'),exist=exist)
1317 if (.not. exist)
then
1318 message(1) =
'oct-wannier90: Cannot find the Wannier90 file seedname_centres.xyz.'
1319 write(message(2),
'(a)')
'Please run wannier90.x with "write_xyz=.true." in '// trim(adjustl(w90_prefix)) //
'.'
1320 call messages_fatal(2)
1323 w90_xyz = io_open(trim(trim(adjustl(w90_prefix))//
'_centres.xyz'), global_namespace, action=
'read')
1325 safe_allocate(centers(1:3, 1:w90_num_wann))
1329 do iw = 1, w90_num_wann
1330 read(w90_xyz, *) dum, centers(1:3, iw)
1332 centers(1:3, iw) = units_to_atomic(unit_angstrom, centers(1:3, iw))
1334 call io_close(w90_xyz)
1337 inquire(file=trim(trim(adjustl(w90_prefix))//
'_u_dis.mat'),exist=exist)
1339 message(1) =
'oct-wannier90: Calculation of Wannier states with disentanglement is not yet supported.'
1340 call messages_fatal(1)
1343 inquire(file=trim(trim(adjustl(w90_prefix))//
'_u.mat'),exist=exist)
1344 if (.not. exist)
then
1345 message(1) =
'oct-wannier90: Cannot find the Wannier90 seedname_u.mat file.'
1346 write(message(2),
'(a)')
'Please run wannier90.x with "write_u_matrices=.true." in '// trim(adjustl(w90_prefix)) //
'.'
1347 call messages_fatal(2)
1349 w90_u_mat = io_open(trim(trim(adjustl(w90_prefix))//
'_u.mat'), global_namespace, action=
'read')
1355 read(w90_u_mat, *) nik, nwann, nwann
1356 if (nik /= w90_num_kpts .or. nwann /= w90_num_wann)
then
1357 print *, w90_num_wann, w90_num_kpts, nik, nwann
1358 message(1) =
"The file contains U matrices is inconsistent with the .win file."
1359 call messages_fatal(1)
1362 safe_allocate(umnk(1:w90_num_wann, 1:w90_num_wann, 1:w90_num_kpts))
1364 do ik = 1, w90_num_kpts
1369 read(w90_u_mat,
'(f15.10,sp,f15.10)') ((umnk(iw, iw2, ik), iw=1, w90_num_wann), iw2=1, w90_num_wann)
1372 call io_close(w90_u_mat)
1375 call parse_variable(global_namespace,
'OutputFormat', 0, how)
1377 call io_mkdir(
'wannier', global_namespace)
1380 safe_allocate(zwn(1:mesh%np))
1381 safe_allocate(psi(1:mesh%np, 1:st%d%dim))
1382 safe_allocate(phase(1:mesh%np))
1384 do iw = 1, w90_num_wann
1388 do ik = 1, w90_num_kpts
1389 kpoint(1:space%dim) = kpoints%get_point(ik, absolute_coordinates=.
true.)
1393 xx = mesh%x(ip, 1:space%dim)-centers(1:space%dim, iw)
1394 xx = ions%latt%fold_into_cell(xx)
1395 phase(ip) =
exp(-m_zi* sum( xx * kpoint(1:space%dim)))
1399 if (exclude_list(iw2)) cycle
1401 if (st%d%ispin /= spin_polarized)
then
1402 call states_elec_get_state(st, mesh, iw2, ik, psi)
1404 call states_elec_get_state(st, mesh, iw2, (ik-1)*2+w90_spin_channel, psi)
1409 zwn(ip) = zwn(ip) + umnk(band_index(iw2), iw, ik) * psi(ip, 1) * phase(ip)
1419 wmod = real(zwn(ip)*conjg(zwn(ip)), real64)
1420 if (wmod > wmodmax)
then
1425 scal =
sqrt(wmodmax)/zwn(ipmax)/w90_num_kpts
1426 call mesh_minmaxloc(mesh, wmodmax, rankmax, mpi_maxloc)
1427 call mesh%mpi_grp%bcast(scal, 1, mpi_double_complex, rankmax)
1428 call lalg_scal(mesh%np, scal, zwn)
1431 fn_unit =
sqrt(units_out%length**(-space%dim))
1432 write(fname,
'(a,i3.3)')
'wannier-', iw
1433 call zio_function_output(how,
"wannier", trim(fname), global_namespace, space, mesh, &
1434 zwn, fn_unit, ierr, pos=ions%pos, atoms=ions%atom, grp = st%dom_st_kpt_mpi_grp)
1439 if(abs(real(zwn(ip), real64)) >= 1e-2_real64)
then
1440 wmodmax = max(wmodmax, abs(aimag(zwn(ip)))/abs(real(zwn(ip), real64)))
1443 call mesh_minmaxloc(mesh, wmodmax, rankmax, mpi_maxloc)
1445 write(message(1),
'(a,i4,a,f11.6)')
'oct-wannier90: Wannier function ', iw,
' Max. Im/Re Ratio = ', wmodmax
1446 call messages_info(1)
1449 safe_deallocate_a(umnk)
1450 safe_deallocate_a(zwn)
1451 safe_deallocate_a(psi)
1452 safe_deallocate_a(phase)
1453 safe_deallocate_a(centers)
double log(double __x) __attribute__((__nothrow__
double exp(double __x) __attribute__((__nothrow__
double sqrt(double __x) __attribute__((__nothrow__
This module implements batches of mesh functions.
integer, parameter, public batch_not_packed
functions are stored in CPU memory, unpacked order
integer, parameter, public batch_device_packed
functions are stored in device memory in packed order
integer, parameter, public batch_packed
functions are stored in CPU memory, in transposed (packed) order
This module handles the calculation mode.
type(calc_mode_par_t), public calc_mode_par
Singleton instance of parallel calculation mode.
integer, parameter, public p_strategy_states
parallelization in states
subroutine, public zmesh_to_cube(mesh, mf, cube, cf)
The next two subroutines convert a function between the normal mesh and the cube.
subroutine, public dcube_function_free_rs(cube, cf)
Deallocates the real space grid.
subroutine, public zcube_function_alloc_rs(cube, cf, in_device, force_alloc)
Allocates locally the real space grid, if PFFT library is not used. Otherwise, it assigns the PFFT re...
subroutine, public cube_init(cube, nn, namespace, space, spacing, coord_system, fft_type, fft_library, dont_optimize, nn_out, mpi_grp, need_partition, tp_enlarge, blocksize)
subroutine, public cube_end(cube)
subroutine, public cube_init_cube_map(cube, mesh)
integer, parameter, public unpolarized
Parameters...
integer, parameter, public spinors
integer, parameter, public spin_polarized
Fast Fourier Transform module. This module provides a single interface that works with different FFT ...
subroutine, public fft_all_init(namespace)
initialize the table
subroutine, public fft_all_end()
delete all plans
real(real64), parameter, public m_two
subroutine, public global_end()
Finalise parser varinfo file, and MPI.
real(real64), parameter, public m_huge
real(real64), parameter, public m_zero
complex(real64), parameter, public m_z0
complex(real64), parameter, public m_zi
subroutine, public global_init(communicator)
Initialise Octopus.
real(real64), parameter, public m_half
real(real64), parameter, public m_one
This module implements the underlying real-space grid.
subroutine, public io_init(defaults)
If the argument defaults is present and set to true, then the routine will not try to read anything f...
subroutine, public io_close(iunit, grp)
subroutine, public io_end()
integer function, public io_open(file, namespace, action, status, form, position, die, recl, grp)
subroutine, public kpoints_to_absolute(latt, kin, kout)
This module defines various routines, operating on mesh functions.
This module defines the meshes, which are used in Octopus.
subroutine, public messages_end()
subroutine, public messages_not_implemented(feature, namespace)
subroutine, public messages_init(output_dir)
subroutine, public messages_warning(no_lines, all_nodes, namespace)
subroutine, public messages_info(no_lines, iunit, verbose_limit, stress, all_nodes, namespace)
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
subroutine, public messages_experimental(name, namespace)
logical function mpi_grp_is_root(grp)
Is the current MPI process of grpcomm, root.
type(mpi_grp_t), public mpi_world
This module handles the communicators for the various parallelization strategies.
type(namespace_t), public global_namespace
subroutine, public orbitalset_init(this)
subroutine, public orbitalset_end(this)
subroutine, public orbitalset_update_phase(os, dim, kpt, kpoints, spin_polarized, vec_pot, vec_pot_var, kpt_max)
Build the phase correction to the global phase in case the orbital crosses the border of the simulato...
logical function, public parse_is_defined(namespace, name)
subroutine, public parser_init()
Initialise the Octopus parser.
subroutine, public parser_end()
End the Octopus parser.
subroutine, public profiling_end(namespace)
subroutine, public profiling_out(label)
Increment out counter and sum up difference between entry and exit time.
subroutine, public profiling_in(label, exclude)
Increment in counter and save entry time.
subroutine, public profiling_init(namespace)
Create profiling subdirectory.
subroutine, public restart_module_init(namespace)
integer, parameter, public restart_gs
subroutine, public restart_init(restart, namespace, data_type, type, mc, ierr, mesh, dir, exact)
Initializes a restart object.
integer, parameter, public restart_td
integer, parameter, public restart_type_load
subroutine, public restart_end(restart)
subroutine, public zstates_elec_rrqr_decomposition(st, namespace, mesh, nst, root, ik, jpvt)
Perform RRQR on the transpose states stored in the states object and return the pivot vector.
This module defines routines to write information about states.
logical function, public state_kpt_is_local(st, ist, ik)
check whether a given state (ist, ik) is on the local node
subroutine, public states_elec_allocate_wfns(st, mesh, wfs_type, skip, packed)
Allocates the KS wavefunctions defined within a states_elec_t structure.
subroutine, public states_elec_look(restart, nik, dim, nst, ierr)
Reads the 'states' file in the restart directory, and finds out the nik, dim, and nst contained in it...
This module handles reading and writing restart information for the states_elec_t.
subroutine, public states_elec_load(restart, namespace, space, st, mesh, kpoints, ierr, iter, lr, lowest_missing, label, verbose, skip)
returns in ierr: <0 => Fatal error, or nothing read =0 => read all wavefunctions >0 => could only rea...
subroutine, public submesh_init(this, space, mesh, latt, center, rc)
type(type_t), public type_cmplx
brief This module defines the class unit_t which is used by the unit_systems_oct_m module.
This module defines the unit system, used for input and output.
type(unit_t), public unit_angstrom
For XYZ files.
subroutine, public unit_system_init(namespace)
type(unit_t), public unit_ev
For output energies in eV.
This module is intended to contain simple general-purpose utility functions and procedures.
subroutine, public ylm_wannier(ylm, l, mr, rr, xx, nr)
Class describing the electron system.
Describes mesh distribution to nodes.
The states_elec_t class contains all electronic wave functions.
batches of electronic states
subroutine create_wannier90_eig()
subroutine read_wannier90_files()
subroutine create_wannier90_mmn(mesh, st)
subroutine wannier90_setup(ions, kpoints, space)
subroutine write_unk(space, mesh, st)
subroutine generate_wannier_states(space, mesh, ions, st, kpoints)
program wannier90_interface
subroutine create_wannier90_amn(space, mesh, latt, st, kpoints)
subroutine wannier90_output()