51#if defined(HAVE_BERKELEYGW)
68 integer,
intent(in) :: nst
69 type(namespace_t),
intent(in) :: namespace
70 type(output_bgw_t),
intent(out) :: bgw
71 integer,
intent(in) :: periodic_dim
81#ifndef HAVE_BERKELEYGW
82 message(1) =
"Cannot do BerkeleyGW output: the library was not linked."
94 call parse_variable(namespace,
'BerkeleyGW_NumberBands', nst, bgw%nbands)
97 if (bgw%nbands > nst)
then
98 message(1) =
"BerkeleyGW_NumberBands must be <= number of states."
110 call parse_variable(namespace,
'BerkeleyGW_Vxc_diag_nmin', 1, bgw%vxc_diag_nmin)
112 if (bgw%vxc_diag_nmin > nst)
then
113 message(1) =
"BerkeleyGW_Vxc_diag_nmin must be <= number of states."
125 call parse_variable(namespace,
'BerkeleyGW_Vxc_diag_nmax', nst, bgw%vxc_diag_nmax)
127 if (bgw%vxc_diag_nmax > nst)
then
128 message(1) =
"BerkeleyGW_Vxc_diag_nmax must be <= number of states."
132 if (bgw%vxc_diag_nmin <= 0 .or. bgw%vxc_diag_nmax <= 0)
then
133 bgw%vxc_diag_nmin = 0
134 bgw%vxc_diag_nmax = 0
145 call parse_variable(namespace,
'BerkeleyGW_Vxc_offdiag_nmin', 1, bgw%vxc_offdiag_nmin)
147 if (bgw%vxc_offdiag_nmin > nst)
then
148 message(1) =
"BerkeleyGW_Vxc_offdiag_nmin must be <= number of states."
160 call parse_variable(namespace,
'BerkeleyGW_Vxc_offdiag_nmax', nst, bgw%vxc_offdiag_nmax)
162 if (bgw%vxc_offdiag_nmax > nst)
then
163 message(1) =
"BerkeleyGW_Vxc_offdiag_nmax must be <= number of states."
167 if (bgw%vxc_offdiag_nmin <= 0 .or. bgw%vxc_offdiag_nmax <= 0)
then
168 bgw%vxc_offdiag_nmin = 0
169 bgw%vxc_offdiag_nmax = 0
192 call parse_variable(namespace,
'BerkeleyGW_WFN_filename',
'WFN', bgw%wfn_filename)
203 call parse_variable(namespace,
'BerkeleyGW_CalcExchange', .false., bgw%calc_exchange)
218 call parse_variable(namespace,
'BerkeleyGW_CalcDipoleMtxels', .false., bgw%calc_vmtxel)
230 bgw%vmtxel_polarization(1:3) =
m_zero
231 bgw%vmtxel_polarization(1) =
m_one
233 if (bgw%calc_vmtxel .and.
parse_block(namespace,
'BerkeleyGW_VmtxelPolarization', blk) == 0)
then
237 if (idir <= periodic_dim .and. abs(bgw%vmtxel_polarization(idir)) >
m_epsilon)
then
238 message(1) =
"You cannot calculate vmtxel with polarization in a periodic direction. Use WFNq_fi instead."
243 norm = sum(abs(bgw%vmtxel_polarization(1:3))**2)
245 message(1) =
"A non-zero value must be set for BerkeleyGW_VmtxelPolarization when BerkeleyGW_CalcDipoleMtxels = yes."
248 bgw%vmtxel_polarization(1:3) = bgw%vmtxel_polarization(1:3) /
sqrt(norm)
260 if (bgw%calc_vmtxel)
call parse_variable(namespace,
'BerkeleyGW_VmtxelNumCondBands', 0, bgw%vmtxel_ncband)
272 if (bgw%calc_vmtxel)
call parse_variable(namespace,
'BerkeleyGW_VmtxelNumValBands', 0, bgw%vmtxel_nvband)
283 class(
space_t),
intent(in) :: space
284 character(len=*),
intent(in) :: dir
286 type(
grid_t),
target,
intent(in) :: gr
287 type(
v_ks_t),
intent(inout) :: ks
289 type(
ions_t),
intent(in) :: ions
291#ifdef HAVE_BERKELEYGW
292 integer :: ik, is, ikk, ist, itran, iunit, iatom, mtrx(3, 3, 48), fftgrid(3), ngkmax
293 integer,
pointer :: atyp(:)
294 integer,
allocatable :: ifmin(:,:), ifmax(:,:), ngk(:)
295 character(len=3) :: sheader
296 real(real64) :: adot(3,3), bdot(3,3), recvol, tnp(3, 48), ecutrho, ecutwfc
297 real(real64),
allocatable :: energies(:,:,:), occupations(:,:,:)
298 real(real64),
pointer :: apos(:,:)
299 real(real64),
allocatable :: vxc(:,:), dpsi(:,:)
300 complex(real64),
allocatable :: field_g(:,:), zpsi(:,:)
308 if (space%dim /= 3)
then
309 message(1) =
"BerkeleyGW output only available in 3D."
315 if (st%parallel_in_states)
call messages_not_implemented(
"BerkeleyGW output parallel in states", namespace=namespace)
325#ifdef HAVE_BERKELEYGW
327 safe_allocate(vxc(1:gr%np, 1:st%d%nspin))
330 call xc_get_vxc(gr, ks%xc, st, hm%kpoints, hm%psolver, namespace, space, st%rho, st%d%ispin, &
331 hm%ions%latt%rcell_volume, vxc)
333 message(1) =
"BerkeleyGW output: vxc.dat"
338 call dbgw_vxc_dat(bgw, namespace, space, dir, st, gr, hm, vxc)
340 call zbgw_vxc_dat(bgw, namespace, space, dir, st, gr, hm, vxc)
343 call cube_init(cube, gr%idx%ll, namespace, space, gr%spacing, gr%coord_system, &
346 if (any(gr%idx%ll(1:3) /= fftgrid(1:3)))
then
347 message(1) =
"Cannot do BerkeleyGW output: FFT grid has been modified."
355 ecutrho = shell_density%ekin_cutoff
356 safe_allocate(field_g(1:shell_density%ngvectors, 1:st%d%nspin))
361 if (bgw%calc_vmtxel)
then
362 write(
message(1),
'(a,3f12.6)')
"BerkeleyGW output: vmtxel. Polarization = ", bgw%vmtxel_polarization(1:3)
366 call dbgw_vmtxel(bgw, namespace, dir, st, gr, ifmax)
368 call zbgw_vmtxel(bgw, namespace, dir, st, gr, ifmax)
372 message(1) =
"BerkeleyGW output: VXC"
377 iunit =
io_open(trim(dir) //
'VXC', namespace, form =
'unformatted', action =
'write')
381 vxc(:,:) = vxc(:,:) *
m_two / (product(cube%rs_n_global(1:3)) * gr%volume_element)
382 call dbgw_write_fs(namespace, iunit, vxc, field_g, shell_density, st%d%nspin, gr, cube, cf, is_wfn = .false.)
384 safe_deallocate_a(vxc)
387 message(1) =
"BerkeleyGW output: RHO"
392 iunit =
io_open(trim(dir) //
'RHO', namespace, form =
'unformatted', action =
'write')
395 call dbgw_write_fs(namespace, iunit, st%rho, field_g, shell_density, st%d%nspin, gr, cube, cf, is_wfn = .false.)
398 message(1) =
"BerkeleyGW output: WFN"
399 write(
message(2),
'(a,f12.6,a)')
"Wavefunction cutoff for BerkeleyGW: ", &
404 safe_allocate(dpsi(1:gr%np, 1:st%d%nspin))
406 safe_allocate(zpsi(1:gr%np, 1:st%d%nspin))
411 iunit =
io_open(trim(dir) // bgw%wfn_filename, namespace, form =
'unformatted', action =
'write')
418 do ik = st%d%kpt%start, st%d%kpt%end, st%d%nspin
419 call fourier_shell_init(shell_wfn, namespace, space, cube, gr, kk = hm%kpoints%reduced%red_point(:, ik))
422 call write_binary_gvectors(iunit, shell_wfn%ngvectors, shell_wfn%ngvectors, shell_wfn%red_gvec)
425 do is = 1, st%d%nspin
434 call dbgw_write_fs(namespace, iunit, dpsi, field_g, shell_wfn, st%d%nspin, gr, cube, cf, is_wfn = .
true.)
436 call zbgw_write_fs(namespace, iunit, zpsi, field_g, shell_wfn, st%d%nspin, gr, cube, cf, is_wfn = .
true.)
450 safe_deallocate_a(dpsi)
452 safe_deallocate_a(zpsi)
454 safe_deallocate_a(vxc)
455 safe_deallocate_a(field_g)
456 safe_deallocate_a(ifmin)
457 safe_deallocate_a(ifmax)
458 safe_deallocate_a(ngk)
459 safe_deallocate_a(energies)
460 safe_deallocate_a(occupations)
461 safe_deallocate_p(atyp)
462 safe_deallocate_p(apos)
465 message(1) =
"Cannot do BerkeleyGW output: the library was not linked."
471#ifdef HAVE_BERKELEYGW
477 if (space%periodic_dim /= 0 .and. space%periodic_dim /= 3)
then
478 message(1) =
"BerkeleyGW for mixed-periodicity is currently not implemented."
486 adot(1:3, 1:3) = matmul(ions%latt%rlattice(1:3, 1:3), ions%latt%rlattice(1:3, 1:3))
487 bdot(1:3, 1:3) = matmul(ions%latt%klattice(1:3, 1:3), ions%latt%klattice(1:3, 1:3))
488 recvol = (
m_two *
m_pi)**3 / ions%latt%rcell_volume
497 safe_allocate(ifmin(1:hm%kpoints%reduced%npoints, 1:st%d%nspin))
498 safe_allocate(ifmax(1:hm%kpoints%reduced%npoints, 1:st%d%nspin))
499 safe_allocate(energies(1:st%nst, 1:hm%kpoints%reduced%npoints, 1:st%d%nspin))
500 safe_allocate(occupations(1:st%nst, 1:hm%kpoints%reduced%npoints, 1:st%d%nspin))
508 is = st%d%get_spin_index(ik)
509 ikk = st%d%get_kpoint_index(ik)
510 energies(1:st%nst, ikk, is) = st%eigenval(1:st%nst,ik) *
m_two
511 occupations(1:st%nst, ikk, is) = st%occ(1:st%nst, ik) / st%smear%el_per_state
514 if (st%eigenval(ist, ik) < st%smear%e_fermi +
m_epsilon)
then
522 safe_allocate(ngk(1:hm%kpoints%reduced%npoints))
523 do ik = 1, st%nik, st%d%nspin
524 call fourier_shell_init(shell_wfn, namespace, space, cube, gr, kk = hm%kpoints%reduced%red_point(:, ik))
525 if (ik == 1) ecutwfc = shell_wfn%ekin_cutoff
526 ngk(ik) = shell_wfn%ngvectors
531 safe_allocate(atyp(1:ions%natoms))
532 safe_allocate(apos(1:3, 1:ions%natoms))
533 do iatom = 1, ions%natoms
534 atyp(iatom) = ions%atom(iatom)%species%get_index()
535 apos(1:3, iatom) = ions%pos(1:3, iatom)
538 if (any(hm%kpoints%nik_axis(1:3) == 0))
then
539 message(1) =
"KPointsGrid has a zero component. Set KPointsGrid appropriately,"
540 message(2) =
"or this WFN will only be usable in BerkeleyGW's inteqp."
549 character(len=3),
intent(inout) :: sheader
550 integer,
intent(in) :: iunit
554 call write_binary_header(iunit, sheader, 2, st%d%nspin, shell_density%ngvectors, &
556 hm%kpoints%reduced%npoints, st%nst, ngkmax, ecutrho *
m_two, &
557 ecutwfc *
m_two, fftgrid, hm%kpoints%nik_axis, hm%kpoints%full%shifts, &
558 ions%latt%rcell_volume,
m_one, ions%latt%rlattice, adot, recvol, &
559 m_one, ions%latt%klattice, bdot, mtrx, tnp, atyp, &
560 apos, ngk, hm%kpoints%reduced%weight, hm%kpoints%reduced%red_point, &
561 ifmin, ifmax, energies, occupations, warn = .false.)
563 call write_binary_gvectors(iunit, shell_density%ngvectors, shell_density%ngvectors, shell_density%red_gvec)
573#include "complex.F90"
574#ifdef HAVE_BERKELEYGW
575#include "output_berkeleygw_inc.F90"
580#ifdef HAVE_BERKELEYGW
581#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, public xc_get_vxc(gr, xcs, st, kpoints, psolver, namespace, space, rho, ispin, rcell_volume, vxc, ex, ec, deltaxc, vtau, ex_density, ec_density, stress_xc, force_orbitalfree)
logical pure function, public xc_is_orbital_dependent(xcs)
Is the xc family orbital dependent.
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.