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
129 if (w90_prefix ==
'w90')
then
130 message(1) =
"oct-wannier90: the prefix is set by default to w90"
160 if (w90_mode == 0)
then
161 message(1) =
"Wannier90Mode must be set to a value different from 0."
181 w90_what_default = option__wannier90files__w90_mmn + option__wannier90files__w90_amn + option__wannier90files__w90_eig
222 if (sys%kpoints%use_symmetries)
then
223 message(1) =
'oct-wannier90: k-points symmetries are not allowed'
226 if (sys%kpoints%use_time_reversal)
then
227 message(1) =
'oct-wannier90: time-reversal symmetry is not allowed'
230 if (sys%kpoints%reduced%nshifts > 1)
then
231 message(1) =
'oct-wannier90: Wannier90 does not allow for multiple shifts of the k-point grid'
240 w90_spinors = .false.
245 do idir = sys%space%periodic_dim+1, sys%space%dim
246 factor(idir) =
m_two * sys%gr%box%bounding_box_l(idir)
248 call sys%ions%latt%scale(factor)
251 select case (w90_mode)
252 case (option__wannier90mode__w90_setup)
256 case (option__wannier90mode__w90_output)
259 case (option__wannier90mode__w90_wannier)
264 if (read_td_states)
then
266 sys%mc, ierr, sys%gr)
269 sys%mc, ierr, sys%gr)
274 if (dim == sys%st%d%dim .and. nik == sys%kpoints%reduced%npoints .and. nst == sys%st%nst)
then
276 ierr, iter, label =
": wannier90", skip=exclude_list)
278 write(
message(1),
'(a)')
'Restart structure not commensurate.'
286 message(1) =
"Wannier90Mode is set to an unsupported value."
290 safe_deallocate_a(exclude_list)
291 safe_deallocate_a(band_index)
292 safe_deallocate_a(w90_nnk_list)
293 safe_deallocate_a(w90_proj_centers)
294 safe_deallocate_a(w90_proj_lmr)
296 safe_deallocate_p(sys)
308 type(
ions_t),
intent(in) :: ions
310 class(
space_t),
intent(in) :: space
312 character(len=80) :: filename
313 integer :: w90_win, ia, axis(3), npath
317 assert(space%dim == 3)
320 filename = trim(adjustl(w90_prefix)) //
'.win'
323 write(w90_win,
'(a)')
'# this file has been created by the Octopus wannier90 utility'
324 write(w90_win,
'(a)')
' '
327 write(w90_win,
'(a)')
'begin unit_cell_cart'
328 write(w90_win,
'(a)')
'Ang'
332 write(w90_win,
'(a)')
'end unit_cell_cart'
333 write(w90_win,
'(a)')
' '
335 write(w90_win,
'(a)')
'begin atoms_frac'
336 do ia = 1, ions%natoms
337 write(w90_win,
'(a,2x,f13.8,f13.8,f13.8)') trim(ions%atom(ia)%label), ions%latt%cart_to_red(ions%pos(:, ia))
339 write(w90_win,
'(a)')
'end atoms_frac'
340 write(w90_win,
'(a)')
' '
343 write(w90_win,
'(a)')
'use_bloch_phases = .true.'
344 write(w90_win,
'(a)')
' '
346 write(w90_win,
'(a10,i4)')
'num_bands ', sys%st%nst
347 write(w90_win,
'(a9,i4)')
'num_wann ', sys%st%nst
348 write(w90_win,
'(a)')
' '
350 if (sys%st%d%ispin ==
spinors)
then
351 write(w90_win,
'(a)')
'spinors = .true.'
354 write(w90_win,
'(a)')
'spin = up'
358 write(w90_win,
'(a)')
'write_u_matrices = .true.'
359 write(w90_win,
'(a)')
'write_xyz = .true.'
360 write(w90_win,
'(a)')
' '
362 if (kpoints%reduced%npoints == 1)
then
363 write(w90_win,
'(a)')
'gamma_only = .true.'
364 write(w90_win,
'(a)')
' '
367 message(1) =
'oct-wannier90: need Monkhorst-Pack grid. Please specify %KPointsGrid'
372 npath = kpoints%nkpt_in_path()
374 axis(1:3) = kpoints%nik_axis(1:3)
375 assert(product(kpoints%nik_axis(1:3)) == kpoints%reduced%npoints - npath)
377 write(w90_win,
'(a8,i4,i4,i4)')
'mp_grid =', axis(1:3)
378 write(w90_win,
'(a)')
' '
379 write(w90_win,
'(a)')
'begin kpoints '
382 do ii = 1, kpoints%reduced%npoints-npath
383 write(w90_win,
'(f13.8,f13.8,f13.8)') - kpoints%reduced%red_point(1:3,ii)
385 write(w90_win,
'(a)')
'end kpoints '
404 if (read_td_states)
then
406 sys%mc, ierr, sys%gr)
409 sys%mc, ierr, sys%gr)
417 if (dim == sys%st%d%dim .and. nik == sys%kpoints%reduced%npoints .and. nst == sys%st%nst)
then
419 ierr, iter, label =
": wannier90", skip=exclude_list)
421 write(
message(1),
'(a)')
'Restart structure not commensurate.'
429 safe_allocate(jpvt(1:sys%gr%np_global*sys%st%d%dim))
430 safe_allocate(psi(1:sys%gr%np, 1:sys%st%d%dim))
431 safe_allocate(occ_temp(1:w90_num_bands))
434 do ist = 1, w90_num_bands
435 occ_temp(ist)= sys%st%occ(ist, 1)
436 sys%st%occ(ist, 1)=
m_half*
loct_erfc((sys%st%eigenval(ist, 1)-scdm_mu) / scdm_sigma)
442 do ist = 1, w90_num_bands
443 sys%st%occ(ist, 1) = occ_temp(ist)
446 safe_allocate(uk(1:w90_num_bands, 1:w90_num_bands, 1:nik))
449 safe_allocate(chi(1:w90_num_bands, 1:w90_num_bands))
450 safe_allocate(chi_diag(1:w90_num_bands, 1:w90_num_bands))
451 safe_allocate(chi2(1:w90_num_bands, 1:w90_num_bands))
452 safe_allocate(chi_eigenval(1:w90_num_bands))
454 chi(1:w90_num_bands, 1:w90_num_bands) =
m_zero
457 kvec(:) = sys%kpoints%reduced%point(:, ik)
460 ik_real = (ik-1)*2 + w90_spin_channel
465 do ist = 1, w90_num_bands
467 smear=
m_half *
loct_erfc((sys%st%eigenval(ist, ik_real) - scdm_mu) / scdm_sigma)
469 do jst = 1, w90_num_bands
470 chi(ist, jst) = smear * conjg(psi(jpvt(jst), 1)) &
471 *
exp(
m_zi * dot_product(sys%gr%x(jpvt(jst), 1:3), kvec(1:3)))
477 chi_diag = matmul(conjg(transpose(chi)), chi)
479 chi2 = conjg(transpose(chi_diag))
482 if (any(chi_eigenval(:) .lt.
m_zero))
then
483 message(1) =
'SCDM Wannierization failed because chi matrix is'
484 message(2) =
'ill conditioned. Try increasingin scdm_sigma and/or'
489 do ist = 1, w90_num_bands
491 chi2(ist, 1:w90_num_bands) = chi_eigenval(ist) * chi2(ist, 1:w90_num_bands)
495 uk(:,:,ik) = matmul(chi, matmul(chi_diag,chi2))
499 safe_deallocate_a(chi)
500 safe_deallocate_a(psi)
501 safe_deallocate_a(chi_diag)
502 safe_deallocate_a(chi2)
503 safe_deallocate_a(chi_eigenval)
504 safe_deallocate_a(jpvt)
505 safe_deallocate_a(psi)
506 safe_deallocate_a(occ_temp)
510 if (
bitand(w90_what, option__wannier90files__w90_mmn) /= 0)
then
514 if (
bitand(w90_what, option__wannier90files__w90_unk) /= 0)
then
515 call write_unk(sys%space, sys%gr, sys%st)
518 if (
bitand(w90_what, option__wannier90files__w90_amn) /= 0)
then
522 if (
bitand(w90_what, option__wannier90files__w90_eig) /= 0)
then
526 safe_deallocate_a(uk)
527 safe_deallocate_a(w90_spin_proj_component)
528 safe_deallocate_a(w90_spin_proj_axis)
535 integer :: w90_nnkp, itemp, dummyint, io
536 character(len=80) :: filename, dummy, dummy1, dummy2, line
537 logical :: exist, parse_is_ok
538 real(real64) :: dummyr(7)
542 w90_num_kpts = product(sys%kpoints%nik_axis(1:3))
546 filename = trim(adjustl(w90_prefix)) //
'.nnkp'
548 message(1) =
"oct-wannier90: Parsing "//filename
551 inquire(file=filename,exist=exist)
552 if (.not. exist)
then
553 message(1) =
'oct-wannier90: Cannot find specified Wannier90 nnkp file.'
554 write(
message(2),
'(a)')
'Please run wannier90.x -pp '// trim(adjustl(w90_prefix)) //
' first.'
558 parse_is_ok = .false.
563 read(w90_nnkp, *, iostat=io) dummy, dummy1
564 if (io == iostat_end)
exit
566 if (dummy ==
'begin' .and. dummy1 ==
'kpoints')
then
567 read(w90_nnkp,*) itemp
568 if (itemp /= w90_num_kpts)
then
569 message(1) =
'oct-wannier90: wannier90 setup seems to have been done with a different number of k-points.'
579 if (.not. parse_is_ok)
then
580 message(1) =
'oct-wannier90: Did not find the kpoints block in nnkp file'
583 parse_is_ok = .false.
589 read(w90_nnkp, *, iostat=io) dummy, dummy1
590 if (io == iostat_end)
exit
592 if (dummy ==
'begin' .and. dummy1 ==
'nnkpts')
then
593 read(w90_nnkp,*) w90_nntot
594 safe_allocate(w90_nnk_list(1:5, 1:w90_num_kpts * w90_nntot))
595 do ii = 1, w90_num_kpts * w90_nntot
596 read(w90_nnkp,*) w90_nnk_list(1:5, ii)
599 read(w90_nnkp,*) dummy
600 if (dummy /=
'end')
then
601 message(1) =
'oct-wannier90: There dont seem to be enough k-points in nnkpts file to.'
609 if (.not. parse_is_ok)
then
610 message(1) =
'oct-wannier90: Did not find nnkpts block in nnkp file'
616 safe_allocate(exclude_list(1:sys%st%nst))
618 exclude_list(1:sys%st%nst) = .false.
621 read(w90_nnkp, *, iostat=io) dummy, dummy1
622 if (io == iostat_end)
exit
623 if (dummy ==
'begin' .and. dummy1 ==
'exclude_bands')
then
624 read(w90_nnkp, *) w90_num_exclude
625 do ii = 1, w90_num_exclude
626 read(w90_nnkp, *) itemp
627 if(itemp > sys%st%nst)
then
628 message(1) =
'oct-wannier90: The exclude_bands list contains a state index higher than the number of states.'
631 exclude_list(itemp) = .
true.
634 read(w90_nnkp, *) dummy
635 if (dummy /=
'end')
then
636 message(1) =
'oct-wannier90: There dont seem to be enough bands in exclude_bands list.'
645 w90_num_bands = sys%st%nst - w90_num_exclude
647 safe_allocate(band_index(1:sys%st%nst))
649 do ii = 1, sys%st%nst
650 if (exclude_list(ii)) cycle
652 band_index(ii) = itemp
655 if (
bitand(w90_what, option__wannier90files__w90_amn) /= 0 &
656 .or. w90_mode == option__wannier90mode__w90_wannier )
then
661 read(w90_nnkp, *, iostat=io) dummy, dummy1
662 if (io == iostat_end)
then
663 message(1) =
'oct-wannier90: Did not find projections block in w90.nnkp file'
667 if (dummy ==
'begin' .and. (dummy1 ==
'projections' .or. dummy1 ==
'spinor_projections'))
then
669 if (dummy1 ==
'spinor_projections')
then
671 if (sys%st%d%ispin /=
spinors)
then
672 message(1) =
'oct-wannier90: Spinor = .true. is only valid with spinors wavefunctions.'
676 message(1) =
'oct-wannier90: Spinor interface incomplete. Note there is no quantization axis implemented'
679 if (sys%st%d%ispin ==
spinors)
then
680 message(1) =
'oct-wannier90: Octopus has spinors wavefunctions but spinor_projections is not defined.'
681 message(2) =
'oct-wannier90: Please check the input file for wannier 90.'
686 read(w90_nnkp, *) w90_nproj
689 w90_num_wann = w90_nproj
691 if(w90_nproj == 0) w90_num_wann = w90_num_bands
693 safe_allocate(w90_proj_centers(1:3, 1:w90_nproj))
694 safe_allocate(w90_proj_lmr(1:w90_nproj, 1:3))
695 if (w90_spinors)
then
696 safe_allocate(w90_spin_proj_component(1:w90_nproj))
698 if (w90_spinors)
then
699 safe_allocate(w90_spin_proj_axis(1:w90_nproj, 1:3))
703 read(w90_nnkp, *) w90_proj_centers(1:3, ii), w90_proj_lmr(ii, 1:3)
705 read(w90_nnkp, *) dummyr(1:7)
706 if (w90_spinors)
then
707 read(w90_nnkp, *) w90_spin_proj_component(ii), w90_spin_proj_axis(ii, 1:3)
709 if (w90_spin_proj_component(ii) == -1) w90_spin_proj_component(ii) = 2
713 read(w90_nnkp, *) dummy
714 if (dummy /=
'end')
then
715 message(1) =
'oct-wannier90: There dont seem to be enough projections in nnkpts file to.'
725 read(w90_nnkp, *, iostat=io) dummy, dummy1
726 if (io == iostat_end)
exit
728 if (dummy ==
'begin' .and. dummy1 ==
'auto_projections')
then
730 read(w90_nnkp, *) w90_nproj
731 w90_num_wann = w90_nproj
733 if (.not. w90_scdm)
then
734 message(1) =
'oct-wannier90: Found auto_projections block. Currently the only implemented automatic way'
735 message(2) =
'oct-wannier90: to compute projections is the SCDM method.'
736 message(3) =
'oct-wannier90: Please set Wannier90UseSCDM = yes in the inp file.'
740 if (w90_nproj /= w90_num_bands)
then
741 message(1) =
'oct-wannier90: In auto_projections block first row needs to be equal to num_bands.'
744 read(w90_nnkp, *) dummyint
745 if (dummyint /= 0)
then
746 message(1) =
'oct-wannier90: The second row in auto_projections has to be 0, per Wannier90 documentation.'
755 message(1) =
"oct-wannier90: Finished parsing "//filename
760 filename = trim(adjustl(w90_prefix)) //
'.win'
761 message(1) =
"oct-wannier90: Parsing "//filename
765 read(w90_nnkp, fmt=
'(a)', iostat=io) line
766 if (io == iostat_end)
exit
767 if (index(line,
'=') > 0)
then
768 read(line, *, iostat=io) dummy, dummy2, dummy1
770 read(line, *, iostat=io) dummy, dummy1
774 if (dummy ==
'spin')
then
776 message(1) =
'oct-wannier90: The variable spin is set for a non spin-polarized calculation.'
780 if (dummy1 ==
'up')
then
782 else if (dummy1 ==
'down')
then
785 message(1) =
'oct-wannier90: Error parsing the variable spin.'
793 write(
message(1),
'(a,i1)')
'oct-wannier90: Using spin channel ', w90_spin_channel
797 message(1) =
"oct-wannier90: Finished parsing "//filename
806 class(
mesh_t),
intent(in) :: mesh
809 integer :: ist, jst, ik, ip, w90_mmn, iknn, idim, ibind
810 real(real64) :: Gcart(3)
812 character(len=80) :: filename
813 complex(real64),
allocatable :: overlap(:)
814 complex(real64),
allocatable :: psim(:,:), psin(:,:), phase(:)
816 integer :: inode, node_fr, node_to
817 type(mpi_request) :: send_req
823 if (st%parallel_in_states)
then
827 message(1) =
"Info: Computing the overlap matrix"
831 filename =
'./'// trim(adjustl(w90_prefix))//
'.mmn'
836 write(w90_mmn,*)
'Created by oct-wannier90'
837 write(w90_mmn,*) w90_num_bands, w90_num_kpts, w90_nntot
840 safe_allocate(psim(1:mesh%np, 1:st%d%dim))
841 safe_allocate(psin(1:mesh%np, 1:st%d%dim))
842 safe_allocate(phase(1:mesh%np))
843 safe_allocate(overlap(1:w90_num_bands))
847 do ii = 1, w90_num_kpts * w90_nntot
848 ik = w90_nnk_list(1, ii)
849 iknn = w90_nnk_list(2, ii)
850 g(1:3) = w90_nnk_list(3:5, ii)
851 if (
mpi_world%is_root())
write(w90_mmn,
'(I10,2x,I10,2x,I3,2x,I3,2x,I3)') ik, iknn, g
855 ik = (ik-1)*2 + w90_spin_channel
856 iknn = (iknn-1)*2 + w90_spin_channel
861 if(ik >= st%d%kpt%start .and. ik <= st%d%kpt%end)
then
870 if (any(g /= 0))
then
872 phase(ip) =
exp(-
m_zi*dot_product(mesh%x(ip,1:3), gcart(1:3)))
880 if (exclude_list(jst)) cycle
883 if ( .not. st%d%kpt%parallel .and. .not. st%parallel_in_states)
then
888 do inode = 0, st%d%kpt%mpi_grp%size-1
889 if(iknn >= st%st_kpt_task(inode,3) .and. iknn <= st%st_kpt_task(inode,4))
then
892 if(ik >= st%st_kpt_task(inode,3) .and. ik <= st%st_kpt_task(inode,4))
then
899 send_req = mpi_request_null
904 if(node_to /= st%d%kpt%mpi_grp%rank)
then
905 call st%d%kpt%mpi_grp%isend(psin, mesh%np*st%d%dim, mpi_double_complex, node_to, send_req)
909 if(node_to == st%d%kpt%mpi_grp%rank .and. node_to /= node_fr)
then
910 call st%d%kpt%mpi_grp%recv(psin, mesh%np*st%d%dim, mpi_double_complex, node_fr)
912 if (send_req /= mpi_request_null)
then
913 call st%d%kpt%mpi_grp%wait(send_req)
919 if(ik >= st%d%kpt%start .and. ik <= st%d%kpt%end)
then
922 if (any(g /= 0))
then
924 do idim = 1, st%d%dim
926 psin(ip, idim) = psin(ip, idim) * phase(ip)
935 if (exclude_list(ist)) cycle
937 batch => st%group%psib(st%group%iblock(ist), ik)
939 select case (batch%status())
941 overlap(band_index(ist)) =
m_z0
942 do idim = 1, st%d%dim
943 ibind = batch%inv_index((/ist, idim/))
944 overlap(band_index(ist)) = overlap(band_index(ist)) + &
945 zmf_dotp(mesh, batch%zff_linear(:, ibind), psin(:,idim), reduce = .false.)
950 overlap(band_index(ist)) =
zmf_dotp(mesh, st%d%dim, psim, psin, reduce = .false.)
956 call mesh%allreduce(overlap)
959 if(st%d%kpt%parallel)
then
966 if (exclude_list(ist)) cycle
967 write(w90_mmn,
'(e18.10,2x,e18.10)') overlap(band_index(ist))
976 safe_deallocate_a(psim)
977 safe_deallocate_a(psin)
978 safe_deallocate_a(phase)
979 safe_deallocate_a(overlap)
989 integer :: ist, ik, w90_eig
990 character(len=80) :: filename
994 if (sys%st%parallel_in_states)
then
999 filename =
'./'//trim(adjustl(w90_prefix))//
'.eig'
1001 do ik = 1, w90_num_kpts
1002 do ist = 1, sys%st%nst
1003 if (exclude_list(ist)) cycle
1005 write(w90_eig,
'(I5,2x,I8,2x,e18.10)') band_index(ist), ik, &
1008 write(w90_eig,
'(I5,2x,I8,2x,e18.10)') band_index(ist), ik, &
1022 class(
space_t),
intent(in) :: space
1023 class(
mesh_t),
intent(in) :: mesh
1026 integer :: ist, ik, unk_file, ispin
1027 integer :: ix, iy, iz
1028 character(len=80) :: filename
1029 complex(real64),
allocatable :: psi(:)
1035 if (st%d%kpt%parallel)
then
1039 if (sys%gr%parallel_in_domains)
then
1043 if (st%parallel_in_states)
then
1050 safe_allocate(psi(1:mesh%np))
1053 mesh%coord_system, need_partition=.not.mesh%parallel_in_domains)
1058 do ik = 1, w90_num_kpts
1059 do ispin = 1, st%d%dim
1061 write(filename,
'(a,i5.5,a1,i1)')
'./UNK', ik,
'.', ispin
1064 write(unk_file) mesh%idx%ll(1:mesh%idx%dim), ik, w90_num_bands
1069 if (exclude_list(ist)) cycle
1079 if (cube%parallel_in_domains)
then
1080 assert(.not. cube%parallel_in_domains)
1086 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))
1096 safe_deallocate_a(psi)
1104 class(
space_t),
intent(in) :: space
1105 class(
mesh_t),
intent(in) :: mesh
1110 integer :: ist, ik, w90_amn, idim, iw, ip, ik_real
1111 real(real64) :: center(3), kpoint(3), threshold
1112 character(len=80) :: filename
1113 complex(real64),
allocatable :: psi(:,:), phase(:), projection(:)
1114 real(real64),
allocatable :: ylm(:)
1120 if (st%parallel_in_states)
then
1124 filename =
'./'// trim(adjustl(w90_prefix))//
'.amn'
1129 write(w90_amn,*)
'Created by oct-wannier90'
1130 write(w90_amn,*) w90_num_bands, w90_num_kpts, w90_num_wann
1135 message(1) =
"Info: Writing projections obtained from SCDM."
1138 if (st%d%kpt%parallel)
then
1143 do ik = 1, w90_num_kpts
1145 if (exclude_list(ist)) cycle
1147 do iw = 1, w90_nproj
1148 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)
1156 message(1) =
"Info: Computing the projection matrix"
1162 safe_allocate(orbitals(1:w90_nproj))
1167 orbitals(iw)%norbs = 1
1168 orbitals(iw)%ndim = 1
1169 orbitals(iw)%radius = -
log(threshold)
1170 orbitals(iw)%use_submesh = .false.
1173 center(1:3) = latt%red_to_cart(w90_proj_centers(1:3, iw))
1174 call submesh_init(orbitals(iw)%sphere, space, mesh, latt, center, orbitals(iw)%radius)
1177 safe_allocate(ylm(1:orbitals(iw)%sphere%np))
1179 call ylm_wannier(ylm, w90_proj_lmr(iw,1), w90_proj_lmr(iw,2), &
1180 orbitals(iw)%sphere%r, orbitals(iw)%sphere%rel_x, orbitals(iw)%sphere%np)
1183 if (w90_proj_lmr(iw,3) == 1)
then
1184 do ip = 1,orbitals(iw)%sphere%np
1185 ylm(ip) = ylm(ip)*
m_two*
exp(-orbitals(iw)%sphere%r(ip))
1191 safe_allocate(orbitals(iw)%zorb(1:orbitals(iw)%sphere%np, 1, 1))
1192 orbitals(iw)%zorb(1:orbitals(iw)%sphere%np, 1, 1) = ylm(1:orbitals(iw)%sphere%np)
1193 safe_deallocate_a(ylm)
1195 safe_allocate(orbitals(iw)%phase(1:orbitals(iw)%sphere%np, st%d%kpt%start:st%d%kpt%end))
1196 orbitals(iw)%phase(:,:) =
m_z0
1197 safe_allocate(orbitals(iw)%eorb_mesh(1:mesh%np, 1, 1, st%d%kpt%start:st%d%kpt%end))
1198 orbitals(iw)%eorb_mesh(:,:,:,:) =
m_z0
1201 kpt_max = w90_num_kpts)
1205 safe_allocate(psi(1:mesh%np, 1:st%d%dim))
1206 safe_allocate(phase(1:mesh%np))
1207 safe_allocate(projection(1:w90_nproj))
1209 do ik = 1, w90_num_kpts
1210 kpoint(1:space%dim) = kpoints%get_point(ik)
1212 phase(ip) =
exp(-
m_zi* sum(mesh%x(ip, 1:space%dim) * kpoint(1:space%dim)))
1217 ik_real = (ik-1)*2 + w90_spin_channel
1224 if (exclude_list(ist)) cycle
1228 if(ik_real >= st%d%kpt%start .and. ik_real <= st%d%kpt%end)
then
1231 do idim = 1, st%d%dim
1234 psi(ip, idim) = psi(ip, idim)*phase(ip)
1238 do iw = 1, w90_nproj
1240 if (w90_spinors) idim = w90_spin_proj_component(iw)
1244 projection(iw) =
zmf_dotp(mesh, psi(1:mesh%np,idim), &
1245 orbitals(iw)%eorb_mesh(1:mesh%np,1,1,ik_real), reduce = .false.)
1249 call mesh%allreduce(projection)
1253 if(st%d%kpt%parallel)
then
1258 do iw = 1, w90_nproj
1259 write (w90_amn,
'(I5,2x,I5,2x,I5,2x,e18.10,2x,e18.10)') band_index(ist), iw, ik, projection(iw)
1265 safe_deallocate_a(psi)
1266 safe_deallocate_a(phase)
1267 safe_deallocate_a(projection)
1269 do iw = 1, w90_nproj
1272 safe_deallocate_a(orbitals)
1285 class(space_t),
intent(in) :: space
1286 class(mesh_t),
intent(in) :: mesh
1287 type(ions_t),
intent(in) :: ions
1288 type(states_elec_t),
intent(in) :: st
1289 type(kpoints_t),
intent(in) :: kpoints
1291 integer :: w90_u_mat, w90_xyz, nwann, nik
1292 integer :: ik, iw, iw2, ip, ipmax, rankmax
1293 real(real64),
allocatable :: centers(:,:)
1294 complex(real64),
allocatable :: Umnk(:,:,:)
1295 complex(real64),
allocatable :: zwn(:), psi(:,:), phase(:)
1296 character(len=MAX_PATH_LEN) :: fname
1297 real(real64) :: kpoint(3), wmod, wmodmax, xx(space%dim)
1298 character(len=2) :: dum
1300 type(unit_t) :: fn_unit
1301 complex(real64) :: scal
1305 assert(st%d%ispin /= spinors)
1307 message(1) =
"oct-wannier90: Constructing the Wannier states from the U matrix."
1308 call messages_info(1)
1310 inquire(file=trim(trim(adjustl(w90_prefix))//
'_centres.xyz'),exist=exist)
1311 if (.not. exist)
then
1312 message(1) =
'oct-wannier90: Cannot find the Wannier90 file seedname_centres.xyz.'
1313 write(message(2),
'(a)')
'Please run wannier90.x with "write_xyz=.true." in '// trim(adjustl(w90_prefix)) //
'.'
1314 call messages_fatal(2)
1317 w90_xyz = io_open(trim(trim(adjustl(w90_prefix))//
'_centres.xyz'), global_namespace, action=
'read')
1319 safe_allocate(centers(1:3, 1:w90_num_wann))
1323 do iw = 1, w90_num_wann
1324 read(w90_xyz, *) dum, centers(1:3, iw)
1326 centers(1:3, iw) = units_to_atomic(unit_angstrom, centers(1:3, iw))
1328 call io_close(w90_xyz)
1331 inquire(file=trim(trim(adjustl(w90_prefix))//
'_u_dis.mat'),exist=exist)
1333 message(1) =
'oct-wannier90: Calculation of Wannier states with disentanglement is not yet supported.'
1334 call messages_fatal(1)
1337 inquire(file=trim(trim(adjustl(w90_prefix))//
'_u.mat'),exist=exist)
1338 if (.not. exist)
then
1339 message(1) =
'oct-wannier90: Cannot find the Wannier90 seedname_u.mat file.'
1340 write(message(2),
'(a)')
'Please run wannier90.x with "write_u_matrices=.true." in '// trim(adjustl(w90_prefix)) //
'.'
1341 call messages_fatal(2)
1343 w90_u_mat = io_open(trim(trim(adjustl(w90_prefix))//
'_u.mat'), global_namespace, action=
'read')
1349 read(w90_u_mat, *) nik, nwann, nwann
1350 if (nik /= w90_num_kpts .or. nwann /= w90_num_wann)
then
1351 print *, w90_num_wann, w90_num_kpts, nik, nwann
1352 message(1) =
"The file contains U matrices is inconsistent with the .win file."
1353 call messages_fatal(1)
1356 safe_allocate(umnk(1:w90_num_wann, 1:w90_num_wann, 1:w90_num_kpts))
1358 do ik = 1, w90_num_kpts
1363 read(w90_u_mat,
'(f15.10,sp,f15.10)') ((umnk(iw, iw2, ik), iw=1, w90_num_wann), iw2=1, w90_num_wann)
1366 call io_close(w90_u_mat)
1369 call parse_variable(global_namespace,
'OutputFormat', 0, how)
1371 call io_mkdir(
'wannier', global_namespace)
1374 safe_allocate(zwn(1:mesh%np))
1375 safe_allocate(psi(1:mesh%np, 1:st%d%dim))
1376 safe_allocate(phase(1:mesh%np))
1378 do iw = 1, w90_num_wann
1382 do ik = 1, w90_num_kpts
1383 kpoint(1:space%dim) = kpoints%get_point(ik, absolute_coordinates=.
true.)
1387 xx = mesh%x(ip, 1:space%dim)-centers(1:space%dim, iw)
1388 xx = ions%latt%fold_into_cell(xx)
1389 phase(ip) =
exp(-m_zi* sum( xx * kpoint(1:space%dim)))
1393 if (exclude_list(iw2)) cycle
1395 if (st%d%ispin /= spin_polarized)
then
1396 call states_elec_get_state(st, mesh, iw2, ik, psi)
1398 call states_elec_get_state(st, mesh, iw2, (ik-1)*2+w90_spin_channel, psi)
1403 zwn(ip) = zwn(ip) + umnk(band_index(iw2), iw, ik) * psi(ip, 1) * phase(ip)
1413 wmod = real(zwn(ip)*conjg(zwn(ip)), real64)
1414 if (wmod > wmodmax)
then
1419 scal =
sqrt(wmodmax)/zwn(ipmax)/w90_num_kpts
1420 call mesh_minmaxloc(mesh, wmodmax, rankmax, mpi_maxloc)
1421 call mesh%mpi_grp%bcast(scal, 1, mpi_double_complex, rankmax)
1422 call lalg_scal(mesh%np, scal, zwn)
1425 fn_unit =
sqrt(units_out%length**(-space%dim))
1426 write(fname,
'(a,i3.3)')
'wannier-', iw
1427 call zio_function_output(how,
"wannier", trim(fname), global_namespace, space, mesh, &
1428 zwn, fn_unit, ierr, pos=ions%pos, atoms=ions%atom, grp = st%dom_st_kpt_mpi_grp)
1433 if(abs(real(zwn(ip), real64)) >= 1e-2_real64)
then
1434 wmodmax = max(wmodmax, abs(aimag(zwn(ip)))/abs(real(zwn(ip), real64)))
1437 call mesh_minmaxloc(mesh, wmodmax, rankmax, mpi_maxloc)
1439 write(message(1),
'(a,i4,a,f11.6)')
'oct-wannier90: Wannier function ', iw,
' Max. Im/Re Ratio = ', wmodmax
1440 call messages_info(1)
1443 safe_deallocate_a(umnk)
1444 safe_deallocate_a(zwn)
1445 safe_deallocate_a(psi)
1446 safe_deallocate_a(phase)
1447 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)
Convert a function from the mesh to 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)
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)
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
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.
integer, parameter, public restart_gs
integer, parameter, public restart_td
integer, parameter, public restart_type_load
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()