39 use,
intrinsic :: iso_fortran_env
75#ifdef HAVE_LIBXC_FUNCS
76 use xc_f03_funcs_m,
only: xc_mgga_x_tb09
114 logical :: calculating
115 logical :: time_present
117 real(real64),
allocatable :: density(:, :)
118 logical :: total_density_alloc
119 real(real64),
pointer,
contiguous :: total_density(:)
120 type(energy_t),
allocatable :: energy
122 type(states_elec_t),
pointer :: hf_st
127 real(real64),
allocatable :: vxc(:, :)
128 real(real64),
allocatable :: vtau(:, :)
129 real(real64),
allocatable :: axc(:, :, :)
130 real(real64),
allocatable :: a_ind(:, :)
131 real(real64),
allocatable :: b_ind(:, :)
132 logical :: calc_energy
137 integer,
public :: theory_level = -1
138 logical,
public :: frozen_hxc = .false.
140 integer,
public :: xc_family = 0
141 integer,
public :: xc_flags = 0
142 type(xc_t),
public :: xc
143 class(xc_oep_t),
allocatable,
public :: oep
144 class(xc_ks_inversion_t),
allocatable,
public :: ks_inversion
145 class(xc_sic_t),
allocatable,
public :: sic
146 type(xc_vdw_t),
public :: vdw
147 type(grid_t),
pointer,
public :: gr
148 type(sturm_liouville_t),
public :: sl_solver
149 type(v_ks_calc_t) :: calc
150 logical :: calculate_current = .false.
151 type(current_t) :: current_calculator
152 logical :: include_td_field = .false.
155 real(real64),
public :: stress_xc(3, 3)
156 type(v_ks_photon_t),
public :: v_ks_photons
162 subroutine v_ks_init(ks, namespace, gr, st, ions, mc, space, kpoints)
163 type(v_ks_t),
intent(inout) :: ks
164 type(namespace_t),
intent(in) :: namespace
165 type(grid_t),
target,
intent(inout) :: gr
166 type(states_elec_t),
intent(in) :: st
167 type(ions_t),
intent(inout) :: ions
168 type(multicomm_t),
intent(in) :: mc
169 class(space_t),
intent(in) :: space
170 type(kpoints_t),
intent(in) :: kpoints
172 integer :: x_id, c_id, xk_id, ck_id, default, val
173 logical :: parsed_theory_level
174 integer :: pseudo_x_functional, pseudo_c_functional
222 ks%xc_family = xc_family_none
227 parsed_theory_level = .false.
248 call messages_write(
'Info: the XCFunctional has been selected to match the pseudopotentials', new_line = .
true.)
263 call messages_write(
'The XCFunctional that you selected does not match the one used', new_line = .
true.)
296 call ks%v_ks_photons%init(namespace)
302 call xc_init(ks%xc, namespace, space%dim, space%periodic_dim, st%qtot, &
303 x_id, c_id, xk_id, ck_id, theory_level = ks%theory_level, ispin=st%d%ispin)
305 ks%xc_family = ks%xc%family
306 ks%xc_flags = ks%xc%flags
308 if (.not. parsed_theory_level)
then
317 call parse_variable(namespace,
'TheoryLevel', default, ks%theory_level)
329 ks%xc_family = ior(ks%xc_family, xc_family_oep)
339 ks%sic%amaldi_factor =
m_one
341 select case (ks%theory_level)
346 if (space%periodic_dim == space%dim)
then
349 if (kpoints%full%npoints > 1)
then
354 if (kpoints%full%npoints > 1)
then
369 if (
bitand(ks%xc_family, xc_family_lda + xc_family_gga) /= 0)
then
370 call xc_sic_init(ks%sic, namespace, gr, st, mc, space)
373 if (
bitand(ks%xc_family, xc_family_oep) /= 0)
then
374 select case (ks%xc%functional(
func_x,1)%id)
376 if (kpoints%reduced%npoints > 1 .and. st%d%ispin ==
spinors)
then
379 if (kpoints%use_symmetries)
then
384 if (kpoints%reduced%npoints > 1)
then
389 if((.not. ks%v_ks_photons%active()) .or. (ks%v_ks_photons%functional() /= 0))
then
390 if(oep_type == -1)
then
393 call xc_oep_init(ks%oep, namespace, gr, st, mc, space, oep_type)
407 message(1) =
"SICCorrection can only be used with Kohn-Sham DFT"
411 if (st%d%ispin ==
spinors)
then
412 if (
bitand(ks%xc_family, xc_family_mgga + xc_family_hyb_mgga) /= 0)
then
417 ks%frozen_hxc = .false.
422 ks%calc%calculating = .false.
427 call ks%vdw%init(namespace, space, gr, ks%xc, ions, x_id, c_id)
428 if (ks%vdw%vdw_correction /= option__vdwcorrection__none .and. ks%theory_level ==
rdmft)
then
429 message(1) =
"VDWCorrection and RDMFT are not compatible"
432 if (ks%vdw%vdw_correction /= option__vdwcorrection__none .and. ks%theory_level ==
independent_particles)
then
433 message(1) =
"VDWCorrection and independent particles are not compatible"
437 call ks%v_ks_photons%init_xc(namespace, space, gr, st)
449 integer,
intent(out) :: x_functional
450 integer,
intent(out) :: c_functional
452 integer :: xf, cf, ispecies
453 logical :: warned_inconsistent
458 warned_inconsistent = .false.
459 do ispecies = 1, ions%nspecies
460 select type(spec=>ions%species(ispecies)%s)
462 xf = spec%x_functional()
463 cf = spec%c_functional()
466 call messages_write(
"Unknown XC functional for species '"//trim(ions%species(ispecies)%s%get_label())//
"'")
474 if (xf /= x_functional .and. .not. warned_inconsistent)
then
475 call messages_write(
'Inconsistent XC functional detected between species')
477 warned_inconsistent = .
true.
484 if (cf /= c_functional .and. .not. warned_inconsistent)
then
485 call messages_write(
'Inconsistent XC functional detected between species')
487 warned_inconsistent = .
true.
507 type(
v_ks_t),
intent(inout) :: ks
514 select case (ks%theory_level)
519 if (
bitand(ks%xc_family, xc_family_oep) /= 0)
then
529 call ks%v_ks_photons%end()
538 type(
v_ks_t),
intent(in) :: ks
539 integer,
optional,
intent(in) :: iunit
540 type(
namespace_t),
optional,
intent(in) :: namespace
547 select case (ks%theory_level)
594 type(
v_ks_t),
intent(in) :: ks
603 if (st%requires_generalized_overlap)
then
608 if (hm%ep%has_paw .and. hm%lda_u_level /=
dft_u_none)
then
613 "Spin-orbit coupling through the pseudopotential (j-dependent projectors) with ultrasoft/PAW", &
616 if (st%d%ispin ==
spinors)
then
618 "Noncollinear (spinor) calculations with ultrasoft/PAW", namespace=namespace)
622 "Spin-polarized calculations with ultrasoft/PAW", namespace=namespace)
625 if (hm%ep%has_paw)
then
629 "meta-GGA with ultrasoft (the kinetic-energy-density augmentation is missing)", &
635 "Hartree-Fock / hybrid functionals with ultrasoft/PAW (exact-exchange augmentation is missing)", &
638 if (hm%ep%has_paw)
then
643 if (ks%xc%functional(
func_x, is)%id /= 0 .and. &
647 if (ks%xc%functional(
func_c, is)%id /= 0 .and. &
655 "PZ-SIC / OEP with ultrasoft/PAW (orbital-resolved augmentation is missing)", &
666 subroutine v_ks_h_setup(namespace, space, gr, ions, ext_partners, st, ks, hm, calc_eigenval, calc_current)
669 type(
grid_t),
intent(in) :: gr
670 type(
ions_t),
intent(in) :: ions
673 type(
v_ks_t),
intent(inout) :: ks
675 logical,
optional,
intent(in) :: calc_eigenval
676 logical,
optional,
intent(in) :: calc_current
678 integer,
allocatable :: ind(:)
680 real(real64),
allocatable :: copy_occ(:)
681 logical :: calc_eigenval_
682 logical :: calc_current_
689 call density_calc(st, gr, st%rho, ep = hm%ep, vnl = hm%aug_overlap, phase = hm%phase)
690 call v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, &
691 calc_eigenval = calc_eigenval_, calc_current = calc_current_)
693 if (st%restart_reorder_occs .and. .not. st%fromScratch)
then
694 message(1) =
"Reordering occupations for restart."
697 safe_allocate(ind(1:st%nst))
698 safe_allocate(copy_occ(1:st%nst))
701 call sort(st%eigenval(:,
ik), ind)
702 copy_occ(1:st%nst) = st%occ(1:st%nst,
ik)
704 st%occ(ist,
ik) = copy_occ(ind(ist))
708 safe_deallocate_a(ind)
709 safe_deallocate_a(copy_occ)
719 subroutine v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, &
720 calc_eigenval, time, calc_energy, calc_current, force_semilocal)
721 type(
v_ks_t),
intent(inout) :: ks
726 type(
ions_t),
intent(in) :: ions
728 logical,
optional,
intent(in) :: calc_eigenval
729 real(real64),
optional,
intent(in) :: time
730 logical,
optional,
intent(in) :: calc_energy
731 logical,
optional,
intent(in) :: calc_current
732 logical,
optional,
intent(in) :: force_semilocal
734 logical :: calc_current_
739 .and. (ks%calculate_current &
743 if (calc_current_)
then
748 call v_ks_calc_start(ks, namespace, space, hm, st, ions, hm%kpoints%latt, ext_partners, time, &
749 calc_energy, force_semilocal=force_semilocal)
751 ext_partners, force_semilocal=force_semilocal)
762 call lalg_axpy(ks%gr%np, st%d%nspin,
m_one, hm%magnetic_constrain%pot, hm%ks_pot%vhxc)
774 subroutine v_ks_calc_start(ks, namespace, space, hm, st, ions, latt, ext_partners, time, &
775 calc_energy, force_semilocal)
776 type(
v_ks_t),
target,
intent(inout) :: ks
778 class(
space_t),
intent(in) :: space
781 type(
ions_t),
intent(in) :: ions
784 real(real64),
optional,
intent(in) :: time
785 logical,
optional,
intent(in) :: calc_energy
786 logical,
optional,
intent(in) :: force_semilocal
792 assert(.not. ks%calc%calculating)
793 ks%calc%calculating = .
true.
795 write(
message(1),
'(a)')
'Debug: Calculating Kohn-Sham potential.'
798 ks%calc%time_present =
present(time)
804 if (ks%frozen_hxc)
then
810 allocate(ks%calc%energy)
814 ks%calc%energy%intnvxc =
m_zero
816 nullify(ks%calc%total_density)
826 if (ks%theory_level /=
hartree .and. ks%theory_level /=
rdmft)
call v_a_xc(hm, force_semilocal)
828 ks%calc%total_density_alloc = .false.
835 nullify(ks%calc%hf_st)
840 if (st%parallel_in_states)
then
842 call messages_write(
'State parallelization of Hartree-Fock exchange is not supported')
844 call messages_write(
'when running with GPUs. Please use domain parallelization')
851 if (hm%exxop%useACE)
then
854 safe_allocate(ks%calc%hf_st)
863 if (hm%self_induced_magnetic)
then
864 safe_allocate(ks%calc%a_ind(1:ks%gr%np_part, 1:space%dim))
865 safe_allocate(ks%calc%b_ind(1:ks%gr%np_part, 1:space%dim))
866 call magnetic_induced(namespace, ks%gr, st, hm%psolver, hm%kpoints, ks%calc%a_ind, ks%calc%b_ind)
869 if ((ks%v_ks_photons%active()) .and. (ks%calc%time_present) .and. (ks%v_ks_photons%functional() == 0) )
then
870 call ks%v_ks_photons%mf_calc(ks%gr, st, ions, time)
888 safe_allocate(ks%calc%density(1:ks%gr%np, 1:st%d%nspin))
893 call lalg_scal(ks%gr%np, st%d%nspin, ks%sic%amaldi_factor, ks%calc%density)
905 if (
allocated(st%rho_core))
then
909 int(ks%gr%np, int64), st%rho_core)
911 if (
allocated(st%frozen_rho))
then
915 int(ks%gr%np, int64), int(st%d%nspin, int64), st%frozen_rho)
916 ks%xc%quantities%frozen_rho_np = ks%gr%np
919 ks%xc%quantities%amaldi_factor = ks%sic%amaldi_factor
923 nullify(ks%calc%total_density)
924 if (
allocated(st%rho_core) .or. hm%d%spin_channels > 1)
then
925 ks%calc%total_density_alloc = .
true.
927 safe_allocate(ks%calc%total_density(1:ks%gr%np))
930 ks%calc%total_density(ip) = sum(ks%calc%density(ip, 1:hm%d%spin_channels))
934 if (
allocated(st%rho_core))
then
935 call lalg_axpy(ks%gr%np, -ks%sic%amaldi_factor, st%rho_core, ks%calc%total_density)
938 ks%calc%total_density_alloc = .false.
939 ks%calc%total_density => ks%calc%density(:, 1)
946 subroutine v_a_xc(hm, force_semilocal)
948 logical,
optional,
intent(in) :: force_semilocal
950 real(real64),
allocatable :: nhat(:,:)
955 ks%calc%energy%exchange =
m_zero
956 ks%calc%energy%correlation =
m_zero
957 ks%calc%energy%xc_j =
m_zero
958 ks%calc%energy%vdw =
m_zero
960 allocate(ks%calc%vxc(1:ks%gr%np, 1:st%d%nspin))
964 safe_allocate(ks%calc%vtau(1:ks%gr%np, 1:st%d%nspin))
968 ks%xc%paw_tb09_onecenter =
m_zero
969 if (hm%ep%has_paw .and.
allocated(hm%aug_overlap%onsite_density_matrix) &
970 .and. ks%xc%functional(
func_x, 1)%id == xc_mgga_x_tb09)
then
972 hm%aug_overlap%onsite_density_matrix)
979 if (ks%calc%calc_energy)
then
981 call xc_get_vxc(ks%gr, ks%xc, st, hm%kpoints, hm%psolver, namespace, space, ks%calc%density, st%d%ispin, &
982 latt%rcell_volume, ks%calc%vxc, ex = ks%calc%energy%exchange, ec = ks%calc%energy%correlation, &
983 deltaxc = ks%calc%energy%delta_xc, vtau = ks%calc%vtau, stress_xc=ks%stress_xc, &
984 force_orbitalfree=force_semilocal, nhat=nhat)
986 call xc_get_vxc(ks%gr, ks%xc, st, hm%kpoints, hm%psolver, namespace, space, ks%calc%density, st%d%ispin, &
987 latt%rcell_volume, ks%calc%vxc, ex = ks%calc%energy%exchange, ec = ks%calc%energy%correlation, &
988 deltaxc = ks%calc%energy%delta_xc, stress_xc=ks%stress_xc, force_orbitalfree=force_semilocal, nhat=nhat)
992 call xc_get_vxc(ks%gr, ks%xc, st, hm%kpoints, hm%psolver, namespace, space, ks%calc%density, &
993 st%d%ispin, latt%rcell_volume, ks%calc%vxc, vtau = ks%calc%vtau, stress_xc=ks%stress_xc, &
994 force_orbitalfree=force_semilocal, nhat=nhat)
996 call xc_get_vxc(ks%gr, ks%xc, st, hm%kpoints, hm%psolver, namespace, space, ks%calc%density, &
997 st%d%ispin, latt%rcell_volume, ks%calc%vxc, stress_xc=ks%stress_xc, force_orbitalfree=force_semilocal, &
1001 safe_deallocate_a(nhat)
1005 if (st%d%ispin /=
spinors)
then
1006 message(1) =
"Noncollinear functionals can only be used with spinor wavefunctions."
1011 message(1) =
"Cannot perform LCAO for noncollinear MGGAs."
1012 message(2) =
"Please perform a LDA calculation first."
1016 if (ks%calc%calc_energy)
then
1018 call xc_get_nc_vxc(ks%gr, ks%xc, st, hm%kpoints, space, namespace, ks%calc%density, ks%calc%vxc, &
1019 vtau = ks%calc%vtau, ex = ks%calc%energy%exchange, ec = ks%calc%energy%correlation)
1021 call xc_get_nc_vxc(ks%gr, ks%xc, st, hm%kpoints, space, namespace, ks%calc%density, ks%calc%vxc, &
1022 ex = ks%calc%energy%exchange, ec = ks%calc%energy%correlation)
1026 call xc_get_nc_vxc(ks%gr, ks%xc, st, hm%kpoints, space, namespace, ks%calc%density, &
1027 ks%calc%vxc, vtau = ks%calc%vtau)
1029 call xc_get_nc_vxc(ks%gr, ks%xc, st, hm%kpoints, space, namespace, ks%calc%density, ks%calc%vxc)
1034 call ks%vdw%calc(namespace, space, latt, ions%atom, ions%natoms, ions%pos, &
1035 ks%gr, st, ks%calc%energy%vdw, ks%calc%vxc)
1048 if (ks%calc%calc_energy)
then
1049 call xc_sic_calc_adsic(ks%sic, namespace, space, ks%gr, st, hm, ks%xc, ks%calc%density, &
1050 ks%calc%vxc, ex = ks%calc%energy%exchange, ec = ks%calc%energy%correlation)
1052 call xc_sic_calc_adsic(ks%sic, namespace, space, ks%gr, st, hm, ks%xc, ks%calc%density, &
1064 call x_slater_calc(namespace, ks%gr, space, hm%exxop, st, hm%kpoints, ks%calc%energy%exchange, &
1067 call x_fbe_calc(ks%xc%functional(
func_x,1)%id, namespace, hm%psolver, ks%sl_solver, ks%gr, st, space, &
1068 ks%calc%energy%exchange, vxc = ks%calc%vxc)
1072 call fbe_c_lda_sl(namespace, hm%psolver, ks%sl_solver, ks%gr, st, space, ks%calc%energy%correlation, vxc = ks%calc%vxc)
1080 call xc_ks_inversion_calc(ks%ks_inversion, namespace, space, ks%gr, hm, ext_partners, st, vxc = ks%calc%vxc, &
1081 time = ks%calc%time)
1085 if (ks%v_ks_photons%functional() /= 0)
then
1086 call ks%v_ks_photons%add_px(namespace, ks%calc%total_density, ks%gr, space, hm%psolver, st, &
1087 hm%d%spin_channels, ks%calc%vxc, ks%calc%energy%photon_exchange)
1092 if (ks%calc%calc_energy)
then
1105 subroutine v_ks_calc_finish(ks, hm, namespace, space, latt, st, ext_partners, force_semilocal)
1106 type(
v_ks_t),
target,
intent(inout) :: ks
1109 class(
space_t),
intent(in) :: space
1113 logical,
optional,
intent(in) :: force_semilocal
1115 integer :: ip, ispin
1118 real(real64) :: exx_energy
1119 real(real64) :: factor
1120 real(real64),
allocatable :: nhat_xc(:, :)
1124 assert(ks%calc%calculating)
1125 ks%calc%calculating = .false.
1127 if (ks%frozen_hxc)
then
1133 safe_deallocate_a(hm%energy)
1134 call move_alloc(ks%calc%energy, hm%energy)
1136 if (hm%self_induced_magnetic)
then
1137 hm%a_ind(1:ks%gr%np, 1:space%dim) = ks%calc%a_ind(1:ks%gr%np, 1:space%dim)
1138 hm%b_ind(1:ks%gr%np, 1:space%dim) = ks%calc%b_ind(1:ks%gr%np, 1:space%dim)
1140 safe_deallocate_a(ks%calc%a_ind)
1141 safe_deallocate_a(ks%calc%b_ind)
1144 if (
allocated(hm%v_static))
then
1145 if (
associated(ks%calc%total_density))
then
1146 hm%energy%intnvstatic =
dmf_dotp(ks%gr, ks%calc%total_density, hm%v_static)
1149 hm%energy%intnvstatic =
m_zero
1150 do ispin = 1, hm%d%spin_channels
1151 hm%energy%intnvstatic = hm%energy%intnvstatic +
dmf_dotp(ks%gr, st%rho(:, ispin), hm%v_static)
1155 hm%energy%intnvstatic =
m_zero
1161 hm%energy%intnvxc =
m_zero
1162 hm%energy%hartree =
m_zero
1163 hm%energy%exchange =
m_zero
1164 hm%energy%exchange_hf =
m_zero
1165 hm%energy%correlation =
m_zero
1168 hm%energy%hartree =
m_zero
1169 call v_ks_hartree(namespace, ks, space, hm, ext_partners)
1175 call dxc_oep_calc(ks%sic%oep, namespace, ks%xc, ks%gr, hm, st, space, &
1176 latt%rcell_volume, hm%energy%exchange, hm%energy%correlation, vxc = ks%calc%vxc)
1178 call zxc_oep_calc(ks%sic%oep, namespace, ks%xc, ks%gr, hm, st, space, &
1179 latt%rcell_volume, hm%energy%exchange, hm%energy%correlation, vxc = ks%calc%vxc)
1188 call dxc_oep_calc(ks%oep, namespace, ks%xc, ks%gr, hm, st, space, &
1189 latt%rcell_volume, hm%energy%exchange, hm%energy%correlation, vxc = ks%calc%vxc)
1191 call zxc_oep_calc(ks%oep, namespace, ks%xc, ks%gr, hm, st, space, &
1192 latt%rcell_volume, hm%energy%exchange, hm%energy%correlation, vxc = ks%calc%vxc)
1199 call ks%v_ks_photons%oep_calc(namespace, ks%xc, ks%gr, hm, st, space, ks%calc%vxc)
1203 if (ks%calc%calc_energy)
then
1205 hm%energy%intnvxc =
m_zero
1210 do ispin = 1, hm%d%nspin
1211 if (ispin <= 2)
then
1216 if (
allocated(nhat_xc))
then
1217 hm%energy%intnvxc = hm%energy%intnvxc + factor*
dmf_dotp(ks%gr, &
1218 st%rho(1:ks%gr%np, ispin) - nhat_xc(1:ks%gr%np, ispin), ks%calc%vxc(1:ks%gr%np, ispin), &
1221 hm%energy%intnvxc = hm%energy%intnvxc + &
1222 factor*
dmf_dotp(ks%gr, st%rho(:, ispin), ks%calc%vxc(:, ispin), reduce = .false.)
1225 call ks%gr%allreduce(hm%energy%intnvxc)
1226 safe_deallocate_a(nhat_xc)
1231 if (ks%theory_level /=
hartree .and. ks%theory_level /=
rdmft)
then
1233 safe_deallocate_a(hm%ks_pot%vxc)
1234 call move_alloc(ks%calc%vxc, hm%ks_pot%vxc)
1237 call hm%ks_pot%set_vtau(ks%calc%vtau)
1238 safe_deallocate_a(ks%calc%vtau)
1244 hm%energy%intnvxc = hm%energy%intnvxc &
1247 hm%energy%intnvxc = hm%energy%intnvxc &
1257 if (.not. ks%v_ks_photons%includes_hartree())
then
1258 hm%energy%hartree =
m_zero
1259 hm%ks_pot%vhartree =
m_zero
1265 hm%ks_pot%vhxc(ip, 1) = hm%ks_pot%vxc(ip, 1) + hm%ks_pot%vhartree(ip)
1267 if (
allocated(hm%vberry))
then
1269 hm%ks_pot%vhxc(ip, 1) = hm%ks_pot%vhxc(ip, 1) + hm%vberry(ip, 1)
1275 hm%ks_pot%vhxc(ip, 2) = hm%ks_pot%vxc(ip, 2) + hm%ks_pot%vhartree(ip)
1277 if (
allocated(hm%vberry))
then
1279 hm%ks_pot%vhxc(ip, 2) = hm%ks_pot%vhxc(ip, 2) + hm%vberry(ip, 2)
1284 if (hm%d%ispin ==
spinors)
then
1287 hm%ks_pot%vhxc(ip, ispin) = hm%ks_pot%vxc(ip, ispin)
1293 hm%energy%exchange_hf =
m_zero
1295 .or. ks%theory_level ==
rdmft &
1299 if (.not. hm%exxop%useACE)
then
1301 if (
associated(hm%exxop%st))
then
1304 safe_deallocate_p(hm%exxop%st)
1315 select case (ks%theory_level)
1329 if (hm%exxop%useACE)
then
1333 if (hm%exxop%with_isdf)
then
1336 call hm%exxop%isdf%get_interpolation_points(namespace, space, ks%gr, st%rho(1:ks%gr%np, 1))
1338 ks%calc%hf_st, xst, hm%kpoints)
1341 ks%calc%hf_st, xst, hm%kpoints)
1347 ks%calc%hf_st, xst, hm%kpoints)
1349 if (hm%phase%is_allocated())
then
1356 exx_energy = exx_energy + hm%exxop%singul%energy
1360 select case (ks%theory_level)
1363 hm%energy%exchange_hf = hm%energy%exchange_hf + exx_energy
1366 hm%energy%exchange_hf = hm%energy%exchange_hf + exx_energy
1384 if (ks%v_ks_photons%active() .and. (ks%v_ks_photons%functional() == 0))
then
1385 call ks%v_ks_photons%add_mf_potential(ks%gr, hm%ks_pot%vhxc, hm%d%ispin, hm%ep%photon_forces(1:space%dim))
1388 if (ks%vdw%vdw_correction /= option__vdwcorrection__none)
then
1389 assert(
allocated(ks%vdw%forces))
1390 hm%ep%vdw_forces(:, :) = ks%vdw%forces(:, :)
1391 hm%ep%vdw_stress = ks%vdw%stress
1392 safe_deallocate_a(ks%vdw%forces)
1394 hm%ep%vdw_forces = 0.0_real64
1397 if (ks%calc%time_present .or. hm%time_zero)
then
1398 call hm%update(ks%gr, namespace, space, ext_partners, time = ks%calc%time)
1404 safe_deallocate_a(ks%calc%density)
1405 if (ks%calc%total_density_alloc)
then
1406 safe_deallocate_p(ks%calc%total_density)
1408 nullify(ks%calc%total_density)
1422 class(
space_t),
intent(in ) :: space
1423 class(
mesh_t),
intent(in ) :: gr
1429 if (exxop%isdf%use_serial)
then
1431 hf_st, xst, kpoints)
1433 call isdf_parallel_ace_compute_potentials(exxop, namespace, space, gr, &
1434 hf_st, xst, kpoints)
1445 subroutine v_ks_hartree(namespace, ks, space, hm, ext_partners)
1447 type(
v_ks_t),
intent(inout) :: ks
1448 class(
space_t),
intent(in) :: space
1456 call dpoisson_solve(hm%psolver, namespace, hm%ks_pot%vhartree, ks%calc%total_density, reset=.false.)
1462 if (ks%calc%calc_energy)
then
1464 hm%energy%hartree =
m_half*
dmf_dotp(ks%gr, ks%calc%total_density, hm%ks_pot%vhartree)
1468 if(ks%calc%time_present)
then
1471 ks%calc%total_density, hm%energy%pcm_corr, kick=hm%kick, time=ks%calc%time)
1474 ks%calc%total_density, hm%energy%pcm_corr, time=ks%calc%time)
1479 ks%calc%total_density, hm%energy%pcm_corr, kick=hm%kick)
1482 ks%calc%total_density, hm%energy%pcm_corr)
1493 type(
v_ks_t),
intent(inout) :: ks
1497 ks%frozen_hxc = .
true.
1504 type(
v_ks_t),
intent(inout) :: this
1505 logical,
intent(in) :: calc_cur
1509 this%calculate_current = calc_cur
1516 type(
v_ks_t),
intent(inout) :: ks
1520 real(real64),
intent(out) :: int_dft_u
1539 type(
v_ks_t),
intent(in) :: ks
constant times a vector plus a vector
scales a vector by a constant
This is the common interface to a sorting routine. It performs the shell algorithm,...
logical pure function, public accel_buffer_is_allocated(this)
pure logical function, public accel_is_enabled()
integer, parameter, public accel_mem_read_only
subroutine, public current_calculate(this, namespace, gr, hm, space, st)
Compute total electronic current density.
subroutine, public current_init(this, namespace)
This module implements a calculator for the density and defines related functions.
subroutine, public density_calc(st, gr, density, istin, ep, vnl, phase)
Computes the density from the orbitals in st.
subroutine, public states_elec_total_density(st, mesh, total_rho)
This routine calculates the total electronic density.
This module calculates the derivatives (gradients, Laplacians, etc.) of a function.
integer, parameter, public unpolarized
Parameters...
integer, parameter, public spinors
integer, parameter, public spin_polarized
subroutine, public energy_calc_total(namespace, space, hm, gr, st, ext_partners, iunit, full)
This subroutine calculates the total energy of the system. Basically, it adds up the KS eigenvalues,...
real(real64) function, public zenergy_calc_electronic(namespace, hm, der, st, terms)
real(real64) function, public denergy_calc_electronic(namespace, hm, der, st, terms)
subroutine, public energy_calc_eigenvalues(namespace, hm, der, st)
subroutine, public energy_copy(ein, eout)
integer, parameter, public spin_orbit
subroutine, public dexchange_operator_ace(this, namespace, mesh, st, xst, phase)
Construct the ACE vectors.
subroutine, public zexchange_operator_compute_potentials(this, namespace, space, gr, st, xst, kpoints, F_out)
subroutine, public exchange_operator_reinit(this, cam, st)
subroutine, public dexchange_operator_compute_potentials(this, namespace, space, gr, st, xst, kpoints, F_out)
subroutine, public zexchange_operator_ace(this, namespace, mesh, st, xst, phase)
Construct the ACE vectors.
real(real64) function, public dexchange_operator_compute_ex(mesh, st, xst)
Compute the exact exchange energy.
real(real64) function, public zexchange_operator_compute_ex(mesh, st, xst)
Compute the exact exchange energy.
real(real64), parameter, public m_two
real(real64), parameter, public m_zero
integer, parameter, public rdmft
integer, parameter, public hartree_fock
integer, parameter, public independent_particles
Theory level.
integer, parameter, public generalized_kohn_sham_dft
integer, parameter, public kohn_sham_dft
real(real64), parameter, public m_epsilon
real(real64), parameter, public m_half
real(real64), parameter, public m_one
integer, parameter, public hartree
This module implements the underlying real-space grid.
integer, parameter, public term_mgga
integer, parameter, public term_dft_u
subroutine, public hamiltonian_elec_xc_nhat(this, mesh, nhat)
PAW with the Bloechl compensation scheme (usexcnhat = false): the compensation charge n^hat_s(r) = su...
logical function, public hamiltonian_elec_has_kick(hm)
logical function, public hamiltonian_elec_needs_current(hm, states_are_real)
subroutine, public hamiltonian_elec_update_pot(this, mesh, accumulate)
Update the KS potential of the electronic Hamiltonian.
This module defines classes and functions for interaction partners.
Interoperable Separable Density Fitting (ISDF) molecular implementation.
subroutine, public isdf_ace_compute_potentials(exxop, namespace, space, mesh, st, Vx_on_st, kpoints)
ISDF wrapper computing interpolation points and vectors, which are used to build the potential used ...
integer, parameter, private ik
All molecular calculations performed at the Gamma-point.
Serial prototype for benchmarking and validating ISDF implementation.
subroutine, public isdf_serial_ace_compute_potentials(exxop, namespace, space, mesh, st, Vx_on_st, kpoints)
ISDF wrapper computing interpolation points and vectors, which are used to build the potential used ...
A module to handle KS potential, without the external potential.
integer, parameter, public dft_u_none
This modules implements the routines for doing constrain DFT for noncollinear magnetism.
integer, parameter, public constrain_none
subroutine, public magnetic_constrain_update(this, mesh, std, space, latt, pos, rho)
Recomputes the magnetic contraining potential.
subroutine, public magnetic_induced(namespace, gr, st, psolver, kpoints, a_ind, b_ind)
This subroutine receives as input a current, and produces as an output the vector potential that it i...
This module defines various routines, operating on mesh functions.
This module defines the meshes, which are used in Octopus.
subroutine, public messages_print_with_emphasis(msg, iunit, namespace)
subroutine, public messages_not_implemented(feature, namespace)
character(len=512), private msg
subroutine, public messages_warning(no_lines, all_nodes, namespace)
subroutine, public messages_obsolete_variable(namespace, name, rep)
subroutine, public messages_new_line()
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_input_error(namespace, var, details, row, column)
subroutine, public messages_experimental(name, namespace)
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
This module handles the communicators for the various parallelization strategies.
real(real64) function, public nonlocal_pseudopotential_tb09_grad_over_dens(this, epot, onsite_density_matrix)
Sum over the PAW atoms of the one-center correction to int |grad n|/n (TB09 c), see paw_onsite_tb09_g...
logical function, public parse_is_defined(namespace, name)
subroutine, public pcm_hartree_potential(pcm, space, mesh, psolver, ext_partners, vhartree, density, pcm_corr, kick, time)
PCM reaction field due to the electronic density.
subroutine, public dpoisson_solve_start(this, rho)
subroutine, public dpoisson_solve(this, namespace, pot, rho, all_nodes, kernel, reset)
Calculates the Poisson equation. Given the density returns the corresponding potential.
subroutine, public dpoisson_solve_finish(this, pot)
logical pure function, public poisson_is_async(this)
/* To use the profiling module, call profiling_in and profiling_out with the label of the region as a...
subroutine, public profiling_out(label)
Increment out counter and sum up difference between entry and exit time.
subroutine, public profiling_in(label, exclude)
Increment in counter and save entry time.
integer, parameter, public pseudo_exchange_unknown
integer, parameter, public pseudo_correlation_unknown
integer, parameter, public pseudo_correlation_any
integer, parameter, public pseudo_exchange_any
This module is intended to contain "only mathematical" functions and procedures.
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.
subroutine, public states_elec_fermi(st, namespace, mesh, compute_spin)
calculate the Fermi level for the states in this object
subroutine, public states_elec_end(st)
finalize the states_elec_t object
subroutine, public states_elec_copy(stout, stin, exclude_wfns, exclude_eigenval, special, dest_type, copy_data)
make a (selective) copy of a states_elec_t object
subroutine, public states_elec_allocate_current(st, space, mesh)
This module provides routines for communicating states when using states parallelization.
subroutine, public states_elec_parallel_remote_access_stop(this)
stop remote memory access for states on other processors
subroutine, public states_elec_parallel_remote_access_start(this)
start remote memory access for states on other processors
General Sturm-Liouville solver for equations of the form .
subroutine, public sturm_liouville_end(this)
Finalize the Sturm-Liouville solver.
subroutine, public sturm_liouville_init(this, namespace, gr, space, max_iter, thr, inverse_tol)
Initialize the Sturm-Liouville solver.
type(type_t), parameter, public type_float
subroutine v_ks_hartree(namespace, ks, space, hm, ext_partners)
Hartree contribution to the KS potential. This function is designed to be used by v_ks_calc_finish an...
subroutine, public v_ks_calc_finish(ks, hm, namespace, space, latt, st, ext_partners, force_semilocal)
subroutine, public v_ks_freeze_hxc(ks)
subroutine, public v_ks_end(ks)
subroutine, public v_ks_calculate_current(this, calc_cur)
subroutine, public v_ks_write_info(ks, iunit, namespace)
subroutine, public v_ks_update_dftu_energy(ks, namespace, hm, st, int_dft_u)
Update the value of <\psi | V_U | \psi>, where V_U is the DFT+U potential.
logical function, public v_ks_is_orbital_dependent(ks)
Is the theory method and functional orbital-dependent?
subroutine, public v_ks_calc_start(ks, namespace, space, hm, st, ions, latt, ext_partners, time, calc_energy, force_semilocal)
This routine starts the calculation of the Kohn-Sham potential. The routine v_ks_calc_finish must be ...
subroutine, public v_ks_calc(ks, namespace, space, hm, st, ions, ext_partners, calc_eigenval, time, calc_energy, calc_current, force_semilocal)
subroutine, public v_ks_check_generalized_overlap(ks, st, hm, namespace)
Fence the spin treatments and theory levels / functionals that are not yet correct for ultrasoft/PAW.
subroutine, public v_ks_h_setup(namespace, space, gr, ions, ext_partners, st, ks, hm, calc_eigenval, calc_current)
subroutine, public v_ks_init(ks, namespace, gr, st, ions, mc, space, kpoints)
QEDFT / electron-photon (cavity) extension of the Kohn-Sham potential.
subroutine, public x_slater_calc(namespace, gr, space, exxop, st, kpoints, ex, vxc)
Interface to X(slater_calc)
type(xc_cam_t), parameter, public cam_null
All CAM parameters set to zero.
type(xc_cam_t), parameter, public cam_exact_exchange
Use only Hartree Fock exact exchange.
subroutine, public fbe_c_lda_sl(namespace, psolver, sl_solver, gr, st, space, ec, vxc)
Sturm-Liouville version of the FBE local-density correlation functional.
subroutine, public x_fbe_calc(id, namespace, psolver, sl_solver, gr, st, space, ex, vxc)
Interface to X(x_fbe_calc) Two possible run modes possible: adiabatic and Sturm-Liouville....
integer, parameter, public xc_family_ks_inversion
declaring 'family' constants for 'functionals' not handled by libxc careful not to use a value define...
integer function, public xc_get_default_functional(dim, pseudo_x_functional, pseudo_c_functional)
Returns the default functional given the one parsed from the pseudopotentials and the space dimension...
integer, parameter, public xc_family_nc_mgga
integer, parameter, public xc_oep_x
Exact exchange.
integer, parameter, public xc_lda_c_fbe_sl
LDA correlation based ib the force-balance equation - Sturm-Liouville version.
integer, parameter, public libxc_c_index
integer, parameter, public xc_family_nc_lda
integer, parameter, public xc_oep_x_fbe_sl
Exchange approximation based on the force balance equation - Sturn-Liouville version.
integer, parameter, public xc_oep_x_fbe
Exchange approximation based on the force balance equation.
logical pure function, public xc_functional_is_from_libxc(functl)
Whether the functional is provided by libxc (as opposed to an octopus-internal functional: OEP,...
integer, parameter, public xc_oep_x_slater
Slater approximation to the exact exchange.
integer, parameter, public func_c
integer, parameter, public func_x
subroutine, public xc_ks_inversion_end(ks_inv)
subroutine, public xc_ks_inversion_write_info(ks_inversion, iunit, namespace)
subroutine, public xc_ks_inversion_init(ks_inv, namespace, gr, ions, st, xc, mc, space, kpoints)
subroutine, public xc_ks_inversion_calc(ks_inversion, namespace, space, gr, hm, ext_partners, st, vxc, time)
subroutine, public xc_get_nc_vxc(gr, xcs, st, kpoints, space, namespace, rho, vxc, ex, ec, vtau, ex_density, ec_density)
This routines is similar to xc_get_vxc but for noncollinear functionals, which are not implemented in...
subroutine, public xc_write_info(xcs, iunit, namespace)
pure logical function, public family_is_mgga(family, only_collinear)
Is the xc function part of the mGGA family.
subroutine, public xc_init(xcs, namespace, ndim, periodic_dim, nel, x_id, c_id, xk_id, ck_id, theory_level, ispin)
logical pure function, public family_is_mgga_with_exc(xcs)
Is the xc function part of the mGGA family with an energy functional.
subroutine, public xc_end(xcs)
logical pure function, public family_is_hybrid(xcs)
Returns true if the functional is an hybrid functional.
logical pure function, public xc_is_orbital_dependent(xcs)
Is the xc family orbital dependent.
integer, parameter, public oep_type_mgga
integer, parameter, public oep_level_none
the OEP levels
subroutine, public xc_oep_end(oep)
subroutine, public zxc_oep_calc(oep, namespace, xcs, gr, hm, st, space, rcell_volume, ex, ec, vxc)
This file handles the evaluation of the OEP potential, in the KLI or full OEP as described in S....
subroutine, public dxc_oep_calc(oep, namespace, xcs, gr, hm, st, space, rcell_volume, ex, ec, vxc)
This file handles the evaluation of the OEP potential, in the KLI or full OEP as described in S....
subroutine, public xc_oep_write_info(oep, iunit, namespace)
integer, parameter, public oep_type_exx
The different types of OEP that we can work with.
subroutine, public xc_oep_init(oep, namespace, gr, st, mc, space, oep_type)
integer, parameter, public sic_none
no self-interaction correction
subroutine, public xc_sic_write_info(sic, iunit, namespace)
integer, parameter, public sic_adsic
Averaged density SIC.
subroutine, public xc_sic_init(sic, namespace, gr, st, mc, space)
initialize the SIC object
subroutine, public xc_sic_end(sic)
finalize the SIC and, if needed, the included OEP
integer, parameter, public sic_pz_oep
Perdew-Zunger SIC (OEP way)
integer, parameter, public sic_amaldi
Amaldi correction term.
subroutine, public xc_sic_calc_adsic(sic, namespace, space, gr, st, hm, xc, density, vxc, ex, ec)
Computes the ADSIC potential and energy.
A module that takes care of xc contribution from vdW interactions.
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, force_host, nhat)
Extension of space that contains the knowledge of the spin dimension.
Description of the grid, containing information on derivatives, stencil, and symmetries.
Describes mesh distribution to nodes.
The states_elec_t class contains all electronic wave functions.
Photon (QEDFT) part of v_ks_t.
subroutine get_functional_from_pseudos(x_functional, c_functional)
Tries to find out the functional from the pseudopotential.
subroutine v_a_xc(hm, force_semilocal)
subroutine calculate_density()