(git:f2099e5)
Loading...
Searching...
No Matches
qs_linres_kernel.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
8! **************************************************************************************************
9!> \brief linres kernel functions
10!> \par History
11!> created from qs_linres_methods
12!> \author JGH
13! **************************************************************************************************
15 USE admm_types, ONLY: admm_type,&
20 USE cp_dbcsr_api, ONLY: dbcsr_add,&
29 USE cp_fm_types, ONLY: cp_fm_get_info,&
35 USE hfx_ri, ONLY: hfx_ri_update_ks
36 USE hfx_types, ONLY: hfx_type
48 USE kinds, ONLY: default_string_length,&
49 dp
55 USE mulliken, ONLY: ao_charges
57 USE pw_env_types, ONLY: pw_env_get,&
59 USE pw_methods, ONLY: pw_axpy,&
60 pw_copy,&
61 pw_scale,&
66 USE pw_types, ONLY: pw_c1d_gs_type,&
71 USE qs_fxc, ONLY: qs_fxc_apply,&
74 USE qs_integrate_potential, ONLY: integrate_v_rspace,&
75 integrate_v_rspace_diagonal,&
76 integrate_v_rspace_one_center
77 USE qs_kind_types, ONLY: get_qs_kind,&
82 USE qs_ks_atom, ONLY: update_ks_atom
91 USE qs_rho_types, ONLY: qs_rho_create,&
97 USE xtb_types, ONLY: get_xtb_atom_param,&
99#include "./base/base_uses.f90"
100
101 IMPLICIT NONE
102
103 PRIVATE
104
105 ! *** Public subroutines ***
106 PUBLIC :: apply_xc_admm
107 PUBLIC :: apply_hfx
108 PUBLIC :: apply_hxc_kernel_kp
109 PUBLIC :: apply_op_2
110 PUBLIC :: hfx_matrix
111
112 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_linres_kernel'
113
114! **************************************************************************************************
115
116CONTAINS
117
118! **************************************************************************************************
119!> \brief Apply the periodic GPW Hartree-XC kernel to a K-point AO density response.
120!> \param qs_env Ground-state QS environment defining the density and XC kernel.
121!> \param kpp1_env Persistent XC derivative data at the ground-state density.
122!> \param rho1_ao_kp Real-space image matrices of the spin-resolved density response.
123!> \param v1_ao_kp Real-space image matrices of the resulting Hartree-XC potential response.
124!>
125!> The input is the physical density response, including occupations and irreducible K-point
126!> weights. Consequently, unlike the occupied-virtual linear-response path, no closed-shell
127!> factor of two is introduced here.
128! **************************************************************************************************
129 SUBROUTINE apply_hxc_kernel_kp(qs_env, kpp1_env, rho1_ao_kp, v1_ao_kp)
130 TYPE(qs_environment_type), POINTER :: qs_env
131 TYPE(qs_kpp1_env_type), INTENT(INOUT) :: kpp1_env
132 TYPE(dbcsr_p_type), DIMENSION(:, :), INTENT(IN) :: rho1_ao_kp
133 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: v1_ao_kp
134
135 CHARACTER(LEN=*), PARAMETER :: routinen = 'apply_hxc_kernel_kp'
136
137 INTEGER :: handle, img, ispin, nimages, nspins
138 LOGICAL :: do_hfx
139 REAL(kind=dp) :: energy_hartree
140 TYPE(admm_type), POINTER :: admm_env
141 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: v1_ao_spin
142 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: rho1_work
143 TYPE(dft_control_type), POINTER :: dft_control
144 TYPE(pw_c1d_gs_type) :: rho1_tot_gspace, v_hartree_gspace
145 TYPE(pw_c1d_gs_type), DIMENSION(:), POINTER :: rho1_g
146 TYPE(pw_env_type), POINTER :: pw_env
147 TYPE(pw_poisson_type), POINTER :: poisson_env
148 TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
149 TYPE(pw_r3d_rs_type) :: v_hartree_rspace
150 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: rho0_r, rho1_r, v_hxc, v_xc, v_xc_tau
151 TYPE(qs_rho_type), POINTER :: rho, rho1
152 TYPE(qs_rho_type), TARGET :: rho1_store
153 TYPE(rho_atom_type), DIMENSION(:), POINTER :: rho1_atom_set, rho_atom_set
154 TYPE(section_vals_type), POINTER :: hfx_section, input, xc_section
155
156 CALL timeset(routinen, handle)
157
158 NULLIFY (admm_env, auxbas_pw_pool, dft_control, hfx_section, input, poisson_env, pw_env, rho, rho1, &
159 rho1_g, rho1_work, rho_atom_set, rho1_atom_set, v1_ao_spin, v_hxc, v_xc, &
160 v_xc_tau, xc_section)
161 CALL get_qs_env(qs_env=qs_env, admm_env=admm_env, dft_control=dft_control, input=input, &
162 pw_env=pw_env, rho=rho)
163
164 IF (dft_control%qs_control%semi_empirical .OR. dft_control%qs_control%dftb .OR. &
165 dft_control%qs_control%xtb) THEN
166 cpabort("The periodic AO Hartree-XC kernel is only available for DFT")
167 END IF
168 IF (dft_control%qs_control%gapw .OR. dft_control%qs_control%gapw_xc .OR. &
169 dft_control%qs_control%lrigpw .OR. dft_control%qs_control%rigpw) THEN
170 cpabort("The periodic AO Hartree-XC kernel currently requires GPW")
171 END IF
172 IF (dft_control%do_admm) THEN
173 cpabort("The periodic AO Hartree-XC kernel currently excludes ADMM")
174 END IF
175 hfx_section => section_vals_get_subs_vals(input, "DFT%XC%HF")
176 CALL section_vals_get(hfx_section, explicit=do_hfx)
177 IF (do_hfx) THEN
178 cpabort("The periodic AO Hartree-XC kernel currently excludes exact exchange")
179 END IF
180
181 nspins = dft_control%nspins
182 nimages = dft_control%nimages
183 cpassert(all(shape(rho1_ao_kp) == [nspins, nimages]))
184
185 IF (.NOT. ASSOCIATED(v1_ao_kp)) THEN
186 CALL dbcsr_allocate_matrix_set(v1_ao_kp, nspins, nimages)
187 DO ispin = 1, nspins
188 DO img = 1, nimages
189 ALLOCATE (v1_ao_kp(ispin, img)%matrix)
190 CALL dbcsr_copy(v1_ao_kp(ispin, img)%matrix, rho1_ao_kp(ispin, img)%matrix, &
191 name="K-point Hartree-XC response")
192 END DO
193 END DO
194 ELSE
195 cpassert(all(shape(v1_ao_kp) == [nspins, nimages]))
196 END IF
197 DO ispin = 1, nspins
198 DO img = 1, nimages
199 CALL dbcsr_set(v1_ao_kp(ispin, img)%matrix, 0.0_dp)
200 END DO
201 END DO
202
203 CALL qs_rho_create(rho1_store)
204 rho1 => rho1_store
205 CALL qs_rho_rebuild(rho1_store, qs_env, rebuild_ao=.true., rebuild_grids=.true.)
206 CALL qs_rho_get(rho1, rho_ao_kp=rho1_work)
207 DO ispin = 1, nspins
208 DO img = 1, nimages
209 CALL dbcsr_copy(rho1_work(ispin, img)%matrix, rho1_ao_kp(ispin, img)%matrix)
210 END DO
211 END DO
212 CALL qs_rho_update_rho(rho1, qs_env)
213
214 xc_section => section_vals_get_subs_vals(input, "DFT%XC")
215 IF (.NOT. ASSOCIATED(kpp1_env%deriv_set)) THEN
216 ALLOCATE (kpp1_env%deriv_set, kpp1_env%rho_set)
217 CALL qs_fxc_prep(qs_env, rho, kpp1_env%rho_set, kpp1_env%deriv_set, &
218 xc_section, pw_env, is_triplet=.false.)
219 END IF
220
221 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool, poisson_env=poisson_env)
222 CALL auxbas_pw_pool%create_pw(rho1_tot_gspace)
223 CALL auxbas_pw_pool%create_pw(v_hartree_gspace)
224 CALL auxbas_pw_pool%create_pw(v_hartree_rspace)
225 CALL qs_rho_get(rho1, rho_g=rho1_g)
226 CALL pw_copy(rho1_g(1), rho1_tot_gspace)
227 DO ispin = 2, nspins
228 CALL pw_axpy(rho1_g(ispin), rho1_tot_gspace)
229 END DO
230 energy_hartree = 0.0_dp
231 CALL pw_poisson_solve(poisson_env, rho1_tot_gspace, energy_hartree, v_hartree_gspace)
232 CALL pw_transfer(v_hartree_gspace, v_hartree_rspace)
233 CALL pw_scale(v_hartree_rspace, v_hartree_rspace%pw_grid%dvol)
234
235 CALL qs_fxc_apply(qs_env, kpp1_env%deriv_set, kpp1_env%rho_set, rho1, &
236 rho_atom_set, xc_section, .false., v_xc, v_xc_tau, rho1_atom_set)
237 ! nl-vdW
238 CALL qs_rho_get(rho, rho_r=rho0_r)
239 CALL qs_rho_get(rho1, rho_r=rho1_r)
240 CALL qs_fxc_nlvdw_apply(qs_env, xc_section, qs_env%dispersion_env, rho0_r, rho1_r, v_xc)
241 !
242 v_hxc => v_xc
243 NULLIFY (v_xc)
244 DO ispin = 1, nspins
245 CALL pw_scale(v_hxc(ispin), v_hxc(ispin)%pw_grid%dvol)
246 CALL pw_axpy(v_hartree_rspace, v_hxc(ispin))
247 v1_ao_spin => v1_ao_kp(ispin, :)
248 CALL integrate_v_rspace(v_rspace=v_hxc(ispin), hmat_kp=v1_ao_spin, &
249 qs_env=qs_env, calculate_forces=.false.)
250 END DO
251 IF (ASSOCIATED(v_xc_tau)) THEN
252 DO ispin = 1, nspins
253 CALL pw_scale(v_xc_tau(ispin), v_xc_tau(ispin)%pw_grid%dvol)
254 v1_ao_spin => v1_ao_kp(ispin, :)
255 CALL integrate_v_rspace(v_rspace=v_xc_tau(ispin), hmat_kp=v1_ao_spin, &
256 qs_env=qs_env, compute_tau=.true., calculate_forces=.false.)
257 END DO
258 END IF
259 NULLIFY (v1_ao_spin)
260
261 CALL auxbas_pw_pool%give_back_pw(rho1_tot_gspace)
262 CALL auxbas_pw_pool%give_back_pw(v_hartree_gspace)
263 CALL auxbas_pw_pool%give_back_pw(v_hartree_rspace)
264 DO ispin = 1, SIZE(v_hxc)
265 CALL auxbas_pw_pool%give_back_pw(v_hxc(ispin))
266 END DO
267 DEALLOCATE (v_hxc)
268 IF (ASSOCIATED(v_xc_tau)) THEN
269 DO ispin = 1, SIZE(v_xc_tau)
270 CALL auxbas_pw_pool%give_back_pw(v_xc_tau(ispin))
271 END DO
272 DEALLOCATE (v_xc_tau)
273 END IF
274 CALL qs_rho_release(rho1_store)
275
276 CALL timestop(handle)
277 END SUBROUTINE apply_hxc_kernel_kp
278
279! **************************************************************************************************
280!> \brief ...
281!> \param qs_env ...
282!> \param p_env ...
283!> \param c0 ...
284!> \param Av ...
285! **************************************************************************************************
286 SUBROUTINE apply_op_2(qs_env, p_env, c0, Av)
287 !
288 TYPE(qs_environment_type), POINTER :: qs_env
289 TYPE(qs_p_env_type) :: p_env
290 TYPE(cp_fm_type), DIMENSION(:), INTENT(IN) :: c0
291 TYPE(cp_fm_type), DIMENSION(:), INTENT(INOUT) :: av
292
293 INTEGER :: ispin, ncol
294 TYPE(dft_control_type), POINTER :: dft_control
295
296 CALL get_qs_env(qs_env=qs_env, dft_control=dft_control)
297 IF (dft_control%qs_control%semi_empirical) THEN
298 cpabort("Linear response not available with SE methods")
299 ELSE IF (dft_control%qs_control%dftb) THEN
300 cpabort("Linear response not available with DFTB")
301 ELSE IF (dft_control%qs_control%xtb) THEN
302 CALL apply_op_2_xtb(qs_env, p_env)
303 ELSE
304 CALL apply_op_2_dft(qs_env, p_env)
305 CALL apply_hfx(qs_env, p_env)
306 CALL apply_xc_admm(qs_env, p_env)
307 IF (dft_control%do_admm) CALL p_env_finish_kpp1(qs_env, p_env)
308 END IF
309
310 DO ispin = 1, SIZE(c0)
311 CALL cp_fm_get_info(c0(ispin), ncol_global=ncol)
312 CALL cp_dbcsr_sm_fm_multiply(p_env%kpp1(ispin)%matrix, &
313 c0(ispin), &
314 av(ispin), &
315 ncol=ncol, alpha=1.0_dp, beta=1.0_dp)
316 END DO
317
318 END SUBROUTINE apply_op_2
319
320! **************************************************************************************************
321!> \brief ...
322!> \param qs_env ...
323!> \param p_env ...
324! **************************************************************************************************
325 SUBROUTINE apply_op_2_dft(qs_env, p_env)
326 TYPE(qs_environment_type), POINTER :: qs_env
327 TYPE(qs_p_env_type) :: p_env
328
329 CHARACTER(len=*), PARAMETER :: routinen = 'apply_op_2_dft'
330
331 INTEGER :: handle, ikind, ispin, nkind, ns, nspins
332 LOGICAL :: do_onecenter, gapw, gapw_xc, lr_triplet, &
333 lrigpw
334 REAL(kind=dp) :: alpha, ekin_mol, energy_hartree, &
335 energy_hartree_1c
336 TYPE(admm_type), POINTER :: admm_env
337 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
338 TYPE(cp_logger_type), POINTER :: logger
339 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: k1mat, rho1_ao, rho_ao
340 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: ksmat, psmat
341 TYPE(dft_control_type), POINTER :: dft_control
342 TYPE(kg_environment_type), POINTER :: kg_env
343 TYPE(linres_control_type), POINTER :: linres_control
344 TYPE(lri_density_type), POINTER :: lri_density
345 TYPE(lri_environment_type), POINTER :: lri_env
346 TYPE(lri_kind_type), DIMENSION(:), POINTER :: lri_v_int
347 TYPE(mp_para_env_type), POINTER :: para_env
348 TYPE(pw_c1d_gs_type) :: rho1_tot_gspace, v_hartree_gspace
349 TYPE(pw_c1d_gs_type), DIMENSION(:), POINTER :: rho1_g
350 TYPE(pw_env_type), POINTER :: pw_env
351 TYPE(pw_poisson_type), POINTER :: poisson_env
352 TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
353 TYPE(pw_r3d_rs_type) :: v_hartree_rspace
354 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: rho0_r, rho1_r, rho_r, v_rspace_new, &
355 v_xc, v_xc_tau
356 TYPE(qs_kpp1_env_type), POINTER :: kpp1_env
357 TYPE(qs_rho_type), POINTER :: rho, rho0, rho1, rho1_xc, rho1a, &
358 rho_aux, rho_xc
359 TYPE(rho_atom_type), DIMENSION(:), POINTER :: rho1_atom_set, rho_atom_set
360 TYPE(section_vals_type), POINTER :: input, xc_section, xc_section_aux
361
362 CALL timeset(routinen, handle)
363
364 NULLIFY (auxbas_pw_pool, pw_env, v_rspace_new, para_env, v_xc, &
365 rho1_ao, rho_ao, poisson_env, input, rho, dft_control, logger, &
366 rho1_g, v_xc_tau)
367 logger => cp_get_default_logger()
368
369 energy_hartree = 0.0_dp
370 energy_hartree_1c = 0.0_dp
371
372 cpassert(ASSOCIATED(p_env%kpp1))
373 cpassert(ASSOCIATED(p_env%kpp1_env))
374 kpp1_env => p_env%kpp1_env
375
376 CALL get_qs_env(qs_env=qs_env, &
377 pw_env=pw_env, &
378 input=input, &
379 admm_env=admm_env, &
380 para_env=para_env, &
381 rho=rho, &
382 rho_xc=rho_xc, &
383 linres_control=linres_control, &
384 dft_control=dft_control)
385
386 gapw = dft_control%qs_control%gapw
387 gapw_xc = dft_control%qs_control%gapw_xc
388 do_onecenter = gapw .OR. gapw_xc
389 lr_triplet = linres_control%lr_triplet
390
391 rho1 => p_env%rho1
392 rho1_xc => p_env%rho1_xc
393 cpassert(ASSOCIATED(rho1))
394 IF (gapw_xc) THEN
395 cpassert(ASSOCIATED(rho1_xc))
396 END IF
397
398 CALL qs_rho_get(rho, rho_ao=rho_ao, rho_r=rho_r)
399 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
400
401 nspins = SIZE(p_env%kpp1)
402 lrigpw = dft_control%qs_control%lrigpw
403 IF (lrigpw) THEN
404 CALL get_qs_env(qs_env, &
405 lri_env=lri_env, &
406 lri_density=lri_density, &
407 atomic_kind_set=atomic_kind_set)
408 END IF
409
410 IF (dft_control%do_admm) THEN
411 xc_section => admm_env%xc_section_primary
412 ELSE
413 xc_section => section_vals_get_subs_vals(input, "DFT%XC")
414 END IF
415
416 CALL kpp1_check_i_alloc(kpp1_env, qs_env, xc_section)
417
418 ! gets the tmp grids
419 cpassert(ASSOCIATED(pw_env))
420 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool, &
421 poisson_env=poisson_env)
422 CALL auxbas_pw_pool%create_pw(v_hartree_gspace)
423 CALL auxbas_pw_pool%create_pw(v_hartree_rspace)
424
425 IF (gapw .OR. gapw_xc) THEN
426 CALL prepare_gapw_den(qs_env, p_env%local_rho_set, do_rho0=(.NOT. gapw_xc))
427 END IF
428
429 ! *** calculate the hartree potential on the total density ***
430 CALL auxbas_pw_pool%create_pw(rho1_tot_gspace)
431
432 CALL qs_rho_get(rho1, rho_g=rho1_g)
433 CALL pw_copy(rho1_g(1), rho1_tot_gspace)
434 DO ispin = 2, nspins
435 CALL pw_axpy(rho1_g(ispin), rho1_tot_gspace)
436 END DO
437 IF (gapw) THEN
438 CALL pw_axpy(p_env%local_rho_set%rho0_mpole%rho0_s_gs, rho1_tot_gspace)
439 IF (ASSOCIATED(p_env%local_rho_set%rho0_mpole%rhoz_cneo_s_gs)) THEN
440 CALL pw_axpy(p_env%local_rho_set%rho0_mpole%rhoz_cneo_s_gs, rho1_tot_gspace)
441 END IF
442 END IF
443
444 IF (.NOT. (nspins == 1 .AND. lr_triplet)) THEN
445 CALL pw_poisson_solve(poisson_env, rho1_tot_gspace, &
446 energy_hartree, &
447 v_hartree_gspace)
448 CALL pw_transfer(v_hartree_gspace, v_hartree_rspace)
449 END IF
450
451 CALL auxbas_pw_pool%give_back_pw(rho1_tot_gspace)
452
453 ! *** calculate the xc potential ***
454 NULLIFY (rho1a)
455 IF (gapw_xc) THEN
456 CALL get_qs_env(qs_env, rho_xc=rho0)
457 rho1a => rho1_xc
458 ELSE
459 CALL get_qs_env(qs_env, rho=rho0)
460 rho1a => rho1
461 END IF
462
463 NULLIFY (v_xc_tau)
464 NULLIFY (rho_atom_set, rho1_atom_set)
465 IF (do_onecenter) THEN
466 CALL get_qs_env(qs_env, rho_atom_set=rho_atom_set)
467 rho1_atom_set => p_env%local_rho_set%rho_atom_set
468 END IF
469 CALL qs_fxc_apply(qs_env, kpp1_env%deriv_set, kpp1_env%rho_set, rho1a, rho_atom_set, &
470 xc_section, do_onecenter, v_xc, v_xc_tau, rho1_atom_set)
471 ! nl-vdW
472 CALL qs_rho_get(rho0, rho_r=rho0_r)
473 CALL qs_rho_get(rho1a, rho_r=rho1_r)
474 CALL qs_fxc_nlvdw_apply(qs_env, xc_section, qs_env%dispersion_env, rho0_r, rho1_r, v_xc)
475
476 v_rspace_new => v_xc
477 NULLIFY (v_xc)
478
479 CALL pw_scale(v_hartree_rspace, v_hartree_rspace%pw_grid%dvol)
480 DO ispin = 1, nspins
481 CALL pw_scale(v_rspace_new(ispin), v_rspace_new(ispin)%pw_grid%dvol)
482 IF (ASSOCIATED(v_xc_tau)) CALL pw_scale(v_xc_tau(ispin), v_xc_tau(ispin)%pw_grid%dvol)
483 END DO
484
485 ! ADMM Correction
486 IF (dft_control%do_admm) THEN
487 IF (admm_env%aux_exch_func /= do_admm_aux_exch_func_none) THEN
488 IF (.NOT. ASSOCIATED(kpp1_env%deriv_set_admm)) THEN
489 cpassert(.NOT. lr_triplet)
490 xc_section_aux => admm_env%xc_section_aux
491 CALL get_admm_env(qs_env%admm_env, rho_aux_fit=rho_aux)
492 ALLOCATE (kpp1_env%deriv_set_admm, kpp1_env%rho_set_admm)
493 CALL qs_fxc_prep(qs_env, rho_aux, kpp1_env%rho_set_admm, kpp1_env%deriv_set_admm, &
494 xc_section_aux, pw_env, is_triplet=.false.)
495 END IF
496 END IF
497 END IF
498
499 !-------------------------------!
500 ! Add both hartree and xc terms !
501 !-------------------------------!
502 DO ispin = 1, nspins
503 CALL dbcsr_set(kpp1_env%v_ao(ispin)%matrix, 0.0_dp)
504
505 IF (gapw_xc) THEN
506 ! XC and Hartree are integrated separatedly
507 ! XC uses the soft basis set only
508
509 IF (nspins == 1) THEN
510
511 IF (.NOT. (lr_triplet)) THEN
512 CALL pw_scale(v_rspace_new(1), 2.0_dp)
513 IF (ASSOCIATED(v_xc_tau)) CALL pw_scale(v_xc_tau(1), 2.0_dp)
514 END IF
515 CALL qs_rho_get(rho1, rho_ao=rho1_ao)
516 ! remove kpp1_env%v_ao and work directly on k_p_p1 ?
517 CALL integrate_v_rspace(v_rspace=v_rspace_new(ispin), &
518 pmat=rho1_ao(ispin), &
519 hmat=kpp1_env%v_ao(ispin), &
520 qs_env=qs_env, &
521 calculate_forces=.false., gapw=gapw_xc)
522
523 IF (ASSOCIATED(v_xc_tau)) THEN
524 CALL integrate_v_rspace(v_rspace=v_xc_tau(ispin), &
525 pmat=rho1_ao(ispin), &
526 hmat=kpp1_env%v_ao(ispin), &
527 qs_env=qs_env, &
528 compute_tau=.true., &
529 calculate_forces=.false., gapw=gapw_xc)
530 END IF
531
532 ! add hartree only for SINGLETS
533 IF (.NOT. lr_triplet) THEN
534 CALL pw_axpy(v_hartree_rspace, v_rspace_new(1), 2.0_dp, 0.0_dp)
535
536 CALL integrate_v_rspace(v_rspace=v_rspace_new(ispin), &
537 pmat=rho_ao(ispin), &
538 hmat=kpp1_env%v_ao(ispin), &
539 qs_env=qs_env, &
540 calculate_forces=.false., gapw=gapw)
541 END IF
542 ELSE
543 ! remove kpp1_env%v_ao and work directly on k_p_p1 ?
544 CALL integrate_v_rspace(v_rspace=v_rspace_new(ispin), &
545 pmat=rho_ao(ispin), &
546 hmat=kpp1_env%v_ao(ispin), &
547 qs_env=qs_env, &
548 calculate_forces=.false., gapw=gapw_xc)
549
550 IF (ASSOCIATED(v_xc_tau)) THEN
551 CALL integrate_v_rspace(v_rspace=v_xc_tau(ispin), &
552 pmat=rho_ao(ispin), &
553 hmat=kpp1_env%v_ao(ispin), &
554 qs_env=qs_env, &
555 compute_tau=.true., &
556 calculate_forces=.false., gapw=gapw_xc)
557 END IF
558
559 CALL pw_copy(v_hartree_rspace, v_rspace_new(ispin))
560 CALL integrate_v_rspace(v_rspace=v_rspace_new(ispin), &
561 pmat=rho_ao(ispin), &
562 hmat=kpp1_env%v_ao(ispin), &
563 qs_env=qs_env, &
564 calculate_forces=.false., gapw=gapw)
565 END IF
566
567 ELSE
568
569 IF (nspins == 1) THEN
570 IF (.NOT. (lr_triplet)) THEN
571 CALL pw_scale(v_rspace_new(1), 2.0_dp)
572 IF (ASSOCIATED(v_xc_tau)) CALL pw_scale(v_xc_tau(1), 2.0_dp)
573 END IF
574 ! add hartree only for SINGLETS
575 !IF (res_etype == tddfpt_singlet) THEN
576 IF (.NOT. lr_triplet) THEN
577 CALL pw_axpy(v_hartree_rspace, v_rspace_new(1), 2.0_dp)
578 END IF
579 ELSE
580 CALL pw_axpy(v_hartree_rspace, v_rspace_new(ispin), 1.0_dp)
581 END IF
582
583 IF (lrigpw) THEN
584 IF (ASSOCIATED(v_xc_tau)) THEN
585 cpabort("metaGGA-functionals not supported with LRI!")
586 END IF
587
588 lri_v_int => lri_density%lri_coefs(ispin)%lri_kinds
589 CALL get_qs_env(qs_env, nkind=nkind)
590 DO ikind = 1, nkind
591 lri_v_int(ikind)%v_int = 0.0_dp
592 END DO
593 CALL integrate_v_rspace_one_center(v_rspace_new(ispin), qs_env, &
594 lri_v_int, .false., "LRI_AUX")
595 DO ikind = 1, nkind
596 CALL para_env%sum(lri_v_int(ikind)%v_int)
597 END DO
598 ALLOCATE (k1mat(1))
599 k1mat(1)%matrix => kpp1_env%v_ao(ispin)%matrix
600 IF (lri_env%exact_1c_terms) THEN
601 CALL integrate_v_rspace_diagonal(v_rspace_new(ispin), k1mat(1)%matrix, &
602 rho_ao(ispin)%matrix, qs_env, .false., "ORB")
603 END IF
604 CALL calculate_lri_ks_matrix(lri_env, lri_v_int, k1mat, atomic_kind_set)
605 DEALLOCATE (k1mat)
606 ELSE
607 CALL integrate_v_rspace(v_rspace=v_rspace_new(ispin), &
608 pmat=rho_ao(ispin), &
609 hmat=kpp1_env%v_ao(ispin), &
610 qs_env=qs_env, &
611 calculate_forces=.false., gapw=gapw)
612
613 IF (ASSOCIATED(v_xc_tau)) THEN
614 CALL integrate_v_rspace(v_rspace=v_xc_tau(ispin), &
615 pmat=rho_ao(ispin), &
616 hmat=kpp1_env%v_ao(ispin), &
617 qs_env=qs_env, &
618 compute_tau=.true., &
619 calculate_forces=.false., gapw=gapw)
620 END IF
621 END IF
622
623 END IF
624
625 CALL dbcsr_copy(p_env%kpp1(ispin)%matrix, kpp1_env%v_ao(ispin)%matrix)
626 END DO
627
628 IF (gapw) THEN
629 IF (.NOT. ((nspins == 1 .AND. lr_triplet))) THEN
630 CALL vh_1c_gg_integrals(qs_env, energy_hartree_1c, &
631 p_env%hartree_local%ecoul_1c, &
632 p_env%local_rho_set, &
633 para_env, tddft=.true., core_2nd=.true.)
634
635 CALL integrate_vhg0_rspace(qs_env, v_hartree_rspace, para_env, &
636 calculate_forces=.false., &
637 local_rho_set=p_env%local_rho_set)
638 END IF
639 ! *** Add single atom contributions to the KS matrix ***
640 ! remap pointer
641 ns = SIZE(p_env%kpp1)
642 ksmat(1:ns, 1:1) => p_env%kpp1(1:ns)
643 ns = SIZE(rho_ao)
644 psmat(1:ns, 1:1) => rho_ao(1:ns)
645 CALL update_ks_atom(qs_env, ksmat, psmat, forces=.false., tddft=.true., &
646 rho_atom_external=p_env%local_rho_set%rho_atom_set)
647 ELSE IF (gapw_xc) THEN
648 ns = SIZE(p_env%kpp1)
649 ksmat(1:ns, 1:1) => p_env%kpp1(1:ns)
650 ns = SIZE(rho_ao)
651 psmat(1:ns, 1:1) => rho_ao(1:ns)
652 CALL update_ks_atom(qs_env, ksmat, psmat, forces=.false., tddft=.true., &
653 rho_atom_external=p_env%local_rho_set%rho_atom_set)
654 END IF
655
656 ! KG embedding, contribution of kinetic energy functional to kernel
657 IF (dft_control%qs_control%do_kg .AND. .NOT. (lr_triplet .OR. gapw .OR. gapw_xc)) THEN
658 IF (qs_env%kg_env%tnadd_method == kg_tnadd_embed) THEN
659
660 CALL qs_rho_get(rho1, rho_ao=rho1_ao)
661 alpha = 1.0_dp
662
663 ekin_mol = 0.0_dp
664 CALL get_qs_env(qs_env, kg_env=kg_env)
665 CALL kg_ekin_subset(qs_env=qs_env, &
666 ks_matrix=p_env%kpp1, &
667 ekin_mol=ekin_mol, &
668 calc_force=.false., &
669 do_kernel=.true., &
670 pmat_ext=rho1_ao)
671 END IF
672 END IF
673
674 CALL auxbas_pw_pool%give_back_pw(v_hartree_gspace)
675 CALL auxbas_pw_pool%give_back_pw(v_hartree_rspace)
676 DO ispin = 1, nspins
677 CALL auxbas_pw_pool%give_back_pw(v_rspace_new(ispin))
678 END DO
679 DEALLOCATE (v_rspace_new)
680 IF (ASSOCIATED(v_xc_tau)) THEN
681 DO ispin = 1, nspins
682 CALL auxbas_pw_pool%give_back_pw(v_xc_tau(ispin))
683 END DO
684 DEALLOCATE (v_xc_tau)
685 END IF
686
687 CALL timestop(handle)
688
689 END SUBROUTINE apply_op_2_dft
690
691! **************************************************************************************************
692!> \brief ...
693!> \param qs_env ...
694!> \param p_env ...
695! **************************************************************************************************
696 SUBROUTINE apply_op_2_xtb(qs_env, p_env)
697 TYPE(qs_environment_type), POINTER :: qs_env
698 TYPE(qs_p_env_type) :: p_env
699
700 CHARACTER(len=*), PARAMETER :: routinen = 'apply_op_2_xtb'
701
702 INTEGER :: atom_a, handle, iatom, ikind, is, ispin, &
703 na, natom, natorb, nkind, ns, nsgf, &
704 nspins
705 INTEGER, DIMENSION(25) :: lao
706 INTEGER, DIMENSION(5) :: occ
707 LOGICAL :: lr_triplet
708 REAL(dp), ALLOCATABLE, DIMENSION(:) :: mcharge, mcharge1
709 REAL(dp), ALLOCATABLE, DIMENSION(:, :) :: aocg, aocg1, charges, charges1
710 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
711 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: pmat, rho_ao
712 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_p, matrix_p1, matrix_s
713 TYPE(dft_control_type), POINTER :: dft_control
714 TYPE(linres_control_type), POINTER :: linres_control
715 TYPE(mp_para_env_type), POINTER :: para_env
716 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
717 TYPE(pw_env_type), POINTER :: pw_env
718 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
719 TYPE(qs_kpp1_env_type), POINTER :: kpp1_env
720 TYPE(qs_rho_type), POINTER :: rho, rho1
721 TYPE(xtb_atom_type), POINTER :: xtb_kind
722
723 CALL timeset(routinen, handle)
724
725 cpassert(ASSOCIATED(p_env%kpp1_env))
726 cpassert(ASSOCIATED(p_env%kpp1))
727 kpp1_env => p_env%kpp1_env
728
729 rho1 => p_env%rho1
730 cpassert(ASSOCIATED(rho1))
731
732 CALL get_qs_env(qs_env=qs_env, &
733 pw_env=pw_env, &
734 para_env=para_env, &
735 rho=rho, &
736 linres_control=linres_control, &
737 dft_control=dft_control)
738
739 CALL qs_rho_get(rho, rho_ao=rho_ao)
740
741 lr_triplet = linres_control%lr_triplet
742 cpassert(.NOT. lr_triplet)
743
744 nspins = SIZE(p_env%kpp1)
745
746 DO ispin = 1, nspins
747 CALL dbcsr_set(p_env%kpp1(ispin)%matrix, 0.0_dp)
748 END DO
749
750 IF (dft_control%qs_control%xtb_control%coulomb_interaction) THEN
751 ! Mulliken charges
752 CALL get_qs_env(qs_env, particle_set=particle_set, matrix_s_kp=matrix_s)
753 natom = SIZE(particle_set)
754 CALL qs_rho_get(rho, rho_ao_kp=matrix_p)
755 CALL qs_rho_get(rho1, rho_ao_kp=matrix_p1)
756 ALLOCATE (mcharge(natom), charges(natom, 5))
757 ALLOCATE (mcharge1(natom), charges1(natom, 5))
758 charges = 0.0_dp
759 charges1 = 0.0_dp
760 CALL get_qs_env(qs_env, atomic_kind_set=atomic_kind_set, qs_kind_set=qs_kind_set)
761 nkind = SIZE(atomic_kind_set)
762 CALL get_qs_kind_set(qs_kind_set, maxsgf=nsgf)
763 ALLOCATE (aocg(nsgf, natom))
764 aocg = 0.0_dp
765 ALLOCATE (aocg1(nsgf, natom))
766 aocg1 = 0.0_dp
767 CALL ao_charges(matrix_p, matrix_s, aocg, para_env)
768 CALL ao_charges(matrix_p1, matrix_s, aocg1, para_env)
769 IF (nspins == 2) aocg1 = 0.5_dp*aocg1
770 DO ikind = 1, nkind
771 CALL get_atomic_kind(atomic_kind_set(ikind), natom=na)
772 CALL get_qs_kind(qs_kind_set(ikind), xtb_parameter=xtb_kind)
773 CALL get_xtb_atom_param(xtb_kind, natorb=natorb, lao=lao, occupation=occ)
774 DO iatom = 1, na
775 atom_a = atomic_kind_set(ikind)%atom_list(iatom)
776 charges(atom_a, :) = real(occ(:), kind=dp)
777 DO is = 1, natorb
778 ns = lao(is) + 1
779 charges(atom_a, ns) = charges(atom_a, ns) - aocg(is, atom_a)
780 charges1(atom_a, ns) = charges1(atom_a, ns) - aocg1(is, atom_a)
781 END DO
782 END DO
783 END DO
784 DEALLOCATE (aocg, aocg1)
785 DO iatom = 1, natom
786 mcharge(iatom) = sum(charges(iatom, :))
787 mcharge1(iatom) = sum(charges1(iatom, :))
788 END DO
789 ! Coulomb Kernel
790 pmat => matrix_p1(:, 1)
791 CALL xtb_coulomb_hessian(qs_env, p_env%kpp1, charges1, mcharge1, mcharge, pmat)
792 !
793 DEALLOCATE (charges, mcharge, charges1, mcharge1)
794 END IF
795
796 CALL timestop(handle)
797
798 END SUBROUTINE apply_op_2_xtb
799
800! **************************************************************************************************
801!> \brief Update action of TDDFPT operator on trial vectors by adding exact-exchange term.
802!> \param qs_env ...
803!> \param p_env ...
804!> \par History
805!> * 11.2019 adapted from tddfpt_apply_hfx
806! **************************************************************************************************
807 SUBROUTINE apply_hfx(qs_env, p_env)
808 TYPE(qs_environment_type), POINTER :: qs_env
809 TYPE(qs_p_env_type) :: p_env
810
811 CHARACTER(LEN=*), PARAMETER :: routinen = 'apply_hfx'
812
813 INTEGER :: handle, ispin, nspins
814 LOGICAL :: do_hfx
815 REAL(kind=dp) :: alpha
816 TYPE(cp_logger_type), POINTER :: logger
817 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: h1_mat, matrix_s, rho1_ao, work
818 TYPE(dft_control_type), POINTER :: dft_control
819 TYPE(section_vals_type), POINTER :: hfx_section, input
820
821 CALL timeset(routinen, handle)
822
823 logger => cp_get_default_logger()
824
825 CALL get_qs_env(qs_env=qs_env, &
826 input=input, &
827 matrix_s=matrix_s, &
828 dft_control=dft_control)
829 nspins = dft_control%nspins
830
831 hfx_section => section_vals_get_subs_vals(input, "DFT%XC%HF")
832 CALL section_vals_get(hfx_section, explicit=do_hfx)
833
834 IF (do_hfx) THEN
835
836 IF (dft_control%do_admm) THEN
837 IF (dft_control%admm_control%purification_method /= do_admm_purify_none) THEN
838 cpabort("ADMM: Linear Response needs purification_method=none")
839 END IF
840 IF (dft_control%admm_control%scaling_model /= do_admm_exch_scaling_none) THEN
841 cpabort("ADMM: Linear Response needs scaling_model=none")
842 END IF
843 IF (dft_control%admm_control%method /= do_admm_basis_projection) THEN
844 cpabort("ADMM: Linear Response needs admm_method=basis_projection")
845 END IF
846 !
847 rho1_ao => p_env%p1_admm
848 h1_mat => p_env%kpp1_admm
849 ELSE
850 rho1_ao => p_env%p1
851 h1_mat => p_env%kpp1
852 END IF
853
854 NULLIFY (work)
855 CALL dbcsr_allocate_matrix_set(work, nspins)
856 DO ispin = 1, nspins
857 ALLOCATE (work(ispin)%matrix)
858 CALL dbcsr_create(work(ispin)%matrix, template=h1_mat(ispin)%matrix)
859 CALL dbcsr_copy(work(ispin)%matrix, h1_mat(ispin)%matrix)
860 CALL dbcsr_set(work(ispin)%matrix, 0.0_dp)
861 END DO
862
863 CALL hfx_matrix(work, rho1_ao, qs_env, hfx_section)
864
865 alpha = 2.0_dp
866 IF (nspins == 2) alpha = 1.0_dp
867
868 DO ispin = 1, nspins
869 CALL dbcsr_add(h1_mat(ispin)%matrix, work(ispin)%matrix, 1.0_dp, alpha)
870 END DO
871
873
874 END IF
875
876 CALL timestop(handle)
877
878 END SUBROUTINE apply_hfx
879
880! **************************************************************************************************
881!> \brief Add the hfx contributions to the Hamiltonian
882!>
883!> \param matrix_ks ...
884!> \param rho_ao ...
885!> \param qs_env ...
886!> \param hfx_sections ...
887!> \param external_x_data ...
888!> \param ex ...
889!> \note
890!> Simplified version of subroutine hfx_ks_matrix()
891! **************************************************************************************************
892 SUBROUTINE hfx_matrix(matrix_ks, rho_ao, qs_env, hfx_sections, external_x_data, ex)
893 TYPE(dbcsr_p_type), DIMENSION(:), TARGET :: matrix_ks, rho_ao
894 TYPE(qs_environment_type), POINTER :: qs_env
895 TYPE(section_vals_type), POINTER :: hfx_sections
896 TYPE(hfx_type), DIMENSION(:, :), OPTIONAL, TARGET :: external_x_data
897 REAL(kind=dp), OPTIONAL :: ex
898
899 CHARACTER(LEN=*), PARAMETER :: routinen = 'hfx_matrix'
900
901 INTEGER :: handle, irep, ispin, mspin, n_rep_hf, &
902 nspins
903 LOGICAL :: distribute_fock_matrix, &
904 hfx_treat_lsd_in_core, &
905 s_mstruct_changed
906 REAL(kind=dp) :: eh1, ehfx
907 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_ks_kp, rho_ao_kp
908 TYPE(dft_control_type), POINTER :: dft_control
909 TYPE(hfx_type), DIMENSION(:, :), POINTER :: x_data
910 TYPE(mp_para_env_type), POINTER :: para_env
911
912 CALL timeset(routinen, handle)
913
914 NULLIFY (dft_control, para_env, matrix_ks_kp, rho_ao_kp, x_data)
915
916 CALL get_qs_env(qs_env=qs_env, &
917 dft_control=dft_control, &
918 para_env=para_env, &
919 s_mstruct_changed=s_mstruct_changed, &
920 x_data=x_data)
921
922 IF (PRESENT(external_x_data)) x_data => external_x_data
923
924 cpassert(dft_control%nimages == 1)
925 nspins = dft_control%nspins
926
927 CALL section_vals_get(hfx_sections, n_repetition=n_rep_hf)
928 CALL section_vals_val_get(hfx_sections, "TREAT_LSD_IN_CORE", l_val=hfx_treat_lsd_in_core, &
929 i_rep_section=1)
930
931 CALL section_vals_get(hfx_sections, n_repetition=n_rep_hf)
932 distribute_fock_matrix = .true.
933
934 mspin = 1
935 IF (hfx_treat_lsd_in_core) mspin = nspins
936
937 matrix_ks_kp(1:nspins, 1:1) => matrix_ks(1:nspins)
938 rho_ao_kp(1:nspins, 1:1) => rho_ao(1:nspins)
939
940 DO irep = 1, n_rep_hf
941 ehfx = 0.0_dp
942
943 IF (x_data(irep, 1)%do_hfx_ri) THEN
944 CALL hfx_ri_update_ks(qs_env, x_data(irep, 1)%ri_data, matrix_ks_kp, ehfx, &
945 rho_ao=rho_ao_kp, geometry_did_change=s_mstruct_changed, &
946 nspins=nspins, hf_fraction=x_data(irep, 1)%general_parameter%fraction)
947
948 ELSE
949
950 DO ispin = 1, mspin
951 CALL integrate_four_center(qs_env, x_data, matrix_ks_kp, eh1, rho_ao_kp, hfx_sections, para_env, &
952 s_mstruct_changed, irep, distribute_fock_matrix, ispin=ispin)
953 ehfx = ehfx + eh1
954 END DO
955
956 END IF
957 END DO
958
959 ! Export energy
960 IF (PRESENT(ex)) ex = ehfx
961
962 CALL timestop(handle)
963
964 END SUBROUTINE hfx_matrix
965
966! **************************************************************************************************
967!> \brief ...
968!> \param qs_env ...
969!> \param p_env ...
970! **************************************************************************************************
971 SUBROUTINE apply_xc_admm(qs_env, p_env)
972 TYPE(qs_environment_type), POINTER :: qs_env
973 TYPE(qs_p_env_type) :: p_env
974
975 CHARACTER(len=*), PARAMETER :: routinen = 'apply_xc_admm'
976
977 CHARACTER(LEN=default_string_length) :: basis_type
978 INTEGER :: handle, ispin, ns, nspins
979 REAL(kind=dp) :: alpha
980 TYPE(admm_type), POINTER :: admm_env
981 TYPE(dbcsr_p_type) :: xcmat
982 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_s
983 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: ksmat, psmat
984 TYPE(dft_control_type), POINTER :: dft_control
985 TYPE(linres_control_type), POINTER :: linres_control
986 TYPE(mp_para_env_type), POINTER :: para_env
987 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
988 POINTER :: sab_aux_fit
989 TYPE(pw_env_type), POINTER :: pw_env
990 TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
991 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: v_xc, v_xc_tau
992 TYPE(qs_kind_type), DIMENSION(:), POINTER :: kind_set
993 TYPE(qs_kpp1_env_type), POINTER :: kpp1_env
994 TYPE(qs_rho_type), POINTER :: rho_aux
995 TYPE(rho_atom_type), DIMENSION(:), POINTER :: rho1_atom_set, rho_atom_set
996 TYPE(section_vals_type), POINTER :: xc_section
997 TYPE(task_list_type), POINTER :: task_list
998
999 CALL timeset(routinen, handle)
1000
1001 CALL get_qs_env(qs_env=qs_env, dft_control=dft_control)
1002
1003 IF (dft_control%do_admm) THEN
1004 CALL get_qs_env(qs_env, admm_env=admm_env)
1005 IF (admm_env%aux_exch_func == do_admm_aux_exch_func_none) THEN
1006 ! nothing to do
1007 ELSE
1008 CALL get_qs_env(qs_env=qs_env, linres_control=linres_control)
1009 cpassert(.NOT. dft_control%qs_control%lrigpw)
1010 cpassert(.NOT. linres_control%lr_triplet)
1011
1012 nspins = dft_control%nspins
1013
1014 ! AUX basis contribution
1015 CALL get_qs_env(qs_env=qs_env, pw_env=pw_env)
1016 cpassert(ASSOCIATED(pw_env))
1017 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
1018 ! calculate the xc potential
1019 CALL get_admm_env(admm_env, matrix_s_aux_fit=matrix_s)
1020 ALLOCATE (xcmat%matrix)
1021 CALL dbcsr_create(xcmat%matrix, template=matrix_s(1)%matrix)
1022
1023 NULLIFY (v_xc, v_xc_tau)
1024 CALL get_admm_env(admm_env, rho_aux_fit=rho_aux)
1025 xc_section => admm_env%xc_section_aux
1026 kpp1_env => p_env%kpp1_env
1027
1028 NULLIFY (rho_atom_set, rho1_atom_set)
1029 basis_type = "AUX_FIT"
1030 CALL get_qs_env(qs_env, para_env=para_env, qs_kind_set=kind_set)
1031 CALL get_admm_env(admm_env, task_list_aux_fit=task_list)
1032 IF (admm_env%do_gapw) THEN
1033 kind_set => admm_env%admm_gapw_env%admm_kind_set
1034 CALL prepare_gapw_den(qs_env, local_rho_set=p_env%local_rho_set_admm, &
1035 do_rho0=.false., kind_set_external=kind_set)
1036 rho_atom_set => admm_env%admm_gapw_env%local_rho_set%rho_atom_set
1037 rho1_atom_set => p_env%local_rho_set_admm%rho_atom_set
1038 basis_type = "AUX_FIT_SOFT"
1039 task_list => admm_env%admm_gapw_env%task_list
1040 END IF
1041
1042 CALL qs_fxc_apply(qs_env, kpp1_env%deriv_set_admm, kpp1_env%rho_set_admm, p_env%rho1_admm, &
1043 rho_atom_set, xc_section, admm_env%do_gapw, v_xc, v_xc_tau, rho1_atom_set, &
1044 kind_set_external=kind_set)
1045 IF (ASSOCIATED(v_xc_tau)) THEN
1046 cpabort("Meta-GGA ADMM functionals not yet supported!")
1047 END IF
1048
1049 alpha = 1.0_dp
1050 IF (nspins == 1) alpha = 2.0_dp
1051
1052 DO ispin = 1, nspins
1053 CALL pw_scale(v_xc(ispin), v_xc(ispin)%pw_grid%dvol)
1054 CALL dbcsr_copy(xcmat%matrix, matrix_s(1)%matrix)
1055 CALL dbcsr_set(xcmat%matrix, 0.0_dp)
1056 CALL integrate_v_rspace(v_rspace=v_xc(ispin), hmat=xcmat, qs_env=qs_env, &
1057 calculate_forces=.false., basis_type=basis_type, &
1058 task_list_external=task_list)
1059 CALL dbcsr_add(p_env%kpp1_admm(ispin)%matrix, xcmat%matrix, 1.0_dp, alpha)
1060 END DO
1061
1062 IF (admm_env%do_gapw) THEN
1063 CALL get_admm_env(admm_env, sab_aux_fit=sab_aux_fit)
1064 ns = SIZE(p_env%kpp1_admm)
1065 ksmat(1:ns, 1:1) => p_env%kpp1_admm(1:ns)
1066 psmat(1:ns, 1:1) => p_env%p1_admm(1:ns)
1067 CALL update_ks_atom(qs_env, ksmat, psmat, forces=.false., tddft=.true., &
1068 rho_atom_external=p_env%local_rho_set_admm%rho_atom_set, &
1069 kind_set_external=admm_env%admm_gapw_env%admm_kind_set, &
1070 oce_external=admm_env%admm_gapw_env%oce, &
1071 sab_external=sab_aux_fit)
1072 END IF
1073
1074 DO ispin = 1, nspins
1075 CALL auxbas_pw_pool%give_back_pw(v_xc(ispin))
1076 END DO
1077 DEALLOCATE (v_xc)
1078 CALL dbcsr_deallocate_matrix(xcmat%matrix)
1079
1080 END IF
1081 END IF
1082
1083 CALL timestop(handle)
1084
1085 END SUBROUTINE apply_xc_admm
1086
1087END MODULE qs_linres_kernel
Types and set/get functions for auxiliary density matrix methods.
Definition admm_types.F:15
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.
Definition admm_types.F:599
Define the atomic kind types and their sub types.
subroutine, public get_atomic_kind(atomic_kind, fist_potential, element_symbol, name, mass, kind_number, natom, atom_list, rcov, rvdw, z, qeff, apol, cpol, mm_radius, shell, shell_active, damping)
Get attributes of an atomic kind.
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
subroutine, public dbcsr_deallocate_matrix(matrix)
...
subroutine, public dbcsr_copy(matrix_b, matrix_a, name, keep_sparsity, keep_imaginary)
...
subroutine, public dbcsr_set(matrix, alpha)
...
subroutine, public dbcsr_add(matrix_a, matrix_b, alpha_scalar, beta_scalar)
...
DBCSR operations in CP2K.
subroutine, public cp_dbcsr_sm_fm_multiply(matrix, fm_in, fm_out, ncol, alpha, beta)
multiply a dbcsr with a fm matrix
represent a full matrix distributed on many processors
Definition cp_fm_types.F:15
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
various routines to log and control the output. The idea is that decisions about where to log should ...
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
subroutine, public vh_1c_gg_integrals(qs_env, energy_hartree_1c, ecoul_1c, local_rho_set, para_env, tddft, local_rho_set_2nd, core_2nd)
Calculates one center GAPW Hartree energies and matrix elements Hartree potentials are input Takes po...
Routines to calculate HFX energy and potential.
subroutine, public integrate_four_center(qs_env, x_data, ks_matrix, ehfx, rho_ao, hfx_section, para_env, geometry_did_change, irep, distribute_fock_matrix, ispin, nspins)
computes four center integrals for a full basis set and updates the Kohn-Sham-Matrix and energy....
RI-methods for HFX.
Definition hfx_ri.F:12
subroutine, public hfx_ri_update_ks(qs_env, ri_data, ks_matrix, ehfx, mos, rho_ao, geometry_did_change, nspins, hf_fraction)
...
Definition hfx_ri.F:1041
Types and set/get functions for HFX.
Definition hfx_types.F:16
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public do_admm_purify_none
integer, parameter, public kg_tnadd_embed
integer, parameter, public do_admm_basis_projection
integer, parameter, public do_admm_aux_exch_func_none
integer, parameter, public do_admm_exch_scaling_none
objects that represent the structure of input sections and the data contained in an input section
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
subroutine, public section_vals_get(section_vals, ref_count, n_repetition, n_subs_vals_rep, section, explicit)
returns various attributes about the section_vals
subroutine, public section_vals_val_get(section_vals, keyword_name, i_rep_section, i_rep_val, n_rep_val, val, l_val, i_val, r_val, c_val, l_vals, i_vals, r_vals, c_vals, explicit)
returns the requested value
Routines for a Kim-Gordon-like partitioning into molecular subunits.
subroutine, public kg_ekin_subset(qs_env, ks_matrix, ekin_mol, calc_force, do_kernel, pmat_ext)
Calculates the subsystem Hohenberg-Kohn kinetic energy and the forces.
Types needed for a Kim-Gordon-like partitioning into molecular subunits.
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
integer, parameter, public default_string_length
Definition kinds.F:57
contains the types and subroutines for dealing with the lri_env lri : local resolution of the identit...
routines that build the Kohn-Sham matrix for the LRIGPW and xc parts
subroutine, public calculate_lri_ks_matrix(lri_env, lri_v_int, h_matrix, atomic_kind_set, cell_to_index)
update of LRIGPW KS matrix
Interface to the message passing library MPI.
compute mulliken charges we (currently) define them as c_i = 1/2 [ (PS)_{ii} + (SP)_{ii}...
Definition mulliken.F:13
Define the data structure for the particle information.
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
functions related to the poisson solver on regular grids
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
Calculation of non local dispersion functionals Some routines adapted from: Copyright (C) 2001-2009 Q...
subroutine, public qs_fxc_nlvdw_apply(qs_env, xc_section, dispersion_env, rho0_r, rho1_r, fxc_rho)
Second derivative of nl-vdW potential.
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.
Definition qs_fxc.F:15
subroutine, public qs_fxc_apply(qs_env, xc_deriv_set, xc_rho_set, rho1_struct, rho0_atom_set, xc_section, do_onecenter, fxc_rho, fxc_tau, rho1_atom_set, do_scale, is_triplet, spinflip, pw_env_ext, kind_set_external, para_env_external, compute_virial, virial_xc)
...
Definition qs_fxc.F:713
subroutine, public qs_fxc_prep(qs_env, rho0_struct, xc_rho_set, xc_deriv_set, xc_section, pw_env_ext, is_triplet)
...
Definition qs_fxc.F:538
subroutine, public prepare_gapw_den(qs_env, local_rho_set, do_rho0, kind_set_external, pw_env_sub)
...
Integrate single or product functions over a potential on a RS grid.
Define the quickstep kind type and their sub types.
subroutine, public get_qs_kind(qs_kind, basis_set, basis_type, ncgf, nsgf, all_potential, tnadd_potential, gth_potential, sgp_potential, upf_potential, cneo_potential, se_parameter, dftb_parameter, xtb_parameter, dftb3_param, zatom, zeff, elec_conf, mao, lmax_dftb, alpha_core_charge, ccore_charge, core_charge, core_charge_radius, paw_proj_set, paw_atom, hard_radius, hard0_radius, max_rad_local, covalent_radius, vdw_radius, gpw_type_forced, harmonics, max_iso_not0, max_s_harm, grid_atom, ngrid_ang, ngrid_rad, lmax_rho0, dft_plus_u_atom, l_of_dft_plus_u, n_of_dft_plus_u, u_minus_j, hund_j, u_of_dft_plus_u, j_of_dft_plus_u, alpha_of_dft_plus_u, beta_of_dft_plus_u, j0_of_dft_plus_u, occupation_of_dft_plus_u, dispersion, bs_occupation, magnetization, no_optimize, addel, laddel, naddel, orbitals, max_scf, eps_scf, smear, u_ramping, u_minus_j_target, eps_u_ramping, proj_shell_charge, lr_atom, do_mtlr, u_j_loop, ao_coef, init_u_ramping_each_scf, reltmat, ghost, monovalent, floating, name, element_symbol, pao_basis_size, pao_model_file, pao_potentials, pao_descriptors, nelec)
Get attributes of an atomic kind.
subroutine, public get_qs_kind_set(qs_kind_set, all_potential_present, tnadd_potential_present, gth_potential_present, sgp_potential_present, paw_atom_present, dft_plus_u_atom_present, maxcgf, maxsgf, maxco, maxco_proj, maxgtops, maxlgto, maxlprj, maxnset, maxsgf_set, ncgf, npgf, nset, nsgf, nshell, maxpol, maxlppl, maxlppnl, maxppnl, nelectron, maxder, max_ngrid_rad, max_sph_harm, maxg_iso_not0, lmax_rho0, basis_rcut, do_mtlr_present, basis_type, total_zeff_corr, npgf_seg, cneo_potential_present, nkind_q, natom_q)
Get attributes of an atomic kind set.
module that builds the second order perturbation kernel kpp1 = delta_rho|_P delta_rho|_P E drho(P1) d...
subroutine, public kpp1_check_i_alloc(kpp1_env, qs_env, xc_section)
checks that the intenal storage is allocated, and allocs it if needed
basis types for the calculation of the perturbation of density theory.
routines that build the Kohn-Sham matrix contributions coming from local atomic densities
Definition qs_ks_atom.F:12
subroutine, public update_ks_atom(qs_env, ksmat, pmat, forces, tddft, rho_atom_external, kind_set_external, oce_external, sab_external, kscale, kintegral, kforce, fscale)
The correction to the KS matrix due to the GAPW local terms to the hartree and XC contributions is he...
Definition qs_ks_atom.F:110
linres kernel functions
subroutine, public apply_op_2(qs_env, p_env, c0, av)
...
subroutine, public apply_xc_admm(qs_env, p_env)
...
subroutine, public hfx_matrix(matrix_ks, rho_ao, qs_env, hfx_sections, external_x_data, ex)
Add the hfx contributions to the Hamiltonian.
subroutine, public apply_hfx(qs_env, p_env)
Update action of TDDFPT operator on trial vectors by adding exact-exchange term.
subroutine, public apply_hxc_kernel_kp(qs_env, kpp1_env, rho1_ao_kp, v1_ao_kp)
Apply the periodic GPW Hartree-XC kernel to a K-point AO density response.
Type definitiona for linear response calculations.
Define the neighbor list data types and the corresponding functionality.
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.
subroutine, public integrate_vhg0_rspace(qs_env, v_rspace, para_env, calculate_forces, local_rho_set, local_rho_set_2nd, atener, kforce, my_pools, my_rs_descs)
...
methods of the rho structure (defined in qs_rho_types)
subroutine, public qs_rho_update_rho(rho_struct, qs_env, rho_xc_external, local_rho_set, task_list_external, task_list_external_soft, pw_env_external, para_env_external)
updates rho_r and rho_g to the rhorho_ao. if use_kinetic_energy_density also computes tau_r and tau_g...
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_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 qs_rho_release(rho_struct)
releases a rho_struct by decreasing the reference count by one and deallocating if it reaches 0 (to b...
types for task lists
Calculation of Coulomb Hessian contributions in xTB.
Definition xtb_ehess.F:12
subroutine, public xtb_coulomb_hessian(qs_env, ks_matrix, charges1, mcharge1, mcharge, matrix_p1)
...
Definition xtb_ehess.F:79
Definition of the xTB parameter types.
Definition xtb_types.F:20
subroutine, public get_xtb_atom_param(xtb_parameter, symbol, aname, typ, defined, z, zeff, natorb, lmax, nao, lao, rcut, rcov, kx, eta, xgamma, alpha, zneff, nshell, nval, lval, kpoly, kappa, wall, hen, zeta, xi, kappa0, alpg, occupation, ngauss, electronegativity, chmax, en, kqat2, kcn, kq)
...
Definition xtb_types.F:206
stores some data used in wavefunction fitting
Definition admm_types.F:120
Provides all information about an atomic kind.
represent a full matrix
type of a logger, at the moment it contains just a print level starting at which level it should be l...
stores some data used in construction of Kohn-Sham matrix
Definition hfx_types.F:514
Contains all the info needed for KG runs...
stores all the informations relevant to an mpi environment
contained for different pw related things
environment for the poisson solver
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
Provides all information about a quickstep kind.
environment that keeps the informations and temporary val to build the kpp1 kernel matrix
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.