(git:d1312bc)
Loading...
Searching...
No Matches
qs_kpp1_env_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
8! **************************************************************************************************
9!> \brief module that builds the second order perturbation kernel
10!> kpp1 = delta_rho|_P delta_rho|_P E drho(P1) drho
11!> \par History
12!> 07.2002 created [fawzi]
13!> \author Fawzi Mohamed
14! **************************************************************************************************
16 USE admm_types, ONLY: admm_type,&
20 USE cp_dbcsr_api, ONLY: dbcsr_add,&
38 USE kahan_sum, ONLY: accurate_sum
39 USE kinds, ONLY: dp
45 USE pw_env_types, ONLY: pw_env_get,&
47 USE pw_methods, ONLY: pw_axpy,&
48 pw_copy,&
50 pw_scale,&
55 USE pw_types, ONLY: pw_c1d_gs_type,&
60 USE qs_integrate_potential, ONLY: integrate_v_rspace,&
61 integrate_v_rspace_diagonal,&
62 integrate_v_rspace_one_center
64 USE qs_ks_atom, ONLY: update_ks_atom
68 USE qs_rho_types, ONLY: qs_rho_get,&
71 USE xc, ONLY: xc_calc_2nd_deriv,&
75#include "./base/base_uses.f90"
76
77 IMPLICIT NONE
78
79 PRIVATE
80
81 LOGICAL, PRIVATE, PARAMETER :: debug_this_module = .true.
82 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_kpp1_env_methods'
83
84 PUBLIC :: kpp1_create, &
87
88CONTAINS
89
90! **************************************************************************************************
91!> \brief allocates and initializes a kpp1_env
92!> \param kpp1_env the environment to initialize
93!> \par History
94!> 07.2002 created [fawzi]
95!> \author Fawzi Mohamed
96! **************************************************************************************************
97 SUBROUTINE kpp1_create(kpp1_env)
98 TYPE(qs_kpp1_env_type) :: kpp1_env
99
100 NULLIFY (kpp1_env%v_ao, kpp1_env%rho_set, kpp1_env%deriv_set, &
101 kpp1_env%rho_set_admm, kpp1_env%deriv_set_admm)
102 END SUBROUTINE kpp1_create
103
104! **************************************************************************************************
105!> \brief ...
106!> \param rho1_xc ...
107!> \param rho1 ...
108!> \param xc_section ...
109!> \param lrigpw ...
110!> \param do_triplet ...
111!> \param qs_env ...
112!> \param p_env ...
113!> \param calc_forces ...
114!> \param calc_virial ...
115!> \param virial ...
116! **************************************************************************************************
117 SUBROUTINE calc_kpp1(rho1_xc, rho1, xc_section, lrigpw, do_triplet, qs_env, p_env, &
118 calc_forces, calc_virial, virial)
119
120 TYPE(qs_rho_type), POINTER :: rho1_xc, rho1
121 TYPE(section_vals_type), POINTER :: xc_section
122 LOGICAL, INTENT(IN) :: lrigpw, do_triplet
123 TYPE(qs_environment_type), POINTER :: qs_env
124 TYPE(qs_p_env_type) :: p_env
125 LOGICAL, INTENT(IN), OPTIONAL :: calc_forces, calc_virial
126 REAL(kind=dp), DIMENSION(3, 3), INTENT(INOUT), &
127 OPTIONAL :: virial
128
129 CHARACTER(len=*), PARAMETER :: routinen = 'calc_kpp1'
130
131 INTEGER :: handle, ikind, ispin, nkind, ns, nspins, &
132 output_unit
133 LOGICAL :: gapw, gapw_xc, lsd, my_calc_forces
134 REAL(kind=dp) :: alpha, energy_hartree, energy_hartree_1c
135 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
136 TYPE(cp_logger_type), POINTER :: logger
137 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: k1mat, rho_ao
138 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: ksmat, psmat
139 TYPE(lri_density_type), POINTER :: lri_density
140 TYPE(lri_environment_type), POINTER :: lri_env
141 TYPE(lri_kind_type), DIMENSION(:), POINTER :: lri_v_int
142 TYPE(mp_para_env_type), POINTER :: para_env
143 TYPE(pw_c1d_gs_type) :: rho1_tot_gspace
144 TYPE(pw_c1d_gs_type), DIMENSION(:), POINTER :: rho1_g, rho1_g_pw
145 TYPE(pw_env_type), POINTER :: pw_env
146 TYPE(pw_poisson_type), POINTER :: poisson_env
147 TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
148 TYPE(pw_r3d_rs_type) :: v_hartree_rspace
149 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: rho1_r, rho1_r_pw, tau1_r, tau1_r_pw, &
150 v_rspace_new, v_xc, v_xc_tau
151 TYPE(pw_r3d_rs_type), POINTER :: weights
152 TYPE(qs_rho_type), POINTER :: rho
153 TYPE(rho_atom_type), DIMENSION(:), POINTER :: rho1_atom_set, rho_atom_set
154 TYPE(section_vals_type), POINTER :: input, scf_section
155
156 CALL timeset(routinen, handle)
157
158 NULLIFY (v_xc, rho1_g, pw_env, rho1_g_pw, tau1_r_pw)
159 logger => cp_get_default_logger()
160
161 cpassert(ASSOCIATED(p_env%kpp1))
162 cpassert(ASSOCIATED(p_env%kpp1_env))
163 cpassert(ASSOCIATED(rho1))
164
165 nspins = SIZE(p_env%kpp1)
166 lsd = (nspins == 2)
167
168 my_calc_forces = .false.
169 IF (PRESENT(calc_forces)) my_calc_forces = calc_forces
170
171 CALL get_qs_env(qs_env, &
172 pw_env=pw_env, &
173 input=input, &
174 para_env=para_env, &
175 rho=rho)
176
177 cpassert(ASSOCIATED(rho1))
178
179 IF (lrigpw) THEN
180 CALL get_qs_env(qs_env, &
181 lri_env=lri_env, &
182 lri_density=lri_density, &
183 atomic_kind_set=atomic_kind_set)
184 END IF
185
186 gapw = (section_get_ival(input, "DFT%QS%METHOD") == do_method_gapw)
187 gapw_xc = (section_get_ival(input, "DFT%QS%METHOD") == do_method_gapw_xc)
188 IF (gapw_xc) THEN
189 cpassert(ASSOCIATED(rho1_xc))
190 END IF
191
192 CALL kpp1_check_i_alloc(p_env%kpp1_env, qs_env, do_triplet)
193
194 CALL qs_rho_get(rho, rho_ao=rho_ao)
195 CALL qs_rho_get(rho1, rho_g=rho1_g)
196
197 ! gets the tmp grids
198 cpassert(ASSOCIATED(pw_env))
199 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool, &
200 poisson_env=poisson_env)
201 CALL auxbas_pw_pool%create_pw(v_hartree_rspace)
202
203 IF (gapw .OR. gapw_xc) THEN
204 CALL prepare_gapw_den(qs_env, p_env%local_rho_set, do_rho0=(.NOT. gapw_xc))
205 END IF
206
207 ! *** calculate the hartree potential on the total density ***
208 CALL auxbas_pw_pool%create_pw(rho1_tot_gspace)
209
210 CALL pw_copy(rho1_g(1), rho1_tot_gspace)
211 DO ispin = 2, nspins
212 CALL pw_axpy(rho1_g(ispin), rho1_tot_gspace)
213 END DO
214 IF (gapw) THEN
215 CALL pw_axpy(p_env%local_rho_set%rho0_mpole%rho0_s_gs, rho1_tot_gspace)
216 IF (ASSOCIATED(p_env%local_rho_set%rho0_mpole%rhoz_cneo_s_gs)) THEN
217 CALL pw_axpy(p_env%local_rho_set%rho0_mpole%rhoz_cneo_s_gs, rho1_tot_gspace)
218 END IF
219 END IF
220
221 scf_section => section_vals_get_subs_vals(input, "DFT%SCF")
222 IF (cp_print_key_should_output(logger%iter_info, scf_section, "PRINT%TOTAL_DENSITIES") &
223 /= 0) THEN
224 output_unit = cp_print_key_unit_nr(logger, scf_section, "PRINT%TOTAL_DENSITIES", &
225 extension=".scfLog")
226 CALL print_densities(rho1, rho1_tot_gspace, output_unit)
227 CALL cp_print_key_finished_output(output_unit, logger, scf_section, &
228 "PRINT%TOTAL_DENSITIES")
229 END IF
230
231 IF (.NOT. (nspins == 1 .AND. do_triplet)) THEN
232 block
233 TYPE(pw_c1d_gs_type) :: v_hartree_gspace
234 CALL auxbas_pw_pool%create_pw(v_hartree_gspace)
235 CALL pw_poisson_solve(poisson_env, rho1_tot_gspace, &
236 energy_hartree, &
237 v_hartree_gspace)
238 CALL pw_transfer(v_hartree_gspace, v_hartree_rspace)
239 CALL auxbas_pw_pool%give_back_pw(v_hartree_gspace)
240 END block
241 CALL pw_scale(v_hartree_rspace, v_hartree_rspace%pw_grid%dvol)
242 END IF
243
244 CALL auxbas_pw_pool%give_back_pw(rho1_tot_gspace)
245
246 ! *** calculate the xc potential ***
247 IF (gapw_xc) THEN
248 CALL qs_rho_get(rho1_xc, rho_r=rho1_r, tau_r=tau1_r)
249 ELSE
250 CALL qs_rho_get(rho1, rho_r=rho1_r, tau_r=tau1_r)
251 END IF
252
253 IF (nspins == 1 .AND. do_triplet) THEN
254
255 lsd = .true.
256 ALLOCATE (rho1_r_pw(2))
257 DO ispin = 1, 2
258 CALL rho1_r_pw(ispin)%create(rho1_r(1)%pw_grid)
259 CALL pw_transfer(rho1_r(1), rho1_r_pw(ispin))
260 END DO
261
262 IF (ASSOCIATED(tau1_r)) THEN
263 ALLOCATE (tau1_r_pw(2))
264 DO ispin = 1, 2
265 CALL tau1_r_pw(ispin)%create(tau1_r(1)%pw_grid)
266 CALL pw_transfer(tau1_r(1), tau1_r_pw(ispin))
267 END DO
268 END IF
269
270 ELSE
271
272 rho1_r_pw => rho1_r
273
274 tau1_r_pw => tau1_r
275
276 END IF
277
278 NULLIFY (weights)
279 CALL get_qs_env(qs_env, xcint_weights=weights)
280
281 CALL xc_calc_2nd_deriv(v_xc, v_xc_tau, p_env%kpp1_env%deriv_set, p_env%kpp1_env%rho_set, &
282 rho1_r_pw, rho1_g_pw, tau1_r_pw, auxbas_pw_pool, weights, &
283 xc_section, .false., do_excitations=.true., do_triplet=do_triplet, &
284 compute_virial=calc_virial, virial_xc=virial)
285
286 DO ispin = 1, nspins
287 CALL pw_scale(v_xc(ispin), v_xc(ispin)%pw_grid%dvol)
288 END DO
289 v_rspace_new => v_xc
290 IF (SIZE(v_xc) /= nspins) THEN
291 CALL auxbas_pw_pool%give_back_pw(v_xc(2))
292 END IF
293 NULLIFY (v_xc)
294 IF (ASSOCIATED(v_xc_tau)) THEN
295 DO ispin = 1, nspins
296 CALL pw_scale(v_xc_tau(ispin), v_xc_tau(ispin)%pw_grid%dvol)
297 END DO
298 IF (SIZE(v_xc_tau) /= nspins) THEN
299 CALL auxbas_pw_pool%give_back_pw(v_xc_tau(2))
300 END IF
301 END IF
302
303 IF (gapw .OR. gapw_xc) THEN
304 CALL get_qs_env(qs_env, rho_atom_set=rho_atom_set)
305 rho1_atom_set => p_env%local_rho_set%rho_atom_set
306 CALL calculate_xc_2nd_deriv_atom(rho_atom_set, rho1_atom_set, qs_env, xc_section, para_env, &
307 do_triplet=do_triplet)
308 END IF
309
310 IF (nspins == 1 .AND. do_triplet) THEN
311 DO ispin = 1, SIZE(rho1_r_pw)
312 CALL rho1_r_pw(ispin)%release()
313 END DO
314 DEALLOCATE (rho1_r_pw)
315 IF (ASSOCIATED(tau1_r_pw)) THEN
316 DO ispin = 1, SIZE(tau1_r_pw)
317 CALL tau1_r_pw(ispin)%release()
318 END DO
319 DEALLOCATE (tau1_r_pw)
320 END IF
321 END IF
322
323 alpha = 1.0_dp
324 IF (nspins == 1) alpha = 2.0_dp
325
326 !-------------------------------!
327 ! Add both hartree and xc terms !
328 !-------------------------------!
329 DO ispin = 1, nspins
330 CALL dbcsr_set(p_env%kpp1_env%v_ao(ispin)%matrix, 0.0_dp)
331
332 ! XC and Hartree are integrated separatedly
333 ! XC uses the soft basis set only
334 IF (gapw_xc) THEN
335
336 IF (nspins == 1) THEN
337 CALL integrate_v_rspace(v_rspace=v_rspace_new(ispin), &
338 pmat=rho_ao(ispin), &
339 hmat=p_env%kpp1_env%v_ao(ispin), &
340 qs_env=qs_env, &
341 calculate_forces=my_calc_forces, gapw=gapw_xc)
342
343 IF (ASSOCIATED(v_xc_tau)) THEN
344 CALL integrate_v_rspace(v_rspace=v_xc_tau(ispin), &
345 pmat=rho_ao(ispin), &
346 hmat=p_env%kpp1_env%v_ao(ispin), &
347 qs_env=qs_env, &
348 compute_tau=.true., &
349 calculate_forces=my_calc_forces, gapw=gapw_xc)
350 END IF
351
352 ! add hartree only for SINGLETS
353 IF (.NOT. do_triplet) THEN
354 CALL pw_copy(v_hartree_rspace, v_rspace_new(1))
355
356 CALL integrate_v_rspace(v_rspace=v_rspace_new(ispin), &
357 pmat=rho_ao(ispin), &
358 hmat=p_env%kpp1_env%v_ao(ispin), &
359 qs_env=qs_env, &
360 calculate_forces=my_calc_forces, gapw=gapw)
361 END IF
362 ELSE
363 CALL integrate_v_rspace(v_rspace=v_rspace_new(ispin), &
364 pmat=rho_ao(ispin), &
365 hmat=p_env%kpp1_env%v_ao(ispin), &
366 qs_env=qs_env, &
367 calculate_forces=my_calc_forces, gapw=gapw_xc)
368
369 IF (ASSOCIATED(v_xc_tau)) THEN
370 CALL integrate_v_rspace(v_rspace=v_xc_tau(ispin), &
371 pmat=rho_ao(ispin), &
372 hmat=p_env%kpp1_env%v_ao(ispin), &
373 qs_env=qs_env, &
374 compute_tau=.true., &
375 calculate_forces=my_calc_forces, gapw=gapw_xc)
376 END IF
377
378 CALL pw_copy(v_hartree_rspace, v_rspace_new(ispin))
379 CALL integrate_v_rspace(v_rspace=v_rspace_new(ispin), &
380 pmat=rho_ao(ispin), &
381 hmat=p_env%kpp1_env%v_ao(ispin), &
382 qs_env=qs_env, &
383 calculate_forces=my_calc_forces, gapw=gapw)
384 END IF
385
386 ELSE
387
388 IF (nspins == 1) THEN
389
390 ! add hartree only for SINGLETS
391 IF (.NOT. do_triplet) THEN
392 CALL pw_axpy(v_hartree_rspace, v_rspace_new(1))
393 END IF
394 ELSE
395 CALL pw_axpy(v_hartree_rspace, v_rspace_new(ispin))
396 END IF
397
398 IF (lrigpw) THEN
399 IF (ASSOCIATED(v_xc_tau)) cpabort("Meta-GGA functionals not supported with LRI!")
400
401 lri_v_int => lri_density%lri_coefs(ispin)%lri_kinds
402 CALL get_qs_env(qs_env, nkind=nkind)
403 DO ikind = 1, nkind
404 lri_v_int(ikind)%v_int = 0.0_dp
405 END DO
406 CALL integrate_v_rspace_one_center(v_rspace_new(ispin), qs_env, &
407 lri_v_int, .false., "LRI_AUX")
408 DO ikind = 1, nkind
409 CALL para_env%sum(lri_v_int(ikind)%v_int)
410 END DO
411 ALLOCATE (k1mat(1))
412 k1mat(1)%matrix => p_env%kpp1_env%v_ao(ispin)%matrix
413 IF (lri_env%exact_1c_terms) THEN
414 CALL integrate_v_rspace_diagonal(v_rspace_new(ispin), k1mat(1)%matrix, &
415 rho_ao(ispin)%matrix, qs_env, my_calc_forces, "ORB")
416 END IF
417 CALL calculate_lri_ks_matrix(lri_env, lri_v_int, k1mat, atomic_kind_set)
418 DEALLOCATE (k1mat)
419 ELSE
420 CALL integrate_v_rspace(v_rspace=v_rspace_new(ispin), &
421 pmat=rho_ao(ispin), &
422 hmat=p_env%kpp1_env%v_ao(ispin), &
423 qs_env=qs_env, &
424 calculate_forces=my_calc_forces, gapw=gapw)
425
426 IF (ASSOCIATED(v_xc_tau)) THEN
427 CALL integrate_v_rspace(v_rspace=v_xc_tau(ispin), &
428 pmat=rho_ao(ispin), &
429 hmat=p_env%kpp1_env%v_ao(ispin), &
430 qs_env=qs_env, &
431 compute_tau=.true., &
432 calculate_forces=my_calc_forces, gapw=gapw)
433 END IF
434 END IF
435 END IF
436
437 CALL dbcsr_add(p_env%kpp1(ispin)%matrix, p_env%kpp1_env%v_ao(ispin)%matrix, 1.0_dp, alpha)
438 END DO
439
440 IF (gapw) THEN
441 IF (.NOT. (nspins == 1 .AND. do_triplet)) THEN
442 CALL vh_1c_gg_integrals(qs_env, energy_hartree_1c, &
443 p_env%hartree_local%ecoul_1c, &
444 p_env%local_rho_set, &
445 para_env, tddft=.true., core_2nd=.true.)
446 CALL integrate_vhg0_rspace(qs_env, v_hartree_rspace, para_env, &
447 calculate_forces=my_calc_forces, &
448 local_rho_set=p_env%local_rho_set)
449 END IF
450 ! *** Add single atom contributions to the KS matrix ***
451 ! remap pointer
452 ns = SIZE(p_env%kpp1)
453 ksmat(1:ns, 1:1) => p_env%kpp1(1:ns)
454 ns = SIZE(rho_ao)
455 psmat(1:ns, 1:1) => rho_ao(1:ns)
456 CALL update_ks_atom(qs_env, ksmat, psmat, forces=my_calc_forces, tddft=.true., &
457 rho_atom_external=p_env%local_rho_set%rho_atom_set)
458 ELSE IF (gapw_xc) THEN
459 ns = SIZE(p_env%kpp1)
460 ksmat(1:ns, 1:1) => p_env%kpp1(1:ns)
461 ns = SIZE(rho_ao)
462 psmat(1:ns, 1:1) => rho_ao(1:ns)
463 CALL update_ks_atom(qs_env, ksmat, psmat, forces=my_calc_forces, tddft=.true., &
464 rho_atom_external=p_env%local_rho_set%rho_atom_set)
465 END IF
466
467 CALL auxbas_pw_pool%give_back_pw(v_hartree_rspace)
468 DO ispin = 1, SIZE(v_rspace_new)
469 CALL auxbas_pw_pool%give_back_pw(v_rspace_new(ispin))
470 END DO
471 DEALLOCATE (v_rspace_new)
472 IF (ASSOCIATED(v_xc_tau)) THEN
473 DO ispin = 1, SIZE(v_xc_tau)
474 CALL auxbas_pw_pool%give_back_pw(v_xc_tau(ispin))
475 END DO
476 DEALLOCATE (v_xc_tau)
477 END IF
478
479 CALL timestop(handle)
480 END SUBROUTINE calc_kpp1
481
482! **************************************************************************************************
483!> \brief checks that the intenal storage is allocated, and allocs it if needed
484!> \param kpp1_env the environment to check
485!> \param qs_env the qs environment this kpp1_env lives in
486!> \param do_triplet ...
487!> \author Fawzi Mohamed
488!> \note
489!> private routine
490! **************************************************************************************************
491 SUBROUTINE kpp1_check_i_alloc(kpp1_env, qs_env, do_triplet)
492
493 TYPE(qs_kpp1_env_type) :: kpp1_env
494 TYPE(qs_environment_type), INTENT(IN), POINTER :: qs_env
495 LOGICAL, INTENT(IN) :: do_triplet
496
497 INTEGER :: ispin, nspins
498 TYPE(admm_type), POINTER :: admm_env
499 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_s
500 TYPE(dft_control_type), POINTER :: dft_control
501 TYPE(pw_env_type), POINTER :: pw_env
502 TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
503 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: my_rho_r, my_tau_r, rho_r, tau_r
504 TYPE(pw_r3d_rs_type), POINTER :: weights
505 TYPE(qs_rho_type), POINTER :: rho
506 TYPE(section_vals_type), POINTER :: admm_xc_section, input, xc_section
507
508! ------------------------------------------------------------------
509
510 NULLIFY (pw_env, auxbas_pw_pool, matrix_s, rho, rho_r, admm_env, dft_control, my_rho_r, my_tau_r)
511
512 CALL get_qs_env(qs_env, pw_env=pw_env, &
513 matrix_s=matrix_s, rho=rho, input=input, &
514 admm_env=admm_env, dft_control=dft_control)
515
516 NULLIFY (weights)
517 CALL get_qs_env(qs_env, xcint_weights=weights)
518
519 CALL qs_rho_get(rho, rho_r=rho_r, tau_r=tau_r)
520 nspins = SIZE(rho_r)
521
522 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
523
524 IF (.NOT. ASSOCIATED(kpp1_env%v_ao)) THEN
525 CALL dbcsr_allocate_matrix_set(kpp1_env%v_ao, nspins)
526 DO ispin = 1, nspins
527 ALLOCATE (kpp1_env%v_ao(ispin)%matrix)
528 CALL dbcsr_copy(kpp1_env%v_ao(ispin)%matrix, matrix_s(1)%matrix, &
529 name="kpp1%v_ao-"//adjustl(cp_to_string(ispin)))
530 END DO
531 END IF
532
533 IF (.NOT. ASSOCIATED(kpp1_env%deriv_set)) THEN
534
535 IF (nspins == 1 .AND. do_triplet) THEN
536 ALLOCATE (my_rho_r(2))
537 DO ispin = 1, 2
538 CALL auxbas_pw_pool%create_pw(my_rho_r(ispin))
539 CALL pw_axpy(rho_r(1), my_rho_r(ispin), 0.5_dp, 0.0_dp)
540 END DO
541 IF (dft_control%use_kinetic_energy_density) THEN
542 ALLOCATE (my_tau_r(2))
543 DO ispin = 1, 2
544 CALL auxbas_pw_pool%create_pw(my_tau_r(ispin))
545 CALL pw_axpy(tau_r(1), my_tau_r(ispin), 0.5_dp, 0.0_dp)
546 END DO
547 END IF
548 ELSE
549 my_rho_r => rho_r
550 IF (dft_control%use_kinetic_energy_density) THEN
551 my_tau_r => tau_r
552 END IF
553 END IF
554
555 IF (dft_control%do_admm) THEN
556 xc_section => admm_env%xc_section_primary
557 ELSE
558 xc_section => section_vals_get_subs_vals(input, "DFT%XC")
559 END IF
560
561 ALLOCATE (kpp1_env%deriv_set, kpp1_env%rho_set)
562 CALL xc_prep_2nd_deriv(kpp1_env%deriv_set, kpp1_env%rho_set, &
563 my_rho_r, auxbas_pw_pool, weights, &
564 xc_section=xc_section, tau_r=my_tau_r)
565
566 IF (nspins == 1 .AND. do_triplet) THEN
567 DO ispin = 1, SIZE(my_rho_r)
568 CALL my_rho_r(ispin)%release()
569 END DO
570 DEALLOCATE (my_rho_r)
571 IF (ASSOCIATED(my_tau_r)) THEN
572 DO ispin = 1, SIZE(my_tau_r)
573 CALL my_tau_r(ispin)%release()
574 END DO
575 DEALLOCATE (my_tau_r)
576 END IF
577 END IF
578 END IF
579
580 ! ADMM Correction
581 IF (dft_control%do_admm) THEN
582 IF (admm_env%aux_exch_func /= do_admm_aux_exch_func_none) THEN
583 IF (.NOT. ASSOCIATED(kpp1_env%deriv_set_admm)) THEN
584 cpassert(.NOT. do_triplet)
585 admm_xc_section => admm_env%xc_section_aux
586 CALL get_admm_env(qs_env%admm_env, rho_aux_fit=rho)
587 CALL qs_rho_get(rho, rho_r=rho_r)
588 ALLOCATE (kpp1_env%deriv_set_admm, kpp1_env%rho_set_admm)
589 CALL xc_prep_2nd_deriv(kpp1_env%deriv_set_admm, kpp1_env%rho_set_admm, &
590 rho_r, auxbas_pw_pool, weights, &
591 xc_section=admm_xc_section)
592 END IF
593 END IF
594 END IF
595
596 END SUBROUTINE kpp1_check_i_alloc
597
598! **************************************************************************************************
599!> \brief function to advise of changes either in the grids
600!> \param kpp1_env the kpp1_env
601!> \par History
602!> 11.2002 created [fawzi]
603!> \author Fawzi Mohamed
604! **************************************************************************************************
605 SUBROUTINE kpp1_did_change(kpp1_env)
606 TYPE(qs_kpp1_env_type) :: kpp1_env
607
608 IF (ASSOCIATED(kpp1_env%deriv_set)) THEN
609 CALL xc_dset_release(kpp1_env%deriv_set)
610 DEALLOCATE (kpp1_env%deriv_set)
611 NULLIFY (kpp1_env%deriv_set)
612 END IF
613 IF (ASSOCIATED(kpp1_env%rho_set)) THEN
614 CALL xc_rho_set_release(kpp1_env%rho_set)
615 DEALLOCATE (kpp1_env%rho_set)
616 END IF
617
618 END SUBROUTINE kpp1_did_change
619
620! **************************************************************************************************
621!> \brief ...
622!> \param rho1 ...
623!> \param rho1_tot_gspace ...
624!> \param out_unit ...
625! **************************************************************************************************
626 SUBROUTINE print_densities(rho1, rho1_tot_gspace, out_unit)
627
628 TYPE(qs_rho_type), POINTER :: rho1
629 TYPE(pw_c1d_gs_type), INTENT(IN) :: rho1_tot_gspace
630 INTEGER :: out_unit
631
632 REAL(kind=dp) :: total_rho_gspace
633 REAL(kind=dp), DIMENSION(:), POINTER :: tot_rho1_r
634
635 NULLIFY (tot_rho1_r)
636
637 total_rho_gspace = pw_integrate_function(rho1_tot_gspace, isign=-1)
638 IF (out_unit > 0) THEN
639 CALL qs_rho_get(rho1, tot_rho_r=tot_rho1_r)
640 WRITE (unit=out_unit, fmt="(T3,A,T60,F20.10)") &
641 "KPP1 total charge density (r-space):", &
642 accurate_sum(tot_rho1_r), &
643 "KPP1 total charge density (g-space):", &
644 total_rho_gspace
645 END IF
646
647 END SUBROUTINE print_densities
648
649END MODULE qs_kpp1_env_methods
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.
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_add(matrix_a, matrix_b, alpha_scalar, beta_scalar)
...
DBCSR operations in CP2K.
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
routines to handle the output, The idea is to remove the decision of wheter to output and what to out...
integer function, public cp_print_key_unit_nr(logger, basis_section, print_key_path, extension, middle_name, local, log_filename, ignore_should_output, file_form, file_position, file_action, file_status, do_backup, on_file, is_new_file, mpi_io, fout)
...
subroutine, public cp_print_key_finished_output(unit_nr, logger, basis_section, print_key_path, local, ignore_should_output, on_file, mpi_io)
should be called after you finish working with a unit obtained with cp_print_key_unit_nr,...
integer function, public cp_print_key_should_output(iteration_info, basis_section, print_key_path, used_print_key, first_time)
returns what should be done with the given property if btest(res,cp_p_store) then the property should...
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...
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public do_admm_aux_exch_func_none
integer, parameter, public do_method_gapw
integer, parameter, public do_method_gapw_xc
objects that represent the structure of input sections and the data contained in an input section
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
sums arrays of real/complex numbers with much reduced round-off as compared to a naive implementation...
Definition kahan_sum.F:29
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
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.
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 ...
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.
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.
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, do_triplet, qs_env, p_env, calc_forces, calc_virial, virial)
...
subroutine, public kpp1_create(kpp1_env)
allocates and initializes a kpp1_env
subroutine, public kpp1_did_change(kpp1_env)
function to advise of changes either in the grids
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
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)
...
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...
routines that build the integrals of the Vxc potential calculated for the atomic density in the basis...
Definition qs_vxc_atom.F:12
subroutine, public calculate_xc_2nd_deriv_atom(rho_atom_set, rho1_atom_set, qs_env, xc_section, para_env, do_tddfpt2, do_triplet, do_sf, kind_set_external)
...
represent a group ofunctional derivatives
subroutine, public xc_dset_release(derivative_set)
releases a derivative set
contains the structure
subroutine, public xc_rho_set_release(rho_set, pw_pool)
releases the given 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:5539
subroutine, public xc_calc_2nd_deriv(v_xc, v_xc_tau, deriv_set, rho_set, rho1_r, rho1_g, tau1_r, pw_pool, weights, xc_section, gapw, vxg, do_excitations, do_sf, do_triplet, compute_virial, virial_xc)
Caller routine to calculate the second order potential in the direction of rho1_r.
Definition xc.F:928
stores some data used in wavefunction fitting
Definition admm_types.F:120
Provides all information about an atomic kind.
type of a logger, at the moment it contains just a print level starting at which level it should be l...
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 ...
environment that keeps the informations and temporary val to build the kpp1 kernel matrix
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.