56#include "./base/base_uses.f90"
68 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'qs_2nd_kernel_ao'
82 TYPE(
cp_fm_type),
DIMENSION(:),
INTENT(IN) :: c0, c1
85 INTEGER :: ispin, ncol, nspins
95 ncol=ncol, alpha=2.0_dp, &
96 keep_sparsity=.true., &
115 LOGICAL,
INTENT(IN),
OPTIONAL :: recalc_hfx_integrals, calc_forces, &
117 REAL(kind=
dp),
DIMENSION(3, 3),
INTENT(INOUT), &
120 CHARACTER(LEN=*),
PARAMETER :: routinen =
'apply_2nd_order_kernel'
122 INTEGER :: handle, ispin
123 LOGICAL :: do_hfx, my_calc_forces, my_calc_virial, &
124 my_recalc_hfx_integrals
130 CALL timeset(routinen, handle)
132 my_recalc_hfx_integrals = .false.
133 IF (
PRESENT(recalc_hfx_integrals)) my_recalc_hfx_integrals = recalc_hfx_integrals
135 my_calc_forces = .false.
136 IF (
PRESENT(calc_forces)) my_calc_forces = calc_forces
138 my_calc_virial = .false.
139 IF (
PRESENT(calc_virial)) my_calc_virial = calc_virial
141 CALL get_qs_env(qs_env, dft_control=dft_control)
143 DO ispin = 1,
SIZE(p_env%kpp1)
144 CALL dbcsr_set(p_env%kpp1(ispin)%matrix, 0.0_dp)
145 IF (dft_control%do_admm)
CALL dbcsr_set(p_env%kpp1_admm(ispin)%matrix, 0.0_dp)
150 linres_control=linres_control)
152 IF (dft_control%do_admm)
THEN
154 xc_section => admm_env%xc_section_primary
159 CALL calc_kpp1(p_env%rho1_xc, p_env%rho1, xc_section, &
160 dft_control%qs_control%lrigpw, qs_env, p_env, &
161 calc_forces=my_calc_forces, calc_virial=my_calc_virial, virial=virial)
164 NULLIFY (hfx_sections)
168 CALL apply_hfx_ao(qs_env, p_env, my_recalc_hfx_integrals)
170 IF (dft_control%do_admm)
THEN
171 CALL apply_xc_admm_ao(qs_env, p_env, my_calc_forces, my_calc_virial, virial)
176 CALL timestop(handle)
189 LOGICAL,
INTENT(IN),
OPTIONAL :: recalc_integrals
191 CHARACTER(LEN=*),
PARAMETER :: routinen =
'apply_hfx_ao'
193 INTEGER :: handle, ispin, nspins
194 LOGICAL :: my_recalc_integrals
195 REAL(kind=
dp) :: alpha
196 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: h1_mat, rho1, work_hmat
199 CALL timeset(routinen, handle)
201 my_recalc_integrals = .false.
202 IF (
PRESENT(recalc_integrals)) my_recalc_integrals = recalc_integrals
204 CALL get_qs_env(qs_env=qs_env, dft_control=dft_control)
206 IF (dft_control%do_admm)
THEN
208 cpabort(
"ADMM: Linear Response needs purification_method=none")
211 cpabort(
"ADMM: Linear Response needs scaling_model=none")
214 cpabort(
"ADMM: Linear Response needs admm_method=basis_projection")
219 nspins = dft_control%nspins
221 IF (dft_control%do_admm)
THEN
222 rho1 => p_env%p1_admm
223 h1_mat => p_env%kpp1_admm
230 cpassert(
ASSOCIATED(rho1(ispin)%matrix))
231 cpassert(
ASSOCIATED(h1_mat(ispin)%matrix))
237 ALLOCATE (work_hmat(ispin)%matrix)
238 CALL dbcsr_create(work_hmat(ispin)%matrix, template=rho1(ispin)%matrix)
239 CALL dbcsr_copy(work_hmat(ispin)%matrix, rho1(ispin)%matrix)
240 CALL dbcsr_set(work_hmat(ispin)%matrix, 0.0_dp)
244 CALL tddft_hfx_matrix(work_hmat, rho1, qs_env, .false., my_recalc_integrals)
247 IF (nspins == 2) alpha = 1.0_dp
250 CALL dbcsr_add(h1_mat(ispin)%matrix, work_hmat(ispin)%matrix, 1.0_dp, alpha)
255 CALL timestop(handle)
270 LOGICAL,
INTENT(IN),
OPTIONAL :: calc_forces, calc_virial
271 REAL(kind=
dp),
DIMENSION(3, 3),
INTENT(INOUT), &
274 CHARACTER(len=*),
PARAMETER :: routinen =
'apply_xc_admm_ao'
276 INTEGER :: handle, ispin, nao, nao_aux, nspins
277 LOGICAL :: my_calc_forces
278 REAL(kind=
dp) :: alpha
288 TYPE(
rho_atom_type),
DIMENSION(:),
POINTER :: rho0_atom_set, rho1_atom_set
292 CALL timeset(routinen, handle)
294 CALL get_qs_env(qs_env=qs_env, dft_control=dft_control)
297 CALL get_qs_env(qs_env=qs_env, linres_control=linres_control)
298 cpassert(.NOT. dft_control%qs_control%gapw)
299 cpassert(.NOT. dft_control%qs_control%gapw_xc)
300 cpassert(.NOT. dft_control%qs_control%lrigpw)
301 cpassert(.NOT. linres_control%lr_triplet)
302 IF (.NOT.
ASSOCIATED(p_env%kpp1_admm))
THEN
303 cpabort(
"kpp1_admm has to be associated if ADMM kernel calculations are requested")
306 nspins = dft_control%nspins
308 my_calc_forces = .false.
309 IF (
PRESENT(calc_forces)) my_calc_forces = calc_forces
313 NULLIFY (v_xc, v_xc_tau)
314 CALL get_qs_env(qs_env=qs_env, admm_env=admm_env)
315 xc_section => admm_env%xc_section_aux
317 CALL qs_fxc_create(qs_env, rho_aux, p_env%rho1_admm, rho0_atom_set, xc_section, &
318 .false., v_xc, v_xc_tau, rho1_atom_set, &
319 compute_virial=calc_virial, virial_xc=virial)
321 NULLIFY (work_hmat%matrix)
322 ALLOCATE (work_hmat%matrix)
323 CALL dbcsr_copy(work_hmat%matrix, p_env%kpp1_admm(1)%matrix)
326 IF (nspins == 1) alpha = 2.0_dp
329 CALL get_admm_env(admm_env, task_list_aux_fit=task_list_aux_fit)
331 CALL cp_fm_get_info(admm_env%A, nrow_global=nao_aux, ncol_global=nao)
333 CALL pw_scale(v_xc(ispin), v_xc(ispin)%pw_grid%dvol)
335 CALL integrate_v_rspace(v_rspace=v_xc(ispin), hmat=work_hmat, qs_env=qs_env, &
336 calculate_forces=my_calc_forces, basis_type=
"AUX_FIT", &
337 task_list_external=task_list_aux_fit, pmat=rho_ao_aux(ispin))
338 IF (
ASSOCIATED(v_xc_tau))
THEN
339 CALL pw_scale(v_xc_tau(ispin), v_xc_tau(ispin)%pw_grid%dvol)
340 CALL integrate_v_rspace(v_rspace=v_xc_tau(ispin), hmat=work_hmat, qs_env=qs_env, &
341 compute_tau=.true., &
342 calculate_forces=my_calc_forces, basis_type=
"AUX_FIT", &
343 task_list_external=task_list_aux_fit, pmat=rho_ao_aux(ispin))
345 CALL dbcsr_add(p_env%kpp1_admm(ispin)%matrix, work_hmat%matrix, 1.0_dp, alpha)
350 DEALLOCATE (work_hmat%matrix)
353 cpassert(
ASSOCIATED(pw_env))
354 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
357 CALL auxbas_pw_pool%give_back_pw(v_xc(ispin))
360 IF (
ASSOCIATED(v_xc_tau))
THEN
362 CALL auxbas_pw_pool%give_back_pw(v_xc_tau(ispin))
364 DEALLOCATE (v_xc_tau)
369 CALL timestop(handle)
Types and set/get functions for auxiliary density matrix methods.
subroutine, public get_admm_env(admm_env, mo_derivs_aux_fit, mos_aux_fit, sab_aux_fit, sab_aux_fit_asymm, sab_aux_fit_vs_orb, matrix_s_aux_fit, matrix_s_aux_fit_kp, matrix_s_aux_fit_vs_orb, matrix_s_aux_fit_vs_orb_kp, task_list_aux_fit, matrix_ks_aux_fit, matrix_ks_aux_fit_kp, matrix_ks_aux_fit_im, matrix_ks_aux_fit_dft, matrix_ks_aux_fit_hfx, matrix_ks_aux_fit_dft_kp, matrix_ks_aux_fit_hfx_kp, rho_aux_fit, rho_aux_fit_buffer, admm_dm)
Get routine for the ADMM env.
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
subroutine, public dbcsr_copy(matrix_b, matrix_a, name, keep_sparsity, keep_imaginary)
...
subroutine, public dbcsr_set(matrix, alpha)
...
subroutine, public dbcsr_release(matrix)
...
subroutine, public dbcsr_add(matrix_a, matrix_b, alpha_scalar, beta_scalar)
...
DBCSR operations in CP2K.
subroutine, public cp_dbcsr_plus_fm_fm_t(sparse_matrix, matrix_v, matrix_g, ncol, alpha, keep_sparsity, symmetry_mode)
performs the multiplication sparse_matrix+dense_mat*dens_mat^T if matrix_g is not explicitly given,...
represent a full matrix distributed on many processors
subroutine, public cp_fm_get_info(matrix, name, nrow_global, ncol_global, nrow_block, ncol_block, nrow_local, ncol_local, row_indices, col_indices, local_data, context, nrow_locals, ncol_locals, matrix_struct, para_env)
returns all kind of information about the full matrix
Utilities for hfx and admm methods.
subroutine, public tddft_hfx_matrix(matrix_ks, rho_ao, qs_env, update_energy, recalc_integrals, external_hfx_sections, external_x_data, external_para_env)
Add the hfx contributions to the Hamiltonian.
Defines the basic variable types.
integer, parameter, public dp
container for various plainwaves related things
subroutine, public pw_env_get(pw_env, pw_pools, cube_info, gridlevel_info, auxbas_pw_pool, auxbas_grid, auxbas_rs_desc, auxbas_rs_grid, rs_descs, rs_grids, xc_pw_pool, vdw_pw_pool, poisson_env, interp_section)
returns the various attributes of the pw env
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
Routines to calculate 2nd order kernels from a given response density in ao basis linear response scf...
subroutine, public apply_2nd_order_kernel(qs_env, p_env, recalc_hfx_integrals, calc_forces, calc_virial, virial)
Calculate a second order kernel (DFT, HF, ADMM correction) for a given density.
subroutine, public build_dm_response(c0, c1, dm)
This routine builds response density in dbcsr format.
subroutine, public apply_xc_admm_ao(qs_env, p_env, calc_forces, calc_virial, virial)
apply the kernel from the ADMM exchange correction
subroutine, public apply_hfx_ao(qs_env, p_env, recalc_integrals)
This routine applies the Hartree-Fock Exchange kernel to a perturbation density matrix considering AD...
subroutine, public get_qs_env(qs_env, atomic_kind_set, qs_kind_set, cell, super_cell, cell_ref, use_ref_cell, kpoints, dft_control, mos, sab_orb, sab_all, qmmm, qmmm_periodic, mimic, sac_ae, sac_ppl, sac_lri, sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, sab_cneo, particle_set, energy, force, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, matrix_vhxc, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, xcint_weights, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, rhoz_cneo_set, ecoul_1c, rho0_s_rs, rho0_s_gs, rhoz_cneo_s_rs, rhoz_cneo_s_gs, do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, lri_env, lri_density, exstate_env, ec_env, harris_env, dispersion_env, gcp_env, vee, rho_external, external_vxc, mask, mp2_env, bs_env, kg_env, wanniercentres, atprop, ls_scf_env, do_transport, transport_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, mscfg_env, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, eeq, rhs, do_rixs, tb_tblite)
Get the QUICKSTEP environment.
Setup Routine for Fxc Potentials.
subroutine, public qs_fxc_create(qs_env, rho0_struct, rho1_struct, rho0_atom_set, xc_section, do_onecenter, fxc_rho, fxc_tau, rho1_atom_set, do_scale, is_triplet, spinflip, no_weights, uf_grid_results, pw_env_ext, kind_set_external, para_env_external, compute_virial, virial_xc)
...
Integrate single or product functions over a potential on a RS grid.
module that builds the second order perturbation kernel kpp1 = delta_rho|_P delta_rho|_P E drho(P1) d...
subroutine, public calc_kpp1(rho1_xc, rho1, xc_section, lrigpw, qs_env, p_env, calc_forces, calc_virial, virial)
...
Type definitiona for linear response calculations.
Utility functions for the perturbation calculations.
subroutine, public p_env_finish_kpp1(qs_env, p_env)
...
basis types for the calculation of the perturbation of density theory.
superstucture that hold various representations of the density and keeps track of which ones are vali...
subroutine, public qs_rho_get(rho_struct, rho_ao, rho_ao_im, rho_ao_kp, rho_ao_im_kp, rho_r, drho_r, rho_g, drho_g, tau_r, tau_g, rho_r_valid, drho_r_valid, rho_g_valid, drho_g_valid, tau_r_valid, tau_g_valid, tot_rho_r, tot_rho_g, rho_r_sccs, soft_valid, complex_rho_ao)
returns info about the density described by this object. If some representation is not available an e...
stores some data used in wavefunction fitting
contained for different pw related things
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
General settings for linear response calculations.
Represent a qs system that is perturbed. Can calculate the linear operator and the rhs of the system ...
keeps the density in various representations, keeping track of which ones are valid.