62 type(output_me_t),
intent(out) :: this
63 type(namespace_t),
intent(in) :: namespace
64 class(space_t),
intent(in) :: space
65 type(states_elec_t),
intent(in) :: st
66 type(grid_t),
intent(in) :: gr
67 integer,
intent(in) :: nst
69 integer(int64) :: how(0:MAX_OUTPUT_TYPES)
70 integer :: output_interval(0:MAX_OUTPUT_TYPES)
116 'OutputMatrixElements')
118 if (st%parallel_in_states)
then
119 if (this%what(option__outputmatrixelements__two_body))
then
123 if (this%what(option__outputmatrixelements__dipole))
then
129 if (space%dim /= 2 .and. space%dim /= 3) this%what(option__outputmatrixelements__ang_momentum) = .false.
131 if (this%what(option__outputmatrixelements__ks_multipoles))
then
152 call parse_variable(namespace,
'OutputMEMultipoles', 1, this%ks_multipoles)
164 assert(this%st_start > 0 .and. this%st_start <= nst)
175 if (this%st_end <= 0 .or. this%st_end > nst .or. this%st_start > this%st_end)
then
176 message(1) =
"OutputMEEnd must be positive, smaller or equal to the number of states, and larger than OutputMEStart"
179 this%nst = this%st_end - this%st_start +1
186 subroutine output_me(this, namespace, space, dir, st, gr, ions, hm)
189 class(
space_t),
intent(in) :: space
190 character(len=*),
intent(in) :: dir
192 type(
grid_t),
intent(in) :: gr
193 type(
ions_t),
intent(in) :: ions
196 integer :: id, ll, iunit
197 character(len=256) :: fname
198 real(real64),
allocatable :: doneint(:), dtwoint(:)
199 complex(real64),
allocatable :: zoneint(:), ztwoint(:)
200 integer,
allocatable :: iindex(:,:), jindex(:,:), kindex(:,:), lindex(:,:)
205 if (this%what(option__outputmatrixelements__momentum))
then
206 write(fname,
'(2a)') trim(dir),
'/ks_me_momentum'
210 if (this%what(option__outputmatrixelements__ang_momentum))
then
211 write(fname,
'(2a)') trim(dir),
'/ks_me_angular_momentum'
215 if (this%what(option__outputmatrixelements__ks_multipoles))
then
219 if (this%what(option__outputmatrixelements__dipole))
then
220 assert(.not. st%parallel_in_states)
224 if (this%what(option__outputmatrixelements__one_body))
then
225 message(1) =
"Computing one-body matrix elements"
228 if (st%parallel_in_states)
call messages_not_implemented(
"OutputMatrixElements=one_body with states parallelization", &
230 if (st%d%kpt%parallel)
call messages_not_implemented(
"OutputMatrixElements=one_body with k-points parallelization", &
236 iunit =
io_open(trim(dir)//
'/output_me_one_body', namespace, action=
'write')
238 id = st%nst*(st%nst+1)/2
240 safe_allocate(iindex(1:id,1))
241 safe_allocate(jindex(1:id,1))
244 safe_allocate(doneint(1:id))
245 call one_body_me(gr, st, namespace, hm, iindex(:,1), jindex(:,1), doneint)
248 write(iunit, *) iindex(ll,1), jindex(ll,1), doneint(ll)
251 safe_deallocate_a(doneint)
253 safe_allocate(zoneint(1:id))
254 call one_body_me(gr, st, namespace, hm, iindex(:,1), jindex(:,1), zoneint)
257 write(iunit, *) iindex(ll,1), jindex(ll,1), zoneint(ll)
260 safe_deallocate_a(zoneint)
263 safe_deallocate_a(iindex)
264 safe_deallocate_a(jindex)
268 if (this%what(option__outputmatrixelements__two_body) .or. this%what(option__outputmatrixelements__two_body_exc_k))
then
269 message(1) =
"Computing two-body matrix elements"
272 assert(.not. st%parallel_in_states)
273 if (this%what(option__outputmatrixelements__two_body))
then
274 if (st%parallel_in_states)
then
277 if (st%d%kpt%parallel)
then
281 iunit =
io_open(trim(dir)//
'/output_me_two_body', namespace, action=
'write')
283 write(iunit,
'(a)')
'# (n1, k1) (n2, k2) (n3, k3) (n4, k4) (n1-k1, n2-k2|n3-k3, n4-k4)'
286 if (st%parallel_in_states)
then
287 call messages_not_implemented(
"OutputMatrixElements=two_body_exc_k with states parallelization", namespace=namespace)
289 if (st%d%kpt%parallel)
then
290 call messages_not_implemented(
"OutputMatrixElements=two_body_exc_k with k-points parallelization", namespace=namespace)
293 iunit =
io_open(trim(dir)//
'/output_me_two_body_density', namespace, action=
'write')
295 write(iunit,
'(a)')
'#(n1, k1) (n2, k2) (n1-k1, n1-k2|n2-k2, n2-k1)'
299 if (this%what(option__outputmatrixelements__two_body))
then
301 id = st%nik*this%nst*(st%nik*this%nst+1)*(st%nik**2*this%nst**2+st%nik*this%nst+2)/8
303 id = (st%nik*this%nst)**4
306 id = (st%nik*this%nst)**2
313 safe_allocate(iindex(1:2, 1:id))
314 safe_allocate(jindex(1:2, 1:id))
315 safe_allocate(kindex(1:2, 1:id))
316 safe_allocate(lindex(1:2, 1:id))
319 safe_allocate(dtwoint(1:id))
320 call two_body_me(gr, st, space, namespace, hm%kpoints, hm%exxop%psolver, this%st_start, this%st_end, &
321 iindex, jindex, kindex, lindex, dtwoint)
324 write(iunit,
'(4(i4,i5,1x),es22.12)') iindex(1:2,ll), jindex(1:2,ll), kindex(1:2,ll), lindex(1:2,ll), dtwoint(ll)
327 safe_deallocate_a(dtwoint)
329 safe_allocate(ztwoint(1:id))
330 if (hm%phase%is_allocated())
then
332 assert(.not. st%d%kpt%parallel)
333 call two_body_me(gr, st, space, namespace, hm%kpoints, hm%exxop%psolver, this%st_start, this%st_end, iindex, jindex, &
334 kindex, lindex, ztwoint, phase = hm%phase, singularity = singul, &
335 exc_k = (this%what(option__outputmatrixelements__two_body_exc_k)))
337 call two_body_me(gr, st, space, namespace, hm%kpoints, hm%exxop%psolver, this%st_start, this%st_end, &
338 iindex, jindex, kindex, lindex, ztwoint, exc_k = (this%what(option__outputmatrixelements__two_body_exc_k)))
342 if (this%what(option__outputmatrixelements__two_body))
then
344 write(iunit,
'(4(i4,i5,1x),2es22.12)') iindex(1:2,ll), jindex(1:2,ll), kindex(1:2,ll), lindex(1:2,ll), ztwoint(ll)
348 write(iunit,
'(2(i4,i5),2es22.12)') iindex(1:2,ll), kindex(1:2,ll), ztwoint(ll)
352 safe_deallocate_a(ztwoint)
355 safe_deallocate_a(iindex)
356 safe_deallocate_a(jindex)
357 safe_deallocate_a(kindex)
358 safe_deallocate_a(lindex)
372 type(
grid_t),
intent(in) :: gr
374 type(
space_t),
intent(in) :: space
375 character(len=*),
intent(in) :: fname
379 integer :: ik, ist, is, ns, iunit, idir, dim
380 character(len=80) :: cspin, str_tmp
381 real(real64) :: kpoint(space%dim)
382 real(real64),
allocatable :: momentum(:,:,:)
388 safe_allocate(momentum(1:dim, 1:st%nst, 1:st%nik))
393 iunit =
io_open(fname, namespace, action=
'write')
396 if (st%d%nspin == 2) ns = 2
398 write(
message(1),
'(a)')
'Momentum of the KS states [a.u.]:'
400 if (st%nik > ns)
then
405 do ik = 1, st%nik, ns
406 kpoint(:) = kpoints%get_point(st%d%get_kpoint_index(ik))
408 if (st%nik > ns)
then
409 write(
message(1),
'(a,i4, a)')
'#k =', ik,
', k = ('
413 if (idir == dim)
then
422 write(
message(1),
'(a4,1x,a5)')
'#st',
' Spin'
424 write(str_tmp,
'(a,a1,a)')
' <p',
index2axis(idir),
'>'
427 write(str_tmp,
'(4x,a12,1x)')
'Occupation '
434 if (is == 0) cspin =
'up'
435 if (is == 1) cspin =
'dn'
438 write(
message(1),
'(i4,3x,a2,1x)') ist, trim(cspin)
440 write(str_tmp,
'(f12.6)') momentum(idir, ist, ik+is)
443 write(str_tmp,
'(3x,f12.6)') st%occ(ist, ik+is)
455 safe_deallocate_a(momentum)
466 type(
space_t),
intent(in) :: space
467 character(len=*),
intent(in) :: fname
471 integer :: iunit, ik, ist, is, ns, idir, k_start, k_end, k_n, dim, st_start, st_end, nst
472 character(len=80) :: tmp_str(space%dim), cspin
473 real(real64) :: angular(3), lsquare, kpoint(space%dim)
474 real(real64),
allocatable :: ang(:, :, :), ang2(:, :)
478 real(real64),
allocatable :: lang(:, :)
483 if (st%d%nspin == 2) ns = 2
484 assert(space%dim == 3)
487 st_start = st%st_start
491 iunit =
io_open(fname, namespace, action=
'write')
494 write(iunit,
'(a)')
'Warning: When non-local pseudopotentials are used '
495 write(iunit,
'(a)')
' the numbers below may be meaningless. '
496 write(iunit,
'(a)')
' '
497 write(iunit,
'(a)')
'Angular Momentum of the KS states [dimensionless]:'
499 if (st%nik > ns)
then
505 safe_allocate(ang(1:nst, 1:st%nik, 1:3))
506 safe_allocate(ang2(1:nst, 1:st%nik))
511 k_start = st%d%kpt%start
518 if (st%d%kpt%parallel)
then
519 k_n = st%d%kpt%nlocal
521 assert(.not. st%parallel_in_states)
524 safe_allocate(lang(1:st%lnst, 1:k_n))
526 lang(1:st%lnst, 1:k_n) = ang(st_start:st_end, k_start:k_end, idir)
527 call st%d%kpt%mpi_grp%allgatherv(lang, nst*k_n, mpi_double_precision, ang(:, :, idir), &
528 st%d%kpt%num(:)*nst, (st%d%kpt%range(1, :) - 1)*nst, mpi_double_precision)
530 lang(1:st%lnst, 1:k_n) = ang2(st_start:st_end, k_start:k_end)
531 call st%d%kpt%mpi_grp%allgatherv(lang, nst*k_n, mpi_double_precision, ang2, &
532 st%d%kpt%num(:)*nst, (st%d%kpt%range(1, :) - 1)*nst, mpi_double_precision)
533 safe_deallocate_a(lang)
536 if (st%parallel_in_states)
then
537 safe_allocate(lang(1:st%lnst, 1))
540 do ik = 1, st%nik, ns
541 if (st%nik > ns)
then
543 kpoint(:) = kpoints%get_point(st%d%get_kpoint_index(ik))
545 write(
message(1),
'(a,i4, a)')
'#k =', ik,
', k = ('
549 if (idir == dim)
then
559 if (st%parallel_in_states)
then
560 assert(.not. st%d%kpt%parallel)
564 lang(1:st%lnst, 1) = ang(st_start:st_end, ik+is-1, idir)
567 lang(1:st%lnst, 1) = ang2(st_start:st_end, ik+is-1)
573 write(
message(1),
'(a4,1x,a5,4a12,4x,a12,1x)') &
574 '#st',
' Spin',
' <Lx>',
' <Ly>',
' <Lz>',
' <L2>',
'Occupation '
581 if (is == 0) cspin =
'up'
582 if (is == 1) cspin =
'dn'
585 write(tmp_str(1),
'(i4,3x,a2)') ist, trim(cspin)
586 write(tmp_str(2),
'(1x,4f12.6,3x,f12.6)') &
587 (ang(ist, ik+is, idir), idir = 1, 3), ang2(ist, ik+is), st%occ(ist, ik+is)
588 message(1) = trim(tmp_str(1))//trim(tmp_str(2))
598 write(
message(1),
'(a)')
'Total Angular Momentum L [dimensionless]'
599 write(
message(2),
'(10x,4f12.6)') angular(1:3), lsquare
604 if (st%parallel_in_states)
then
605 safe_deallocate_a(lang)
608 safe_deallocate_a(ang)
609 safe_deallocate_a(ang2)
615 type(
grid_t),
intent(in) :: gr
617 type(
space_t),
intent(in) :: space
618 character(len=*),
intent(in) :: dir
621 type(
ions_t),
intent(in) :: ions
622 integer,
intent(in) :: st_start, st_end
624 integer :: ik, idir, ist, jst, iunit
625 character(len=256) :: fname
626 real(real64),
allocatable :: ddip_elements(:,:,:)
627 complex(real64),
allocatable :: zdip_elements(:,:,:)
632 do ik = st%d%kpt%start, st%d%kpt%end
633 write(fname,
'(i8)') ik
634 write(fname,
'(a)') trim(dir)//
'/ks_me_dipole.k'//trim(adjustl(fname))//
'_'
638 safe_allocate(ddip_elements(1:space%dim, st_start:st_end, st_start:st_end))
640 call dipole_me(gr, st, namespace, hm, ions, ik, st_start, st_end, ddip_elements)
642 do idir = 1, space%dim
644 write(iunit,
'(a)')
'# Dipole matrix elements file: |<Phi_i | r | Phi_j>|'
645 write(iunit,
'(a,i8)')
'# ik =', ik
648 do ist = st_start, st_end
649 do jst = st_start, st_end
651 write(iunit, fmt=
'(a)', advance =
'no')
' '
653 write(iunit,
'(a)')
''
657 safe_deallocate_a(ddip_elements)
660 safe_allocate(zdip_elements(1:space%dim, st_start:st_end, st_start:st_end))
662 call dipole_me(gr, st, namespace, hm, ions, ik, st_start, st_end, zdip_elements)
664 do idir = 1, space%dim
666 write(iunit,
'(a)')
'# Dipole matrix elements file: |<Phi_i | r | Phi_j>|'
667 write(iunit,
'(a,i8)')
'# ik =', ik
670 do ist = st_start, st_end
671 do jst = st_start, st_end
673 write(iunit, fmt=
'(a)', advance =
'no')
' '
675 write(iunit,
'(a)')
''
679 safe_deallocate_a(zdip_elements)
687 type(
grid_t),
intent(in) :: gr
689 type(
space_t),
intent(in) :: space
690 character(len=*),
intent(in) :: dir
694 integer :: id, ll, mm, ik, iunit
695 character(len=256) :: fname
696 real(real64),
allocatable :: delements(:,:)
697 complex(real64),
allocatable :: zelements(:,:)
704 select case (space%dim)
706 do ll = 1, this%ks_multipoles
709 write(fname,
'(i4)') id
710 write(fname,
'(a)') trim(dir) //
'/ks_me_multipoles.' // trim(adjustl(fname))
711 iunit =
io_open(fname, namespace, action =
'write')
716 safe_allocate(delements(1:st%nst, 1:st%nst))
719 safe_deallocate_a(delements)
721 safe_allocate(zelements(1:st%nst, 1:st%nst))
724 safe_deallocate_a(zelements)
734 write(fname,
'(i4)') id
735 write(fname,
'(a)') trim(dir) //
'/ks_me_multipoles.' // trim(adjustl(fname))
736 iunit =
io_open(fname, namespace, action =
'write')
741 safe_allocate(delements(1:st%nst, 1:st%nst))
744 safe_deallocate_a(delements)
746 safe_allocate(zelements(1:st%nst, 1:st%nst))
749 safe_deallocate_a(zelements)
756 do ll = 1, this%ks_multipoles
758 write(fname,
'(i4)') id
759 write(fname,
'(a)') trim(dir) //
'/ks_me_multipoles.' // trim(adjustl(fname))
760 iunit =
io_open(fname, namespace, action =
'write')
765 safe_allocate(delements(1:st%nst, 1:st%nst))
768 safe_deallocate_a(delements)
770 safe_allocate(zelements(1:st%nst, 1:st%nst))
773 safe_deallocate_a(zelements)
787 integer,
intent(in) :: iunit, ll, mm, ik
789 write(iunit, fmt =
'(a)')
'# Multipole matrix elements file: <Phi_i | r**l * Y_{lm}(theta,phi) | Phi_j>'
790 write(iunit, fmt =
'(a,i2,a,i2)')
'# l =', ll,
'; m =', mm
791 write(iunit, fmt =
'(a,i8)')
'# ik =', ik
800 integer,
intent(in) :: iunit, nst
801 real(real64),
intent(in) :: elements(:,:)
802 integer,
optional,
intent(in) :: ll
805 real(real64) :: element
810 write(iunit, fmt=
'(f20.12, a)', advance =
'no') element,
' '
812 write(iunit,
'(a)')
''
817 integer,
intent(in) :: iunit, nst
818 complex(real64),
intent(in) :: elements(:,:)
819 integer,
optional,
intent(in) :: ll
822 complex(real64) :: element
827 write(iunit, fmt=
'(f20.12,a1,f20.12,a)', advance =
'no') real(element),
',',aimag(element),
' '
829 write(iunit,
'(a)')
''
840#include "complex.F90"
subroutine, public elec_angular_momentum_me(gr, st, space, ll, l2)
subroutine, public elec_momentum_me(gr, st, space, kpoints, momentum)
integer, parameter, public unpolarized
Parameters...
integer, parameter, public spinors
This module implements the underlying real-space grid.
subroutine, public io_function_read_what_how_when(namespace, space, what, how, output_interval, what_tag_in, how_tag_in, output_interval_tag_in, ignore_error)
subroutine, public io_close(iunit, grp)
integer function, public io_open(file, namespace, action, status, form, position, die, recl, grp)
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 contains some common usage patterns of MPI routines.
logical function mpi_grp_is_root(grp)
Is the current MPI process of grpcomm, root.
type(mpi_grp_t), public mpi_world
this module contains the low-level part of the output system
subroutine output_me_out_ang_momentum(gr, st, space, fname, namespace, kpoints)
subroutine output_me_out_momentum(gr, st, space, fname, namespace, kpoints)
subroutine output_me_out_dipole(gr, st, space, dir, namespace, hm, ions, st_start, st_end)
subroutine, public output_me_init(this, namespace, space, st, gr, nst)
subroutine, public output_me(this, namespace, space, dir, st, gr, ions, hm)
subroutine output_me_out_ks_multipoles(gr, st, space, dir, this, namespace)
subroutine, public singularity_end(this)
subroutine, public singularity_init(this, namespace, space, st, kpoints)
pure logical function, public states_are_complex(st)
pure logical function, public states_are_real(st)
This module handles spin dimensions of the states and the k-point distribution.
real(real64) function, public states_elec_eigenvalues_sum(st, alt_eig)
function to calculate the eigenvalues sum using occupations as weights
brief This module defines the class unit_t which is used by the unit_systems_oct_m module.
character(len=20) pure function, public units_abbrev(this)
This module defines the unit system, used for input and output.
type(unit_system_t), public units_out
type(unit_t), public unit_one
some special units required for particular quantities
This module is intended to contain simple general-purpose utility functions and procedures.
character pure function, public index2axis(idir)
logical pure function, public family_is_mgga_with_exc(xcs)
Is the xc function part of the mGGA family with an energy functional.
subroutine print_ks_multipole_header(iunit, ll, mm, ik)
subroutine zprint_ks_multipole(iunit, nst, elements, ll)
subroutine dprint_ks_multipole(iunit, nst, elements, ll)
Description of the grid, containing information on derivatives, stencil, and symmetries.
Output information for matrix elements.
The states_elec_t class contains all electronic wave functions.