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, fixed_occ=st%restart_fixed_occ , &
116 ierr=ierr, label =
": wannier90")
128 band_index, space, mesh, latt, st, kpoints, &
129 spin_channel, num_proj, proj_input, projection)
130 type(wannier_opts_t),
intent(in) :: wan_opts
131 class(space_t),
intent(in) :: space
132 class(mesh_t),
intent(in) :: mesh
133 type(lattice_vectors_t),
intent(in) :: latt
134 type(states_elec_t),
intent(in) :: st
135 type(kpoints_t),
intent(in) :: kpoints
136 logical,
intent(in) :: exclude_list(:)
137 integer,
intent(in) :: band_index(:)
138 integer,
intent(in) :: spin_channel
139 integer,
intent(in) :: num_proj
140 type(wannier_calc_proj_t),
intent(in) :: proj_input(:)
142 complex(real64),
contiguous,
intent(out) :: projection(:, :, :)
144 integer :: ist, ik, idim, iw, ip, ik_real, iband, num_kpts
145 real(real64) :: center(3), kpoint(3)
147 complex(real64),
allocatable :: psi(:,:), phase(:)
148 real(real64),
allocatable :: ylm(:)
149 type(orbitalset_t),
allocatable :: orbitals(:)
154 if (st%parallel_in_states)
then
158 message(1) =
"Info: Computing the projection matrix"
161 assert(num_proj ==
size(proj_input))
163 num_kpts = product(kpoints%nik_axis(1:3))
166 safe_allocate(orbitals(1:num_proj))
170 orbitals(iw)%norbs = 1
171 orbitals(iw)%ndim = 1
172 orbitals(iw)%radius = -
log(wan_opts%threshold)
173 orbitals(iw)%use_submesh = .false.
176 center(1:3) = latt%red_to_cart(proj_input(iw)%site(1:3))
177 call submesh_init(orbitals(iw)%sphere, space, mesh, latt, center, orbitals(iw)%radius)
180 safe_allocate(ylm(1:orbitals(iw)%sphere%np))
182 call ylm_wannier(ylm, proj_input(iw)%l, proj_input(iw)%m, &
183 orbitals(iw)%sphere%r, orbitals(iw)%sphere%rel_x, orbitals(iw)%sphere%np)
185 if (proj_input(iw)%radial /= 1)
then
190 do ip = 1, orbitals(iw)%sphere%np
191 ylm(ip) = ylm(ip) *
m_two *
exp(-orbitals(iw)%sphere%r(ip))
195 safe_allocate(orbitals(iw)%zorb(1:orbitals(iw)%sphere%np, 1:1, 1:1))
196 orbitals(iw)%zorb(1:orbitals(iw)%sphere%np, 1, 1) = ylm(1:orbitals(iw)%sphere%np)
197 safe_deallocate_a(ylm)
199 safe_allocate(orbitals(iw)%phase(1:orbitals(iw)%sphere%np, st%d%kpt%start:st%d%kpt%end))
200 orbitals(iw)%phase =
m_z0
201 safe_allocate(orbitals(iw)%eorb_mesh(1:mesh%np, 1:1, 1:1, st%d%kpt%start:st%d%kpt%end))
202 orbitals(iw)%eorb_mesh =
m_z0
209 safe_allocate(psi(1:mesh%np, 1:st%d%dim))
210 safe_allocate(phase(1:mesh%np))
214 kpoint(1:space%dim) = kpoints%get_point(ik)
216 phase(ip) =
exp(-
m_zi * sum(mesh%x(1:space%dim, ip) * kpoint(1:space%dim)))
221 ik_real = (ik-1)*2 + spin_channel
228 if (exclude_list(ist)) cycle
229 iband = band_index(ist)
231 if(ik_real >= st%d%kpt%start .and. ik_real <= st%d%kpt%end)
then
234 do idim = 1, st%d%dim
236 psi(ip, idim) = psi(ip, idim)*phase(ip)
242 if (wan_opts%spinors) idim = wan_opts%spin_proj_component(iw)
245 projection(iband, iw, ik) =
zmf_dotp(mesh, psi(1:mesh%np, idim), &
246 orbitals(iw)%eorb_mesh(1:mesh%np, 1, 1, ik_real), reduce = .false.)
250 call mesh%allreduce(projection(iband, :, ik))
254 if(st%d%kpt%parallel)
then
261 safe_deallocate_a(psi)
262 safe_deallocate_a(phase)
267 safe_deallocate_a(orbitals)
285 spin_channel, nnlist, nncell, overlap)
286 logical,
intent(in) :: exclude_list(:)
287 integer,
intent(in) :: band_index(:)
288 class(
mesh_t),
intent(in) :: mesh
290 type(
ions_t),
intent(in) :: ions
291 integer,
intent(in) :: spin_channel
292 integer,
intent(in) :: nnlist(:,:)
293 integer,
intent(in) :: nncell(:,:,:)
295 complex(real64),
contiguous,
intent(out) :: overlap(:, :, :, :)
297 integer :: ist, jst, ik, ip, iknn, idim, ibind
298 integer :: ik_oct, iknn_oct, inn
300 integer :: iband, jband, inode, node_fr, node_to
301 real(real64) :: gcart(3)
304 integer :: nntot, num_kpts
306 complex(real64),
allocatable :: psim(:,:), psin(:,:), phase(:)
308 type(mpi_request) :: send_req
315 nntot =
size(nnlist, 2)
316 num_kpts =
size(nnlist, 1)
317 assert(
size(nnlist, 1) == num_kpts)
318 assert(
size(nncell, 1) == 3)
319 assert(
size(nncell, 2) == num_kpts)
320 assert(
size(nncell, 3) == nntot)
322 if (st%parallel_in_states)
then
326 message(1) =
"Info: Computing the overlap matrix for wannerisation"
330 safe_allocate(psim(1:mesh%np, 1:st%d%dim))
331 safe_allocate(psin(1:mesh%np, 1:st%d%dim))
332 safe_allocate(phase(1:mesh%np))
334 if (st%d%kpt%parallel) ik_loc = 0
340 iknn = nnlist(ik, inn)
341 g(1:3) = nncell(:, ik, inn)
345 ik_oct = (ik-1)*2 + spin_channel
346 iknn_oct = (iknn-1)*2 + spin_channel
353 if(ik_oct >= st%d%kpt%start .and. ik_oct <= st%d%kpt%end)
then
361 if (any(g /= 0))
then
363 phase(ip) =
exp(-
m_zi*dot_product(mesh%x(1:3, ip), gcart(1:3)))
370 if (exclude_list(jst)) cycle
371 jband = band_index(jst)
373 if (st%d%kpt%parallel)
then
376 do inode = 0, st%d%kpt%mpi_grp%size-1
377 if(iknn_oct >= st%st_kpt_task(inode,3) .and. iknn_oct <= st%st_kpt_task(inode,4))
then
380 if(ik_oct >= st%st_kpt_task(inode,3) .and. ik_oct <= st%st_kpt_task(inode,4))
then
386 send_req = mpi_request_null
391 if(node_to /= st%d%kpt%mpi_grp%rank)
then
392 call st%d%kpt%mpi_grp%isend(psin, mesh%np*st%d%dim, mpi_double_complex, node_to, send_req)
396 if(node_to == st%d%kpt%mpi_grp%rank .and. node_to /= node_fr)
then
397 call st%d%kpt%mpi_grp%recv(psin, mesh%np*st%d%dim, mpi_double_complex, node_fr)
399 if (send_req /= mpi_request_null)
then
400 call st%d%kpt%mpi_grp%wait(send_req)
406 if(ik_oct >= st%d%kpt%start .and. ik_oct <= st%d%kpt%end)
then
409 if (any(g /= 0))
then
410 do idim = 1, st%d%dim
412 psin(ip, idim) = psin(ip, idim) * phase(ip)
420 if (exclude_list(ist)) cycle
421 iband = band_index(ist)
423 batch => st%group%psib(st%group%iblock(ist), ik_oct)
425 select case (batch%status())
427 overlap(iband, jband, inn, ik) =
m_z0
428 do idim = 1, st%d%dim
429 ibind = batch%inv_index((/ist, idim/))
430 overlap(iband, jband, inn, ik) = overlap(iband, jband, inn, ik) + &
431 zmf_dotp(mesh, batch%zff_linear(:, ibind), psin(:,idim), reduce = .false.)
436 overlap(iband, jband, inn, ik) =
zmf_dotp(mesh, st%d%dim, psim, psin, reduce = .false.)
442 call mesh%allreduce(overlap(:, jband, inn, ik))
445 if(st%d%kpt%parallel)
then
454 if (st%d%kpt%parallel)
then
456 ik_oct = (ik-1)*2 + spin_channel
460 if (ik_oct >= st%d%kpt%start .and. ik_oct <= st%d%kpt%end)
then
462 if (ik_loc /= ik)
then
463 overlap(:, :, :, ik_loc) = overlap(:, :, :, ik)
469 safe_deallocate_a(psim)
470 safe_deallocate_a(psin)
471 safe_deallocate_a(phase)
485 real(real64),
intent(inout) :: centers(:, :)
487 integer :: w90_xyz, iw
488 character(len=2) :: dum
493 assert(
size(centers, 2) == wan_opts%num_wann)
494 assert(
size(centers, 1) == 3)
496 inquire(file=trim(adjustl(wan_opts%prefix))//
'_centres.xyz',exist=exist)
497 if (.not. exist)
then
498 message(1) =
'Cannot find the Wannier90 file seedname_centres.xyz.'
507 do iw = 1, wan_opts%num_wann
508 read(w90_xyz, *) dum, centers(1:3, iw)
524 complex(real64),
intent(inout) :: u_matrix(:, :, :)
525 complex(real64),
intent(inout) :: u_dis_matrix(:, :, :)
527 integer :: w90_u_mat, w90_u_dis, ik, ib, iw, iw2, nik, nwann, nib
529 logical :: exist, have_disentangled
531 num_kpts = product(kpoints%nik_axis(1:3))
535 inquire(file=trim(adjustl(wan_opts%prefix))//
'_u.mat',exist=exist)
536 if (.not. exist)
then
537 message(1) =
'Cannot find the Wannier90 seedname_u.mat file.'
545 read(w90_u_mat, *) nik, nwann, nwann
546 if (nik /= num_kpts .or. nwann /= wan_opts%num_wann)
then
547 message(1) =
"The U matrix has inconsistent shape."
556 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)
561 inquire(file=trim(adjustl(wan_opts%prefix))//
'_u_dis.mat',exist=have_disentangled)
562 if (have_disentangled)
then
570 read(w90_u_dis, *) nik, nwann, nib
571 if (nik /= num_kpts .or. nwann /= wan_opts%num_wann .or. nib /= wan_opts%num_bands)
then
572 message(1) =
'The u_dis matrix has inconsistent shape.'
581 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)
597 character(len=*),
intent(in) :: dir
598 character(len=*),
intent(in) :: prefix
599 real(real64),
intent(in) :: centers(:, :)
600 class(
ions_t),
intent(in) :: ions
602 integer :: w90_xyz, iw, ia, ind
603 character(len=512) :: header
604 integer :: date_time(8)
608 w90_xyz =
io_open(trim(adjustl(dir))//
'/'//trim(adjustl(prefix))//
'_centres.xyz',
global_namespace, action=
'write', die=.false.)
609 if (w90_xyz == -1)
then
610 message(1) =
'Unable to open output file '//trim(adjustl(prefix))//
'_centres.xyz for writing.'
615 call date_and_time(
values=date_time)
617 write(w90_xyz,
'(i6)')
size(centers, 2) + ions%natoms
618 write(header,
'(a,i4,a1,i2.2,a1,i2.2,a,i2.2,a1,i2.2,a1,i2.2)') &
619 'Wannier centers, written by octopus on ', date_time(1),
'/', date_time(2),
'/', date_time(3), &
620 ' at ', date_time(5),
':', date_time(6),
':', date_time(7)
621 write (w90_xyz, *) trim(header)
623 do iw = 1,
size(centers, 2)
624 write(w90_xyz,
'("X",6x,3(f14.8,3x))') &
627 do ia = 1, ions%natoms
628 write(w90_xyz,
'(a2,5x,3(f14.8,3x))') trim(ions%atom(ia)%label), &
642 character(len=*),
intent(in) :: dir
643 character(len=*),
intent(in) :: prefix
645 complex(real64),
intent(in) :: u_matrix(:, :, :)
646 complex(real64),
intent(in) :: u_dis_matrix(:, :, :)
648 integer :: w90_u_mat, w90_u_dis
649 logical :: have_disentangled
650 integer :: i, j, nkp, num_wann, num_bands, num_kpts
651 character(len=512) :: header
652 integer :: date_time(8)
654 num_kpts =
size(u_matrix, 3)
655 num_wann =
size(u_matrix, 1)
656 num_bands =
size(u_dis_matrix, 1)
657 assert(num_kpts ==
size(kpoints%reduced%red_point, 2))
662 call date_and_time(
values=date_time)
664 w90_u_mat =
io_open(trim(adjustl(dir))//
'/'//trim(adjustl(prefix))//
'_u.mat',
global_namespace, action=
'write', die=.false.)
665 if (w90_u_mat == -1)
then
666 message(1) =
'Unable to open output file '//trim(adjustl(prefix))//
'_u.mat for writing.'
670 write(header,
'(a,i4,a1,i2.2,a1,i2.2,a,i2.2,a1,i2.2,a1,i2.2)') &
671 'written on ', date_time(1),
'/', date_time(2),
'/', date_time(3), &
672 ' at ', date_time(5),
':', date_time(6),
':', date_time(7)
673 write (w90_u_mat, *) trim(header)
674 write (w90_u_mat, *) num_kpts, num_wann, num_wann
678 write (w90_u_mat,
'(f15.10,sp,f15.10,sp,f15.10)') -kpoints%reduced%red_point(1:3, nkp)
679 write (w90_u_mat,
'(f15.10,sp,f15.10)') ((u_matrix(i, j, nkp), i=1, num_wann), j=1, num_wann)
684 inquire(file=trim(trim(adjustl(prefix))//
'_u_dis.mat'),exist=have_disentangled)
685 if (have_disentangled)
then
687 w90_u_dis =
io_open(trim(adjustl(dir))//
'/'//trim(adjustl(prefix))//
'_u_dis.mat', &
689 if (w90_u_dis == -1)
then
690 message(1) =
'Unable to open output file '//trim(adjustl(prefix))//
'_u_dis.mat for writing.'
694 write (w90_u_dis, *) trim(header)
695 write (w90_u_dis, *) num_kpts, num_wann, num_bands
698 write (w90_u_dis,
'(f15.10,sp,f15.10,sp,f15.10)') -kpoints%reduced%red_point(1:3, nkp)
699 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, 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.
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)