(git:6344619)
Loading...
Searching...
No Matches
qs_dcdr_ao.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 Calculate the derivatives of the MO coefficients wrt nuclear coordinates
10!> \author Sandra Luber, Edward Ditler
11! **************************************************************************************************
12
14
18 USE cp_dbcsr_api, ONLY: dbcsr_copy,&
21 dbcsr_set,&
25 USE cp_fm_types, ONLY: cp_fm_create,&
32 USE kinds, ONLY: default_string_length,&
33 dp
35 USE pw_env_types, ONLY: pw_env_get,&
37 USE pw_methods, ONLY: pw_axpy,&
38 pw_copy,&
39 pw_scale,&
44 USE pw_pool_types, ONLY: pw_pool_p_type,&
46 USE pw_types, ONLY: pw_c1d_gs_type,&
54 USE qs_fxc, ONLY: qs_fxc_create
56 USE qs_integrate_potential, ONLY: integrate_v_dbasis,&
57 integrate_v_rspace
59 USE qs_ks_types, ONLY: get_ks_env,&
72 USE qs_rho_types, ONLY: qs_rho_create,&
77 USE qs_vxc, ONLY: qs_vxc_create
78
79!$ USE OMP_LIB, ONLY: omp_get_max_threads, omp_get_thread_num, omp_get_num_threads
80!$ USE OMP_LIB, ONLY: omp_lock_kind, &
81!$ omp_init_lock, omp_set_lock, &
82!$ omp_unset_lock, omp_destroy_lock
83
84#include "./base/base_uses.f90"
85
86 IMPLICIT NONE
87
88 PRIVATE
91 PUBLIC :: hr_mult_by_delta_1d
92
93 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_dcdr_ao'
94 CHARACTER(len=*), PARAMETER, PRIVATE :: dcdr_meta_gga_error = &
95 "Analytical DCDR is not implemented for functionals that depend on the kinetic energy density. "// &
96 "Use PROPERTIES%LINRES%DCDR%APT_FD T to calculate APTs by finite differences."
97
98CONTAINS
99
100! **************************************************************************************************
101!> \brief Build the perturbed density matrix correction depending on the overlap derivative
102!> \param qs_env ...
103!> \param dcdr_env ...
104!> \param overlap1 Overlap derivative in AO basis
105!> \author Edward Ditler
106! **************************************************************************************************
107 SUBROUTINE apply_op_constant_term(qs_env, dcdr_env, overlap1)
108 TYPE(qs_environment_type), POINTER :: qs_env
109 TYPE(dcdr_env_type) :: dcdr_env
110 TYPE(dbcsr_p_type), OPTIONAL :: overlap1
111
112 CHARACTER(len=*), PARAMETER :: routinen = 'apply_op_constant_term'
113
114 INTEGER :: handle, ispin
115 REAL(kind=dp) :: energy_hartree
116 TYPE(cp_fm_type) :: rho_ao_fm, rho_ao_s1, rho_ao_s1_rho_ao, &
117 s1_ao
118 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: rho1_ao, rho_ao
119 TYPE(pw_c1d_gs_type) :: rho1_tot_gspace, v_hartree_gspace
120 TYPE(pw_c1d_gs_type), DIMENSION(:), POINTER :: rho1_g
121 TYPE(pw_env_type), POINTER :: pw_env
122 TYPE(pw_poisson_type), POINTER :: poisson_env
123 TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
124 TYPE(pw_r3d_rs_type) :: v_hartree_rspace
125 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: rho_r, v_rspace_new, v_xc, v_xc_tau
126 TYPE(qs_rho_type), POINTER :: perturbed_density, rho
127 TYPE(rho_atom_type), DIMENSION(:), POINTER :: rho0_atom_set, rho1_atom_set
128 TYPE(section_vals_type), POINTER :: input, xc_section
129
130 ! Build the perturbed density matrix correction depending on the overlap derivative
131 ! P1 = C0 C1 + C1 C0
132 ! - C0_(mu j) S1_(jk) C0_(k nu)
133 ! This routine is adapted from apply_op_2_dft. There, build_dm_response builds
134 ! C0 * dCR + dCR * C0.
135 ! build_dm_response is computing $-1 * (C^0 C^1 + C^1 C^0)$ and later on in the
136 ! integration the factor 2 is applied to account for the occupancy.
137 ! The sign is negative because the kernel is on the RHS of the Sternheimer equation.
138 !
139 ! The correction factor in this routine needs to have
140 ! the opposite sign mathematically as (C0 C1 + C1 C0)
141 ! so the same sign in the code because of the $-1$ in dCR
142 ! so the opposite sign in the code because we are on the LHS of the Sternheimer equation.
143 !
144 ! This term must not go into the kernel applied by the linear response solver, because
145 ! for the (P)CG algorithm, all constant terms have to be on one side of the equations
146 ! and all solution dependent terms must be on the other side.
147
148 CALL timeset(routinen, handle)
149
150 NULLIFY (auxbas_pw_pool, pw_env, v_xc, poisson_env, input, rho, &
151 rho1_g, v_xc_tau)
152
153 CALL cp_fm_create(rho_ao_fm, dcdr_env%aoao_fm_struct)
154 CALL cp_fm_create(rho_ao_s1, dcdr_env%aoao_fm_struct)
155 CALL cp_fm_create(rho_ao_s1_rho_ao, dcdr_env%aoao_fm_struct)
156 CALL cp_fm_create(s1_ao, dcdr_env%aoao_fm_struct)
157
158 IF (PRESENT(overlap1)) THEN
159 CALL copy_dbcsr_to_fm(overlap1%matrix, s1_ao)
160 ELSE
161 CALL copy_dbcsr_to_fm(dcdr_env%matrix_s1(dcdr_env%beta + 1)%matrix, s1_ao)
162 END IF
163
164 DO ispin = 1, dcdr_env%nspins
165 CALL dbcsr_set(dcdr_env%perturbed_dm_correction(ispin)%matrix, 0._dp)
166 CALL dbcsr_set(dcdr_env%matrix_apply_op_constant(ispin)%matrix, 0.0_dp)
167
168 CALL parallel_gemm('N', 'T', dcdr_env%nao, dcdr_env%nao, dcdr_env%nmo(ispin), &
169 1.0_dp, dcdr_env%mo_coeff(ispin), dcdr_env%mo_coeff(ispin), &
170 0.0_dp, rho_ao_fm)
171
172 CALL parallel_gemm('N', 'N', dcdr_env%nao, dcdr_env%nao, dcdr_env%nao, &
173 1.0_dp, rho_ao_fm, s1_ao, &
174 0.0_dp, rho_ao_s1)
175
176 CALL parallel_gemm('N', 'N', dcdr_env%nao, dcdr_env%nao, dcdr_env%nao, &
177 -1._dp, rho_ao_s1, rho_ao_fm, & ! this is the sign mentioned above.
178 0.0_dp, rho_ao_s1_rho_ao)
179
180 CALL copy_fm_to_dbcsr(rho_ao_s1_rho_ao, dcdr_env%perturbed_dm_correction(ispin)%matrix)
181 END DO
182
183 CALL cp_fm_release(rho_ao_fm)
184 CALL cp_fm_release(rho_ao_s1)
185 CALL cp_fm_release(rho_ao_s1_rho_ao)
186 CALL cp_fm_release(s1_ao)
187 ! Done building the density matrix correction
188
189 ! Build the density struct from the environment
190 NULLIFY (perturbed_density)
191 ALLOCATE (perturbed_density)
192 CALL qs_rho_create(perturbed_density)
193 CALL qs_rho_rebuild(perturbed_density, qs_env=qs_env)
194
195 ! ... set the density matrix to be the perturbed density matrix
196 CALL qs_rho_get(perturbed_density, rho_ao=rho1_ao)
197 DO ispin = 1, dcdr_env%nspins
198 CALL dbcsr_copy(rho1_ao(ispin)%matrix, dcdr_env%perturbed_dm_correction(ispin)%matrix)
199 END DO
200
201 ! ... updates rho_r and rho_g to the rho%rho_ao.
202 CALL qs_rho_update_rho(rho_struct=perturbed_density, &
203 qs_env=qs_env)
204
205 ! Also update the qs_env%rho
206 CALL get_qs_env(qs_env, rho=rho)
207 CALL qs_rho_update_rho(rho, qs_env=qs_env)
208 CALL qs_rho_get(rho, rho_ao=rho_ao, rho_r=rho_r)
209
210 energy_hartree = 0.0_dp
211
212 CALL get_qs_env(qs_env=qs_env, &
213 pw_env=pw_env, &
214 input=input)
215
216 ! Create the temporary grids
217 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool, &
218 poisson_env=poisson_env)
219
220 xc_section => section_vals_get_subs_vals(input, "DFT%XC")
221
222 ALLOCATE (v_rspace_new(dcdr_env%nspins))
223 CALL auxbas_pw_pool%create_pw(v_hartree_gspace)
224 CALL auxbas_pw_pool%create_pw(v_hartree_rspace)
225
226 ! Calculate the Hartree potential on the total density
227 CALL auxbas_pw_pool%create_pw(rho1_tot_gspace)
228
229 CALL qs_rho_get(perturbed_density, rho_g=rho1_g)
230 CALL pw_copy(rho1_g(1), rho1_tot_gspace)
231 DO ispin = 2, dcdr_env%nspins
232 CALL pw_axpy(rho1_g(ispin), rho1_tot_gspace)
233 END DO
234
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
240 CALL auxbas_pw_pool%give_back_pw(rho1_tot_gspace)
241
242 ! Calculate the second derivative of the exchange-correlation potential
243 CALL qs_fxc_create(qs_env, rho, perturbed_density, rho0_atom_set, xc_section, &
244 .false., v_xc, v_xc_tau, rho1_atom_set, &
245 dispersion_env=qs_env%dispersion_env)
246 !
247
248 DO ispin = 1, dcdr_env%nspins
249 v_rspace_new(ispin) = v_xc(ispin)
250 END DO
251 DEALLOCATE (v_xc)
252
253 ! Done calculating the potentials
254
255 !-------------------------------!
256 ! Add both hartree and xc terms !
257 !-------------------------------!
258 CALL pw_scale(v_hartree_rspace, v_hartree_rspace%pw_grid%dvol)
259 DO ispin = 1, dcdr_env%nspins
260 CALL pw_scale(v_rspace_new(ispin), v_rspace_new(ispin)%pw_grid%dvol)
261 END DO
262
263 DO ispin = 1, dcdr_env%nspins
264 CALL dbcsr_set(dcdr_env%matrix_apply_op_constant(ispin)%matrix, 0.0_dp)
265 CALL pw_axpy(v_hartree_rspace, v_rspace_new(ispin))
266 IF (dcdr_env%nspins == 1) THEN
267 CALL pw_scale(v_rspace_new(1), 2.0_dp)
268 END IF
269
270 CALL integrate_v_rspace(v_rspace=v_rspace_new(ispin), &
271 hmat=dcdr_env%matrix_apply_op_constant(ispin), &
272 qs_env=qs_env, &
273 calculate_forces=.false.)
274 END DO
275
276 CALL auxbas_pw_pool%give_back_pw(v_hartree_gspace)
277 CALL auxbas_pw_pool%give_back_pw(v_hartree_rspace)
278 DO ispin = 1, dcdr_env%nspins
279 CALL auxbas_pw_pool%give_back_pw(v_rspace_new(ispin))
280 END DO
281 DEALLOCATE (v_rspace_new)
282
283 IF (ASSOCIATED(v_xc_tau)) THEN
284 CALL pw_scale(v_xc_tau(1), 2._dp*v_xc_tau(1)%pw_grid%dvol)
285 CALL integrate_v_rspace(v_rspace=v_xc_tau(1), &
286 hmat=dcdr_env%matrix_apply_op_constant(1), &
287 qs_env=qs_env, &
288 compute_tau=.true., &
289 calculate_forces=.false.)
290
291 CALL auxbas_pw_pool%give_back_pw(v_xc_tau(1))
292 DEALLOCATE (v_xc_tau)
293 END IF
294
295 CALL qs_rho_release(perturbed_density)
296 DEALLOCATE (perturbed_density)
297
298 CALL timestop(handle)
299
300 END SUBROUTINE apply_op_constant_term
301
302! **************************************************************************************************
303!> \brief Calculate the derivative of the Hartree term due to the core charge density
304!> \param qs_env ...
305!> \param dcdr_env ...
306!> \author Edward Ditler
307! **************************************************************************************************
308 SUBROUTINE d_core_charge_density_dr(qs_env, dcdr_env)
309 ! drho_core contribution
310 ! sum over all directions
311 ! output in ao x ao
312 TYPE(qs_environment_type), POINTER :: qs_env
313 TYPE(dcdr_env_type) :: dcdr_env
314
315 CHARACTER(len=*), PARAMETER :: routinen = 'd_core_charge_density_dR'
316
317 INTEGER :: beta, handle
318 TYPE(cp_logger_type), POINTER :: logger
319 TYPE(dft_control_type), POINTER :: dft_control
320 TYPE(pw_c1d_gs_type) :: drho_g, v_hartree_gspace
321 TYPE(pw_env_type), POINTER :: pw_env
322 TYPE(pw_poisson_type), POINTER :: poisson_env
323 TYPE(pw_pool_p_type), DIMENSION(:), POINTER :: pw_pools
324 TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
325 TYPE(pw_r3d_rs_type) :: v_hartree_rspace
326 TYPE(qs_rho_type), POINTER :: rho
327
328 CALL timeset(routinen, handle)
329
330 logger => cp_get_default_logger()
331
332 NULLIFY (pw_env, auxbas_pw_pool, pw_pools, poisson_env, dft_control, &
333 rho)
334
335 CALL get_qs_env(qs_env=qs_env, pw_env=pw_env, rho=rho, &
336 dft_control=dft_control)
337
338 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool, poisson_env=poisson_env, &
339 pw_pools=pw_pools)
340
341 ! Create the Hartree potential grids in real and reciprocal space.
342 CALL auxbas_pw_pool%create_pw(v_hartree_gspace)
343 CALL auxbas_pw_pool%create_pw(v_hartree_rspace)
344 ! Create the grid for the derivative of the core potential
345 CALL auxbas_pw_pool%create_pw(drho_g)
346
347 DO beta = 1, 3
348 CALL pw_zero(v_hartree_gspace)
349 CALL pw_zero(v_hartree_rspace)
350 CALL pw_zero(drho_g)
351
352 ! Calculate the Hartree potential on the perturbed density and Poisson solve it
353 CALL calculate_drho_core(drho_core=drho_g, qs_env=qs_env, &
354 beta=beta, lambda=dcdr_env%lambda)
355 CALL pw_poisson_solve(poisson_env, drho_g, &
356 vhartree=v_hartree_gspace)
357 CALL pw_transfer(v_hartree_gspace, v_hartree_rspace)
358 CALL pw_scale(v_hartree_rspace, v_hartree_rspace%pw_grid%dvol)
359
360 ! Calculate the integrals
361 CALL integrate_v_rspace(v_rspace=v_hartree_rspace, &
362 hmat=dcdr_env%matrix_core_charge_1(beta), &
363 qs_env=qs_env, &
364 calculate_forces=.false.)
365 END DO
366
367 CALL auxbas_pw_pool%give_back_pw(drho_g)
368 CALL auxbas_pw_pool%give_back_pw(v_hartree_rspace)
369 CALL auxbas_pw_pool%give_back_pw(v_hartree_gspace)
370
371 CALL timestop(handle)
372 END SUBROUTINE d_core_charge_density_dr
373
374! **************************************************************************************************
375!> \brief Core Hamiltonian contributions to the operator (the pseudopotentials)
376!> \param qs_env ...
377!> \param dcdr_env ..
378!> \author Edward Ditler
379! **************************************************************************************************
380 SUBROUTINE core_dr(qs_env, dcdr_env)
381 TYPE(qs_environment_type), POINTER :: qs_env
382 TYPE(dcdr_env_type) :: dcdr_env
383
384 CHARACTER(LEN=*), PARAMETER :: routinen = 'core_dR'
385
386 CHARACTER(LEN=default_string_length) :: my_basis_type
387 INTEGER :: handle, nder
388 LOGICAL :: calculate_forces
389 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: rho_ao
390 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_h, matrix_p_pass
391 TYPE(qs_ks_env_type), POINTER :: ks_env
392 TYPE(qs_rho_type), POINTER :: rho
393
394 CALL timeset(routinen, handle)
395
396 CALL get_qs_env(qs_env=qs_env, ks_env=ks_env)
397 CALL get_ks_env(ks_env=ks_env, rho=rho)
398 CALL qs_rho_get(rho, rho_ao=rho_ao)
399
400 nder = 1
401 calculate_forces = .false.
402
403 my_basis_type = "ORB"
404
405 NULLIFY (matrix_h)
406 matrix_p_pass(1:1, 1:1) => rho_ao(1:1)
407 CALL core_matrices(qs_env, matrix_h, matrix_p_pass, calculate_forces, nder, &
408 dcdr_env=dcdr_env)
409
410 CALL timestop(handle)
411
412 END SUBROUTINE core_dr
413
414! **************************************************************************************************
415!> \brief The derivatives of the basis functions going into the HXC potential wrt nuclear positions
416!> \param qs_env ...
417!> \param dcdr_env ...
418!> \author Edward Ditler
419! **************************************************************************************************
420 SUBROUTINE d_vhxc_dr(qs_env, dcdr_env)
421 TYPE(qs_environment_type), POINTER :: qs_env
422 TYPE(dcdr_env_type) :: dcdr_env
423
424 CHARACTER(len=*), PARAMETER :: routinen = 'd_vhxc_dR'
425
426 INTEGER :: handle, idir, ispin
427 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: rho_ao
428 TYPE(pw_c1d_gs_type) :: drho_g_total, v_hartree_gspace
429 TYPE(pw_c1d_gs_type), DIMENSION(:), POINTER :: drho_g
430 TYPE(pw_env_type), POINTER :: pw_env
431 TYPE(pw_poisson_type), POINTER :: poisson_env
432 TYPE(pw_pool_p_type), DIMENSION(:), POINTER :: pw_pools
433 TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
434 TYPE(pw_r3d_rs_type) :: drho_r_total, v_hartree_rspace
435 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: drho_r, dtau_r, rho_r, v_xc, v_xc_tau
436 TYPE(qs_rho_type), POINTER :: drho, rho
437 TYPE(rho_atom_type), DIMENSION(:), POINTER :: rho0_atom_set, rho1_atom_set
438 TYPE(section_vals_type), POINTER :: input, xc_section
439
440 CALL timeset(routinen, handle)
441
442 CALL get_qs_env(qs_env=qs_env, &
443 pw_env=pw_env, &
444 input=input, &
445 rho=rho)
446 CALL qs_rho_get(rho, rho_ao=rho_ao, rho_r=rho_r)
447
448 xc_section => section_vals_get_subs_vals(input, "DFT%XC")
449
450 ! get the tmp grids
451 ALLOCATE (drho_r(dcdr_env%nspins))
452 ALLOCATE (drho_g(dcdr_env%nspins))
453
454 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool, &
455 pw_pools=pw_pools, poisson_env=poisson_env)
456 CALL auxbas_pw_pool%create_pw(v_hartree_gspace)
457 CALL auxbas_pw_pool%create_pw(v_hartree_rspace)
458
459 DO ispin = 1, dcdr_env%nspins
460 CALL auxbas_pw_pool%create_pw(drho_r(ispin))
461 CALL auxbas_pw_pool%create_pw(drho_g(ispin))
462 END DO
463 CALL auxbas_pw_pool%create_pw(drho_g_total)
464 CALL auxbas_pw_pool%create_pw(drho_r_total)
465
466 DO idir = 1, 3
467 CALL pw_zero(v_hartree_gspace)
468 CALL pw_zero(v_hartree_rspace)
469 CALL pw_zero(drho_g_total)
470 CALL pw_zero(drho_r_total)
471
472 DO ispin = 1, dcdr_env%nspins
473 CALL pw_zero(drho_r(ispin))
474 CALL pw_zero(drho_g(ispin))
475
476 ! Get the density
477 CALL calculate_drho_elec_dr(matrix_p=rho_ao(ispin)%matrix, &
478 drho=drho_r(ispin), &
479 drho_gspace=drho_g(ispin), &
480 qs_env=qs_env, &
481 beta=idir, lambda=dcdr_env%lambda)
482
483 CALL pw_axpy(drho_g(ispin), drho_g_total)
484 CALL pw_axpy(drho_r(ispin), drho_r_total)
485 END DO
486 ! Get the Hartree potential corresponding to the perturbed density
487 CALL pw_poisson_solve(poisson_env, drho_g_total, &
488 vhartree=v_hartree_gspace)
489 CALL pw_transfer(v_hartree_gspace, v_hartree_rspace)
490
491 ALLOCATE (drho)
492 CALL qs_rho_create(drho)
493 IF (ASSOCIATED(drho_r)) THEN
494 CALL qs_rho_set(drho, rho_r=drho_r, rho_r_valid=.true.)
495 END IF
496 IF (ASSOCIATED(drho_g)) THEN
497 CALL qs_rho_set(drho, rho_g=drho_g, rho_g_valid=.true.)
498 END IF
499 IF (ASSOCIATED(dtau_r)) THEN
500 CALL qs_rho_set(drho, tau_r=dtau_r, tau_r_valid=.true.)
501 END IF
502 !
503 NULLIFY (v_xc, v_xc_tau)
504 CALL qs_fxc_create(qs_env, rho, drho, rho0_atom_set, xc_section, .false., &
505 v_xc, v_xc_tau, rho1_atom_set, &
506 dispersion_env=qs_env%dispersion_env)
507 !
508 DEALLOCATE (drho)
509
510 IF (ASSOCIATED(v_xc_tau)) THEN
511 cpabort(dcdr_meta_gga_error)
512 END IF
513
514 !-------------------------------!
515 ! Add both hartree and xc terms !
516 !-------------------------------!
517 DO ispin = 1, dcdr_env%nspins
518 ! Can the dvol be different?
519 CALL pw_scale(v_xc(ispin), v_xc(ispin)%pw_grid%dvol)
520 CALL pw_axpy(v_hartree_rspace, v_xc(ispin), v_hartree_rspace%pw_grid%dvol)
521
522 CALL integrate_v_rspace(v_rspace=v_xc(ispin), &
523 hmat=dcdr_env%matrix_d_vhxc_dR(idir, ispin), &
524 qs_env=qs_env, &
525 calculate_forces=.false.)
526
527 ! v_xc gets allocated again in xc_calc_2nd_deriv
528 CALL auxbas_pw_pool%give_back_pw(v_xc(ispin))
529 END DO ! ispin
530 DEALLOCATE (v_xc)
531 END DO ! idir
532
533 CALL auxbas_pw_pool%give_back_pw(v_hartree_gspace)
534 CALL auxbas_pw_pool%give_back_pw(v_hartree_rspace)
535 CALL auxbas_pw_pool%give_back_pw(drho_g_total)
536 CALL auxbas_pw_pool%give_back_pw(drho_r_total)
537
538 DO ispin = 1, dcdr_env%nspins
539 CALL auxbas_pw_pool%give_back_pw(drho_g(ispin))
540 CALL auxbas_pw_pool%give_back_pw(drho_r(ispin))
541 END DO
542
543 DEALLOCATE (drho_g)
544 DEALLOCATE (drho_r)
545
546 CALL timestop(handle)
547
548 END SUBROUTINE d_vhxc_dr
549
550! **************************************************************************************************
551!> \brief The derivatives of the basis functions over which the HXC potential is integrated,
552!> so < da/dR | Vhxc | b >
553!> \param qs_env ...
554!> \param dcdr_env ...
555!> \author Edward Ditler
556! **************************************************************************************************
557 SUBROUTINE vhxc_r_perturbed_basis_functions(qs_env, dcdr_env)
558 TYPE(qs_environment_type), POINTER :: qs_env
559 TYPE(dcdr_env_type) :: dcdr_env
560
561 CHARACTER(LEN=*), PARAMETER :: routinen = 'vhxc_R_perturbed_basis_functions'
562
563 INTEGER :: handle, ispin
564 REAL(kind=dp) :: edisp
565 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_vhxc_dbasis
566 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_p
567 TYPE(pw_env_type), POINTER :: pw_env
568 TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
569 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: v_hxc_r, v_tau_rspace
570 TYPE(pw_r3d_rs_type), POINTER :: v_hartree_r
571 TYPE(qs_energy_type), POINTER :: energy
572 TYPE(qs_ks_env_type), POINTER :: ks_env
573 TYPE(qs_rho_type), POINTER :: rho_struct
574 TYPE(section_vals_type), POINTER :: input, xc_section
575
576 CALL timeset(routinen, handle)
577
578 NULLIFY (rho_struct, energy, input, ks_env, pw_env, matrix_p)
579 CALL get_qs_env(qs_env, &
580 rho=rho_struct, &
581 energy=energy, &
582 input=input, &
583 ks_env=ks_env, &
584 pw_env=pw_env, &
585 v_hartree_rspace=v_hartree_r)
586 CALL qs_rho_get(rho_struct, rho_ao_kp=matrix_p)
587 xc_section => section_vals_get_subs_vals(input, "DFT%XC")
588
589 NULLIFY (auxbas_pw_pool)
590 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
591
592 ! *** calculate the xc potential on the pw density ***
593 ! *** associates v_hxc_r if the xc potential needs to be computed.
594 ! If we do wavefunction fitting, we need the vxc_potential in the auxiliary basis set
595 NULLIFY (v_hxc_r, v_tau_rspace)
596 CALL qs_vxc_create(ks_env=ks_env, rho_struct=rho_struct, xc_section=xc_section, &
597 vxc_rho=v_hxc_r, vxc_tau=v_tau_rspace, exc=energy%exc, &
598 edisp=edisp, dispersion_env=qs_env%dispersion_env)
599
600 DO ispin = 1, dcdr_env%nspins
601 CALL pw_scale(v_hxc_r(ispin), v_hxc_r(ispin)%pw_grid%dvol)
602
603 ! sum up potentials and integrate
604 CALL pw_axpy(v_hartree_r, v_hxc_r(ispin), 1._dp)
605
606 matrix_vhxc_dbasis => dcdr_env%matrix_vhxc_perturbed_basis(ispin, :)
607 CALL integrate_v_dbasis(v_rspace=v_hxc_r(ispin), &
608 matrix_p=matrix_p(ispin, 1)%matrix, &
609 matrix_vhxc_dbasis=matrix_vhxc_dbasis, &
610 qs_env=qs_env, &
611 lambda=dcdr_env%lambda)
612
613 CALL auxbas_pw_pool%give_back_pw(v_hxc_r(ispin))
614 END DO
615
616 DEALLOCATE (v_hxc_r)
617
618 CALL timestop(handle)
620
621! **************************************************************************************************
622!> \brief Enforce that one of the basis functions in < a | O | b > is centered on atom lambda.
623!> \param matrix ...
624!> \param qs_kind_set ...
625!> \param basis_type ...
626!> \param sab_nl ...
627!> \param lambda Atom index
628!> \param direction_Or True: < a | O | b==lambda >, False: < a==lambda | O | b >
629! **************************************************************************************************
630 SUBROUTINE hr_mult_by_delta_1d(matrix, qs_kind_set, basis_type, sab_nl, lambda, direction_Or)
631
632 TYPE(dbcsr_type), POINTER :: matrix
633 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
634 CHARACTER(LEN=*), INTENT(IN) :: basis_type
635 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
636 POINTER :: sab_nl
637 INTEGER, INTENT(IN) :: lambda
638 LOGICAL, INTENT(IN) :: direction_or
639
640 CHARACTER(len=*), PARAMETER :: routinen = 'hr_mult_by_delta_1d'
641
642 INTEGER :: handle, iatom, icol, ikind, irow, jatom, &
643 jkind, mepos, nkind, nthread
644 LOGICAL :: do_symmetric, found
645 REAL(kind=dp), DIMENSION(:, :), POINTER :: k_block
646 TYPE(gto_basis_set_p_type), DIMENSION(:), POINTER :: basis_set_list
647 TYPE(gto_basis_set_type), POINTER :: basis_set_a, basis_set_b
649 DIMENSION(:), POINTER :: nl_iterator
650
651 CALL timeset(routinen, handle)
652
653 nkind = SIZE(qs_kind_set)
654
655 ! check for symmetry
656 cpassert(SIZE(sab_nl) > 0)
657 CALL get_neighbor_list_set_p(neighbor_list_sets=sab_nl, symmetric=do_symmetric)
658
659 ! prepare basis set
660 ALLOCATE (basis_set_list(nkind))
661 CALL basis_set_list_setup(basis_set_list, basis_type, qs_kind_set)
662
663 nthread = 1
664!$ nthread = omp_get_max_threads()
665 ! Iterate of neighbor list
666 CALL neighbor_list_iterator_create(nl_iterator, sab_nl, nthread=nthread)
667
668!$OMP PARALLEL DEFAULT(NONE) &
669!$OMP SHARED (nl_iterator, do_symmetric) &
670!$OMP SHARED (matrix,basis_set_list) &
671!$OMP SHARED (direction_or, lambda) &
672!$OMP PRIVATE (k_block,mepos,ikind,jkind,iatom,jatom) &
673!$OMP PRIVATE (basis_set_a,basis_set_b) &
674!$OMP PRIVATE (irow, icol, found)
675
676 mepos = 0
677!$ mepos = omp_get_thread_num()
678
679 DO WHILE (neighbor_list_iterate(nl_iterator, mepos=mepos) == 0)
680 CALL get_iterator_info(nl_iterator, mepos=mepos, ikind=ikind, jkind=jkind, &
681 iatom=iatom, jatom=jatom)
682 basis_set_a => basis_set_list(ikind)%gto_basis_set
683 IF (.NOT. ASSOCIATED(basis_set_a)) cycle
684 basis_set_b => basis_set_list(jkind)%gto_basis_set
685 IF (.NOT. ASSOCIATED(basis_set_b)) cycle
686 IF (do_symmetric) THEN
687 IF (iatom <= jatom) THEN
688 irow = iatom
689 icol = jatom
690 ELSE
691 irow = jatom
692 icol = iatom
693 END IF
694 ELSE
695 irow = iatom
696 icol = jatom
697 END IF
698
699 NULLIFY (k_block)
700 CALL dbcsr_get_block_p(matrix, irow, icol, k_block, found)
701 cpassert(found)
702
703 IF (direction_or) THEN
704 IF (jatom /= lambda) k_block(:, :) = 0._dp
705 ELSE IF (.NOT. direction_or) THEN
706 IF (iatom /= lambda) k_block(:, :) = 0._dp
707 END IF
708 END DO
709!$OMP END PARALLEL
710 CALL neighbor_list_iterator_release(nl_iterator)
711
712 ! Release work storage
713 DEALLOCATE (basis_set_list)
714
715 CALL timestop(handle)
716
717 END SUBROUTINE hr_mult_by_delta_1d
718
719END MODULE qs_dcdr_ao
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_get_block_p(matrix, row, col, block, found, row_size, col_size)
...
subroutine, public dbcsr_set(matrix, alpha)
...
DBCSR operations in CP2K.
subroutine, public copy_dbcsr_to_fm(matrix, fm, plan, check_plan)
Copy a DBCSR matrix to a BLACS matrix.
subroutine, public copy_fm_to_dbcsr(fm, matrix, keep_sparsity)
Copy a BLACS matrix to a dbcsr matrix.
represent a full matrix distributed on many processors
Definition cp_fm_types.F:15
subroutine, public cp_fm_create(matrix, matrix_struct, name, nrow, ncol, set_zero)
creates a new full matrix with the given structure
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
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
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
basic linear algebra operations for full matrixes
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 ...
Calculate the plane wave density by collocating the primitive Gaussian functions (pgf).
subroutine, public calculate_drho_elec_dr(matrix_p, matrix_p_kp, drho, drho_gspace, qs_env, soft_valid, basis_type, beta, lambda)
Computes the gradient wrt. nuclear coordinates of a density on the grid The density is given in terms...
subroutine, public calculate_drho_core(drho_core, qs_env, beta, lambda)
Computes the derivative of the density of the core charges with respect to the nuclear coordinates on...
Calculation of the core Hamiltonian integral matrix <a|H|b> over Cartesian Gaussian-type functions.
subroutine, public core_matrices(qs_env, matrix_h, matrix_p, calculate_forces, nder, ec_env, dcdr_env, ec_env_matrices, ext_kpoints, basis_type, debug_forces, debug_stress, atcore)
...
Calculate the derivatives of the MO coefficients wrt nuclear coordinates.
Definition qs_dcdr_ao.F:13
subroutine, public core_dr(qs_env, dcdr_env)
Core Hamiltonian contributions to the operator (the pseudopotentials).
Definition qs_dcdr_ao.F:381
subroutine, public apply_op_constant_term(qs_env, dcdr_env, overlap1)
Build the perturbed density matrix correction depending on the overlap derivative.
Definition qs_dcdr_ao.F:108
subroutine, public hr_mult_by_delta_1d(matrix, qs_kind_set, basis_type, sab_nl, lambda, direction_or)
Enforce that one of the basis functions in < a | O | b > is centered on atom lambda.
Definition qs_dcdr_ao.F:631
subroutine, public vhxc_r_perturbed_basis_functions(qs_env, dcdr_env)
The derivatives of the basis functions over which the HXC potential is integrated,...
Definition qs_dcdr_ao.F:558
subroutine, public d_vhxc_dr(qs_env, dcdr_env)
The derivatives of the basis functions going into the HXC potential wrt nuclear positions.
Definition qs_dcdr_ao.F:421
subroutine, public d_core_charge_density_dr(qs_env, dcdr_env)
Calculate the derivative of the Hartree term due to the core charge density.
Definition qs_dcdr_ao.F:309
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_create(qs_env, rho0_struct, rho1_struct, rho0_atom_set, xc_section, do_onecenter, fxc_rho, fxc_tau, rho1_atom_set, do_scale, is_triplet, spinflip, no_weights, uf_grid_results, pw_env_ext, kind_set_external, para_env_external, dispersion_env, compute_virial, virial_xc)
...
Definition qs_fxc.F:109
Some utility functions for the calculation of integrals.
subroutine, public basis_set_list_setup(basis_set_list, basis_type, qs_kind_set)
Set up an easy accessible list of the basis sets for all kinds.
Integrate single or product functions over a potential on a RS grid.
Define the quickstep kind type and their sub types.
subroutine, public get_ks_env(ks_env, v_hartree_rspace, s_mstruct_changed, rho_changed, exc_accint, potential_changed, forces_up_to_date, complex_ks, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, kinetic, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, matrix_vhxc, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_ks_im_kp, rho, rho_xc, vppl, xcint_weights, rho_core, rho_nlcc, rho_nlcc_g, vee, neighbor_list_id, sab_orb, sab_all, sac_ae, sac_ppl, sac_lri, sap_ppnl, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_vdw, sab_scp, sab_almo, sab_kp, sab_kp_nosym, sab_cneo, task_list, task_list_soft, kpoints, do_kpoints, atomic_kind_set, qs_kind_set, cell, cell_ref, use_ref_cell, particle_set, energy, force, local_particles, local_molecules, molecule_kind_set, molecule_set, subsys, cp_subsys, virial, results, atprop, nkind, natom, dft_control, dbcsr_dist, distribution_2d, pw_env, para_env, blacs_env, nelectron_total, nelectron_spin)
...
Type definitiona for linear response calculations.
Define the neighbor list data types and the corresponding functionality.
subroutine, public neighbor_list_iterator_create(iterator_set, nl, search, nthread)
Neighbor list iterator functions.
subroutine, public neighbor_list_iterator_release(iterator_set)
...
subroutine, public get_neighbor_list_set_p(neighbor_list_sets, nlist, symmetric)
Return the components of the first neighbor list set.
integer function, public neighbor_list_iterate(iterator_set, mepos)
...
subroutine, public get_iterator_info(iterator_set, mepos, ikind, jkind, nkind, ilist, nlist, inode, nnode, iatom, jatom, r, cell)
...
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_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 qs_rho_release(rho_struct)
releases a rho_struct by decreasing the reference count by one and deallocating if it reaches 0 (to b...
subroutine, public qs_vxc_create(ks_env, rho_struct, xc_section, vxc_rho, vxc_tau, exc, just_energy, edisp, dispersion_env, adiabatic_rescale_factor, pw_env_external, native_skala_atom_force, qs_env_external, native_gapw_composite_override, native_skala_defer_to_atom_composite)
calculates and allocates the xc potential, already reducing it to the dependence on rho and the one o...
Definition qs_vxc.F:120
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...
contained for different pw related things
environment for the poisson solver
to create arrays of pools
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.
calculation environment to calculate the ks matrix, holds all the needed vars. assumes that the core ...
keeps the density in various representations, keeping track of which ones are valid.