38 use,
intrinsic :: iso_fortran_env
73 integer :: w90_what, w90_mode
74 integer(int64) :: w90_what_default
78 integer :: ii, nik, iter, nst
80 type(restart_t) :: restart
81 type(electrons_t),
pointer :: sys
82 logical :: w90_spinors, scdm_proj, w90_scdm
83 integer :: w90_nntot, w90_num_bands, w90_num_kpts
84 integer,
allocatable :: w90_nnk_list(:,:)
85 character(len=80) :: w90_prefix
86 integer :: w90_num_wann
87 real(real64),
allocatable :: w90_proj_centers(:,:)
88 integer,
allocatable :: w90_proj_lmr(:,:)
90 integer,
allocatable :: w90_spin_proj_component(:)
91 real(real64),
allocatable :: w90_spin_proj_axis(:,:)
92 integer :: w90_num_exclude
93 logical,
allocatable :: exclude_list(:)
94 integer,
allocatable :: band_index(:)
95 integer,
allocatable :: active_bands(:)
96 logical :: read_td_states
97 integer :: w90_spin_channel
98 integer :: w90_scdm_entanglement
99 logical :: w90_bloch_sums = .false.
100 logical :: w90_have_dis_win_min = .false.
101 logical :: w90_have_dis_win_max = .false.
102 real(real64) :: w90_dis_win_min =
m_zero
103 real(real64) :: w90_dis_win_max =
m_zero
106 integer,
allocatable :: jpvt(:)
107 complex(real64),
allocatable :: uk(:,:,:)
108 complex(real64),
allocatable :: chi(:,:), chi_diag(:,:),chi2(:,:)
109 real(real64),
allocatable :: x_global(:,:)
110 real(real64),
allocatable :: chi_eigenval(:), occ_temp(:), occ_smeared(:,:)
111 real(real64) :: scdm_mu, scdm_sigma, kvec(3), factor(3)
112 integer :: jst, idir, sender, ikpoint
114 integer(int64) :: how
138 if (w90_prefix ==
'w90')
then
139 message(1) =
"oct-wannier90: the prefix is set by default to w90"
169 if (w90_mode == 0)
then
170 message(1) =
"Wannier90Mode must be set to a value different from 0."
192 w90_what_default = option__wannier90files__w90_mmn + option__wannier90files__w90_amn + option__wannier90files__w90_eig
193 if (sys%st%d%ispin ==
spinors) w90_what_default = w90_what_default + option__wannier90files__w90_spn
247 if (sys%st%parallel_in_states)
then
250 if (sys%kpoints%use_symmetries)
then
251 message(1) =
'oct-wannier90: k-points symmetries are not allowed'
254 if (sys%kpoints%use_time_reversal)
then
255 message(1) =
'oct-wannier90: time-reversal symmetry is not allowed'
258 if (sys%kpoints%reduced%nshifts > 1)
then
259 message(1) =
'oct-wannier90: Wannier90 does not allow for multiple shifts of the k-point grid'
267 w90_spinors = .false.
279 do idir = sys%space%periodic_dim+1, sys%space%dim
280 factor(idir) =
m_two * sys%gr%box%bounding_box_l(idir)
282 call sys%ions%latt%scale(factor)
285 select case (w90_mode)
286 case (option__wannier90mode__w90_setup)
290 case (option__wannier90mode__w90_output)
293 case (option__wannier90mode__w90_wannier)
309 if (read_td_states)
then
311 sys%mc, ierr, sys%gr)
314 sys%mc, ierr, sys%gr)
322 if (dim == sys%st%d%dim .and. nik == sys%kpoints%reduced%npoints .and. nst >= sys%st%nst)
then
324 fixed_occ=.
true., ierr=ierr, iter=iter, label =
": wannier90", skip=exclude_list)
326 write(
message(1),
'(a)')
'Restart structure not commensurate.'
334 message(1) =
"Wannier90Mode is set to an unsupported value."
338 safe_deallocate_a(exclude_list)
339 safe_deallocate_a(band_index)
340 safe_deallocate_a(active_bands)
341 safe_deallocate_a(w90_nnk_list)
342 safe_deallocate_a(w90_proj_centers)
343 safe_deallocate_a(w90_proj_lmr)
345 safe_deallocate_p(sys)
357 type(
ions_t),
intent(in) :: ions
359 class(
space_t),
intent(in) :: space
361 character(len=80) :: filename
362 integer :: w90_win, ia, axis(3), npath
366 assert(space%dim == 3)
369 filename = trim(adjustl(w90_prefix)) //
'.win'
372 write(w90_win,
'(a)')
'# this file has been created by the Octopus wannier90 utility'
373 write(w90_win,
'(a)')
' '
376 write(w90_win,
'(a)')
'begin unit_cell_cart'
377 write(w90_win,
'(a)')
'Ang'
381 write(w90_win,
'(a)')
'end unit_cell_cart'
382 write(w90_win,
'(a)')
' '
384 write(w90_win,
'(a)')
'begin atoms_frac'
385 do ia = 1, ions%natoms
386 write(w90_win,
'(a,2x,f13.8,f13.8,f13.8)') trim(ions%atom(ia)%label), ions%latt%cart_to_red(ions%pos(:, ia))
388 write(w90_win,
'(a)')
'end atoms_frac'
389 write(w90_win,
'(a)')
' '
392 write(w90_win,
'(a)')
'use_bloch_phases = .true.'
393 write(w90_win,
'(a)')
' '
395 write(w90_win,
'(a10,i4)')
'num_bands ', sys%st%nst
396 write(w90_win,
'(a9,i4)')
'num_wann ', sys%st%nst
397 write(w90_win,
'(a)')
' '
399 if (sys%st%d%ispin ==
spinors)
then
400 write(w90_win,
'(a)')
'spinors = .true.'
403 if (w90_spin_channel == 1)
then
404 write(w90_win,
'(a)')
'spin = up'
405 else if (w90_spin_channel == 2)
then
406 write(w90_win,
'(a)')
'spin = down'
408 message(1) =
'Wannier90SpinChannel value is invalid.'
414 write(w90_win,
'(a)')
'write_u_matrices = .true.'
415 write(w90_win,
'(a)')
'write_xyz = .true.'
416 write(w90_win,
'(a)')
' '
418 if (kpoints%reduced%npoints == 1)
then
419 write(w90_win,
'(a)')
'gamma_only = .true.'
420 write(w90_win,
'(a)')
' '
423 message(1) =
'oct-wannier90: need Monkhorst-Pack grid. Please specify %KPointsGrid'
428 npath = kpoints%nkpt_in_path()
430 axis(1:3) = kpoints%nik_axis(1:3)
431 assert(product(kpoints%nik_axis(1:3)) == kpoints%reduced%npoints - npath)
433 write(w90_win,
'(a8,i4,i4,i4)')
'mp_grid =', axis(1:3)
434 write(w90_win,
'(a)')
' '
435 write(w90_win,
'(a)')
'begin kpoints '
438 do ii = 1, kpoints%reduced%npoints-npath
439 write(w90_win,
'(f13.8,f13.8,f13.8)') - kpoints%reduced%red_point(1:3,ii)
441 write(w90_win,
'(a)')
'end kpoints '
459 if (read_td_states)
then
461 sys%mc, ierr, sys%gr)
464 sys%mc, ierr, sys%gr)
472 if (dim == sys%st%d%dim .and. nik == sys%kpoints%reduced%npoints .and. nst >= sys%st%nst)
then
474 fixed_occ=.
true., ierr=ierr, iter=iter, label =
": wannier90", skip=exclude_list)
476 write(
message(1),
'(a)')
'Restart structure not commensurate.'
483 if (
bitand(w90_what, option__wannier90files__w90_mmn) /= 0)
then
487 if (
bitand(w90_what, option__wannier90files__w90_unk) /= 0)
then
488 call write_unk(sys%space, sys%gr, sys%st, formatted=.false.)
491 if (
bitand(w90_what, option__wannier90files__w90_amn) /= 0)
then
495 if (
bitand(w90_what, option__wannier90files__w90_eig) /= 0)
then
499 if (
bitand(w90_what, option__wannier90files__w90_spn) /= 0)
then
503 safe_deallocate_a(w90_spin_proj_component)
504 safe_deallocate_a(w90_spin_proj_axis)
511 integer :: w90_nnkp, itemp, dummyint, io, spin_channel_win
512 character(len=80) :: filename, dummy, dummy1, dummy2, line
513 logical :: exist, parse_is_ok
514 real(real64) :: dis_win_min_ev, dis_win_max_ev
515 real(real64) :: dummyr(7)
519 w90_num_kpts = product(sys%kpoints%nik_axis(1:3))
520 assert(w90_num_kpts == sys%st%nik)
526 filename = trim(adjustl(w90_prefix)) //
'.nnkp'
528 message(1) =
"oct-wannier90: Parsing "//filename
531 inquire(file=filename,exist=exist)
532 if (.not. exist)
then
533 message(1) =
'oct-wannier90: Cannot find specified Wannier90 nnkp file.'
534 write(
message(2),
'(a)')
'Please run wannier90.x -pp '// trim(adjustl(w90_prefix)) //
' first.'
538 parse_is_ok = .false.
543 read(w90_nnkp, *, iostat=io) dummy, dummy1
544 if (io == iostat_end)
exit
546 if (dummy ==
'begin' .and. dummy1 ==
'kpoints')
then
547 read(w90_nnkp,*) itemp
548 if (itemp /= w90_num_kpts)
then
549 message(1) =
'oct-wannier90: wannier90 setup seems to have been done with a different number of k-points.'
559 if (.not. parse_is_ok)
then
560 message(1) =
'oct-wannier90: Did not find the kpoints block in nnkp file'
563 parse_is_ok = .false.
569 read(w90_nnkp, *, iostat=io) dummy, dummy1
570 if (io == iostat_end)
exit
572 if (dummy ==
'begin' .and. dummy1 ==
'nnkpts')
then
573 read(w90_nnkp,*) w90_nntot
574 safe_allocate(w90_nnk_list(1:5, 1:w90_num_kpts * w90_nntot))
575 do ii = 1, w90_num_kpts * w90_nntot
576 read(w90_nnkp,*) w90_nnk_list(1:5, ii)
579 read(w90_nnkp,*) dummy
580 if (dummy /=
'end')
then
581 message(1) =
'oct-wannier90: There dont seem to be enough k-points in nnkpts file to.'
589 if (.not. parse_is_ok)
then
590 message(1) =
'oct-wannier90: Did not find nnkpts block in nnkp file'
596 safe_allocate(exclude_list(1:sys%st%nst))
598 exclude_list(1:sys%st%nst) = .false.
601 read(w90_nnkp, *, iostat=io) dummy, dummy1
602 if (io == iostat_end)
exit
603 if (dummy ==
'begin' .and. dummy1 ==
'exclude_bands')
then
604 read(w90_nnkp, *) w90_num_exclude
605 do ii = 1, w90_num_exclude
606 read(w90_nnkp, *) itemp
607 if(itemp > sys%st%nst)
then
608 message(1) =
'oct-wannier90: The exclude_bands list contains a state index higher than the number of states.'
611 exclude_list(itemp) = .
true.
614 read(w90_nnkp, *) dummy
615 if (dummy /=
'end')
then
616 message(1) =
'oct-wannier90: There dont seem to be enough bands in exclude_bands list.'
625 w90_num_bands = sys%st%nst - w90_num_exclude
627 safe_allocate(band_index(1:sys%st%nst))
628 safe_allocate(active_bands(1:w90_num_bands))
630 do ii = 1, sys%st%nst
631 if (exclude_list(ii)) cycle
633 band_index(ii) = itemp
634 active_bands(itemp) = ii
637 if (
bitand(w90_what, option__wannier90files__w90_amn) /= 0 &
638 .or. w90_mode == option__wannier90mode__w90_wannier )
then
643 read(w90_nnkp, *, iostat=io) dummy, dummy1
644 if (io == iostat_end)
then
645 message(1) =
'oct-wannier90: Did not find projections block in w90.nnkp file'
649 if (dummy ==
'begin' .and. (dummy1 ==
'projections' .or. dummy1 ==
'spinor_projections'))
then
651 if (dummy1 ==
'spinor_projections')
then
653 if (sys%st%d%ispin /=
spinors)
then
654 message(1) =
'oct-wannier90: Spinor = .true. is only valid with spinors wavefunctions.'
658 message(1) =
'oct-wannier90: Spinor interface incomplete. Note there is no quantization axis implemented'
661 if (sys%st%d%ispin ==
spinors)
then
662 message(1) =
'oct-wannier90: Octopus has spinors wavefunctions but spinor_projections is not defined.'
663 message(2) =
'oct-wannier90: Please check the input file for wannier 90.'
668 read(w90_nnkp, *) w90_nproj
672 w90_num_wann = w90_nproj
674 if(w90_nproj == 0) w90_num_wann = w90_num_bands
676 safe_allocate(w90_proj_centers(1:3, 1:w90_nproj))
677 safe_allocate(w90_proj_lmr(1:w90_nproj, 1:3))
678 if (w90_spinors)
then
679 safe_allocate(w90_spin_proj_component(1:w90_nproj))
681 if (w90_spinors)
then
682 safe_allocate(w90_spin_proj_axis(1:w90_nproj, 1:3))
686 read(w90_nnkp, *) w90_proj_centers(1:3, ii), w90_proj_lmr(ii, 1:3)
688 read(w90_nnkp, *) dummyr(1:7)
689 if (w90_spinors)
then
690 read(w90_nnkp, *) w90_spin_proj_component(ii), w90_spin_proj_axis(ii, 1:3)
692 if (w90_spin_proj_component(ii) == -1) w90_spin_proj_component(ii) = 2
696 read(w90_nnkp, *) dummy
697 if (dummy /=
'end')
then
698 message(1) =
'oct-wannier90: There dont seem to be enough projections in nnkpts file to.'
708 read(w90_nnkp, *, iostat=io) dummy, dummy1
709 if (io == iostat_end)
exit
711 if (dummy ==
'begin' .and. dummy1 ==
'auto_projections')
then
713 read(w90_nnkp, *) w90_num_wann
715 if (.not. w90_scdm)
then
716 message(1) =
'oct-wannier90: Found auto_projections block. Currently the only implemented automatic way'
717 message(2) =
'oct-wannier90: to compute projections is the SCDM method.'
718 message(3) =
'oct-wannier90: Please set Wannier90UseSCDM = yes in the inp file.'
722 read(w90_nnkp, *) dummyint
723 if (dummyint /= 0)
then
724 message(1) =
'oct-wannier90: The second row in auto_projections has to be 0, per Wannier90 documentation.'
728 if (w90_num_wann <= 0)
then
729 message(1) =
'oct-wannier90: num_wann must be larger than 0 when using auto_projections.'
732 if (w90_num_wann > w90_num_bands)
then
733 message(1) =
'oct-wannier90: num_wann cannot be larger than num_bands when using auto_projections.'
742 message(1) =
"oct-wannier90: Finished parsing "//filename
747 filename = trim(adjustl(w90_prefix)) //
'.win'
748 message(1) =
"oct-wannier90: Parsing "//filename
752 read(w90_nnkp, fmt=
'(a)', iostat=io) line
753 if (io == iostat_end)
exit
754 if (index(line,
'=') > 0)
then
755 read(line, *, iostat=io) dummy, dummy2, dummy1
757 read(line, *, iostat=io) dummy, dummy1
760 if (dummy ==
'dis_win_min')
then
761 if (index(line,
'=') > 0)
then
762 read(line, *, iostat=io) dummy, dummy2, dis_win_min_ev
764 read(line, *, iostat=io) dummy, dis_win_min_ev
766 if (io == 0) w90_have_dis_win_min = .
true.
769 if (dummy ==
'dis_win_max')
then
770 if (index(line,
'=') > 0)
then
771 read(line, *, iostat=io) dummy, dummy2, dis_win_max_ev
773 read(line, *, iostat=io) dummy, dis_win_max_ev
775 if (io == 0) w90_have_dis_win_max = .
true.
779 if (dummy ==
'spin')
then
781 message(1) =
'oct-wannier90: The variable spin is set for a non spin-polarized calculation.'
785 if (dummy1 ==
'up')
then
787 else if (dummy1 ==
'down')
then
790 message(1) =
'oct-wannier90: Error parsing the variable spin.'
793 if (spin_channel_win /= w90_spin_channel)
then
794 message(1) =
'spin polarization input from .win and Wannier90SpinChannel do not agree.'
801 if (w90_have_dis_win_min)
then
803 write(
message(1),
'(a,f12.5)')
'oct-wannier90: Parsed dis_win_min (eV) = ', dis_win_min_ev
806 if (w90_have_dis_win_max)
then
808 write(
message(1),
'(a,f12.5)')
'oct-wannier90: Parsed dis_win_max (eV) = ', dis_win_max_ev
813 write(
message(1),
'(a,i1)')
'oct-wannier90: Using spin channel ', w90_spin_channel
817 message(1) =
"oct-wannier90: Finished parsing "//filename
826 class(
mesh_t),
intent(in) :: mesh
829 integer :: ist, jst, ik, ip, w90_mmn, iknn, ib
830 real(real64) :: Gcart(3)
832 character(len=80) :: filename
833 complex(real64),
allocatable :: overlap(:), ss(:)
834 complex(real64),
allocatable :: psin(:,:), phase(:)
836 integer :: inode, node_fr, node_to
837 type(mpi_request) :: send_req
843 if (st%parallel_in_states)
then
847 message(1) =
"Info: Computing the overlap matrix"
851 filename =
'./'// trim(adjustl(w90_prefix))//
'.mmn'
855 if (st%system_grp%is_root())
then
856 write(w90_mmn,*)
'Created by oct-wannier90'
857 write(w90_mmn,*) w90_num_bands, w90_num_kpts, w90_nntot
860 safe_allocate(psin(1:mesh%np, 1:st%d%dim))
861 safe_allocate(phase(1:mesh%np))
862 safe_allocate(overlap(1:w90_num_bands))
863 safe_allocate(ss(1:st%nst))
867 do ii = 1, w90_num_kpts * w90_nntot
868 ik = w90_nnk_list(1, ii)
869 iknn = w90_nnk_list(2, ii)
870 g(1:3) = w90_nnk_list(3:5, ii)
871 if (st%system_grp%is_root())
write(w90_mmn,
'(I10,2x,I10,2x,I3,2x,I3,2x,I3)') ik, iknn, g
876 if (sys%space%periodic_dim > 0)
then
877 g(sys%space%periodic_dim+1:sys%space%dim) = 0
881 ik = sys%st%d%get_k_spin_index(ik, w90_spin_channel)
882 iknn = sys%st%d%get_k_spin_index(iknn, w90_spin_channel)
885 if(ik >= st%d%kpt%start .and. ik <= st%d%kpt%end)
then
894 if (any(g /= 0))
then
897 phase(ip) =
exp(-
m_zi*dot_product(mesh%x(1:3, ip), gcart(1:3)))
906 if (exclude_list(jst)) cycle
909 if ( .not. st%d%kpt%parallel .and. .not. st%parallel_in_states)
then
914 do inode = 0, st%d%kpt%mpi_grp%size-1
915 if(iknn >= st%st_kpt_task(inode,3) .and. iknn <= st%st_kpt_task(inode,4))
then
918 if(ik >= st%st_kpt_task(inode,3) .and. ik <= st%st_kpt_task(inode,4))
then
925 send_req = mpi_request_null
930 if(node_to /= st%d%kpt%mpi_grp%rank)
then
931 call st%d%kpt%mpi_grp%isend(psin, mesh%np*st%d%dim, mpi_double_complex, node_to, send_req)
935 if(node_to == st%d%kpt%mpi_grp%rank .and. node_to /= node_fr)
then
936 call st%d%kpt%mpi_grp%recv(psin, mesh%np*st%d%dim, mpi_double_complex, node_fr)
938 if (send_req /= mpi_request_null)
then
939 call st%d%kpt%mpi_grp%wait(send_req)
945 if(ik >= st%d%kpt%start .and. ik <= st%d%kpt%end)
then
948 if (any(g /= 0))
then
951 do idim = 1, st%d%dim
954 psin(ip, idim) = psin(ip, idim) * phase(ip)
963 do ib = st%group%block_start, st%group%block_end
964 batch => st%group%psib(ib, ik)
965 if (all(exclude_list(batch%ist(1:batch%nst)))) cycle
967 do ist = 1, batch%nst
968 if (exclude_list(batch%ist(ist))) cycle
969 overlap(band_index(batch%ist(ist))) = ss(ist)
975 call mesh%allreduce(overlap)
978 if(st%d%kpt%parallel)
then
983 if (st%system_grp%is_root())
then
985 if (exclude_list(ist)) cycle
986 write(w90_mmn,
'(e18.10,2x,e18.10)') overlap(band_index(ist))
995 safe_deallocate_a(psin)
996 safe_deallocate_a(phase)
997 safe_deallocate_a(overlap)
998 safe_deallocate_a(ss)
1008 integer :: ist, ik, w90_eig
1009 character(len=80) :: filename
1013 if (sys%st%parallel_in_states)
then
1017 if (sys%st%system_grp%is_root())
then
1018 filename =
'./'//trim(adjustl(w90_prefix))//
'.eig'
1020 do ik = 1, w90_num_kpts
1021 do ist = 1, sys%st%nst
1022 if (exclude_list(ist)) cycle
1024 write(w90_eig,
'(I5,2x,I8,2x,e18.10)') band_index(ist), ik, &
1027 write(w90_eig,
'(I5,2x,I8,2x,e18.10)') band_index(ist), ik, &
1040 subroutine write_unk(space, mesh, st, formatted)
1041 class(
space_t),
intent(in) :: space
1042 class(
mesh_t),
intent(in) :: mesh
1044 logical,
intent(in) :: formatted
1046 integer :: ist, ik, unk_file, ispin
1047 integer :: ix, iy, iz
1048 real(real64) :: w_real, w_imag
1049 character(len=80) :: filename
1050 complex(real64),
allocatable :: psi(:)
1056 if (st%d%kpt%parallel)
then
1060 if (sys%gr%parallel_in_domains)
then
1064 if (st%parallel_in_states)
then
1071 safe_allocate(psi(1:mesh%np))
1074 mesh%coord_system, need_partition=.not.mesh%parallel_in_domains)
1078 assert(cf%batch_size == 1)
1080 do ikpoint = 1, w90_num_kpts
1082 do ispin = 1, st%d%dim
1083 if (st%system_grp%is_root())
then
1084 write(filename,
'(a,i5.5,a1,i1)')
'./UNK', ikpoint,
'.', ispin
1088 write(unk_file, *) mesh%idx%ll(1:mesh%idx%dim), ikpoint, w90_num_bands
1091 write(unk_file) mesh%idx%ll(1:mesh%idx%dim), ikpoint, w90_num_bands
1097 if (exclude_list(ist)) cycle
1099 ik = st%d%get_k_spin_index(ikpoint, w90_spin_channel)
1104 assert(.not. cube%parallel_in_domains)
1107 if (st%system_grp%is_root())
then
1109 do iz=1,cube%rs_n_global(3)
1110 do iy = 1,cube%rs_n_global(2)
1111 do ix = 1,cube%rs_n_global(1)
1112 w_real = real(cf%zrs(ix,iy,iz,1), real64)
1113 w_imag = aimag(cf%zrs(ix,iy,iz,1))
1114 write (unk_file, *) w_real, w_imag
1119 write(unk_file) (((cf%zrs(ix,iy,iz,1), ix=1,cube%rs_n_global(1)), iy=1,cube%rs_n_global(2)), iz=1,cube%rs_n_global(3))
1123 if (st%system_grp%is_root())
call io_close(unk_file)
1130 safe_deallocate_a(psi)
1138 class(
space_t),
intent(in) :: space
1139 class(
mesh_t),
intent(in) :: mesh
1144 integer :: ist, ik, w90_amn, idim, iw, ip, igamma
1145 real(real64) :: center(3), kpoint(3), threshold
1146 character(len=80) :: filename
1147 complex(real64),
allocatable :: psi(:,:), psi_global(:,:), phase(:), projection(:)
1148 real(real64),
allocatable :: ylm(:)
1151 integer :: tag, root_rank
1156 if (st%parallel_in_states)
then
1160 filename =
'./'// trim(adjustl(w90_prefix))//
'.amn'
1164 if (st%system_grp%is_root())
then
1165 write(w90_amn,*)
'Created by oct-wannier90'
1166 write(w90_amn,*) w90_num_bands, w90_num_kpts, w90_num_wann
1171 safe_allocate(jpvt(1:sys%gr%np_global*sys%st%d%dim))
1172 safe_allocate(psi(1:sys%gr%np, 1:sys%st%d%dim))
1173 safe_allocate(psi_global(1:sys%gr%np_global, 1:sys%st%d%dim))
1174 safe_allocate(x_global(1:sys%gr%np_global, 1:3))
1175 safe_allocate(occ_temp(1:sys%st%nst))
1176 safe_allocate(occ_smeared(1:w90_num_bands,1:w90_num_kpts))
1179 if (sys%st%system_grp%is_root())
then
1180 root_rank = sys%st%system_grp%rank
1185 w90_spin_channel, w90_scdm_entanglement, scdm_mu, scdm_sigma, occ_smeared)
1190 do ikpoint = 1, w90_num_kpts
1196 if (igamma == 0)
then
1202 do ist = 1, sys%st%nst
1203 occ_temp(ist)= sys%st%occ(ist, igamma)
1204 if (exclude_list(ist))
then
1205 sys%st%occ(ist, igamma)=
m_zero
1207 sys%st%occ(ist, igamma)=occ_smeared(band_index(ist), igamma)
1215 do ist = 1, sys%st%nst
1216 sys%st%occ(ist, igamma) = occ_temp(ist)
1219 safe_allocate(uk(1:w90_num_bands, 1:w90_num_wann, 1:w90_num_kpts))
1222 safe_allocate(chi(1:w90_num_bands, 1:w90_num_wann))
1223 safe_allocate(chi_diag(1:w90_num_wann, 1:w90_num_wann))
1224 safe_allocate(chi2(1:w90_num_wann, 1:w90_num_wann))
1225 safe_allocate(chi_eigenval(1:w90_num_wann))
1227 chi(1:w90_num_bands, 1:w90_num_wann) =
m_zero
1235 do ikpoint = 1, w90_num_kpts
1236 kvec(:) = sys%kpoints%reduced%point(:, ikpoint)
1237 ik = sys%st%d%get_k_spin_index(ikpoint, w90_spin_channel)
1238 do ist = 1, w90_num_bands
1242 do idim = 1, sys%st%d%dim
1245 sender = sys%st%d%kpt%mpi_grp%rank
1249 call sys%st%d%kpt%mpi_grp%allreduce_inplace(sender, 1, mpi_integer, mpi_max)
1252 tag = (idim - 1)*
size(active_bands) + ii
1253 if (sender /= root_rank)
then
1254 if (sys%st%system_grp%rank == sender)
then
1255 do idim = 1, sys%st%d%dim
1256 call sys%st%system_grp%send(psi_global(:,idim),
i8_to_i4(sys%gr%np_global), mpi_double_complex, root_rank, tag=tag)
1259 if (sys%st%system_grp%is_root())
then
1260 do idim = 1, sys%st%d%dim
1261 call sys%st%system_grp%recv(psi_global(:,idim),
i8_to_i4(sys%gr%np_global), mpi_double_complex, sender, tag=tag)
1265 if (sys%st%system_grp%is_root())
then
1266 do jst = 1, w90_num_wann
1267 chi(ist, jst) = occ_smeared(ist, ik) * conjg(psi_global(jpvt(jst), 1)) &
1268 *
exp(
m_zi * dot_product(x_global(jpvt(jst),1:3), kvec(1:3)))
1273 if (sys%st%system_grp%is_root())
then
1276 chi_diag = matmul(conjg(transpose(chi)), chi)
1278 chi2 = conjg(transpose(chi_diag))
1281 if (any(chi_eigenval(:) .lt.
m_zero))
then
1282 message(1) =
'SCDM Wannierization failed because chi matrix is'
1283 message(2) =
'ill conditioned. Try changing scdm_sigma and/or'
1288 do ist = 1, w90_num_wann
1289 chi_eigenval(ist) =
m_one /
sqrt(chi_eigenval(ist))
1290 chi2(ist, 1:w90_num_wann) = chi_eigenval(ist) * chi2(ist, 1:w90_num_wann)
1294 uk(:,:,ik) = matmul(chi, matmul(chi_diag,chi2))
1299 safe_deallocate_a(chi)
1300 safe_deallocate_a(psi)
1301 safe_deallocate_a(psi_global)
1302 safe_deallocate_a(x_global)
1303 safe_deallocate_a(chi_diag)
1304 safe_deallocate_a(chi2)
1305 safe_deallocate_a(chi_eigenval)
1306 safe_deallocate_a(jpvt)
1307 safe_deallocate_a(occ_temp)
1308 safe_deallocate_a(occ_smeared)
1310 message(1) =
"Info: Writing projections obtained from SCDM."
1313 do ik = 1, w90_num_kpts
1315 if (exclude_list(ist)) cycle
1316 if (st%system_grp%is_root())
then
1317 do iw = 1, w90_num_wann
1318 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)
1324 safe_deallocate_a(uk)
1328 message(1) =
"Info: Computing the projection matrix"
1334 safe_allocate(orbitals(1:w90_nproj))
1339 orbitals(iw)%norbs = 1
1340 orbitals(iw)%ndim = 1
1341 orbitals(iw)%radius = -
log(threshold)
1342 orbitals(iw)%use_submesh = .false.
1345 center(1:3) = latt%red_to_cart(w90_proj_centers(1:3, iw))
1346 call submesh_init(orbitals(iw)%sphere, space, mesh, latt, center, orbitals(iw)%radius)
1349 safe_allocate(ylm(1:orbitals(iw)%sphere%np))
1351 call ylm_wannier(ylm, w90_proj_lmr(iw,1), w90_proj_lmr(iw,2), &
1352 orbitals(iw)%sphere%r, orbitals(iw)%sphere%rel_x, orbitals(iw)%sphere%np)
1355 if (w90_proj_lmr(iw,3) == 1)
then
1356 do ip = 1,orbitals(iw)%sphere%np
1357 ylm(ip) = ylm(ip)*
m_two*
exp(-orbitals(iw)%sphere%r(ip))
1363 safe_allocate(orbitals(iw)%zorb(1:orbitals(iw)%sphere%np, 1, 1))
1364 orbitals(iw)%zorb(1:orbitals(iw)%sphere%np, 1, 1) = ylm(1:orbitals(iw)%sphere%np)
1365 safe_deallocate_a(ylm)
1367 safe_allocate(orbitals(iw)%phase(1:orbitals(iw)%sphere%np, st%d%kpt%start:st%d%kpt%end))
1368 orbitals(iw)%phase(:,:) =
m_z0
1369 safe_allocate(orbitals(iw)%eorb_mesh(1:mesh%np, 1, 1, st%d%kpt%start:st%d%kpt%end))
1370 orbitals(iw)%eorb_mesh(:,:,:,:) =
m_z0
1373 kpt_max = w90_num_kpts)
1377 safe_allocate(psi(1:mesh%np, 1:st%d%dim))
1378 safe_allocate(phase(1:mesh%np))
1379 safe_allocate(projection(1:w90_nproj))
1381 do ikpoint = 1, w90_num_kpts
1382 kpoint(1:space%dim) = kpoints%get_point(ikpoint)
1385 phase(ip) =
exp(-
m_zi* sum(mesh%x(1:space%dim, ip) * kpoint(1:space%dim)))
1389 ik = sys%st%d%get_k_spin_index(ikpoint, w90_spin_channel)
1392 if (exclude_list(ist)) cycle
1396 if(ik >= st%d%kpt%start .and. ik <= st%d%kpt%end)
then
1400 do idim = 1, st%d%dim
1404 psi(ip, idim) = psi(ip, idim)*phase(ip)
1409 do iw = 1, w90_nproj
1411 if (w90_spinors) idim = w90_spin_proj_component(iw)
1415 projection(iw) =
zmf_dotp(mesh, psi(1:mesh%np,idim), &
1416 orbitals(iw)%eorb_mesh(1:mesh%np,1,1,ik), reduce = .false.)
1420 call mesh%allreduce(projection)
1424 if(st%d%kpt%parallel)
then
1428 if (st%system_grp%is_root())
then
1429 do iw = 1, w90_nproj
1430 write (w90_amn,
'(I5,2x,I5,2x,I5,2x,e18.10,2x,e18.10)') band_index(ist), iw, ikpoint, projection(iw)
1436 safe_deallocate_a(psi)
1437 safe_deallocate_a(phase)
1438 safe_deallocate_a(projection)
1440 do iw = 1, w90_nproj
1443 safe_deallocate_a(orbitals)
1459 class(mesh_t),
intent(in) :: mesh
1460 type(states_elec_t),
target,
intent(in) :: st
1462 integer :: ist, jst, ik, w90_spn, counter
1463 character(len=80) :: filename
1464 complex(real64),
allocatable :: spin(:,:,:)
1465 complex(real64),
allocatable :: psim(:,:), psin(:,:)
1466 complex(real64) :: dot_upup, dot_updown, dot_downup, dot_downdown
1469 call profiling_in(
"W90_SPN")
1471 assert(st%d%ispin == spinors)
1473 if (st%parallel_in_states)
then
1474 call messages_not_implemented(
"w90_spn output with states parallelization")
1477 message(1) =
"Info: Computing the spin file"
1478 call messages_info(1)
1480 filename =
'./'// trim(adjustl(w90_prefix))//
'.spn'
1481 w90_spn = io_open(trim(filename), global_namespace, action=
'write')
1484 if (st%system_grp%is_root())
then
1485 write(w90_spn,*)
'Created by oct-wannier90'
1486 write(w90_spn,*) w90_num_bands, w90_num_kpts
1489 safe_allocate(psim(1:mesh%np, 1:st%d%dim))
1490 safe_allocate(psin(1:mesh%np, 1:st%d%dim))
1491 safe_allocate(spin(1:3, 1:(w90_num_bands*(w90_num_bands+1))/2, 1:w90_num_kpts))
1495 do ik = st%d%kpt%start, st%d%kpt%end
1498 if (exclude_list(jst)) cycle
1500 call states_elec_get_state(st, mesh, jst, ik, psim)
1502 if (exclude_list(ist)) cycle
1504 counter = counter + 1
1506 call states_elec_get_state(st, mesh, ist, ik, psin)
1508 dot_upup = zmf_dotp(mesh, psin(:, 1), psim(:, 1), reduce = .false.)
1509 dot_downdown = zmf_dotp(mesh, psin(:, 2), psim(:, 2), reduce = .false.)
1510 dot_updown = zmf_dotp(mesh, psin(:, 1), psim(:, 2), reduce = .false.)
1511 dot_downup = zmf_dotp(mesh, psin(:, 2), psim(:, 1), reduce = .false.)
1513 spin(1, counter, ik) = dot_updown + dot_downup
1514 spin(2, counter, ik) = -m_zi * dot_updown + m_zi * dot_downup
1515 spin(3, counter, ik) = dot_upup - dot_downdown
1520 call profiling_in(
"W90_SPN_REDUCE")
1521 call mesh%allreduce(spin)
1523 if(st%d%kpt%parallel)
then
1524 call comm_allreduce(st%d%kpt%mpi_grp, spin)
1526 call profiling_out(
"W90_SPN_REDUCE")
1529 if (st%system_grp%is_root())
then
1530 do ik = 1, w90_num_kpts
1533 if (exclude_list(jst)) cycle
1536 if (exclude_list(ist)) cycle
1538 counter = counter + 1
1539 write(w90_spn,
'(e18.10,2x,e18.10)') spin(1, counter, ik)
1540 write(w90_spn,
'(e18.10,2x,e18.10)') spin(2, counter, ik)
1541 write(w90_spn,
'(e18.10,2x,e18.10)') spin(3, counter, ik)
1547 call io_close(w90_spn)
1549 safe_deallocate_a(psim)
1550 safe_deallocate_a(psin)
1551 safe_deallocate_a(spin)
1553 call profiling_out(
"W90_SPN")
1561 class(space_t),
intent(in) :: space
1562 class(mesh_t),
intent(in) :: mesh
1563 type(ions_t),
intent(in) :: ions
1564 type(states_elec_t),
intent(in) :: st
1565 type(kpoints_t),
intent(in) :: kpoints
1567 integer :: w90_u_mat, w90_u_dis, w90_xyz, nwann, nik, nib
1568 integer :: ik, iw, iw2, ip, ipmax, rankmax, idmmax, ib
1569 real(real64),
allocatable :: centers(:,:), supercell_centers(:,:), new_centers(:,:)
1570 complex(real64),
allocatable :: Umnk(:,:,:), Umat(:,:,:), Udis(:,:,:)
1571 complex(real64),
allocatable :: zwn(:,:,:), psi(:,:), phase(:,:), phase_bloch(:), zwn_bloch(:,:,:)
1572 character(len=MAX_PATH_LEN) :: fname
1573 real(real64) :: kpoint(3), wmod, wmodmax, xx(space%dim)
1574 character(len=2) :: dum
1575 logical :: exist, have_disentangled
1576 type(unit_t) :: fn_unit
1577 complex(real64) :: scal
1578 type(block_t) :: blk
1579 integer :: supercell(space%dim), ii, jj, kk, ncols, Nreplica, irep, irepmax
1580 real(real64) :: min_image_displ(3), offset(space%dim)
1581 integer :: jw, ib_orig, nactive, j, nfixed
1582 integer,
allocatable :: parent(:)
1583 real(real64),
parameter :: tol_cluster = 0.25_real64
1585 integer,
allocatable :: active_rows(:)
1586 complex(real64),
allocatable :: uwork(:,:)
1587 logical :: in_window
1592 message(1) =
"oct-wannier90: Constructing the Wannier states from the U matrix."
1593 call messages_info(1)
1595 inquire(file=trim(trim(adjustl(w90_prefix))//
'_centres.xyz'),exist=exist)
1596 if (.not. exist)
then
1597 message(1) =
'oct-wannier90: Cannot find the Wannier90 file seedname_centres.xyz.'
1598 write(message(2),
'(a)')
'Please run wannier90.x with "write_xyz=.true." in '// trim(adjustl(w90_prefix)) //
'.'
1599 call messages_fatal(2)
1602 w90_xyz = io_open(trim(trim(adjustl(w90_prefix))//
'_centres.xyz'), global_namespace, action=
'read')
1604 safe_allocate(centers(1:3, 1:w90_num_wann))
1608 do iw = 1, w90_num_wann
1609 read(w90_xyz, *) dum, centers(1:3, iw)
1611 centers(1:3, iw) = units_to_atomic(unit_angstrom, centers(1:3, iw))
1613 call io_close(w90_xyz)
1617 safe_allocate(parent(1:w90_num_wann))
1618 do iw = 1, w90_num_wann
1621 min_image_displ(:) = ions%latt%cart_to_red(centers(:, iw) - centers(:, jw))
1622 min_image_displ(1:space%periodic_dim) = min_image_displ(1:space%periodic_dim) - nint(min_image_displ(1:space%periodic_dim))
1623 min_image_displ = ions%latt%red_to_cart(min_image_displ)
1624 if (norm2(min_image_displ) < tol_cluster)
then
1625 parent(iw) = parent(jw)
1631 message(1) =
"Info : Clustering of the Wannier centers"
1632 call messages_info(1)
1634 safe_allocate(new_centers(1:3, 1:w90_num_wann))
1635 do iw = 1, w90_num_wann
1636 write(message(1),
'(a,i0,a,3(f7.3,a))')
'Info : Original Wannier center ', &
1637 iw,
' (', centers(1, iw),
', ', centers(2, iw),
', ', centers(3, iw),
')'
1639 if (parent(iw) == iw)
then
1641 new_centers(1:3, iw) = ions%latt%fold_into_cell(centers(1:3, iw))
1645 min_image_displ(:) = ions%latt%cart_to_red(centers(:, iw) - new_centers(:, parent(iw)))
1646 min_image_displ(1:space%periodic_dim) = real(nint(min_image_displ(1:space%periodic_dim)), real64)
1647 min_image_displ = ions%latt%red_to_cart(min_image_displ)
1648 new_centers(1:3, iw) = centers(1:3, iw) - min_image_displ
1651 write(message(2),
'(a,i0,a,3(f7.3,a))')
'Info : New Wannier center ', &
1652 iw,
' (', new_centers(1, iw),
', ', new_centers(2, iw),
', ', new_centers(3, iw),
')'
1653 write(message(3),
'(a)')
''
1654 call messages_info(3)
1658 centers = new_centers - centers
1659 safe_deallocate_a(parent)
1660 safe_deallocate_a(new_centers)
1662 inquire(file=trim(trim(adjustl(w90_prefix))//
'_u.mat'),exist=exist)
1663 if (.not. exist)
then
1664 message(1) =
'oct-wannier90: Cannot find the Wannier90 seedname_u.mat file.'
1665 write(message(2),
'(a)')
'Please run wannier90.x with "write_u_matrices=.true." in '// trim(adjustl(w90_prefix)) //
'.'
1666 call messages_fatal(2)
1668 w90_u_mat = io_open(trim(trim(adjustl(w90_prefix))//
'_u.mat'), global_namespace, action=
'read')
1673 read(w90_u_mat, *) nik, nwann, nwann
1674 if (nik /= w90_num_kpts .or. nwann /= w90_num_wann)
then
1675 message(1) =
"The file contains U matrices is inconsistent with the .win file."
1676 call messages_fatal(1)
1680 safe_allocate(umat(1:w90_num_wann, 1:w90_num_wann, 1:w90_num_kpts))
1682 do ik = 1, w90_num_kpts
1687 read(w90_u_mat,
'(f15.10,sp,f15.10)') ((umat(iw, iw2, ik), iw=1, w90_num_wann), iw2=1, w90_num_wann)
1690 call io_close(w90_u_mat)
1692 inquire(file=trim(trim(adjustl(w90_prefix))//
'_u_dis.mat'),exist=have_disentangled)
1693 if (have_disentangled)
then
1694 message(1) =
'oct-wannier90: Found u_dis.mat, will include disentanglement in Wannier state construction.'
1695 call messages_info(1)
1700 w90_u_dis = io_open(trim(trim(adjustl(w90_prefix))//
'_u_dis.mat'), global_namespace, action=
'read')
1704 read(w90_u_dis, *) nik, nwann, nib
1705 if (nik /= w90_num_kpts .or. nwann /= w90_num_wann .or. nib /= w90_num_bands)
then
1706 message(1) =
'oct-wannier90: The u_dis.mat file is inconsistent with the .win/.nnkp files.'
1707 call messages_fatal(1)
1710 safe_allocate(udis(1:w90_num_bands, 1:w90_num_wann, 1:w90_num_kpts))
1711 do ik = 1, w90_num_kpts
1716 read(w90_u_dis,
'(f15.10,sp,f15.10)') ((udis(ib, iw, ik), ib=1, w90_num_bands), iw=1, w90_num_wann)
1719 call io_close(w90_u_dis)
1723 if (w90_have_dis_win_min .or. w90_have_dis_win_max)
then
1724 safe_allocate(active_rows(1:w90_num_bands))
1725 safe_allocate(uwork(1:w90_num_bands, 1:w90_num_wann))
1728 do ikpoint = 1, w90_num_kpts
1729 ik = st%d%get_k_spin_index(ikpoint, w90_spin_channel)
1731 do ib_orig = 1, st%nst
1732 if (exclude_list(ib_orig)) cycle
1734 if (w90_have_dis_win_min) in_window = in_window .and. st%eigenval(ib_orig, ik) >= w90_dis_win_min
1735 if (w90_have_dis_win_max) in_window = in_window .and. st%eigenval(ib_orig, ik) <= w90_dis_win_max
1737 nactive = nactive + 1
1738 active_rows(nactive) = band_index(ib_orig)
1742 if (nactive > 0)
then
1745 uwork(active_rows(j), 1:w90_num_wann) = udis(j, 1:w90_num_wann, ikpoint)
1747 udis(1:w90_num_bands, 1:w90_num_wann, ikpoint) = uwork(1:w90_num_bands, 1:w90_num_wann)
1752 if (nfixed > 0)
then
1753 write(message(1),
'(a,i0,a)')
'oct-wannier90: remapped legacy u_dis row layout for ', nfixed,
' k-points.'
1754 call messages_info(1)
1757 safe_deallocate_a(active_rows)
1758 safe_deallocate_a(uwork)
1760 message(1) =
'oct-wannier90: dis_win_min/dis_win_max not found in .win; skipping legacy u_dis remap.'
1761 call messages_warning(1)
1766 safe_allocate(umnk(1:w90_num_bands, 1:w90_num_wann, 1:w90_num_kpts))
1768 do ik = 1, w90_num_kpts
1769 umnk(:, :, ik) = umnk(:, :, ik) + matmul(udis(:, :, ik), umat(:, :, ik))
1771 safe_deallocate_a(udis)
1774 safe_allocate(umnk(1:w90_num_wann, 1:w90_num_wann, 1:w90_num_kpts))
1777 safe_deallocate_a(umat)
1780 call parse_variable(global_namespace,
'OutputFormat', 0, how)
1782 message(1) =
"OutputFormat must be specified for outputing Wannier functions."
1783 call messages_fatal(1)
1793 if (parse_is_defined(sys%namespace,
'Wannier90Supercell'))
then
1794 if (parse_block(sys%namespace,
'Wannier90Supercell', blk) == 0)
then
1795 ncols = parse_block_cols(blk, 0)
1796 if (ncols /= space%dim)
then
1797 write(message(1),
'(a,i3,a,i3)')
'Wannier90Supercell has ', ncols,
' columns but must have ', sys%space%dim
1798 call messages_fatal(1, namespace=sys%namespace)
1800 do ii = 1, space%dim
1801 call parse_block_integer(blk, 0, ii - 1, supercell(ii))
1804 call parse_block_end(blk)
1810 nreplica = product(supercell)
1813 safe_allocate(supercell_centers(1:space%dim, 1:nreplica))
1814 offset(1:space%dim) = -
floor((real(supercell(1:space%dim), real64) - m_one) / m_two)
1816 do ii = 0, supercell(1)-1
1817 do jj = 0, supercell(2)-1
1818 do kk = 0, supercell(3)-1
1819 supercell_centers(:, irep) = ions%latt%red_to_cart(offset &
1820 + [real(ii, real64), real(jj, real64), real(kk, real64)])
1828 call io_mkdir(
'wannier', global_namespace)
1831 safe_allocate(zwn(1:mesh%np, 1:nreplica, 1:st%d%dim))
1832 safe_allocate(psi(1:mesh%np, 1:st%d%dim))
1833 safe_allocate(phase(1:mesh%np, 1:nreplica))
1834 safe_allocate(phase_bloch(1:mesh%np))
1835 if (w90_bloch_sums)
then
1836 safe_allocate(zwn_bloch(1:mesh%np, 1:st%d%dim, st%d%kpt%start:st%d%kpt%end))
1839 do iw = 1, w90_num_wann
1843 do ik = 1, w90_num_kpts
1845 if (.not. (ik >= st%d%kpt%start .and. ik <= st%d%kpt%end)) cycle
1847 if (w90_bloch_sums) zwn_bloch(:,:,ik) = m_z0
1849 kpoint(1:space%dim) = kpoints%get_point(ik, absolute_coordinates=.
true.)
1853 do irep = 1, nreplica
1856 xx = mesh%x(1:space%dim, ip)-centers(1:space%dim, iw) + supercell_centers(1:space%dim, irep)
1857 phase(ip, irep) =
exp(-m_zi* sum( xx * kpoint(1:space%dim)))
1860 if (w90_bloch_sums)
then
1862 xx = mesh%x(1:space%dim, ip)
1863 phase_bloch(ip) =
exp(-m_zi* sum( xx * kpoint(1:space%dim)))
1868 if (exclude_list(iw2)) cycle
1870 if (st%d%ispin /= spin_polarized)
then
1871 call states_elec_get_state(st, mesh, iw2, ik, psi)
1873 call states_elec_get_state(st, mesh, iw2, (ik-1)*2+w90_spin_channel, psi)
1877 do idim = 1, st%d%dim
1878 do irep = 1, nreplica
1881 zwn(ip, irep, idim) = zwn(ip, irep, idim) + umnk(band_index(iw2), iw, ik) * psi(ip, idim) * phase(ip, irep)
1888 if (w90_bloch_sums)
then
1890 do idim = 1, st%d%dim
1893 zwn_bloch(ip, idim, ik) = zwn_bloch(ip, idim, ik) &
1894 + umnk(band_index(iw2), iw, ik) * psi(ip, idim) * phase_bloch(ip)
1902 if(st%d%kpt%parallel)
then
1903 call comm_allreduce(st%d%kpt%mpi_grp, zwn)
1908 if (sys%st%d%ispin /= spinors)
then
1912 do irep = 1, nreplica
1914 wmod = real(zwn(ip, irep, 1)*conjg(zwn(ip, irep, 1)), real64)
1915 if (wmod > wmodmax)
then
1922 scal =
sqrt(wmodmax)/zwn(ipmax, irepmax, 1)/w90_num_kpts
1923 call mesh_minmaxloc(mesh, wmodmax, rankmax, mpi_maxloc)
1924 call mesh%mpi_grp%bcast(scal, 1, mpi_double_complex, rankmax)
1925 call lalg_scal(mesh%np, nreplica, scal, zwn(:,:,1))
1927 if (w90_bloch_sums)
then
1928 do ik = st%d%kpt%start, st%d%kpt%end
1932 do idim = 1, st%d%dim
1934 wmod = real(zwn_bloch(ip, idim, ik)*conjg(zwn_bloch(ip, idim, ik)), real64)
1935 if (wmod > wmodmax)
then
1942 scal =
sqrt(wmodmax)/zwn_bloch(ipmax, idmmax, ik)/w90_num_kpts
1943 call mesh_minmaxloc(mesh, wmodmax, rankmax, mpi_maxloc)
1944 call mesh%mpi_grp%bcast(scal, 1, mpi_double_complex, rankmax)
1945 call lalg_scal(mesh%np, st%d%dim, scal, zwn_bloch(:,:,ik))
1951 fn_unit =
sqrt(units_out%length**(-space%dim))
1952 do idim = 1, st%d%dim
1953 if (st%d%ispin == spinors)
then
1954 write(fname,
'(a,i3.3,a4,i1)')
'wannier-', iw,
'-isp', idim
1956 write(fname,
'(a,i3.3,a4,i1)')
'wannier-', iw
1958 if (any(supercell_centers > 1))
then
1959 if (mesh%parallel_in_domains)
then
1960 call messages_not_implemented(
"w90 generate supercell larger than 1x1x1 with domain parallelization")
1962 call io_function_output_supercell(how,
"wannier", trim(fname), mesh, &
1963 space, ions%latt, zwn(:, :, idim), supercell_centers, supercell, fn_unit, ierr, global_namespace, &
1964 pos=ions%pos, atoms=ions%atom, grp = st%dom_st_kpt_mpi_grp)
1966 call zio_function_output(how,
"wannier", trim(fname), global_namespace, space, mesh, &
1967 zwn(:, 1, idim), fn_unit, ierr, pos=ions%pos, atoms=ions%atom, grp = st%dom_st_kpt_mpi_grp)
1972 if (w90_bloch_sums)
then
1973 do ik = st%d%kpt%start, st%d%kpt%end
1974 do idim = 1, st%d%dim
1975 if (st%d%ispin == spinors)
then
1976 write(fname,
'(a,i3.3,a4,i1,a3,i5.5)')
'wannier_bloch-', iw,
'-isp', idim,
'-ik', ik
1978 write(fname,
'(a,i3.3,a4,i1,a3,i5.5)')
'wannier_bloch-', iw,
'-ik', ik
1980 call zio_function_output(how,
"wannier", trim(fname), global_namespace, space, mesh, &
1981 zwn_bloch(:, idim, ik), fn_unit, ierr, pos=ions%pos, atoms=ions%atom)
1987 if (sys%st%d%ispin /= spinors)
then
1989 do irep = 1, nreplica
1991 if(abs(real(zwn(ip, irep, 1), real64)) >= 1e-2_real64)
then
1992 wmodmax = max(wmodmax, abs(aimag(zwn(ip, irep, 1)))/abs(real(zwn(ip, irep, 1), real64)))
1996 call mesh_minmaxloc(mesh, wmodmax, rankmax, mpi_maxloc)
1998 write(message(1),
'(a,i4,a,f11.6)')
'oct-wannier90: Wannier function ', iw,
' Max. Im/Re Ratio = ', wmodmax
1999 call messages_info(1)
2001 write(message(1),
'(a,i4)')
'oct-wannier90: Wannier function done ', iw
2002 call messages_info(1)
2006 safe_deallocate_a(umnk)
2007 safe_deallocate_a(zwn)
2008 safe_deallocate_a(psi)
2009 safe_deallocate_a(phase)
2010 safe_deallocate_a(phase_bloch)
2011 safe_deallocate_a(centers)
2012 safe_deallocate_a(supercell_centers)
2013 safe_deallocate_a(umat)
2014 safe_deallocate_a(udis)
2020 type(states_elec_t),
intent(in) :: st
2021 integer,
intent(in) :: act_bands(:)
2022 integer,
intent(in) :: num_kpts, num_bands
2023 integer,
intent(in) :: spin_channel
2024 integer,
intent(in) :: scdm_entanglement
2025 real(real64),
intent(in) :: mu, sigma
2026 real(real64),
intent(out) :: smeared(:,:)
2028 integer :: ik, ist, ikpoint
2030 select case (scdm_entanglement)
2031 case (option__scdmentanglement__scdm_isolated)
2032 do ikpoint = 1, num_kpts
2033 ik = st%d%get_k_spin_index(ikpoint, spin_channel)
2034 smeared(:, ikpoint) = m_zero
2035 do ist = 1, num_bands
2036 if (st%eigenval(act_bands(ist), ik) .le. mu)
then
2037 smeared(ist, ikpoint)=m_one
2042 case (option__scdmentanglement__scdm_erfc)
2043 do ikpoint = 1, num_kpts
2044 ik = st%d%get_k_spin_index(ikpoint, spin_channel)
2045 do ist = 1, num_bands
2046 smeared(ist, ikpoint)=m_half*erfc((st%eigenval(act_bands(ist), ik)-mu) / sigma)
2050 case (option__scdmentanglement__scdm_gaussian)
2051 do ikpoint = 1, num_kpts
2052 ik = st%d%get_k_spin_index(ikpoint, spin_channel)
2053 do ist = 1, num_bands
2054 smeared(ist, ikpoint)=
exp(-(st%eigenval(act_bands(ist), ik)-mu)**2 / sigma**2)
2059 message(1) =
"SCDMEntanglement is set to an unsupported value."
2060 call messages_fatal(1)
double log(double __x) __attribute__((__nothrow__
double exp(double __x) __attribute__((__nothrow__
double sqrt(double __x) __attribute__((__nothrow__
double floor(double __x) __attribute__((__nothrow__
This module implements batches of mesh functions.
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 zcube_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_end(cube)
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, batch_size)
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_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)
logical pure function, public kpoints_point_is_gamma(this, ik)
subroutine, public kpoints_to_absolute(latt, kin, kout)
System information (time, memory, sysname)
This module defines functions over batches of mesh functions.
subroutine, public zmesh_batch_mf_dotp(mesh, aa, psi, dot, reduce, nst)
calculate the dot products between a batch and a vector of mesh functions
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...
Some general things and nomenclature:
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, act_bands, 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_spn(mesh, st)
Write the spn file containing .
subroutine create_wannier90_eig()
subroutine read_wannier90_files()
subroutine write_unk(space, mesh, st, formatted)
subroutine create_wannier90_mmn(mesh, st)
subroutine wannier90_setup(ions, kpoints, space)
subroutine generate_wannier_states(space, mesh, ions, st, kpoints)
program wannier90_interface
subroutine create_wannier90_amn(space, mesh, latt, st, kpoints)
subroutine choose_scdm_smearing_function(st, act_bands, num_kpts, num_bands, spin_channel, scdm_entanglement, mu, sigma, smeared)
subroutine wannier90_output()