Octopus
wannier_calc.F90
Go to the documentation of this file.
1!! Copyright (C) A Buccheri, J Reimann. 2026
2!!
3!! This Source Code Form is subject to the terms of the Mozilla Public
4!! License, v. 2.0. If a copy of the MPL was not distributed with this
5!! file, You can obtain one at https://mozilla.org/MPL/2.0/.
6
7#include "global.h"
8
11 use, intrinsic :: iso_fortran_env
12
14 use comm_oct_m
15 use debug_oct_m
17 use global_oct_m
18 use io_oct_m
19 use ions_oct_m
22 use mesh_oct_m
25 use mpi_oct_m
31 use space_oct_m
35 use types_oct_m
36 use unit_oct_m
39 use wfs_elec_oct_m, only: wfs_elec_t
41
42 implicit none
43 private
44
45 public :: &
54
60 integer :: l, m, s
61 integer :: radial = 1
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
67 end type wannier_calc_proj_t
68
69contains
70
75 subroutine wannier_calc_load_restart(namespace, mc, space, st, gr, kpoints, restart_states)
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
83 ! Defaults to ground state
84
85 integer :: restart_states_, ierr, nik, dim, nst
86 type(restart_t) :: restart
87
88 restart_states_ = optional_default(restart_states, restart_gs)
89 if (.not. (restart_states_ == restart_gs .or. restart_states_ == restart_td)) then
90 message(1) = 'Invalid restart_states value; expected RESTART_GS or RESTART_TD.'
91 call messages_fatal(1)
92 end if
93
94 call states_elec_allocate_wfns(st, gr, wfs_type = type_cmplx)
95 call restart%init(namespace, restart_states_, restart_type_load, mc, ierr, gr)
96
97 if (ierr /= 0) then
98 write(message(1),'(a)') 'Error opening restart file'
99 call messages_fatal(1)
100 endif
101
102 call states_elec_look(restart, nik, dim, nst, ierr)
103 if (st%d%ispin == spin_polarized) nik = nik / 2
104 if (dim /= st%d%dim) then
105 write(message(1),'(a)') 'Restart structure not commensurate, since spin dimensions differ.'
106 call messages_fatal(1)
107 else if (nik /= kpoints%reduced%npoints) then
108 write(message(1),'(a)') 'Restart structure not commensurate, since number of k-points differ.'
109 call messages_fatal(1)
110 else if (nst /= st%nst) then
111 write(message(1),'(a)') 'Restart structure not commensurate, since number of states differ.'
112 call messages_fatal(1)
113 end if
114
115 call states_elec_load(restart, namespace, space, st, gr, kpoints, ierr, label = ": wannier90")
116 call restart%end()
117
118 end subroutine wannier_calc_load_restart
119
120 ! TODO: Removed SCDM - Should reintroduce once the code is working
126 subroutine wannier_calc_create_amn(wan_opts, exclude_list, &
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(:)
140
141 complex(real64), contiguous, intent(out) :: projection(:, :, :)
142
143 integer :: ist, ik, idim, iw, ip, ik_real, iband, num_kpts
144 real(real64) :: center(3), kpoint(3)
145
146 complex(real64), allocatable :: psi(:,:), phase(:)
147 real(real64), allocatable :: ylm(:)
148 type(orbitalset_t), allocatable :: orbitals(:)
149
151 call profiling_in("W90_AMN")
152
153 if (st%parallel_in_states) then
154 call messages_not_implemented("w90_amn output with states parallelization")
155 end if
157 message(1) = "Info: Computing the projection matrix"
160 assert(num_proj == size(proj_input))
162 num_kpts = product(kpoints%nik_axis(1:3))
163
164 ! Precompute orbitals
165 safe_allocate(orbitals(1:num_proj))
166 do iw=1, num_proj
167 call orbitalset_init(orbitals(iw))
168
169 orbitals(iw)%norbs = 1
170 orbitals(iw)%ndim = 1
171 orbitals(iw)%radius = -log(wan_opts%threshold)
172 orbitals(iw)%use_submesh = .false.
173
174 ! cartesian coordinate of orbital center
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)
177
178 ! get dorb as submesh points
179 safe_allocate(ylm(1:orbitals(iw)%sphere%np))
180 ! (this is a routine from pwscf)
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)
183
184 if (proj_input(iw)%radial /= 1) then
185 call messages_not_implemented("oct-wannier90: r/=1 for the radial part")
186 end if
187
188 ! apply radial function
189 do ip = 1, orbitals(iw)%sphere%np
190 ylm(ip) = ylm(ip) * m_two * exp(-orbitals(iw)%sphere%r(ip))
191 end do
192
193 ! NOTE(Alex) One can probably fill directly into zorb, and avoid allocating ylm
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)
197
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
202
203 call orbitalset_update_phase(orbitals(iw), space%dim, st%d%kpt, kpoints, st%d%ispin == spin_polarized, &
204 kpt_max = num_kpts)
205 end do
206
207 ! Compute the projections
208 safe_allocate(psi(1:mesh%np, 1:st%d%dim))
209 safe_allocate(phase(1:mesh%np))
210 projection = m_zero
211
212 do ik = 1, num_kpts
213 kpoint(1:space%dim) = kpoints%get_point(ik)
214 do ip = 1, mesh%np
215 phase(ip) = exp(-m_zi * sum(mesh%x(1:space%dim, ip) * kpoint(1:space%dim)))
216 end do
217
218 !For spin-polarized calculations, we select the right k-point
219 if (st%d%ispin == spin_polarized) then
220 ik_real = (ik-1)*2 + spin_channel
221 else
222 ik_real = ik
223 end if
224
225 ! TODO(Alex) ist and iw loops need interchanging to optimise array access
226 do ist = 1, st%nst
227 if (exclude_list(ist)) cycle
228 iband = band_index(ist)
229
230 if(ik_real >= st%d%kpt%start .and. ik_real <= st%d%kpt%end) then
231 call states_elec_get_state(st, mesh, ist, ik_real, psi)
232
233 do idim = 1, st%d%dim
234 do ip = 1, mesh%np
235 psi(ip, idim) = psi(ip, idim)*phase(ip)
236 end do
237 end do
238
239 do iw = 1, num_proj
240 idim = 1
241 if (wan_opts%spinors) idim = wan_opts%spin_proj_component(iw)
242 !At the moment the orbitals do not depend on idim
243 !The idim index for eorb_mesh would be for a spin-resolved orbital like j=1/2
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.)
246 end do
247
248 call profiling_in("W90_AMN_REDUCE")
249 call mesh%allreduce(projection(iband, :, ik))
250 call profiling_out("W90_AMN_REDUCE")
251 end if
252
253 if(st%d%kpt%parallel) then
254 call comm_allreduce(st%d%kpt%mpi_grp, projection(iband, :, ik))
255 end if
256
257 end do !ist
258 end do !ik
259
260 safe_deallocate_a(psi)
261 safe_deallocate_a(phase)
262
263 do iw = 1, num_proj
264 call orbitalset_end(orbitals(iw))
265 end do
266 safe_deallocate_a(orbitals)
267
268 call profiling_out("W90_AMN")
269
271
272 end subroutine wannier_calc_create_amn
273
283 subroutine wannier_calc_create_mmn(exclude_list, band_index, mesh, st, ions, &
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
288 type(states_elec_t), target, intent(in) :: st
289 type(ions_t), intent(in) :: ions
290 integer, intent(in) :: spin_channel
291 integer, intent(in) :: nnlist(:,:)
292 integer, intent(in) :: nncell(:,:,:)
293
294 complex(real64), contiguous, intent(out) :: overlap(:, :, :, :)
295
296 integer :: ist, jst, ik, ip, iknn, idim, ibind
297 integer :: ik_oct, iknn_oct, inn
298 integer :: ik_loc
299 integer :: iband, jband, inode, node_fr, node_to
300 real(real64) :: gcart(3)
301 integer :: g(3)
302
303 integer :: nntot, num_kpts
304
305 complex(real64), allocatable :: psim(:,:), psin(:,:), phase(:)
306 type(wfs_elec_t), pointer :: batch
307 type(mpi_request) :: send_req
308
310
311 call profiling_in("W90_MMN")
312
313
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)
320
321 if (st%parallel_in_states) then
322 call messages_not_implemented("w90_mmn output with states parallelization")
323 end if
324
325 message(1) = "Info: Computing the overlap matrix for wannerisation"
326 call messages_info(1)
327
328 overlap = m_zero
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))
332
333 if (st%d%kpt%parallel) ik_loc = 0
334
335 ! loop over the pairs specified in the nnk tuple
336 do ik = 1, num_kpts
337 do inn = 1, nntot
338
339 iknn = nnlist(ik, inn)
340 g(1:3) = nncell(:, ik, inn)
341
342 ! For spin-polarized calculations, we select the right k-point
343 if (st%d%ispin == spin_polarized) then
344 ik_oct = (ik-1)*2 + spin_channel
345 iknn_oct = (iknn-1)*2 + spin_channel
346 else
347 ik_oct = ik
348 iknn_oct = iknn
349 end if
350
351 ! If the k-point is local, compute the phase e^{-i G.r}
352 if(ik_oct >= st%d%kpt%start .and. ik_oct <= st%d%kpt%end) then
353 ! Wannier90 treats everything fully periodic
354 ! Conversion is done with the 3D "correct" klattice
355 call kpoints_to_absolute(ions%latt, real(g, real64) , gcart)
356
357 ! Phase that gives u_{n,k+G}(r) from u_{nk}(r)
358 ! Here the minus sign of Octopus cancels with minus sign of the input G
359 ! (ik and iknn correspond in the list to minus the k-points in Octopus)
360 if (any(g /= 0)) then
361 do ip = 1, mesh%np
362 phase(ip) = exp(-m_zi*dot_product(mesh%x(1:3, ip), gcart(1:3)))
363 end do
364 end if
365 end if
366
367 ! Loop over distributed bands
368 do jst = 1, st%nst
369 if (exclude_list(jst)) cycle
370 jband = band_index(jst)
371
372 if (st%d%kpt%parallel) then
373 node_fr = -1
374 node_to = -1
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
377 node_fr = inode
378 end if
379 if(ik_oct >= st%st_kpt_task(inode,3) .and. ik_oct <= st%st_kpt_task(inode,4)) then
380 node_to = inode
381 end if
382 end do
383 assert(node_fr > -1)
384 assert(node_to > -1)
385 send_req = mpi_request_null
386 ! We have locally the k-point
387 if (state_kpt_is_local(st, jst, iknn_oct)) then
388 call states_elec_get_state(st, mesh, jst, iknn_oct, psin)
389 ! We send it only if we don`t want to use it locally
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)
392 end if
393 end if
394 ! We receive the desired state, only if it is not a local one
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)
397 end if
398 if (send_req /= mpi_request_null) then
399 call st%d%kpt%mpi_grp%wait(send_req)
400 end if
401 else
402 call states_elec_get_state(st, mesh, jst, iknn_oct, psin)
403 end if
404
405 if(ik_oct >= st%d%kpt%start .and. ik_oct <= st%d%kpt%end) then
406
407 ! Do not apply the phase if the phase factor is 1
408 if (any(g /= 0)) then
409 do idim = 1, st%d%dim
410 do ip = 1, mesh%np
411 psin(ip, idim) = psin(ip, idim) * phase(ip)
412 end do
413 end do
414 end if
415
416 ! See Eq. (25) in PRB 56, 12847 (1997)
417 ! Loop over local k-points
418 do ist = 1, st%nst
419 if (exclude_list(ist)) cycle
420 iband = band_index(ist)
421
422 batch => st%group%psib(st%group%iblock(ist), ik_oct)
423
424 select case (batch%status())
425 case (batch_not_packed)
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.)
431 end do
432 !Not properly done at the moment
434 call states_elec_get_state(st, mesh, ist, ik_oct, psim)
435 overlap(iband, jband, inn, ik) = zmf_dotp(mesh, st%d%dim, psim, psin, reduce = .false.)
436 end select
437 end do !ist
438 end if
439
440 call profiling_in("W90_MMN_REDUCE")
441 call mesh%allreduce(overlap(:, jband, inn, ik))
442 call profiling_out("W90_MMN_REDUCE")
443
444 if(st%d%kpt%parallel) then
445 call comm_allreduce(st%d%kpt%mpi_grp, overlap(:, jband, inn, ik))
446 end if
447 end do !jst
448 end do !inn
449
450 ! This contains a necessary remap: wannier90 only stores the local m_matrix, so it stores
451 ! only the first nk_rank kpoints in the matrix. The following block remaps from the global
452 ! kpoint to the local kpoint
453 if (st%d%kpt%parallel) then
454 if (st%d%ispin == spin_polarized) then
455 ik_oct = (ik-1)*2 + spin_channel
456 else
457 ik_oct = ik
458 end if
459 if (ik_oct >= st%d%kpt%start .and. ik_oct <= st%d%kpt%end) then
460 ik_loc = ik_loc + 1
461 if (ik_loc /= ik) then
462 overlap(:, :, :, ik_loc) = overlap(:, :, :, ik)
463 end if
464 end if
465 end if
466 end do !ik
467
468 safe_deallocate_a(psim)
469 safe_deallocate_a(psin)
470 safe_deallocate_a(phase)
471
472 call profiling_out("W90_MMN")
473
475
476 end subroutine wannier_calc_create_mmn
477
482 subroutine wannier_calc_read_centers(wan_opts, centers)
483 type(wannier_opts_t), intent(in) :: wan_opts
484 real(real64), intent(inout) :: centers(:, :)
485
486 integer :: w90_xyz, iw
487 character(len=2) :: dum
488 logical :: exist
489
491
492 assert(size(centers, 2) == wan_opts%num_wann)
493 assert(size(centers, 1) == 3)
494
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.'
498 call messages_fatal(1)
499 end if
500
501 w90_xyz = io_open(trim(adjustl(wan_opts%prefix))//'_centres.xyz', global_namespace, action='read')
502
503 !Skip two lines
504 read(w90_xyz, *)
505 read(w90_xyz, *)
506 do iw = 1, wan_opts%num_wann
507 read(w90_xyz, *) dum, centers(1:3, iw)
508 ! Wannier90 outputs the coordinates in angstrom
509 centers(1:3, iw) = units_to_atomic(unit_angstrom, centers(1:3, iw))
510 end do
511 call io_close(w90_xyz)
512
514 end subroutine wannier_calc_read_centers
515
520 subroutine wannier_calc_read_u_matrices(wan_opts, kpoints, u_matrix, u_dis_matrix)
521 type(wannier_opts_t), intent(in) :: wan_opts
522 type(kpoints_t), intent(in) :: kpoints
523 complex(real64), intent(inout) :: u_matrix(:, :, :)
524 complex(real64), intent(inout) :: u_dis_matrix(:, :, :)
525
526 integer :: w90_u_mat, w90_u_dis, ik, ib, iw, iw2, nik, nwann, nib
527 integer :: num_kpts
528 logical :: exist, have_disentangled
529
530 num_kpts = product(kpoints%nik_axis(1:3))
531
533
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.'
537 call messages_fatal(1)
538 end if
539 w90_u_mat = io_open(trim(adjustl(wan_opts%prefix))//'_u.mat', global_namespace, action='read')
540
541 !Skip one line
542 read(w90_u_mat, *)
543 !Read num_kpts, num_wann, num_wann for consistency check
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."
547 call messages_fatal(1)
548 end if
549
550 do ik = 1, num_kpts
551 !Skip one line
552 read(w90_u_mat, *)
553 !Skip one line (k-point coordinate)
554 read(w90_u_mat, *)
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)
556 end do
557
558 call io_close(w90_u_mat)
559
560 inquire(file=trim(adjustl(wan_opts%prefix))//'_u_dis.mat',exist=have_disentangled)
561 if (have_disentangled) then
562 ! Read u_dis.mat: dimensions are (w90_num_bands x w90_num_wann) per k-point.
563 ! The band rows follow the compressed, non-excluded band ordering used by
564 ! the rest of the Wannier90 interface (i.e. after applying exclude_bands).
565 w90_u_dis = io_open(trim(adjustl(wan_opts%prefix))//'_u_dis.mat', global_namespace, action='read')
566 !Skip one line
567 read(w90_u_dis, *)
568 !Read num_kpts, num_wann, num_bands for consistency check
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.'
572 call messages_fatal(1)
573 end if
574
575 do ik = 1, num_kpts
576 !Skip one line
577 read(w90_u_dis, *)
578 !Skip one line (k-point coordinate)
579 read(w90_u_dis, *)
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)
581 end do
582
583 call io_close(w90_u_dis)
584
585 ! In case of disentanglement, u_dis matrix needs to be reordered to the correct layout.
586 ! See issue #1465.
587 end if
588
590 end subroutine wannier_calc_read_u_matrices
591
595 subroutine wannier_calc_write_centers(dir, prefix, centers, ions)
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
600
601 integer :: w90_xyz, iw, ia, ind
602 character(len=512) :: header
603 integer :: date_time(8)
604
606
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.'
610 call messages_fatal(1)
611 end if
612
613 ! Get current date and time
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)
621
622 do iw = 1, size(centers, 2)
623 write(w90_xyz, '("X",6x,3(f14.8,3x))') &
624 (units_from_atomic(unit_angstrom, centers(ind, iw)), ind=1, 3)
625 end do
626 do ia = 1, ions%natoms
627 write(w90_xyz, '(a2,5x,3(f14.8,3x))') trim(ions%atom(ia)%label), &
628 (units_from_atomic(unit_angstrom, ions%pos(ind, ia)), ind=1, 3)
629 end do
630 call io_close(w90_xyz)
631
633
634 end subroutine wannier_calc_write_centers
635
640 subroutine wannier_calc_write_u_matrices(dir, prefix, kpoints, u_matrix, u_dis_matrix)
641 character(len=*), intent(in) :: dir
642 character(len=*), intent(in) :: prefix
643 type(kpoints_t), intent(in) :: kpoints
644 complex(real64), intent(in) :: u_matrix(:, :, :)
645 complex(real64), intent(in) :: u_dis_matrix(:, :, :)
646
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)
652
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))
657
659
660 ! Get current date and time
661 call date_and_time(values=date_time)
662
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.'
666 call messages_fatal(1)
667 end if
668
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
674
675 do nkp = 1, num_kpts
676 write (w90_u_mat, *)
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)
679 end do
680
681 call io_close(w90_u_mat)
682
683 inquire(file=trim(trim(adjustl(prefix))//'_u_dis.mat'),exist=have_disentangled)
684 if (have_disentangled) then
685
686 w90_u_dis = io_open(trim(adjustl(dir))//'/'//trim(adjustl(prefix))//'_u_dis.mat', &
687 global_namespace, action='write', die=.false.)
688 if (w90_u_dis == -1) then
689 message(1) = 'Unable to open output file '//trim(adjustl(prefix))//'_u_dis.mat for writing.'
691 end if
692
693 write (w90_u_dis, *) trim(header)
694 write (w90_u_dis, *) num_kpts, num_wann, num_bands
695 do nkp = 1, num_kpts
696 write (w90_u_dis, *)
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)
699 end do
700
701 call io_close(w90_u_dis)
702 end if
703
705
706 end subroutine wannier_calc_write_u_matrices
707
708end module wannier_calc_oct_m
double log(double __x) __attribute__((__nothrow__
double exp(double __x) __attribute__((__nothrow__
This module implements batches of mesh functions.
Definition: batch.F90:135
integer, parameter, public batch_not_packed
functions are stored in CPU memory, unpacked order
Definition: batch.F90:286
integer, parameter, public batch_device_packed
functions are stored in device memory in packed order
Definition: batch.F90:286
integer, parameter, public batch_packed
functions are stored in CPU memory, in transposed (packed) order
Definition: batch.F90:286
integer, parameter, public spin_polarized
real(real64), parameter, public m_two
Definition: global.F90:202
real(real64), parameter, public m_zero
Definition: global.F90:200
complex(real64), parameter, public m_z0
Definition: global.F90:210
complex(real64), parameter, public m_zi
Definition: global.F90:214
Definition: io.F90:116
subroutine, public io_close(iunit, grp)
Definition: io.F90:467
integer function, public io_open(file, namespace, action, status, form, position, die, recl, grp)
Definition: io.F90:402
subroutine, public kpoints_to_absolute(latt, kin, kout)
Definition: kpoints.F90:1137
This module defines various routines, operating on mesh functions.
This module defines the meshes, which are used in Octopus.
Definition: mesh.F90:120
subroutine, public messages_not_implemented(feature, namespace)
Definition: messages.F90:1068
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:162
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
Definition: messages.F90:410
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
Definition: messages.F90:594
This module handles the communicators for the various parallelization strategies.
Definition: multicomm.F90:147
type(namespace_t), public global_namespace
Definition: namespace.F90:135
subroutine, public orbitalset_init(this)
Definition: orbitalset.F90:210
subroutine, public orbitalset_end(this)
Definition: orbitalset.F90:236
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...
Definition: orbitalset.F90:286
subroutine, public profiling_out(label)
Increment out counter and sum up difference between entry and exit time.
Definition: profiling.F90:631
subroutine, public profiling_in(label, exclude)
Increment in counter and save entry time.
Definition: profiling.F90:554
integer, parameter, public restart_gs
Definition: restart.F90:156
integer, parameter, public restart_td
Definition: restart.F90:156
integer, parameter, public restart_type_load
Definition: restart.F90:184
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)
Definition: submesh.F90:227
type(type_t), public type_cmplx
Definition: types.F90:136
brief This module defines the class unit_t which is used by the unit_systems_oct_m module.
Definition: unit.F90:134
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.
Wannier options module.
subroutine, public ylm_wannier(ylm, l, mr, rr, xx, nr)
Describes mesh distribution to nodes.
Definition: mesh.F90:187
The states_elec_t class contains all electronic wave functions.
Mocks the projection type from wannier90.
Wannier related options.
batches of electronic states
Definition: wfs_elec.F90:141
real(real64) function values(xx)
Definition: test.F90:2143