11 use,
intrinsic :: iso_fortran_env
62 real(real64) :: site(3)
63 real(real64) :: s_qaxis(3) = [0.0_real64, 0.0_real64, 1.0_real64]
64 real(real64) :: z(3) = [0.0_real64, 0.0_real64, 1.0_real64]
65 real(real64) :: x(3) = [1.0_real64, 0.0_real64, 0.0_real64]
66 real(real64) :: zona = 1.0_real64
76 type(namespace_t),
intent(in) :: namespace
77 type(multicomm_t),
intent(in) :: mc
78 class(space_t),
intent(inout) :: space
79 type(states_elec_t),
intent(inout) :: st
80 class(mesh_t),
intent(inout) :: gr
81 type(kpoints_t),
intent(inout) :: kpoints
82 integer,
optional,
intent(in) :: restart_states
85 integer :: restart_states_, ierr, nik, dim, nst
86 type(restart_t) :: restart
90 message(1) =
'Invalid restart_states value; expected RESTART_GS or RESTART_TD.'
98 write(
message(1),
'(a)')
'Error opening restart file'
104 if (dim /= st%d%dim)
then
105 write(
message(1),
'(a)')
'Restart structure not commensurate, since spin dimensions differ.'
107 else if (nik /= kpoints%reduced%npoints)
then
108 write(
message(1),
'(a)')
'Restart structure not commensurate, since number of k-points differ.'
110 else if (nst /= st%nst)
then
111 write(
message(1),
'(a)')
'Restart structure not commensurate, since number of states differ.'
115 call states_elec_load(restart, namespace, space, st, gr, kpoints, ierr, label =
": wannier90")
127 band_index, space, mesh, latt, st, kpoints, &
128 spin_channel, num_proj, proj_input, projection)
129 type(wannier_opts_t),
intent(in) :: wan_opts
130 class(space_t),
intent(in) :: space
131 class(mesh_t),
intent(in) :: mesh
132 type(lattice_vectors_t),
intent(in) :: latt
133 type(states_elec_t),
intent(in) :: st
134 type(kpoints_t),
intent(in) :: kpoints
135 logical,
intent(in) :: exclude_list(:)
136 integer,
intent(in) :: band_index(:)
137 integer,
intent(in) :: spin_channel
138 integer,
intent(in) :: num_proj
139 type(wannier_calc_proj_t),
intent(in) :: proj_input(:)
141 complex(real64),
contiguous,
intent(out) :: projection(:, :, :)
143 integer :: ist, ik, idim, iw, ip, ik_real, iband, num_kpts
144 real(real64) :: center(3), kpoint(3)
146 complex(real64),
allocatable :: psi(:,:), phase(:)
147 real(real64),
allocatable :: ylm(:)
148 type(orbitalset_t),
allocatable :: orbitals(:)
153 if (st%parallel_in_states)
then
157 message(1) =
"Info: Computing the projection matrix"
160 assert(num_proj ==
size(proj_input))
162 num_kpts = product(kpoints%nik_axis(1:3))
165 safe_allocate(orbitals(1:num_proj))
169 orbitals(iw)%norbs = 1
170 orbitals(iw)%ndim = 1
171 orbitals(iw)%radius = -
log(wan_opts%threshold)
172 orbitals(iw)%use_submesh = .false.
175 center(1:3) = latt%red_to_cart(proj_input(iw)%site(1:3))
176 call submesh_init(orbitals(iw)%sphere, space, mesh, latt, center, orbitals(iw)%radius)
179 safe_allocate(ylm(1:orbitals(iw)%sphere%np))
181 call ylm_wannier(ylm, proj_input(iw)%l, proj_input(iw)%m, &
182 orbitals(iw)%sphere%r, orbitals(iw)%sphere%rel_x, orbitals(iw)%sphere%np)
184 if (proj_input(iw)%radial /= 1)
then
189 do ip = 1, orbitals(iw)%sphere%np
190 ylm(ip) = ylm(ip) *
m_two *
exp(-orbitals(iw)%sphere%r(ip))
194 safe_allocate(orbitals(iw)%zorb(1:orbitals(iw)%sphere%np, 1:1, 1:1))
195 orbitals(iw)%zorb(1:orbitals(iw)%sphere%np, 1, 1) = ylm(1:orbitals(iw)%sphere%np)
196 safe_deallocate_a(ylm)
198 safe_allocate(orbitals(iw)%phase(1:orbitals(iw)%sphere%np, st%d%kpt%start:st%d%kpt%end))
199 orbitals(iw)%phase =
m_z0
200 safe_allocate(orbitals(iw)%eorb_mesh(1:mesh%np, 1:1, 1:1, st%d%kpt%start:st%d%kpt%end))
201 orbitals(iw)%eorb_mesh =
m_z0
208 safe_allocate(psi(1:mesh%np, 1:st%d%dim))
209 safe_allocate(phase(1:mesh%np))
213 kpoint(1:space%dim) = kpoints%get_point(ik)
215 phase(ip) =
exp(-
m_zi * sum(mesh%x(1:space%dim, ip) * kpoint(1:space%dim)))
220 ik_real = (ik-1)*2 + spin_channel
227 if (exclude_list(ist)) cycle
228 iband = band_index(ist)
230 if(ik_real >= st%d%kpt%start .and. ik_real <= st%d%kpt%end)
then
233 do idim = 1, st%d%dim
235 psi(ip, idim) = psi(ip, idim)*phase(ip)
241 if (wan_opts%spinors) idim = wan_opts%spin_proj_component(iw)
244 projection(iband, iw, ik) =
zmf_dotp(mesh, psi(1:mesh%np, idim), &
245 orbitals(iw)%eorb_mesh(1:mesh%np, 1, 1, ik_real), reduce = .false.)
249 call mesh%allreduce(projection(iband, :, ik))
253 if(st%d%kpt%parallel)
then
260 safe_deallocate_a(psi)
261 safe_deallocate_a(phase)
266 safe_deallocate_a(orbitals)
284 spin_channel, nnlist, nncell, overlap)
285 logical,
intent(in) :: exclude_list(:)
286 integer,
intent(in) :: band_index(:)
287 class(
mesh_t),
intent(in) :: mesh
289 type(
ions_t),
intent(in) :: ions
290 integer,
intent(in) :: spin_channel
291 integer,
intent(in) :: nnlist(:,:)
292 integer,
intent(in) :: nncell(:,:,:)
294 complex(real64),
contiguous,
intent(out) :: overlap(:, :, :, :)
296 integer :: ist, jst, ik, ip, iknn, idim, ibind
297 integer :: ik_oct, iknn_oct, inn
299 integer :: iband, jband, inode, node_fr, node_to
300 real(real64) :: gcart(3)
303 integer :: nntot, num_kpts
305 complex(real64),
allocatable :: psim(:,:), psin(:,:), phase(:)
307 type(mpi_request) :: send_req
314 nntot =
size(nnlist, 2)
315 num_kpts =
size(nnlist, 1)
316 assert(
size(nnlist, 1) == num_kpts)
317 assert(
size(nncell, 1) == 3)
318 assert(
size(nncell, 2) == num_kpts)
319 assert(
size(nncell, 3) == nntot)
321 if (st%parallel_in_states)
then
325 message(1) =
"Info: Computing the overlap matrix for wannerisation"
329 safe_allocate(psim(1:mesh%np, 1:st%d%dim))
330 safe_allocate(psin(1:mesh%np, 1:st%d%dim))
331 safe_allocate(phase(1:mesh%np))
333 if (st%d%kpt%parallel) ik_loc = 0
339 iknn = nnlist(ik, inn)
340 g(1:3) = nncell(:, ik, inn)
344 ik_oct = (ik-1)*2 + spin_channel
345 iknn_oct = (iknn-1)*2 + spin_channel
352 if(ik_oct >= st%d%kpt%start .and. ik_oct <= st%d%kpt%end)
then
360 if (any(g /= 0))
then
362 phase(ip) =
exp(-
m_zi*dot_product(mesh%x(1:3, ip), gcart(1:3)))
369 if (exclude_list(jst)) cycle
370 jband = band_index(jst)
372 if (st%d%kpt%parallel)
then
375 do inode = 0, st%d%kpt%mpi_grp%size-1
376 if(iknn_oct >= st%st_kpt_task(inode,3) .and. iknn_oct <= st%st_kpt_task(inode,4))
then
379 if(ik_oct >= st%st_kpt_task(inode,3) .and. ik_oct <= st%st_kpt_task(inode,4))
then
385 send_req = mpi_request_null
390 if(node_to /= st%d%kpt%mpi_grp%rank)
then
391 call st%d%kpt%mpi_grp%isend(psin, mesh%np*st%d%dim, mpi_double_complex, node_to, send_req)
395 if(node_to == st%d%kpt%mpi_grp%rank .and. node_to /= node_fr)
then
396 call st%d%kpt%mpi_grp%recv(psin, mesh%np*st%d%dim, mpi_double_complex, node_fr)
398 if (send_req /= mpi_request_null)
then
399 call st%d%kpt%mpi_grp%wait(send_req)
405 if(ik_oct >= st%d%kpt%start .and. ik_oct <= st%d%kpt%end)
then
408 if (any(g /= 0))
then
409 do idim = 1, st%d%dim
411 psin(ip, idim) = psin(ip, idim) * phase(ip)
419 if (exclude_list(ist)) cycle
420 iband = band_index(ist)
422 batch => st%group%psib(st%group%iblock(ist), ik_oct)
424 select case (batch%status())
426 overlap(iband, jband, inn, ik) =
m_z0
427 do idim = 1, st%d%dim
428 ibind = batch%inv_index((/ist, idim/))
429 overlap(iband, jband, inn, ik) = overlap(iband, jband, inn, ik) + &
430 zmf_dotp(mesh, batch%zff_linear(:, ibind), psin(:,idim), reduce = .false.)
435 overlap(iband, jband, inn, ik) =
zmf_dotp(mesh, st%d%dim, psim, psin, reduce = .false.)
441 call mesh%allreduce(overlap(:, jband, inn, ik))
444 if(st%d%kpt%parallel)
then
453 if (st%d%kpt%parallel)
then
455 ik_oct = (ik-1)*2 + spin_channel
459 if (ik_oct >= st%d%kpt%start .and. ik_oct <= st%d%kpt%end)
then
461 if (ik_loc /= ik)
then
462 overlap(:, :, :, ik_loc) = overlap(:, :, :, ik)
468 safe_deallocate_a(psim)
469 safe_deallocate_a(psin)
470 safe_deallocate_a(phase)
484 real(real64),
intent(inout) :: centers(:, :)
486 integer :: w90_xyz, iw
487 character(len=2) :: dum
492 assert(
size(centers, 2) == wan_opts%num_wann)
493 assert(
size(centers, 1) == 3)
495 inquire(file=trim(adjustl(wan_opts%prefix))//
'_centres.xyz',exist=exist)
496 if (.not. exist)
then
497 message(1) =
'Cannot find the Wannier90 file seedname_centres.xyz.'
506 do iw = 1, wan_opts%num_wann
507 read(w90_xyz, *) dum, centers(1:3, iw)
523 complex(real64),
intent(inout) :: u_matrix(:, :, :)
524 complex(real64),
intent(inout) :: u_dis_matrix(:, :, :)
526 integer :: w90_u_mat, w90_u_dis, ik, ib, iw, iw2, nik, nwann, nib
528 logical :: exist, have_disentangled
530 num_kpts = product(kpoints%nik_axis(1:3))
534 inquire(file=trim(adjustl(wan_opts%prefix))//
'_u.mat',exist=exist)
535 if (.not. exist)
then
536 message(1) =
'Cannot find the Wannier90 seedname_u.mat file.'
544 read(w90_u_mat, *) nik, nwann, nwann
545 if (nik /= num_kpts .or. nwann /= wan_opts%num_wann)
then
546 message(1) =
"The U matrix has inconsistent shape."
555 read(w90_u_mat,
'(f15.10,sp,f15.10)') ((u_matrix(iw, iw2, ik), iw=1, wan_opts%num_wann), iw2=1, wan_opts%num_wann)
560 inquire(file=trim(adjustl(wan_opts%prefix))//
'_u_dis.mat',exist=have_disentangled)
561 if (have_disentangled)
then
569 read(w90_u_dis, *) nik, nwann, nib
570 if (nik /= num_kpts .or. nwann /= wan_opts%num_wann .or. nib /= wan_opts%num_bands)
then
571 message(1) =
'The u_dis matrix has inconsistent shape.'
580 read(w90_u_dis,
'(f15.10,sp,f15.10)') ((u_dis_matrix(ib, iw, ik), ib=1, wan_opts%num_bands), iw=1, wan_opts%num_wann)
596 character(len=*),
intent(in) :: dir
597 character(len=*),
intent(in) :: prefix
598 real(real64),
intent(in) :: centers(:, :)
599 class(
ions_t),
intent(in) :: ions
601 integer :: w90_xyz, iw, ia, ind
602 character(len=512) :: header
603 integer :: date_time(8)
607 w90_xyz =
io_open(trim(adjustl(dir))//
'/'//trim(adjustl(prefix))//
'_centres.xyz',
global_namespace, action=
'write', die=.false.)
608 if (w90_xyz == -1)
then
609 message(1) =
'Unable to open output file '//trim(adjustl(prefix))//
'_centres.xyz for writing.'
614 call date_and_time(
values=date_time)
616 write(w90_xyz,
'(i6)')
size(centers, 2) + ions%natoms
617 write(header,
'(a,i4,a1,i2.2,a1,i2.2,a,i2.2,a1,i2.2,a1,i2.2)') &
618 'Wannier centers, written by octopus on ', date_time(1),
'/', date_time(2),
'/', date_time(3), &
619 ' at ', date_time(5),
':', date_time(6),
':', date_time(7)
620 write (w90_xyz, *) trim(header)
622 do iw = 1,
size(centers, 2)
623 write(w90_xyz,
'("X",6x,3(f14.8,3x))') &
626 do ia = 1, ions%natoms
627 write(w90_xyz,
'(a2,5x,3(f14.8,3x))') trim(ions%atom(ia)%label), &
641 character(len=*),
intent(in) :: dir
642 character(len=*),
intent(in) :: prefix
644 complex(real64),
intent(in) :: u_matrix(:, :, :)
645 complex(real64),
intent(in) :: u_dis_matrix(:, :, :)
647 integer :: w90_u_mat, w90_u_dis
648 logical :: have_disentangled
649 integer :: i, j, nkp, num_wann, num_bands, num_kpts
650 character(len=512) :: header
651 integer :: date_time(8)
653 num_kpts =
size(u_matrix, 3)
654 num_wann =
size(u_matrix, 1)
655 num_bands =
size(u_dis_matrix, 1)
656 assert(num_kpts ==
size(kpoints%reduced%red_point, 2))
661 call date_and_time(
values=date_time)
663 w90_u_mat =
io_open(trim(adjustl(dir))//
'/'//trim(adjustl(prefix))//
'_u.mat',
global_namespace, action=
'write', die=.false.)
664 if (w90_u_mat == -1)
then
665 message(1) =
'Unable to open output file '//trim(adjustl(prefix))//
'_u.mat for writing.'
669 write(header,
'(a,i4,a1,i2.2,a1,i2.2,a,i2.2,a1,i2.2,a1,i2.2)') &
670 'written on ', date_time(1),
'/', date_time(2),
'/', date_time(3), &
671 ' at ', date_time(5),
':', date_time(6),
':', date_time(7)
672 write (w90_u_mat, *) trim(header)
673 write (w90_u_mat, *) num_kpts, num_wann, num_wann
677 write (w90_u_mat,
'(f15.10,sp,f15.10,sp,f15.10)') -kpoints%reduced%red_point(1:3, nkp)
678 write (w90_u_mat,
'(f15.10,sp,f15.10)') ((u_matrix(i, j, nkp), i=1, num_wann), j=1, num_wann)
683 inquire(file=trim(trim(adjustl(prefix))//
'_u_dis.mat'),exist=have_disentangled)
684 if (have_disentangled)
then
686 w90_u_dis =
io_open(trim(adjustl(dir))//
'/'//trim(adjustl(prefix))//
'_u_dis.mat', &
688 if (w90_u_dis == -1)
then
689 message(1) =
'Unable to open output file '//trim(adjustl(prefix))//
'_u_dis.mat for writing.'
693 write (w90_u_dis, *) trim(header)
694 write (w90_u_dis, *) num_kpts, num_wann, num_bands
697 write (w90_u_dis,
'(f15.10,sp,f15.10,sp,f15.10)') -kpoints%reduced%red_point(1:3, nkp)
698 write (w90_u_dis,
'(f15.10,sp,f15.10)') ((u_dis_matrix(i, j, nkp), i=1, num_bands), j=1, num_wann)
double log(double __x) __attribute__((__nothrow__
double exp(double __x) __attribute__((__nothrow__
This module implements batches of mesh functions.
integer, parameter, public batch_not_packed
functions are stored in CPU memory, unpacked order
integer, parameter, public batch_device_packed
functions are stored in device memory in packed order
integer, parameter, public batch_packed
functions are stored in CPU memory, in transposed (packed) order
integer, parameter, public spin_polarized
real(real64), parameter, public m_two
real(real64), parameter, public m_zero
complex(real64), parameter, public m_z0
complex(real64), parameter, public m_zi
subroutine, public io_close(iunit, grp)
integer function, public io_open(file, namespace, action, status, form, position, die, recl, grp)
subroutine, public kpoints_to_absolute(latt, kin, kout)
This module defines various routines, operating on mesh functions.
This module defines the meshes, which are used in Octopus.
subroutine, public messages_not_implemented(feature, 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_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
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...
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.
integer, parameter, public restart_gs
integer, parameter, public restart_td
integer, parameter, public restart_type_load
logical function, public state_kpt_is_local(st, ist, ik)
check whether a given state (ist, ik) is on the local node
subroutine, public states_elec_allocate_wfns(st, mesh, wfs_type, skip, packed)
Allocates the KS wavefunctions defined within a states_elec_t structure.
subroutine, public states_elec_look(restart, nik, dim, nst, ierr)
Reads the 'states' file in the restart directory, and finds out the nik, dim, and nst contained in it...
This module handles reading and writing restart information for the states_elec_t.
subroutine, public states_elec_load(restart, namespace, space, st, mesh, kpoints, ierr, iter, lr, lowest_missing, label, verbose, skip)
returns in ierr: <0 => Fatal error, or nothing read =0 => read all wavefunctions >0 => could only rea...
subroutine, public submesh_init(this, space, mesh, latt, center, rc)
type(type_t), public type_cmplx
brief This module defines the class unit_t which is used by the unit_systems_oct_m module.
This module defines the unit system, used for input and output.
type(unit_t), public unit_angstrom
For XYZ files.
Wannier90 related calculations.
subroutine, public wannier_calc_write_centers(dir, prefix, centers, ions)
Write wannier centers to file.
subroutine, public wannier_calc_read_centers(wan_opts, centers)
Read wannier centers.
subroutine, public wannier_calc_create_amn(wan_opts, exclude_list, band_index, space, mesh, latt, st, kpoints, spin_channel, num_proj, proj_input, projection)
Calculation of Wannier90 Projection Matrix.
subroutine, public wannier_calc_write_u_matrices(dir, prefix, kpoints, u_matrix, u_dis_matrix)
Write U and U_dis matrices to file.
subroutine, public wannier_calc_read_u_matrices(wan_opts, kpoints, u_matrix, u_dis_matrix)
Read wannier transformation matrix.
subroutine, public wannier_calc_load_restart(namespace, mc, space, st, gr, kpoints, restart_states)
Load Octopus restart data from disk.
subroutine, public wannier_calc_create_mmn(exclude_list, band_index, mesh, st, ions, spin_channel, nnlist, nncell, overlap)
Kohn-Sham State Overlap Matrix.
subroutine, public ylm_wannier(ylm, l, mr, rr, xx, nr)
Describes mesh distribution to nodes.
The states_elec_t class contains all electronic wave functions.
Mocks the projection type from wannier90.
batches of electronic states
real(real64) function values(xx)