(git:23d6dbe)
Loading...
Searching...
No Matches
qs_kernel_methods.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2026 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
19 USE kinds, ONLY: dp
20 USE pw_env_types, ONLY: pw_env_get,&
22 USE pw_methods, ONLY: pw_axpy,&
25 USE pw_types, ONLY: pw_c1d_gs_type,&
32 USE qs_rho_types, ONLY: qs_rho_create,&
38 USE xc, ONLY: xc_prep_2nd_deriv
42#include "./base/base_uses.f90"
43
44 IMPLICIT NONE
45
46 PRIVATE
47
48 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_kernel_methods'
49
50 LOGICAL, PARAMETER, PRIVATE :: debug_this_module = .false.
51
53
54CONTAINS
55
56! **************************************************************************************************
57!> \brief Create kernel environment.
58!> \param kernel_env kernel environment (allocated and initialised on exit)
59!> \param xc_section input section which defines an exchange-correlation functional
60!> \param is_rks_triplets indicates that the triplet excited states calculation using
61!> spin-unpolarised molecular orbitals has been requested
62!> \param rho_struct_sub ground state charge density, if not associated on input, it will be associated on output
63!> \param lsd_singlets ...
64!> \param do_excitations ...
65!> \param sub_env parallel group environment
66!> \param qs_env ...
67!> \par History
68!> * 02.2017 created [Sergey Chulkov]
69!> * 06.2018 the charge density needs to be provided via a dummy argument [Sergey Chulkov]
70! **************************************************************************************************
71 SUBROUTINE create_kernel_env(kernel_env, xc_section, is_rks_triplets, rho_struct_sub, &
72 lsd_singlets, do_excitations, sub_env, qs_env)
73 TYPE(full_kernel_env_type), INTENT(inout) :: kernel_env
74 TYPE(section_vals_type), INTENT(IN), POINTER :: xc_section
75 LOGICAL, INTENT(in) :: is_rks_triplets
76 TYPE(qs_rho_type), POINTER :: rho_struct_sub
77 LOGICAL, INTENT(in), OPTIONAL :: lsd_singlets, do_excitations
78 TYPE(tddfpt_subgroup_env_type), INTENT(in), &
79 OPTIONAL :: sub_env
80 TYPE(qs_environment_type), INTENT(in), OPTIONAL, &
81 POINTER :: qs_env
82
83 CHARACTER(LEN=*), PARAMETER :: routinen = 'create_kernel_env'
84
85 INTEGER :: handle, ispin, nspins
86 LOGICAL :: lsd, my_excitations, my_singlets
87 TYPE(dbcsr_distribution_type), POINTER :: dbcsr_dist
88 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_s, rho_ia_ao
89 TYPE(dft_control_type), POINTER :: dft_control
90 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
91 POINTER :: sab_orb
92 TYPE(pw_env_type), POINTER :: pw_env
93 TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
94 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: rho_ij_r, rho_ij_r2, tau_ij_r, tau_ij_r2
95 TYPE(pw_r3d_rs_type), POINTER :: weights
96 TYPE(section_vals_type), POINTER :: xc_fun_section
97
98 CALL timeset(routinen, handle)
99
100 IF (PRESENT(sub_env)) THEN
101 pw_env => sub_env%pw_env
102 dbcsr_dist => sub_env%dbcsr_dist
103 sab_orb => sub_env%sab_orb
104
105 nspins = SIZE(sub_env%mos_occ)
106
107 NULLIFY (weights)
108 weights => sub_env%xcint_weights
109 IF (sub_env%is_split .AND. ASSOCIATED(weights)) THEN
110 cpabort("Split communicators and integration weights")
111 END IF
112
113 ELSE
114 cpassert(PRESENT(qs_env))
115
116 CALL get_qs_env(qs_env=qs_env, &
117 pw_env=pw_env, &
118 dbcsr_dist=dbcsr_dist, &
119 sab_orb=sab_orb, &
120 dft_control=dft_control)
121
122 NULLIFY (weights)
123 CALL get_qs_env(qs_env=qs_env, xcint_weights=weights)
124
125 nspins = dft_control%nspins
126
127 IF (.NOT. ASSOCIATED(rho_struct_sub)) THEN
128 ! Build rho_set
129 NULLIFY (rho_ia_ao)
130 CALL dbcsr_allocate_matrix_set(rho_ia_ao, nspins)
131 DO ispin = 1, nspins
132 CALL dbcsr_init_p(rho_ia_ao(ispin)%matrix)
133 CALL tddfpt_dbcsr_create_by_dist(rho_ia_ao(ispin)%matrix, template=matrix_s(1)%matrix, &
134 dbcsr_dist=dbcsr_dist, sab=sab_orb)
135 END DO
136
137 ALLOCATE (rho_struct_sub)
138 CALL qs_rho_create(rho_struct_sub)
139 CALL qs_rho_set(rho_struct_sub, rho_ao=rho_ia_ao)
140 CALL qs_rho_rebuild(rho_struct_sub, qs_env, rebuild_ao=.false., &
141 rebuild_grids=.true., pw_env_external=pw_env)
142 END IF
143 END IF
144
145 lsd = (nspins > 1) .OR. is_rks_triplets
146
147 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
148
149 CALL qs_rho_get(rho_struct_sub, rho_r=rho_ij_r, tau_r=tau_ij_r)
150
151 NULLIFY (kernel_env%xc_rho_set, kernel_env%xc_rho1_set)
152
153 ALLOCATE (kernel_env%xc_rho_set)
154 IF (is_rks_triplets) THEN
155 ! we are about to compute triplet states using spin-restricted reference MOs;
156 ! we still need the beta-spin density component in order to compute the TDDFT kernel
157 ALLOCATE (rho_ij_r2(2))
158 rho_ij_r2(1) = rho_ij_r(1)
159 rho_ij_r2(2) = rho_ij_r(1)
160
161 IF (ASSOCIATED(tau_ij_r)) THEN
162 ALLOCATE (tau_ij_r2(2))
163 tau_ij_r2(1) = tau_ij_r(1)
164 tau_ij_r2(2) = tau_ij_r(1)
165 END IF
166
167 CALL xc_prep_2nd_deriv(kernel_env%xc_deriv_set, kernel_env%xc_rho_set, rho_ij_r2, &
168 auxbas_pw_pool, weights, xc_section=xc_section, tau_r=tau_ij_r2)
169
170 IF (ASSOCIATED(tau_ij_r)) DEALLOCATE (tau_ij_r2)
171
172 DEALLOCATE (rho_ij_r2)
173 ELSE
174 CALL xc_prep_2nd_deriv(kernel_env%xc_deriv_set, kernel_env%xc_rho_set, rho_ij_r, &
175 auxbas_pw_pool, weights, xc_section=xc_section, tau_r=tau_ij_r)
176 END IF
177
178 ! ++ allocate structure for response density
179 kernel_env%xc_section => xc_section
180 kernel_env%deriv_method_id = section_get_ival(xc_section, "XC_GRID%XC_DERIV")
181 kernel_env%rho_smooth_id = section_get_ival(xc_section, "XC_GRID%XC_SMOOTH_RHO")
182
183 xc_fun_section => section_vals_get_subs_vals(xc_section, "XC_FUNCTIONAL")
184 kernel_env%xc_rho1_cflags = xc_functionals_get_needs(functionals=xc_fun_section, lsd=lsd, &
185 calc_potential=.true.)
186
187 IF (.NOT. ASSOCIATED(kernel_env%xc_rho1_set)) THEN
188 NULLIFY (kernel_env%xc_rho1_set)
189 ALLOCATE (kernel_env%xc_rho1_set)
190 END IF
191 CALL xc_rho_set_create(kernel_env%xc_rho1_set, auxbas_pw_pool%pw_grid%bounds_local, &
192 rho_cutoff=section_get_rval(xc_section, "DENSITY_CUTOFF"), &
193 drho_cutoff=section_get_rval(xc_section, "GRADIENT_CUTOFF"), &
194 tau_cutoff=section_get_rval(xc_section, "TAU_CUTOFF"))
195
196 my_excitations = .true.
197 IF (PRESENT(do_excitations)) my_excitations = do_excitations
198
199 my_singlets = .false.
200 IF (PRESENT(lsd_singlets)) my_singlets = lsd_singlets
201
202 kernel_env%alpha = 1.0_dp
203 kernel_env%beta = 0.0_dp
204
205 ! kernel_env%beta is taken into account in spin-restricted case only
206 IF (nspins == 1 .AND. my_excitations) THEN
207 IF (is_rks_triplets) THEN
208 ! K_{triplets} = K_{alpha,alpha} - K_{alpha,beta}
209 kernel_env%beta = -1.0_dp
210 ELSE
211 ! alpha beta
212 ! K_{singlets} = K_{alpha,alpha} + K_{alpha,beta} = 2 * K_{alpha,alpha} + 0 * K_{alpha,beta},
213 ! due to the following relation : K_{alpha,alpha,singlets} == K_{alpha,beta,singlets}
214 kernel_env%alpha = 2.0_dp
215
216 IF (my_singlets) THEN
217 kernel_env%beta = 1.0_dp
218 END IF
219 END IF
220 END IF
221
222 ! finite differences
223 kernel_env%deriv2_analytic = section_get_lval(xc_section, "2ND_DERIV_ANALYTICAL")
224 kernel_env%deriv3_analytic = section_get_lval(xc_section, "3RD_DERIV_ANALYTICAL")
225
226 CALL timestop(handle)
227
228 END SUBROUTINE create_kernel_env
229
230! **************************************************************************************************
231!> \brief Create the xc kernel potential for the approximate Fxc kernel model
232!> \param rho_struct ...
233!> \param fxc_rspace ...
234!> \param xc_section ...
235!> \param is_rks_triplets ...
236!> \param sub_env ...
237!> \param qs_env ...
238! **************************************************************************************************
239 SUBROUTINE create_fxc_kernel(rho_struct, fxc_rspace, xc_section, is_rks_triplets, sub_env, qs_env)
240 TYPE(qs_rho_type), POINTER :: rho_struct
241 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: fxc_rspace
242 TYPE(section_vals_type), INTENT(IN), POINTER :: xc_section
243 LOGICAL, INTENT(IN) :: is_rks_triplets
244 TYPE(tddfpt_subgroup_env_type), INTENT(IN) :: sub_env
245 TYPE(qs_environment_type), INTENT(IN), POINTER :: qs_env
246
247 CHARACTER(LEN=*), PARAMETER :: routinen = 'create_fxc_kernel'
248
249 INTEGER :: handle, ispin, nspins
250 LOGICAL :: rho_g_valid, tau_r_valid
251 REAL(kind=dp) :: factor
252 TYPE(pw_c1d_gs_type), DIMENSION(:), POINTER :: rho_g
253 TYPE(pw_c1d_gs_type), POINTER :: rho_nlcc_g
254 TYPE(pw_env_type), POINTER :: pw_env
255 TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
256 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: rho_r, tau_r
257 TYPE(pw_r3d_rs_type), POINTER :: rho_nlcc
258 TYPE(section_vals_type), POINTER :: xc_kernel
259
260 CALL timeset(routinen, handle)
261
262 pw_env => sub_env%pw_env
263 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
264
265 NULLIFY (rho_r, rho_g, tau_r)
266 CALL qs_rho_get(rho_struct, &
267 tau_r_valid=tau_r_valid, &
268 rho_g_valid=rho_g_valid, &
269 rho_r=rho_r, &
270 rho_g=rho_g, &
271 tau_r=tau_r)
272
273 IF (.NOT. tau_r_valid) NULLIFY (tau_r)
274 IF (.NOT. rho_g_valid) NULLIFY (rho_g)
275
276 nspins = SIZE(rho_r)
277
278 NULLIFY (rho_nlcc, rho_nlcc_g)
279 CALL get_qs_env(qs_env, &
280 rho_nlcc=rho_nlcc, &
281 rho_nlcc_g=rho_nlcc_g)
282 ! add the nlcc densities
283 IF (ASSOCIATED(rho_nlcc)) THEN
284 factor = 1.0_dp
285 DO ispin = 1, nspins
286 CALL pw_axpy(rho_nlcc, rho_r(ispin), factor)
287 CALL pw_axpy(rho_nlcc_g, rho_g(ispin), factor)
288 END DO
289 END IF
290
291 DO ispin = 1, SIZE(fxc_rspace)
292 CALL pw_zero(fxc_rspace(ispin))
293 END DO
294
295 xc_kernel => section_vals_get_subs_vals(xc_section, "XC_KERNEL")
296 CALL calc_fxc_kernel(fxc_rspace, rho_r, rho_g, tau_r, &
297 xc_kernel, is_rks_triplets, auxbas_pw_pool)
298
299 ! remove the nlcc densities (keep stuff in original state)
300 IF (ASSOCIATED(rho_nlcc)) THEN
301 factor = -1.0_dp
302 DO ispin = 1, nspins
303 CALL pw_axpy(rho_nlcc, rho_r(ispin), factor)
304 CALL pw_axpy(rho_nlcc_g, rho_g(ispin), factor)
305 END DO
306 END IF
307
308 CALL timestop(handle)
309
310 END SUBROUTINE create_fxc_kernel
311
312END MODULE qs_kernel_methods
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
subroutine, public dbcsr_init_p(matrix)
...
DBCSR operations in CP2K.
objects that represent the structure of input sections and the data contained in an input section
real(kind=dp) function, public section_get_rval(section_vals, keyword_name)
...
integer function, public section_get_ival(section_vals, keyword_name)
...
recursive type(section_vals_type) function, pointer, public section_vals_get_subs_vals(section_vals, subsection_name, i_rep_section, can_return_null)
returns the values of the requested subsection
logical function, public section_get_lval(section_vals, keyword_name)
...
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
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 ...
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, 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.
subroutine, public create_fxc_kernel(rho_struct, fxc_rspace, xc_section, is_rks_triplets, sub_env, qs_env)
Create the xc kernel potential for the approximate Fxc kernel model.
subroutine, public create_kernel_env(kernel_env, xc_section, is_rks_triplets, rho_struct_sub, lsd_singlets, do_excitations, sub_env, qs_env)
Create kernel environment.
Define the neighbor list data types and the corresponding functionality.
methods of the rho structure (defined in qs_rho_types)
subroutine, public qs_rho_rebuild(rho, qs_env, rebuild_ao, rebuild_grids, admm, pw_env_external)
rebuilds rho (if necessary allocating and initializing it)
superstucture that hold various representations of the density and keeps track of which ones are vali...
subroutine, public qs_rho_set(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)
...
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...
subroutine, public qs_rho_create(rho)
Allocates a new instance of rho.
subroutine, public tddfpt_dbcsr_create_by_dist(matrix, template, dbcsr_dist, sab)
Create a DBCSR matrix based on a template matrix, distribution object, and the list of neighbours.
type(xc_rho_cflags_type) function, public xc_functionals_get_needs(functionals, lsd, calc_potential)
...
Exchange and Correlation kernel functionals.
subroutine, public calc_fxc_kernel(fxc_rspace, rho_r, rho_g, tau_r, xc_kernel, triplet, pw_pool)
Exchange and Correlation kernel functional calculations.
contains the structure
subroutine, public xc_rho_set_create(rho_set, local_bounds, rho_cutoff, drho_cutoff, tau_cutoff)
allocates and does (minimal) initialization of a rho_set
Exchange and Correlation functional calculations.
Definition xc.F:17
subroutine, public xc_prep_2nd_deriv(deriv_set, rho_set, rho_r, pw_pool, weights, xc_section, tau_r)
Prepare objects for the calculation of the 2nd derivatives of the density functional....
Definition xc.F:5533
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 ...
Collection of variables required to evaluate adiabatic TDDFPT kernel.
keeps the density in various representations, keeping track of which ones are valid.