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