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 fixed_occ=.
true., ierr=ierr, iter=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 fixed_occ=.
true., ierr=ierr, iter=iter, label =
": wannier90", skip=exclude_list)
423 write(
message(1),
'(a)')
'Restart structure not commensurate.'
431 safe_allocate(jpvt(1:sys%gr%np_global*sys%st%d%dim))
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(occ_temp)
511 if (
bitand(w90_what, option__wannier90files__w90_mmn) /= 0)
then
515 if (
bitand(w90_what, option__wannier90files__w90_unk) /= 0)
then
516 call write_unk(sys%space, sys%gr, sys%st)
519 if (
bitand(w90_what, option__wannier90files__w90_amn) /= 0)
then
523 if (
bitand(w90_what, option__wannier90files__w90_eig) /= 0)
then
527 safe_deallocate_a(uk)
528 safe_deallocate_a(w90_spin_proj_component)
529 safe_deallocate_a(w90_spin_proj_axis)
536 integer :: w90_nnkp, itemp, dummyint, io
537 character(len=80) :: filename, dummy, dummy1, dummy2, line
538 logical :: exist, parse_is_ok
539 real(real64) :: dummyr(7)
543 w90_num_kpts = product(sys%kpoints%nik_axis(1:3))
547 filename = trim(adjustl(w90_prefix)) //
'.nnkp'
549 message(1) =
"oct-wannier90: Parsing "//filename
552 inquire(file=filename,exist=exist)
553 if (.not. exist)
then
554 message(1) =
'oct-wannier90: Cannot find specified Wannier90 nnkp file.'
555 write(
message(2),
'(a)')
'Please run wannier90.x -pp '// trim(adjustl(w90_prefix)) //
' first.'
559 parse_is_ok = .false.
564 read(w90_nnkp, *, iostat=io) dummy, dummy1
565 if (io == iostat_end)
exit
567 if (dummy ==
'begin' .and. dummy1 ==
'kpoints')
then
568 read(w90_nnkp,*) itemp
569 if (itemp /= w90_num_kpts)
then
570 message(1) =
'oct-wannier90: wannier90 setup seems to have been done with a different number of k-points.'
580 if (.not. parse_is_ok)
then
581 message(1) =
'oct-wannier90: Did not find the kpoints block in nnkp file'
584 parse_is_ok = .false.
590 read(w90_nnkp, *, iostat=io) dummy, dummy1
591 if (io == iostat_end)
exit
593 if (dummy ==
'begin' .and. dummy1 ==
'nnkpts')
then
594 read(w90_nnkp,*) w90_nntot
595 safe_allocate(w90_nnk_list(1:5, 1:w90_num_kpts * w90_nntot))
596 do ii = 1, w90_num_kpts * w90_nntot
597 read(w90_nnkp,*) w90_nnk_list(1:5, ii)
600 read(w90_nnkp,*) dummy
601 if (dummy /=
'end')
then
602 message(1) =
'oct-wannier90: There dont seem to be enough k-points in nnkpts file to.'
610 if (.not. parse_is_ok)
then
611 message(1) =
'oct-wannier90: Did not find nnkpts block in nnkp file'
617 safe_allocate(exclude_list(1:sys%st%nst))
619 exclude_list(1:sys%st%nst) = .false.
622 read(w90_nnkp, *, iostat=io) dummy, dummy1
623 if (io == iostat_end)
exit
624 if (dummy ==
'begin' .and. dummy1 ==
'exclude_bands')
then
625 read(w90_nnkp, *) w90_num_exclude
626 do ii = 1, w90_num_exclude
627 read(w90_nnkp, *) itemp
628 if(itemp > sys%st%nst)
then
629 message(1) =
'oct-wannier90: The exclude_bands list contains a state index higher than the number of states.'
632 exclude_list(itemp) = .
true.
635 read(w90_nnkp, *) dummy
636 if (dummy /=
'end')
then
637 message(1) =
'oct-wannier90: There dont seem to be enough bands in exclude_bands list.'
646 w90_num_bands = sys%st%nst - w90_num_exclude
648 safe_allocate(band_index(1:sys%st%nst))
650 do ii = 1, sys%st%nst
651 if (exclude_list(ii)) cycle
653 band_index(ii) = itemp
656 if (
bitand(w90_what, option__wannier90files__w90_amn) /= 0 &
657 .or. w90_mode == option__wannier90mode__w90_wannier )
then
662 read(w90_nnkp, *, iostat=io) dummy, dummy1
663 if (io == iostat_end)
then
664 message(1) =
'oct-wannier90: Did not find projections block in w90.nnkp file'
668 if (dummy ==
'begin' .and. (dummy1 ==
'projections' .or. dummy1 ==
'spinor_projections'))
then
670 if (dummy1 ==
'spinor_projections')
then
672 if (sys%st%d%ispin /=
spinors)
then
673 message(1) =
'oct-wannier90: Spinor = .true. is only valid with spinors wavefunctions.'
677 message(1) =
'oct-wannier90: Spinor interface incomplete. Note there is no quantization axis implemented'
680 if (sys%st%d%ispin ==
spinors)
then
681 message(1) =
'oct-wannier90: Octopus has spinors wavefunctions but spinor_projections is not defined.'
682 message(2) =
'oct-wannier90: Please check the input file for wannier 90.'
687 read(w90_nnkp, *) w90_nproj
690 w90_num_wann = w90_nproj
692 if(w90_nproj == 0) w90_num_wann = w90_num_bands
694 safe_allocate(w90_proj_centers(1:3, 1:w90_nproj))
695 safe_allocate(w90_proj_lmr(1:w90_nproj, 1:3))
696 if (w90_spinors)
then
697 safe_allocate(w90_spin_proj_component(1:w90_nproj))
699 if (w90_spinors)
then
700 safe_allocate(w90_spin_proj_axis(1:w90_nproj, 1:3))
704 read(w90_nnkp, *) w90_proj_centers(1:3, ii), w90_proj_lmr(ii, 1:3)
706 read(w90_nnkp, *) dummyr(1:7)
707 if (w90_spinors)
then
708 read(w90_nnkp, *) w90_spin_proj_component(ii), w90_spin_proj_axis(ii, 1:3)
710 if (w90_spin_proj_component(ii) == -1) w90_spin_proj_component(ii) = 2
714 read(w90_nnkp, *) dummy
715 if (dummy /=
'end')
then
716 message(1) =
'oct-wannier90: There dont seem to be enough projections in nnkpts file to.'
726 read(w90_nnkp, *, iostat=io) dummy, dummy1
727 if (io == iostat_end)
exit
729 if (dummy ==
'begin' .and. dummy1 ==
'auto_projections')
then
731 read(w90_nnkp, *) w90_nproj
732 w90_num_wann = w90_nproj
734 if (.not. w90_scdm)
then
735 message(1) =
'oct-wannier90: Found auto_projections block. Currently the only implemented automatic way'
736 message(2) =
'oct-wannier90: to compute projections is the SCDM method.'
737 message(3) =
'oct-wannier90: Please set Wannier90UseSCDM = yes in the inp file.'
741 if (w90_nproj /= w90_num_bands)
then
742 message(1) =
'oct-wannier90: In auto_projections block first row needs to be equal to num_bands.'
745 read(w90_nnkp, *) dummyint
746 if (dummyint /= 0)
then
747 message(1) =
'oct-wannier90: The second row in auto_projections has to be 0, per Wannier90 documentation.'
756 message(1) =
"oct-wannier90: Finished parsing "//filename
761 filename = trim(adjustl(w90_prefix)) //
'.win'
762 message(1) =
"oct-wannier90: Parsing "//filename
766 read(w90_nnkp, fmt=
'(a)', iostat=io) line
767 if (io == iostat_end)
exit
768 if (index(line,
'=') > 0)
then
769 read(line, *, iostat=io) dummy, dummy2, dummy1
771 read(line, *, iostat=io) dummy, dummy1
775 if (dummy ==
'spin')
then
777 message(1) =
'oct-wannier90: The variable spin is set for a non spin-polarized calculation.'
781 if (dummy1 ==
'up')
then
783 else if (dummy1 ==
'down')
then
786 message(1) =
'oct-wannier90: Error parsing the variable spin.'
794 write(
message(1),
'(a,i1)')
'oct-wannier90: Using spin channel ', w90_spin_channel
798 message(1) =
"oct-wannier90: Finished parsing "//filename
807 class(
mesh_t),
intent(in) :: mesh
810 integer :: ist, jst, ik, ip, w90_mmn, iknn, idim, ibind
811 real(real64) :: Gcart(3)
813 character(len=80) :: filename
814 complex(real64),
allocatable :: overlap(:)
815 complex(real64),
allocatable :: psim(:,:), psin(:,:), phase(:)
817 integer :: inode, node_fr, node_to
818 type(mpi_request) :: send_req
824 if (st%parallel_in_states)
then
828 message(1) =
"Info: Computing the overlap matrix"
832 filename =
'./'// trim(adjustl(w90_prefix))//
'.mmn'
837 write(w90_mmn,*)
'Created by oct-wannier90'
838 write(w90_mmn,*) w90_num_bands, w90_num_kpts, w90_nntot
841 safe_allocate(psim(1:mesh%np, 1:st%d%dim))
842 safe_allocate(psin(1:mesh%np, 1:st%d%dim))
843 safe_allocate(phase(1:mesh%np))
844 safe_allocate(overlap(1:w90_num_bands))
848 do ii = 1, w90_num_kpts * w90_nntot
849 ik = w90_nnk_list(1, ii)
850 iknn = w90_nnk_list(2, ii)
851 g(1:3) = w90_nnk_list(3:5, ii)
852 if (
mpi_grp_is_root(
mpi_world))
write(w90_mmn,
'(I10,2x,I10,2x,I3,2x,I3,2x,I3)') ik, iknn, g
856 ik = (ik-1)*2 + w90_spin_channel
857 iknn = (iknn-1)*2 + w90_spin_channel
862 if(ik >= st%d%kpt%start .and. ik <= st%d%kpt%end)
then
871 if (any(g /= 0))
then
873 phase(ip) =
exp(-
m_zi*dot_product(mesh%x(ip,1:3), gcart(1:3)))
881 if (exclude_list(jst)) cycle
884 if ( .not. st%d%kpt%parallel .and. .not. st%parallel_in_states)
then
889 do inode = 0, st%d%kpt%mpi_grp%size-1
890 if(iknn >= st%st_kpt_task(inode,3) .and. iknn <= st%st_kpt_task(inode,4))
then
893 if(ik >= st%st_kpt_task(inode,3) .and. ik <= st%st_kpt_task(inode,4))
then
900 send_req = mpi_request_null
905 if(node_to /= st%d%kpt%mpi_grp%rank)
then
906 call st%d%kpt%mpi_grp%isend(psin, mesh%np*st%d%dim, mpi_double_complex, node_to, send_req)
910 if(node_to == st%d%kpt%mpi_grp%rank .and. node_to /= node_fr)
then
911 call st%d%kpt%mpi_grp%recv(psin, mesh%np*st%d%dim, mpi_double_complex, node_fr)
913 if (send_req /= mpi_request_null)
then
914 call st%d%kpt%mpi_grp%wait(send_req)
920 if(ik >= st%d%kpt%start .and. ik <= st%d%kpt%end)
then
923 if (any(g /= 0))
then
925 do idim = 1, st%d%dim
927 psin(ip, idim) = psin(ip, idim) * phase(ip)
936 if (exclude_list(ist)) cycle
938 batch => st%group%psib(st%group%iblock(ist), ik)
940 select case (batch%status())
942 overlap(band_index(ist)) =
m_z0
943 do idim = 1, st%d%dim
944 ibind = batch%inv_index((/ist, idim/))
945 overlap(band_index(ist)) = overlap(band_index(ist)) + &
946 zmf_dotp(mesh, batch%zff_linear(:, ibind), psin(:,idim), reduce = .false.)
951 overlap(band_index(ist)) =
zmf_dotp(mesh, st%d%dim, psim, psin, reduce = .false.)
957 call mesh%allreduce(overlap)
960 if(st%d%kpt%parallel)
then
967 if (exclude_list(ist)) cycle
968 write(w90_mmn,
'(e18.10,2x,e18.10)') overlap(band_index(ist))
977 safe_deallocate_a(psim)
978 safe_deallocate_a(psin)
979 safe_deallocate_a(phase)
980 safe_deallocate_a(overlap)
990 integer :: ist, ik, w90_eig
991 character(len=80) :: filename
995 if (sys%st%parallel_in_states)
then
1000 filename =
'./'//trim(adjustl(w90_prefix))//
'.eig'
1002 do ik = 1, w90_num_kpts
1003 do ist = 1, sys%st%nst
1004 if (exclude_list(ist)) cycle
1006 write(w90_eig,
'(I5,2x,I8,2x,e18.10)') band_index(ist), ik, &
1009 write(w90_eig,
'(I5,2x,I8,2x,e18.10)') band_index(ist), ik, &
1023 class(
space_t),
intent(in) :: space
1024 class(
mesh_t),
intent(in) :: mesh
1027 integer :: ist, ik, unk_file, ispin
1028 integer :: ix, iy, iz
1029 character(len=80) :: filename
1030 complex(real64),
allocatable :: psi(:)
1036 if (st%d%kpt%parallel)
then
1040 if (sys%gr%parallel_in_domains)
then
1044 if (st%parallel_in_states)
then
1051 safe_allocate(psi(1:mesh%np))
1054 mesh%coord_system, need_partition=.not.mesh%parallel_in_domains)
1059 do ik = 1, w90_num_kpts
1060 do ispin = 1, st%d%dim
1062 write(filename,
'(a,i5.5,a1,i1)')
'./UNK', ik,
'.', ispin
1065 write(unk_file) mesh%idx%ll(1:mesh%idx%dim), ik, w90_num_bands
1070 if (exclude_list(ist)) cycle
1080 if (cube%parallel_in_domains)
then
1081 assert(.not. cube%parallel_in_domains)
1087 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))
1097 safe_deallocate_a(psi)
1105 class(
space_t),
intent(in) :: space
1106 class(
mesh_t),
intent(in) :: mesh
1111 integer :: ist, ik, w90_amn, idim, iw, ip, ik_real
1112 real(real64) :: center(3), kpoint(3), threshold
1113 character(len=80) :: filename
1114 complex(real64),
allocatable :: psi(:,:), phase(:), projection(:)
1115 real(real64),
allocatable :: ylm(:)
1121 if (st%parallel_in_states)
then
1125 filename =
'./'// trim(adjustl(w90_prefix))//
'.amn'
1130 write(w90_amn,*)
'Created by oct-wannier90'
1131 write(w90_amn,*) w90_num_bands, w90_num_kpts, w90_num_wann
1136 message(1) =
"Info: Writing projections obtained from SCDM."
1139 if (st%d%kpt%parallel)
then
1144 do ik = 1, w90_num_kpts
1146 if (exclude_list(ist)) cycle
1148 do iw = 1, w90_nproj
1149 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)
1157 message(1) =
"Info: Computing the projection matrix"
1163 safe_allocate(orbitals(1:w90_nproj))
1168 orbitals(iw)%norbs = 1
1169 orbitals(iw)%ndim = 1
1170 orbitals(iw)%radius = -
log(threshold)
1171 orbitals(iw)%use_submesh = .false.
1174 center(1:3) = latt%red_to_cart(w90_proj_centers(1:3, iw))
1175 call submesh_init(orbitals(iw)%sphere, space, mesh, latt, center, orbitals(iw)%radius)
1178 safe_allocate(ylm(1:orbitals(iw)%sphere%np))
1180 call ylm_wannier(ylm, w90_proj_lmr(iw,1), w90_proj_lmr(iw,2), &
1181 orbitals(iw)%sphere%r, orbitals(iw)%sphere%rel_x, orbitals(iw)%sphere%np)
1184 if (w90_proj_lmr(iw,3) == 1)
then
1185 do ip = 1,orbitals(iw)%sphere%np
1186 ylm(ip) = ylm(ip)*
m_two*
exp(-orbitals(iw)%sphere%r(ip))
1192 safe_allocate(orbitals(iw)%zorb(1:orbitals(iw)%sphere%np, 1, 1))
1193 orbitals(iw)%zorb(1:orbitals(iw)%sphere%np, 1, 1) = ylm(1:orbitals(iw)%sphere%np)
1194 safe_deallocate_a(ylm)
1196 safe_allocate(orbitals(iw)%phase(1:orbitals(iw)%sphere%np, st%d%kpt%start:st%d%kpt%end))
1198 safe_allocate(orbitals(iw)%eorb_mesh(1:mesh%np, 1, 1, st%d%kpt%start:st%d%kpt%end))
1199 orbitals(iw)%eorb_mesh(:,:,:,:) =
m_z0
1202 kpt_max = w90_num_kpts)
1206 safe_allocate(psi(1:mesh%np, 1:st%d%dim))
1207 safe_allocate(phase(1:mesh%np))
1208 safe_allocate(projection(1:w90_nproj))
1210 do ik = 1, w90_num_kpts
1211 kpoint(1:space%dim) = kpoints%get_point(ik)
1213 phase(ip) =
exp(-
m_zi* sum(mesh%x(ip, 1:space%dim) * kpoint(1:space%dim)))
1218 ik_real = (ik-1)*2 + w90_spin_channel
1225 if (exclude_list(ist)) cycle
1229 if(ik_real >= st%d%kpt%start .and. ik_real <= st%d%kpt%end)
then
1232 do idim = 1, st%d%dim
1235 psi(ip, idim) = psi(ip, idim)*phase(ip)
1239 do iw = 1, w90_nproj
1241 if (w90_spinors) idim = w90_spin_proj_component(iw)
1245 projection(iw) =
zmf_dotp(mesh, psi(1:mesh%np,idim), &
1246 orbitals(iw)%eorb_mesh(1:mesh%np,1,1,ik_real), reduce = .false.)
1250 call mesh%allreduce(projection)
1254 if(st%d%kpt%parallel)
then
1259 do iw = 1, w90_nproj
1260 write (w90_amn,
'(I5,2x,I5,2x,I5,2x,e18.10,2x,e18.10)') band_index(ist), iw, ik, projection(iw)
1266 safe_deallocate_a(psi)
1267 safe_deallocate_a(phase)
1268 safe_deallocate_a(projection)
1270 do iw = 1, w90_nproj
1273 safe_deallocate_a(orbitals)
1286 class(space_t),
intent(in) :: space
1287 class(mesh_t),
intent(in) :: mesh
1288 type(ions_t),
intent(in) :: ions
1289 type(states_elec_t),
intent(in) :: st
1290 type(kpoints_t),
intent(in) :: kpoints
1292 integer :: w90_u_mat, w90_xyz, nwann, nik
1293 integer :: ik, iw, iw2, ip, ipmax, rankmax
1294 real(real64),
allocatable :: centers(:,:)
1295 complex(real64),
allocatable :: Umnk(:,:,:)
1296 complex(real64),
allocatable :: zwn(:), psi(:,:), phase(:)
1297 character(len=MAX_PATH_LEN) :: fname
1298 real(real64) :: kpoint(3), wmod, wmodmax, xx(space%dim)
1299 character(len=2) :: dum
1301 type(unit_t) :: fn_unit
1302 complex(real64) :: scal
1306 assert(st%d%ispin /= spinors)
1308 message(1) =
"oct-wannier90: Constructing the Wannier states from the U matrix."
1309 call messages_info(1)
1311 inquire(file=trim(trim(adjustl(w90_prefix))//
'_centres.xyz'),exist=exist)
1312 if (.not. exist)
then
1313 message(1) =
'oct-wannier90: Cannot find the Wannier90 file seedname_centres.xyz.'
1314 write(message(2),
'(a)')
'Please run wannier90.x with "write_xyz=.true." in '// trim(adjustl(w90_prefix)) //
'.'
1315 call messages_fatal(2)
1318 w90_xyz = io_open(trim(trim(adjustl(w90_prefix))//
'_centres.xyz'), global_namespace, action=
'read')
1320 safe_allocate(centers(1:3, 1:w90_num_wann))
1324 do iw = 1, w90_num_wann
1325 read(w90_xyz, *) dum, centers(1:3, iw)
1327 centers(1:3, iw) = units_to_atomic(unit_angstrom, centers(1:3, iw))
1329 call io_close(w90_xyz)
1332 inquire(file=trim(trim(adjustl(w90_prefix))//
'_u_dis.mat'),exist=exist)
1334 message(1) =
'oct-wannier90: Calculation of Wannier states with disentanglement is not yet supported.'
1335 call messages_fatal(1)
1338 inquire(file=trim(trim(adjustl(w90_prefix))//
'_u.mat'),exist=exist)
1339 if (.not. exist)
then
1340 message(1) =
'oct-wannier90: Cannot find the Wannier90 seedname_u.mat file.'
1341 write(message(2),
'(a)')
'Please run wannier90.x with "write_u_matrices=.true." in '// trim(adjustl(w90_prefix)) //
'.'
1342 call messages_fatal(2)
1344 w90_u_mat = io_open(trim(trim(adjustl(w90_prefix))//
'_u.mat'), global_namespace, action=
'read')
1350 read(w90_u_mat, *) nik, nwann, nwann
1351 if (nik /= w90_num_kpts .or. nwann /= w90_num_wann)
then
1352 print *, w90_num_wann, w90_num_kpts, nik, nwann
1353 message(1) =
"The file contains U matrices is inconsistent with the .win file."
1354 call messages_fatal(1)
1357 safe_allocate(umnk(1:w90_num_wann, 1:w90_num_wann, 1:w90_num_kpts))
1359 do ik = 1, w90_num_kpts
1364 read(w90_u_mat,
'(f15.10,sp,f15.10)') ((umnk(iw, iw2, ik), iw=1, w90_num_wann), iw2=1, w90_num_wann)
1367 call io_close(w90_u_mat)
1370 call parse_variable(global_namespace,
'OutputFormat', 0, how)
1372 call io_mkdir(
'wannier', global_namespace)
1375 safe_allocate(zwn(1:mesh%np))
1376 safe_allocate(psi(1:mesh%np, 1:st%d%dim))
1377 safe_allocate(phase(1:mesh%np))
1379 do iw = 1, w90_num_wann
1383 do ik = 1, w90_num_kpts
1384 kpoint(1:space%dim) = kpoints%get_point(ik, absolute_coordinates=.
true.)
1388 xx = mesh%x(ip, 1:space%dim)-centers(1:space%dim, iw)
1389 xx = ions%latt%fold_into_cell(xx)
1390 phase(ip) =
exp(-m_zi* sum( xx * kpoint(1:space%dim)))
1394 if (exclude_list(iw2)) cycle
1396 if (st%d%ispin /= spin_polarized)
then
1397 call states_elec_get_state(st, mesh, iw2, ik, psi)
1399 call states_elec_get_state(st, mesh, iw2, (ik-1)*2+w90_spin_channel, psi)
1404 zwn(ip) = zwn(ip) + umnk(band_index(iw2), iw, ik) * psi(ip, 1) * phase(ip)
1414 wmod = real(zwn(ip)*conjg(zwn(ip)), real64)
1415 if (wmod > wmodmax)
then
1420 scal =
sqrt(wmodmax)/zwn(ipmax)/w90_num_kpts
1421 call mesh_minmaxloc(mesh, wmodmax, rankmax, mpi_maxloc)
1422 call mesh%mpi_grp%bcast(scal, 1, mpi_double_complex, rankmax)
1423 call lalg_scal(mesh%np, scal, zwn)
1426 fn_unit =
sqrt(units_out%length**(-space%dim))
1427 write(fname,
'(a,i0)')
'wannier-', iw
1428 call zio_function_output(how,
"wannier", trim(fname), global_namespace, space, mesh, &
1429 zwn, fn_unit, ierr, pos=ions%pos, atoms=ions%atom, grp = st%dom_st_kpt_mpi_grp)
1434 if(abs(real(zwn(ip), real64)) >= 1e-2_real64)
then
1435 wmodmax = max(wmodmax, abs(aimag(zwn(ip)))/abs(real(zwn(ip), real64)))
1438 call mesh_minmaxloc(mesh, wmodmax, rankmax, mpi_maxloc)
1440 write(message(1),
'(a,i0,a,f11.6)')
'oct-wannier90: Wannier function ', iw,
' Max. Im/Re Ratio = ', wmodmax
1441 call messages_info(1)
1444 safe_deallocate_a(umnk)
1445 safe_deallocate_a(zwn)
1446 safe_deallocate_a(psi)
1447 safe_deallocate_a(phase)
1448 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)
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, fixed_occ, 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), parameter, 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()