(git:374b731)
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-2024 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
11 USE dbcsr_api, ONLY: dbcsr_distribution_type,&
12 dbcsr_init_p,&
13 dbcsr_p_type
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(section_vals_type), POINTER :: xc_fun_section
96
97 CALL timeset(routinen, handle)
98
99 IF (PRESENT(sub_env)) THEN
100 pw_env => sub_env%pw_env
101 dbcsr_dist => sub_env%dbcsr_dist
102 sab_orb => sub_env%sab_orb
103
104 nspins = SIZE(sub_env%mos_occ)
105 ELSE
106 cpassert(PRESENT(qs_env))
107
108 CALL get_qs_env(qs_env=qs_env, &
109 pw_env=pw_env, &
110 dbcsr_dist=dbcsr_dist, &
111 sab_orb=sab_orb, &
112 dft_control=dft_control)
113
114 nspins = dft_control%nspins
115
116 IF (.NOT. ASSOCIATED(rho_struct_sub)) THEN
117 ! Build rho_set
118 NULLIFY (rho_ia_ao)
119 CALL dbcsr_allocate_matrix_set(rho_ia_ao, nspins)
120 DO ispin = 1, nspins
121 CALL dbcsr_init_p(rho_ia_ao(ispin)%matrix)
122 CALL tddfpt_dbcsr_create_by_dist(rho_ia_ao(ispin)%matrix, template=matrix_s(1)%matrix, &
123 dbcsr_dist=dbcsr_dist, sab=sab_orb)
124 END DO
125
126 ALLOCATE (rho_struct_sub)
127 CALL qs_rho_create(rho_struct_sub)
128 CALL qs_rho_set(rho_struct_sub, rho_ao=rho_ia_ao)
129 CALL qs_rho_rebuild(rho_struct_sub, qs_env, rebuild_ao=.false., &
130 rebuild_grids=.true., pw_env_external=pw_env)
131 END IF
132 END IF
133
134 lsd = (nspins > 1) .OR. is_rks_triplets
135
136 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
137
138 CALL qs_rho_get(rho_struct_sub, rho_r=rho_ij_r, tau_r=tau_ij_r)
139
140 NULLIFY (kernel_env%xc_rho_set, kernel_env%xc_rho1_set)
141
142 ALLOCATE (kernel_env%xc_rho_set)
143 IF (is_rks_triplets) THEN
144 ! we are about to compute triplet states using spin-restricted reference MOs;
145 ! we still need the beta-spin density component in order to compute the TDDFT kernel
146 ALLOCATE (rho_ij_r2(2))
147 rho_ij_r2(1) = rho_ij_r(1)
148 rho_ij_r2(2) = rho_ij_r(1)
149
150 IF (ASSOCIATED(tau_ij_r)) THEN
151 ALLOCATE (tau_ij_r2(2))
152 tau_ij_r2(1) = tau_ij_r(1)
153 tau_ij_r2(2) = tau_ij_r(1)
154 END IF
155
156 CALL xc_prep_2nd_deriv(kernel_env%xc_deriv_set, kernel_env%xc_rho_set, rho_ij_r2, &
157 auxbas_pw_pool, xc_section=xc_section, tau_r=tau_ij_r2)
158
159 IF (ASSOCIATED(tau_ij_r)) DEALLOCATE (tau_ij_r2)
160
161 DEALLOCATE (rho_ij_r2)
162 ELSE
163 CALL xc_prep_2nd_deriv(kernel_env%xc_deriv_set, kernel_env%xc_rho_set, rho_ij_r, &
164 auxbas_pw_pool, xc_section=xc_section, tau_r=tau_ij_r)
165 END IF
166
167 ! ++ allocate structure for response density
168 kernel_env%xc_section => xc_section
169 kernel_env%deriv_method_id = section_get_ival(xc_section, "XC_GRID%XC_DERIV")
170 kernel_env%rho_smooth_id = section_get_ival(xc_section, "XC_GRID%XC_SMOOTH_RHO")
171
172 xc_fun_section => section_vals_get_subs_vals(xc_section, "XC_FUNCTIONAL")
173 kernel_env%xc_rho1_cflags = xc_functionals_get_needs(functionals=xc_fun_section, lsd=lsd, &
174 calc_potential=.true.)
175
176 IF (.NOT. ASSOCIATED(kernel_env%xc_rho1_set)) THEN
177 NULLIFY (kernel_env%xc_rho1_set)
178 ALLOCATE (kernel_env%xc_rho1_set)
179 END IF
180 CALL xc_rho_set_create(kernel_env%xc_rho1_set, auxbas_pw_pool%pw_grid%bounds_local, &
181 rho_cutoff=section_get_rval(xc_section, "DENSITY_CUTOFF"), &
182 drho_cutoff=section_get_rval(xc_section, "GRADIENT_CUTOFF"), &
183 tau_cutoff=section_get_rval(xc_section, "TAU_CUTOFF"))
184
185 my_excitations = .true.
186 IF (PRESENT(do_excitations)) my_excitations = do_excitations
187
188 my_singlets = .false.
189 IF (PRESENT(lsd_singlets)) my_singlets = lsd_singlets
190
191 kernel_env%alpha = 1.0_dp
192 kernel_env%beta = 0.0_dp
193
194 ! kernel_env%beta is taken into account in spin-restricted case only
195 IF (nspins == 1 .AND. my_excitations) THEN
196 IF (is_rks_triplets) THEN
197 ! K_{triplets} = K_{alpha,alpha} - K_{alpha,beta}
198 kernel_env%beta = -1.0_dp
199 ELSE
200 ! alpha beta
201 ! K_{singlets} = K_{alpha,alpha} + K_{alpha,beta} = 2 * K_{alpha,alpha} + 0 * K_{alpha,beta},
202 ! due to the following relation : K_{alpha,alpha,singlets} == K_{alpha,beta,singlets}
203 kernel_env%alpha = 2.0_dp
204
205 IF (my_singlets) THEN
206 kernel_env%beta = 1.0_dp
207 END IF
208 END IF
209 END IF
210
211 ! finite differences
212 kernel_env%deriv2_analytic = section_get_lval(xc_section, "2ND_DERIV_ANALYTICAL")
213 kernel_env%deriv3_analytic = section_get_lval(xc_section, "3RD_DERIV_ANALYTICAL")
214
215 CALL timestop(handle)
216
217 END SUBROUTINE create_kernel_env
218
219! **************************************************************************************************
220!> \brief Create the xc kernel potential for the approximate Fxc kernel model
221!> \param rho_struct ...
222!> \param fxc_rspace ...
223!> \param xc_section ...
224!> \param is_rks_triplets ...
225!> \param sub_env ...
226!> \param qs_env ...
227! **************************************************************************************************
228 SUBROUTINE create_fxc_kernel(rho_struct, fxc_rspace, xc_section, is_rks_triplets, sub_env, qs_env)
229 TYPE(qs_rho_type), POINTER :: rho_struct
230 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: fxc_rspace
231 TYPE(section_vals_type), INTENT(IN), POINTER :: xc_section
232 LOGICAL, INTENT(IN) :: is_rks_triplets
233 TYPE(tddfpt_subgroup_env_type), INTENT(IN) :: sub_env
234 TYPE(qs_environment_type), INTENT(IN), POINTER :: qs_env
235
236 CHARACTER(LEN=*), PARAMETER :: routinen = 'create_fxc_kernel'
237
238 INTEGER :: handle, ispin, nspins
239 LOGICAL :: rho_g_valid, tau_r_valid
240 REAL(kind=dp) :: factor
241 TYPE(pw_c1d_gs_type), DIMENSION(:), POINTER :: rho_g
242 TYPE(pw_c1d_gs_type), POINTER :: rho_nlcc_g
243 TYPE(pw_env_type), POINTER :: pw_env
244 TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
245 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: rho_r, tau_r
246 TYPE(pw_r3d_rs_type), POINTER :: rho_nlcc
247 TYPE(section_vals_type), POINTER :: xc_kernel
248
249 CALL timeset(routinen, handle)
250
251 pw_env => sub_env%pw_env
252 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
253
254 NULLIFY (rho_r, rho_g, tau_r)
255 CALL qs_rho_get(rho_struct, &
256 tau_r_valid=tau_r_valid, &
257 rho_g_valid=rho_g_valid, &
258 rho_r=rho_r, &
259 rho_g=rho_g, &
260 tau_r=tau_r)
261
262 IF (.NOT. tau_r_valid) NULLIFY (tau_r)
263 IF (.NOT. rho_g_valid) NULLIFY (rho_g)
264
265 nspins = SIZE(rho_r)
266
267 NULLIFY (rho_nlcc, rho_nlcc_g)
268 CALL get_qs_env(qs_env, &
269 rho_nlcc=rho_nlcc, &
270 rho_nlcc_g=rho_nlcc_g)
271 ! add the nlcc densities
272 IF (ASSOCIATED(rho_nlcc)) THEN
273 factor = 1.0_dp
274 DO ispin = 1, nspins
275 CALL pw_axpy(rho_nlcc, rho_r(ispin), factor)
276 CALL pw_axpy(rho_nlcc_g, rho_g(ispin), factor)
277 END DO
278 END IF
279
280 DO ispin = 1, SIZE(fxc_rspace)
281 CALL pw_zero(fxc_rspace(ispin))
282 END DO
283
284 xc_kernel => section_vals_get_subs_vals(xc_section, "XC_KERNEL")
285 CALL calc_fxc_kernel(fxc_rspace, rho_r, rho_g, tau_r, &
286 xc_kernel, is_rks_triplets, auxbas_pw_pool)
287
288 ! remove the nlcc densities (keep stuff in original state)
289 IF (ASSOCIATED(rho_nlcc)) THEN
290 factor = -1.0_dp
291 DO ispin = 1, nspins
292 CALL pw_axpy(rho_nlcc, rho_r(ispin), factor)
293 CALL pw_axpy(rho_nlcc_g, rho_g(ispin), factor)
294 END DO
295 END IF
296
297 CALL timestop(handle)
298
299 END SUBROUTINE create_fxc_kernel
300
301END MODULE qs_kernel_methods
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
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, 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_nonbond, sab_almo, sab_kp, sab_kp_nosym, 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, 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, ecoul_1c, rho0_s_rs, rho0_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, 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, rhs)
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, xc_section, tau_r)
Prepare objects for the calculation of the 2nd derivatives of the density functional....
Definition xc.F:5364
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.