(git:374b731)
Loading...
Searching...
No Matches
response_solver.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2024 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
8! **************************************************************************************************
9!> \brief Calculate the CPKS equation and the resulting forces
10!> \par History
11!> 03.2014 created
12!> 09.2019 Moved from KG to Kohn-Sham
13!> 11.2019 Moved from energy_correction
14!> 08.2020 AO linear response solver [fbelle]
15!> \author JGH
16! **************************************************************************************************
19 USE admm_types, ONLY: admm_type,&
23 USE cell_types, ONLY: cell_type
24 USE core_ae, ONLY: build_core_ae
25 USE core_ppl, ONLY: build_core_ppl
26 USE core_ppnl, ONLY: build_core_ppnl
38 USE cp_fm_types, ONLY: cp_fm_create,&
47 USE dbcsr_api, ONLY: &
48 dbcsr_add, dbcsr_copy, dbcsr_create, dbcsr_distribution_type, dbcsr_multiply, &
49 dbcsr_p_type, dbcsr_release, dbcsr_scale, dbcsr_set, dbcsr_type, dbcsr_type_no_symmetry
51 USE ec_methods, ONLY: create_kernel,&
62 USE hfx_ri, ONLY: hfx_ri_update_forces,&
64 USE hfx_types, ONLY: hfx_type
65 USE input_constants, ONLY: &
77 USE kinds, ONLY: default_string_length,&
78 dp
79 USE machine, ONLY: m_flush
80 USE mathlib, ONLY: det_3x3
82 USE mulliken, ONLY: ao_charges
85 USE physcon, ONLY: pascal
86 USE pw_env_types, ONLY: pw_env_get,&
88 USE pw_methods, ONLY: pw_axpy,&
89 pw_copy,&
91 pw_scale,&
97 USE pw_types, ONLY: pw_c1d_gs_type,&
107 USE qs_force_types, ONLY: qs_force_type,&
110 USE qs_integrate_potential, ONLY: integrate_v_core_rspace,&
111 integrate_v_rspace
112 USE qs_kind_types, ONLY: get_qs_kind,&
116 USE qs_ks_atom, ONLY: update_ks_atom
118 USE qs_ks_types, ONLY: qs_ks_env_type
126 USE qs_mo_types, ONLY: deallocate_mo_set,&
127 get_mo_set,&
132 USE qs_p_env_methods, ONLY: p_env_create,&
134 USE qs_p_env_types, ONLY: p_env_release,&
138 USE qs_rho0_methods, ONLY: init_rho0
141 USE qs_rho_types, ONLY: qs_rho_get,&
147 USE virial_types, ONLY: virial_type
150 USE xtb_matrices, ONLY: xtb_hab_force
151 USE xtb_types, ONLY: get_xtb_atom_param,&
153#include "./base/base_uses.f90"
154
155 IMPLICIT NONE
156
157 PRIVATE
158
159 ! Global parameters
160
161 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'response_solver'
162
165
166! **************************************************************************************************
167
168CONTAINS
169
170! **************************************************************************************************
171!> \brief Initializes solver of linear response equation for energy correction
172!> \brief Call AO or MO based linear response solver for energy correction
173!>
174!> \param qs_env The quickstep environment
175!> \param ec_env The energy correction environment
176!>
177!> \date 01.2020
178!> \author Fabian Belleflamme
179! **************************************************************************************************
180 SUBROUTINE response_calculation(qs_env, ec_env)
181 TYPE(qs_environment_type), POINTER :: qs_env
182 TYPE(energy_correction_type), POINTER :: ec_env
183
184 CHARACTER(LEN=*), PARAMETER :: routinen = 'response_calculation'
185
186 INTEGER :: handle, homo, ispin, nao, nao_aux, nmo, &
187 nocc, nspins, solver_method, unit_nr
188 LOGICAL :: should_stop
189 REAL(kind=dp) :: focc
190 TYPE(admm_type), POINTER :: admm_env
191 TYPE(cp_blacs_env_type), POINTER :: blacs_env
192 TYPE(cp_fm_struct_type), POINTER :: fm_struct
193 TYPE(cp_fm_type) :: sv
194 TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:) :: cpmos, mo_occ
195 TYPE(cp_fm_type), POINTER :: mo_coeff
196 TYPE(cp_logger_type), POINTER :: logger
197 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_s, matrix_s_aux, rho_ao
198 TYPE(dft_control_type), POINTER :: dft_control
199 TYPE(linres_control_type), POINTER :: linres_control
200 TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
201 TYPE(mp_para_env_type), POINTER :: para_env
202 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
203 POINTER :: sab_orb
204 TYPE(qs_energy_type), POINTER :: energy
205 TYPE(qs_p_env_type), POINTER :: p_env
206 TYPE(qs_rho_type), POINTER :: rho
207 TYPE(section_vals_type), POINTER :: input, solver_section
208
209 CALL timeset(routinen, handle)
210
211 NULLIFY (admm_env, dft_control, energy, logger, matrix_s, matrix_s_aux, mo_coeff, mos, para_env, &
212 rho_ao, sab_orb, solver_section)
213
214 ! Get useful output unit
215 logger => cp_get_default_logger()
216 IF (logger%para_env%is_source()) THEN
217 unit_nr = cp_logger_get_default_unit_nr(logger, local=.true.)
218 ELSE
219 unit_nr = -1
220 END IF
221
222 CALL get_qs_env(qs_env, &
223 dft_control=dft_control, &
224 input=input, &
225 matrix_s=matrix_s, &
226 para_env=para_env, &
227 sab_orb=sab_orb)
228 nspins = dft_control%nspins
229
230 ! initialize linres_control
231 NULLIFY (linres_control)
232 ALLOCATE (linres_control)
233 linres_control%do_kernel = .true.
234 linres_control%lr_triplet = .false.
235 linres_control%converged = .false.
236 linres_control%energy_gap = 0.02_dp
237
238 ! Read input
239 solver_section => section_vals_get_subs_vals(input, "DFT%ENERGY_CORRECTION%RESPONSE_SOLVER")
240 CALL section_vals_val_get(solver_section, "EPS", r_val=linres_control%eps)
241 CALL section_vals_val_get(solver_section, "EPS_FILTER", r_val=linres_control%eps_filter)
242 CALL section_vals_val_get(solver_section, "MAX_ITER", i_val=linres_control%max_iter)
243 CALL section_vals_val_get(solver_section, "METHOD", i_val=solver_method)
244 CALL section_vals_val_get(solver_section, "PRECONDITIONER", i_val=linres_control%preconditioner_type)
245 CALL section_vals_val_get(solver_section, "RESTART", l_val=linres_control%linres_restart)
246 CALL section_vals_val_get(solver_section, "RESTART_EVERY", i_val=linres_control%restart_every)
247 CALL set_qs_env(qs_env, linres_control=linres_control)
248
249 ! Write input section of response solver
250 CALL response_solver_write_input(solver_section, linres_control, unit_nr)
251
252 ! Allocate and initialize response density matrix Z,
253 ! and the energy weighted response density matrix
254 ! Template is the ground-state overlap matrix
255 CALL dbcsr_allocate_matrix_set(ec_env%matrix_wz, nspins)
256 CALL dbcsr_allocate_matrix_set(ec_env%matrix_z, nspins)
257 DO ispin = 1, nspins
258 ALLOCATE (ec_env%matrix_wz(ispin)%matrix)
259 ALLOCATE (ec_env%matrix_z(ispin)%matrix)
260 CALL dbcsr_create(ec_env%matrix_wz(ispin)%matrix, name="Wz MATRIX", &
261 template=matrix_s(1)%matrix)
262 CALL dbcsr_create(ec_env%matrix_z(ispin)%matrix, name="Z MATRIX", &
263 template=matrix_s(1)%matrix)
264 CALL cp_dbcsr_alloc_block_from_nbl(ec_env%matrix_wz(ispin)%matrix, sab_orb)
265 CALL cp_dbcsr_alloc_block_from_nbl(ec_env%matrix_z(ispin)%matrix, sab_orb)
266 CALL dbcsr_set(ec_env%matrix_wz(ispin)%matrix, 0.0_dp)
267 CALL dbcsr_set(ec_env%matrix_z(ispin)%matrix, 0.0_dp)
268 END DO
269
270 ! MO solver requires MO's of the ground-state calculation,
271 ! The MOs environment is not allocated if LS-DFT has been used.
272 ! Introduce MOs here
273 ! Remark: MOS environment also required for creation of p_env
274 IF (dft_control%qs_control%do_ls_scf) THEN
275
276 ! Allocate and initialize MO environment
277 CALL ec_mos_init(qs_env, matrix_s(1)%matrix)
278 CALL get_qs_env(qs_env, mos=mos, rho=rho)
279
280 ! Get ground-state density matrix
281 CALL qs_rho_get(rho, rho_ao=rho_ao)
282
283 DO ispin = 1, nspins
284 CALL get_mo_set(mo_set=mos(ispin), &
285 mo_coeff=mo_coeff, &
286 nmo=nmo, nao=nao, homo=homo)
287
288 CALL cp_fm_set_all(mo_coeff, 0.0_dp)
289 CALL cp_fm_init_random(mo_coeff, nmo)
290
291 CALL cp_fm_create(sv, mo_coeff%matrix_struct, "SV")
292 ! multiply times PS
293 ! PS*C(:,1:nomo)+C(:,nomo+1:nmo) (nomo=NINT(nelectron/maxocc))
294 CALL cp_dbcsr_sm_fm_multiply(matrix_s(1)%matrix, mo_coeff, sv, nmo)
295 CALL cp_dbcsr_sm_fm_multiply(rho_ao(ispin)%matrix, sv, mo_coeff, homo)
296 CALL cp_fm_release(sv)
297 ! and ortho the result
298 CALL make_basis_sm(mo_coeff, nmo, matrix_s(1)%matrix)
299
300 ! rebuilds fm_pools
301 ! originally done in qs_env_setup, only when mos associated
302 NULLIFY (blacs_env)
303 CALL get_qs_env(qs_env, blacs_env=blacs_env)
304 CALL mpools_rebuild_fm_pools(qs_env%mpools, mos=mos, &
305 blacs_env=blacs_env, para_env=para_env)
306 END DO
307 END IF
308
309 ! initialize p_env
310 ! Remark: mos environment is needed for this
311 IF (ASSOCIATED(ec_env%p_env)) THEN
312 CALL p_env_release(ec_env%p_env)
313 DEALLOCATE (ec_env%p_env)
314 NULLIFY (ec_env%p_env)
315 END IF
316 ALLOCATE (ec_env%p_env)
317 CALL p_env_create(ec_env%p_env, qs_env, orthogonal_orbitals=.true., &
318 linres_control=linres_control)
319 CALL p_env_psi0_changed(ec_env%p_env, qs_env)
320 ! Total energy overwritten, replace with Etot from energy correction
321 CALL get_qs_env(qs_env, energy=energy)
322 energy%total = ec_env%etotal
323 !
324 p_env => ec_env%p_env
325 !
326 CALL dbcsr_allocate_matrix_set(p_env%p1, nspins)
327 CALL dbcsr_allocate_matrix_set(p_env%w1, nspins)
328 DO ispin = 1, nspins
329 ALLOCATE (p_env%p1(ispin)%matrix, p_env%w1(ispin)%matrix)
330 CALL dbcsr_create(matrix=p_env%p1(ispin)%matrix, template=matrix_s(1)%matrix)
331 CALL dbcsr_create(matrix=p_env%w1(ispin)%matrix, template=matrix_s(1)%matrix)
332 CALL cp_dbcsr_alloc_block_from_nbl(p_env%p1(ispin)%matrix, sab_orb)
333 CALL cp_dbcsr_alloc_block_from_nbl(p_env%w1(ispin)%matrix, sab_orb)
334 END DO
335 IF (dft_control%do_admm) THEN
336 CALL get_admm_env(qs_env%admm_env, matrix_s_aux_fit=matrix_s_aux)
337 CALL dbcsr_allocate_matrix_set(p_env%p1_admm, nspins)
338 DO ispin = 1, nspins
339 ALLOCATE (p_env%p1_admm(ispin)%matrix)
340 CALL dbcsr_create(p_env%p1_admm(ispin)%matrix, &
341 template=matrix_s_aux(1)%matrix)
342 CALL dbcsr_copy(p_env%p1_admm(ispin)%matrix, matrix_s_aux(1)%matrix)
343 CALL dbcsr_set(p_env%p1_admm(ispin)%matrix, 0.0_dp)
344 END DO
345 END IF
346
347 ! Choose between MO-solver and AO-solver
348 SELECT CASE (solver_method)
349 CASE (ec_mo_solver)
350
351 ! CPKS vector cpmos - RHS of response equation as Ax + b = 0 (sign of b)
352 ! Sign is changed in linres_solver!
353 ! Projector Q applied in linres_solver!
354 CALL get_qs_env(qs_env, mos=mos)
355 ALLOCATE (cpmos(nspins), mo_occ(nspins))
356 DO ispin = 1, nspins
357 CALL get_mo_set(mo_set=mos(ispin), mo_coeff=mo_coeff, homo=nocc)
358 NULLIFY (fm_struct)
359 CALL cp_fm_struct_create(fm_struct, ncol_global=nocc, &
360 template_fmstruct=mo_coeff%matrix_struct)
361 CALL cp_fm_create(cpmos(ispin), fm_struct)
362 CALL cp_fm_set_all(cpmos(ispin), 0.0_dp)
363 CALL cp_fm_create(mo_occ(ispin), fm_struct)
364 CALL cp_fm_to_fm(mo_coeff, mo_occ(ispin), nocc)
365 CALL cp_fm_struct_release(fm_struct)
366 END DO
367
368 focc = 2.0_dp
369 IF (nspins == 1) focc = 4.0_dp
370 DO ispin = 1, nspins
371 CALL get_mo_set(mo_set=mos(ispin), mo_coeff=mo_coeff, homo=nocc)
372 CALL cp_dbcsr_sm_fm_multiply(ec_env%matrix_hz(ispin)%matrix, mo_occ(ispin), &
373 cpmos(ispin), nocc, &
374 alpha=focc, beta=0.0_dp)
375 END DO
376 CALL cp_fm_release(mo_occ)
377
378 CALL response_equation_new(qs_env, p_env, cpmos, unit_nr)
379
380 ! Get the response density matrix,
381 ! and energy-weighted response density matrix
382 DO ispin = 1, nspins
383 CALL dbcsr_copy(ec_env%matrix_z(ispin)%matrix, p_env%p1(ispin)%matrix)
384 CALL dbcsr_copy(ec_env%matrix_wz(ispin)%matrix, p_env%w1(ispin)%matrix)
385 END DO
386 CALL cp_fm_release(cpmos)
387
388 CASE (ec_ls_solver)
389
390 ! AO ortho solver
391 CALL ec_response_ao(qs_env=qs_env, &
392 p_env=p_env, &
393 matrix_hz=ec_env%matrix_hz, &
394 matrix_pz=ec_env%matrix_z, &
395 matrix_wz=ec_env%matrix_wz, &
396 iounit=unit_nr, &
397 should_stop=should_stop)
398
399 IF (dft_control%do_admm) THEN
400 CALL get_qs_env(qs_env, admm_env=admm_env)
401 cpassert(ASSOCIATED(admm_env%work_orb_orb))
402 cpassert(ASSOCIATED(admm_env%work_aux_orb))
403 cpassert(ASSOCIATED(admm_env%work_aux_aux))
404 nao = admm_env%nao_orb
405 nao_aux = admm_env%nao_aux_fit
406 DO ispin = 1, nspins
407 CALL copy_dbcsr_to_fm(ec_env%matrix_z(ispin)%matrix, admm_env%work_orb_orb)
408 CALL parallel_gemm('N', 'N', nao_aux, nao, nao, &
409 1.0_dp, admm_env%A, admm_env%work_orb_orb, 0.0_dp, &
410 admm_env%work_aux_orb)
411 CALL parallel_gemm('N', 'T', nao_aux, nao_aux, nao, &
412 1.0_dp, admm_env%work_aux_orb, admm_env%A, 0.0_dp, &
413 admm_env%work_aux_aux)
414 CALL copy_fm_to_dbcsr(admm_env%work_aux_aux, p_env%p1_admm(ispin)%matrix, &
415 keep_sparsity=.true.)
416 END DO
417 END IF
418
419 CASE DEFAULT
420 cpabort("Unknown solver for response equation requested")
421 END SELECT
422
423 IF (dft_control%do_admm) THEN
424 CALL dbcsr_allocate_matrix_set(ec_env%z_admm, nspins)
425 DO ispin = 1, nspins
426 ALLOCATE (ec_env%z_admm(ispin)%matrix)
427 CALL dbcsr_create(matrix=ec_env%z_admm(ispin)%matrix, template=matrix_s_aux(1)%matrix)
428 CALL get_qs_env(qs_env, admm_env=admm_env)
429 CALL dbcsr_copy(ec_env%z_admm(ispin)%matrix, p_env%p1_admm(ispin)%matrix)
430 END DO
431 END IF
432
433 ! Get rid of MO environment again
434 IF (dft_control%qs_control%do_ls_scf) THEN
435 DO ispin = 1, nspins
436 CALL deallocate_mo_set(mos(ispin))
437 END DO
438 IF (ASSOCIATED(qs_env%mos)) THEN
439 DO ispin = 1, SIZE(qs_env%mos)
440 CALL deallocate_mo_set(qs_env%mos(ispin))
441 END DO
442 DEALLOCATE (qs_env%mos)
443 END IF
444 END IF
445
446 CALL timestop(handle)
447
448 END SUBROUTINE response_calculation
449
450! **************************************************************************************************
451!> \brief Parse the input section of the response solver
452!> \param input Input section which controls response solver parameters
453!> \param linres_control Environment for general setting of linear response calculation
454!> \param unit_nr ...
455!> \par History
456!> 2020.05 created [Fabian Belleflamme]
457!> \author Fabian Belleflamme
458! **************************************************************************************************
459 SUBROUTINE response_solver_write_input(input, linres_control, unit_nr)
460 TYPE(section_vals_type), POINTER :: input
461 TYPE(linres_control_type), POINTER :: linres_control
462 INTEGER, INTENT(IN) :: unit_nr
463
464 CHARACTER(len=*), PARAMETER :: routinen = 'response_solver_write_input'
465
466 INTEGER :: handle, max_iter_lanczos, s_sqrt_method, &
467 s_sqrt_order, solver_method
468 REAL(kind=dp) :: eps_lanczos
469
470 CALL timeset(routinen, handle)
471
472 IF (unit_nr > 0) THEN
473
474 ! linres_control
475 WRITE (unit_nr, '(/,T2,A)') &
476 repeat("-", 30)//" Linear Response Solver "//repeat("-", 25)
477
478 ! Which type of solver is used
479 CALL section_vals_val_get(input, "METHOD", i_val=solver_method)
480
481 SELECT CASE (solver_method)
482 CASE (ec_ls_solver)
483 WRITE (unit_nr, '(T2,A,T61,A20)') "Solver: ", "AO-based CG-solver"
484 CASE (ec_mo_solver)
485 WRITE (unit_nr, '(T2,A,T61,A20)') "Solver: ", "MO-based CG-solver"
486 END SELECT
487
488 WRITE (unit_nr, '(T2,A,T61,E20.3)') "eps:", linres_control%eps
489 WRITE (unit_nr, '(T2,A,T61,E20.3)') "eps_filter:", linres_control%eps_filter
490 WRITE (unit_nr, '(T2,A,T61,I20)') "Max iter:", linres_control%max_iter
491
492 SELECT CASE (linres_control%preconditioner_type)
494 WRITE (unit_nr, '(T2,A,T61,A20)') "Preconditioner: ", "FULL_ALL"
496 WRITE (unit_nr, '(T2,A,T61,A20)') "Preconditioner: ", "FULL_SINGLE_INVERSE"
498 WRITE (unit_nr, '(T2,A,T61,A20)') "Preconditioner: ", "FULL_SINGLE"
500 WRITE (unit_nr, '(T2,A,T61,A20)') "Preconditioner: ", "FULL_KINETIC"
502 WRITE (unit_nr, '(T2,A,T61,A20)') "Preconditioner: ", "FULL_S_INVERSE"
503 CASE (precond_mlp)
504 WRITE (unit_nr, '(T2,A,T61,A20)') "Preconditioner: ", "MULTI_LEVEL"
505 CASE (ot_precond_none)
506 WRITE (unit_nr, '(T2,A,T61,A20)') "Preconditioner: ", "NONE"
507 END SELECT
508
509 SELECT CASE (solver_method)
510 CASE (ec_ls_solver)
511
512 CALL section_vals_val_get(input, "S_SQRT_METHOD", i_val=s_sqrt_method)
513 CALL section_vals_val_get(input, "S_SQRT_ORDER", i_val=s_sqrt_order)
514 CALL section_vals_val_get(input, "EPS_LANCZOS", r_val=eps_lanczos)
515 CALL section_vals_val_get(input, "MAX_ITER_LANCZOS", i_val=max_iter_lanczos)
516
517 ! Response solver transforms P and KS into orthonormal basis,
518 ! reuires matrx S sqrt and its inverse
519 SELECT CASE (s_sqrt_method)
520 CASE (ls_s_sqrt_ns)
521 WRITE (unit_nr, '(T2,A,T61,A20)') "S sqrt method:", "NEWTONSCHULZ"
522 CASE (ls_s_sqrt_proot)
523 WRITE (unit_nr, '(T2,A,T61,A20)') "S sqrt method:", "PROOT"
524 CASE DEFAULT
525 cpabort("Unknown sqrt method.")
526 END SELECT
527 WRITE (unit_nr, '(T2,A,T61,I20)') "S sqrt order:", s_sqrt_order
528
529 CASE (ec_mo_solver)
530 END SELECT
531
532 WRITE (unit_nr, '(T2,A)') repeat("-", 79)
533
534 CALL m_flush(unit_nr)
535 END IF
536
537 CALL timestop(handle)
538
539 END SUBROUTINE response_solver_write_input
540
541! **************************************************************************************************
542!> \brief Initializes vectors for MO-coefficient based linear response solver
543!> and calculates response density, and energy-weighted response density matrix
544!>
545!> \param qs_env ...
546!> \param p_env ...
547!> \param cpmos ...
548!> \param iounit ...
549! **************************************************************************************************
550 SUBROUTINE response_equation_new(qs_env, p_env, cpmos, iounit)
551 TYPE(qs_environment_type), POINTER :: qs_env
552 TYPE(qs_p_env_type) :: p_env
553 TYPE(cp_fm_type), DIMENSION(:), INTENT(INOUT) :: cpmos
554 INTEGER, INTENT(IN) :: iounit
555
556 CHARACTER(LEN=*), PARAMETER :: routinen = 'response_equation_new'
557
558 INTEGER :: handle, ispin, nao, nao_aux, nocc, nspins
559 LOGICAL :: should_stop
560 TYPE(admm_type), POINTER :: admm_env
561 TYPE(cp_fm_struct_type), POINTER :: fm_struct
562 TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:) :: psi0, psi1
563 TYPE(cp_fm_type), POINTER :: mo_coeff
564 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_ks, matrix_s
565 TYPE(dft_control_type), POINTER :: dft_control
566 TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
567
568 CALL timeset(routinen, handle)
569
570 NULLIFY (dft_control, matrix_ks, mo_coeff, mos)
571
572 CALL get_qs_env(qs_env, dft_control=dft_control, matrix_ks=matrix_ks, &
573 matrix_s=matrix_s, mos=mos)
574 nspins = dft_control%nspins
575
576 ! Initialize vectors:
577 ! psi0 : The ground-state MO-coefficients
578 ! psi1 : The "perturbed" linear response orbitals
579 ALLOCATE (psi0(nspins), psi1(nspins))
580 DO ispin = 1, nspins
581 CALL get_mo_set(mos(ispin), mo_coeff=mo_coeff, homo=nocc)
582 NULLIFY (fm_struct)
583 CALL cp_fm_struct_create(fm_struct, ncol_global=nocc, &
584 template_fmstruct=mo_coeff%matrix_struct)
585 CALL cp_fm_create(psi0(ispin), fm_struct)
586 CALL cp_fm_to_fm(mo_coeff, psi0(ispin), nocc)
587 CALL cp_fm_create(psi1(ispin), fm_struct)
588 CALL cp_fm_set_all(psi1(ispin), 0.0_dp)
589 CALL cp_fm_struct_release(fm_struct)
590 END DO
591
592 should_stop = .false.
593 ! The response solver
594 CALL linres_solver(p_env, qs_env, psi1, cpmos, psi0, iounit, should_stop)
595
596 ! Building the response density matrix
597 DO ispin = 1, nspins
598 CALL dbcsr_copy(p_env%p1(ispin)%matrix, matrix_s(1)%matrix)
599 END DO
600 CALL build_dm_response(psi0, psi1, p_env%p1)
601 DO ispin = 1, nspins
602 CALL dbcsr_scale(p_env%p1(ispin)%matrix, 0.5_dp)
603 END DO
604
605 IF (dft_control%do_admm) THEN
606 CALL get_qs_env(qs_env, admm_env=admm_env)
607 cpassert(ASSOCIATED(admm_env%work_orb_orb))
608 cpassert(ASSOCIATED(admm_env%work_aux_orb))
609 cpassert(ASSOCIATED(admm_env%work_aux_aux))
610 nao = admm_env%nao_orb
611 nao_aux = admm_env%nao_aux_fit
612 DO ispin = 1, nspins
613 CALL copy_dbcsr_to_fm(p_env%p1(ispin)%matrix, admm_env%work_orb_orb)
614 CALL parallel_gemm('N', 'N', nao_aux, nao, nao, &
615 1.0_dp, admm_env%A, admm_env%work_orb_orb, 0.0_dp, &
616 admm_env%work_aux_orb)
617 CALL parallel_gemm('N', 'T', nao_aux, nao_aux, nao, &
618 1.0_dp, admm_env%work_aux_orb, admm_env%A, 0.0_dp, &
619 admm_env%work_aux_aux)
620 CALL copy_fm_to_dbcsr(admm_env%work_aux_aux, p_env%p1_admm(ispin)%matrix, &
621 keep_sparsity=.true.)
622 END DO
623 END IF
624
625 ! Calculate Wz = 0.5*(psi1*eps*psi0^T + psi0*eps*psi1^T)
626 DO ispin = 1, nspins
627 CALL calculate_wz_matrix(mos(ispin), psi1(ispin), matrix_ks(ispin)%matrix, &
628 p_env%w1(ispin)%matrix)
629 END DO
630 DO ispin = 1, nspins
631 CALL cp_fm_release(cpmos(ispin))
632 END DO
633 CALL cp_fm_release(psi1)
634 CALL cp_fm_release(psi0)
635
636 CALL timestop(handle)
637
638 END SUBROUTINE response_equation_new
639
640! **************************************************************************************************
641!> \brief Initializes vectors for MO-coefficient based linear response solver
642!> and calculates response density, and energy-weighted response density matrix
643!>
644!> \param qs_env ...
645!> \param p_env ...
646!> \param cpmos RHS of equation as Ax + b = 0 (sign of b)
647!> \param iounit ...
648!> \param lr_section ...
649! **************************************************************************************************
650 SUBROUTINE response_equation(qs_env, p_env, cpmos, iounit, lr_section)
651 TYPE(qs_environment_type), POINTER :: qs_env
652 TYPE(qs_p_env_type) :: p_env
653 TYPE(cp_fm_type), DIMENSION(:), POINTER :: cpmos
654 INTEGER, INTENT(IN) :: iounit
655 TYPE(section_vals_type), OPTIONAL, POINTER :: lr_section
656
657 CHARACTER(LEN=*), PARAMETER :: routinen = 'response_equation'
658
659 INTEGER :: handle, ispin, nao, nao_aux, nocc, nspins
660 LOGICAL :: should_stop
661 TYPE(admm_type), POINTER :: admm_env
662 TYPE(cp_fm_struct_type), POINTER :: fm_struct
663 TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:) :: psi0, psi1
664 TYPE(cp_fm_type), POINTER :: mo_coeff
665 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_ks, matrix_s, matrix_s_aux
666 TYPE(dft_control_type), POINTER :: dft_control
667 TYPE(linres_control_type), POINTER :: linres_control
668 TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
669 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
670 POINTER :: sab_orb
671
672 CALL timeset(routinen, handle)
673
674 ! initialized linres_control
675 NULLIFY (linres_control)
676 ALLOCATE (linres_control)
677 linres_control%do_kernel = .true.
678 linres_control%lr_triplet = .false.
679 IF (PRESENT(lr_section)) THEN
680 CALL section_vals_val_get(lr_section, "RESTART", l_val=linres_control%linres_restart)
681 CALL section_vals_val_get(lr_section, "MAX_ITER", i_val=linres_control%max_iter)
682 CALL section_vals_val_get(lr_section, "EPS", r_val=linres_control%eps)
683 CALL section_vals_val_get(lr_section, "EPS_FILTER", r_val=linres_control%eps_filter)
684 CALL section_vals_val_get(lr_section, "RESTART_EVERY", i_val=linres_control%restart_every)
685 CALL section_vals_val_get(lr_section, "PRECONDITIONER", i_val=linres_control%preconditioner_type)
686 CALL section_vals_val_get(lr_section, "ENERGY_GAP", r_val=linres_control%energy_gap)
687 ELSE
688 linres_control%linres_restart = .false.
689 linres_control%max_iter = 100
690 linres_control%eps = 1.0e-10_dp
691 linres_control%eps_filter = 1.0e-15_dp
692 linres_control%restart_every = 50
693 linres_control%preconditioner_type = ot_precond_full_single_inverse
694 linres_control%energy_gap = 0.02_dp
695 END IF
696
697 ! initialized p_env
698 CALL p_env_create(p_env, qs_env, orthogonal_orbitals=.true., &
699 linres_control=linres_control)
700 CALL set_qs_env(qs_env, linres_control=linres_control)
701 CALL p_env_psi0_changed(p_env, qs_env)
702 p_env%new_preconditioner = .true.
703
704 CALL get_qs_env(qs_env, dft_control=dft_control, mos=mos)
705 !
706 nspins = dft_control%nspins
707
708 ! Initialize vectors:
709 ! psi0 : The ground-state MO-coefficients
710 ! psi1 : The "perturbed" linear response orbitals
711 ALLOCATE (psi0(nspins), psi1(nspins))
712 DO ispin = 1, nspins
713 CALL get_mo_set(mos(ispin), mo_coeff=mo_coeff, homo=nocc)
714 NULLIFY (fm_struct)
715 CALL cp_fm_struct_create(fm_struct, ncol_global=nocc, &
716 template_fmstruct=mo_coeff%matrix_struct)
717 CALL cp_fm_create(psi0(ispin), fm_struct)
718 CALL cp_fm_to_fm(mo_coeff, psi0(ispin), nocc)
719 CALL cp_fm_create(psi1(ispin), fm_struct)
720 CALL cp_fm_set_all(psi1(ispin), 0.0_dp)
721 CALL cp_fm_struct_release(fm_struct)
722 END DO
723
724 should_stop = .false.
725 ! The response solver
726 CALL get_qs_env(qs_env, matrix_s=matrix_s, sab_orb=sab_orb)
727 CALL dbcsr_allocate_matrix_set(p_env%p1, nspins)
728 CALL dbcsr_allocate_matrix_set(p_env%w1, nspins)
729 DO ispin = 1, nspins
730 ALLOCATE (p_env%p1(ispin)%matrix, p_env%w1(ispin)%matrix)
731 CALL dbcsr_create(matrix=p_env%p1(ispin)%matrix, template=matrix_s(1)%matrix)
732 CALL dbcsr_create(matrix=p_env%w1(ispin)%matrix, template=matrix_s(1)%matrix)
733 CALL cp_dbcsr_alloc_block_from_nbl(p_env%p1(ispin)%matrix, sab_orb)
734 CALL cp_dbcsr_alloc_block_from_nbl(p_env%w1(ispin)%matrix, sab_orb)
735 END DO
736 IF (dft_control%do_admm) THEN
737 CALL get_admm_env(qs_env%admm_env, matrix_s_aux_fit=matrix_s_aux)
738 CALL dbcsr_allocate_matrix_set(p_env%p1_admm, nspins)
739 DO ispin = 1, nspins
740 ALLOCATE (p_env%p1_admm(ispin)%matrix)
741 CALL dbcsr_create(p_env%p1_admm(ispin)%matrix, &
742 template=matrix_s_aux(1)%matrix)
743 CALL dbcsr_copy(p_env%p1_admm(ispin)%matrix, matrix_s_aux(1)%matrix)
744 CALL dbcsr_set(p_env%p1_admm(ispin)%matrix, 0.0_dp)
745 END DO
746 END IF
747
748 CALL linres_solver(p_env, qs_env, psi1, cpmos, psi0, iounit, should_stop)
749
750 ! Building the response density matrix
751 DO ispin = 1, nspins
752 CALL dbcsr_copy(p_env%p1(ispin)%matrix, matrix_s(1)%matrix)
753 END DO
754 CALL build_dm_response(psi0, psi1, p_env%p1)
755 DO ispin = 1, nspins
756 CALL dbcsr_scale(p_env%p1(ispin)%matrix, 0.5_dp)
757 END DO
758 IF (dft_control%do_admm) THEN
759 CALL get_qs_env(qs_env, admm_env=admm_env)
760 cpassert(ASSOCIATED(admm_env%work_orb_orb))
761 cpassert(ASSOCIATED(admm_env%work_aux_orb))
762 cpassert(ASSOCIATED(admm_env%work_aux_aux))
763 nao = admm_env%nao_orb
764 nao_aux = admm_env%nao_aux_fit
765 DO ispin = 1, nspins
766 CALL copy_dbcsr_to_fm(p_env%p1(ispin)%matrix, admm_env%work_orb_orb)
767 CALL parallel_gemm('N', 'N', nao_aux, nao, nao, &
768 1.0_dp, admm_env%A, admm_env%work_orb_orb, 0.0_dp, &
769 admm_env%work_aux_orb)
770 CALL parallel_gemm('N', 'T', nao_aux, nao_aux, nao, &
771 1.0_dp, admm_env%work_aux_orb, admm_env%A, 0.0_dp, &
772 admm_env%work_aux_aux)
773 CALL copy_fm_to_dbcsr(admm_env%work_aux_aux, p_env%p1_admm(ispin)%matrix, &
774 keep_sparsity=.true.)
775 END DO
776 END IF
777
778 ! Calculate Wz = 0.5*(psi1*eps*psi0^T + psi0*eps*psi1^T)
779 CALL get_qs_env(qs_env, matrix_ks=matrix_ks)
780 DO ispin = 1, nspins
781 CALL calculate_wz_matrix(mos(ispin), psi1(ispin), matrix_ks(ispin)%matrix, &
782 p_env%w1(ispin)%matrix)
783 END DO
784 CALL cp_fm_release(psi0)
785 CALL cp_fm_release(psi1)
786
787 CALL timestop(handle)
788
789 END SUBROUTINE response_equation
790
791! **************************************************************************************************
792!> \brief ...
793!> \param qs_env ...
794!> \param vh_rspace ...
795!> \param vxc_rspace ...
796!> \param vtau_rspace ...
797!> \param vadmm_rspace ...
798!> \param matrix_hz Right-hand-side of linear response equation
799!> \param matrix_pz Linear response density matrix
800!> \param matrix_pz_admm Linear response density matrix in ADMM basis
801!> \param matrix_wz Energy-weighted linear response density
802!> \param zehartree Hartree volume response contribution to stress tensor
803!> \param zexc XC volume response contribution to stress tensor
804!> \param zexc_aux_fit ADMM XC volume response contribution to stress tensor
805!> \param rhopz_r Response density on real space grid
806!> \param p_env ...
807!> \param ex_env ...
808!> \param debug ...
809! **************************************************************************************************
810 SUBROUTINE response_force(qs_env, vh_rspace, vxc_rspace, vtau_rspace, vadmm_rspace, &
811 matrix_hz, matrix_pz, matrix_pz_admm, matrix_wz, &
812 zehartree, zexc, zexc_aux_fit, rhopz_r, p_env, ex_env, debug)
813 TYPE(qs_environment_type), POINTER :: qs_env
814 TYPE(pw_r3d_rs_type), INTENT(IN) :: vh_rspace
815 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: vxc_rspace, vtau_rspace, vadmm_rspace
816 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_hz, matrix_pz, matrix_pz_admm, &
817 matrix_wz
818 REAL(kind=dp), OPTIONAL :: zehartree, zexc, zexc_aux_fit
819 TYPE(pw_r3d_rs_type), DIMENSION(:), &
820 INTENT(INOUT), OPTIONAL :: rhopz_r
821 TYPE(qs_p_env_type), OPTIONAL :: p_env
822 TYPE(excited_energy_type), OPTIONAL, POINTER :: ex_env
823 LOGICAL, INTENT(IN), OPTIONAL :: debug
824
825 CHARACTER(LEN=*), PARAMETER :: routinen = 'response_force'
826
827 CHARACTER(LEN=default_string_length) :: basis_type
828 INTEGER :: handle, iounit, ispin, mspin, myfun, &
829 n_rep_hf, nao, nao_aux, natom, nder, &
830 nimages, nocc, nspins
831 INTEGER, DIMENSION(:, :, :), POINTER :: cell_to_index
832 LOGICAL :: debug_forces, debug_stress, distribute_fock_matrix, do_ex, do_hfx, gapw, gapw_xc, &
833 hfx_treat_lsd_in_core, resp_only, s_mstruct_changed, use_virial
834 REAL(kind=dp) :: eh1, ehartree, ekin_mol, eps_filter, &
835 eps_ppnl, exc, exc_aux_fit, fconv, &
836 focc, hartree_gs, hartree_t
837 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :) :: ftot1, ftot2, ftot3
838 REAL(kind=dp), DIMENSION(2) :: total_rho_gs, total_rho_t
839 REAL(kind=dp), DIMENSION(3) :: fodeb
840 REAL(kind=dp), DIMENSION(3, 3) :: h_stress, pv_loc, stdeb, sttot, sttot2
841 TYPE(admm_type), POINTER :: admm_env
842 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
843 TYPE(cell_type), POINTER :: cell
844 TYPE(cp_logger_type), POINTER :: logger
845 TYPE(dbcsr_distribution_type), POINTER :: dbcsr_dist
846 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_ht, matrix_pd, matrix_pza, &
847 matrix_s, mpa, scrm
848 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_h, matrix_p, mhd, mhx, mhy, mhz, &
849 mpd, mpz
850 TYPE(dbcsr_type), POINTER :: dbwork
851 TYPE(dft_control_type), POINTER :: dft_control
852 TYPE(hartree_local_type), POINTER :: hartree_local_gs, hartree_local_t
853 TYPE(hfx_type), DIMENSION(:, :), POINTER :: x_data
854 TYPE(kg_environment_type), POINTER :: kg_env
855 TYPE(local_rho_type), POINTER :: local_rho_set_f, local_rho_set_gs, &
856 local_rho_set_t, local_rho_set_vxc, &
857 local_rhoz_set_admm
858 TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
859 TYPE(mp_para_env_type), POINTER :: para_env
860 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
861 POINTER :: sab_aux_fit, sab_orb, sac_ae, sac_ppl, &
862 sap_ppnl
863 TYPE(oce_matrix_type), POINTER :: oce
864 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
865 TYPE(pw_c1d_gs_type) :: rho_tot_gspace, rho_tot_gspace_gs, rho_tot_gspace_t, &
866 rhoz_tot_gspace, v_hartree_gspace_gs, v_hartree_gspace_t, zv_hartree_gspace
867 TYPE(pw_c1d_gs_type), DIMENSION(:), POINTER :: rho_g_aux, rho_g_gs, rho_g_t, rhoz_g, &
868 rhoz_g_aux, rhoz_g_xc
869 TYPE(pw_c1d_gs_type), POINTER :: rho_core
870 TYPE(pw_env_type), POINTER :: pw_env
871 TYPE(pw_poisson_type), POINTER :: poisson_env
872 TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
873 TYPE(pw_r3d_rs_type) :: v_hartree_rspace_gs, v_hartree_rspace_t, &
874 vhxc_rspace, zv_hartree_rspace
875 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: rho_r_aux, rho_r_gs, rho_r_t, rhoz_r, &
876 rhoz_r_aux, rhoz_r_xc, tau_r_aux, &
877 tauz_r, tauz_r_xc, v_xc, v_xc_tau
878 TYPE(qs_force_type), DIMENSION(:), POINTER :: force
879 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
880 TYPE(qs_ks_env_type), POINTER :: ks_env
881 TYPE(qs_rho_type), POINTER :: rho, rho_aux_fit, rho_xc
882 TYPE(section_vals_type), POINTER :: hfx_section, xc_fun_section, xc_section
883 TYPE(task_list_type), POINTER :: task_list, task_list_aux_fit
884 TYPE(virial_type), POINTER :: virial
885
886 CALL timeset(routinen, handle)
887
888 IF (PRESENT(debug)) THEN
889 debug_forces = debug
890 debug_stress = debug
891 ELSE
892 debug_forces = .false.
893 debug_stress = .false.
894 END IF
895
896 logger => cp_get_default_logger()
897 logger => cp_get_default_logger()
898 IF (logger%para_env%is_source()) THEN
899 iounit = cp_logger_get_default_unit_nr(logger, local=.true.)
900 ELSE
901 iounit = -1
902 END IF
903
904 do_ex = .false.
905 IF (PRESENT(ex_env)) do_ex = .true.
906 IF (do_ex) THEN
907 cpassert(PRESENT(p_env))
908 END IF
909
910 NULLIFY (ks_env, sab_orb, sac_ae, sac_ppl, sap_ppnl, virial)
911 CALL get_qs_env(qs_env=qs_env, &
912 cell=cell, &
913 force=force, &
914 ks_env=ks_env, &
915 dft_control=dft_control, &
916 para_env=para_env, &
917 sab_orb=sab_orb, &
918 sac_ae=sac_ae, &
919 sac_ppl=sac_ppl, &
920 sap_ppnl=sap_ppnl, &
921 virial=virial)
922 nspins = dft_control%nspins
923 gapw = dft_control%qs_control%gapw
924 gapw_xc = dft_control%qs_control%gapw_xc
925
926 IF (debug_forces) THEN
927 CALL get_qs_env(qs_env, natom=natom, atomic_kind_set=atomic_kind_set)
928 ALLOCATE (ftot1(3, natom))
929 CALL total_qs_force(ftot1, force, atomic_kind_set)
930 END IF
931
932 ! check for virial
933 use_virial = virial%pv_availability .AND. (.NOT. virial%pv_numer)
934
935 IF (use_virial .AND. do_ex) THEN
936 CALL cp_abort(__location__, "Stress Tensor not available for TDDFT calculations.")
937 END IF
938
939 fconv = 1.0e-9_dp*pascal/cell%deth
940 IF (debug_stress .AND. use_virial) THEN
941 sttot = virial%pv_virial
942 END IF
943
944 ! *** If LSD, then combine alpha density and beta density to
945 ! *** total density: alpha <- alpha + beta and
946 NULLIFY (mpa)
947 NULLIFY (matrix_ht)
948 IF (do_ex) THEN
949 CALL dbcsr_allocate_matrix_set(mpa, nspins)
950 DO ispin = 1, nspins
951 ALLOCATE (mpa(ispin)%matrix)
952 CALL dbcsr_create(mpa(ispin)%matrix, template=p_env%p1(ispin)%matrix)
953 CALL dbcsr_copy(mpa(ispin)%matrix, p_env%p1(ispin)%matrix)
954 CALL dbcsr_add(mpa(ispin)%matrix, ex_env%matrix_pe(ispin)%matrix, 1.0_dp, 1.0_dp)
955 CALL dbcsr_set(matrix_hz(ispin)%matrix, 0.0_dp)
956 END DO
957
958 CALL dbcsr_allocate_matrix_set(matrix_ht, nspins)
959 DO ispin = 1, nspins
960 ALLOCATE (matrix_ht(ispin)%matrix)
961 CALL dbcsr_create(matrix_ht(ispin)%matrix, template=matrix_hz(ispin)%matrix)
962 CALL dbcsr_copy(matrix_ht(ispin)%matrix, matrix_hz(ispin)%matrix)
963 CALL dbcsr_set(matrix_ht(ispin)%matrix, 0.0_dp)
964 END DO
965 ELSE
966 mpa => matrix_pz
967 END IF
968 !
969 ! START OF Tr(P+Z)Hcore
970 !
971 IF (nspins == 2) THEN
972 CALL dbcsr_add(mpa(1)%matrix, mpa(2)%matrix, 1.0_dp, 1.0_dp)
973 END IF
974 nimages = 1
975
976 ! Kinetic energy matrix
977 NULLIFY (scrm)
978 IF (debug_forces) fodeb(1:3) = force(1)%kinetic(1:3, 1)
979 IF (debug_stress .AND. use_virial) stdeb = virial%pv_ekinetic
980 CALL build_kinetic_matrix(ks_env, matrix_t=scrm, &
981 matrix_name="KINETIC ENERGY MATRIX", &
982 basis_type="ORB", &
983 sab_nl=sab_orb, calculate_forces=.true., &
984 matrix_p=mpa(1)%matrix)
985 IF (debug_forces) THEN
986 fodeb(1:3) = force(1)%kinetic(1:3, 1) - fodeb(1:3)
987 CALL para_env%sum(fodeb)
988 IF (iounit > 0) WRITE (iounit, "(T3,A,T33,3F16.8)") "DEBUG:: Pz*dT ", fodeb
989 END IF
990 IF (debug_stress .AND. use_virial) THEN
991 stdeb = fconv*(virial%pv_ekinetic - stdeb)
992 CALL para_env%sum(stdeb)
993 IF (iounit > 0) WRITE (unit=iounit, fmt="(T2,A,T41,2(1X,ES19.11))") &
994 'STRESS| Kinetic energy', one_third_sum_diag(stdeb), det_3x3(stdeb)
995 END IF
996
997 IF (nspins == 2) THEN
998 CALL dbcsr_add(mpa(1)%matrix, mpa(2)%matrix, 1.0_dp, -1.0_dp)
999 END IF
1001
1002 ! Initialize a matrix scrm, later used for scratch purposes
1003 CALL get_qs_env(qs_env=qs_env, matrix_s=matrix_s)
1004 CALL dbcsr_allocate_matrix_set(scrm, nspins)
1005 DO ispin = 1, nspins
1006 ALLOCATE (scrm(ispin)%matrix)
1007 CALL dbcsr_create(scrm(ispin)%matrix, template=matrix_s(1)%matrix)
1008 CALL dbcsr_copy(scrm(ispin)%matrix, matrix_s(1)%matrix)
1009 CALL dbcsr_set(scrm(ispin)%matrix, 0.0_dp)
1010 END DO
1011
1012 CALL get_qs_env(qs_env, qs_kind_set=qs_kind_set, particle_set=particle_set, &
1013 atomic_kind_set=atomic_kind_set)
1014
1015 NULLIFY (cell_to_index)
1016 ALLOCATE (matrix_p(nspins, 1), matrix_h(nspins, 1))
1017 DO ispin = 1, nspins
1018 matrix_p(ispin, 1)%matrix => mpa(ispin)%matrix
1019 matrix_h(ispin, 1)%matrix => scrm(ispin)%matrix
1020 END DO
1021 matrix_h(1, 1)%matrix => scrm(1)%matrix
1022
1023 IF (ASSOCIATED(sac_ae)) THEN
1024 nder = 1
1025 IF (debug_forces) fodeb(1:3) = force(1)%all_potential(1:3, 1)
1026 IF (debug_stress .AND. use_virial) stdeb = virial%pv_ppl
1027 CALL build_core_ae(matrix_h, matrix_p, force, virial, .true., use_virial, nder, &
1028 qs_kind_set, atomic_kind_set, particle_set, sab_orb, sac_ae, &
1029 nimages, cell_to_index)
1030 IF (debug_forces) THEN
1031 fodeb(1:3) = force(1)%all_potential(1:3, 1) - fodeb(1:3)
1032 CALL para_env%sum(fodeb)
1033 IF (iounit > 0) WRITE (iounit, "(T3,A,T33,3F16.8)") "DEBUG:: Pz*dHae ", fodeb
1034 END IF
1035 IF (debug_stress .AND. use_virial) THEN
1036 stdeb = fconv*(virial%pv_ppl - stdeb)
1037 CALL para_env%sum(stdeb)
1038 IF (iounit > 0) WRITE (unit=iounit, fmt="(T2,A,T41,2(1X,ES19.11))") &
1039 'STRESS| Pz*dHae ', one_third_sum_diag(stdeb), det_3x3(stdeb)
1040 END IF
1041 END IF
1042
1043 IF (ASSOCIATED(sac_ppl)) THEN
1044 nder = 1
1045 IF (debug_forces) fodeb(1:3) = force(1)%gth_ppl(1:3, 1)
1046 IF (debug_stress .AND. use_virial) stdeb = virial%pv_ppl
1047 CALL build_core_ppl(matrix_h, matrix_p, force, &
1048 virial, .true., use_virial, nder, &
1049 qs_kind_set, atomic_kind_set, particle_set, &
1050 sab_orb, sac_ppl, nimages, cell_to_index, "ORB")
1051 IF (debug_forces) THEN
1052 fodeb(1:3) = force(1)%gth_ppl(1:3, 1) - fodeb(1:3)
1053 CALL para_env%sum(fodeb)
1054 IF (iounit > 0) WRITE (iounit, "(T3,A,T33,3F16.8)") "DEBUG:: Pz*dHppl ", fodeb
1055 END IF
1056 IF (debug_stress .AND. use_virial) THEN
1057 stdeb = fconv*(virial%pv_ppl - stdeb)
1058 CALL para_env%sum(stdeb)
1059 IF (iounit > 0) WRITE (unit=iounit, fmt="(T2,A,T41,2(1X,ES19.11))") &
1060 'STRESS| Pz*dHppl ', one_third_sum_diag(stdeb), det_3x3(stdeb)
1061 END IF
1062 END IF
1063 eps_ppnl = dft_control%qs_control%eps_ppnl
1064 IF (ASSOCIATED(sap_ppnl)) THEN
1065 nder = 1
1066 IF (debug_forces) fodeb(1:3) = force(1)%gth_ppnl(1:3, 1)
1067 IF (debug_stress .AND. use_virial) stdeb = virial%pv_ppnl
1068 CALL build_core_ppnl(matrix_h, matrix_p, force, &
1069 virial, .true., use_virial, nder, &
1070 qs_kind_set, atomic_kind_set, particle_set, &
1071 sab_orb, sap_ppnl, eps_ppnl, nimages, cell_to_index, "ORB")
1072 IF (debug_forces) THEN
1073 fodeb(1:3) = force(1)%gth_ppnl(1:3, 1) - fodeb(1:3)
1074 CALL para_env%sum(fodeb)
1075 IF (iounit > 0) WRITE (iounit, "(T3,A,T33,3F16.8)") "DEBUG:: Pz*dHppnl ", fodeb
1076 END IF
1077 IF (debug_stress .AND. use_virial) THEN
1078 stdeb = fconv*(virial%pv_ppnl - stdeb)
1079 CALL para_env%sum(stdeb)
1080 IF (iounit > 0) WRITE (unit=iounit, fmt="(T2,A,T41,2(1X,ES19.11))") &
1081 'STRESS| Pz*dHppnl ', one_third_sum_diag(stdeb), det_3x3(stdeb)
1082 END IF
1083
1084 END IF
1085 ! Kim-Gordon subsystem DFT
1086 ! Atomic potential for nonadditive kinetic energy contribution
1087 IF (dft_control%qs_control%do_kg) THEN
1088 IF (qs_env%kg_env%tnadd_method == kg_tnadd_atomic) THEN
1089 CALL get_qs_env(qs_env=qs_env, kg_env=kg_env, dbcsr_dist=dbcsr_dist)
1090
1091 IF (use_virial) THEN
1092 pv_loc = virial%pv_virial
1093 END IF
1094
1095 IF (debug_forces) fodeb(1:3) = force(1)%kinetic(1:3, 1)
1096 IF (debug_stress .AND. use_virial) stdeb = virial%pv_virial
1097 CALL build_tnadd_mat(kg_env=kg_env, matrix_p=matrix_p, force=force, virial=virial, &
1098 calculate_forces=.true., use_virial=use_virial, &
1099 qs_kind_set=qs_kind_set, atomic_kind_set=atomic_kind_set, &
1100 particle_set=particle_set, sab_orb=sab_orb, dbcsr_dist=dbcsr_dist)
1101 IF (debug_forces) THEN
1102 fodeb(1:3) = force(1)%kinetic(1:3, 1) - fodeb(1:3)
1103 CALL para_env%sum(fodeb)
1104 IF (iounit > 0) WRITE (iounit, "(T3,A,T33,3F16.8)") "DEBUG:: Pz*dTnadd ", fodeb
1105 END IF
1106 IF (debug_stress .AND. use_virial) THEN
1107 stdeb = fconv*(virial%pv_virial - stdeb)
1108 CALL para_env%sum(stdeb)
1109 IF (iounit > 0) WRITE (unit=iounit, fmt="(T2,A,T41,2(1X,ES19.11))") &
1110 'STRESS| Pz*dTnadd ', one_third_sum_diag(stdeb), det_3x3(stdeb)
1111 END IF
1112
1113 ! Stress-tensor update components
1114 IF (use_virial) THEN
1115 virial%pv_ekinetic = virial%pv_ekinetic + (virial%pv_virial - pv_loc)
1116 END IF
1117
1118 END IF
1119 END IF
1120
1121 DEALLOCATE (matrix_h)
1122 DEALLOCATE (matrix_p)
1124
1125 ! initialize src matrix
1126 ! Necessary as build_kinetic_matrix will only allocate scrm(1)
1127 ! and not scrm(2) in open-shell case
1128 NULLIFY (scrm)
1129 CALL dbcsr_allocate_matrix_set(scrm, nspins)
1130 DO ispin = 1, nspins
1131 ALLOCATE (scrm(ispin)%matrix)
1132 CALL dbcsr_create(scrm(ispin)%matrix, template=matrix_pz(1)%matrix)
1133 CALL dbcsr_copy(scrm(ispin)%matrix, matrix_pz(ispin)%matrix)
1134 CALL dbcsr_set(scrm(ispin)%matrix, 0.0_dp)
1135 END DO
1136
1137 IF (debug_forces) THEN
1138 ALLOCATE (ftot2(3, natom))
1139 CALL total_qs_force(ftot2, force, atomic_kind_set)
1140 fodeb(1:3) = ftot2(1:3, 1) - ftot1(1:3, 1)
1141 CALL para_env%sum(fodeb)
1142 IF (iounit > 0) WRITE (iounit, "(T3,A,T33,3F16.8)") "DEBUG:: Pz*dHcore", fodeb
1143 END IF
1144 IF (debug_stress .AND. use_virial) THEN
1145 stdeb = fconv*(virial%pv_virial - sttot)
1146 CALL para_env%sum(stdeb)
1147 IF (iounit > 0) WRITE (unit=iounit, fmt="(T2,A,T41,2(1X,ES19.11))") &
1148 'STRESS| Stress Pz*dHcore ', one_third_sum_diag(stdeb), det_3x3(stdeb)
1149 ! save current total viral, does not contain volume terms yet
1150 sttot2 = virial%pv_virial
1151 END IF
1152 !
1153 ! END OF Tr(P+Z)Hcore
1154 !
1155 !
1156 ! Vhxc (KS potentials calculated externally)
1157 CALL get_qs_env(qs_env, pw_env=pw_env)
1158 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool, poisson_env=poisson_env)
1159 !
1160 IF (dft_control%do_admm) THEN
1161 CALL get_qs_env(qs_env, admm_env=admm_env)
1162 xc_section => admm_env%xc_section_primary
1163 ELSE
1164 xc_section => section_vals_get_subs_vals(qs_env%input, "DFT%XC")
1165 END IF
1166 xc_fun_section => section_vals_get_subs_vals(xc_section, "XC_FUNCTIONAL")
1167 CALL section_vals_val_get(xc_fun_section, "_SECTION_PARAMETERS_", i_val=myfun)
1168 !
1169 IF (gapw .OR. gapw_xc) THEN
1170 NULLIFY (oce, sab_orb)
1171 CALL get_qs_env(qs_env=qs_env, oce=oce, sab_orb=sab_orb)
1172 ! set up local_rho_set for GS density
1173 NULLIFY (local_rho_set_gs)
1174 CALL get_qs_env(qs_env=qs_env, rho=rho)
1175 CALL qs_rho_get(rho, rho_ao_kp=matrix_p)
1176 CALL local_rho_set_create(local_rho_set_gs)
1177 CALL allocate_rho_atom_internals(local_rho_set_gs%rho_atom_set, atomic_kind_set, &
1178 qs_kind_set, dft_control, para_env)
1179 CALL init_rho0(local_rho_set_gs, qs_env, dft_control%qs_control%gapw_control)
1180 CALL rho0_s_grid_create(pw_env, local_rho_set_gs%rho0_mpole)
1181 CALL calculate_rho_atom_coeff(qs_env, matrix_p(:, 1), local_rho_set_gs%rho_atom_set, &
1182 qs_kind_set, oce, sab_orb, para_env)
1183 CALL prepare_gapw_den(qs_env, local_rho_set_gs, do_rho0=gapw)
1184 ! set up local_rho_set for response density
1185 NULLIFY (local_rho_set_t)
1186 CALL local_rho_set_create(local_rho_set_t)
1187 CALL allocate_rho_atom_internals(local_rho_set_t%rho_atom_set, atomic_kind_set, &
1188 qs_kind_set, dft_control, para_env)
1189 CALL init_rho0(local_rho_set_t, qs_env, dft_control%qs_control%gapw_control, &
1190 zcore=0.0_dp)
1191 CALL rho0_s_grid_create(pw_env, local_rho_set_t%rho0_mpole)
1192 CALL calculate_rho_atom_coeff(qs_env, mpa(:), local_rho_set_t%rho_atom_set, &
1193 qs_kind_set, oce, sab_orb, para_env)
1194 CALL prepare_gapw_den(qs_env, local_rho_set_t, do_rho0=gapw)
1195
1196 ! compute soft GS potential
1197 ALLOCATE (rho_r_gs(nspins), rho_g_gs(nspins))
1198 DO ispin = 1, nspins
1199 CALL auxbas_pw_pool%create_pw(rho_r_gs(ispin))
1200 CALL auxbas_pw_pool%create_pw(rho_g_gs(ispin))
1201 END DO
1202 CALL auxbas_pw_pool%create_pw(rho_tot_gspace_gs)
1203 ! compute soft GS density
1204 total_rho_gs = 0.0_dp
1205 CALL pw_zero(rho_tot_gspace_gs)
1206 DO ispin = 1, nspins
1207 CALL calculate_rho_elec(ks_env=ks_env, matrix_p=matrix_p(ispin, 1)%matrix, &
1208 rho=rho_r_gs(ispin), &
1209 rho_gspace=rho_g_gs(ispin), &
1210 soft_valid=(gapw .OR. gapw_xc), &
1211 total_rho=total_rho_gs(ispin))
1212 CALL pw_axpy(rho_g_gs(ispin), rho_tot_gspace_gs)
1213 END DO
1214 IF (gapw) THEN
1215 CALL get_qs_env(qs_env, natom=natom)
1216 ! add rho0 contributions to GS density (only for Coulomb) only for gapw
1217 CALL pw_axpy(local_rho_set_gs%rho0_mpole%rho0_s_gs, rho_tot_gspace_gs)
1218 IF (dft_control%qs_control%gapw_control%nopaw_as_gpw) THEN
1219 CALL get_qs_env(qs_env=qs_env, rho_core=rho_core)
1220 CALL pw_axpy(rho_core, rho_tot_gspace_gs)
1221 END IF
1222 ! compute GS potential
1223 CALL auxbas_pw_pool%create_pw(v_hartree_gspace_gs)
1224 CALL auxbas_pw_pool%create_pw(v_hartree_rspace_gs)
1225 NULLIFY (hartree_local_gs)
1226 CALL hartree_local_create(hartree_local_gs)
1227 CALL init_coulomb_local(hartree_local_gs, natom)
1228 CALL pw_poisson_solve(poisson_env, rho_tot_gspace_gs, hartree_gs, v_hartree_gspace_gs)
1229 CALL pw_transfer(v_hartree_gspace_gs, v_hartree_rspace_gs)
1230 CALL pw_scale(v_hartree_rspace_gs, v_hartree_rspace_gs%pw_grid%dvol)
1231 END IF
1232 END IF
1233
1234 IF (gapw) THEN
1235 ! Hartree grid PAW term
1236 cpassert(do_ex)
1237 cpassert(.NOT. use_virial)
1238 IF (debug_forces) fodeb(1:3) = force(1)%g0s_Vh_elec(1:3, 1)
1239 CALL vh_1c_gg_integrals(qs_env, hartree_gs, hartree_local_gs%ecoul_1c, local_rho_set_t, para_env, tddft=.true., &
1240 local_rho_set_2nd=local_rho_set_gs, core_2nd=.false.) ! n^core for GS potential
1241 ! 1st to define integral space, 2nd for potential, integral contributions stored on local_rho_set_gs
1242 CALL integrate_vhg0_rspace(qs_env, v_hartree_rspace_gs, para_env, calculate_forces=.true., &
1243 local_rho_set=local_rho_set_t, local_rho_set_2nd=local_rho_set_gs)
1244 IF (debug_forces) THEN
1245 fodeb(1:3) = force(1)%g0s_Vh_elec(1:3, 1) - fodeb(1:3)
1246 CALL para_env%sum(fodeb)
1247 IF (iounit > 0) WRITE (iounit, "(T3,A,T33,3F16.8)") "DEBUG:: (T+Dz)*dVh[D^GS]PAWg0", fodeb
1248 END IF
1249 END IF
1250 IF (gapw .OR. gapw_xc) THEN
1251 IF (myfun /= xc_none) THEN
1252 ! add 1c hard and soft XC contributions
1253 NULLIFY (local_rho_set_vxc)
1254 CALL local_rho_set_create(local_rho_set_vxc)
1255 CALL allocate_rho_atom_internals(local_rho_set_vxc%rho_atom_set, atomic_kind_set, &
1256 qs_kind_set, dft_control, para_env)
1257 CALL calculate_rho_atom_coeff(qs_env, matrix_p(:, 1), local_rho_set_vxc%rho_atom_set, &
1258 qs_kind_set, oce, sab_orb, para_env)
1259 CALL prepare_gapw_den(qs_env, local_rho_set_vxc, do_rho0=.false.)
1260 ! compute hard and soft atomic contributions
1261 CALL calculate_vxc_atom(qs_env, .false., exc1=hartree_gs, xc_section_external=xc_section, &
1262 rho_atom_set_external=local_rho_set_vxc%rho_atom_set)
1263 END IF ! myfun
1264 END IF ! gapw
1265
1266 CALL auxbas_pw_pool%create_pw(vhxc_rspace)
1267 !
1268 ! Stress-tensor: integration contribution direct term
1269 ! int v_Hxc[n^in]*n^z
1270 IF (use_virial) THEN
1271 pv_loc = virial%pv_virial
1272 END IF
1273
1274 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
1275 IF (debug_stress .AND. use_virial) stdeb = virial%pv_virial
1276 IF (gapw .OR. gapw_xc) THEN
1277 ! vtot = v_xc + v_hartree
1278 DO ispin = 1, nspins
1279 CALL pw_zero(vhxc_rspace)
1280 IF (gapw) THEN
1281 CALL pw_transfer(v_hartree_rspace_gs, vhxc_rspace)
1282 ELSEIF (gapw_xc) THEN
1283 CALL pw_transfer(vh_rspace, vhxc_rspace)
1284 END IF
1285 CALL integrate_v_rspace(v_rspace=vhxc_rspace, &
1286 hmat=scrm(ispin), pmat=mpa(ispin), &
1287 qs_env=qs_env, gapw=gapw, &
1288 calculate_forces=.true.)
1289 END DO
1290 IF (myfun /= xc_none) THEN
1291 DO ispin = 1, nspins
1292 CALL pw_zero(vhxc_rspace)
1293 CALL pw_axpy(vxc_rspace(ispin), vhxc_rspace)
1294 CALL integrate_v_rspace(v_rspace=vhxc_rspace, &
1295 hmat=scrm(ispin), pmat=mpa(ispin), &
1296 qs_env=qs_env, gapw=(gapw .OR. gapw_xc), &
1297 calculate_forces=.true.)
1298 END DO
1299 END IF
1300 ELSE ! original GPW with Standard Hartree as Potential
1301 DO ispin = 1, nspins
1302 CALL pw_transfer(vh_rspace, vhxc_rspace)
1303 CALL pw_axpy(vxc_rspace(ispin), vhxc_rspace)
1304 CALL integrate_v_rspace(v_rspace=vhxc_rspace, &
1305 hmat=scrm(ispin), pmat=mpa(ispin), &
1306 qs_env=qs_env, gapw=gapw, calculate_forces=.true.)
1307 END DO
1308 END IF
1309
1310 IF (debug_forces) THEN
1311 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
1312 CALL para_env%sum(fodeb)
1313 IF (iounit > 0) WRITE (iounit, "(T3,A,T33,3F16.8)") "DEBUG:: (T+Dz)*dVhxc[D^GS] ", fodeb
1314 END IF
1315 IF (debug_stress .AND. use_virial) THEN
1316 stdeb = fconv*(virial%pv_virial - pv_loc)
1317 CALL para_env%sum(stdeb)
1318 IF (iounit > 0) WRITE (unit=iounit, fmt="(T2,A,T41,2(1X,ES19.11))") &
1319 'STRESS| INT Pz*dVhxc ', one_third_sum_diag(stdeb), det_3x3(stdeb)
1320 END IF
1321
1322 IF (gapw .OR. gapw_xc) THEN
1323 cpassert(do_ex)
1324 ! HXC term
1325 IF (debug_forces) fodeb(1:3) = force(1)%Vhxc_atom(1:3, 1)
1326 IF (gapw) CALL update_ks_atom(qs_env, scrm, mpa, forces=.true., tddft=.false., &
1327 rho_atom_external=local_rho_set_gs%rho_atom_set)
1328 IF (myfun /= xc_none) CALL update_ks_atom(qs_env, scrm, mpa, forces=.true., tddft=.false., &
1329 rho_atom_external=local_rho_set_vxc%rho_atom_set)
1330 IF (debug_forces) THEN
1331 fodeb(1:3) = force(1)%Vhxc_atom(1:3, 1) - fodeb(1:3)
1332 CALL para_env%sum(fodeb)
1333 IF (iounit > 0) WRITE (iounit, "(T3,A,T33,3F16.8)") "DEBUG:: (T+Dz)*dVhxc[D^GS]PAW ", fodeb
1334 END IF
1335 ! release local environments for GAPW
1336 IF (myfun /= xc_none) THEN
1337 IF (ASSOCIATED(local_rho_set_vxc)) CALL local_rho_set_release(local_rho_set_vxc)
1338 END IF
1339 IF (ASSOCIATED(local_rho_set_gs)) CALL local_rho_set_release(local_rho_set_gs)
1340 IF (gapw) THEN
1341 IF (ASSOCIATED(hartree_local_gs)) CALL hartree_local_release(hartree_local_gs)
1342 CALL auxbas_pw_pool%give_back_pw(v_hartree_gspace_gs)
1343 CALL auxbas_pw_pool%give_back_pw(v_hartree_rspace_gs)
1344 END IF
1345 CALL auxbas_pw_pool%give_back_pw(rho_tot_gspace_gs)
1346 IF (ASSOCIATED(rho_r_gs)) THEN
1347 DO ispin = 1, nspins
1348 CALL auxbas_pw_pool%give_back_pw(rho_r_gs(ispin))
1349 END DO
1350 DEALLOCATE (rho_r_gs)
1351 END IF
1352 IF (ASSOCIATED(rho_g_gs)) THEN
1353 DO ispin = 1, nspins
1354 CALL auxbas_pw_pool%give_back_pw(rho_g_gs(ispin))
1355 END DO
1356 DEALLOCATE (rho_g_gs)
1357 END IF
1358 END IF !gapw
1359
1360 IF (ASSOCIATED(vtau_rspace)) THEN
1361 cpassert(.NOT. (gapw .OR. gapw_xc))
1362 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
1363 IF (debug_stress .AND. use_virial) stdeb = virial%pv_virial
1364 DO ispin = 1, nspins
1365 CALL integrate_v_rspace(v_rspace=vtau_rspace(ispin), &
1366 hmat=scrm(ispin), pmat=mpa(ispin), &
1367 qs_env=qs_env, gapw=(gapw .OR. gapw_xc), &
1368 calculate_forces=.true., compute_tau=.true.)
1369 END DO
1370 IF (debug_forces) THEN
1371 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
1372 CALL para_env%sum(fodeb)
1373 IF (iounit > 0) WRITE (iounit, "(T3,A,T33,3F16.8)") "DEBUG:: Pz*dVxc_tau ", fodeb
1374 END IF
1375 IF (debug_stress .AND. use_virial) THEN
1376 stdeb = fconv*(virial%pv_virial - pv_loc)
1377 CALL para_env%sum(stdeb)
1378 IF (iounit > 0) WRITE (unit=iounit, fmt="(T2,A,T41,2(1X,ES19.11))") &
1379 'STRESS| INT Pz*dVxc_tau ', one_third_sum_diag(stdeb), det_3x3(stdeb)
1380 END IF
1381 END IF
1382 CALL auxbas_pw_pool%give_back_pw(vhxc_rspace)
1383
1384 ! Stress-tensor Pz*v_Hxc[Pin]
1385 IF (use_virial) THEN
1386 virial%pv_ehartree = virial%pv_ehartree + (virial%pv_virial - pv_loc)
1387 END IF
1388
1389 ! KG Embedding
1390 ! calculate kinetic energy potential and integrate with response density
1391 IF (dft_control%qs_control%do_kg) THEN
1392 IF (qs_env%kg_env%tnadd_method == kg_tnadd_embed .OR. &
1393 qs_env%kg_env%tnadd_method == kg_tnadd_embed_ri) THEN
1394
1395 ekin_mol = 0.0_dp
1396 IF (use_virial) THEN
1397 pv_loc = virial%pv_virial
1398 END IF
1399
1400 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
1401 CALL kg_ekin_subset(qs_env=qs_env, &
1402 ks_matrix=scrm, &
1403 ekin_mol=ekin_mol, &
1404 calc_force=.true., &
1405 do_kernel=.false., &
1406 pmat_ext=mpa)
1407 IF (debug_forces) THEN
1408 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
1409 CALL para_env%sum(fodeb)
1410 IF (iounit > 0) WRITE (iounit, "(T3,A,T33,3F16.8)") "DEBUG:: Pz*dVkg ", fodeb
1411 END IF
1412 IF (debug_stress .AND. use_virial) THEN
1413 !IF (iounit > 0) WRITE(iounit, *) &
1414 ! "response_force | VOL 1st KG - v_KG[n_in]*n_z: ", ekin_mol
1415 stdeb = 1.0_dp*fconv*ekin_mol
1416 IF (iounit > 0) WRITE (unit=iounit, fmt="(T2,A,T41,2(1X,ES19.11))") &
1417 'STRESS| VOL KG Pz*dVKG ', one_third_sum_diag(stdeb), det_3x3(stdeb)
1418
1419 stdeb = fconv*(virial%pv_virial - pv_loc)
1420 CALL para_env%sum(stdeb)
1421 IF (iounit > 0) WRITE (unit=iounit, fmt="(T2,A,T41,2(1X,ES19.11))") &
1422 'STRESS| INT KG Pz*dVKG ', one_third_sum_diag(stdeb), det_3x3(stdeb)
1423
1424 stdeb = fconv*virial%pv_xc
1425 CALL para_env%sum(stdeb)
1426 IF (iounit > 0) WRITE (unit=iounit, fmt="(T2,A,T41,2(1X,ES19.11))") &
1427 'STRESS| GGA KG Pz*dVKG ', one_third_sum_diag(stdeb), det_3x3(stdeb)
1428 END IF
1429 IF (use_virial) THEN
1430 ! Direct integral contribution
1431 virial%pv_ehartree = virial%pv_ehartree + (virial%pv_virial - pv_loc)
1432 END IF
1433
1434 END IF ! tnadd_method
1435 END IF ! do_kg
1436
1438
1439 !
1440 ! Hartree potential of response density
1441 !
1442 ALLOCATE (rhoz_r(nspins), rhoz_g(nspins))
1443 DO ispin = 1, nspins
1444 CALL auxbas_pw_pool%create_pw(rhoz_r(ispin))
1445 CALL auxbas_pw_pool%create_pw(rhoz_g(ispin))
1446 END DO
1447 CALL auxbas_pw_pool%create_pw(rhoz_tot_gspace)
1448 CALL auxbas_pw_pool%create_pw(zv_hartree_rspace)
1449 CALL auxbas_pw_pool%create_pw(zv_hartree_gspace)
1450
1451 CALL pw_zero(rhoz_tot_gspace)
1452 DO ispin = 1, nspins
1453 CALL calculate_rho_elec(ks_env=ks_env, matrix_p=mpa(ispin)%matrix, &
1454 rho=rhoz_r(ispin), rho_gspace=rhoz_g(ispin), &
1455 soft_valid=gapw)
1456 CALL pw_axpy(rhoz_g(ispin), rhoz_tot_gspace)
1457 END DO
1458 IF (gapw_xc) THEN
1459 NULLIFY (tauz_r_xc)
1460 ALLOCATE (rhoz_r_xc(nspins), rhoz_g_xc(nspins))
1461 DO ispin = 1, nspins
1462 CALL auxbas_pw_pool%create_pw(rhoz_r_xc(ispin))
1463 CALL auxbas_pw_pool%create_pw(rhoz_g_xc(ispin))
1464 END DO
1465 DO ispin = 1, nspins
1466 CALL calculate_rho_elec(ks_env=ks_env, matrix_p=mpa(ispin)%matrix, &
1467 rho=rhoz_r_xc(ispin), rho_gspace=rhoz_g_xc(ispin), &
1468 soft_valid=gapw_xc)
1469 END DO
1470 END IF
1471
1472 IF (ASSOCIATED(vtau_rspace)) THEN
1473 cpassert(.NOT. (gapw .OR. gapw_xc))
1474 block
1475 TYPE(pw_c1d_gs_type) :: work_g
1476 ALLOCATE (tauz_r(nspins))
1477 CALL auxbas_pw_pool%create_pw(work_g)
1478 DO ispin = 1, nspins
1479 CALL auxbas_pw_pool%create_pw(tauz_r(ispin))
1480 CALL calculate_rho_elec(ks_env=ks_env, matrix_p=mpa(ispin)%matrix, &
1481 rho=tauz_r(ispin), rho_gspace=work_g, &
1482 compute_tau=.true.)
1483 END DO
1484 CALL auxbas_pw_pool%give_back_pw(work_g)
1485 END block
1486 END IF
1487
1488 !
1489 IF (PRESENT(rhopz_r)) THEN
1490 DO ispin = 1, nspins
1491 CALL pw_copy(rhoz_r(ispin), rhopz_r(ispin))
1492 END DO
1493 END IF
1494
1495 ! Stress-tensor contribution second derivative
1496 ! Volume : int v_H[n^z]*n_in
1497 ! Volume : int epsilon_xc*n_z
1498 IF (use_virial) THEN
1499
1500 CALL get_qs_env(qs_env, rho=rho)
1501 CALL auxbas_pw_pool%create_pw(rho_tot_gspace)
1502
1503 ! Get the total input density in g-space [ions + electrons]
1504 CALL calc_rho_tot_gspace(rho_tot_gspace, qs_env, rho)
1505
1506 h_stress(:, :) = 0.0_dp
1507 ! calculate associated hartree potential
1508 ! This term appears twice in the derivation of the equations
1509 ! v_H[n_in]*n_z and v_H[n_z]*n_in
1510 ! due to symmetry we only need to call this routine once,
1511 ! and count the Volume and Green function contribution
1512 ! which is stored in h_stress twice
1513 CALL pw_poisson_solve(poisson_env, &
1514 density=rhoz_tot_gspace, & ! n_z
1515 ehartree=ehartree, &
1516 vhartree=zv_hartree_gspace, & ! v_H[n_z]
1517 h_stress=h_stress, &
1518 aux_density=rho_tot_gspace) ! n_in
1519
1520 CALL auxbas_pw_pool%give_back_pw(rho_tot_gspace)
1521
1522 ! Stress tensor Green function contribution
1523 virial%pv_ehartree = virial%pv_ehartree + 2.0_dp*h_stress/real(para_env%num_pe, dp)
1524 virial%pv_virial = virial%pv_virial + 2.0_dp*h_stress/real(para_env%num_pe, dp)
1525
1526 IF (debug_stress) THEN
1527 stdeb = -1.0_dp*fconv*ehartree
1528 IF (iounit > 0) WRITE (unit=iounit, fmt="(T2,A,T41,2(1X,ES19.11))") &
1529 'STRESS| VOL 1st v_H[n_z]*n_in ', one_third_sum_diag(stdeb), det_3x3(stdeb)
1530 stdeb = -1.0_dp*fconv*ehartree
1531 IF (iounit > 0) WRITE (unit=iounit, fmt="(T2,A,T41,2(1X,ES19.11))") &
1532 'STRESS| VOL 2nd v_H[n_in]*n_z ', one_third_sum_diag(stdeb), det_3x3(stdeb)
1533 stdeb = fconv*(h_stress/real(para_env%num_pe, dp))
1534 CALL para_env%sum(stdeb)
1535 IF (iounit > 0) WRITE (unit=iounit, fmt="(T2,A,T41,2(1X,ES19.11))") &
1536 'STRESS| GREEN 1st v_H[n_z]*n_in ', one_third_sum_diag(stdeb), det_3x3(stdeb)
1537 stdeb = fconv*(h_stress/real(para_env%num_pe, dp))
1538 CALL para_env%sum(stdeb)
1539 IF (iounit > 0) WRITE (unit=iounit, fmt="(T2,A,T41,2(1X,ES19.11))") &
1540 'STRESS| GREEN 2nd v_H[n_in]*n_z ', one_third_sum_diag(stdeb), det_3x3(stdeb)
1541 END IF
1542
1543 ! Stress tensor volume term: \int v_xc[n_in]*n_z
1544 ! vxc_rspace already scaled, we need to unscale it!
1545 exc = 0.0_dp
1546 DO ispin = 1, nspins
1547 exc = exc + pw_integral_ab(rhoz_r(ispin), vxc_rspace(ispin))/ &
1548 vxc_rspace(ispin)%pw_grid%dvol
1549 END DO
1550 IF (ASSOCIATED(vtau_rspace)) THEN
1551 DO ispin = 1, nspins
1552 exc = exc + pw_integral_ab(tauz_r(ispin), vtau_rspace(ispin))/ &
1553 vtau_rspace(ispin)%pw_grid%dvol
1554 END DO
1555 END IF
1556
1557 ! Add KG embedding correction
1558 IF (dft_control%qs_control%do_kg) THEN
1559 IF (qs_env%kg_env%tnadd_method == kg_tnadd_embed .OR. &
1560 qs_env%kg_env%tnadd_method == kg_tnadd_embed_ri) THEN
1561 exc = exc - ekin_mol
1562 END IF
1563 END IF
1564
1565 IF (debug_stress) THEN
1566 stdeb = -1.0_dp*fconv*exc
1567 IF (iounit > 0) WRITE (unit=iounit, fmt="(T2,A,T41,2(1X,ES19.11))") &
1568 'STRESS| VOL 1st eps_XC[n_in]*n_z', one_third_sum_diag(stdeb), det_3x3(stdeb)
1569 END IF
1570
1571 ELSE ! use_virial
1572
1573 ! calculate associated hartree potential
1574 ! contribution for both T and D^Z
1575 IF (gapw) THEN
1576 CALL pw_axpy(local_rho_set_t%rho0_mpole%rho0_s_gs, rhoz_tot_gspace)
1577 END IF
1578 CALL pw_poisson_solve(poisson_env, rhoz_tot_gspace, ehartree, zv_hartree_gspace)
1579
1580 END IF ! use virial
1581 IF (gapw .OR. gapw_xc) THEN
1582 IF (ASSOCIATED(local_rho_set_t)) CALL local_rho_set_release(local_rho_set_t)
1583 END IF
1584
1585 IF (debug_forces) fodeb(1:3) = force(1)%rho_core(1:3, 1)
1586 IF (debug_stress .AND. use_virial) stdeb = virial%pv_ehartree
1587 CALL pw_transfer(zv_hartree_gspace, zv_hartree_rspace)
1588 CALL pw_scale(zv_hartree_rspace, zv_hartree_rspace%pw_grid%dvol)
1589 ! Getting nuclear force contribution from the core charge density (not for GAPW)
1590 CALL integrate_v_core_rspace(zv_hartree_rspace, qs_env)
1591 IF (debug_forces) THEN
1592 fodeb(1:3) = force(1)%rho_core(1:3, 1) - fodeb(1:3)
1593 CALL para_env%sum(fodeb)
1594 IF (iounit > 0) WRITE (iounit, "(T3,A,T33,3F16.8)") "DEBUG:: Vh(rhoz)*dncore ", fodeb
1595 END IF
1596 IF (debug_stress .AND. use_virial) THEN
1597 stdeb = fconv*(virial%pv_ehartree - stdeb)
1598 CALL para_env%sum(stdeb)
1599 IF (iounit > 0) WRITE (unit=iounit, fmt="(T2,A,T41,2(1X,ES19.11))") &
1600 'STRESS| INT Vh(rhoz)*dncore ', one_third_sum_diag(stdeb), det_3x3(stdeb)
1601 END IF
1602
1603 !
1604 IF (gapw_xc) THEN
1605 CALL get_qs_env(qs_env=qs_env, rho_xc=rho_xc)
1606 ELSE
1607 CALL get_qs_env(qs_env=qs_env, rho=rho)
1608 END IF
1609 IF (dft_control%do_admm) THEN
1610 CALL get_qs_env(qs_env, admm_env=admm_env)
1611 xc_section => admm_env%xc_section_primary
1612 ELSE
1613 xc_section => section_vals_get_subs_vals(qs_env%input, "DFT%XC")
1614 END IF
1615
1616 IF (use_virial) THEN
1617 virial%pv_xc = 0.0_dp
1618 END IF
1619 !
1620 NULLIFY (v_xc, v_xc_tau)
1621 IF (gapw_xc) THEN
1622 CALL create_kernel(qs_env, vxc=v_xc, vxc_tau=v_xc_tau, &
1623 rho=rho_xc, rho1_r=rhoz_r_xc, rho1_g=rhoz_g_xc, tau1_r=tauz_r_xc, &
1624 xc_section=xc_section, compute_virial=use_virial, virial_xc=virial%pv_xc)
1625 ELSE
1626 CALL create_kernel(qs_env, vxc=v_xc, vxc_tau=v_xc_tau, &
1627 rho=rho, rho1_r=rhoz_r, rho1_g=rhoz_g, tau1_r=tauz_r, &
1628 xc_section=xc_section, compute_virial=use_virial, virial_xc=virial%pv_xc)
1629 END IF
1630
1631 IF (gapw .OR. gapw_xc) THEN
1632 !get local_rho_set for GS density and response potential / density
1633 NULLIFY (local_rho_set_t)
1634 CALL local_rho_set_create(local_rho_set_t)
1635 CALL allocate_rho_atom_internals(local_rho_set_t%rho_atom_set, atomic_kind_set, &
1636 qs_kind_set, dft_control, para_env)
1637 CALL init_rho0(local_rho_set_t, qs_env, dft_control%qs_control%gapw_control, &
1638 zcore=0.0_dp)
1639 CALL rho0_s_grid_create(pw_env, local_rho_set_t%rho0_mpole)
1640 CALL calculate_rho_atom_coeff(qs_env, mpa(:), local_rho_set_t%rho_atom_set, &
1641 qs_kind_set, oce, sab_orb, para_env)
1642 CALL prepare_gapw_den(qs_env, local_rho_set_t, do_rho0=gapw)
1643 NULLIFY (local_rho_set_gs)
1644 CALL local_rho_set_create(local_rho_set_gs)
1645 CALL allocate_rho_atom_internals(local_rho_set_gs%rho_atom_set, atomic_kind_set, &
1646 qs_kind_set, dft_control, para_env)
1647 CALL init_rho0(local_rho_set_gs, qs_env, dft_control%qs_control%gapw_control)
1648 CALL rho0_s_grid_create(pw_env, local_rho_set_gs%rho0_mpole)
1649 CALL calculate_rho_atom_coeff(qs_env, matrix_p(:, 1), local_rho_set_gs%rho_atom_set, &
1650 qs_kind_set, oce, sab_orb, para_env)
1651 CALL prepare_gapw_den(qs_env, local_rho_set_gs, do_rho0=gapw)
1652 ! compute response potential
1653 ALLOCATE (rho_r_t(nspins), rho_g_t(nspins))
1654 DO ispin = 1, nspins
1655 CALL auxbas_pw_pool%create_pw(rho_r_t(ispin))
1656 CALL auxbas_pw_pool%create_pw(rho_g_t(ispin))
1657 END DO
1658 CALL auxbas_pw_pool%create_pw(rho_tot_gspace_t)
1659 total_rho_t = 0.0_dp
1660 CALL pw_zero(rho_tot_gspace_t)
1661 DO ispin = 1, nspins
1662 CALL calculate_rho_elec(ks_env=ks_env, matrix_p=mpa(ispin)%matrix, &
1663 rho=rho_r_t(ispin), &
1664 rho_gspace=rho_g_t(ispin), &
1665 soft_valid=gapw, &
1666 total_rho=total_rho_t(ispin))
1667 CALL pw_axpy(rho_g_t(ispin), rho_tot_gspace_t)
1668 END DO
1669 ! add rho0 contributions to response density (only for Coulomb) only for gapw
1670 IF (gapw) THEN
1671 CALL pw_axpy(local_rho_set_t%rho0_mpole%rho0_s_gs, rho_tot_gspace_t)
1672 ! compute response Coulomb potential
1673 CALL auxbas_pw_pool%create_pw(v_hartree_gspace_t)
1674 CALL auxbas_pw_pool%create_pw(v_hartree_rspace_t)
1675 NULLIFY (hartree_local_t)
1676 CALL hartree_local_create(hartree_local_t)
1677 CALL init_coulomb_local(hartree_local_t, natom)
1678 CALL pw_poisson_solve(poisson_env, rho_tot_gspace_t, hartree_t, v_hartree_gspace_t)
1679 CALL pw_transfer(v_hartree_gspace_t, v_hartree_rspace_t)
1680 CALL pw_scale(v_hartree_rspace_t, v_hartree_rspace_t%pw_grid%dvol)
1681 !
1682 IF (debug_forces) fodeb(1:3) = force(1)%g0s_Vh_elec(1:3, 1)
1683 CALL vh_1c_gg_integrals(qs_env, hartree_t, hartree_local_t%ecoul_1c, local_rho_set_gs, para_env, tddft=.false., &
1684 local_rho_set_2nd=local_rho_set_t, core_2nd=.true.) ! n^core for GS potential
1685 CALL integrate_vhg0_rspace(qs_env, v_hartree_rspace_t, para_env, calculate_forces=.true., &
1686 local_rho_set=local_rho_set_gs, local_rho_set_2nd=local_rho_set_t)
1687 IF (debug_forces) THEN
1688 fodeb(1:3) = force(1)%g0s_Vh_elec(1:3, 1) - fodeb(1:3)
1689 CALL para_env%sum(fodeb)
1690 IF (iounit > 0) WRITE (iounit, "(T3,A,T33,3F16.8)") "DEBUG:: Vh(T)*dncore PAWg0", fodeb
1691 END IF
1692 END IF !gapw
1693 END IF !gapw
1694
1695 IF (gapw .OR. gapw_xc) THEN
1696 !GAPW compute atomic fxc contributions
1697 IF (myfun /= xc_none) THEN
1698 ! local_rho_set_f
1699 NULLIFY (local_rho_set_f)
1700 CALL local_rho_set_create(local_rho_set_f)
1701 CALL allocate_rho_atom_internals(local_rho_set_f%rho_atom_set, atomic_kind_set, &
1702 qs_kind_set, dft_control, para_env)
1703 CALL calculate_rho_atom_coeff(qs_env, mpa, local_rho_set_f%rho_atom_set, &
1704 qs_kind_set, oce, sab_orb, para_env)
1705 CALL prepare_gapw_den(qs_env, local_rho_set_f, do_rho0=.false.)
1706 ! add hard and soft atomic contributions
1707 CALL calculate_xc_2nd_deriv_atom(local_rho_set_gs%rho_atom_set, &
1708 local_rho_set_f%rho_atom_set, &
1709 qs_env, xc_section, para_env, &
1710 do_tddft=.false., do_triplet=.false.)
1711 END IF ! myfun
1712 END IF
1713
1714 ! Stress-tensor XC-kernel GGA contribution
1715 IF (use_virial) THEN
1716 virial%pv_exc = virial%pv_exc + virial%pv_xc
1717 virial%pv_virial = virial%pv_virial + virial%pv_xc
1718 END IF
1719
1720 IF (debug_stress .AND. use_virial) THEN
1721 stdeb = 1.0_dp*fconv*virial%pv_xc
1722 CALL para_env%sum(stdeb)
1723 IF (iounit > 0) WRITE (unit=iounit, fmt="(T2,A,T41,2(1X,ES19.11))") &
1724 'STRESS| GGA 2nd Pin*dK*rhoz', one_third_sum_diag(stdeb), det_3x3(stdeb)
1725 END IF
1726
1727 ! Stress-tensor integral contribution of 2nd derivative terms
1728 IF (use_virial) THEN
1729 pv_loc = virial%pv_virial
1730 END IF
1731
1732 CALL get_qs_env(qs_env=qs_env, rho=rho)
1733 CALL qs_rho_get(rho, rho_ao_kp=matrix_p)
1734 IF (debug_stress .AND. use_virial) stdeb = virial%pv_virial
1735
1736 DO ispin = 1, nspins
1737 CALL pw_scale(v_xc(ispin), v_xc(ispin)%pw_grid%dvol)
1738 END DO
1739 IF ((.NOT. (gapw)) .AND. (.NOT. gapw_xc)) THEN
1740 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
1741 DO ispin = 1, nspins
1742 CALL pw_axpy(zv_hartree_rspace, v_xc(ispin)) ! Hartree potential of response density
1743 CALL integrate_v_rspace(qs_env=qs_env, &
1744 v_rspace=v_xc(ispin), &
1745 hmat=matrix_hz(ispin), &
1746 pmat=matrix_p(ispin, 1), &
1747 gapw=.false., &
1748 calculate_forces=.true.)
1749 END DO
1750 IF (debug_forces) THEN
1751 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
1752 CALL para_env%sum(fodeb)
1753 IF (iounit > 0) WRITE (iounit, "(T3,A,T33,3F16.8)") "DEBUG:: Pin*dKhxc*rhoz ", fodeb
1754 END IF
1755 ELSE
1756 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
1757 IF (myfun /= xc_none) THEN
1758 DO ispin = 1, nspins
1759 CALL integrate_v_rspace(qs_env=qs_env, &
1760 v_rspace=v_xc(ispin), &
1761 hmat=matrix_hz(ispin), &
1762 pmat=matrix_p(ispin, 1), &
1763 gapw=.true., &
1764 calculate_forces=.true.)
1765 END DO
1766 END IF ! my_fun
1767 ! Coulomb T+Dz
1768 DO ispin = 1, nspins
1769 CALL pw_zero(v_xc(ispin))
1770 IF (gapw) THEN ! Hartree potential of response density
1771 CALL pw_axpy(v_hartree_rspace_t, v_xc(ispin))
1772 ELSEIF (gapw_xc) THEN
1773 CALL pw_axpy(zv_hartree_rspace, v_xc(ispin))
1774 END IF
1775 CALL integrate_v_rspace(qs_env=qs_env, &
1776 v_rspace=v_xc(ispin), &
1777 hmat=matrix_ht(ispin), &
1778 pmat=matrix_p(ispin, 1), &
1779 gapw=gapw, &
1780 calculate_forces=.true.)
1781 END DO
1782 IF (debug_forces) THEN
1783 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
1784 CALL para_env%sum(fodeb)
1785 IF (iounit > 0) WRITE (iounit, "(T3,A,T33,3F16.8)") "DEBUG:: Pin*dKhxc*rhoz ", fodeb
1786 END IF
1787 END IF
1788
1789 IF (gapw .OR. gapw_xc) THEN
1790 ! compute hard and soft atomic contributions
1791 IF (myfun /= xc_none) THEN
1792 IF (debug_forces) fodeb(1:3) = force(1)%Vhxc_atom(1:3, 1)
1793 CALL update_ks_atom(qs_env, matrix_hz, matrix_p, forces=.true., tddft=.false., &
1794 rho_atom_external=local_rho_set_f%rho_atom_set)
1795 IF (debug_forces) THEN
1796 fodeb(1:3) = force(1)%Vhxc_atom(1:3, 1) - fodeb(1:3)
1797 CALL para_env%sum(fodeb)
1798 IF (iounit > 0) WRITE (iounit, "(T3,A,T33,3F16.8)") "DEBUG:: P^GS*dKxc*(Dz+T) PAW", fodeb
1799 END IF
1800 END IF !myfun
1801 ! Coulomb contributions
1802 IF (gapw) THEN
1803 IF (debug_forces) fodeb(1:3) = force(1)%Vhxc_atom(1:3, 1)
1804 CALL update_ks_atom(qs_env, matrix_ht, matrix_p, forces=.true., tddft=.false., &
1805 rho_atom_external=local_rho_set_t%rho_atom_set)
1806 IF (debug_forces) THEN
1807 fodeb(1:3) = force(1)%Vhxc_atom(1:3, 1) - fodeb(1:3)
1808 CALL para_env%sum(fodeb)
1809 IF (iounit > 0) WRITE (iounit, "(T3,A,T33,3F16.8)") "DEBUG:: P^GS*dKh*(Dz+T) PAW", fodeb
1810 END IF
1811 END IF
1812 ! add Coulomb and XC
1813 DO ispin = 1, nspins
1814 CALL dbcsr_add(matrix_hz(ispin)%matrix, matrix_ht(ispin)%matrix, 1.0_dp, 1.0_dp)
1815 END DO
1816
1817 ! release
1818 IF (myfun /= xc_none) THEN
1819 IF (ASSOCIATED(local_rho_set_f)) CALL local_rho_set_release(local_rho_set_f)
1820 END IF
1821 IF (ASSOCIATED(local_rho_set_t)) CALL local_rho_set_release(local_rho_set_t)
1822 IF (ASSOCIATED(local_rho_set_gs)) CALL local_rho_set_release(local_rho_set_gs)
1823 IF (gapw) THEN
1824 IF (ASSOCIATED(hartree_local_t)) CALL hartree_local_release(hartree_local_t)
1825 CALL auxbas_pw_pool%give_back_pw(v_hartree_gspace_t)
1826 CALL auxbas_pw_pool%give_back_pw(v_hartree_rspace_t)
1827 END IF
1828 CALL auxbas_pw_pool%give_back_pw(rho_tot_gspace_t)
1829 DO ispin = 1, nspins
1830 CALL auxbas_pw_pool%give_back_pw(rho_r_t(ispin))
1831 CALL auxbas_pw_pool%give_back_pw(rho_g_t(ispin))
1832 END DO
1833 DEALLOCATE (rho_r_t, rho_g_t)
1834 END IF ! gapw
1835
1836 IF (debug_stress .AND. use_virial) THEN
1837 stdeb = fconv*(virial%pv_virial - stdeb)
1838 CALL para_env%sum(stdeb)
1839 IF (iounit > 0) WRITE (unit=iounit, fmt="(T2,A,T41,2(1X,ES19.11))") &
1840 'STRESS| INT 2nd f_Hxc[Pz]*Pin', one_third_sum_diag(stdeb), det_3x3(stdeb)
1841 END IF
1842 !
1843 IF (ASSOCIATED(v_xc_tau)) THEN
1844 cpassert(.NOT. (gapw .OR. gapw_xc))
1845 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
1846 IF (debug_stress .AND. use_virial) stdeb = virial%pv_virial
1847 DO ispin = 1, nspins
1848 CALL pw_scale(v_xc_tau(ispin), v_xc_tau(ispin)%pw_grid%dvol)
1849 CALL integrate_v_rspace(qs_env=qs_env, &
1850 v_rspace=v_xc_tau(ispin), &
1851 hmat=matrix_hz(ispin), &
1852 pmat=matrix_p(ispin, 1), &
1853 compute_tau=.true., &
1854 gapw=(gapw .OR. gapw_xc), &
1855 calculate_forces=.true.)
1856 END DO
1857 IF (debug_forces) THEN
1858 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
1859 CALL para_env%sum(fodeb)
1860 IF (iounit > 0) WRITE (iounit, "(T3,A,T33,3F16.8)") "DEBUG:: Pin*dKtau*tauz ", fodeb
1861 END IF
1862 END IF
1863 IF (debug_stress .AND. use_virial) THEN
1864 stdeb = fconv*(virial%pv_virial - stdeb)
1865 CALL para_env%sum(stdeb)
1866 IF (iounit > 0) WRITE (unit=iounit, fmt="(T2,A,T41,2(1X,ES19.11))") &
1867 'STRESS| INT 2nd f_xctau[Pz]*Pin', one_third_sum_diag(stdeb), det_3x3(stdeb)
1868 END IF
1869 ! Stress-tensor integral contribution of 2nd derivative terms
1870 IF (use_virial) THEN
1871 virial%pv_ehartree = virial%pv_ehartree + (virial%pv_virial - pv_loc)
1872 END IF
1873
1874 ! KG Embedding
1875 ! calculate kinetic energy kernel, folded with response density for partial integration
1876 IF (dft_control%qs_control%do_kg) THEN
1877 IF (qs_env%kg_env%tnadd_method == kg_tnadd_embed) THEN
1878 ekin_mol = 0.0_dp
1879 IF (use_virial) THEN
1880 pv_loc = virial%pv_virial
1881 END IF
1882
1883 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
1884 IF (use_virial) virial%pv_xc = 0.0_dp
1885 CALL kg_ekin_subset(qs_env=qs_env, &
1886 ks_matrix=matrix_hz, &
1887 ekin_mol=ekin_mol, &
1888 calc_force=.true., &
1889 do_kernel=.true., &
1890 pmat_ext=matrix_pz)
1891
1892 IF (debug_forces) THEN
1893 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
1894 CALL para_env%sum(fodeb)
1895 IF (iounit > 0) WRITE (iounit, "(T3,A,T33,3F16.8)") "DEBUG:: Pin*d(Kkg)*rhoz ", fodeb
1896 END IF
1897 IF (debug_stress .AND. use_virial) THEN
1898 stdeb = fconv*(virial%pv_virial - pv_loc)
1899 CALL para_env%sum(stdeb)
1900 IF (iounit > 0) WRITE (unit=iounit, fmt="(T2,A,T41,2(1X,ES19.11))") &
1901 'STRESS| INT KG Pin*d(KKG)*rhoz ', one_third_sum_diag(stdeb), det_3x3(stdeb)
1902
1903 stdeb = fconv*(virial%pv_xc)
1904 CALL para_env%sum(stdeb)
1905 IF (iounit > 0) WRITE (unit=iounit, fmt="(T2,A,T41,2(1X,ES19.11))") &
1906 'STRESS| GGA KG Pin*d(KKG)*rhoz ', one_third_sum_diag(stdeb), det_3x3(stdeb)
1907 END IF
1908
1909 ! Stress tensor
1910 IF (use_virial) THEN
1911 ! XC-kernel Integral contribution
1912 virial%pv_ehartree = virial%pv_ehartree + (virial%pv_virial - pv_loc)
1913
1914 ! XC-kernel GGA contribution
1915 virial%pv_exc = virial%pv_exc - virial%pv_xc
1916 virial%pv_virial = virial%pv_virial - virial%pv_xc
1917 virial%pv_xc = 0.0_dp
1918 END IF
1919 END IF
1920 END IF
1921 CALL auxbas_pw_pool%give_back_pw(rhoz_tot_gspace)
1922 CALL auxbas_pw_pool%give_back_pw(zv_hartree_gspace)
1923 CALL auxbas_pw_pool%give_back_pw(zv_hartree_rspace)
1924 DO ispin = 1, nspins
1925 CALL auxbas_pw_pool%give_back_pw(rhoz_r(ispin))
1926 CALL auxbas_pw_pool%give_back_pw(rhoz_g(ispin))
1927 CALL auxbas_pw_pool%give_back_pw(v_xc(ispin))
1928 END DO
1929 DEALLOCATE (rhoz_r, rhoz_g, v_xc)
1930 IF (gapw_xc) THEN
1931 DO ispin = 1, nspins
1932 CALL auxbas_pw_pool%give_back_pw(rhoz_r_xc(ispin))
1933 CALL auxbas_pw_pool%give_back_pw(rhoz_g_xc(ispin))
1934 END DO
1935 DEALLOCATE (rhoz_r_xc, rhoz_g_xc)
1936 END IF
1937 IF (ASSOCIATED(v_xc_tau)) THEN
1938 DO ispin = 1, nspins
1939 CALL auxbas_pw_pool%give_back_pw(tauz_r(ispin))
1940 CALL auxbas_pw_pool%give_back_pw(v_xc_tau(ispin))
1941 END DO
1942 DEALLOCATE (tauz_r, v_xc_tau)
1943 END IF
1944 IF (debug_forces) THEN
1945 ALLOCATE (ftot3(3, natom))
1946 CALL total_qs_force(ftot3, force, atomic_kind_set)
1947 fodeb(1:3) = ftot3(1:3, 1) - ftot2(1:3, 1)
1948 CALL para_env%sum(fodeb)
1949 IF (iounit > 0) WRITE (iounit, "(T3,A,T33,3F16.8)") "DEBUG:: Pin*V(rhoz)", fodeb
1950 END IF
1952 CALL dbcsr_deallocate_matrix_set(matrix_ht)
1953
1954 ! -----------------------------------------
1955 ! Apply ADMM exchange correction
1956 ! -----------------------------------------
1957
1958 IF (dft_control%do_admm) THEN
1959 ! volume term
1960 exc_aux_fit = 0.0_dp
1961
1962 IF (qs_env%admm_env%aux_exch_func == do_admm_aux_exch_func_none) THEN
1963 ! nothing to do
1964 NULLIFY (mpz, mhz, mhx, mhy)
1965 ELSE
1966 ! add ADMM xc_section_aux terms: Pz*Vxc + P0*K0[rhoz]
1967 CALL get_qs_env(qs_env, admm_env=admm_env)
1968 CALL get_admm_env(admm_env, rho_aux_fit=rho_aux_fit, matrix_s_aux_fit=scrm, &
1969 task_list_aux_fit=task_list_aux_fit)
1970 !
1971 NULLIFY (mpz, mhz, mhx, mhy)
1972 CALL dbcsr_allocate_matrix_set(mhx, nspins, 1)
1973 CALL dbcsr_allocate_matrix_set(mhy, nspins, 1)
1974 CALL dbcsr_allocate_matrix_set(mpz, nspins, 1)
1975 DO ispin = 1, nspins
1976 ALLOCATE (mhx(ispin, 1)%matrix)
1977 CALL dbcsr_create(mhx(ispin, 1)%matrix, template=scrm(1)%matrix)
1978 CALL dbcsr_copy(mhx(ispin, 1)%matrix, scrm(1)%matrix)
1979 CALL dbcsr_set(mhx(ispin, 1)%matrix, 0.0_dp)
1980 ALLOCATE (mhy(ispin, 1)%matrix)
1981 CALL dbcsr_create(mhy(ispin, 1)%matrix, template=scrm(1)%matrix)
1982 CALL dbcsr_copy(mhy(ispin, 1)%matrix, scrm(1)%matrix)
1983 CALL dbcsr_set(mhy(ispin, 1)%matrix, 0.0_dp)
1984 ALLOCATE (mpz(ispin, 1)%matrix)
1985 IF (do_ex) THEN
1986 CALL dbcsr_create(mpz(ispin, 1)%matrix, template=p_env%p1_admm(ispin)%matrix)
1987 CALL dbcsr_copy(mpz(ispin, 1)%matrix, p_env%p1_admm(ispin)%matrix)
1988 CALL dbcsr_add(mpz(ispin, 1)%matrix, ex_env%matrix_pe_admm(ispin)%matrix, &
1989 1.0_dp, 1.0_dp)
1990 ELSE
1991 CALL dbcsr_create(mpz(ispin, 1)%matrix, template=matrix_pz_admm(ispin)%matrix)
1992 CALL dbcsr_copy(mpz(ispin, 1)%matrix, matrix_pz_admm(ispin)%matrix)
1993 END IF
1994 END DO
1995 !
1996 xc_section => admm_env%xc_section_aux
1997 ! Stress-tensor: integration contribution direct term
1998 ! int Pz*v_xc[rho_admm]
1999 IF (use_virial) THEN
2000 pv_loc = virial%pv_virial
2001 END IF
2002
2003 basis_type = "AUX_FIT"
2004 task_list => task_list_aux_fit
2005 IF (admm_env%do_gapw) THEN
2006 basis_type = "AUX_FIT_SOFT"
2007 task_list => admm_env%admm_gapw_env%task_list
2008 END IF
2009 !
2010 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
2011 IF (debug_stress .AND. use_virial) stdeb = virial%pv_virial
2012 DO ispin = 1, nspins
2013 CALL integrate_v_rspace(v_rspace=vadmm_rspace(ispin), &
2014 hmat=mhx(ispin, 1), pmat=mpz(ispin, 1), &
2015 qs_env=qs_env, calculate_forces=.true., &
2016 basis_type=basis_type, task_list_external=task_list)
2017 END DO
2018 IF (debug_forces) THEN
2019 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
2020 CALL para_env%sum(fodeb)
2021 IF (iounit > 0) WRITE (iounit, "(T3,A,T33,3F16.8)") "DEBUG:: Pz*Vxc(rho_admm)", fodeb
2022 END IF
2023 IF (debug_stress .AND. use_virial) THEN
2024 stdeb = fconv*(virial%pv_virial - pv_loc)
2025 CALL para_env%sum(stdeb)
2026 IF (iounit > 0) WRITE (unit=iounit, fmt="(T2,A,T41,2(1X,ES19.11))") &
2027 'STRESS| INT 1st Pz*dVxc(rho_admm) ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2028 END IF
2029 ! Stress-tensor Pz_admm*v_xc[rho_admm]
2030 IF (use_virial) THEN
2031 virial%pv_ehartree = virial%pv_ehartree + (virial%pv_virial - pv_loc)
2032 END IF
2033 !
2034 IF (admm_env%do_gapw) THEN
2035 CALL get_admm_env(admm_env, sab_aux_fit=sab_aux_fit)
2036 IF (debug_forces) fodeb(1:3) = force(1)%Vhxc_atom(1:3, 1)
2037 CALL update_ks_atom(qs_env, mhx(:, 1), mpz(:, 1), forces=.true., tddft=.false., &
2038 rho_atom_external=admm_env%admm_gapw_env%local_rho_set%rho_atom_set, &
2039 kind_set_external=admm_env%admm_gapw_env%admm_kind_set, &
2040 oce_external=admm_env%admm_gapw_env%oce, &
2041 sab_external=sab_aux_fit)
2042 IF (debug_forces) THEN
2043 fodeb(1:3) = force(1)%Vhxc_atom(1:3, 1) - fodeb(1:3)
2044 CALL para_env%sum(fodeb)
2045 IF (iounit > 0) WRITE (iounit, "(T3,A,T33,3F16.8)") "DEBUG:: Pz*Vxc(rho_admm)PAW", fodeb
2046 END IF
2047 END IF
2048 !
2049 NULLIFY (rho_g_aux, rho_r_aux, tau_r_aux)
2050 CALL qs_rho_get(rho_aux_fit, rho_r=rho_r_aux, rho_g=rho_g_aux, tau_r=tau_r_aux)
2051 ! rhoz_aux
2052 NULLIFY (rhoz_g_aux, rhoz_r_aux)
2053 ALLOCATE (rhoz_r_aux(nspins), rhoz_g_aux(nspins))
2054 DO ispin = 1, nspins
2055 CALL auxbas_pw_pool%create_pw(rhoz_r_aux(ispin))
2056 CALL auxbas_pw_pool%create_pw(rhoz_g_aux(ispin))
2057 END DO
2058 DO ispin = 1, nspins
2059 CALL calculate_rho_elec(ks_env=ks_env, matrix_p=mpz(ispin, 1)%matrix, &
2060 rho=rhoz_r_aux(ispin), rho_gspace=rhoz_g_aux(ispin), &
2061 basis_type=basis_type, task_list_external=task_list)
2062 END DO
2063 !
2064 ! Add ADMM volume contribution to stress tensor
2065 IF (use_virial) THEN
2066
2067 ! Stress tensor volume term: \int v_xc[n_in_admm]*n_z_admm
2068 ! vadmm_rspace already scaled, we need to unscale it!
2069 DO ispin = 1, nspins
2070 exc_aux_fit = exc_aux_fit + pw_integral_ab(rhoz_r_aux(ispin), vadmm_rspace(ispin))/ &
2071 vadmm_rspace(ispin)%pw_grid%dvol
2072 END DO
2073
2074 IF (debug_stress) THEN
2075 stdeb = -1.0_dp*fconv*exc_aux_fit
2076 IF (iounit > 0) WRITE (unit=iounit, fmt="(T2,A,T43,2(1X,ES19.11))") &
2077 'STRESS| VOL 1st eps_XC[n_in_admm]*n_z_admm', one_third_sum_diag(stdeb), det_3x3(stdeb)
2078 END IF
2079
2080 END IF
2081 !
2082 NULLIFY (v_xc)
2083
2084 IF (use_virial) virial%pv_xc = 0.0_dp
2085
2086 CALL create_kernel(qs_env=qs_env, &
2087 vxc=v_xc, &
2088 vxc_tau=v_xc_tau, &
2089 rho=rho_aux_fit, &
2090 rho1_r=rhoz_r_aux, &
2091 rho1_g=rhoz_g_aux, &
2092 tau1_r=tau_r_aux, &
2093 xc_section=xc_section, &
2094 compute_virial=use_virial, &
2095 virial_xc=virial%pv_xc)
2096
2097 ! Stress-tensor ADMM-kernel GGA contribution
2098 IF (use_virial) THEN
2099 virial%pv_exc = virial%pv_exc + virial%pv_xc
2100 virial%pv_virial = virial%pv_virial + virial%pv_xc
2101 END IF
2102
2103 IF (debug_stress .AND. use_virial) THEN
2104 stdeb = 1.0_dp*fconv*virial%pv_xc
2105 CALL para_env%sum(stdeb)
2106 IF (iounit > 0) WRITE (unit=iounit, fmt="(T2,A,T41,2(1X,ES19.11))") &
2107 'STRESS| GGA 2nd Pin_admm*dK*rhoz_admm', one_third_sum_diag(stdeb), det_3x3(stdeb)
2108 END IF
2109 !
2110 CALL qs_rho_get(rho_aux_fit, rho_ao_kp=matrix_p)
2111 ! Stress-tensor Pin*dK*rhoz_admm
2112 IF (use_virial) THEN
2113 virial%pv_ehartree = virial%pv_ehartree + (virial%pv_virial - pv_loc)
2114 END IF
2115 IF (debug_forces) fodeb(1:3) = force(1)%rho_elec(1:3, 1)
2116 IF (debug_stress .AND. use_virial) stdeb = virial%pv_virial
2117 DO ispin = 1, nspins
2118 CALL dbcsr_set(mhy(ispin, 1)%matrix, 0.0_dp)
2119 CALL pw_scale(v_xc(ispin), v_xc(ispin)%pw_grid%dvol)
2120 CALL integrate_v_rspace(qs_env=qs_env, v_rspace=v_xc(ispin), &
2121 hmat=mhy(ispin, 1), pmat=matrix_p(ispin, 1), &
2122 calculate_forces=.true., &
2123 basis_type=basis_type, task_list_external=task_list)
2124 END DO
2125 IF (debug_forces) THEN
2126 fodeb(1:3) = force(1)%rho_elec(1:3, 1) - fodeb(1:3)
2127 CALL para_env%sum(fodeb)
2128 IF (iounit > 0) WRITE (iounit, "(T3,A,T33,3F16.8)") "DEBUG:: Pin*dK*rhoz_admm ", fodeb
2129 END IF
2130 IF (debug_stress .AND. use_virial) THEN
2131 stdeb = fconv*(virial%pv_virial - pv_loc)
2132 CALL para_env%sum(stdeb)
2133 IF (iounit > 0) WRITE (unit=iounit, fmt="(T2,A,T41,2(1X,ES19.11))") &
2134 'STRESS| INT 2nd Pin*dK*rhoz_admm ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2135 END IF
2136 ! Stress-tensor Pin*dK*rhoz_admm
2137 IF (use_virial) THEN
2138 virial%pv_ehartree = virial%pv_ehartree + (virial%pv_virial - pv_loc)
2139 END IF
2140 DO ispin = 1, nspins
2141 CALL auxbas_pw_pool%give_back_pw(v_xc(ispin))
2142 CALL auxbas_pw_pool%give_back_pw(rhoz_r_aux(ispin))
2143 CALL auxbas_pw_pool%give_back_pw(rhoz_g_aux(ispin))
2144 END DO
2145 DEALLOCATE (v_xc, rhoz_r_aux, rhoz_g_aux)
2146 !
2147 IF (admm_env%do_gapw) THEN
2148 CALL local_rho_set_create(local_rhoz_set_admm)
2149 CALL allocate_rho_atom_internals(local_rhoz_set_admm%rho_atom_set, atomic_kind_set, &
2150 admm_env%admm_gapw_env%admm_kind_set, dft_control, para_env)
2151 CALL calculate_rho_atom_coeff(qs_env, mpz(:, 1), local_rhoz_set_admm%rho_atom_set, &
2152 admm_env%admm_gapw_env%admm_kind_set, &
2153 admm_env%admm_gapw_env%oce, sab_aux_fit, para_env)
2154 CALL prepare_gapw_den(qs_env, local_rho_set=local_rhoz_set_admm, &
2155 do_rho0=.false., kind_set_external=admm_env%admm_gapw_env%admm_kind_set)
2156 !compute the potential due to atomic densities
2157 CALL calculate_xc_2nd_deriv_atom(admm_env%admm_gapw_env%local_rho_set%rho_atom_set, &
2158 local_rhoz_set_admm%rho_atom_set, &
2159 qs_env, xc_section, para_env, do_tddft=.false., do_triplet=.false., &
2160 kind_set_external=admm_env%admm_gapw_env%admm_kind_set)
2161 !
2162 IF (debug_forces) fodeb(1:3) = force(1)%Vhxc_atom(1:3, 1)
2163 CALL update_ks_atom(qs_env, mhy(:, 1), matrix_p(:, 1), forces=.true., tddft=.false., &
2164 rho_atom_external=local_rhoz_set_admm%rho_atom_set, &
2165 kind_set_external=admm_env%admm_gapw_env%admm_kind_set, &
2166 oce_external=admm_env%admm_gapw_env%oce, &
2167 sab_external=sab_aux_fit)
2168 IF (debug_forces) THEN
2169 fodeb(1:3) = force(1)%Vhxc_atom(1:3, 1) - fodeb(1:3)
2170 CALL para_env%sum(fodeb)
2171 IF (iounit > 0) WRITE (iounit, "(T3,A,T33,3F16.8)") "DEBUG:: Pin*dK*rhoz_admm[PAW] ", fodeb
2172 END IF
2173 CALL local_rho_set_release(local_rhoz_set_admm)
2174 END IF
2175 !
2176 nao = admm_env%nao_orb
2177 nao_aux = admm_env%nao_aux_fit
2178 ALLOCATE (dbwork)
2179 CALL dbcsr_create(dbwork, template=matrix_hz(1)%matrix)
2180 DO ispin = 1, nspins
2181 CALL cp_dbcsr_sm_fm_multiply(mhy(ispin, 1)%matrix, admm_env%A, &
2182 admm_env%work_aux_orb, nao)
2183 CALL parallel_gemm('T', 'N', nao, nao, nao_aux, &
2184 1.0_dp, admm_env%A, admm_env%work_aux_orb, 0.0_dp, &
2185 admm_env%work_orb_orb)
2186 CALL dbcsr_copy(dbwork, matrix_hz(ispin)%matrix)
2187 CALL dbcsr_set(dbwork, 0.0_dp)
2188 CALL copy_fm_to_dbcsr(admm_env%work_orb_orb, dbwork, keep_sparsity=.true.)
2189 CALL dbcsr_add(matrix_hz(ispin)%matrix, dbwork, 1.0_dp, 1.0_dp)
2190 END DO
2191 CALL dbcsr_release(dbwork)
2192 DEALLOCATE (dbwork)
2194 END IF ! qs_env%admm_env%aux_exch_func == do_admm_aux_exch_func_none
2195 END IF ! do_admm
2196
2197 ! -----------------------------------------
2198 ! HFX
2199 ! -----------------------------------------
2200
2201 ! HFX
2202 hfx_section => section_vals_get_subs_vals(xc_section, "HF")
2203 CALL section_vals_get(hfx_section, explicit=do_hfx)
2204 IF (do_hfx) THEN
2205 CALL section_vals_get(hfx_section, n_repetition=n_rep_hf)
2206 cpassert(n_rep_hf == 1)
2207 CALL section_vals_val_get(hfx_section, "TREAT_LSD_IN_CORE", l_val=hfx_treat_lsd_in_core, &
2208 i_rep_section=1)
2209 mspin = 1
2210 IF (hfx_treat_lsd_in_core) mspin = nspins
2211 IF (use_virial) virial%pv_fock_4c = 0.0_dp
2212 !
2213 CALL get_qs_env(qs_env=qs_env, rho=rho, x_data=x_data, &
2214 s_mstruct_changed=s_mstruct_changed)
2215 distribute_fock_matrix = .true.
2216
2217 ! -----------------------------------------
2218 ! HFX-ADMM
2219 ! -----------------------------------------
2220 IF (dft_control%do_admm) THEN
2221 CALL get_qs_env(qs_env=qs_env, admm_env=admm_env)
2222 CALL get_admm_env(admm_env, matrix_s_aux_fit=scrm, rho_aux_fit=rho_aux_fit)
2223 CALL qs_rho_get(rho_aux_fit, rho_ao_kp=matrix_p)
2224 NULLIFY (mpz, mhz, mpd, mhd)
2225 CALL dbcsr_allocate_matrix_set(mpz, nspins, 1)
2226 CALL dbcsr_allocate_matrix_set(mhz, nspins, 1)
2227 CALL dbcsr_allocate_matrix_set(mpd, nspins, 1)
2228 CALL dbcsr_allocate_matrix_set(mhd, nspins, 1)
2229 DO ispin = 1, nspins
2230 ALLOCATE (mhz(ispin, 1)%matrix, mhd(ispin, 1)%matrix)
2231 CALL dbcsr_create(mhz(ispin, 1)%matrix, template=scrm(1)%matrix)
2232 CALL dbcsr_create(mhd(ispin, 1)%matrix, template=scrm(1)%matrix)
2233 CALL dbcsr_copy(mhz(ispin, 1)%matrix, scrm(1)%matrix)
2234 CALL dbcsr_copy(mhd(ispin, 1)%matrix, scrm(1)%matrix)
2235 CALL dbcsr_set(mhz(ispin, 1)%matrix, 0.0_dp)
2236 CALL dbcsr_set(mhd(ispin, 1)%matrix, 0.0_dp)
2237 ALLOCATE (mpz(ispin, 1)%matrix)
2238 IF (do_ex) THEN
2239 CALL dbcsr_create(mpz(ispin, 1)%matrix, template=scrm(1)%matrix)
2240 CALL dbcsr_copy(mpz(ispin, 1)%matrix, p_env%p1_admm(ispin)%matrix)
2241 CALL dbcsr_add(mpz(ispin, 1)%matrix, ex_env%matrix_pe_admm(ispin)%matrix, &
2242 1.0_dp, 1.0_dp)
2243 ELSE
2244 CALL dbcsr_create(mpz(ispin, 1)%matrix, template=scrm(1)%matrix)
2245 CALL dbcsr_copy(mpz(ispin, 1)%matrix, matrix_pz_admm(ispin)%matrix)
2246 END IF
2247 mpd(ispin, 1)%matrix => matrix_p(ispin, 1)%matrix
2248 END DO
2249 !
2250 IF (x_data(1, 1)%do_hfx_ri) THEN
2251
2252 eh1 = 0.0_dp
2253 CALL hfx_ri_update_ks(qs_env, x_data(1, 1)%ri_data, mhz, eh1, rho_ao=mpz, &
2254 geometry_did_change=s_mstruct_changed, nspins=nspins, &
2255 hf_fraction=x_data(1, 1)%general_parameter%fraction)
2256
2257 eh1 = 0.0_dp
2258 CALL hfx_ri_update_ks(qs_env, x_data(1, 1)%ri_data, mhd, eh1, rho_ao=mpd, &
2259 geometry_did_change=s_mstruct_changed, nspins=nspins, &
2260 hf_fraction=x_data(1, 1)%general_parameter%fraction)
2261
2262 ELSE
2263 DO ispin = 1, mspin
2264 eh1 = 0.0
2265 CALL integrate_four_center(qs_env, x_data, mhz, eh1, mpz, hfx_section, &
2266 para_env, s_mstruct_changed, 1, distribute_fock_matrix, &
2267 ispin=ispin)
2268 END DO
2269 DO ispin = 1, mspin
2270 eh1 = 0.0
2271 CALL integrate_four_center(qs_env, x_data, mhd, eh1, mpd, hfx_section, &
2272 para_env, s_mstruct_changed, 1, distribute_fock_matrix, &
2273 ispin=ispin)
2274 END DO
2275 END IF
2276 !
2277 CALL get_qs_env(qs_env, admm_env=admm_env)
2278 cpassert(ASSOCIATED(admm_env%work_aux_orb))
2279 cpassert(ASSOCIATED(admm_env%work_orb_orb))
2280 nao = admm_env%nao_orb
2281 nao_aux = admm_env%nao_aux_fit
2282 ALLOCATE (dbwork)
2283 CALL dbcsr_create(dbwork, template=matrix_hz(1)%matrix)
2284 DO ispin = 1, nspins
2285 CALL cp_dbcsr_sm_fm_multiply(mhz(ispin, 1)%matrix, admm_env%A, &
2286 admm_env%work_aux_orb, nao)
2287 CALL parallel_gemm('T', 'N', nao, nao, nao_aux, &
2288 1.0_dp, admm_env%A, admm_env%work_aux_orb, 0.0_dp, &
2289 admm_env%work_orb_orb)
2290 CALL dbcsr_copy(dbwork, matrix_hz(ispin)%matrix)
2291 CALL dbcsr_set(dbwork, 0.0_dp)
2292 CALL copy_fm_to_dbcsr(admm_env%work_orb_orb, dbwork, keep_sparsity=.true.)
2293 CALL dbcsr_add(matrix_hz(ispin)%matrix, dbwork, 1.0_dp, 1.0_dp)
2294 END DO
2295 CALL dbcsr_release(dbwork)
2296 DEALLOCATE (dbwork)
2297 ! derivatives Tr (Pz [A(T)H dA/dR])
2298 IF (debug_forces) fodeb(1:3) = force(1)%overlap_admm(1:3, 1)
2299 IF (ASSOCIATED(mhx) .AND. ASSOCIATED(mhy)) THEN
2300 DO ispin = 1, nspins
2301 CALL dbcsr_add(mhd(ispin, 1)%matrix, mhx(ispin, 1)%matrix, 1.0_dp, 1.0_dp)
2302 CALL dbcsr_add(mhz(ispin, 1)%matrix, mhy(ispin, 1)%matrix, 1.0_dp, 1.0_dp)
2303 END DO
2304 END IF
2305 CALL qs_rho_get(rho, rho_ao=matrix_pd)
2306 CALL admm_projection_derivative(qs_env, mhd(:, 1), mpa)
2307 CALL admm_projection_derivative(qs_env, mhz(:, 1), matrix_pd)
2308 IF (debug_forces) THEN
2309 fodeb(1:3) = force(1)%overlap_admm(1:3, 1) - fodeb(1:3)
2310 CALL para_env%sum(fodeb)
2311 IF (iounit > 0) WRITE (iounit, "(T3,A,T33,3F16.8)") "DEBUG:: Pz*hfx*S' ", fodeb
2312 END IF
2316 IF (ASSOCIATED(mhx) .AND. ASSOCIATED(mhy)) THEN
2319 END IF
2320 DEALLOCATE (mpd)
2321 ELSE
2322 ! -----------------------------------------
2323 ! conventional HFX
2324 ! -----------------------------------------
2325 ALLOCATE (mpz(nspins, 1), mhz(nspins, 1))
2326 DO ispin = 1, nspins
2327 mhz(ispin, 1)%matrix => matrix_hz(ispin)%matrix
2328 mpz(ispin, 1)%matrix => mpa(ispin)%matrix
2329 END DO
2330
2331 IF (x_data(1, 1)%do_hfx_ri) THEN
2332
2333 eh1 = 0.0_dp
2334 CALL hfx_ri_update_ks(qs_env, x_data(1, 1)%ri_data, mhz, eh1, rho_ao=mpz, &
2335 geometry_did_change=s_mstruct_changed, nspins=nspins, &
2336 hf_fraction=x_data(1, 1)%general_parameter%fraction)
2337 ELSE
2338 DO ispin = 1, mspin
2339 eh1 = 0.0
2340 CALL integrate_four_center(qs_env, x_data, mhz, eh1, mpz, hfx_section, &
2341 para_env, s_mstruct_changed, 1, distribute_fock_matrix, &
2342 ispin=ispin)
2343 END DO
2344 END IF
2345 DEALLOCATE (mhz, mpz)
2346 END IF
2347
2348 ! -----------------------------------------
2349 ! HFX FORCES
2350 ! -----------------------------------------
2351
2352 resp_only = .true.
2353 IF (debug_forces) fodeb(1:3) = force(1)%fock_4c(1:3, 1)
2354 IF (dft_control%do_admm) THEN
2355 ! -----------------------------------------
2356 ! HFX-ADMM FORCES
2357 ! -----------------------------------------
2358 CALL qs_rho_get(rho_aux_fit, rho_ao_kp=matrix_p)
2359 NULLIFY (matrix_pza)
2360 CALL dbcsr_allocate_matrix_set(matrix_pza, nspins)
2361 DO ispin = 1, nspins
2362 ALLOCATE (matrix_pza(ispin)%matrix)
2363 IF (do_ex) THEN
2364 CALL dbcsr_create(matrix_pza(ispin)%matrix, template=p_env%p1_admm(ispin)%matrix)
2365 CALL dbcsr_copy(matrix_pza(ispin)%matrix, p_env%p1_admm(ispin)%matrix)
2366 CALL dbcsr_add(matrix_pza(ispin)%matrix, ex_env%matrix_pe_admm(ispin)%matrix, &
2367 1.0_dp, 1.0_dp)
2368 ELSE
2369 CALL dbcsr_create(matrix_pza(ispin)%matrix, template=matrix_pz_admm(ispin)%matrix)
2370 CALL dbcsr_copy(matrix_pza(ispin)%matrix, matrix_pz_admm(ispin)%matrix)
2371 END IF
2372 END DO
2373 IF (x_data(1, 1)%do_hfx_ri) THEN
2374
2375 CALL hfx_ri_update_forces(qs_env, x_data(1, 1)%ri_data, nspins, &
2376 x_data(1, 1)%general_parameter%fraction, &
2377 rho_ao=matrix_p, rho_ao_resp=matrix_pza, &
2378 use_virial=use_virial, resp_only=resp_only)
2379 ELSE
2380 CALL derivatives_four_center(qs_env, matrix_p, matrix_pza, hfx_section, para_env, &
2381 1, use_virial, resp_only=resp_only)
2382 END IF
2383 CALL dbcsr_deallocate_matrix_set(matrix_pza)
2384 ELSE
2385 ! -----------------------------------------
2386 ! conventional HFX FORCES
2387 ! -----------------------------------------
2388 CALL qs_rho_get(rho, rho_ao_kp=matrix_p)
2389 IF (x_data(1, 1)%do_hfx_ri) THEN
2390
2391 CALL hfx_ri_update_forces(qs_env, x_data(1, 1)%ri_data, nspins, &
2392 x_data(1, 1)%general_parameter%fraction, &
2393 rho_ao=matrix_p, rho_ao_resp=mpa, &
2394 use_virial=use_virial, resp_only=resp_only)
2395 ELSE
2396 CALL derivatives_four_center(qs_env, matrix_p, mpa, hfx_section, para_env, &
2397 1, use_virial, resp_only=resp_only)
2398 END IF
2399 END IF ! do_admm
2400
2401 IF (use_virial) THEN
2402 virial%pv_exx = virial%pv_exx - virial%pv_fock_4c
2403 virial%pv_virial = virial%pv_virial - virial%pv_fock_4c
2404 virial%pv_calculate = .false.
2405 END IF
2406
2407 IF (debug_forces) THEN
2408 fodeb(1:3) = force(1)%fock_4c(1:3, 1) - fodeb(1:3)
2409 CALL para_env%sum(fodeb)
2410 IF (iounit > 0) WRITE (iounit, "(T3,A,T33,3F16.8)") "DEBUG:: Pz*hfx ", fodeb
2411 END IF
2412 IF (debug_stress .AND. use_virial) THEN
2413 stdeb = -1.0_dp*fconv*virial%pv_fock_4c
2414 CALL para_env%sum(stdeb)
2415 IF (iounit > 0) WRITE (unit=iounit, fmt="(T2,A,T41,2(1X,ES19.11))") &
2416 'STRESS| Pz*hfx ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2417 END IF
2418 END IF ! do_hfx
2419
2420 ! Stress-tensor volume contributions
2421 ! These need to be applied at the end of qs_force
2422 IF (use_virial) THEN
2423 ! Adding mixed Hartree energy twice, due to symmetry
2424 zehartree = zehartree + 2.0_dp*ehartree
2425 zexc = zexc + exc
2426 ! ADMM contribution handled differently in qs_force
2427 IF (dft_control%do_admm) THEN
2428 zexc_aux_fit = zexc_aux_fit + exc_aux_fit
2429 END IF
2430 END IF
2431
2432 ! Overlap matrix
2433 ! H(drho+dz) + Wz
2434 ! If ground-state density matrix solved by diagonalization, then use this
2435 IF (dft_control%qs_control%do_ls_scf) THEN
2436 ! Ground-state density has been calculated by LS
2437 eps_filter = dft_control%qs_control%eps_filter_matrix
2438 CALL calculate_whz_ao_matrix(qs_env, matrix_hz, matrix_wz, eps_filter)
2439 ELSE
2440 IF (do_ex) THEN
2441 matrix_wz => p_env%w1
2442 END IF
2443 focc = 1.0_dp
2444 IF (nspins == 1) focc = 2.0_dp
2445 CALL get_qs_env(qs_env, mos=mos)
2446 DO ispin = 1, nspins
2447 CALL get_mo_set(mo_set=mos(ispin), homo=nocc)
2448 CALL calculate_whz_matrix(mos(ispin)%mo_coeff, matrix_hz(ispin)%matrix, &
2449 matrix_wz(ispin)%matrix, focc, nocc)
2450 END DO
2451 END IF
2452 IF (nspins == 2) THEN
2453 CALL dbcsr_add(matrix_wz(1)%matrix, matrix_wz(2)%matrix, &
2454 alpha_scalar=1.0_dp, beta_scalar=1.0_dp)
2455 END IF
2456
2457 IF (debug_forces) fodeb(1:3) = force(1)%overlap(1:3, 1)
2458 IF (debug_stress .AND. use_virial) stdeb = virial%pv_overlap
2459 NULLIFY (scrm)
2460 CALL build_overlap_matrix(ks_env, matrix_s=scrm, &
2461 matrix_name="OVERLAP MATRIX", &
2462 basis_type_a="ORB", basis_type_b="ORB", &
2463 sab_nl=sab_orb, calculate_forces=.true., &
2464 matrix_p=matrix_wz(1)%matrix)
2465
2466 IF (SIZE(matrix_wz, 1) == 2) THEN
2467 CALL dbcsr_add(matrix_wz(1)%matrix, matrix_wz(2)%matrix, &
2468 alpha_scalar=1.0_dp, beta_scalar=-1.0_dp)
2469 END IF
2470
2471 IF (debug_forces) THEN
2472 fodeb(1:3) = force(1)%overlap(1:3, 1) - fodeb(1:3)
2473 CALL para_env%sum(fodeb)
2474 IF (iounit > 0) WRITE (iounit, "(T3,A,T33,3F16.8)") "DEBUG:: Wz*dS ", fodeb
2475 END IF
2476 IF (debug_stress .AND. use_virial) THEN
2477 stdeb = fconv*(virial%pv_overlap - stdeb)
2478 CALL para_env%sum(stdeb)
2479 IF (iounit > 0) WRITE (unit=iounit, fmt="(T2,A,T41,2(1X,ES19.11))") &
2480 'STRESS| WHz ', one_third_sum_diag(stdeb), det_3x3(stdeb)
2481 END IF
2483
2484 IF (debug_forces) THEN
2485 CALL total_qs_force(ftot2, force, atomic_kind_set)
2486 fodeb(1:3) = ftot2(1:3, 1) - ftot1(1:3, 1)
2487 CALL para_env%sum(fodeb)
2488 IF (iounit > 0) WRITE (iounit, "(T3,A,T33,3F16.8)") "DEBUG:: Response Force", fodeb
2489 fodeb(1:3) = ftot2(1:3, 1)
2490 CALL para_env%sum(fodeb)
2491 IF (iounit > 0) WRITE (iounit, "(T3,A,T33,3F16.8)") "DEBUG:: Total Force ", fodeb
2492 DEALLOCATE (ftot1, ftot2, ftot3)
2493 END IF
2494
2495 IF (do_ex) THEN
2497 CALL dbcsr_deallocate_matrix_set(matrix_hz)
2498 END IF
2499
2500 CALL timestop(handle)
2501
2502 END SUBROUTINE response_force
2503
2504! **************************************************************************************************
2505!> \brief ...
2506!> \param qs_env ...
2507!> \param p_env ...
2508!> \param matrix_hz ...
2509!> \param ex_env ...
2510!> \param debug ...
2511! **************************************************************************************************
2512 SUBROUTINE response_force_xtb(qs_env, p_env, matrix_hz, ex_env, debug)
2513 TYPE(qs_environment_type), POINTER :: qs_env
2514 TYPE(qs_p_env_type) :: p_env
2515 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_hz
2516 TYPE(excited_energy_type), OPTIONAL, POINTER :: ex_env
2517 LOGICAL, INTENT(IN), OPTIONAL :: debug
2518
2519 CHARACTER(LEN=*), PARAMETER :: routinen = 'response_force_xtb'
2520
2521 INTEGER :: atom_a, handle, iatom, ikind, iounit, &
2522 is, ispin, na, natom, natorb, nimages, &
2523 nkind, nocc, ns, nsgf, nspins
2524 INTEGER, DIMENSION(25) :: lao
2525 INTEGER, DIMENSION(5) :: occ
2526 LOGICAL :: debug_forces, do_ex, use_virial
2527 REAL(kind=dp) :: focc
2528 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: mcharge, mcharge1
2529 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :) :: aocg, aocg1, charges, charges1, ftot1, &
2530 ftot2
2531 REAL(kind=dp), DIMENSION(3) :: fodeb
2532 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
2533 TYPE(cp_logger_type), POINTER :: logger
2534 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_pz, matrix_wz, mpa, p_matrix, scrm
2535 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_p, matrix_s
2536 TYPE(dbcsr_type), POINTER :: s_matrix
2537 TYPE(dft_control_type), POINTER :: dft_control
2538 TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
2539 TYPE(mp_para_env_type), POINTER :: para_env
2540 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
2541 POINTER :: sab_orb
2542 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
2543 TYPE(qs_force_type), DIMENSION(:), POINTER :: force
2544 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
2545 TYPE(qs_ks_env_type), POINTER :: ks_env
2546 TYPE(qs_rho_type), POINTER :: rho
2547 TYPE(xtb_atom_type), POINTER :: xtb_kind
2548
2549 CALL timeset(routinen, handle)
2550
2551 IF (PRESENT(debug)) THEN
2552 debug_forces = debug
2553 ELSE
2554 debug_forces = .false.
2555 END IF
2556
2557 logger => cp_get_default_logger()
2558 IF (logger%para_env%is_source()) THEN
2559 iounit = cp_logger_get_default_unit_nr(logger, local=.true.)
2560 ELSE
2561 iounit = -1
2562 END IF
2563
2564 do_ex = .false.
2565 IF (PRESENT(ex_env)) do_ex = .true.
2566
2567 NULLIFY (ks_env, sab_orb)
2568 CALL get_qs_env(qs_env=qs_env, ks_env=ks_env, dft_control=dft_control, &
2569 sab_orb=sab_orb)
2570 CALL get_qs_env(qs_env=qs_env, para_env=para_env, force=force)
2571 nspins = dft_control%nspins
2572
2573 IF (debug_forces) THEN
2574 CALL get_qs_env(qs_env, natom=natom, atomic_kind_set=atomic_kind_set)
2575 ALLOCATE (ftot1(3, natom))
2576 ALLOCATE (ftot2(3, natom))
2577 CALL total_qs_force(ftot1, force, atomic_kind_set)
2578 END IF
2579
2580 matrix_pz => p_env%p1
2581 NULLIFY (mpa)
2582 IF (do_ex) THEN
2583 CALL dbcsr_allocate_matrix_set(mpa, nspins)
2584 DO ispin = 1, nspins
2585 ALLOCATE (mpa(ispin)%matrix)
2586 CALL dbcsr_create(mpa(ispin)%matrix, template=matrix_pz(ispin)%matrix)
2587 CALL dbcsr_copy(mpa(ispin)%matrix, matrix_pz(ispin)%matrix)
2588 CALL dbcsr_add(mpa(ispin)%matrix, ex_env%matrix_pe(ispin)%matrix, 1.0_dp, 1.0_dp)
2589 CALL dbcsr_set(matrix_hz(ispin)%matrix, 0.0_dp)
2590 END DO
2591 ELSE
2592 mpa => p_env%p1
2593 END IF
2594 !
2595 ! START OF Tr(P+Z)Hcore
2596 !
2597 IF (nspins == 2) THEN
2598 CALL dbcsr_add(mpa(1)%matrix, mpa(2)%matrix, 1.0_dp, 1.0_dp)
2599 END IF
2600 ! Hcore matrix
2601 IF (debug_forces) fodeb(1:3) = force(1)%all_potential(1:3, 1)
2602 CALL xtb_hab_force(qs_env, mpa(1)%matrix)
2603 IF (debug_forces) THEN
2604 fodeb(1:3) = force(1)%all_potential(1:3, 1) - fodeb(1:3)
2605 CALL para_env%sum(fodeb)
2606 IF (iounit > 0) WRITE (iounit, "(T3,A,T33,3F16.8)") "DEBUG:: Pz*dHcore ", fodeb
2607 END IF
2608 IF (nspins == 2) THEN
2609 CALL dbcsr_add(mpa(1)%matrix, mpa(2)%matrix, 1.0_dp, -1.0_dp)
2610 END IF
2611 !
2612 ! END OF Tr(P+Z)Hcore
2613 !
2614 use_virial = .false.
2615 nimages = 1
2616 !
2617 ! Hartree potential of response density
2618 !
2619 IF (dft_control%qs_control%xtb_control%coulomb_interaction) THEN
2620 ! Mulliken charges
2621 CALL get_qs_env(qs_env, rho=rho, particle_set=particle_set, matrix_s_kp=matrix_s)
2622 natom = SIZE(particle_set)
2623 CALL qs_rho_get(rho, rho_ao_kp=matrix_p)
2624 ALLOCATE (mcharge(natom), charges(natom, 5))
2625 ALLOCATE (mcharge1(natom), charges1(natom, 5))
2626 charges = 0.0_dp
2627 charges1 = 0.0_dp
2628 CALL get_qs_env(qs_env, atomic_kind_set=atomic_kind_set, qs_kind_set=qs_kind_set)
2629 nkind = SIZE(atomic_kind_set)
2630 CALL get_qs_kind_set(qs_kind_set, maxsgf=nsgf)
2631 ALLOCATE (aocg(nsgf, natom))
2632 aocg = 0.0_dp
2633 ALLOCATE (aocg1(nsgf, natom))
2634 aocg1 = 0.0_dp
2635 p_matrix => matrix_p(:, 1)
2636 s_matrix => matrix_s(1, 1)%matrix
2637 CALL ao_charges(p_matrix, s_matrix, aocg, para_env)
2638 CALL ao_charges(mpa, s_matrix, aocg1, para_env)
2639 DO ikind = 1, nkind
2640 CALL get_atomic_kind(atomic_kind_set(ikind), natom=na)
2641 CALL get_qs_kind(qs_kind_set(ikind), xtb_parameter=xtb_kind)
2642 CALL get_xtb_atom_param(xtb_kind, natorb=natorb, lao=lao, occupation=occ)
2643 DO iatom = 1, na
2644 atom_a = atomic_kind_set(ikind)%atom_list(iatom)
2645 charges(atom_a, :) = real(occ(:), kind=dp)
2646 DO is = 1, natorb
2647 ns = lao(is) + 1
2648 charges(atom_a, ns) = charges(atom_a, ns) - aocg(is, atom_a)
2649 charges1(atom_a, ns) = charges1(atom_a, ns) - aocg1(is, atom_a)
2650 END DO
2651 END DO
2652 END DO
2653 DEALLOCATE (aocg, aocg1)
2654 DO iatom = 1, natom
2655 mcharge(iatom) = sum(charges(iatom, :))
2656 mcharge1(iatom) = sum(charges1(iatom, :))
2657 END DO
2658 ! Coulomb Kernel
2659 CALL xtb_coulomb_hessian(qs_env, matrix_hz, charges1, mcharge1, mcharge)
2660 CALL calc_xtb_ehess_force(qs_env, p_matrix, mpa, charges, mcharge, charges1, &
2661 mcharge1, debug_forces)
2662 !
2663 DEALLOCATE (charges, mcharge, charges1, mcharge1)
2664 END IF
2665 ! Overlap matrix
2666 ! H(drho+dz) + Wz
2667 matrix_wz => p_env%w1
2668 focc = 0.5_dp
2669 IF (nspins == 1) focc = 1.0_dp
2670 CALL get_qs_env(qs_env, mos=mos)
2671 DO ispin = 1, nspins
2672 CALL get_mo_set(mo_set=mos(ispin), homo=nocc)
2673 CALL calculate_whz_matrix(mos(ispin)%mo_coeff, matrix_hz(ispin)%matrix, &
2674 matrix_wz(ispin)%matrix, focc, nocc)
2675 END DO
2676 IF (nspins == 2) THEN
2677 CALL dbcsr_add(matrix_wz(1)%matrix, matrix_wz(2)%matrix, &
2678 alpha_scalar=1.0_dp, beta_scalar=1.0_dp)
2679 END IF
2680 IF (debug_forces) fodeb(1:3) = force(1)%overlap(1:3, 1)
2681 NULLIFY (scrm)
2682 CALL build_overlap_matrix(ks_env, matrix_s=scrm, &
2683 matrix_name="OVERLAP MATRIX", &
2684 basis_type_a="ORB", basis_type_b="ORB", &
2685 sab_nl=sab_orb, calculate_forces=.true., &
2686 matrix_p=matrix_wz(1)%matrix)
2687 IF (debug_forces) THEN
2688 fodeb(1:3) = force(1)%overlap(1:3, 1) - fodeb(1:3)
2689 CALL para_env%sum(fodeb)
2690 IF (iounit > 0) WRITE (iounit, "(T3,A,T33,3F16.8)") "DEBUG:: Wz*dS ", fodeb
2691 END IF
2692 CALL dbcsr_deallocate_matrix_set(scrm)
2693
2694 IF (debug_forces) THEN
2695 CALL total_qs_force(ftot2, force, atomic_kind_set)
2696 fodeb(1:3) = ftot2(1:3, 1) - ftot1(1:3, 1)
2697 CALL para_env%sum(fodeb)
2698 IF (iounit > 0) WRITE (iounit, "(T3,A,T30,3F16.8)") "DEBUG:: Response Force", fodeb
2699 DEALLOCATE (ftot1, ftot2)
2700 END IF
2701
2702 IF (do_ex) THEN
2703 CALL dbcsr_deallocate_matrix_set(mpa)
2704 END IF
2705
2706 CALL timestop(handle)
2707
2708 END SUBROUTINE response_force_xtb
2709
2710! **************************************************************************************************
2711!> \brief Win = focc*(P*(H[P_out - P_in] + H[Z] )*P)
2712!> Langrange multiplier matrix with response and perturbation (Harris) kernel matrices
2713!>
2714!> \param qs_env ...
2715!> \param matrix_hz ...
2716!> \param matrix_whz ...
2717!> \param eps_filter ...
2718!> \param
2719!> \par History
2720!> 2020.2 created [Fabian Belleflamme]
2721!> \author Fabian Belleflamme
2722! **************************************************************************************************
2723 SUBROUTINE calculate_whz_ao_matrix(qs_env, matrix_hz, matrix_whz, eps_filter)
2724
2725 TYPE(qs_environment_type), POINTER :: qs_env
2726 TYPE(dbcsr_p_type), DIMENSION(:), INTENT(IN), &
2727 POINTER :: matrix_hz
2728 TYPE(dbcsr_p_type), DIMENSION(:), INTENT(INOUT), &
2729 POINTER :: matrix_whz
2730 REAL(kind=dp), INTENT(IN) :: eps_filter
2731
2732 CHARACTER(len=*), PARAMETER :: routinen = 'calculate_whz_ao_matrix'
2733
2734 INTEGER :: handle, ispin, nspins
2735 REAL(kind=dp) :: scaling
2736 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: rho_ao
2737 TYPE(dbcsr_type) :: matrix_tmp
2738 TYPE(dft_control_type), POINTER :: dft_control
2739 TYPE(mp_para_env_type), POINTER :: para_env
2740 TYPE(qs_rho_type), POINTER :: rho
2741
2742 CALL timeset(routinen, handle)
2743
2744 cpassert(ASSOCIATED(qs_env))
2745 cpassert(ASSOCIATED(matrix_hz))
2746 cpassert(ASSOCIATED(matrix_whz))
2747
2748 CALL get_qs_env(qs_env=qs_env, &
2749 dft_control=dft_control, &
2750 rho=rho, &
2751 para_env=para_env)
2752 nspins = dft_control%nspins
2753 CALL qs_rho_get(rho, rho_ao=rho_ao)
2754
2755 ! init temp matrix
2756 CALL dbcsr_create(matrix_tmp, template=matrix_hz(1)%matrix, &
2757 matrix_type=dbcsr_type_no_symmetry)
2758
2759 !Spin factors simplify to
2760 scaling = 1.0_dp
2761 IF (nspins == 1) scaling = 0.5_dp
2762
2763 ! Operation in MO-solver :
2764 ! Whz = focc*(CC^T*Hz*CC^T)
2765 ! focc = 2.0_dp Closed-shell
2766 ! focc = 1.0_dp Open-shell
2767
2768 ! Operation in AO-solver :
2769 ! Whz = (scaling*P)*(focc*Hz)*(scaling*P)
2770 ! focc see above
2771 ! scaling = 0.5_dp Closed-shell (P = 2*CC^T), WHz = (0.5*P)*(2*Hz)*(0.5*P)
2772 ! scaling = 1.0_dp Open-shell, WHz = P*Hz*P
2773
2774 ! Spin factors from Hz and P simplify to
2775 scaling = 1.0_dp
2776 IF (nspins == 1) scaling = 0.5_dp
2777
2778 DO ispin = 1, nspins
2779
2780 ! tmp = H*CC^T
2781 CALL dbcsr_multiply("N", "N", scaling, matrix_hz(ispin)%matrix, rho_ao(ispin)%matrix, &
2782 0.0_dp, matrix_tmp, filter_eps=eps_filter)
2783 ! WHz = CC^T*tmp
2784 ! WHz = Wz + (scaling*P)*(focc*Hz)*(scaling*P)
2785 ! WHz = Wz + scaling*(P*Hz*P)
2786 CALL dbcsr_multiply("N", "N", 1.0_dp, rho_ao(ispin)%matrix, matrix_tmp, &
2787 1.0_dp, matrix_whz(ispin)%matrix, filter_eps=eps_filter, &
2788 retain_sparsity=.true.)
2789
2790 END DO
2791
2792 CALL dbcsr_release(matrix_tmp)
2793
2794 CALL timestop(handle)
2795
2796 END SUBROUTINE
2797
2798! **************************************************************************************************
2799
2800END MODULE response_solver
Contains ADMM methods which require molecular orbitals.
subroutine, public admm_projection_derivative(qs_env, matrix_hz, matrix_pz, fval)
Calculate derivatives terms from overlap matrices.
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:593
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.
Handles all functions related to the CELL.
Definition cell_types.F:15
Calculation of the nuclear attraction contribution to the core Hamiltonian <a|erfc|b> :we only calcul...
Definition core_ae.F:14
subroutine, public build_core_ae(matrix_h, matrix_p, force, virial, calculate_forces, use_virial, nder, qs_kind_set, atomic_kind_set, particle_set, sab_orb, sac_ae, nimages, cell_to_index)
...
Definition core_ae.F:84
Calculation of the local pseudopotential contribution to the core Hamiltonian <a|V(local)|b> = <a|Sum...
Definition core_ppl.F:18
subroutine, public build_core_ppl(matrix_h, matrix_p, force, virial, calculate_forces, use_virial, nder, qs_kind_set, atomic_kind_set, particle_set, sab_orb, sac_ppl, nimages, cell_to_index, basis_type, deltar)
...
Definition core_ppl.F:95
Calculation of the non-local pseudopotential contribution to the core Hamiltonian <a|V(non-local)|b> ...
Definition core_ppnl.F:15
subroutine, public build_core_ppnl(matrix_h, matrix_p, force, virial, calculate_forces, use_virial, nder, qs_kind_set, atomic_kind_set, particle_set, sab_orb, sap_ppnl, eps_ppnl, nimages, cell_to_index, basis_type, deltar, matrix_l)
...
Definition core_ppnl.F:89
methods related to the blacs parallel environment
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
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
subroutine, public copy_dbcsr_to_fm(matrix, fm)
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 the structure of a full matrix
subroutine, public cp_fm_struct_create(fmstruct, para_env, context, nrow_global, ncol_global, nrow_block, ncol_block, descriptor, first_p_pos, local_leading_dimension, template_fmstruct, square_blocks, force_block)
allocates and initializes a full matrix structure
subroutine, public cp_fm_struct_release(fmstruct)
releases a full matrix structure
represent a full matrix distributed on many processors
Definition cp_fm_types.F:15
subroutine, public cp_fm_set_all(matrix, alpha, beta)
set all elements of a matrix to the same value, and optionally the diagonal to a different one
subroutine, public cp_fm_init_random(matrix, ncol, start_col)
fills a matrix with random numbers
subroutine, public cp_fm_create(matrix, matrix_struct, name, use_sp)
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 ...
recursive integer function, public cp_logger_get_default_unit_nr(logger, local, skip_not_ionode)
asks the default unit number of the given logger. try to use cp_logger_get_unit_nr
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
Types needed for a for a Energy Correction.
Routines used for Harris functional Kohn-Sham calculation.
Definition ec_methods.F:15
subroutine, public ec_mos_init(qs_env, matrix_s)
Allocate and initiate molecular orbitals environment.
Definition ec_methods.F:162
subroutine, public create_kernel(qs_env, vxc, vxc_tau, rho, rho1_r, rho1_g, tau1_r, xc_section, compute_virial, virial_xc)
Creation of second derivative xc-potential.
Definition ec_methods.F:88
AO-based conjugate-gradient response solver routines.
subroutine, public ec_response_ao(qs_env, p_env, matrix_hz, matrix_pz, matrix_wz, iounit, should_stop)
AO-based conjugate gradient linear response solver. In goes the right hand side B of the equation AZ=...
Types for excited states potential energies.
subroutine, public init_coulomb_local(hartree_local, natom)
...
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...
subroutine, public hartree_local_release(hartree_local)
...
subroutine, public hartree_local_create(hartree_local)
...
Routines to calculate derivatives with respect to basis function origin.
subroutine, public derivatives_four_center(qs_env, rho_ao, rho_ao_resp, hfx_section, para_env, irep, use_virial, adiabatic_rescale_factor, resp_only, external_x_data)
computes four center derivatives for a full basis set and updates the forcesfock_4c arrays....
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)
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:1033
subroutine, public hfx_ri_update_forces(qs_env, ri_data, nspins, hf_fraction, rho_ao, rho_ao_resp, mos, use_virial, resp_only, rescale_factor)
the general routine that calls the relevant force code
Definition hfx_ri.F:3036
Types and set/get functions for HFX.
Definition hfx_types.F:15
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public precond_mlp
integer, parameter, public kg_tnadd_embed_ri
integer, parameter, public kg_tnadd_embed
integer, parameter, public ec_mo_solver
integer, parameter, public ot_precond_full_kinetic
integer, parameter, public kg_tnadd_atomic
integer, parameter, public do_admm_aux_exch_func_none
integer, parameter, public ls_s_sqrt_proot
integer, parameter, public ot_precond_full_single
integer, parameter, public ls_s_sqrt_ns
integer, parameter, public ot_precond_none
integer, parameter, public ot_precond_full_single_inverse
integer, parameter, public xc_none
integer, parameter, public ot_precond_s_inverse
integer, parameter, public ot_precond_full_all
integer, parameter, public ec_ls_solver
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.
Calculation of the local potential contribution of the nonadditive kinetic energy <a|V(local)|b> = <a...
subroutine, public build_tnadd_mat(kg_env, matrix_p, force, virial, calculate_forces, use_virial, qs_kind_set, atomic_kind_set, particle_set, sab_orb, dbcsr_dist)
...
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
Machine interface based on Fortran 2003 and POSIX.
Definition machine.F:17
subroutine, public m_flush(lunit)
flushes units if the &GLOBAL flag is set accordingly
Definition machine.F:106
Collection of simple mathematical functions and subroutines.
Definition mathlib.F:15
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
basic linear algebra operations for full matrixes
Define the data structure for the particle information.
Definition of physical constants:
Definition physcon.F:68
real(kind=dp), parameter, public pascal
Definition physcon.F:174
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 ...
Routines to calculate 2nd order kernels from a given response density in ao basis linear response scf...
subroutine, public build_dm_response(c0, c1, dm)
This routine builds response density in dbcsr format.
Calculate the plane wave density by collocating the primitive Gaussian functions (pgf).
subroutine, public calculate_rho_elec(matrix_p, matrix_p_kp, rho, rho_gspace, total_rho, ks_env, soft_valid, compute_tau, compute_grad, basis_type, der_type, idir, task_list_external, pw_env_external)
computes the density corresponding to a given density matrix on the grid
collects routines that calculate density matrices
subroutine, public calculate_whz_matrix(c0vec, hzm, w_matrix, focc, nocc)
Calculate the Wz matrix from the MO eigenvectors, MO eigenvalues, and the MO occupation numbers....
subroutine, public calculate_wz_matrix(mo_set, psi1, ks_matrix, w_matrix)
Calculate the response W matrix from the MO eigenvectors, MO eigenvalues, and the MO occupation numbe...
subroutine, public set_qs_env(qs_env, super_cell, mos, qmmm, qmmm_periodic, ewald_env, ewald_pw, mpools, rho_external, external_vxc, mask, scf_control, rel_control, qs_charges, ks_env, ks_qmmm_env, wf_history, scf_env, active_space, input, oce, rho_atom_set, rho0_atom_set, rho0_mpole, run_rtp, rtp, rhoz_set, rhoz_tot, ecoul_1c, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, efield, linres_control, xas_env, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, ls_scf_env, do_transport, transport_env, lri_env, lri_density, exstate_env, ec_env, dispersion_env, gcp_env, mp2_env, bs_env, kg_env, force, kpoints, wanniercentres, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, rhs)
Set the QUICKSTEP environment.
subroutine, public get_qs_env(qs_env, atomic_kind_set, qs_kind_set, cell, super_cell, cell_ref, use_ref_cell, kpoints, dft_control, mos, sab_orb, sab_all, qmmm, qmmm_periodic, sac_ae, sac_ppl, sac_lri, sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, particle_set, energy, force, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, ecoul_1c, rho0_s_rs, rho0_s_gs, do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, lri_env, lri_density, exstate_env, ec_env, dispersion_env, gcp_env, vee, rho_external, external_vxc, mask, mp2_env, bs_env, kg_env, wanniercentres, atprop, ls_scf_env, do_transport, transport_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, mscfg_env, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, rhs)
Get the QUICKSTEP environment.
subroutine, public total_qs_force(force, qs_force, atomic_kind_set)
Get current total force.
subroutine, public prepare_gapw_den(qs_env, local_rho_set, do_rho0, kind_set_external)
...
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, se_parameter, dftb_parameter, xtb_parameter, dftb3_param, 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_r3d_rs_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, 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, init_u_ramping_each_scf, reltmat, ghost, floating, name, element_symbol, pao_basis_size, 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, basis_type, total_zeff_corr)
Get attributes of an atomic kind set.
Calculation of kinetic energy matrix and forces.
Definition qs_kinetic.F:15
subroutine, public build_kinetic_matrix(ks_env, matrix_t, matrixkp_t, matrix_name, basis_type, sab_nl, calculate_forces, matrix_p, matrixkp_p, eps_filter, nderivative)
Calculation of the kinetic energy matrix over Cartesian Gaussian functions.
Definition qs_kinetic.F:101
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
routines that build the Kohn-Sham matrix (i.e calculate the coulomb and xc parts
subroutine, public calc_rho_tot_gspace(rho_tot_gspace, qs_env, rho, skip_nuclear_density)
...
localize wavefunctions linear response scf
subroutine, public linres_solver(p_env, qs_env, psi1, h1_psi0, psi0_order, iounit, should_stop)
scf loop to optimize the first order wavefunctions (psi1) given a perturbation as an operator applied...
Type definitiona for linear response calculations.
subroutine, public local_rho_set_create(local_rho_set)
...
subroutine, public local_rho_set_release(local_rho_set)
...
wrapper for the pools of matrixes
subroutine, public mpools_rebuild_fm_pools(mpools, mos, blacs_env, para_env, nmosub)
rebuilds the pools of the (ao x mo, ao x ao , mo x mo) full matrixes
collects routines that perform operations directly related to MOs
subroutine, public make_basis_sm(vmatrix, ncol, matrix_s)
returns an S-orthonormal basis v (v^T S v ==1)
Definition and initialisation of the mo data type.
Definition qs_mo_types.F:22
subroutine, public deallocate_mo_set(mo_set)
Deallocate a wavefunction data structure.
subroutine, public get_mo_set(mo_set, maxocc, homo, lfomo, nao, nelectron, n_el_f, nmo, eigenvalues, occupation_numbers, mo_coeff, mo_coeff_b, uniform_occupation, kts, mu, flexible_electron_count)
Get the components of a MO set data structure.
Define the neighbor list data types and the corresponding functionality.
Calculation of overlap matrix, its derivatives and forces.
Definition qs_overlap.F:19
subroutine, public build_overlap_matrix(ks_env, matrix_s, matrixkp_s, matrix_name, nderivative, basis_type_a, basis_type_b, sab_nl, calculate_forces, matrix_p, matrixkp_p)
Calculation of the overlap matrix over Cartesian Gaussian functions.
Definition qs_overlap.F:120
Utility functions for the perturbation calculations.
subroutine, public p_env_psi0_changed(p_env, qs_env)
To be called after the value of psi0 has changed. Recalculates the quantities S_psi0 and m_epsilon.
subroutine, public p_env_create(p_env, qs_env, p1_option, p1_admm_option, orthogonal_orbitals, linres_control)
allocates and initializes the perturbation environment (no setup)
basis types for the calculation of the perturbation of density theory.
subroutine, public p_env_release(p_env)
relases the given p_env (see doc/ReferenceCounting.html)
subroutine, public integrate_vhg0_rspace(qs_env, v_rspace, para_env, calculate_forces, local_rho_set, local_rho_set_2nd, atener, kforce)
...
subroutine, public rho0_s_grid_create(pw_env, rho0_mpole)
...
subroutine, public init_rho0(local_rho_set, qs_env, gapw_control, zcore)
...
subroutine, public allocate_rho_atom_internals(rho_atom_set, atomic_kind_set, qs_kind_set, dft_control, para_env)
...
subroutine, public calculate_rho_atom_coeff(qs_env, rho_ao, rho_atom_set, qs_kind_set, oce, sab, para_env)
...
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_tddft, do_tddfpt2, do_triplet, kind_set_external)
...
subroutine, public calculate_vxc_atom(qs_env, energy_only, exc1, gradient_atom_set, adiabatic_rescale_factor, kind_set_external, rho_atom_set_external, xc_section_external)
...
Definition qs_vxc_atom.F:87
Calculate the CPKS equation and the resulting forces.
subroutine, public response_equation_new(qs_env, p_env, cpmos, iounit)
Initializes vectors for MO-coefficient based linear response solver and calculates response density,...
subroutine, public response_force_xtb(qs_env, p_env, matrix_hz, ex_env, debug)
...
subroutine, public response_force(qs_env, vh_rspace, vxc_rspace, vtau_rspace, vadmm_rspace, matrix_hz, matrix_pz, matrix_pz_admm, matrix_wz, zehartree, zexc, zexc_aux_fit, rhopz_r, p_env, ex_env, debug)
...
subroutine, public response_equation(qs_env, p_env, cpmos, iounit, lr_section)
Initializes vectors for MO-coefficient based linear response solver and calculates response density,...
subroutine, public response_calculation(qs_env, ec_env)
Initializes solver of linear response equation for energy correction.
types for task lists
pure real(kind=dp) function, public one_third_sum_diag(a)
...
Calculation of forces for Coulomb contributions in response xTB.
subroutine, public calc_xtb_ehess_force(qs_env, matrix_p0, matrix_p1, charges0, mcharge0, charges1, mcharge1, debug_forces)
...
Calculation of Coulomb Hessian contributions in xTB.
Definition xtb_ehess.F:12
subroutine, public xtb_coulomb_hessian(qs_env, ks_matrix, charges1, mcharge1, mcharge)
...
Definition xtb_ehess.F:77
Calculation of Overlap and Hamiltonian matrices in xTB Reference: Stefan Grimme, Christoph Bannwarth,...
subroutine, public xtb_hab_force(qs_env, p_matrix)
...
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, hen, zeta, occupation, electronegativity, chmax)
...
Definition xtb_types.F:175
stores some data used in wavefunction fitting
Definition admm_types.F:120
Provides all information about an atomic kind.
Type defining parameters related to the simulation cell.
Definition cell_types.F:55
represent a blacs multidimensional parallel environment (for the mpi corrispective see cp_paratypes/m...
keeps the information about the structure of a full matrix
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...
Contains information on the energy correction functional for KG.
Contains information on the excited states energy.
stores some data used in construction of Kohn-Sham matrix
Definition hfx_types.F:509
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.
calculation environment to calculate the ks matrix, holds all the needed vars. assumes that the core ...
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.