38 use,
intrinsic :: iso_fortran_env
79 integer :: w90_what, w90_mode
80 integer(int64) :: w90_what_default
84 integer :: ii, nik, iter, nst
86 type(restart_t) :: restart
87 type(electrons_t),
pointer :: sys
88 logical :: w90_spinors, scdm_proj, w90_scdm
89 integer :: w90_nntot, w90_num_bands, w90_num_kpts
90 integer,
allocatable :: w90_nnk_list(:,:)
91 character(len=80) :: w90_prefix
92 integer :: w90_num_wann
93 real(real64),
allocatable :: w90_proj_centers(:,:)
94 integer,
allocatable :: w90_proj_lmr(:,:)
96 integer,
allocatable :: w90_spin_proj_component(:)
97 real(real64),
allocatable :: w90_spin_proj_axis(:,:)
98 integer :: w90_num_exclude
99 logical,
allocatable :: exclude_list(:)
100 integer,
allocatable :: band_index(:)
101 integer,
allocatable :: active_bands(:)
102 logical :: read_td_states
103 integer :: w90_spin_channel
104 integer :: w90_scdm_entanglement
105 logical :: w90_bloch_sums = .false.
106 logical :: w90_have_dis_win_min = .false.
107 logical :: w90_have_dis_win_max = .false.
108 real(real64) :: w90_dis_win_min =
m_zero
109 real(real64) :: w90_dis_win_max =
m_zero
112 integer,
allocatable :: jpvt(:)
113 complex(real64),
allocatable :: uk(:,:,:)
114 complex(real64),
allocatable :: chi(:,:), chi_diag(:,:),chi2(:,:)
115 real(real64),
allocatable :: x_global(:,:)
116 real(real64),
allocatable :: chi_eigenval(:), occ_temp(:), occ_smeared(:,:)
117 real(real64) :: scdm_mu, scdm_sigma, kvec(3), factor(3)
118 integer :: jst, idir, sender, ikpoint
120 integer(int64) :: how
144 if (w90_prefix ==
'w90')
then
145 message(1) =
"oct-wannier90: the prefix is set by default to w90"
175 if (w90_mode == 0)
then
176 message(1) =
"Wannier90Mode must be set to a value different from 0."
198 w90_what_default = option__wannier90files__w90_mmn + option__wannier90files__w90_amn + option__wannier90files__w90_eig
199 if (sys%st%d%ispin ==
spinors) w90_what_default = w90_what_default + option__wannier90files__w90_spn
253 if (sys%st%parallel_in_states)
then
256 if (sys%kpoints%use_symmetries)
then
257 message(1) =
'oct-wannier90: k-points symmetries are not allowed'
260 if (sys%kpoints%use_time_reversal)
then
261 message(1) =
'oct-wannier90: time-reversal symmetry is not allowed'
264 if (sys%kpoints%reduced%nshifts > 1)
then
265 message(1) =
'oct-wannier90: Wannier90 does not allow for multiple shifts of the k-point grid'
273 w90_spinors = .false.
285 do idir = sys%space%periodic_dim+1, sys%space%dim
286 factor(idir) =
m_two * sys%gr%box%bounding_box_l(idir)
288 call sys%ions%latt%scale(factor)
291 select case (w90_mode)
292 case (option__wannier90mode__w90_setup)
296 case (option__wannier90mode__w90_output)
299 case (option__wannier90mode__w90_wannier)
315 if (read_td_states)
then
317 sys%mc, ierr, sys%gr)
320 sys%mc, ierr, sys%gr)
328 if (dim == sys%st%d%dim .and. nik == sys%kpoints%reduced%npoints .and. nst >= sys%st%nst)
then
330 fixed_occ=.
true., ierr=ierr, iter=iter, label =
": wannier90", skip=exclude_list)
332 write(
message(1),
'(a)')
'Restart structure not commensurate.'
340 message(1) =
"Wannier90Mode is set to an unsupported value."
344 safe_deallocate_a(exclude_list)
345 safe_deallocate_a(band_index)
346 safe_deallocate_a(active_bands)
347 safe_deallocate_a(w90_nnk_list)
348 safe_deallocate_a(w90_proj_centers)
349 safe_deallocate_a(w90_proj_lmr)
351 safe_deallocate_p(sys)
363 type(
ions_t),
intent(in) :: ions
365 class(
space_t),
intent(in) :: space
367 character(len=80) :: filename
368 integer :: w90_win, ia, axis(3), npath
372 assert(space%dim == 3)
375 filename = trim(adjustl(w90_prefix)) //
'.win'
378 write(w90_win,
'(a)')
'# this file has been created by the Octopus wannier90 utility'
379 write(w90_win,
'(a)')
' '
382 write(w90_win,
'(a)')
'begin unit_cell_cart'
383 write(w90_win,
'(a)')
'Ang'
387 write(w90_win,
'(a)')
'end unit_cell_cart'
388 write(w90_win,
'(a)')
' '
390 write(w90_win,
'(a)')
'begin atoms_frac'
391 do ia = 1, ions%natoms
392 write(w90_win,
'(a,2x,f13.8,f13.8,f13.8)') trim(ions%atom(ia)%label), ions%latt%cart_to_red(ions%pos(:, ia))
394 write(w90_win,
'(a)')
'end atoms_frac'
395 write(w90_win,
'(a)')
' '
398 write(w90_win,
'(a)')
'use_bloch_phases = .true.'
399 write(w90_win,
'(a)')
' '
401 write(w90_win,
'(a10,i4)')
'num_bands ', sys%st%nst
402 write(w90_win,
'(a9,i4)')
'num_wann ', sys%st%nst
403 write(w90_win,
'(a)')
' '
405 if (sys%st%d%ispin ==
spinors)
then
406 write(w90_win,
'(a)')
'spinors = .true.'
409 if (w90_spin_channel == 1)
then
410 write(w90_win,
'(a)')
'spin = up'
411 else if (w90_spin_channel == 2)
then
412 write(w90_win,
'(a)')
'spin = down'
414 message(1) =
'Wannier90SpinChannel value is invalid.'
420 write(w90_win,
'(a)')
'write_u_matrices = .true.'
421 write(w90_win,
'(a)')
'write_xyz = .true.'
422 write(w90_win,
'(a)')
' '
424 if (kpoints%reduced%npoints == 1)
then
425 write(w90_win,
'(a)')
'gamma_only = .true.'
426 write(w90_win,
'(a)')
' '
429 message(1) =
'oct-wannier90: need Monkhorst-Pack grid. Please specify %KPointsGrid'
434 npath = kpoints%nkpt_in_path()
436 axis(1:3) = kpoints%nik_axis(1:3)
437 assert(product(kpoints%nik_axis(1:3)) == kpoints%reduced%npoints - npath)
439 write(w90_win,
'(a8,i4,i4,i4)')
'mp_grid =', axis(1:3)
440 write(w90_win,
'(a)')
' '
441 write(w90_win,
'(a)')
'begin kpoints '
444 do ii = 1, kpoints%reduced%npoints-npath
445 write(w90_win,
'(f13.8,f13.8,f13.8)') - kpoints%reduced%red_point(1:3,ii)
447 write(w90_win,
'(a)')
'end kpoints '
465 if (read_td_states)
then
467 sys%mc, ierr, sys%gr)
470 sys%mc, ierr, sys%gr)
478 if (dim == sys%st%d%dim .and. nik == sys%kpoints%reduced%npoints .and. nst >= sys%st%nst)
then
480 fixed_occ=.
true., ierr=ierr, iter=iter, label =
": wannier90", skip=exclude_list)
482 write(
message(1),
'(a)')
'Restart structure not commensurate.'
489 if (
bitand(w90_what, option__wannier90files__w90_mmn) /= 0)
then
493 if (
bitand(w90_what, option__wannier90files__w90_unk) /= 0)
then
494 call write_unk(sys%space, sys%gr, sys%st, formatted=.false.)
497 if (
bitand(w90_what, option__wannier90files__w90_amn) /= 0)
then
501 if (
bitand(w90_what, option__wannier90files__w90_eig) /= 0)
then
505 if (
bitand(w90_what, option__wannier90files__w90_spn) /= 0)
then
509 safe_deallocate_a(w90_spin_proj_component)
510 safe_deallocate_a(w90_spin_proj_axis)
517 integer :: w90_nnkp, itemp, dummyint, io, spin_channel_win
518 character(len=80) :: filename, dummy, dummy1, dummy2, line
519 logical :: exist, parse_is_ok
520 real(real64) :: dis_win_min_ev, dis_win_max_ev
521 real(real64) :: dummyr(7)
525 w90_num_kpts = product(sys%kpoints%nik_axis(1:3))
526 assert(w90_num_kpts == sys%st%nik)
532 filename = trim(adjustl(w90_prefix)) //
'.nnkp'
534 message(1) =
"oct-wannier90: Parsing "//filename
537 inquire(file=filename,exist=exist)
538 if (.not. exist)
then
539 message(1) =
'oct-wannier90: Cannot find specified Wannier90 nnkp file.'
540 write(
message(2),
'(a)')
'Please run wannier90.x -pp '// trim(adjustl(w90_prefix)) //
' first.'
544 parse_is_ok = .false.
549 read(w90_nnkp, *, iostat=io) dummy, dummy1
550 if (io == iostat_end)
exit
552 if (dummy ==
'begin' .and. dummy1 ==
'kpoints')
then
553 read(w90_nnkp,*) itemp
554 if (itemp /= w90_num_kpts)
then
555 message(1) =
'oct-wannier90: wannier90 setup seems to have been done with a different number of k-points.'
565 if (.not. parse_is_ok)
then
566 message(1) =
'oct-wannier90: Did not find the kpoints block in nnkp file'
569 parse_is_ok = .false.
575 read(w90_nnkp, *, iostat=io) dummy, dummy1
576 if (io == iostat_end)
exit
578 if (dummy ==
'begin' .and. dummy1 ==
'nnkpts')
then
579 read(w90_nnkp,*) w90_nntot
580 safe_allocate(w90_nnk_list(1:5, 1:w90_num_kpts * w90_nntot))
581 do ii = 1, w90_num_kpts * w90_nntot
582 read(w90_nnkp,*) w90_nnk_list(1:5, ii)
585 read(w90_nnkp,*) dummy
586 if (dummy /=
'end')
then
587 message(1) =
'oct-wannier90: There dont seem to be enough k-points in nnkpts file to.'
595 if (.not. parse_is_ok)
then
596 message(1) =
'oct-wannier90: Did not find nnkpts block in nnkp file'
602 safe_allocate(exclude_list(1:sys%st%nst))
604 exclude_list(1:sys%st%nst) = .false.
607 read(w90_nnkp, *, iostat=io) dummy, dummy1
608 if (io == iostat_end)
exit
609 if (dummy ==
'begin' .and. dummy1 ==
'exclude_bands')
then
610 read(w90_nnkp, *) w90_num_exclude
611 do ii = 1, w90_num_exclude
612 read(w90_nnkp, *) itemp
613 if(itemp > sys%st%nst)
then
614 message(1) =
'oct-wannier90: The exclude_bands list contains a state index higher than the number of states.'
617 exclude_list(itemp) = .
true.
620 read(w90_nnkp, *) dummy
621 if (dummy /=
'end')
then
622 message(1) =
'oct-wannier90: There dont seem to be enough bands in exclude_bands list.'
631 w90_num_bands = sys%st%nst - w90_num_exclude
633 safe_allocate(band_index(1:sys%st%nst))
634 safe_allocate(active_bands(1:w90_num_bands))
636 do ii = 1, sys%st%nst
637 if (exclude_list(ii)) cycle
639 band_index(ii) = itemp
640 active_bands(itemp) = ii
643 if (
bitand(w90_what, option__wannier90files__w90_amn) /= 0 &
644 .or. w90_mode == option__wannier90mode__w90_wannier )
then
649 read(w90_nnkp, *, iostat=io) dummy, dummy1
650 if (io == iostat_end)
then
651 message(1) =
'oct-wannier90: Did not find projections block in w90.nnkp file'
655 if (dummy ==
'begin' .and. (dummy1 ==
'projections' .or. dummy1 ==
'spinor_projections'))
then
657 if (dummy1 ==
'spinor_projections')
then
659 if (sys%st%d%ispin /=
spinors)
then
660 message(1) =
'oct-wannier90: Spinor = .true. is only valid with spinors wavefunctions.'
664 message(1) =
'oct-wannier90: Spinor interface incomplete. Note there is no quantization axis implemented'
667 if (sys%st%d%ispin ==
spinors)
then
668 message(1) =
'oct-wannier90: Octopus has spinors wavefunctions but spinor_projections is not defined.'
669 message(2) =
'oct-wannier90: Please check the input file for wannier 90.'
674 read(w90_nnkp, *) w90_nproj
678 w90_num_wann = w90_nproj
680 if(w90_nproj == 0) w90_num_wann = w90_num_bands
682 safe_allocate(w90_proj_centers(1:3, 1:w90_nproj))
683 safe_allocate(w90_proj_lmr(1:w90_nproj, 1:3))
684 if (w90_spinors)
then
685 safe_allocate(w90_spin_proj_component(1:w90_nproj))
687 if (w90_spinors)
then
688 safe_allocate(w90_spin_proj_axis(1:w90_nproj, 1:3))
692 read(w90_nnkp, *) w90_proj_centers(1:3, ii), w90_proj_lmr(ii, 1:3)
694 read(w90_nnkp, *) dummyr(1:7)
695 if (w90_spinors)
then
696 read(w90_nnkp, *) w90_spin_proj_component(ii), w90_spin_proj_axis(ii, 1:3)
698 if (w90_spin_proj_component(ii) == -1) w90_spin_proj_component(ii) = 2
702 read(w90_nnkp, *) dummy
703 if (dummy /=
'end')
then
704 message(1) =
'oct-wannier90: There dont seem to be enough projections in nnkpts file to.'
714 read(w90_nnkp, *, iostat=io) dummy, dummy1
715 if (io == iostat_end)
exit
717 if (dummy ==
'begin' .and. dummy1 ==
'auto_projections')
then
719 read(w90_nnkp, *) w90_num_wann
721 if (.not. w90_scdm)
then
722 message(1) =
'oct-wannier90: Found auto_projections block. Currently the only implemented automatic way'
723 message(2) =
'oct-wannier90: to compute projections is the SCDM method.'
724 message(3) =
'oct-wannier90: Please set Wannier90UseSCDM = yes in the inp file.'
728 read(w90_nnkp, *) dummyint
729 if (dummyint /= 0)
then
730 message(1) =
'oct-wannier90: The second row in auto_projections has to be 0, per Wannier90 documentation.'
734 if (w90_num_wann <= 0)
then
735 message(1) =
'oct-wannier90: num_wann must be larger than 0 when using auto_projections.'
738 if (w90_num_wann > w90_num_bands)
then
739 message(1) =
'oct-wannier90: num_wann cannot be larger than num_bands when using auto_projections.'
748 message(1) =
"oct-wannier90: Finished parsing "//filename
753 filename = trim(adjustl(w90_prefix)) //
'.win'
754 message(1) =
"oct-wannier90: Parsing "//filename
758 read(w90_nnkp, fmt=
'(a)', iostat=io) line
759 if (io == iostat_end)
exit
760 if (index(line,
'=') > 0)
then
761 read(line, *, iostat=io) dummy, dummy2, dummy1
763 read(line, *, iostat=io) dummy, dummy1
766 if (dummy ==
'dis_win_min')
then
767 if (index(line,
'=') > 0)
then
768 read(line, *, iostat=io) dummy, dummy2, dis_win_min_ev
770 read(line, *, iostat=io) dummy, dis_win_min_ev
772 if (io == 0) w90_have_dis_win_min = .
true.
775 if (dummy ==
'dis_win_max')
then
776 if (index(line,
'=') > 0)
then
777 read(line, *, iostat=io) dummy, dummy2, dis_win_max_ev
779 read(line, *, iostat=io) dummy, dis_win_max_ev
781 if (io == 0) w90_have_dis_win_max = .
true.
785 if (dummy ==
'spin')
then
787 message(1) =
'oct-wannier90: The variable spin is set for a non spin-polarized calculation.'
791 if (dummy1 ==
'up')
then
793 else if (dummy1 ==
'down')
then
796 message(1) =
'oct-wannier90: Error parsing the variable spin.'
799 if (spin_channel_win /= w90_spin_channel)
then
800 message(1) =
'spin polarization input from .win and Wannier90SpinChannel do not agree.'
807 if (w90_have_dis_win_min)
then
809 write(
message(1),
'(a,f12.5)')
'oct-wannier90: Parsed dis_win_min (eV) = ', dis_win_min_ev
812 if (w90_have_dis_win_max)
then
814 write(
message(1),
'(a,f12.5)')
'oct-wannier90: Parsed dis_win_max (eV) = ', dis_win_max_ev
819 write(
message(1),
'(a,i1)')
'oct-wannier90: Using spin channel ', w90_spin_channel
823 message(1) =
"oct-wannier90: Finished parsing "//filename
832 class(
mesh_t),
intent(in) :: mesh
835 integer :: ist, jst, ik, ip, w90_mmn, iknn, ib
836 real(real64) :: Gcart(3)
838 character(len=80) :: filename
839 complex(real64),
allocatable :: overlap(:), ss(:)
840 complex(real64),
allocatable :: psin(:,:), phase(:)
842 integer :: inode, node_fr, node_to
843 type(mpi_request) :: send_req
849 if (st%parallel_in_states)
then
853 message(1) =
"Info: Computing the overlap matrix"
857 filename =
'./'// trim(adjustl(w90_prefix))//
'.mmn'
861 if (st%system_grp%is_root())
then
862 write(w90_mmn,*)
'Created by oct-wannier90'
863 write(w90_mmn,*) w90_num_bands, w90_num_kpts, w90_nntot
866 safe_allocate(psin(1:mesh%np, 1:st%d%dim))
867 safe_allocate(phase(1:mesh%np))
868 safe_allocate(overlap(1:w90_num_bands))
869 safe_allocate(ss(1:st%nst))
873 do ii = 1, w90_num_kpts * w90_nntot
874 ik = w90_nnk_list(1, ii)
875 iknn = w90_nnk_list(2, ii)
876 g(1:3) = w90_nnk_list(3:5, ii)
877 if (st%system_grp%is_root())
write(w90_mmn,
'(I10,2x,I10,2x,I3,2x,I3,2x,I3)') ik, iknn, g
882 if (sys%space%periodic_dim > 0)
then
883 g(sys%space%periodic_dim+1:sys%space%dim) = 0
887 ik = sys%st%d%get_k_spin_index(ik, w90_spin_channel)
888 iknn = sys%st%d%get_k_spin_index(iknn, w90_spin_channel)
891 if(ik >= st%d%kpt%start .and. ik <= st%d%kpt%end)
then
900 if (any(g /= 0))
then
903 phase(ip) =
exp(-
m_zi*dot_product(mesh%x(1:3, ip), gcart(1:3)))
912 if (exclude_list(jst)) cycle
915 if ( .not. st%d%kpt%parallel .and. .not. st%parallel_in_states)
then
920 do inode = 0, st%d%kpt%mpi_grp%size-1
921 if(iknn >= st%st_kpt_task(inode,3) .and. iknn <= st%st_kpt_task(inode,4))
then
924 if(ik >= st%st_kpt_task(inode,3) .and. ik <= st%st_kpt_task(inode,4))
then
931 send_req = mpi_request_null
936 if(node_to /= st%d%kpt%mpi_grp%rank)
then
937 call st%d%kpt%mpi_grp%isend(psin, mesh%np*st%d%dim, mpi_double_complex, node_to, send_req)
941 if(node_to == st%d%kpt%mpi_grp%rank .and. node_to /= node_fr)
then
942 call st%d%kpt%mpi_grp%recv(psin, mesh%np*st%d%dim, mpi_double_complex, node_fr)
944 if (send_req /= mpi_request_null)
then
945 call st%d%kpt%mpi_grp%wait(send_req)
951 if(ik >= st%d%kpt%start .and. ik <= st%d%kpt%end)
then
954 if (any(g /= 0))
then
957 do idim = 1, st%d%dim
960 psin(ip, idim) = psin(ip, idim) * phase(ip)
969 do ib = st%group%block_start, st%group%block_end
970 batch => st%group%psib(ib, ik)
971 if (all(exclude_list(batch%ist(1:batch%nst)))) cycle
973 do ist = 1, batch%nst
974 if (exclude_list(batch%ist(ist))) cycle
975 overlap(band_index(batch%ist(ist))) = ss(ist)
981 call mesh%allreduce(overlap)
984 if(st%d%kpt%parallel)
then
989 if (st%system_grp%is_root())
then
991 if (exclude_list(ist)) cycle
992 write(w90_mmn,
'(e18.10,2x,e18.10)') overlap(band_index(ist))
1001 safe_deallocate_a(psin)
1002 safe_deallocate_a(phase)
1003 safe_deallocate_a(overlap)
1004 safe_deallocate_a(ss)
1014 integer :: ist, ik, w90_eig
1015 character(len=80) :: filename
1019 if (sys%st%parallel_in_states)
then
1023 if (sys%st%system_grp%is_root())
then
1024 filename =
'./'//trim(adjustl(w90_prefix))//
'.eig'
1026 do ik = 1, w90_num_kpts
1027 do ist = 1, sys%st%nst
1028 if (exclude_list(ist)) cycle
1030 write(w90_eig,
'(I5,2x,I8,2x,e18.10)') band_index(ist), ik, &
1033 write(w90_eig,
'(I5,2x,I8,2x,e18.10)') band_index(ist), ik, &
1046 subroutine write_unk(space, mesh, st, formatted)
1047 class(
space_t),
intent(in) :: space
1048 class(
mesh_t),
intent(in) :: mesh
1050 logical,
intent(in) :: formatted
1052 integer :: ist, ik, unk_file, ispin
1053 integer :: ix, iy, iz
1054 real(real64) :: w_real, w_imag
1055 character(len=80) :: filename
1056 complex(real64),
allocatable :: psi(:)
1062 if (st%d%kpt%parallel)
then
1066 if (sys%gr%parallel_in_domains)
then
1070 if (st%parallel_in_states)
then
1077 safe_allocate(psi(1:mesh%np))
1080 mesh%coord_system, need_partition=.not.mesh%parallel_in_domains)
1084 assert(cf%batch_size == 1)
1086 do ikpoint = 1, w90_num_kpts
1088 do ispin = 1, st%d%dim
1089 if (st%system_grp%is_root())
then
1090 write(filename,
'(a,i5.5,a1,i1)')
'./UNK', ikpoint,
'.', ispin
1094 write(unk_file, *) mesh%idx%ll(1:mesh%idx%dim), ikpoint, w90_num_bands
1097 write(unk_file) mesh%idx%ll(1:mesh%idx%dim), ikpoint, w90_num_bands
1103 if (exclude_list(ist)) cycle
1105 ik = st%d%get_k_spin_index(ikpoint, w90_spin_channel)
1110 assert(.not. cube%parallel_in_domains)
1113 if (st%system_grp%is_root())
then
1115 do iz=1,cube%rs_n_global(3)
1116 do iy = 1,cube%rs_n_global(2)
1117 do ix = 1,cube%rs_n_global(1)
1118 w_real = real(cf%zrs(ix,iy,iz,1), real64)
1119 w_imag = aimag(cf%zrs(ix,iy,iz,1))
1120 write (unk_file, *) w_real, w_imag
1125 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))
1129 if (st%system_grp%is_root())
call io_close(unk_file)
1136 safe_deallocate_a(psi)
1144 class(
space_t),
intent(in) :: space
1145 class(
mesh_t),
intent(in) :: mesh
1150 integer :: ist, ik, w90_amn, idim, iw, ip, igamma
1151 real(real64) :: center(3), kpoint(3), threshold
1152 character(len=80) :: filename
1153 complex(real64),
allocatable :: psi(:,:), psi_global(:,:), phase(:), projection(:)
1154 real(real64),
allocatable :: ylm(:)
1157 integer :: tag, root_rank
1162 if (st%parallel_in_states)
then
1166 filename =
'./'// trim(adjustl(w90_prefix))//
'.amn'
1170 if (st%system_grp%is_root())
then
1171 write(w90_amn,*)
'Created by oct-wannier90'
1172 write(w90_amn,*) w90_num_bands, w90_num_kpts, w90_num_wann
1177 safe_allocate(jpvt(1:sys%gr%np_global*sys%st%d%dim))
1178 safe_allocate(psi(1:sys%gr%np, 1:sys%st%d%dim))
1179 safe_allocate(psi_global(1:sys%gr%np_global, 1:sys%st%d%dim))
1180 safe_allocate(x_global(1:sys%gr%np_global, 1:3))
1181 safe_allocate(occ_temp(1:sys%st%nst))
1182 safe_allocate(occ_smeared(1:w90_num_bands,1:w90_num_kpts))
1185 if (sys%st%system_grp%is_root())
then
1186 root_rank = sys%st%system_grp%rank
1191 w90_spin_channel, w90_scdm_entanglement, scdm_mu, scdm_sigma, occ_smeared)
1196 do ikpoint = 1, w90_num_kpts
1202 if (igamma == 0)
then
1208 do ist = 1, sys%st%nst
1209 occ_temp(ist)= sys%st%occ(ist, igamma)
1210 if (exclude_list(ist))
then
1211 sys%st%occ(ist, igamma)=
m_zero
1213 sys%st%occ(ist, igamma)=occ_smeared(band_index(ist), igamma)
1221 do ist = 1, sys%st%nst
1222 sys%st%occ(ist, igamma) = occ_temp(ist)
1225 safe_allocate(uk(1:w90_num_bands, 1:w90_num_wann, 1:w90_num_kpts))
1228 safe_allocate(chi(1:w90_num_bands, 1:w90_num_wann))
1229 safe_allocate(chi_diag(1:w90_num_wann, 1:w90_num_wann))
1230 safe_allocate(chi2(1:w90_num_wann, 1:w90_num_wann))
1231 safe_allocate(chi_eigenval(1:w90_num_wann))
1233 chi(1:w90_num_bands, 1:w90_num_wann) =
m_zero
1241 do ikpoint = 1, w90_num_kpts
1242 kvec(:) = sys%kpoints%reduced%point(:, ikpoint)
1243 ik = sys%st%d%get_k_spin_index(ikpoint, w90_spin_channel)
1244 do ist = 1, w90_num_bands
1248 do idim = 1, sys%st%d%dim
1251 sender = sys%st%d%kpt%mpi_grp%rank
1255 call sys%st%d%kpt%mpi_grp%allreduce_inplace(sender, 1, mpi_integer, mpi_max)
1258 tag = (idim - 1)*
size(active_bands) + ii
1259 if (sender /= root_rank)
then
1260 if (sys%st%system_grp%rank == sender)
then
1261 do idim = 1, sys%st%d%dim
1262 call sys%st%system_grp%send(psi_global(:,idim),
i8_to_i4(sys%gr%np_global), mpi_double_complex, root_rank, tag=tag)
1265 if (sys%st%system_grp%is_root())
then
1266 do idim = 1, sys%st%d%dim
1267 call sys%st%system_grp%recv(psi_global(:,idim),
i8_to_i4(sys%gr%np_global), mpi_double_complex, sender, tag=tag)
1271 if (sys%st%system_grp%is_root())
then
1272 do jst = 1, w90_num_wann
1273 chi(ist, jst) = occ_smeared(ist, ik) * conjg(psi_global(jpvt(jst), 1)) &
1274 *
exp(
m_zi * dot_product(x_global(jpvt(jst),1:3), kvec(1:3)))
1279 if (sys%st%system_grp%is_root())
then
1282 chi_diag = matmul(conjg(transpose(chi)), chi)
1284 chi2 = conjg(transpose(chi_diag))
1287 if (any(chi_eigenval(:) .lt.
m_zero))
then
1288 message(1) =
'SCDM Wannierization failed because chi matrix is'
1289 message(2) =
'ill conditioned. Try changing scdm_sigma and/or'
1294 do ist = 1, w90_num_wann
1295 chi_eigenval(ist) =
m_one /
sqrt(chi_eigenval(ist))
1296 chi2(ist, 1:w90_num_wann) = chi_eigenval(ist) * chi2(ist, 1:w90_num_wann)
1300 uk(:,:,ik) = matmul(chi, matmul(chi_diag,chi2))
1305 safe_deallocate_a(chi)
1306 safe_deallocate_a(psi)
1307 safe_deallocate_a(psi_global)
1308 safe_deallocate_a(x_global)
1309 safe_deallocate_a(chi_diag)
1310 safe_deallocate_a(chi2)
1311 safe_deallocate_a(chi_eigenval)
1312 safe_deallocate_a(jpvt)
1313 safe_deallocate_a(occ_temp)
1314 safe_deallocate_a(occ_smeared)
1316 message(1) =
"Info: Writing projections obtained from SCDM."
1319 do ik = 1, w90_num_kpts
1321 if (exclude_list(ist)) cycle
1322 if (st%system_grp%is_root())
then
1323 do iw = 1, w90_num_wann
1324 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)
1330 safe_deallocate_a(uk)
1334 message(1) =
"Info: Computing the projection matrix"
1340 safe_allocate(orbitals(1:w90_nproj))
1345 orbitals(iw)%norbs = 1
1346 orbitals(iw)%ndim = 1
1347 orbitals(iw)%radius = -
log(threshold)
1348 orbitals(iw)%use_submesh = .false.
1351 center(1:3) = latt%red_to_cart(w90_proj_centers(1:3, iw))
1352 call submesh_init(orbitals(iw)%sphere, space, mesh, latt, center, orbitals(iw)%radius)
1355 safe_allocate(ylm(1:orbitals(iw)%sphere%np))
1357 call ylm_wannier(ylm, w90_proj_lmr(iw,1), w90_proj_lmr(iw,2), &
1358 orbitals(iw)%sphere%r, orbitals(iw)%sphere%rel_x, orbitals(iw)%sphere%np)
1361 if (w90_proj_lmr(iw,3) == 1)
then
1362 do ip = 1,orbitals(iw)%sphere%np
1363 ylm(ip) = ylm(ip)*
m_two*
exp(-orbitals(iw)%sphere%r(ip))
1369 safe_allocate(orbitals(iw)%zorb(1:orbitals(iw)%sphere%np, 1, 1))
1370 orbitals(iw)%zorb(1:orbitals(iw)%sphere%np, 1, 1) = ylm(1:orbitals(iw)%sphere%np)
1371 safe_deallocate_a(ylm)
1373 safe_allocate(orbitals(iw)%phase(1:orbitals(iw)%sphere%np, st%d%kpt%start:st%d%kpt%end))
1374 orbitals(iw)%phase(:,:) =
m_z0
1375 safe_allocate(orbitals(iw)%eorb_mesh(1:mesh%np, 1, 1, st%d%kpt%start:st%d%kpt%end))
1376 orbitals(iw)%eorb_mesh(:,:,:,:) =
m_z0
1379 kpt_max = w90_num_kpts)
1383 safe_allocate(psi(1:mesh%np, 1:st%d%dim))
1384 safe_allocate(phase(1:mesh%np))
1385 safe_allocate(projection(1:w90_nproj))
1387 do ikpoint = 1, w90_num_kpts
1388 kpoint(1:space%dim) = kpoints%get_point(ikpoint)
1391 phase(ip) =
exp(-
m_zi* sum(mesh%x(1:space%dim, ip) * kpoint(1:space%dim)))
1395 ik = sys%st%d%get_k_spin_index(ikpoint, w90_spin_channel)
1398 if (exclude_list(ist)) cycle
1402 if(ik >= st%d%kpt%start .and. ik <= st%d%kpt%end)
then
1406 do idim = 1, st%d%dim
1410 psi(ip, idim) = psi(ip, idim)*phase(ip)
1415 do iw = 1, w90_nproj
1417 if (w90_spinors) idim = w90_spin_proj_component(iw)
1421 projection(iw) =
zmf_dotp(mesh, psi(1:mesh%np,idim), &
1422 orbitals(iw)%eorb_mesh(1:mesh%np,1,1,ik), reduce = .false.)
1426 call mesh%allreduce(projection)
1430 if(st%d%kpt%parallel)
then
1434 if (st%system_grp%is_root())
then
1435 do iw = 1, w90_nproj
1436 write (w90_amn,
'(I5,2x,I5,2x,I5,2x,e18.10,2x,e18.10)') band_index(ist), iw, ikpoint, projection(iw)
1442 safe_deallocate_a(psi)
1443 safe_deallocate_a(phase)
1444 safe_deallocate_a(projection)
1446 do iw = 1, w90_nproj
1449 safe_deallocate_a(orbitals)
1465 class(
mesh_t),
intent(in) :: mesh
1468 integer :: ist, jst, ik, w90_spn, counter
1469 character(len=80) :: filename
1470 complex(real64),
allocatable :: spin(:,:,:)
1471 complex(real64),
allocatable :: psim(:,:), psin(:,:)
1472 complex(real64) :: dot_upup, dot_updown, dot_downup, dot_downdown
1479 if (st%parallel_in_states)
then
1483 message(1) =
"Info: Computing the spin file"
1486 filename =
'./'// trim(adjustl(w90_prefix))//
'.spn'
1490 if (st%system_grp%is_root())
then
1491 write(w90_spn,*)
'Created by oct-wannier90'
1492 write(w90_spn,*) w90_num_bands, w90_num_kpts
1495 safe_allocate(psim(1:mesh%np, 1:st%d%dim))
1496 safe_allocate(psin(1:mesh%np, 1:st%d%dim))
1497 safe_allocate(spin(1:3, 1:(w90_num_bands*(w90_num_bands+1))/2, 1:w90_num_kpts))
1501 do ik = st%d%kpt%start, st%d%kpt%end
1504 if (exclude_list(jst)) cycle
1508 if (exclude_list(ist)) cycle
1510 counter = counter + 1
1514 dot_upup =
zmf_dotp(mesh, psin(:, 1), psim(:, 1), reduce = .false.)
1515 dot_downdown =
zmf_dotp(mesh, psin(:, 2), psim(:, 2), reduce = .false.)
1516 dot_updown =
zmf_dotp(mesh, psin(:, 1), psim(:, 2), reduce = .false.)
1517 dot_downup =
zmf_dotp(mesh, psin(:, 2), psim(:, 1), reduce = .false.)
1519 spin(1, counter, ik) = dot_updown + dot_downup
1520 spin(2, counter, ik) = -
m_zi * dot_updown +
m_zi * dot_downup
1521 spin(3, counter, ik) = dot_upup - dot_downdown
1527 call mesh%allreduce(spin)
1529 if(st%d%kpt%parallel)
then
1535 if (st%system_grp%is_root())
then
1536 do ik = 1, w90_num_kpts
1539 if (exclude_list(jst)) cycle
1542 if (exclude_list(ist)) cycle
1544 counter = counter + 1
1545 write(w90_spn,
'(e18.10,2x,e18.10)') spin(1, counter, ik)
1546 write(w90_spn,
'(e18.10,2x,e18.10)') spin(2, counter, ik)
1547 write(w90_spn,
'(e18.10,2x,e18.10)') spin(3, counter, ik)
1555 safe_deallocate_a(psim)
1556 safe_deallocate_a(psin)
1557 safe_deallocate_a(spin)
1567 class(
space_t),
intent(in) :: space
1568 class(
mesh_t),
intent(in) :: mesh
1569 type(
ions_t),
intent(in) :: ions
1573 integer :: w90_u_mat, w90_u_dis, w90_xyz, nwann, nik, nib
1574 integer :: ik, iw, iw2, ip, ipmax, rankmax, idmmax, ib
1575 real(real64),
allocatable :: centers(:,:), supercell_centers(:,:), new_centers(:,:)
1576 complex(real64),
allocatable :: Umnk(:,:,:), Umat(:,:,:), Udis(:,:,:)
1577 complex(real64),
allocatable :: zwn(:,:,:), psi(:,:), phase(:,:), phase_bloch(:), zwn_bloch(:,:,:)
1578 character(len=MAX_PATH_LEN) :: fname
1579 real(real64) :: kpoint(3), wmod, wmodmax, xx(space%dim)
1580 character(len=2) :: dum
1581 logical :: exist, have_disentangled
1583 complex(real64) :: scal
1585 integer :: supercell(space%dim), ii, jj, kk, ncols, Nreplica, irep, irepmax
1586 real(real64) :: min_image_displ(3), offset(space%dim)
1587 integer :: jw, ib_orig, nactive, j, nfixed
1588 integer,
allocatable :: parent(:)
1589 real(real64),
parameter :: tol_cluster = 0.25_real64
1591 integer,
allocatable :: active_rows(:)
1592 complex(real64),
allocatable :: uwork(:,:)
1593 logical :: in_window
1598 message(1) =
"oct-wannier90: Constructing the Wannier states from the U matrix."
1601 inquire(file=trim(trim(adjustl(w90_prefix))//
'_centres.xyz'),exist=exist)
1602 if (.not. exist)
then
1603 message(1) =
'oct-wannier90: Cannot find the Wannier90 file seedname_centres.xyz.'
1604 write(
message(2),
'(a)')
'Please run wannier90.x with "write_xyz=.true." in '// trim(adjustl(w90_prefix)) //
'.'
1610 safe_allocate(centers(1:3, 1:w90_num_wann))
1614 do iw = 1, w90_num_wann
1615 read(w90_xyz, *) dum, centers(1:3, iw)
1623 safe_allocate(parent(1:w90_num_wann))
1624 do iw = 1, w90_num_wann
1627 min_image_displ(:) = ions%latt%cart_to_red(centers(:, iw) - centers(:, jw))
1628 min_image_displ(1:space%periodic_dim) = min_image_displ(1:space%periodic_dim) - nint(min_image_displ(1:space%periodic_dim))
1629 min_image_displ = ions%latt%red_to_cart(min_image_displ)
1630 if (norm2(min_image_displ) < tol_cluster)
then
1631 parent(iw) = parent(jw)
1637 message(1) =
"Info : Clustering of the Wannier centers"
1640 safe_allocate(new_centers(1:3, 1:w90_num_wann))
1641 do iw = 1, w90_num_wann
1642 write(
message(1),
'(a,i0,a,3(f7.3,a))')
'Info : Original Wannier center ', &
1643 iw,
' (', centers(1, iw),
', ', centers(2, iw),
', ', centers(3, iw),
')'
1645 if (parent(iw) == iw)
then
1647 new_centers(1:3, iw) = ions%latt%fold_into_cell(centers(1:3, iw))
1651 min_image_displ(:) = ions%latt%cart_to_red(centers(:, iw) - new_centers(:, parent(iw)))
1652 min_image_displ(1:space%periodic_dim) = real(nint(min_image_displ(1:space%periodic_dim)), real64)
1653 min_image_displ = ions%latt%red_to_cart(min_image_displ)
1654 new_centers(1:3, iw) = centers(1:3, iw) - min_image_displ
1657 write(
message(2),
'(a,i0,a,3(f7.3,a))')
'Info : New Wannier center ', &
1658 iw,
' (', new_centers(1, iw),
', ', new_centers(2, iw),
', ', new_centers(3, iw),
')'
1664 centers = new_centers - centers
1665 safe_deallocate_a(parent)
1666 safe_deallocate_a(new_centers)
1668 inquire(file=trim(trim(adjustl(w90_prefix))//
'_u.mat'),exist=exist)
1669 if (.not. exist)
then
1670 message(1) =
'oct-wannier90: Cannot find the Wannier90 seedname_u.mat file.'
1671 write(
message(2),
'(a)')
'Please run wannier90.x with "write_u_matrices=.true." in '// trim(adjustl(w90_prefix)) //
'.'
1679 read(w90_u_mat, *) nik, nwann, nwann
1680 if (nik /= w90_num_kpts .or. nwann /= w90_num_wann)
then
1681 message(1) =
"The file contains U matrices is inconsistent with the .win file."
1686 safe_allocate(umat(1:w90_num_wann, 1:w90_num_wann, 1:w90_num_kpts))
1688 do ik = 1, w90_num_kpts
1693 read(w90_u_mat,
'(f15.10,sp,f15.10)') ((umat(iw, iw2, ik), iw=1, w90_num_wann), iw2=1, w90_num_wann)
1698 inquire(file=trim(trim(adjustl(w90_prefix))//
'_u_dis.mat'),exist=have_disentangled)
1699 if (have_disentangled)
then
1700 message(1) =
'oct-wannier90: Found u_dis.mat, will include disentanglement in Wannier state construction.'
1710 read(w90_u_dis, *) nik, nwann, nib
1711 if (nik /= w90_num_kpts .or. nwann /= w90_num_wann .or. nib /= w90_num_bands)
then
1712 message(1) =
'oct-wannier90: The u_dis.mat file is inconsistent with the .win/.nnkp files.'
1716 safe_allocate(udis(1:w90_num_bands, 1:w90_num_wann, 1:w90_num_kpts))
1717 do ik = 1, w90_num_kpts
1722 read(w90_u_dis,
'(f15.10,sp,f15.10)') ((udis(ib, iw, ik), ib=1, w90_num_bands), iw=1, w90_num_wann)
1729 if (w90_have_dis_win_min .or. w90_have_dis_win_max)
then
1730 safe_allocate(active_rows(1:w90_num_bands))
1731 safe_allocate(uwork(1:w90_num_bands, 1:w90_num_wann))
1734 do ikpoint = 1, w90_num_kpts
1735 ik = st%d%get_k_spin_index(ikpoint, w90_spin_channel)
1737 do ib_orig = 1, st%nst
1738 if (exclude_list(ib_orig)) cycle
1740 if (w90_have_dis_win_min) in_window = in_window .and. st%eigenval(ib_orig, ik) >= w90_dis_win_min
1741 if (w90_have_dis_win_max) in_window = in_window .and. st%eigenval(ib_orig, ik) <= w90_dis_win_max
1743 nactive = nactive + 1
1744 active_rows(nactive) = band_index(ib_orig)
1748 if (nactive > 0)
then
1751 uwork(active_rows(j), 1:w90_num_wann) = udis(j, 1:w90_num_wann, ikpoint)
1753 udis(1:w90_num_bands, 1:w90_num_wann, ikpoint) = uwork(1:w90_num_bands, 1:w90_num_wann)
1758 if (nfixed > 0)
then
1759 write(
message(1),
'(a,i0,a)')
'oct-wannier90: remapped legacy u_dis row layout for ', nfixed,
' k-points.'
1763 safe_deallocate_a(active_rows)
1764 safe_deallocate_a(uwork)
1766 message(1) =
'oct-wannier90: dis_win_min/dis_win_max not found in .win; skipping legacy u_dis remap.'
1772 safe_allocate(umnk(1:w90_num_bands, 1:w90_num_wann, 1:w90_num_kpts))
1774 do ik = 1, w90_num_kpts
1775 umnk(:, :, ik) = umnk(:, :, ik) + matmul(udis(:, :, ik), umat(:, :, ik))
1777 safe_deallocate_a(udis)
1780 safe_allocate(umnk(1:w90_num_wann, 1:w90_num_wann, 1:w90_num_kpts))
1783 safe_deallocate_a(umat)
1788 message(1) =
"OutputFormat must be specified for outputing Wannier functions."
1800 if (
parse_block(sys%namespace,
'Wannier90Supercell', blk) == 0)
then
1802 if (ncols /= space%dim)
then
1803 write(
message(1),
'(a,i3,a,i3)')
'Wannier90Supercell has ', ncols,
' columns but must have ', sys%space%dim
1806 do ii = 1, space%dim
1816 nreplica = product(supercell)
1819 safe_allocate(supercell_centers(1:space%dim, 1:nreplica))
1820 offset(1:space%dim) = -
floor((real(supercell(1:space%dim), real64) -
m_one) /
m_two)
1822 do ii = 0, supercell(1)-1
1823 do jj = 0, supercell(2)-1
1824 do kk = 0, supercell(3)-1
1825 supercell_centers(:, irep) = ions%latt%red_to_cart(offset &
1826 + [real(ii, real64), real(jj, real64), real(kk, real64)])
1837 safe_allocate(zwn(1:mesh%np, 1:nreplica, 1:st%d%dim))
1838 safe_allocate(psi(1:mesh%np, 1:st%d%dim))
1839 safe_allocate(phase(1:mesh%np, 1:nreplica))
1840 safe_allocate(phase_bloch(1:mesh%np))
1841 if (w90_bloch_sums)
then
1842 safe_allocate(zwn_bloch(1:mesh%np, 1:st%d%dim, st%d%kpt%start:st%d%kpt%end))
1845 do iw = 1, w90_num_wann
1849 do ik = 1, w90_num_kpts
1851 if (.not. (ik >= st%d%kpt%start .and. ik <= st%d%kpt%end)) cycle
1853 if (w90_bloch_sums) zwn_bloch(:,:,ik) =
m_z0
1855 kpoint(1:space%dim) = kpoints%get_point(ik, absolute_coordinates=.
true.)
1859 do irep = 1, nreplica
1862 xx = mesh%x(1:space%dim, ip)-centers(1:space%dim, iw) + supercell_centers(1:space%dim, irep)
1863 phase(ip, irep) =
exp(-
m_zi* sum( xx * kpoint(1:space%dim)))
1866 if (w90_bloch_sums)
then
1868 xx = mesh%x(1:space%dim, ip)
1869 phase_bloch(ip) =
exp(-
m_zi* sum( xx * kpoint(1:space%dim)))
1874 if (exclude_list(iw2)) cycle
1883 do idim = 1, st%d%dim
1884 do irep = 1, nreplica
1887 zwn(ip, irep, idim) = zwn(ip, irep, idim) + umnk(band_index(iw2), iw, ik) * psi(ip, idim) * phase(ip, irep)
1894 if (w90_bloch_sums)
then
1896 do idim = 1, st%d%dim
1899 zwn_bloch(ip, idim, ik) = zwn_bloch(ip, idim, ik) &
1900 + umnk(band_index(iw2), iw, ik) * psi(ip, idim) * phase_bloch(ip)
1908 if(st%d%kpt%parallel)
then
1909 call comm_allreduce(st%d%kpt%mpi_grp, zwn)
1914 if (sys%st%d%ispin /= spinors)
then
1918 do irep = 1, nreplica
1920 wmod = real(zwn(ip, irep, 1)*conjg(zwn(ip, irep, 1)), real64)
1921 if (wmod > wmodmax)
then
1928 scal =
sqrt(wmodmax)/zwn(ipmax, irepmax, 1)/w90_num_kpts
1929 call mesh_minmaxloc(mesh, wmodmax, rankmax, mpi_maxloc)
1930 call mesh%mpi_grp%bcast(scal, 1, mpi_double_complex, rankmax)
1931 call lalg_scal(mesh%np, nreplica, scal, zwn(:,:,1))
1933 if (w90_bloch_sums)
then
1934 do ik = st%d%kpt%start, st%d%kpt%end
1938 do idim = 1, st%d%dim
1940 wmod = real(zwn_bloch(ip, idim, ik)*conjg(zwn_bloch(ip, idim, ik)), real64)
1941 if (wmod > wmodmax)
then
1948 scal =
sqrt(wmodmax)/zwn_bloch(ipmax, idmmax, ik)/w90_num_kpts
1949 call mesh_minmaxloc(mesh, wmodmax, rankmax, mpi_maxloc)
1950 call mesh%mpi_grp%bcast(scal, 1, mpi_double_complex, rankmax)
1951 call lalg_scal(mesh%np, st%d%dim, scal, zwn_bloch(:,:,ik))
1957 fn_unit =
sqrt(units_out%length**(-space%dim))
1958 do idim = 1, st%d%dim
1959 if (st%d%ispin == spinors)
then
1960 write(fname,
'(a,i3.3,a4,i1)')
'wannier-', iw,
'-isp', idim
1962 write(fname,
'(a,i3.3,a4,i1)')
'wannier-', iw
1964 if (any(supercell_centers > 1))
then
1965 if (mesh%parallel_in_domains)
then
1966 call messages_not_implemented(
"w90 generate supercell larger than 1x1x1 with domain parallelization")
1968 call io_function_output_supercell(how,
"wannier", trim(fname), mesh, &
1969 space, ions%latt, zwn(:, :, idim), supercell_centers, supercell, fn_unit, ierr, global_namespace, &
1970 pos=ions%pos, atoms=ions%atom, grp = st%dom_st_kpt_mpi_grp)
1972 call zio_function_output(how,
"wannier", trim(fname), global_namespace, space, mesh, &
1973 zwn(:, 1, idim), fn_unit, ierr, pos=ions%pos, atoms=ions%atom, grp = st%dom_st_kpt_mpi_grp)
1978 if (w90_bloch_sums)
then
1979 do ik = st%d%kpt%start, st%d%kpt%end
1980 do idim = 1, st%d%dim
1981 if (st%d%ispin == spinors)
then
1982 write(fname,
'(a,i3.3,a4,i1,a3,i5.5)')
'wannier_bloch-', iw,
'-isp', idim,
'-ik', ik
1984 write(fname,
'(a,i3.3,a4,i1,a3,i5.5)')
'wannier_bloch-', iw,
'-ik', ik
1986 call zio_function_output(how,
"wannier", trim(fname), global_namespace, space, mesh, &
1987 zwn_bloch(:, idim, ik), fn_unit, ierr, pos=ions%pos, atoms=ions%atom)
1993 if (sys%st%d%ispin /= spinors)
then
1995 do irep = 1, nreplica
1997 if(abs(real(zwn(ip, irep, 1), real64)) >= 1e-2_real64)
then
1998 wmodmax = max(wmodmax, abs(aimag(zwn(ip, irep, 1)))/abs(real(zwn(ip, irep, 1), real64)))
2002 call mesh_minmaxloc(mesh, wmodmax, rankmax, mpi_maxloc)
2004 write(message(1),
'(a,i4,a,f11.6)')
'oct-wannier90: Wannier function ', iw,
' Max. Im/Re Ratio = ', wmodmax
2005 call messages_info(1)
2007 write(message(1),
'(a,i4)')
'oct-wannier90: Wannier function done ', iw
2008 call messages_info(1)
2012 safe_deallocate_a(umnk)
2013 safe_deallocate_a(zwn)
2014 safe_deallocate_a(psi)
2015 safe_deallocate_a(phase)
2016 safe_deallocate_a(phase_bloch)
2017 safe_deallocate_a(centers)
2018 safe_deallocate_a(supercell_centers)
2019 safe_deallocate_a(umat)
2020 safe_deallocate_a(udis)
2026 type(states_elec_t),
intent(in) :: st
2027 integer,
contiguous,
intent(in) :: act_bands(:)
2028 integer,
intent(in) :: num_kpts, num_bands
2029 integer,
intent(in) :: spin_channel
2030 integer,
intent(in) :: scdm_entanglement
2031 real(real64),
intent(in) :: mu, sigma
2032 real(real64),
contiguous,
intent(out) :: smeared(:,:)
2034 integer :: ik, ist, ikpoint
2036 select case (scdm_entanglement)
2037 case (option__scdmentanglement__scdm_isolated)
2038 do ikpoint = 1, num_kpts
2039 ik = st%d%get_k_spin_index(ikpoint, spin_channel)
2040 smeared(:, ikpoint) = m_zero
2041 do ist = 1, num_bands
2042 if (st%eigenval(act_bands(ist), ik) .le. mu)
then
2043 smeared(ist, ikpoint)=m_one
2048 case (option__scdmentanglement__scdm_erfc)
2049 do ikpoint = 1, num_kpts
2050 ik = st%d%get_k_spin_index(ikpoint, spin_channel)
2051 do ist = 1, num_bands
2052 smeared(ist, ikpoint)=m_half*erfc((st%eigenval(act_bands(ist), ik)-mu) / sigma)
2056 case (option__scdmentanglement__scdm_gaussian)
2057 do ikpoint = 1, num_kpts
2058 ik = st%d%get_k_spin_index(ikpoint, spin_channel)
2059 do ist = 1, num_bands
2060 smeared(ist, ikpoint)=
exp(-(st%eigenval(act_bands(ist), ik)-mu)**2 / sigma**2)
2065 message(1) =
"SCDMEntanglement is set to an unsupported value."
2066 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
This module provides an interface to the getopt C library, so that the command line arguments can be ...
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, nthreads, single)
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()
subroutine, public io_mkdir(fname, namespace, parents)
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.
integer function, public parse_block(namespace, name, blk, check_varinfo_)
/* To use the profiling module, call profiling_in and profiling_out with the label of the region as a...
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 wannier90_interface_main()
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_amn(space, mesh, latt, st, kpoints)
subroutine create_wannier90_spn(mesh, st)
Write the spn file containing .
subroutine wannier90_output()
subroutine create_wannier90_mmn(mesh, st)
subroutine choose_scdm_smearing_function(st, act_bands, num_kpts, num_bands, spin_channel, scdm_entanglement, mu, sigma, smeared)
subroutine write_unk(space, mesh, st, formatted)
subroutine generate_wannier_states(space, mesh, ions, st, kpoints)
subroutine create_wannier90_eig()
subroutine wannier90_setup(ions, kpoints, space)
subroutine read_wannier90_files()