50#if defined(HAVE_BERKELEYGW)
66 integer,
intent(in) :: nst
67 type(namespace_t),
intent(in) :: namespace
68 type(output_bgw_t),
intent(out) :: bgw
69 integer,
intent(in) :: periodic_dim
79#ifndef HAVE_BERKELEYGW
80 message(1) =
"Cannot do BerkeleyGW output: the library was not linked."
92 call parse_variable(namespace,
'BerkeleyGW_NumberBands', nst, bgw%nbands)
95 if (bgw%nbands > nst)
then
96 message(1) =
"BerkeleyGW_NumberBands must be <= number of states."
108 call parse_variable(namespace,
'BerkeleyGW_Vxc_diag_nmin', 1, bgw%vxc_diag_nmin)
110 if (bgw%vxc_diag_nmin > nst)
then
111 message(1) =
"BerkeleyGW_Vxc_diag_nmin must be <= number of states."
123 call parse_variable(namespace,
'BerkeleyGW_Vxc_diag_nmax', nst, bgw%vxc_diag_nmax)
125 if (bgw%vxc_diag_nmax > nst)
then
126 message(1) =
"BerkeleyGW_Vxc_diag_nmax must be <= number of states."
130 if (bgw%vxc_diag_nmin <= 0 .or. bgw%vxc_diag_nmax <= 0)
then
131 bgw%vxc_diag_nmin = 0
132 bgw%vxc_diag_nmax = 0
143 call parse_variable(namespace,
'BerkeleyGW_Vxc_offdiag_nmin', 1, bgw%vxc_offdiag_nmin)
145 if (bgw%vxc_offdiag_nmin > nst)
then
146 message(1) =
"BerkeleyGW_Vxc_offdiag_nmin must be <= number of states."
158 call parse_variable(namespace,
'BerkeleyGW_Vxc_offdiag_nmax', nst, bgw%vxc_offdiag_nmax)
160 if (bgw%vxc_offdiag_nmax > nst)
then
161 message(1) =
"BerkeleyGW_Vxc_offdiag_nmax must be <= number of states."
165 if (bgw%vxc_offdiag_nmin <= 0 .or. bgw%vxc_offdiag_nmax <= 0)
then
166 bgw%vxc_offdiag_nmin = 0
167 bgw%vxc_offdiag_nmax = 0
190 call parse_variable(namespace,
'BerkeleyGW_WFN_filename',
'WFN', bgw%wfn_filename)
201 call parse_variable(namespace,
'BerkeleyGW_CalcExchange', .false., bgw%calc_exchange)
216 call parse_variable(namespace,
'BerkeleyGW_CalcDipoleMtxels', .false., bgw%calc_vmtxel)
228 bgw%vmtxel_polarization(1:3) =
m_zero
229 bgw%vmtxel_polarization(1) =
m_one
231 if (bgw%calc_vmtxel .and.
parse_block(namespace,
'BerkeleyGW_VmtxelPolarization', blk) == 0)
then
235 if (idir <= periodic_dim .and. abs(bgw%vmtxel_polarization(idir)) >
m_epsilon)
then
236 message(1) =
"You cannot calculate vmtxel with polarization in a periodic direction. Use WFNq_fi instead."
241 norm = sum(abs(bgw%vmtxel_polarization(1:3))**2)
243 message(1) =
"A non-zero value must be set for BerkeleyGW_VmtxelPolarization when BerkeleyGW_CalcDipoleMtxels = yes."
246 bgw%vmtxel_polarization(1:3) = bgw%vmtxel_polarization(1:3) /
sqrt(norm)
258 if (bgw%calc_vmtxel)
call parse_variable(namespace,
'BerkeleyGW_VmtxelNumCondBands', 0, bgw%vmtxel_ncband)
270 if (bgw%calc_vmtxel)
call parse_variable(namespace,
'BerkeleyGW_VmtxelNumValBands', 0, bgw%vmtxel_nvband)
281 class(
space_t),
intent(in) :: space
282 character(len=*),
intent(in) :: dir
284 type(
grid_t),
target,
intent(in) :: gr
285 type(
v_ks_t),
intent(inout) :: ks
287 type(
ions_t),
intent(in) :: ions
289#ifdef HAVE_BERKELEYGW
290 integer :: ik, is, ikk, ist, itran, iunit, iatom, mtrx(3, 3, 48), fftgrid(3), ngkmax
291 integer,
pointer :: atyp(:)
292 integer,
allocatable :: ifmin(:,:), ifmax(:,:), ngk(:)
293 character(len=3) :: sheader
294 real(real64) :: adot(3,3), bdot(3,3), recvol, tnp(3, 48), ecutrho, ecutwfc
295 real(real64),
allocatable :: energies(:,:,:), occupations(:,:,:)
296 real(real64),
pointer :: apos(:,:)
297 real(real64),
allocatable :: vxc(:,:), dpsi(:,:)
298 complex(real64),
allocatable :: field_g(:,:), zpsi(:,:)
306 if (space%dim /= 3)
then
307 message(1) =
"BerkeleyGW output only available in 3D."
313 if (st%parallel_in_states)
call messages_not_implemented(
"BerkeleyGW output parallel in states", namespace=namespace)
323#ifdef HAVE_BERKELEYGW
325 safe_allocate(vxc(1:gr%np, 1:st%d%nspin))
328 call xc_get_vxc(gr, ks%xc, st, hm%kpoints, hm%psolver, namespace, space, st%rho, st%d%ispin, &
329 hm%ions%latt%rcell_volume, vxc)
331 message(1) =
"BerkeleyGW output: vxc.dat"
336 call dbgw_vxc_dat(bgw, namespace, space, dir, st, gr, hm, vxc)
338 call zbgw_vxc_dat(bgw, namespace, space, dir, st, gr, hm, vxc)
341 call cube_init(cube, gr%idx%ll, namespace, space, gr%spacing, gr%coord_system, &
344 if (any(gr%idx%ll(1:3) /= fftgrid(1:3)))
then
345 message(1) =
"Cannot do BerkeleyGW output: FFT grid has been modified."
353 ecutrho = shell_density%ekin_cutoff
354 safe_allocate(field_g(1:shell_density%ngvectors, 1:st%d%nspin))
359 if (bgw%calc_vmtxel)
then
360 write(
message(1),
'(a,3f12.6)')
"BerkeleyGW output: vmtxel. Polarization = ", bgw%vmtxel_polarization(1:3)
364 call dbgw_vmtxel(bgw, namespace, dir, st, gr, ifmax)
366 call zbgw_vmtxel(bgw, namespace, dir, st, gr, ifmax)
370 message(1) =
"BerkeleyGW output: VXC"
375 iunit =
io_open(trim(dir) //
'VXC', namespace, form =
'unformatted', action =
'write')
379 vxc(:,:) = vxc(:,:) *
m_two / (product(cube%rs_n_global(1:3)) * gr%volume_element)
380 call dbgw_write_fs(namespace, iunit, vxc, field_g, shell_density, st%d%nspin, gr, cube, cf, is_wfn = .false.)
382 safe_deallocate_a(vxc)
385 message(1) =
"BerkeleyGW output: RHO"
390 iunit =
io_open(trim(dir) //
'RHO', namespace, form =
'unformatted', action =
'write')
393 call dbgw_write_fs(namespace, iunit, st%rho, field_g, shell_density, st%d%nspin, gr, cube, cf, is_wfn = .false.)
396 message(1) =
"BerkeleyGW output: WFN"
397 write(
message(2),
'(a,f12.6,a)')
"Wavefunction cutoff for BerkeleyGW: ", &
402 safe_allocate(dpsi(1:gr%np, 1:st%d%nspin))
404 safe_allocate(zpsi(1:gr%np, 1:st%d%nspin))
409 iunit =
io_open(trim(dir) // bgw%wfn_filename, namespace, form =
'unformatted', action =
'write')
416 do ik = st%d%kpt%start, st%d%kpt%end, st%d%nspin
417 call fourier_shell_init(shell_wfn, namespace, space, cube, gr, kk = hm%kpoints%reduced%red_point(:, ik))
420 call write_binary_gvectors(iunit, shell_wfn%ngvectors, shell_wfn%ngvectors, shell_wfn%red_gvec)
423 do is = 1, st%d%nspin
432 call dbgw_write_fs(namespace, iunit, dpsi, field_g, shell_wfn, st%d%nspin, gr, cube, cf, is_wfn = .
true.)
434 call zbgw_write_fs(namespace, iunit, zpsi, field_g, shell_wfn, st%d%nspin, gr, cube, cf, is_wfn = .
true.)
448 safe_deallocate_a(dpsi)
450 safe_deallocate_a(zpsi)
452 safe_deallocate_a(vxc)
453 safe_deallocate_a(field_g)
454 safe_deallocate_a(ifmin)
455 safe_deallocate_a(ifmax)
456 safe_deallocate_a(ngk)
457 safe_deallocate_a(energies)
458 safe_deallocate_a(occupations)
459 safe_deallocate_p(atyp)
460 safe_deallocate_p(apos)
463 message(1) =
"Cannot do BerkeleyGW output: the library was not linked."
469#ifdef HAVE_BERKELEYGW
475 if (space%periodic_dim /= 3)
then
476 message(1) =
"BerkeleyGW for mixed-periodicity is currently not implemented."
484 adot(1:3, 1:3) = matmul(ions%latt%rlattice(1:3, 1:3), ions%latt%rlattice(1:3, 1:3))
485 bdot(1:3, 1:3) = matmul(ions%latt%klattice(1:3, 1:3), ions%latt%klattice(1:3, 1:3))
486 recvol = (
m_two *
m_pi)**3 / ions%latt%rcell_volume
495 safe_allocate(ifmin(1:hm%kpoints%reduced%npoints, 1:st%d%nspin))
496 safe_allocate(ifmax(1:hm%kpoints%reduced%npoints, 1:st%d%nspin))
497 safe_allocate(energies(1:st%nst, 1:hm%kpoints%reduced%npoints, 1:st%d%nspin))
498 safe_allocate(occupations(1:st%nst, 1:hm%kpoints%reduced%npoints, 1:st%d%nspin))
506 is = st%d%get_spin_index(ik)
507 ikk = st%d%get_kpoint_index(ik)
508 energies(1:st%nst, ikk, is) = st%eigenval(1:st%nst,ik) *
m_two
509 occupations(1:st%nst, ikk, is) = st%occ(1:st%nst, ik) / st%smear%el_per_state
512 if (st%eigenval(ist, ik) < st%smear%e_fermi +
m_epsilon)
then
520 safe_allocate(ngk(1:hm%kpoints%reduced%npoints))
521 do ik = 1, st%nik, st%d%nspin
522 call fourier_shell_init(shell_wfn, namespace, space, cube, gr, kk = hm%kpoints%reduced%red_point(:, ik))
523 if (ik == 1) ecutwfc = shell_wfn%ekin_cutoff
524 ngk(ik) = shell_wfn%ngvectors
529 safe_allocate(atyp(1:ions%natoms))
530 safe_allocate(apos(1:3, 1:ions%natoms))
531 do iatom = 1, ions%natoms
532 atyp(iatom) = ions%atom(iatom)%species%get_index()
533 apos(1:3, iatom) = ions%pos(1:3, iatom)
536 if (any(hm%kpoints%nik_axis(1:3) == 0))
then
537 message(1) =
"KPointsGrid has a zero component. Set KPointsGrid appropriately,"
538 message(2) =
"or this WFN will only be usable in BerkeleyGW's inteqp."
547 character(len=3),
intent(inout) :: sheader
548 integer,
intent(in) :: iunit
552 call write_binary_header(iunit, sheader, 2, st%d%nspin, shell_density%ngvectors, &
554 hm%kpoints%reduced%npoints, st%nst, ngkmax, ecutrho *
m_two, &
555 ecutwfc *
m_two, fftgrid, hm%kpoints%nik_axis, hm%kpoints%full%shifts, &
556 ions%latt%rcell_volume,
m_one, ions%latt%rlattice, adot, recvol, &
557 m_one, ions%latt%klattice, bdot, mtrx, tnp, atyp, &
558 apos, ngk, hm%kpoints%reduced%weight, hm%kpoints%reduced%red_point, &
559 ifmin, ifmax, energies, occupations, warn = .false.)
561 call write_binary_gvectors(iunit, shell_density%ngvectors, shell_density%ngvectors, shell_density%red_gvec)
571#include "complex.F90"
572#ifdef HAVE_BERKELEYGW
573#include "output_berkeleygw_inc.F90"
578#ifdef HAVE_BERKELEYGW
579#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.
integer, parameter, public hartree
integer, parameter, public hartree_fock
subroutine, public io_close(iunit, grp)
integer function, public io_open(file, namespace, action, status, form, position, die, recl, grp)
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 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.
The states_elec_t class contains all electronic wave functions.