51#if defined(HAVE_BERKELEYGW)
67 integer,
intent(in) :: nst
68 type(namespace_t),
intent(in) :: namespace
69 type(output_bgw_t),
intent(out) :: bgw
70 integer,
intent(in) :: periodic_dim
80#ifndef HAVE_BERKELEYGW
81 message(1) =
"Cannot do BerkeleyGW output: the library was not linked."
93 call parse_variable(namespace,
'BerkeleyGW_NumberBands', nst, bgw%nbands)
96 if (bgw%nbands > nst)
then
97 message(1) =
"BerkeleyGW_NumberBands must be <= number of states."
109 call parse_variable(namespace,
'BerkeleyGW_Vxc_diag_nmin', 1, bgw%vxc_diag_nmin)
111 if (bgw%vxc_diag_nmin > nst)
then
112 message(1) =
"BerkeleyGW_Vxc_diag_nmin must be <= number of states."
124 call parse_variable(namespace,
'BerkeleyGW_Vxc_diag_nmax', nst, bgw%vxc_diag_nmax)
126 if (bgw%vxc_diag_nmax > nst)
then
127 message(1) =
"BerkeleyGW_Vxc_diag_nmax must be <= number of states."
131 if (bgw%vxc_diag_nmin <= 0 .or. bgw%vxc_diag_nmax <= 0)
then
132 bgw%vxc_diag_nmin = 0
133 bgw%vxc_diag_nmax = 0
144 call parse_variable(namespace,
'BerkeleyGW_Vxc_offdiag_nmin', 1, bgw%vxc_offdiag_nmin)
146 if (bgw%vxc_offdiag_nmin > nst)
then
147 message(1) =
"BerkeleyGW_Vxc_offdiag_nmin must be <= number of states."
159 call parse_variable(namespace,
'BerkeleyGW_Vxc_offdiag_nmax', nst, bgw%vxc_offdiag_nmax)
161 if (bgw%vxc_offdiag_nmax > nst)
then
162 message(1) =
"BerkeleyGW_Vxc_offdiag_nmax must be <= number of states."
166 if (bgw%vxc_offdiag_nmin <= 0 .or. bgw%vxc_offdiag_nmax <= 0)
then
167 bgw%vxc_offdiag_nmin = 0
168 bgw%vxc_offdiag_nmax = 0
191 call parse_variable(namespace,
'BerkeleyGW_WFN_filename',
'WFN', bgw%wfn_filename)
202 call parse_variable(namespace,
'BerkeleyGW_CalcExchange', .false., bgw%calc_exchange)
217 call parse_variable(namespace,
'BerkeleyGW_CalcDipoleMtxels', .false., bgw%calc_vmtxel)
229 bgw%vmtxel_polarization(1:3) =
m_zero
230 bgw%vmtxel_polarization(1) =
m_one
232 if (bgw%calc_vmtxel .and.
parse_block(namespace,
'BerkeleyGW_VmtxelPolarization', blk) == 0)
then
236 if (idir <= periodic_dim .and. abs(bgw%vmtxel_polarization(idir)) >
m_epsilon)
then
237 message(1) =
"You cannot calculate vmtxel with polarization in a periodic direction. Use WFNq_fi instead."
242 norm = sum(abs(bgw%vmtxel_polarization(1:3))**2)
244 message(1) =
"A non-zero value must be set for BerkeleyGW_VmtxelPolarization when BerkeleyGW_CalcDipoleMtxels = yes."
247 bgw%vmtxel_polarization(1:3) = bgw%vmtxel_polarization(1:3) /
sqrt(norm)
259 if (bgw%calc_vmtxel)
call parse_variable(namespace,
'BerkeleyGW_VmtxelNumCondBands', 0, bgw%vmtxel_ncband)
271 if (bgw%calc_vmtxel)
call parse_variable(namespace,
'BerkeleyGW_VmtxelNumValBands', 0, bgw%vmtxel_nvband)
282 class(
space_t),
intent(in) :: space
283 character(len=*),
intent(in) :: dir
285 type(
grid_t),
target,
intent(in) :: gr
286 type(
v_ks_t),
intent(inout) :: ks
288 type(
ions_t),
intent(in) :: ions
290#ifdef HAVE_BERKELEYGW
291 integer :: ik, is, ikk, ist, itran, iunit, iatom, mtrx(3, 3, 48), fftgrid(3), ngkmax
292 integer,
pointer :: atyp(:)
293 integer,
allocatable :: ifmin(:,:), ifmax(:,:), ngk(:)
294 character(len=3) :: sheader
295 real(real64) :: adot(3,3), bdot(3,3), recvol, tnp(3, 48), ecutrho, ecutwfc
296 real(real64),
allocatable :: energies(:,:,:), occupations(:,:,:)
297 real(real64),
pointer :: apos(:,:)
298 real(real64),
allocatable :: vxc(:,:), dpsi(:,:)
299 complex(real64),
allocatable :: field_g(:,:), zpsi(:,:)
307 if (space%dim /= 3)
then
308 message(1) =
"BerkeleyGW output only available in 3D."
314 if (st%parallel_in_states)
call messages_not_implemented(
"BerkeleyGW output parallel in states", namespace=namespace)
318 if (ks%theory_level ==
hartree .or. ks%theory_level ==
hartree_fock .or. xc_is_orbital_dependent(ks%xc))
then
324#ifdef HAVE_BERKELEYGW
326 safe_allocate(vxc(1:gr%np, 1:st%d%nspin))
329 call xc_get_vxc(gr, ks%xc, st, hm%kpoints, hm%psolver, namespace, space, st%rho, st%d%ispin, &
330 hm%ions%latt%rcell_volume, vxc)
332 message(1) =
"BerkeleyGW output: vxc.dat"
337 call dbgw_vxc_dat(bgw, namespace, space, dir, st, gr, hm, vxc)
339 call zbgw_vxc_dat(bgw, namespace, space, dir, st, gr, hm, vxc)
342 call cube_init(cube, gr%idx%ll, namespace, space, gr%spacing, gr%coord_system, &
345 if (any(gr%idx%ll(1:3) /= fftgrid(1:3)))
then
346 message(1) =
"Cannot do BerkeleyGW output: FFT grid has been modified."
354 ecutrho = shell_density%ekin_cutoff
355 safe_allocate(field_g(1:shell_density%ngvectors, 1:st%d%nspin))
360 if (bgw%calc_vmtxel)
then
361 write(
message(1),
'(a,3f12.6)')
"BerkeleyGW output: vmtxel. Polarization = ", bgw%vmtxel_polarization(1:3)
365 call dbgw_vmtxel(bgw, namespace, dir, st, gr, ifmax)
367 call zbgw_vmtxel(bgw, namespace, dir, st, gr, ifmax)
371 message(1) =
"BerkeleyGW output: VXC"
376 iunit =
io_open(trim(dir) //
'VXC', namespace, form =
'unformatted', action =
'write')
380 vxc(:,:) = vxc(:,:) *
m_two / (product(cube%rs_n_global(1:3)) * gr%volume_element)
381 call dbgw_write_fs(namespace, iunit, vxc, field_g, shell_density, st%d%nspin, gr, cube, cf, is_wfn = .false.)
383 safe_deallocate_a(vxc)
386 message(1) =
"BerkeleyGW output: RHO"
391 iunit =
io_open(trim(dir) //
'RHO', namespace, form =
'unformatted', action =
'write')
394 call dbgw_write_fs(namespace, iunit, st%rho, field_g, shell_density, st%d%nspin, gr, cube, cf, is_wfn = .false.)
397 message(1) =
"BerkeleyGW output: WFN"
398 write(
message(2),
'(a,f12.6,a)')
"Wavefunction cutoff for BerkeleyGW: ", &
403 safe_allocate(dpsi(1:gr%np, 1:st%d%nspin))
405 safe_allocate(zpsi(1:gr%np, 1:st%d%nspin))
410 iunit =
io_open(trim(dir) // bgw%wfn_filename, namespace, form =
'unformatted', action =
'write')
417 do ik = st%d%kpt%start, st%d%kpt%end, st%d%nspin
418 call fourier_shell_init(shell_wfn, namespace, space, cube, gr, kk = hm%kpoints%reduced%red_point(:, ik))
421 call write_binary_gvectors(iunit, shell_wfn%ngvectors, shell_wfn%ngvectors, shell_wfn%red_gvec)
424 do is = 1, st%d%nspin
433 call dbgw_write_fs(namespace, iunit, dpsi, field_g, shell_wfn, st%d%nspin, gr, cube, cf, is_wfn = .
true.)
435 call zbgw_write_fs(namespace, iunit, zpsi, field_g, shell_wfn, st%d%nspin, gr, cube, cf, is_wfn = .
true.)
449 safe_deallocate_a(dpsi)
451 safe_deallocate_a(zpsi)
453 safe_deallocate_a(vxc)
454 safe_deallocate_a(field_g)
455 safe_deallocate_a(ifmin)
456 safe_deallocate_a(ifmax)
457 safe_deallocate_a(ngk)
458 safe_deallocate_a(energies)
459 safe_deallocate_a(occupations)
460 safe_deallocate_p(atyp)
461 safe_deallocate_p(apos)
464 message(1) =
"Cannot do BerkeleyGW output: the library was not linked."
470#ifdef HAVE_BERKELEYGW
476 if (space%periodic_dim /= 3)
then
477 message(1) =
"BerkeleyGW for mixed-periodicity is currently not implemented."
485 adot(1:3, 1:3) = matmul(ions%latt%rlattice(1:3, 1:3), ions%latt%rlattice(1:3, 1:3))
486 bdot(1:3, 1:3) = matmul(ions%latt%klattice(1:3, 1:3), ions%latt%klattice(1:3, 1:3))
487 recvol = (
m_two *
m_pi)**3 / ions%latt%rcell_volume
496 safe_allocate(ifmin(1:hm%kpoints%reduced%npoints, 1:st%d%nspin))
497 safe_allocate(ifmax(1:hm%kpoints%reduced%npoints, 1:st%d%nspin))
498 safe_allocate(energies(1:st%nst, 1:hm%kpoints%reduced%npoints, 1:st%d%nspin))
499 safe_allocate(occupations(1:st%nst, 1:hm%kpoints%reduced%npoints, 1:st%d%nspin))
507 is = st%d%get_spin_index(ik)
508 ikk = st%d%get_kpoint_index(ik)
509 energies(1:st%nst, ikk, is) = st%eigenval(1:st%nst,ik) *
m_two
510 occupations(1:st%nst, ikk, is) = st%occ(1:st%nst, ik) / st%smear%el_per_state
513 if (st%eigenval(ist, ik) < st%smear%e_fermi +
m_epsilon)
then
521 safe_allocate(ngk(1:hm%kpoints%reduced%npoints))
522 do ik = 1, st%nik, st%d%nspin
523 call fourier_shell_init(shell_wfn, namespace, space, cube, gr, kk = hm%kpoints%reduced%red_point(:, ik))
524 if (ik == 1) ecutwfc = shell_wfn%ekin_cutoff
525 ngk(ik) = shell_wfn%ngvectors
530 safe_allocate(atyp(1:ions%natoms))
531 safe_allocate(apos(1:3, 1:ions%natoms))
532 do iatom = 1, ions%natoms
533 atyp(iatom) = ions%atom(iatom)%species%get_index()
534 apos(1:3, iatom) = ions%pos(1:3, iatom)
537 if (any(hm%kpoints%nik_axis(1:3) == 0))
then
538 message(1) =
"KPointsGrid has a zero component. Set KPointsGrid appropriately,"
539 message(2) =
"or this WFN will only be usable in BerkeleyGW's inteqp."
548 character(len=3),
intent(inout) :: sheader
549 integer,
intent(in) :: iunit
553 call write_binary_header(iunit, sheader, 2, st%d%nspin, shell_density%ngvectors, &
555 hm%kpoints%reduced%npoints, st%nst, ngkmax, ecutrho *
m_two, &
556 ecutwfc *
m_two, fftgrid, hm%kpoints%nik_axis, hm%kpoints%full%shifts, &
557 ions%latt%rcell_volume,
m_one, ions%latt%rlattice, adot, recvol, &
558 m_one, ions%latt%klattice, bdot, mtrx, tnp, atyp, &
559 apos, ngk, hm%kpoints%reduced%weight, hm%kpoints%reduced%red_point, &
560 ifmin, ifmax, energies, occupations, warn = .false.)
562 call write_binary_gvectors(iunit, shell_density%ngvectors, shell_density%ngvectors, shell_density%red_gvec)
572#include "complex.F90"
573#ifdef HAVE_BERKELEYGW
574#include "output_berkeleygw_inc.F90"
579#ifdef HAVE_BERKELEYGW
580#include "output_berkeleygw_inc.F90"
double sqrt(double __x) __attribute__((__nothrow__
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_init(cube, nn, namespace, space, spacing, coord_system, fft_type, fft_library, dont_optimize, nn_out, mpi_grp, need_partition, tp_enlarge, blocksize)
subroutine, public cube_end(cube)
subroutine, public cube_init_cube_map(cube, mesh)
integer, parameter, public spinors
Fast Fourier Transform module. This module provides a single interface that works with different FFT ...
integer, parameter, public fft_complex
real(real64) function, public fourier_shell_cutoff(space, cube, mesh, is_wfn, dg)
subroutine, public fourier_shell_init(this, namespace, space, cube, mesh, kk)
subroutine, public fourier_shell_end(this)
subroutine, public cube_function_free_fs(cube, cf)
Deallocates the Fourier space grid.
subroutine, public cube_function_alloc_fs(cube, cf, force_alloc)
Allocates locally the Fourier space grid, if PFFT library is not used. Otherwise, it assigns the PFFT...
real(real64), parameter, public m_two
real(real64), parameter, public m_zero
real(real64), parameter, public m_pi
some mathematical constants
real(real64), parameter, public m_epsilon
real(real64), parameter, public m_one
This module implements the underlying real-space grid.
subroutine, public io_close(iunit, grp)
integer function, public io_open(file, namespace, action, status, form, position, die, recl, grp)
A module to handle KS potential, without the external potential.
integer, parameter, public hartree
integer, parameter, public hartree_fock
This module defines various routines, operating on mesh functions.
subroutine, public messages_not_implemented(feature, namespace)
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)
logical function mpi_grp_is_root(grp)
Is the current MPI process of grpcomm, root.
type(mpi_grp_t), public mpi_world
subroutine zbgw_write_fs(namespace, iunit, field_r, field_g, shell, nspin, gr, cube, cf, is_wfn)
subroutine zbgw_vmtxel(bgw, namespace, dir, st, gr, ifmax)
Calculate 'vmtxel' file of dipole matrix elements for BerkeleyGW BSE.
subroutine dbgw_vmtxel(bgw, namespace, dir, st, gr, ifmax)
Calculate 'vmtxel' file of dipole matrix elements for BerkeleyGW BSE.
subroutine dbgw_write_fs(namespace, iunit, field_r, field_g, shell, nspin, gr, cube, cf, is_wfn)
subroutine, public output_berkeleygw(bgw, namespace, space, dir, st, gr, ks, hm, ions)
subroutine, public output_berkeleygw_init(nst, namespace, bgw, periodic_dim)
subroutine zbgw_vxc_dat(bgw, namespace, space, dir, st, gr, hm, vxc)
subroutine dbgw_vxc_dat(bgw, namespace, space, dir, st, gr, hm, vxc)
this module contains the low-level part of the output system
integer function, public parse_block(namespace, name, blk, check_varinfo_)
pure logical function, public states_are_real(st)
This module handles spin dimensions of the states and the k-point distribution.
real(real64) function, dimension(1:this%dim), public symm_op_translation_vector_red(this)
integer function, dimension(1:this%dim, 1:this%dim), public symm_op_rotation_matrix_red(this)
integer pure function, public symmetries_number(this)
subroutine bgw_setup_header()
subroutine bgw_write_header(sheader, iunit)
Description of the grid, containing information on derivatives, stencil, and symmetries.
Output information for BerkeleyGW.
The states_elec_t class contains all electronic wave functions.