(git:27c966b)
Loading...
Searching...
No Matches
qs_ks_utils.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2026 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
8! **************************************************************************************************
9!> \brief routines that build the Kohn-Sham matrix (i.e calculate the coulomb
10!> and xc parts
11!> \par History
12!> 05.2002 moved from qs_scf (see there the history) [fawzi]
13!> JGH [30.08.02] multi-grid arrays independent from density and potential
14!> 10.2002 introduced pools, uses updated rho as input,
15!> removed most temporary variables, renamed may vars,
16!> began conversion to LSD [fawzi]
17!> 10.2004 moved calculate_w_matrix here [Joost VandeVondele]
18!> introduced energy derivative wrt MOs [Joost VandeVondele]
19!> \author Fawzi Mohamed
20! **************************************************************************************************
21
23 USE admm_types, ONLY: admm_type,&
27 USE cell_types, ONLY: cell_type
29 USE cp_dbcsr_api, ONLY: &
32 USE cp_dbcsr_contrib, ONLY: dbcsr_dot,&
44 USE cp_fm_types, ONLY: cp_fm_create,&
53 USE cp_output_handling, ONLY: cp_p_file,&
59 USE hfx_types, ONLY: hfx_type
60 USE input_constants, ONLY: &
69 USE kinds, ONLY: default_string_length,&
70 dp
71 USE kpoint_types, ONLY: get_kpoint_info,&
81 USE mathlib, ONLY: abnormal_value
83 USE ps_implicit_types, ONLY: mixed_bc,&
87 USE pw_env_types, ONLY: pw_env_get,&
89 USE pw_methods, ONLY: pw_axpy,&
90 pw_copy,&
93 pw_scale,&
100 USE pw_types, ONLY: pw_c1d_gs_type,&
109 USE qs_integrate_potential, ONLY: integrate_v_rspace,&
110 integrate_v_rspace_diagonal,&
111 integrate_v_rspace_one_center
112 USE qs_kind_types, ONLY: get_qs_kind,&
115 USE qs_ks_atom, ONLY: update_ks_atom
117 USE qs_ks_types, ONLY: get_ks_env,&
119 USE qs_mo_types, ONLY: get_mo_set,&
129 USE qs_rho_types, ONLY: qs_rho_get,&
135 USE virial_types, ONLY: virial_type
136 USE xc, ONLY: xc_exc_calc,&
141#include "./base/base_uses.f90"
142
143 IMPLICIT NONE
144
145 PRIVATE
146
147 LOGICAL, PARAMETER :: debug_this_module = .true.
148 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_ks_utils'
149
153
154CONTAINS
155
156! **************************************************************************************************
157!> \brief do ROKS calculations yielding low spin states
158!> \param energy ...
159!> \param qs_env ...
160!> \param dft_control ...
161!> \param do_hfx ...
162!> \param just_energy ...
163!> \param calculate_forces ...
164!> \param auxbas_pw_pool ...
165! **************************************************************************************************
166 SUBROUTINE low_spin_roks(energy, qs_env, dft_control, do_hfx, just_energy, &
167 calculate_forces, auxbas_pw_pool)
168
169 TYPE(qs_energy_type), POINTER :: energy
170 TYPE(qs_environment_type), POINTER :: qs_env
171 TYPE(dft_control_type), POINTER :: dft_control
172 LOGICAL, INTENT(IN) :: do_hfx, just_energy, calculate_forces
173 TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
174
175 CHARACTER(*), PARAMETER :: routinen = 'low_spin_roks'
176
177 INTEGER :: handle, irep, ispin, iterm, k, k_alpha, &
178 k_beta, n_rep, nelectron, nspin, nterms
179 INTEGER, DIMENSION(:), POINTER :: ivec
180 INTEGER, DIMENSION(:, :, :), POINTER :: occupations
181 LOGICAL :: compute_tau, compute_virial, gapw, &
182 in_range, uniform_occupation, use_gauxc
183 REAL(kind=dp) :: ehfx, exc, exc1
184 REAL(kind=dp), DIMENSION(3, 3) :: virial_xc_tmp
185 REAL(kind=dp), DIMENSION(:), POINTER :: energy_scaling, rvec, scaling
186 TYPE(cell_type), POINTER :: cell
187 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_h, matrix_hfx, matrix_p, mdummy, &
188 mo_derivs, rho_ao
189 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_p2
190 TYPE(dbcsr_type), POINTER :: dbcsr_deriv, fm_deriv, fm_scaled, &
191 mo_coeff
192 TYPE(hfx_type), DIMENSION(:, :), POINTER :: x_data
193 TYPE(mo_set_type), DIMENSION(:), POINTER :: mo_array
194 TYPE(mp_para_env_type), POINTER :: para_env
195 TYPE(pw_c1d_gs_type), DIMENSION(:), POINTER :: rho_g, tau_g
196 TYPE(pw_env_type), POINTER :: pw_env
197 TYPE(pw_pool_type), POINTER :: xc_pw_pool
198 TYPE(pw_r3d_rs_type) :: work_v_rspace
199 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: rho_r, tau, vxc, vxc_tau
200 TYPE(pw_r3d_rs_type), POINTER :: weights
201 TYPE(qs_ks_env_type), POINTER :: ks_env
202 TYPE(qs_rho_type), POINTER :: rho
203 TYPE(rho_atom_type), DIMENSION(:), POINTER :: rho_atom_set
204 TYPE(section_vals_type), POINTER :: hfx_section, input, &
205 low_spin_roks_section, xc_section
206 TYPE(virial_type), POINTER :: virial
207 TYPE(xc_rho_cflags_type) :: needs
208
209 IF (.NOT. dft_control%low_spin_roks) RETURN
210
211 CALL timeset(routinen, handle)
212
213 NULLIFY (ks_env, rho_ao, rho_atom_set)
214 gapw = dft_control%qs_control%gapw
215 use_gauxc = gapw .AND. dft_control%use_gauxc
216 compute_tau = .false.
217
218 ! Test for not compatible options
219 IF (dft_control%qs_control%gapw_xc) THEN
220 CALL cp_abort(__location__, "GAPW_XC is not compatible with low spin ROKS method.")
221 END IF
222 IF (dft_control%do_admm) THEN
223 CALL cp_abort(__location__, "ADMM not compatible with low spin ROKS method.")
224 END IF
225 IF (dft_control%do_admm) THEN
226 IF (qs_env%admm_env%aux_exch_func /= do_admm_aux_exch_func_none) THEN
227 CALL cp_abort(__location__, "ADMM with XC correction functional "// &
228 "not compatible with low spin ROKS method.")
229 END IF
230 END IF
231 IF (dft_control%qs_control%semi_empirical .OR. dft_control%qs_control%dftb .OR. &
232 dft_control%qs_control%xtb) THEN
233 CALL cp_abort(__location__, "SE/xTB/DFTB are not compatible with low spin ROKS method.")
234 END IF
235
236 CALL get_qs_env(qs_env, &
237 ks_env=ks_env, &
238 mo_derivs=mo_derivs, &
239 mos=mo_array, &
240 rho=rho, &
241 pw_env=pw_env, &
242 xcint_weights=weights, &
243 input=input, &
244 cell=cell, &
245 virial=virial)
246
247 CALL qs_rho_get(rho, rho_ao=rho_ao)
248
249 compute_virial = virial%pv_calculate .AND. (.NOT. virial%pv_numer)
250 xc_section => section_vals_get_subs_vals(input, "DFT%XC")
251 hfx_section => section_vals_get_subs_vals(input, "DFT%XC%HF")
252
253 IF (gapw) THEN
254 IF (compute_virial) cpabort("GAPW low spin ROKS stress is not implemented.")
255 IF (calculate_forces) cpabort("GAPW low spin ROKS forces are not implemented.")
256 IF (.NOT. use_gauxc) THEN
257 needs = xc_functionals_get_needs(section_vals_get_subs_vals(xc_section, "XC_FUNCTIONAL"), &
258 lsd=.true., calc_potential=.true.)
259 compute_tau = needs%tau .OR. needs%tau_spin
260 END IF
261 END IF
262
263 ! The configuration corrections currently use unweighted grid integration.
264 IF (ASSOCIATED(weights)) THEN
265 CALL cp_abort(__location__, "No accurate xc integration possible.")
266 END IF
267 ! some assumptions need to be checked
268 ! we have two spins
269 cpassert(SIZE(mo_array, 1) == 2)
270 nspin = 2
271 ! we want uniform occupations
272 CALL get_mo_set(mo_set=mo_array(1), uniform_occupation=uniform_occupation)
273 cpassert(uniform_occupation)
274 CALL get_mo_set(mo_set=mo_array(2), mo_coeff_b=mo_coeff, uniform_occupation=uniform_occupation)
275 cpassert(uniform_occupation)
276 IF (do_hfx .AND. calculate_forces .AND. compute_virial) THEN
277 CALL cp_abort(__location__, "ROKS virial with HFX not available.")
278 END IF
279
280 NULLIFY (dbcsr_deriv)
281 CALL dbcsr_init_p(dbcsr_deriv)
282 CALL dbcsr_copy(dbcsr_deriv, mo_derivs(1)%matrix)
283 CALL dbcsr_set(dbcsr_deriv, 0.0_dp)
284
285 ! basic info
286 CALL get_mo_set(mo_set=mo_array(1), mo_coeff_b=mo_coeff)
287 CALL dbcsr_get_info(mo_coeff, nfullcols_total=k_alpha)
288 CALL get_mo_set(mo_set=mo_array(2), mo_coeff_b=mo_coeff)
289 CALL dbcsr_get_info(mo_coeff, nfullcols_total=k_beta)
290
291 ! read the input
292 low_spin_roks_section => section_vals_get_subs_vals(input, "DFT%LOW_SPIN_ROKS")
293
294 CALL section_vals_val_get(low_spin_roks_section, "ENERGY_SCALING", r_vals=rvec)
295 nterms = SIZE(rvec)
296 ALLOCATE (energy_scaling(nterms))
297 energy_scaling = rvec !? just wondering, should this add up to 1, in which case we should cpp?
298
299 CALL section_vals_val_get(low_spin_roks_section, "SPIN_CONFIGURATION", n_rep_val=n_rep)
300 cpassert(n_rep == nterms)
301 CALL section_vals_val_get(low_spin_roks_section, "SPIN_CONFIGURATION", i_rep_val=1, i_vals=ivec)
302 nelectron = SIZE(ivec)
303 cpassert(nelectron == k_alpha - k_beta)
304 ALLOCATE (occupations(2, nelectron, nterms))
305 occupations = 0
306 DO iterm = 1, nterms
307 CALL section_vals_val_get(low_spin_roks_section, "SPIN_CONFIGURATION", i_rep_val=iterm, i_vals=ivec)
308 cpassert(nelectron == SIZE(ivec))
309 in_range = all(ivec >= 1) .AND. all(ivec <= 2)
310 cpassert(in_range)
311 DO k = 1, nelectron
312 occupations(ivec(k), k, iterm) = 1
313 END DO
314 END DO
315
316 ! set up general data structures
317 ! density matrices, kohn-sham matrices
318
319 NULLIFY (matrix_p)
320 CALL dbcsr_allocate_matrix_set(matrix_p, nspin)
321 DO ispin = 1, nspin
322 ALLOCATE (matrix_p(ispin)%matrix)
323 CALL dbcsr_copy(matrix_p(ispin)%matrix, rho_ao(1)%matrix, &
324 name="density matrix low spin roks")
325 CALL dbcsr_set(matrix_p(ispin)%matrix, 0.0_dp)
326 END DO
327
328 NULLIFY (matrix_h)
329 IF (.NOT. use_gauxc) THEN
330 CALL dbcsr_allocate_matrix_set(matrix_h, nspin)
331 DO ispin = 1, nspin
332 ALLOCATE (matrix_h(ispin)%matrix)
333 CALL dbcsr_copy(matrix_h(ispin)%matrix, rho_ao(1)%matrix, &
334 name="KS matrix low spin roks")
335 CALL dbcsr_set(matrix_h(ispin)%matrix, 0.0_dp)
336 END DO
337 END IF
338
339 IF (do_hfx) THEN
340 NULLIFY (matrix_hfx)
341 CALL dbcsr_allocate_matrix_set(matrix_hfx, nspin)
342 DO ispin = 1, nspin
343 ALLOCATE (matrix_hfx(ispin)%matrix)
344 CALL dbcsr_copy(matrix_hfx(ispin)%matrix, rho_ao(1)%matrix, &
345 name="HFX matrix low spin roks")
346 END DO
347 END IF
348
349 ! grids in real and g space for rho and vxc
350 ! GAPW meta-GGAs need the kinetic-energy density of each configuration.
351 NULLIFY (rho_r, rho_g, tau, tau_g, vxc_tau, vxc)
352 CALL pw_env_get(pw_env, xc_pw_pool=xc_pw_pool)
353
354 IF (.NOT. use_gauxc) THEN
355 ALLOCATE (rho_r(nspin))
356 ALLOCATE (rho_g(nspin))
357 IF (compute_tau) ALLOCATE (tau(nspin), tau_g(nspin))
358 DO ispin = 1, nspin
359 CALL auxbas_pw_pool%create_pw(rho_r(ispin))
360 CALL auxbas_pw_pool%create_pw(rho_g(ispin))
361 IF (compute_tau) THEN
362 CALL auxbas_pw_pool%create_pw(tau(ispin))
363 CALL auxbas_pw_pool%create_pw(tau_g(ispin))
364 END IF
365 END DO
366 CALL auxbas_pw_pool%create_pw(work_v_rspace)
367 END IF
368
369 ! get mo matrices needed to construct the density matrices
370 ! we will base all on the alpha spin matrix, obviously possible in ROKS
371 CALL get_mo_set(mo_set=mo_array(1), mo_coeff_b=mo_coeff)
372 NULLIFY (fm_scaled, fm_deriv)
373 CALL dbcsr_init_p(fm_scaled)
374 CALL dbcsr_init_p(fm_deriv)
375 CALL dbcsr_copy(fm_scaled, mo_coeff)
376 CALL dbcsr_copy(fm_deriv, mo_coeff)
377
378 ALLOCATE (scaling(k_alpha))
379
380 ! for each term, add it with the given scaling factor to the energy, and compute the required derivatives
381 DO iterm = 1, nterms
382
383 DO ispin = 1, nspin
384 ! compute the proper density matrices with the required occupations
385 CALL dbcsr_set(matrix_p(ispin)%matrix, 0.0_dp)
386 scaling = 1.0_dp
387 scaling(k_alpha - nelectron + 1:k_alpha) = occupations(ispin, :, iterm)
388 CALL dbcsr_copy(fm_scaled, mo_coeff)
389 CALL dbcsr_scale_by_vector(fm_scaled, scaling, side='right')
390 CALL dbcsr_multiply('n', 't', 1.0_dp, mo_coeff, fm_scaled, &
391 0.0_dp, matrix_p(ispin)%matrix, retain_sparsity=.true.)
392 IF (.NOT. use_gauxc) THEN
393 ! compute the densities on the grid
394 CALL calculate_rho_elec(matrix_p=matrix_p(ispin)%matrix, &
395 rho=rho_r(ispin), rho_gspace=rho_g(ispin), &
396 ks_env=ks_env, soft_valid=gapw)
397 IF (compute_tau) THEN
398 CALL calculate_rho_elec(matrix_p=matrix_p(ispin)%matrix, &
399 rho=tau(ispin), rho_gspace=tau_g(ispin), &
400 ks_env=ks_env, soft_valid=gapw, compute_tau=.true.)
401 END IF
402 END IF
403 END DO
404
405 IF (gapw .AND. .NOT. use_gauxc) THEN
406 CALL low_spin_roks_gapw_xc(qs_env, matrix_p, rho_atom_set, xc_section, just_energy, exc1)
407 energy%exc1 = energy%exc1 + energy_scaling(iterm)*exc1
408 END IF
409
410 ! GauXC evaluates each configuration on the complete molecular AO density.
411 ! Its matrix already contains all rho/gradient/tau/model-chain derivatives.
412 IF (use_gauxc) THEN
413 IF (ASSOCIATED(matrix_h)) CALL dbcsr_deallocate_matrix_set(matrix_h)
414 matrix_p2(1:nspin, 1:1) => matrix_p(1:nspin)
415 CALL apply_gauxc(qs_env, xc_section, .false., rho_ao_external=matrix_p2, &
416 exc_external=exc, matrix_vxc_external=matrix_h)
417 ELSE IF (just_energy) THEN
418 exc = xc_exc_calc(rho_r=rho_r, rho_g=rho_g, tau=tau, xc_section=xc_section, &
419 weights=weights, pw_pool=xc_pw_pool)
420 ELSE
421 cpassert(.NOT. compute_virial)
422 CALL xc_vxc_pw_create(vxc_rho=vxc, rho_r=rho_r, &
423 rho_g=rho_g, tau=tau, vxc_tau=vxc_tau, exc=exc, xc_section=xc_section, &
424 weights=weights, pw_pool=xc_pw_pool, &
425 compute_virial=.false., virial_xc=virial_xc_tmp)
426 END IF
427
428 energy%exc = energy%exc + energy_scaling(iterm)*exc
429
430 IF (do_hfx) THEN
431 ! Add Hartree-Fock contribution
432 DO ispin = 1, nspin
433 CALL dbcsr_set(matrix_hfx(ispin)%matrix, 0.0_dp)
434 END DO
435 ehfx = energy%ex
436 CALL tddft_hfx_matrix(matrix_hfx, matrix_p, qs_env, &
437 recalc_integrals=.false., update_energy=.true.)
438 energy%ex = ehfx + energy_scaling(iterm)*energy%ex
439 END IF
440
441 ! add the corresponding derivatives to the MO derivatives
442 IF (.NOT. just_energy) THEN
443 IF (use_gauxc) THEN
444 DO ispin = 1, nspin
445 CALL dbcsr_scale(matrix_h(ispin)%matrix, energy_scaling(iterm))
446 END DO
447 ELSE
448 ! get the potential in matrix form
449 DO ispin = 1, nspin
450 CALL dbcsr_set(matrix_h(ispin)%matrix, 0.0_dp)
451 ! use a work_v_rspace
452 CALL pw_axpy(vxc(ispin), work_v_rspace, energy_scaling(iterm)*vxc(ispin)%pw_grid%dvol, 0.0_dp)
453 CALL integrate_v_rspace(v_rspace=work_v_rspace, pmat=matrix_p(ispin), hmat=matrix_h(ispin), &
454 qs_env=qs_env, calculate_forces=calculate_forces, gapw=gapw)
455 CALL auxbas_pw_pool%give_back_pw(vxc(ispin))
456 IF (ASSOCIATED(vxc_tau)) THEN
457 CALL pw_axpy(vxc_tau(ispin), work_v_rspace, &
458 energy_scaling(iterm)*vxc_tau(ispin)%pw_grid%dvol, 0.0_dp)
459 CALL integrate_v_rspace(v_rspace=work_v_rspace, pmat=matrix_p(ispin), hmat=matrix_h(ispin), &
460 qs_env=qs_env, calculate_forces=.false., gapw=gapw, compute_tau=.true.)
461 CALL auxbas_pw_pool%give_back_pw(vxc_tau(ispin))
462 END IF
463 END DO
464 DEALLOCATE (vxc)
465 IF (ASSOCIATED(vxc_tau)) DEALLOCATE (vxc_tau)
466
467 IF (gapw) THEN
468 CALL update_ks_atom(qs_env, matrix_h, matrix_p, .false., &
469 rho_atom_external=rho_atom_set, kscale=energy_scaling(iterm))
470 END IF
471 END IF
472
473 IF (do_hfx) THEN
474 ! add HFX contribution
475 DO ispin = 1, nspin
476 CALL dbcsr_add(matrix_h(ispin)%matrix, matrix_hfx(ispin)%matrix, &
477 1.0_dp, energy_scaling(iterm))
478 END DO
479 IF (calculate_forces) THEN
480 CALL get_qs_env(qs_env, x_data=x_data, para_env=para_env)
481 IF (x_data(1, 1)%n_rep_hf /= 1) THEN
482 CALL cp_abort(__location__, "Multiple HFX section forces not compatible "// &
483 "with low spin ROKS method.")
484 END IF
485 IF (x_data(1, 1)%do_hfx_ri) THEN
486 CALL cp_abort(__location__, "HFX_RI forces not compatible with low spin ROKS method.")
487 ELSE
488 irep = 1
489 NULLIFY (mdummy)
490 matrix_p2(1:nspin, 1:1) => matrix_p(1:nspin)
491 CALL derivatives_four_center(qs_env, matrix_p2, mdummy, hfx_section, para_env, &
492 irep, compute_virial, &
493 adiabatic_rescale_factor=energy_scaling(iterm))
494 END IF
495 END IF
496
497 END IF
498
499 ! add this to the mo_derivs, again based on the alpha mo_coeff
500 DO ispin = 1, nspin
501 CALL dbcsr_multiply('n', 'n', 1.0_dp, matrix_h(ispin)%matrix, mo_coeff, &
502 0.0_dp, dbcsr_deriv, last_column=k_alpha)
503
504 scaling = 1.0_dp
505 scaling(k_alpha - nelectron + 1:k_alpha) = occupations(ispin, :, iterm)
506 CALL dbcsr_scale_by_vector(dbcsr_deriv, scaling, side='right')
507 CALL dbcsr_add(mo_derivs(1)%matrix, dbcsr_deriv, 1.0_dp, 1.0_dp)
508 END DO
509
510 END IF
511
512 END DO
513
514 ! release allocated memory
515 IF (.NOT. use_gauxc) THEN
516 DO ispin = 1, nspin
517 CALL auxbas_pw_pool%give_back_pw(rho_r(ispin))
518 CALL auxbas_pw_pool%give_back_pw(rho_g(ispin))
519 IF (compute_tau) THEN
520 CALL auxbas_pw_pool%give_back_pw(tau(ispin))
521 CALL auxbas_pw_pool%give_back_pw(tau_g(ispin))
522 END IF
523 END DO
524 DEALLOCATE (rho_r, rho_g)
525 IF (compute_tau) DEALLOCATE (tau, tau_g)
526 CALL auxbas_pw_pool%give_back_pw(work_v_rspace)
527 END IF
528 CALL dbcsr_deallocate_matrix_set(matrix_p)
529 IF (ASSOCIATED(matrix_h)) CALL dbcsr_deallocate_matrix_set(matrix_h)
530 IF (do_hfx) THEN
531 CALL dbcsr_deallocate_matrix_set(matrix_hfx)
532 END IF
533
534 CALL dbcsr_release_p(fm_deriv)
535 CALL dbcsr_release_p(fm_scaled)
536
537 DEALLOCATE (occupations)
538 DEALLOCATE (energy_scaling)
539 DEALLOCATE (scaling)
540
541 CALL dbcsr_release_p(dbcsr_deriv)
542
543 IF (ASSOCIATED(rho_atom_set)) CALL deallocate_rho_atom_set(rho_atom_set)
544
545 CALL timestop(handle)
546
547 END SUBROUTINE low_spin_roks
548
549! **************************************************************************************************
550!> \brief Evaluate the atomic XC correction for one low-spin ROKS configuration.
551!> Keep atomic densities and potential integrals separate from the reference
552!> state. All configurations share the total density, so no electrostatic
553!> correction or compensation-charge update is needed here.
554!> \param qs_env Quickstep environment
555!> \param matrix_p Spin density matrices of the configuration
556!> \param rho_atom_set Scratch atomic densities and XC potential integrals
557!> \param xc_section Exchange-correlation input
558!> \param just_energy Skip potential integrals when only the energy is requested
559!> \param exc1 Atomic hard-minus-soft XC energy
560! **************************************************************************************************
561 SUBROUTINE low_spin_roks_gapw_xc(qs_env, matrix_p, rho_atom_set, xc_section, just_energy, exc1)
562 TYPE(qs_environment_type), POINTER :: qs_env
563 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_p
564 TYPE(rho_atom_type), DIMENSION(:), POINTER :: rho_atom_set
565 TYPE(section_vals_type), POINTER :: xc_section
566 LOGICAL, INTENT(IN) :: just_energy
567 REAL(kind=dp), INTENT(OUT) :: exc1
568
569 INTEGER :: ikind, natom
570 INTEGER, DIMENSION(:), POINTER :: atom_list
571 LOGICAL :: paw_atom
572 REAL(kind=dp) :: hard_abs_spin, hard_spin, soft_abs_spin, &
573 soft_spin
574 REAL(kind=dp), DIMENSION(2) :: hard_total, soft_total
575 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
576 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_p2
577 TYPE(dft_control_type), POINTER :: dft_control
578 TYPE(mp_para_env_type), POINTER :: para_env
579 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
580 POINTER :: sab
581 TYPE(oce_matrix_type), POINTER :: oce
582 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
583
584 CALL get_qs_env(qs_env, atomic_kind_set=atomic_kind_set, qs_kind_set=qs_kind_set, &
585 dft_control=dft_control, para_env=para_env, oce=oce, sab_orb=sab)
586 cpassert(dft_control%nspins == 2)
587 cpassert(dft_control%nimages == 1)
588 IF (.NOT. ASSOCIATED(rho_atom_set)) THEN
589 CALL allocate_rho_atom_internals(rho_atom_set, atomic_kind_set, qs_kind_set, dft_control, para_env)
590 END IF
591 matrix_p2(1:2, 1:1) => matrix_p
592 CALL calculate_rho_atom_coeff(qs_env, matrix_p2, rho_atom_set, qs_kind_set, oce, sab, para_env)
593
594 ! Only local diagnostics: do not overwrite the reference charge summaries.
595 hard_total = 0.0_dp
596 soft_total = 0.0_dp
597 hard_spin = 0.0_dp
598 soft_spin = 0.0_dp
599 hard_abs_spin = 0.0_dp
600 soft_abs_spin = 0.0_dp
601 DO ikind = 1, SIZE(atomic_kind_set)
602 CALL get_atomic_kind(atomic_kind_set(ikind), atom_list=atom_list, natom=natom)
603 CALL get_qs_kind(qs_kind_set(ikind), paw_atom=paw_atom)
604 IF (paw_atom) THEN
605 CALL calculate_rho_atom(para_env, rho_atom_set, qs_kind_set(ikind), atom_list, natom, 2, &
606 hard_total, soft_total, hard_spin, soft_spin, hard_abs_spin, soft_abs_spin)
607 END IF
608 END DO
609 CALL zero_rho_atom_integrals(rho_atom_set)
610 exc1 = 0.0_dp
611 CALL calculate_vxc_atom(qs_env, just_energy, exc1, rho_atom_set_external=rho_atom_set, &
612 xc_section_external=xc_section, calculate_forces=.false.)
613 END SUBROUTINE low_spin_roks_gapw_xc
614
615! **************************************************************************************************
616!> \brief do sic calculations on explicit orbitals
617!> \param energy ...
618!> \param qs_env ...
619!> \param dft_control ...
620!> \param poisson_env ...
621!> \param just_energy ...
622!> \param calculate_forces ...
623!> \param auxbas_pw_pool ...
624! **************************************************************************************************
625 SUBROUTINE sic_explicit_orbitals(energy, qs_env, dft_control, poisson_env, just_energy, &
626 calculate_forces, auxbas_pw_pool)
627
628 TYPE(qs_energy_type), POINTER :: energy
629 TYPE(qs_environment_type), POINTER :: qs_env
630 TYPE(dft_control_type), POINTER :: dft_control
631 TYPE(pw_poisson_type), POINTER :: poisson_env
632 LOGICAL, INTENT(IN) :: just_energy, calculate_forces
633 TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
634
635 CHARACTER(*), PARAMETER :: routinen = 'sic_explicit_orbitals'
636
637 INTEGER :: handle, i, iorb, k_alpha, k_beta, norb
638 INTEGER, ALLOCATABLE, DIMENSION(:, :) :: sic_orbital_list
639 LOGICAL :: compute_virial, uniform_occupation
640 REAL(kind=dp) :: ener, exc
641 REAL(kind=dp), DIMENSION(3, 3) :: virial_xc_tmp
642 TYPE(cell_type), POINTER :: cell
643 TYPE(cp_fm_struct_type), POINTER :: fm_struct_tmp
644 TYPE(cp_fm_type) :: matrix_hv, matrix_v
645 TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:) :: mo_derivs_local
646 TYPE(cp_fm_type), POINTER :: mo_coeff
647 TYPE(dbcsr_p_type) :: orb_density_matrix_p, orb_h_p
648 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: mo_derivs, rho_ao, tmp_dbcsr
649 TYPE(dbcsr_type), POINTER :: orb_density_matrix, orb_h
650 TYPE(mo_set_type), DIMENSION(:), POINTER :: mo_array
651 TYPE(pw_c1d_gs_type) :: work_v_gspace
652 TYPE(pw_c1d_gs_type), DIMENSION(:), POINTER :: rho_g
653 TYPE(pw_c1d_gs_type), TARGET :: orb_rho_g, tmp_g
654 TYPE(pw_env_type), POINTER :: pw_env
655 TYPE(pw_pool_type), POINTER :: xc_pw_pool
656 TYPE(pw_r3d_rs_type) :: work_v_rspace
657 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: rho_r, tau, vxc, vxc_tau
658 TYPE(pw_r3d_rs_type), POINTER :: weights
659 TYPE(pw_r3d_rs_type), TARGET :: orb_rho_r, tmp_r
660 TYPE(qs_ks_env_type), POINTER :: ks_env
661 TYPE(qs_rho_type), POINTER :: rho
662 TYPE(section_vals_type), POINTER :: input, xc_section
663 TYPE(virial_type), POINTER :: virial
664
665 IF (dft_control%sic_method_id /= sic_eo) RETURN
666
667 CALL timeset(routinen, handle)
668
669 NULLIFY (tau, vxc_tau, mo_derivs, ks_env, rho_ao)
670
671 ! generate the lists of orbitals that need sic treatment
672 CALL get_qs_env(qs_env, &
673 ks_env=ks_env, &
674 mo_derivs=mo_derivs, &
675 mos=mo_array, &
676 rho=rho, &
677 xcint_weights=weights, &
678 pw_env=pw_env, &
679 input=input, &
680 cell=cell, &
681 virial=virial)
682
683 CALL qs_rho_get(rho, rho_ao=rho_ao)
684
685 compute_virial = virial%pv_calculate .AND. (.NOT. virial%pv_numer)
686 xc_section => section_vals_get_subs_vals(input, "DFT%XC")
687
688 DO i = 1, SIZE(mo_array) !fm->dbcsr
689 IF (mo_array(i)%use_mo_coeff_b) THEN !fm->dbcsr
690 CALL copy_dbcsr_to_fm(mo_array(i)%mo_coeff_b, &
691 mo_array(i)%mo_coeff) !fm->dbcsr
692 END IF !fm->dbcsr
693 END DO !fm->dbcsr
694
695 CALL pw_env_get(pw_env, xc_pw_pool=xc_pw_pool)
696
697 ! we have two spins
698 cpassert(SIZE(mo_array, 1) == 2)
699 ! we want uniform occupations
700 CALL get_mo_set(mo_set=mo_array(1), uniform_occupation=uniform_occupation)
701 cpassert(uniform_occupation)
702 CALL get_mo_set(mo_set=mo_array(2), mo_coeff=mo_coeff, uniform_occupation=uniform_occupation)
703 cpassert(uniform_occupation)
704
705 NULLIFY (tmp_dbcsr)
706 CALL dbcsr_allocate_matrix_set(tmp_dbcsr, SIZE(mo_derivs, 1))
707 DO i = 1, SIZE(mo_derivs, 1) !fm->dbcsr
708 !
709 NULLIFY (tmp_dbcsr(i)%matrix)
710 CALL dbcsr_init_p(tmp_dbcsr(i)%matrix)
711 CALL dbcsr_copy(tmp_dbcsr(i)%matrix, mo_derivs(i)%matrix)
712 CALL dbcsr_set(tmp_dbcsr(i)%matrix, 0.0_dp)
713 END DO !fm->dbcsr
714
715 k_alpha = 0; k_beta = 0
716 SELECT CASE (dft_control%sic_list_id)
717 CASE (sic_list_all)
718
719 CALL get_mo_set(mo_set=mo_array(1), mo_coeff=mo_coeff)
720 CALL cp_fm_get_info(mo_coeff, ncol_global=k_alpha)
721
722 IF (SIZE(mo_array, 1) > 1) THEN
723 CALL get_mo_set(mo_set=mo_array(2), mo_coeff=mo_coeff)
724 CALL cp_fm_get_info(mo_coeff, ncol_global=k_beta)
725 END IF
726
727 norb = k_alpha + k_beta
728 ALLOCATE (sic_orbital_list(3, norb))
729
730 iorb = 0
731 DO i = 1, k_alpha
732 iorb = iorb + 1
733 sic_orbital_list(1, iorb) = 1
734 sic_orbital_list(2, iorb) = i
735 sic_orbital_list(3, iorb) = 1
736 END DO
737 DO i = 1, k_beta
738 iorb = iorb + 1
739 sic_orbital_list(1, iorb) = 2
740 sic_orbital_list(2, iorb) = i
741 IF (SIZE(mo_derivs, 1) == 1) THEN
742 sic_orbital_list(3, iorb) = 1
743 ELSE
744 sic_orbital_list(3, iorb) = 2
745 END IF
746 END DO
747
748 CASE (sic_list_unpaired)
749 ! we have two spins
750 cpassert(SIZE(mo_array, 1) == 2)
751 ! we have them restricted
752 cpassert(SIZE(mo_derivs, 1) == 1)
753 cpassert(dft_control%restricted)
754
755 CALL get_mo_set(mo_set=mo_array(1), mo_coeff=mo_coeff)
756 CALL cp_fm_get_info(mo_coeff, ncol_global=k_alpha)
757
758 CALL get_mo_set(mo_set=mo_array(2), mo_coeff=mo_coeff)
759 CALL cp_fm_get_info(mo_coeff, ncol_global=k_beta)
760
761 norb = k_alpha - k_beta
762 ALLOCATE (sic_orbital_list(3, norb))
763
764 iorb = 0
765 DO i = k_beta + 1, k_alpha
766 iorb = iorb + 1
767 sic_orbital_list(1, iorb) = 1
768 sic_orbital_list(2, iorb) = i
769 ! we are guaranteed to be restricted
770 sic_orbital_list(3, iorb) = 1
771 END DO
772
773 CASE DEFAULT
774 cpabort("Unknown dft_control%sic_list_id")
775 END SELECT
776
777 ! data needed for each of the orbs
778 CALL auxbas_pw_pool%create_pw(orb_rho_r)
779 CALL auxbas_pw_pool%create_pw(tmp_r)
780 CALL auxbas_pw_pool%create_pw(orb_rho_g)
781 CALL auxbas_pw_pool%create_pw(tmp_g)
782 CALL auxbas_pw_pool%create_pw(work_v_gspace)
783 CALL auxbas_pw_pool%create_pw(work_v_rspace)
784
785 ALLOCATE (orb_density_matrix)
786 CALL dbcsr_copy(orb_density_matrix, rho_ao(1)%matrix, &
787 name="orb_density_matrix")
788 CALL dbcsr_set(orb_density_matrix, 0.0_dp)
789 orb_density_matrix_p%matrix => orb_density_matrix
790
791 ALLOCATE (orb_h)
792 CALL dbcsr_copy(orb_h, rho_ao(1)%matrix, &
793 name="orb_density_matrix")
794 CALL dbcsr_set(orb_h, 0.0_dp)
795 orb_h_p%matrix => orb_h
796
797 CALL get_mo_set(mo_set=mo_array(1), mo_coeff=mo_coeff)
798
799 CALL cp_fm_struct_create(fm_struct_tmp, ncol_global=1, &
800 template_fmstruct=mo_coeff%matrix_struct)
801 CALL cp_fm_create(matrix_v, fm_struct_tmp, name="matrix_v")
802 CALL cp_fm_create(matrix_hv, fm_struct_tmp, name="matrix_hv")
803 CALL cp_fm_struct_release(fm_struct_tmp)
804
805 ALLOCATE (mo_derivs_local(SIZE(mo_array, 1)))
806 DO i = 1, SIZE(mo_array, 1)
807 CALL get_mo_set(mo_set=mo_array(i), mo_coeff=mo_coeff)
808 CALL cp_fm_create(mo_derivs_local(i), mo_coeff%matrix_struct)
809 END DO
810
811 ALLOCATE (rho_r(2))
812 rho_r(1) = orb_rho_r
813 rho_r(2) = tmp_r
814 CALL pw_zero(tmp_r)
815
816 ALLOCATE (rho_g(2))
817 rho_g(1) = orb_rho_g
818 rho_g(2) = tmp_g
819 CALL pw_zero(tmp_g)
820
821 NULLIFY (vxc)
822 ! now apply to SIC correction to each selected orbital
823 DO iorb = 1, norb
824 ! extract the proper orbital from the mo_coeff
825 CALL get_mo_set(mo_set=mo_array(sic_orbital_list(1, iorb)), mo_coeff=mo_coeff)
826 CALL cp_fm_to_fm(mo_coeff, matrix_v, 1, sic_orbital_list(2, iorb), 1)
827
828 ! construct the density matrix and the corresponding density
829 CALL dbcsr_set(orb_density_matrix, 0.0_dp)
830 CALL cp_dbcsr_plus_fm_fm_t(orb_density_matrix, matrix_v=matrix_v, ncol=1, &
831 alpha=1.0_dp)
832
833 CALL calculate_rho_elec(matrix_p=orb_density_matrix, &
834 rho=orb_rho_r, rho_gspace=orb_rho_g, &
835 ks_env=ks_env)
836
837 ! compute the energy functional for this orbital and its derivative
838
839 CALL pw_poisson_solve(poisson_env, orb_rho_g, ener, work_v_gspace)
840 ! no PBC correction is done here, see "calc_v_sic_rspace" for SIC methods
841 ! with PBC aware corrections
842 energy%hartree = energy%hartree - dft_control%sic_scaling_a*ener
843 IF (.NOT. just_energy) THEN
844 CALL pw_transfer(work_v_gspace, work_v_rspace)
845 CALL pw_scale(work_v_rspace, -dft_control%sic_scaling_a*work_v_rspace%pw_grid%dvol)
846 CALL dbcsr_set(orb_h, 0.0_dp)
847 END IF
848
849 IF (just_energy) THEN
850 exc = xc_exc_calc(rho_r=rho_r, rho_g=rho_g, tau=tau, xc_section=xc_section, &
851 weights=weights, pw_pool=xc_pw_pool)
852 ELSE
853 cpassert(.NOT. compute_virial)
854 CALL xc_vxc_pw_create(vxc_rho=vxc, rho_r=rho_r, &
855 rho_g=rho_g, tau=tau, vxc_tau=vxc_tau, exc=exc, xc_section=xc_section, &
856 weights=weights, pw_pool=xc_pw_pool, &
857 compute_virial=compute_virial, virial_xc=virial_xc_tmp)
858 ! add to the existing work_v_rspace
859 CALL pw_axpy(vxc(1), work_v_rspace, -dft_control%sic_scaling_b*vxc(1)%pw_grid%dvol)
860 END IF
861 energy%exc = energy%exc - dft_control%sic_scaling_b*exc
862
863 IF (.NOT. just_energy) THEN
864 ! note, orb_h (which is being pointed to with orb_h_p) is zeroed above
865 CALL integrate_v_rspace(v_rspace=work_v_rspace, pmat=orb_density_matrix_p, hmat=orb_h_p, &
866 qs_env=qs_env, calculate_forces=calculate_forces)
867
868 ! add this to the mo_derivs
869 CALL cp_dbcsr_sm_fm_multiply(orb_h, matrix_v, matrix_hv, 1)
870 ! silly trick, copy to an array of the right size and add to mo_derivs
871 CALL cp_fm_set_all(mo_derivs_local(sic_orbital_list(3, iorb)), 0.0_dp)
872 CALL cp_fm_to_fm(matrix_hv, mo_derivs_local(sic_orbital_list(3, iorb)), 1, 1, sic_orbital_list(2, iorb))
873 CALL copy_fm_to_dbcsr(mo_derivs_local(sic_orbital_list(3, iorb)), &
874 tmp_dbcsr(sic_orbital_list(3, iorb))%matrix)
875 CALL dbcsr_add(mo_derivs(sic_orbital_list(3, iorb))%matrix, &
876 tmp_dbcsr(sic_orbital_list(3, iorb))%matrix, 1.0_dp, 1.0_dp)
877 !
878 ! need to deallocate vxc
879 CALL xc_pw_pool%give_back_pw(vxc(1))
880 CALL xc_pw_pool%give_back_pw(vxc(2))
881 DEALLOCATE (vxc)
882
883 END IF
884
885 END DO
886
887 CALL auxbas_pw_pool%give_back_pw(orb_rho_r)
888 CALL auxbas_pw_pool%give_back_pw(tmp_r)
889 CALL auxbas_pw_pool%give_back_pw(orb_rho_g)
890 CALL auxbas_pw_pool%give_back_pw(tmp_g)
891 CALL auxbas_pw_pool%give_back_pw(work_v_gspace)
892 CALL auxbas_pw_pool%give_back_pw(work_v_rspace)
893
894 CALL dbcsr_deallocate_matrix(orb_density_matrix)
895 CALL dbcsr_deallocate_matrix(orb_h)
896 CALL cp_fm_release(matrix_v)
897 CALL cp_fm_release(matrix_hv)
898 CALL cp_fm_release(mo_derivs_local)
899 DEALLOCATE (rho_r)
900 DEALLOCATE (rho_g)
901
902 CALL dbcsr_deallocate_matrix_set(tmp_dbcsr) !fm->dbcsr
903
904 CALL timestop(handle)
905
906 END SUBROUTINE sic_explicit_orbitals
907
908! **************************************************************************************************
909!> \brief do sic calculations on the spin density
910!> \param v_sic_rspace ...
911!> \param energy ...
912!> \param qs_env ...
913!> \param dft_control ...
914!> \param rho ...
915!> \param poisson_env ...
916!> \param just_energy ...
917!> \param calculate_forces ...
918!> \param auxbas_pw_pool ...
919! **************************************************************************************************
920 SUBROUTINE calc_v_sic_rspace(v_sic_rspace, energy, &
921 qs_env, dft_control, rho, poisson_env, just_energy, &
922 calculate_forces, auxbas_pw_pool)
923
924 TYPE(pw_r3d_rs_type), POINTER :: v_sic_rspace
925 TYPE(qs_energy_type), POINTER :: energy
926 TYPE(qs_environment_type), POINTER :: qs_env
927 TYPE(dft_control_type), POINTER :: dft_control
928 TYPE(qs_rho_type), POINTER :: rho
929 TYPE(pw_poisson_type), POINTER :: poisson_env
930 LOGICAL, INTENT(IN) :: just_energy, calculate_forces
931 TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
932
933 INTEGER :: i, nelec, nelec_a, nelec_b, nforce
934 REAL(kind=dp) :: ener, full_scaling, scaling
935 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :) :: store_forces
936 TYPE(mo_set_type), DIMENSION(:), POINTER :: mo_array
937 TYPE(pw_c1d_gs_type) :: work_rho, work_v
938 TYPE(pw_c1d_gs_type), DIMENSION(:), POINTER :: rho_g
939 TYPE(qs_force_type), DIMENSION(:), POINTER :: force
940
941 NULLIFY (mo_array, rho_g)
942
943 IF (dft_control%sic_method_id == sic_none) RETURN
944 IF (dft_control%sic_method_id == sic_eo) RETURN
945
946 IF (dft_control%qs_control%gapw) THEN
947 cpabort("sic and GAPW not yet compatible")
948 END IF
949
950 ! OK, right now we like two spins to do sic, could be relaxed for AD
951 cpassert(dft_control%nspins == 2)
952
953 CALL auxbas_pw_pool%create_pw(work_rho)
954 CALL auxbas_pw_pool%create_pw(work_v)
955
956 CALL qs_rho_get(rho, rho_g=rho_g)
957
958 ! Hartree sic corrections
959 SELECT CASE (dft_control%sic_method_id)
961 CALL pw_copy(rho_g(1), work_rho)
962 CALL pw_axpy(rho_g(2), work_rho, alpha=-1._dp)
963 CALL pw_poisson_solve(poisson_env, work_rho, ener, work_v)
964 CASE (sic_ad)
965 ! find out how many elecs we have
966 CALL get_qs_env(qs_env, mos=mo_array)
967 CALL get_mo_set(mo_set=mo_array(1), nelectron=nelec_a)
968 CALL get_mo_set(mo_set=mo_array(2), nelectron=nelec_b)
969 nelec = nelec_a + nelec_b
970 CALL pw_copy(rho_g(1), work_rho)
971 CALL pw_axpy(rho_g(2), work_rho)
972 scaling = 1.0_dp/real(nelec, kind=dp)
973 CALL pw_scale(work_rho, scaling)
974 CALL pw_poisson_solve(poisson_env, work_rho, ener, work_v)
975 CASE DEFAULT
976 cpabort("Unknown sic method id")
977 END SELECT
978
979 ! Correct for DDAP charges (if any)
980 ! storing whatever force might be there from previous decoupling
981 IF (calculate_forces) THEN
982 CALL get_qs_env(qs_env=qs_env, force=force)
983 nforce = 0
984 DO i = 1, SIZE(force)
985 nforce = nforce + SIZE(force(i)%ch_pulay, 2)
986 END DO
987 ALLOCATE (store_forces(3, nforce))
988 nforce = 0
989 DO i = 1, SIZE(force)
990 store_forces(1:3, nforce + 1:nforce + SIZE(force(i)%ch_pulay, 2)) = force(i)%ch_pulay(:, :)
991 force(i)%ch_pulay(:, :) = 0.0_dp
992 nforce = nforce + SIZE(force(i)%ch_pulay, 2)
993 END DO
994 END IF
995
996 CALL cp_ddapc_apply_cd(qs_env, &
997 work_rho, &
998 ener, &
999 v_hartree_gspace=work_v, &
1000 calculate_forces=calculate_forces, &
1001 itype_of_density="SPIN")
1002
1003 SELECT CASE (dft_control%sic_method_id)
1005 full_scaling = -dft_control%sic_scaling_a
1006 CASE (sic_ad)
1007 full_scaling = -dft_control%sic_scaling_a*nelec
1008 CASE DEFAULT
1009 cpabort("Unknown sic method id")
1010 END SELECT
1011 energy%hartree = energy%hartree + full_scaling*ener
1012
1013 ! add scaled forces, restoring the old
1014 IF (calculate_forces) THEN
1015 nforce = 0
1016 DO i = 1, SIZE(force)
1017 force(i)%ch_pulay(:, :) = force(i)%ch_pulay(:, :)*full_scaling + &
1018 store_forces(1:3, nforce + 1:nforce + SIZE(force(i)%ch_pulay, 2))
1019 nforce = nforce + SIZE(force(i)%ch_pulay, 2)
1020 END DO
1021 END IF
1022
1023 IF (.NOT. just_energy) THEN
1024 ALLOCATE (v_sic_rspace)
1025 CALL auxbas_pw_pool%create_pw(v_sic_rspace)
1026 CALL pw_transfer(work_v, v_sic_rspace)
1027 ! also take into account the scaling (in addition to the volume element)
1028 CALL pw_scale(v_sic_rspace, &
1029 dft_control%sic_scaling_a*v_sic_rspace%pw_grid%dvol)
1030 END IF
1031
1032 CALL auxbas_pw_pool%give_back_pw(work_rho)
1033 CALL auxbas_pw_pool%give_back_pw(work_v)
1034
1035 END SUBROUTINE calc_v_sic_rspace
1036
1037! **************************************************************************************************
1038!> \brief Check each term of the energy and sum to total
1039!> \param energy ...
1040! **************************************************************************************************
1041 SUBROUTINE check_sum_energies(energy)
1042 TYPE(qs_energy_type), INTENT(INOUT), POINTER :: energy
1043
1044 ! Reset the total energy counter, just in case
1045 ! it is used to store some intermediate value
1046 energy%total = 0.0_dp
1047
1048 CALL check_sum_energy(energy%total, energy%core_overlap, "Core overlap energy")
1049 CALL check_sum_energy(energy%total, energy%core_self, "Core self energy")
1050 CALL check_sum_energy(energy%total, energy%core_cneo, "Quantum nuclear core energy")
1051 CALL check_sum_energy(energy%total, energy%core, "Core Hamiltonian energy")
1052 CALL check_sum_energy(energy%total, energy%hartree, "Hartree energy")
1053 CALL check_sum_energy(energy%total, energy%hartree_1c, "Energy from GAPW local Eh = 1 center integrals")
1054 CALL check_sum_energy(energy%total, energy%exc, "Exchange-correlation energy")
1055 CALL check_sum_energy(energy%total, energy%exc1, "Exc1 energy")
1056 CALL check_sum_energy(energy%total, energy%ex, "Ex energy")
1057 CALL check_sum_energy(energy%total, energy%dispersion, "Dispersion energy")
1058 CALL check_sum_energy(energy%total, energy%gcp, "gCP energy")
1059 CALL check_sum_energy(energy%total, energy%qmmm_el, "QM/MM Electrostatic energy")
1060 CALL check_sum_energy(energy%total, energy%mulliken, "Mulliken restraint energy")
1061 CALL check_sum_energy(energy%total, sum(energy%ddapc_restraint), "DDAPC restraint energy")
1062 CALL check_sum_energy(energy%total, energy%s2_restraint, "S2 restraint energy")
1063 CALL check_sum_energy(energy%total, energy%dft_plus_u, "DFT+U energy")
1064 CALL check_sum_energy(energy%total, energy%kTS, "Electronic entropic contribution energy")
1065 CALL check_sum_energy(energy%total, energy%efield, "Electric field interaction energy")
1066 CALL check_sum_energy(energy%total, energy%efield_core, "Electric field core interaction energy")
1067 CALL check_sum_energy(energy%total, energy%ee, "External potential interaction energy")
1068 CALL check_sum_energy(energy%total, energy%ee_core, "External potential core interaction energy")
1069 CALL check_sum_energy(energy%total, energy%exc_aux_fit, "Wfn fit exchange-correlation energy")
1070 CALL check_sum_energy(energy%total, energy%image_charge, "QM/MM image charge energy energy")
1071 CALL check_sum_energy(energy%total, energy%sccs_pol, "SCCS polarisation energy")
1072 CALL check_sum_energy(energy%total, energy%cdft, "CDFT constraint energy")
1073 CALL check_sum_energy(energy%total, energy%exc1_aux_fit, "Wfn fit soft/hard atomic rho1 Exc contribution energy")
1074 CALL check_sum_energy(energy%total, energy%embed_corr, "Embedding potential correction energy")
1075
1076 IF (abnormal_value(energy%total)) THEN
1077 CALL cp_abort(__location__, &
1078 "Total energy after summing up the terms is an abnormal value (NaN/Inf).")
1079 END IF
1080
1081 END SUBROUTINE check_sum_energies
1082
1083! **************************************************************************************************
1084!> \brief Check one term of the energy and sum to total if normal
1085!> \param total ...
1086!> \param term ...
1087!> \param name ...
1088! **************************************************************************************************
1089 SUBROUTINE check_sum_energy(total, term, name)
1090 REAL(kind=dp), INTENT(INOUT) :: total
1091 REAL(kind=dp), INTENT(IN) :: term
1092 CHARACTER(LEN=*), INTENT(IN) :: name
1093
1094 IF (abnormal_value(term)) THEN
1095 CALL cp_abort(__location__, &
1096 trim(name)//" is an abnormal value (NaN/Inf).")
1097 ELSE
1098 total = total + term
1099 END IF
1100
1101 END SUBROUTINE check_sum_energy
1102
1103! **************************************************************************************************
1104!> \brief ...
1105!> \param qs_env ...
1106!> \param rho ...
1107! **************************************************************************************************
1108 SUBROUTINE print_densities(qs_env, rho)
1109 TYPE(qs_environment_type), POINTER :: qs_env
1110 TYPE(qs_rho_type), POINTER :: rho
1111
1112 INTEGER :: img, ispin, n_electrons, output_unit
1113 REAL(dp) :: tot1_h, tot1_s, tot_rho_r, trace, &
1114 trace_tmp
1115 REAL(kind=dp), DIMENSION(:), POINTER :: tot_rho_r_arr
1116 TYPE(cell_type), POINTER :: cell
1117 TYPE(cp_logger_type), POINTER :: logger
1118 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_s, rho_ao
1119 TYPE(dft_control_type), POINTER :: dft_control
1120 TYPE(qs_charges_type), POINTER :: qs_charges
1121 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
1122 TYPE(section_vals_type), POINTER :: input, scf_section
1123
1124 NULLIFY (qs_charges, qs_kind_set, cell, input, logger, scf_section, matrix_s, &
1125 dft_control, tot_rho_r_arr, rho_ao)
1126
1127 logger => cp_get_default_logger()
1128
1129 CALL get_qs_env(qs_env, &
1130 qs_kind_set=qs_kind_set, &
1131 cell=cell, qs_charges=qs_charges, &
1132 input=input, &
1133 matrix_s_kp=matrix_s, &
1134 dft_control=dft_control)
1135
1136 CALL get_qs_kind_set(qs_kind_set, nelectron=n_electrons)
1137
1138 scf_section => section_vals_get_subs_vals(input, "DFT%SCF")
1139 output_unit = cp_print_key_unit_nr(logger, scf_section, "PRINT%TOTAL_DENSITIES", &
1140 extension=".scfLog")
1141
1142 CALL qs_rho_get(rho, tot_rho_r=tot_rho_r_arr, rho_ao_kp=rho_ao)
1143 n_electrons = n_electrons - dft_control%charge
1144 tot_rho_r = accurate_sum(tot_rho_r_arr)
1145
1146 trace = 0
1147 IF (btest(cp_print_key_should_output(logger%iter_info, scf_section, "PRINT%TOTAL_DENSITIES"), cp_p_file)) THEN
1148 DO ispin = 1, dft_control%nspins
1149 DO img = 1, dft_control%nimages
1150 CALL dbcsr_dot(rho_ao(ispin, img)%matrix, matrix_s(1, img)%matrix, trace_tmp)
1151 trace = trace + trace_tmp
1152 END DO
1153 END DO
1154 END IF
1155
1156 IF (output_unit > 0) THEN
1157 WRITE (unit=output_unit, fmt="(/,T3,A,T41,F20.10)") "Trace(PS):", trace
1158 WRITE (unit=output_unit, fmt="((T3,A,T41,2F20.10))") &
1159 "Electronic density on regular grids: ", &
1160 tot_rho_r, &
1161 tot_rho_r + &
1162 REAL(n_electrons, dp), &
1163 "Core density on regular grids:", &
1164 qs_charges%total_rho_core_rspace, &
1165 qs_charges%total_rho_core_rspace + &
1166 qs_charges%total_rho1_hard_nuc - &
1167 REAL(n_electrons + dft_control%charge, dp)
1168 END IF
1169 IF (dft_control%qs_control%gapw) THEN
1170 tot1_h = qs_charges%total_rho1_hard(1)
1171 tot1_s = qs_charges%total_rho1_soft(1)
1172 DO ispin = 2, dft_control%nspins
1173 tot1_h = tot1_h + qs_charges%total_rho1_hard(ispin)
1174 tot1_s = tot1_s + qs_charges%total_rho1_soft(ispin)
1175 END DO
1176 IF (output_unit > 0) THEN
1177 WRITE (unit=output_unit, fmt="((T3,A,T41,2F20.10))") &
1178 "Hard and soft densities (Lebedev):", &
1179 tot1_h, tot1_s
1180 WRITE (unit=output_unit, fmt="(T3,A,T41,F20.10)") &
1181 "Total Rho_soft + Rho1_hard - Rho1_soft (r-space): ", &
1182 tot_rho_r + tot1_h - tot1_s, &
1183 "Total charge density (r-space): ", &
1184 tot_rho_r + tot1_h - tot1_s &
1185 + qs_charges%total_rho_core_rspace &
1186 + qs_charges%total_rho1_hard_nuc
1187 IF (qs_charges%total_rho1_hard_nuc /= 0.0_dp) THEN
1188 WRITE (unit=output_unit, fmt="(T3,A,T41,F20.10)") &
1189 "Total CNEO nuc. char. den. (Lebedev): ", &
1190 qs_charges%total_rho1_hard_nuc, &
1191 "Total CNEO soft char. den. (Lebedev): ", &
1192 qs_charges%total_rho1_soft_nuc_lebedev, &
1193 "Total CNEO soft char. den. (r-space): ", &
1194 qs_charges%total_rho1_soft_nuc_rspace, &
1195 "Total soft Rho_e+n+0 (g-space):", &
1196 qs_charges%total_rho_gspace
1197 ELSE
1198 WRITE (unit=output_unit, fmt="(T3,A,T41,F20.10)") &
1199 "Total Rho_soft + Rho0_soft (g-space):", &
1200 qs_charges%total_rho_gspace
1201 END IF
1202 END IF
1203 qs_charges%background = tot_rho_r + tot1_h - tot1_s + &
1204 qs_charges%total_rho_core_rspace + &
1205 qs_charges%total_rho1_hard_nuc
1206 ! only add total_rho1_hard_nuc for gapw as cneo requires gapw
1207 ELSE IF (dft_control%qs_control%gapw_xc) THEN
1208 tot1_h = qs_charges%total_rho1_hard(1)
1209 tot1_s = qs_charges%total_rho1_soft(1)
1210 DO ispin = 2, dft_control%nspins
1211 tot1_h = tot1_h + qs_charges%total_rho1_hard(ispin)
1212 tot1_s = tot1_s + qs_charges%total_rho1_soft(ispin)
1213 END DO
1214 IF (output_unit > 0) THEN
1215 WRITE (unit=output_unit, fmt="(/,(T3,A,T41,2F20.10))") &
1216 "Hard and soft densities (Lebedev):", &
1217 tot1_h, tot1_s
1218 WRITE (unit=output_unit, fmt="(T3,A,T41,F20.10)") &
1219 "Total Rho_soft + Rho1_hard - Rho1_soft (r-space): ", &
1220 accurate_sum(tot_rho_r_arr) + tot1_h - tot1_s
1221 END IF
1222 qs_charges%background = tot_rho_r + &
1223 qs_charges%total_rho_core_rspace
1224 ELSE
1225 IF (output_unit > 0) THEN
1226 WRITE (unit=output_unit, fmt="(T3,A,T41,F20.10)") &
1227 "Total charge density on r-space grids: ", &
1228 tot_rho_r + &
1229 qs_charges%total_rho_core_rspace, &
1230 "Total charge density g-space grids: ", &
1231 qs_charges%total_rho_gspace
1232 END IF
1233 qs_charges%background = tot_rho_r + &
1234 qs_charges%total_rho_core_rspace
1235 END IF
1236 IF (output_unit > 0) WRITE (unit=output_unit, fmt="()")
1237 qs_charges%background = qs_charges%background/cell%deth
1238
1239 CALL cp_print_key_finished_output(output_unit, logger, scf_section, &
1240 "PRINT%TOTAL_DENSITIES")
1241
1242 END SUBROUTINE print_densities
1243
1244! **************************************************************************************************
1245!> \brief Print detailed energies
1246!>
1247!> \param qs_env ...
1248!> \param dft_control ...
1249!> \param input ...
1250!> \param energy ...
1251!> \param mulliken_order_p ...
1252!> \par History
1253!> refactoring 04.03.2011 [MI]
1254!> \author
1255! **************************************************************************************************
1256 SUBROUTINE print_detailed_energy(qs_env, dft_control, input, energy, mulliken_order_p)
1257
1258 TYPE(qs_environment_type), POINTER :: qs_env
1259 TYPE(dft_control_type), POINTER :: dft_control
1260 TYPE(section_vals_type), POINTER :: input
1261 TYPE(qs_energy_type), POINTER :: energy
1262 REAL(kind=dp), INTENT(IN) :: mulliken_order_p
1263
1264 INTEGER :: bc, n, output_unit, psolver
1265 REAL(kind=dp) :: ddapc_order_p, implicit_ps_ehartree, &
1266 s2_order_p
1267 TYPE(cp_logger_type), POINTER :: logger
1268 TYPE(pw_env_type), POINTER :: pw_env
1269
1270 logger => cp_get_default_logger()
1271
1272 NULLIFY (pw_env)
1273 CALL get_qs_env(qs_env=qs_env, pw_env=pw_env)
1274 psolver = pw_env%poisson_env%parameters%solver
1275
1276 output_unit = cp_print_key_unit_nr(logger, input, "DFT%SCF%PRINT%DETAILED_ENERGY", &
1277 extension=".scfLog")
1278 IF (output_unit > 0) THEN
1279 IF (dft_control%do_admm) THEN
1280 WRITE (unit=output_unit, fmt="((T3,A,T60,F20.10))") &
1281 "Wfn fit exchange-correlation energy: ", energy%exc_aux_fit
1282 IF (dft_control%qs_control%gapw .OR. dft_control%qs_control%gapw_xc) THEN
1283 WRITE (unit=output_unit, fmt="((T3,A,T60,F20.10))") &
1284 "Wfn fit soft/hard atomic rho1 Exc contribution: ", energy%exc1_aux_fit
1285 END IF
1286 END IF
1287 IF (dft_control%do_admm) THEN
1288 IF (psolver == pw_poisson_implicit) THEN
1289 implicit_ps_ehartree = pw_env%poisson_env%implicit_env%ehartree
1290 bc = pw_env%poisson_env%parameters%ps_implicit_params%boundary_condition
1291 SELECT CASE (bc)
1293 WRITE (unit=output_unit, fmt="(/,(T3,A,T61,F20.10))") &
1294 "Core Hamiltonian energy: ", energy%core, &
1295 "Hartree energy: ", implicit_ps_ehartree, &
1296 "Electric enthalpy: ", energy%hartree, &
1297 "Exchange-correlation energy: ", energy%exc + energy%exc_aux_fit
1298 CASE (periodic_bc, neumann_bc)
1299 WRITE (unit=output_unit, fmt="(/,(T3,A,T61,F20.10))") &
1300 "Core Hamiltonian energy: ", energy%core, &
1301 "Hartree energy: ", energy%hartree, &
1302 "Exchange-correlation energy: ", energy%exc + energy%exc_aux_fit
1303 END SELECT
1304 ELSE
1305 WRITE (unit=output_unit, fmt="(/,(T3,A,T61,F20.10))") &
1306 "Core Hamiltonian energy: ", energy%core, &
1307 "Hartree energy: ", energy%hartree, &
1308 "Exchange-correlation energy: ", energy%exc + energy%exc_aux_fit
1309 END IF
1310 ELSE
1311 !ZMP to print some variables at each step
1312 IF (dft_control%apply_external_density) THEN
1313 WRITE (unit=output_unit, fmt="(/,(T3,A,T61,F20.10))") &
1314 "DOING ZMP CALCULATION FROM EXTERNAL DENSITY "
1315 WRITE (unit=output_unit, fmt="(/,(T3,A,T61,F20.10))") &
1316 "Core Hamiltonian energy: ", energy%core, &
1317 "Hartree energy: ", energy%hartree
1318 ELSE IF (dft_control%apply_external_vxc) THEN
1319 WRITE (unit=output_unit, fmt="(/,(T3,A,T61,F20.10))") &
1320 "DOING ZMP READING EXTERNAL VXC "
1321 WRITE (unit=output_unit, fmt="(/,(T3,A,T61,F20.10))") &
1322 "Core Hamiltonian energy: ", energy%core, &
1323 "Hartree energy: ", energy%hartree
1324 ELSE
1325 IF (psolver == pw_poisson_implicit) THEN
1326 implicit_ps_ehartree = pw_env%poisson_env%implicit_env%ehartree
1327 bc = pw_env%poisson_env%parameters%ps_implicit_params%boundary_condition
1328 SELECT CASE (bc)
1330 WRITE (unit=output_unit, fmt="(/,(T3,A,T61,F20.10))") &
1331 "Core Hamiltonian energy: ", energy%core, &
1332 "Hartree energy: ", implicit_ps_ehartree, &
1333 "Electric enthalpy: ", energy%hartree, &
1334 "Exchange-correlation energy: ", energy%exc
1335 CASE (periodic_bc, neumann_bc)
1336 WRITE (unit=output_unit, fmt="(/,(T3,A,T61,F20.10))") &
1337 "Core Hamiltonian energy: ", energy%core, &
1338 "Hartree energy: ", energy%hartree, &
1339 "Exchange-correlation energy: ", energy%exc
1340 END SELECT
1341 ELSE
1342 WRITE (unit=output_unit, fmt="(/,(T3,A,T61,F20.10))") &
1343 "Core Hamiltonian energy: ", energy%core, &
1344 "Hartree energy: ", energy%hartree, &
1345 "Exchange-correlation energy: ", energy%exc
1346 END IF
1347 END IF
1348 END IF
1349
1350 IF (dft_control%apply_external_density) THEN
1351 WRITE (unit=output_unit, fmt="(/,(T3,A,T61,F20.10))") &
1352 "Integral of the (density * v_xc): ", energy%exc
1353 END IF
1354
1355 IF (energy%e_hartree /= 0.0_dp) THEN
1356 WRITE (unit=output_unit, fmt="(T3,A,T61,F20.10)") &
1357 "Coulomb (electron-electron) energy: ", energy%e_hartree
1358 END IF
1359 IF (energy%dispersion /= 0.0_dp) THEN
1360 WRITE (unit=output_unit, fmt="(T3,A,T61,F20.10)") &
1361 "Dispersion energy: ", energy%dispersion
1362 END IF
1363 IF (energy%efield /= 0.0_dp) THEN
1364 WRITE (unit=output_unit, fmt="(T3,A,T61,F20.10)") &
1365 "Electric field interaction energy: ", energy%efield
1366 END IF
1367 IF (energy%gcp /= 0.0_dp) THEN
1368 WRITE (unit=output_unit, fmt="(T3,A,T61,F20.10)") &
1369 "gCP energy: ", energy%gcp
1370 END IF
1371 IF (dft_control%qs_control%gapw) THEN
1372 WRITE (unit=output_unit, fmt="(/,(T3,A,T61,F20.10))") &
1373 "GAPW| Exc from hard and soft atomic rho1: ", energy%exc1 + energy%exc1_aux_fit, &
1374 "GAPW| local Eh = 1 center integrals: ", energy%hartree_1c
1375 END IF
1376 IF (dft_control%qs_control%gapw_xc) THEN
1377 WRITE (unit=output_unit, fmt="(/,(T3,A,T61,F20.10))") &
1378 "GAPW| Exc from hard and soft atomic rho1: ", energy%exc1 + energy%exc1_aux_fit
1379 END IF
1380 IF (dft_control%dft_plus_u) THEN
1381 WRITE (unit=output_unit, fmt="(T3,A,T61,F20.10)") &
1382 "DFT+U energy:", energy%dft_plus_u
1383 END IF
1384 IF (qs_env%qmmm) THEN
1385 WRITE (unit=output_unit, fmt="(T3,A,T61,F20.10)") &
1386 "QM/MM Electrostatic energy: ", energy%qmmm_el
1387 IF (qs_env%qmmm_env_qm%image_charge) THEN
1388 WRITE (unit=output_unit, fmt="(T3,A,T61,F20.10)") &
1389 "QM/MM image charge energy: ", energy%image_charge
1390 END IF
1391 END IF
1392 IF (dft_control%qs_control%mulliken_restraint) THEN
1393 WRITE (unit=output_unit, fmt="(T3,A,T41,2F20.10)") &
1394 "Mulliken restraint (order_p,energy) : ", mulliken_order_p, energy%mulliken
1395 END IF
1396 IF (dft_control%qs_control%ddapc_restraint) THEN
1397 DO n = 1, SIZE(dft_control%qs_control%ddapc_restraint_control)
1398 ddapc_order_p = &
1399 dft_control%qs_control%ddapc_restraint_control(n)%ddapc_order_p
1400 WRITE (unit=output_unit, fmt="(T3,A,T41,2F20.10)") &
1401 "DDAPC restraint (order_p,energy) : ", ddapc_order_p, energy%ddapc_restraint(n)
1402 END DO
1403 END IF
1404 IF (dft_control%qs_control%s2_restraint) THEN
1405 s2_order_p = dft_control%qs_control%s2_restraint_control%s2_order_p
1406 WRITE (unit=output_unit, fmt="(T3,A,T41,2F20.10)") &
1407 "S2 restraint (order_p,energy) : ", s2_order_p, energy%s2_restraint
1408 END IF
1409 IF (energy%core_cneo /= 0.0_dp) THEN
1410 WRITE (unit=output_unit, fmt="(T3,A,T61,F20.10)") &
1411 "CNEO| quantum nuclear core energy: ", energy%core_cneo
1412 END IF
1413
1414 END IF ! output_unit
1415 CALL cp_print_key_finished_output(output_unit, logger, input, &
1416 "DFT%SCF%PRINT%DETAILED_ENERGY")
1417
1418 END SUBROUTINE print_detailed_energy
1419
1420! **************************************************************************************************
1421!> \brief Integrate the scalar XC potential into spin/image-resolved AO matrices.
1422!> Gamma-only calculations have one image. Tau-dependent operators and
1423!> GAPW one-center corrections are handled separately by the caller.
1424!> \param qs_env Quickstep environment
1425!> \param v_rspace scalar XC potential on the real-space grid, for each spin
1426!> \param matrix_vxc XC matrices indexed by spin and image
1427!> \param gapw_full_basis use the full orbital basis instead of the GAPW soft basis
1428!> \par History
1429!> created 23.10.2012 [Joost VandeVondele]
1430!> \author
1431! **************************************************************************************************
1432 SUBROUTINE compute_matrix_vxc(qs_env, v_rspace, matrix_vxc, gapw_full_basis)
1433 TYPE(qs_environment_type), POINTER :: qs_env
1434 TYPE(pw_r3d_rs_type), DIMENSION(:), INTENT(IN) :: v_rspace
1435 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_vxc
1436 LOGICAL, INTENT(IN), OPTIONAL :: gapw_full_basis
1437
1438 CHARACTER(LEN=*), PARAMETER :: routinen = 'compute_matrix_vxc'
1439
1440 INTEGER :: handle, img, ispin
1441 LOGICAL :: gapw
1442 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: ksmat
1443 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_ks
1444 TYPE(dft_control_type), POINTER :: dft_control
1445
1446 CALL timeset(routinen, handle)
1447
1448 ! create the matrix using matrix_ks as a template
1449 IF (ASSOCIATED(matrix_vxc)) THEN
1450 CALL dbcsr_deallocate_matrix_set(matrix_vxc)
1451 END IF
1452 CALL get_qs_env(qs_env, dft_control=dft_control, matrix_ks_kp=matrix_ks)
1453 ALLOCATE (matrix_vxc(SIZE(matrix_ks, 1), SIZE(matrix_ks, 2)))
1454 DO img = 1, SIZE(matrix_ks, 2)
1455 DO ispin = 1, SIZE(matrix_ks, 1)
1456 NULLIFY (matrix_vxc(ispin, img)%matrix)
1457 CALL dbcsr_init_p(matrix_vxc(ispin, img)%matrix)
1458 CALL dbcsr_copy(matrix_vxc(ispin, img)%matrix, matrix_ks(ispin, img)%matrix, &
1459 name="Matrix VXC of spin "//cp_to_string(ispin)//" image "//cp_to_string(img))
1460 CALL dbcsr_set(matrix_vxc(ispin, img)%matrix, 0.0_dp)
1461 END DO
1462 END DO
1463
1464 ! and integrate
1465 gapw = dft_control%qs_control%gapw .OR. dft_control%qs_control%gapw_xc
1466 IF (PRESENT(gapw_full_basis)) THEN
1467 IF (gapw_full_basis) gapw = .false.
1468 END IF
1469 DO ispin = 1, SIZE(matrix_ks, 1)
1470 ksmat => matrix_vxc(ispin, :)
1471 CALL integrate_v_rspace(v_rspace=v_rspace(ispin), &
1472 hmat_kp=ksmat, &
1473 qs_env=qs_env, &
1474 calculate_forces=.false., &
1475 gapw=gapw)
1476 ! scale by the volume element... should really become part of integrate_v_rspace
1477 DO img = 1, SIZE(matrix_ks, 2)
1478 CALL dbcsr_scale(matrix_vxc(ispin, img)%matrix, v_rspace(ispin)%pw_grid%dvol)
1479 END DO
1480 END DO
1481
1482 CALL timestop(handle)
1483
1484 END SUBROUTINE compute_matrix_vxc
1485
1486! **************************************************************************************************
1487!> \brief Sum up all potentials defined on the grid and integrate
1488!>
1489!> \param qs_env ...
1490!> \param ks_matrix ...
1491!> \param rho ...
1492!> \param my_rho ...
1493!> \param vppl_rspace ...
1494!> \param v_rspace_new ...
1495!> \param v_rspace_new_aux_fit ...
1496!> \param v_tau_rspace ...
1497!> \param v_tau_rspace_aux_fit ...
1498!> \param v_sic_rspace ...
1499!> \param v_spin_ddapc_rest_r ...
1500!> \param v_sccs_rspace ...
1501!> \param v_rspace_embed ...
1502!> \param cdft_control ...
1503!> \param calculate_forces ...
1504!> \par History
1505!> - refactoring 04.03.2011 [MI]
1506!> - SCCS implementation (16.10.2013,MK)
1507!> \author
1508! **************************************************************************************************
1509 SUBROUTINE sum_up_and_integrate(qs_env, ks_matrix, rho, my_rho, &
1510 vppl_rspace, v_rspace_new, &
1511 v_rspace_new_aux_fit, v_tau_rspace, &
1512 v_tau_rspace_aux_fit, &
1513 v_sic_rspace, v_spin_ddapc_rest_r, &
1514 v_sccs_rspace, v_rspace_embed, cdft_control, &
1515 calculate_forces)
1516
1517 TYPE(qs_environment_type), POINTER :: qs_env
1518 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: ks_matrix
1519 TYPE(qs_rho_type), POINTER :: rho
1520 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: my_rho
1521 TYPE(pw_r3d_rs_type), POINTER :: vppl_rspace
1522 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: v_rspace_new, v_rspace_new_aux_fit, &
1523 v_tau_rspace, v_tau_rspace_aux_fit
1524 TYPE(pw_r3d_rs_type), POINTER :: v_sic_rspace, v_spin_ddapc_rest_r, &
1525 v_sccs_rspace
1526 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: v_rspace_embed
1527 TYPE(cdft_control_type), POINTER :: cdft_control
1528 LOGICAL, INTENT(in) :: calculate_forces
1529
1530 CHARACTER(LEN=*), PARAMETER :: routinen = 'sum_up_and_integrate'
1531
1532 CHARACTER(LEN=default_string_length) :: basis_type
1533 INTEGER :: handle, igroup, ikind, img, ispin, &
1534 nkind, nspins
1535 INTEGER, DIMENSION(:, :, :), POINTER :: cell_to_index
1536 LOGICAL :: do_ppl, gapw, gapw_composite_direct_ao, &
1537 gapw_composite_reference, gapw_xc, &
1538 lrigpw, rigpw, use_work_v_rspace
1539 REAL(kind=dp) :: csign, dvol, fadm
1540 TYPE(admm_type), POINTER :: admm_env
1541 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
1542 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: ksmat, rho_ao, rho_ao_nokp, smat
1543 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_ks_aux_fit, &
1544 matrix_ks_aux_fit_dft, rho_ao_aux, &
1545 rho_ao_kp
1546 TYPE(dft_control_type), POINTER :: dft_control
1547 TYPE(kpoint_type), POINTER :: kpoints
1548 TYPE(lri_density_type), POINTER :: lri_density
1549 TYPE(lri_environment_type), POINTER :: lri_env
1550 TYPE(lri_kind_type), DIMENSION(:), POINTER :: lri_v_int
1551 TYPE(mp_para_env_type), POINTER :: para_env
1552 TYPE(pw_env_type), POINTER :: pw_env
1553 TYPE(pw_poisson_type), POINTER :: poisson_env
1554 TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
1555 TYPE(pw_r3d_rs_type), POINTER :: v_rspace, v_rspace_used, vee
1556 TYPE(pw_r3d_rs_type), TARGET :: v_rspace_work
1557 TYPE(qs_ks_env_type), POINTER :: ks_env
1558 TYPE(qs_rho_type), POINTER :: rho_aux_fit
1559 TYPE(section_vals_type), POINTER :: input, xc_section
1560 TYPE(task_list_type), POINTER :: task_list
1561
1562 CALL timeset(routinen, handle)
1563
1564 NULLIFY (auxbas_pw_pool, dft_control, pw_env, matrix_ks_aux_fit, &
1565 v_rspace, rho_aux_fit, vee, rho_ao, rho_ao_kp, rho_ao_aux, &
1566 ksmat, matrix_ks_aux_fit_dft, lri_env, lri_density, atomic_kind_set, &
1567 rho_ao_nokp, ks_env, admm_env, task_list, v_rspace_used, input, xc_section)
1568
1569 CALL get_qs_env(qs_env, &
1570 dft_control=dft_control, &
1571 input=input, &
1572 pw_env=pw_env, &
1573 v_hartree_rspace=v_rspace, &
1574 vee=vee)
1575
1576 CALL qs_rho_get(rho, rho_ao_kp=rho_ao_kp)
1577 CALL pw_env_get(pw_env, poisson_env=poisson_env, auxbas_pw_pool=auxbas_pw_pool)
1578 gapw = dft_control%qs_control%gapw
1579 gapw_xc = dft_control%qs_control%gapw_xc
1580 xc_section => section_vals_get_subs_vals(input, "DFT%XC")
1581 gapw_composite_reference = native_skala_gapw_composite_reference(xc_section) .AND. &
1582 (gapw .OR. gapw_xc)
1583 gapw_composite_direct_ao = gapw_composite_reference .AND. &
1585 do_ppl = dft_control%qs_control%do_ppl_method == do_ppl_grid
1586
1587 rigpw = dft_control%qs_control%rigpw
1588 lrigpw = dft_control%qs_control%lrigpw
1589 IF (lrigpw .OR. rigpw) THEN
1590 CALL get_qs_env(qs_env, &
1591 lri_env=lri_env, &
1592 lri_density=lri_density, &
1593 atomic_kind_set=atomic_kind_set)
1594 END IF
1595
1596 nspins = dft_control%nspins
1597
1598 ! sum up potentials and integrate
1599 IF (ASSOCIATED(v_rspace_new)) THEN
1600 DO ispin = 1, nspins
1601 IF (gapw_composite_reference) THEN
1602 ! The direct AO diagnostic uses the full ORB basis. The reconstructed path uses
1603 ! the soft basis here and adds the hard-minus-soft adjoint through update_ks_atom.
1604 CALL pw_scale(v_rspace_new(ispin), v_rspace_new(ispin)%pw_grid%dvol)
1605 rho_ao => rho_ao_kp(ispin, :)
1606 ksmat => ks_matrix(ispin, :)
1607 CALL integrate_v_rspace(v_rspace=v_rspace_new(ispin), &
1608 pmat_kp=rho_ao, hmat_kp=ksmat, &
1609 qs_env=qs_env, &
1610 calculate_forces=calculate_forces, &
1611 gapw=gapw .AND. .NOT. gapw_composite_direct_ao)
1612 CALL pw_copy(v_rspace, v_rspace_new(ispin))
1613 ELSE IF (gapw_xc) THEN
1614 ! SIC not implemented (or at least not tested)
1615 cpassert(dft_control%sic_method_id == sic_none)
1616 !Only the xc potential, because it has to be integrated with the soft basis
1617 CALL pw_scale(v_rspace_new(ispin), v_rspace_new(ispin)%pw_grid%dvol)
1618
1619 ! add the xc part due to v_rspace soft
1620 rho_ao => rho_ao_kp(ispin, :)
1621 ksmat => ks_matrix(ispin, :)
1622 CALL integrate_v_rspace(v_rspace=v_rspace_new(ispin), &
1623 pmat_kp=rho_ao, hmat_kp=ksmat, &
1624 qs_env=qs_env, &
1625 calculate_forces=calculate_forces, &
1626 gapw=gapw_xc)
1627
1628 ! Now the Hartree potential to be integrated with the full basis
1629 CALL pw_copy(v_rspace, v_rspace_new(ispin))
1630 ELSE
1631 ! Add v_hartree + v_xc = v_rspace_new
1632 CALL pw_axpy(v_rspace, v_rspace_new(ispin), 1.0_dp, v_rspace_new(ispin)%pw_grid%dvol)
1633 END IF ! gapw_xc
1634 IF (dft_control%qs_control%ddapc_explicit_potential) THEN
1635 IF (dft_control%qs_control%ddapc_restraint_is_spin) THEN
1636 IF (ispin == 1) THEN
1637 CALL pw_axpy(v_spin_ddapc_rest_r, v_rspace_new(ispin), 1.0_dp)
1638 ELSE
1639 CALL pw_axpy(v_spin_ddapc_rest_r, v_rspace_new(ispin), -1.0_dp)
1640 END IF
1641 ELSE
1642 CALL pw_axpy(v_spin_ddapc_rest_r, v_rspace_new(ispin), 1.0_dp)
1643 END IF
1644 END IF
1645 ! CDFT constraint contribution
1646 IF (dft_control%qs_control%cdft) THEN
1647 DO igroup = 1, SIZE(cdft_control%group)
1648 SELECT CASE (cdft_control%group(igroup)%constraint_type)
1650 csign = 1.0_dp
1652 IF (ispin == 1) THEN
1653 csign = 1.0_dp
1654 ELSE
1655 csign = -1.0_dp
1656 END IF
1658 csign = 1.0_dp
1659 IF (ispin == 2) cycle
1661 csign = 1.0_dp
1662 IF (ispin == 1) cycle
1663 CASE DEFAULT
1664 cpabort("Unknown constraint type.")
1665 END SELECT
1666 CALL pw_axpy(cdft_control%group(igroup)%weight, v_rspace_new(ispin), &
1667 csign*cdft_control%strength(igroup))
1668 END DO
1669 END IF
1670 ! functional derivative of the Hartree energy wrt the density in the presence of dielectric
1671 ! (vhartree + v_eps); v_eps is nonzero only if the dielectric constant is defind as a function
1672 ! of the charge density
1673 IF (poisson_env%parameters%solver == pw_poisson_implicit) THEN
1674 dvol = poisson_env%implicit_env%v_eps%pw_grid%dvol
1675 CALL pw_axpy(poisson_env%implicit_env%v_eps, v_rspace_new(ispin), dvol)
1676 END IF
1677 ! Add SCCS contribution
1678 IF (dft_control%do_sccs) THEN
1679 CALL pw_axpy(v_sccs_rspace, v_rspace_new(ispin))
1680 END IF
1681 ! External electrostatic potential
1682 IF (dft_control%apply_external_potential) THEN
1683 CALL qmmm_modify_hartree_pot(v_hartree=v_rspace_new(ispin), &
1684 v_qmmm=vee, scale=-1.0_dp)
1685 END IF
1686 IF (do_ppl) THEN
1687 cpassert(.NOT. gapw)
1688 CALL pw_axpy(vppl_rspace, v_rspace_new(ispin), vppl_rspace%pw_grid%dvol)
1689 END IF
1690 ! the electrostatic sic contribution
1691 SELECT CASE (dft_control%sic_method_id)
1692 CASE (sic_none)
1693 !
1695 IF (ispin == 1) THEN
1696 CALL pw_axpy(v_sic_rspace, v_rspace_new(ispin), -1.0_dp)
1697 ELSE
1698 CALL pw_axpy(v_sic_rspace, v_rspace_new(ispin), 1.0_dp)
1699 END IF
1700 CASE (sic_ad)
1701 CALL pw_axpy(v_sic_rspace, v_rspace_new(ispin), -1.0_dp)
1702 CASE (sic_eo)
1703 ! NOTHING TO BE DONE
1704 END SELECT
1705 ! DFT embedding
1706 IF (dft_control%apply_embed_pot) THEN
1707 CALL pw_axpy(v_rspace_embed(ispin), v_rspace_new(ispin), v_rspace_embed(ispin)%pw_grid%dvol)
1708 CALL auxbas_pw_pool%give_back_pw(v_rspace_embed(ispin))
1709 END IF
1710 IF (lrigpw) THEN
1711 lri_v_int => lri_density%lri_coefs(ispin)%lri_kinds
1712 CALL get_qs_env(qs_env, nkind=nkind, para_env=para_env)
1713 DO ikind = 1, nkind
1714 lri_v_int(ikind)%v_int = 0.0_dp
1715 END DO
1716 CALL integrate_v_rspace_one_center(v_rspace_new(ispin), qs_env, &
1717 lri_v_int, calculate_forces, "LRI_AUX")
1718 DO ikind = 1, nkind
1719 CALL para_env%sum(lri_v_int(ikind)%v_int)
1720 END DO
1721 IF (lri_env%exact_1c_terms) THEN
1722 rho_ao => my_rho(ispin, :)
1723 ksmat => ks_matrix(ispin, :)
1724 CALL integrate_v_rspace_diagonal(v_rspace_new(ispin), ksmat(1)%matrix, &
1725 rho_ao(1)%matrix, qs_env, &
1726 calculate_forces, "ORB")
1727 END IF
1728 IF (lri_env%ppl_ri) THEN
1729 CALL v_int_ppl_update(qs_env, lri_v_int, calculate_forces)
1730 END IF
1731 ELSE IF (rigpw) THEN
1732 lri_v_int => lri_density%lri_coefs(ispin)%lri_kinds
1733 CALL get_qs_env(qs_env, nkind=nkind, para_env=para_env)
1734 DO ikind = 1, nkind
1735 lri_v_int(ikind)%v_int = 0.0_dp
1736 END DO
1737 CALL integrate_v_rspace_one_center(v_rspace_new(ispin), qs_env, &
1738 lri_v_int, calculate_forces, "RI_HXC")
1739 DO ikind = 1, nkind
1740 CALL para_env%sum(lri_v_int(ikind)%v_int)
1741 END DO
1742 ELSE
1743 rho_ao => my_rho(ispin, :)
1744 ksmat => ks_matrix(ispin, :)
1745 CALL integrate_v_rspace(v_rspace=v_rspace_new(ispin), &
1746 pmat_kp=rho_ao, hmat_kp=ksmat, &
1747 qs_env=qs_env, &
1748 calculate_forces=calculate_forces, &
1749 gapw=gapw .AND. .NOT. gapw_composite_direct_ao)
1750 END IF
1751 CALL auxbas_pw_pool%give_back_pw(v_rspace_new(ispin))
1752 END DO ! ispin
1753
1754 SELECT CASE (dft_control%sic_method_id)
1755 CASE (sic_none)
1757 CALL auxbas_pw_pool%give_back_pw(v_sic_rspace)
1758 DEALLOCATE (v_sic_rspace)
1759 END SELECT
1760 DEALLOCATE (v_rspace_new)
1761
1762 ELSE
1763 ! not implemented (or at least not tested)
1764 cpassert(dft_control%sic_method_id == sic_none)
1765 cpassert(.NOT. dft_control%qs_control%ddapc_restraint_is_spin)
1766 DO ispin = 1, nspins
1767 use_work_v_rspace = dft_control%qs_control%cdft
1768 IF (use_work_v_rspace) THEN
1769 CALL auxbas_pw_pool%create_pw(v_rspace_work)
1770 CALL pw_copy(v_rspace, v_rspace_work)
1771 v_rspace_used => v_rspace_work
1772 ELSE
1773 v_rspace_used => v_rspace
1774 END IF
1775 ! CDFT constraint contribution
1776 IF (dft_control%qs_control%cdft) THEN
1777 DO igroup = 1, SIZE(cdft_control%group)
1778 SELECT CASE (cdft_control%group(igroup)%constraint_type)
1780 csign = 1.0_dp
1782 IF (ispin == 1) THEN
1783 csign = 1.0_dp
1784 ELSE
1785 csign = -1.0_dp
1786 END IF
1788 csign = 1.0_dp
1789 IF (ispin == 2) cycle
1791 csign = 1.0_dp
1792 IF (ispin == 1) cycle
1793 CASE DEFAULT
1794 cpabort("Unknown constraint type.")
1795 END SELECT
1796 CALL pw_axpy(cdft_control%group(igroup)%weight, v_rspace_used, &
1797 csign*cdft_control%strength(igroup))
1798 END DO
1799 END IF
1800 ! extra contribution attributed to the dependency of the dielectric constant to the charge density
1801 IF (poisson_env%parameters%solver == pw_poisson_implicit) THEN
1802 dvol = poisson_env%implicit_env%v_eps%pw_grid%dvol
1803 CALL pw_axpy(poisson_env%implicit_env%v_eps, v_rspace_used, dvol)
1804 END IF
1805 ! Add SCCS contribution
1806 IF (dft_control%do_sccs) THEN
1807 CALL pw_axpy(v_sccs_rspace, v_rspace_used)
1808 END IF
1809 ! DFT embedding
1810 IF (dft_control%apply_embed_pot) THEN
1811 CALL pw_axpy(v_rspace_embed(ispin), v_rspace_used, v_rspace_embed(ispin)%pw_grid%dvol)
1812 CALL auxbas_pw_pool%give_back_pw(v_rspace_embed(ispin))
1813 END IF
1814 IF (lrigpw) THEN
1815 lri_v_int => lri_density%lri_coefs(ispin)%lri_kinds
1816 CALL get_qs_env(qs_env, nkind=nkind, para_env=para_env)
1817 DO ikind = 1, nkind
1818 lri_v_int(ikind)%v_int = 0.0_dp
1819 END DO
1820 CALL integrate_v_rspace_one_center(v_rspace_used, qs_env, &
1821 lri_v_int, calculate_forces, "LRI_AUX")
1822 DO ikind = 1, nkind
1823 CALL para_env%sum(lri_v_int(ikind)%v_int)
1824 END DO
1825 IF (lri_env%exact_1c_terms) THEN
1826 rho_ao => my_rho(ispin, :)
1827 ksmat => ks_matrix(ispin, :)
1828 CALL integrate_v_rspace_diagonal(v_rspace_used, ksmat(1)%matrix, &
1829 rho_ao(1)%matrix, qs_env, &
1830 calculate_forces, "ORB")
1831 END IF
1832 IF (lri_env%ppl_ri) THEN
1833 CALL v_int_ppl_update(qs_env, lri_v_int, calculate_forces)
1834 END IF
1835 ELSE IF (rigpw) THEN
1836 lri_v_int => lri_density%lri_coefs(ispin)%lri_kinds
1837 CALL get_qs_env(qs_env, nkind=nkind, para_env=para_env)
1838 DO ikind = 1, nkind
1839 lri_v_int(ikind)%v_int = 0.0_dp
1840 END DO
1841 CALL integrate_v_rspace_one_center(v_rspace_used, qs_env, &
1842 lri_v_int, calculate_forces, "RI_HXC")
1843 DO ikind = 1, nkind
1844 CALL para_env%sum(lri_v_int(ikind)%v_int)
1845 END DO
1846 ELSE
1847 rho_ao => my_rho(ispin, :)
1848 ksmat => ks_matrix(ispin, :)
1849 CALL integrate_v_rspace(v_rspace=v_rspace_used, &
1850 pmat_kp=rho_ao, &
1851 hmat_kp=ksmat, &
1852 qs_env=qs_env, &
1853 calculate_forces=calculate_forces, &
1854 gapw=gapw)
1855 END IF
1856 IF (use_work_v_rspace) CALL auxbas_pw_pool%give_back_pw(v_rspace_work)
1857 END DO
1858 END IF ! ASSOCIATED(v_rspace_new)
1859
1860 ! **** LRIGPW: KS matrix from integrated potential
1861 IF (lrigpw) THEN
1862 CALL get_qs_env(qs_env, ks_env=ks_env)
1863 CALL get_ks_env(ks_env=ks_env, kpoints=kpoints)
1864 CALL get_kpoint_info(kpoint=kpoints, cell_to_index=cell_to_index)
1865 DO ispin = 1, nspins
1866 ksmat => ks_matrix(ispin, :)
1867 CALL calculate_lri_ks_matrix(lri_env, lri_v_int, ksmat, atomic_kind_set, &
1868 cell_to_index=cell_to_index)
1869 END DO
1870 IF (calculate_forces) THEN
1871 CALL calculate_lri_forces(lri_env, lri_density, qs_env, rho_ao_kp, atomic_kind_set)
1872 END IF
1873 ELSE IF (rigpw) THEN
1874 CALL get_qs_env(qs_env, matrix_s=smat)
1875 DO ispin = 1, nspins
1876 CALL calculate_ri_ks_matrix(lri_env, lri_v_int, ks_matrix(ispin, 1)%matrix, &
1877 smat(1)%matrix, atomic_kind_set, ispin)
1878 END DO
1879 IF (calculate_forces) THEN
1880 rho_ao_nokp => rho_ao_kp(:, 1)
1881 CALL calculate_ri_forces(lri_env, lri_density, qs_env, rho_ao_nokp, atomic_kind_set)
1882 END IF
1883 END IF
1884
1885 IF (ASSOCIATED(v_tau_rspace)) THEN
1886 IF (lrigpw .OR. rigpw) THEN
1887 cpabort("LRIGPW/RIGPW not implemented for meta-GGAs")
1888 END IF
1889 DO ispin = 1, nspins
1890 CALL pw_scale(v_tau_rspace(ispin), v_tau_rspace(ispin)%pw_grid%dvol)
1891
1892 rho_ao => rho_ao_kp(ispin, :)
1893 ksmat => ks_matrix(ispin, :)
1894 CALL integrate_v_rspace(v_rspace=v_tau_rspace(ispin), &
1895 pmat_kp=rho_ao, hmat_kp=ksmat, &
1896 qs_env=qs_env, &
1897 calculate_forces=calculate_forces, compute_tau=.true., &
1898 gapw=(gapw .OR. gapw_xc) .AND. &
1899 .NOT. gapw_composite_direct_ao)
1900 CALL auxbas_pw_pool%give_back_pw(v_tau_rspace(ispin))
1901 END DO
1902 DEALLOCATE (v_tau_rspace)
1903 END IF
1904
1905 ! Add contributions from ADMM if requested
1906 IF (dft_control%do_admm) THEN
1907 CALL get_qs_env(qs_env, admm_env=admm_env)
1908 CALL get_admm_env(admm_env, matrix_ks_aux_fit_kp=matrix_ks_aux_fit, rho_aux_fit=rho_aux_fit, &
1909 matrix_ks_aux_fit_dft_kp=matrix_ks_aux_fit_dft)
1910 CALL qs_rho_get(rho_aux_fit, rho_ao_kp=rho_ao_aux)
1911 IF (ASSOCIATED(v_rspace_new_aux_fit)) THEN
1912 DO ispin = 1, nspins
1913 ! Calculate the xc potential
1914 CALL pw_scale(v_rspace_new_aux_fit(ispin), v_rspace_new_aux_fit(ispin)%pw_grid%dvol)
1915
1916 ! set matrix_ks_aux_fit_dft = matrix_ks_aux_fit(k_HF)
1917 DO img = 1, dft_control%nimages
1918 CALL dbcsr_copy(matrix_ks_aux_fit_dft(ispin, img)%matrix, matrix_ks_aux_fit(ispin, img)%matrix, &
1919 name="DFT exch. part of matrix_ks_aux_fit")
1920 END DO
1921
1922 ! Add potential to ks_matrix aux_fit, skip integration if no DFT correction
1923
1924 IF (admm_env%aux_exch_func /= do_admm_aux_exch_func_none) THEN
1925
1926 !GPW by default. IF GAPW, then take relevant task list and basis
1927 CALL get_admm_env(admm_env, task_list_aux_fit=task_list)
1928 basis_type = "AUX_FIT"
1929 IF (admm_env%do_gapw) THEN
1930 task_list => admm_env%admm_gapw_env%task_list
1931 basis_type = "AUX_FIT_SOFT"
1932 END IF
1933 fadm = 1.0_dp
1934 ! Calculate bare scaling of force according to Merlot, 1. IF: ADMMP, 2. IF: ADMMS,
1935 IF (admm_env%do_admmp) THEN
1936 fadm = admm_env%gsi(ispin)**2
1937 ELSE IF (admm_env%do_admms) THEN
1938 fadm = (admm_env%gsi(ispin))**(2.0_dp/3.0_dp)
1939 END IF
1940
1941 rho_ao => rho_ao_aux(ispin, :)
1942 ksmat => matrix_ks_aux_fit(ispin, :)
1943
1944 CALL integrate_v_rspace(v_rspace=v_rspace_new_aux_fit(ispin), &
1945 pmat_kp=rho_ao, &
1946 hmat_kp=ksmat, &
1947 qs_env=qs_env, &
1948 calculate_forces=calculate_forces, &
1949 force_adm=fadm, &
1950 gapw=.false., & !even if actual GAPW calculation, want to use AUX_FIT_SOFT
1951 basis_type=basis_type, &
1952 task_list_external=task_list)
1953 END IF
1954
1955 ! matrix_ks_aux_fit_dft(x_DFT)=matrix_ks_aux_fit_dft(old,k_HF)-matrix_ks_aux_fit(k_HF-x_DFT)
1956 DO img = 1, dft_control%nimages
1957 CALL dbcsr_add(matrix_ks_aux_fit_dft(ispin, img)%matrix, &
1958 matrix_ks_aux_fit(ispin, img)%matrix, 1.0_dp, -1.0_dp)
1959 END DO
1960
1961 CALL auxbas_pw_pool%give_back_pw(v_rspace_new_aux_fit(ispin))
1962 END DO
1963 DEALLOCATE (v_rspace_new_aux_fit)
1964 END IF
1965 ! Clean up v_tau_rspace_aux_fit, which is actually not needed
1966 IF (ASSOCIATED(v_tau_rspace_aux_fit)) THEN
1967 DO ispin = 1, nspins
1968 CALL auxbas_pw_pool%give_back_pw(v_tau_rspace_aux_fit(ispin))
1969 END DO
1970 DEALLOCATE (v_tau_rspace_aux_fit)
1971 END IF
1972 END IF
1973
1974 IF (dft_control%apply_embed_pot) DEALLOCATE (v_rspace_embed)
1975
1976 CALL timestop(handle)
1977
1978 END SUBROUTINE sum_up_and_integrate
1979
1980!**************************************************************************
1981!> \brief Calculate the ZMP potential and energy as in Zhao, Morrison Parr
1982!> PRA 50i, 2138 (1994)
1983!> V_c^\lambda defined as int_rho-rho_0/r-r' or rho-rho_0 times a Lagrange
1984!> multiplier, plus Fermi-Amaldi potential that should give the V_xc in the
1985!> limit \lambda --> \infty
1986!>
1987!> \param qs_env ...
1988!> \param v_rspace_new ...
1989!> \param rho ...
1990!> \param exc ...
1991!> \author D. Varsano [daniele.varsano@nano.cnr.it]
1992! **************************************************************************************************
1993 SUBROUTINE calculate_zmp_potential(qs_env, v_rspace_new, rho, exc)
1994
1995 TYPE(qs_environment_type), POINTER :: qs_env
1996 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: v_rspace_new
1997 TYPE(qs_rho_type), POINTER :: rho
1998 REAL(kind=dp) :: exc
1999
2000 CHARACTER(*), PARAMETER :: routinen = 'calculate_zmp_potential'
2001
2002 INTEGER :: handle, my_val, nelectron, nspins
2003 INTEGER, DIMENSION(2) :: nelectron_spin
2004 LOGICAL :: do_zmp_read, fermi_amaldi
2005 REAL(kind=dp) :: lambda
2006 REAL(kind=dp), DIMENSION(:), POINTER :: tot_rho_ext_r
2007 TYPE(dft_control_type), POINTER :: dft_control
2008 TYPE(pw_c1d_gs_type), DIMENSION(:), POINTER :: rho_ext_g, rho_g
2009 TYPE(pw_env_type), POINTER :: pw_env
2010 TYPE(pw_poisson_type), POINTER :: poisson_env
2011 TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
2012 TYPE(pw_r3d_rs_type) :: v_xc_rspace
2013 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: rho_r
2014 TYPE(qs_ks_env_type), POINTER :: ks_env
2015 TYPE(section_vals_type), POINTER :: ext_den_section, input
2016
2017!, v_h_gspace, &
2018
2019 CALL timeset(routinen, handle)
2020 NULLIFY (auxbas_pw_pool)
2021 NULLIFY (pw_env)
2022 NULLIFY (poisson_env)
2023 NULLIFY (v_rspace_new)
2024 NULLIFY (dft_control)
2025 NULLIFY (rho_r, rho_g, tot_rho_ext_r, rho_ext_g)
2026 CALL get_qs_env(qs_env=qs_env, &
2027 pw_env=pw_env, &
2028 ks_env=ks_env, &
2029 rho=rho, &
2030 input=input, &
2031 nelectron_spin=nelectron_spin, &
2032 dft_control=dft_control)
2033 CALL pw_env_get(pw_env=pw_env, &
2034 auxbas_pw_pool=auxbas_pw_pool, &
2035 poisson_env=poisson_env)
2036 CALL qs_rho_get(rho, rho_r=rho_r, rho_g=rho_g)
2037 nspins = 1
2038 ALLOCATE (v_rspace_new(nspins))
2039 CALL auxbas_pw_pool%create_pw(pw=v_rspace_new(1))
2040 CALL auxbas_pw_pool%create_pw(pw=v_xc_rspace)
2041
2042 CALL pw_zero(v_rspace_new(1))
2043 do_zmp_read = dft_control%apply_external_vxc
2044 IF (do_zmp_read) THEN
2045 CALL pw_copy(qs_env%external_vxc, v_rspace_new(1))
2046 exc = accurate_dot_product(v_rspace_new(1)%array, rho_r(1)%array)* &
2047 v_rspace_new(1)%pw_grid%dvol
2048 ELSE
2049 block
2050 REAL(kind=dp) :: factor
2051 TYPE(pw_c1d_gs_type) :: rho_eff_gspace, v_xc_gspace
2052 CALL auxbas_pw_pool%create_pw(pw=rho_eff_gspace)
2053 CALL auxbas_pw_pool%create_pw(pw=v_xc_gspace)
2054 CALL pw_zero(rho_eff_gspace)
2055 CALL pw_zero(v_xc_gspace)
2056 CALL pw_zero(v_xc_rspace)
2057 factor = pw_integrate_function(rho_g(1))
2058 CALL qs_rho_get(qs_env%rho_external, &
2059 rho_g=rho_ext_g, &
2060 tot_rho_r=tot_rho_ext_r)
2061 factor = tot_rho_ext_r(1)/factor
2062
2063 CALL pw_axpy(rho_g(1), rho_eff_gspace, alpha=factor)
2064 CALL pw_axpy(rho_ext_g(1), rho_eff_gspace, alpha=-1.0_dp)
2065 ext_den_section => section_vals_get_subs_vals(input, "DFT%EXTERNAL_DENSITY")
2066 CALL section_vals_val_get(ext_den_section, "LAMBDA", r_val=lambda)
2067 CALL section_vals_val_get(ext_den_section, "ZMP_CONSTRAINT", i_val=my_val)
2068 CALL section_vals_val_get(ext_den_section, "FERMI_AMALDI", l_val=fermi_amaldi)
2069
2070 CALL pw_scale(rho_eff_gspace, a=lambda)
2071 nelectron = nelectron_spin(1)
2072 factor = -1.0_dp/nelectron
2073 CALL pw_axpy(rho_g(1), rho_eff_gspace, alpha=factor)
2074
2075 CALL pw_poisson_solve(poisson_env, rho_eff_gspace, vhartree=v_xc_gspace)
2076 CALL pw_transfer(v_xc_gspace, v_rspace_new(1))
2077 CALL pw_copy(v_rspace_new(1), v_xc_rspace)
2078
2079 exc = 0.0_dp
2080 exc = pw_integral_ab(v_rspace_new(1), rho_r(1))
2081
2082!Note that this is not the xc energy but \int(\rho*v_xc)
2083!Vxc---> v_rspace_new
2084!Exc---> energy%exc
2085 CALL auxbas_pw_pool%give_back_pw(rho_eff_gspace)
2086 CALL auxbas_pw_pool%give_back_pw(v_xc_gspace)
2087 END block
2088 END IF
2089
2090 CALL auxbas_pw_pool%give_back_pw(v_xc_rspace)
2091
2092 CALL timestop(handle)
2093
2094 END SUBROUTINE calculate_zmp_potential
2095
2096! **************************************************************************************************
2097!> \brief ...
2098!> \param qs_env ...
2099!> \param rho ...
2100!> \param v_rspace_embed ...
2101!> \param dft_control ...
2102!> \param embed_corr ...
2103!> \param just_energy ...
2104! **************************************************************************************************
2105 SUBROUTINE get_embed_potential_energy(qs_env, rho, v_rspace_embed, dft_control, embed_corr, &
2106 just_energy)
2107 TYPE(qs_environment_type), POINTER :: qs_env
2108 TYPE(qs_rho_type), POINTER :: rho
2109 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: v_rspace_embed
2110 TYPE(dft_control_type), POINTER :: dft_control
2111 REAL(kind=dp) :: embed_corr
2112 LOGICAL :: just_energy
2113
2114 CHARACTER(*), PARAMETER :: routinen = 'get_embed_potential_energy'
2115
2116 INTEGER :: handle, ispin
2117 REAL(kind=dp) :: embed_corr_local
2118 TYPE(pw_env_type), POINTER :: pw_env
2119 TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
2120 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: rho_r
2121
2122 CALL timeset(routinen, handle)
2123
2124 NULLIFY (auxbas_pw_pool)
2125 NULLIFY (pw_env)
2126 NULLIFY (rho_r)
2127 CALL get_qs_env(qs_env=qs_env, &
2128 pw_env=pw_env, &
2129 rho=rho)
2130 CALL pw_env_get(pw_env=pw_env, &
2131 auxbas_pw_pool=auxbas_pw_pool)
2132 CALL qs_rho_get(rho, rho_r=rho_r)
2133 ALLOCATE (v_rspace_embed(dft_control%nspins))
2134
2135 embed_corr = 0.0_dp
2136
2137 DO ispin = 1, dft_control%nspins
2138 CALL auxbas_pw_pool%create_pw(pw=v_rspace_embed(ispin))
2139 CALL pw_zero(v_rspace_embed(ispin))
2140
2141 CALL pw_copy(qs_env%embed_pot, v_rspace_embed(ispin))
2142 embed_corr_local = 0.0_dp
2143
2144 ! Spin embedding potential in open-shell case
2145 IF (dft_control%nspins == 2) THEN
2146 IF (ispin == 1) CALL pw_axpy(qs_env%spin_embed_pot, v_rspace_embed(ispin), 1.0_dp)
2147 IF (ispin == 2) CALL pw_axpy(qs_env%spin_embed_pot, v_rspace_embed(ispin), -1.0_dp)
2148 END IF
2149 ! Integrate the density*potential
2150 embed_corr_local = pw_integral_ab(v_rspace_embed(ispin), rho_r(ispin))
2151
2152 embed_corr = embed_corr + embed_corr_local
2153
2154 END DO
2155
2156 ! If only energy requiested we delete the potential
2157 IF (just_energy) THEN
2158 DO ispin = 1, dft_control%nspins
2159 CALL auxbas_pw_pool%give_back_pw(v_rspace_embed(ispin))
2160 END DO
2161 DEALLOCATE (v_rspace_embed)
2162 END IF
2163
2164 CALL timestop(handle)
2165
2166 END SUBROUTINE get_embed_potential_energy
2167
2168END MODULE qs_ks_utils
Types and set/get functions for auxiliary density matrix methods.
Definition admm_types.F:15
subroutine, public get_admm_env(admm_env, mo_derivs_aux_fit, mos_aux_fit, sab_aux_fit, sab_aux_fit_asymm, sab_aux_fit_vs_orb, matrix_s_aux_fit, matrix_s_aux_fit_kp, matrix_s_aux_fit_vs_orb, matrix_s_aux_fit_vs_orb_kp, task_list_aux_fit, matrix_ks_aux_fit, matrix_ks_aux_fit_kp, matrix_ks_aux_fit_im, matrix_ks_aux_fit_dft, matrix_ks_aux_fit_hfx, matrix_ks_aux_fit_dft_kp, matrix_ks_aux_fit_hfx_kp, rho_aux_fit, rho_aux_fit_buffer, admm_dm)
Get routine for the ADMM env.
Definition admm_types.F:599
Define the atomic kind types and their sub types.
subroutine, public get_atomic_kind(atomic_kind, fist_potential, element_symbol, name, mass, kind_number, natom, atom_list, rcov, rvdw, z, qeff, apol, cpol, mm_radius, shell, shell_active, damping)
Get attributes of an atomic kind.
Handles all functions related to the CELL.
Definition cell_types.F:15
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
subroutine, public dbcsr_release_p(matrix)
...
subroutine, public dbcsr_scale(matrix, alpha_scalar)
...
subroutine, public dbcsr_deallocate_matrix(matrix)
...
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_get_info(matrix, nblkrows_total, nblkcols_total, nfullrows_total, nfullcols_total, nblkrows_local, nblkcols_local, nfullrows_local, nfullcols_local, my_prow, my_pcol, local_rows, local_cols, proc_row_dist, proc_col_dist, row_blk_size, col_blk_size, row_blk_offset, col_blk_offset, distribution, name, matrix_type, group)
...
subroutine, public dbcsr_init_p(matrix)
...
subroutine, public dbcsr_set(matrix, alpha)
...
subroutine, public dbcsr_add(matrix_a, matrix_b, alpha_scalar, beta_scalar)
...
subroutine, public dbcsr_dot(matrix_a, matrix_b, trace)
Computes the dot product of two matrices, also known as the trace of their matrix product.
subroutine, public dbcsr_scale_by_vector(matrix, alpha, side)
Scales the rows/columns of given matrix.
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, plan, check_plan)
Copy a DBCSR matrix to a BLACS matrix.
subroutine, public cp_dbcsr_plus_fm_fm_t(sparse_matrix, matrix_v, matrix_g, ncol, alpha, keep_sparsity, symmetry_mode)
performs the multiplication sparse_matrix+dense_mat*dens_mat^T if matrix_g is not explicitly given,...
subroutine, public copy_fm_to_dbcsr(fm, matrix, keep_sparsity)
Copy a BLACS matrix to a dbcsr matrix.
Density Derived atomic point charges from a QM calculation (see Bloechl, J. Chem. Phys....
Definition cp_ddapc.F:15
subroutine, public cp_ddapc_apply_cd(qs_env, rho_tot_gspace, energy, v_hartree_gspace, calculate_forces, itype_of_density)
Routine to couple/decouple periodic images with the Bloechl scheme.
Definition cp_ddapc.F:226
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_get_info(matrix, name, nrow_global, ncol_global, nrow_block, ncol_block, nrow_local, ncol_local, row_indices, col_indices, local_data, context, nrow_locals, ncol_locals, matrix_struct, para_env)
returns all kind of information about the full matrix
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_create(matrix, matrix_struct, name, nrow, ncol, set_zero)
creates a new full matrix with the given structure
various routines to log and control the output. The idea is that decisions about where to log should ...
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
routines to handle the output, The idea is to remove the decision of wheter to output and what to out...
subroutine, public cp_print_key_finished_output(unit_nr, logger, basis_section, print_key_path, local, ignore_should_output, on_file, mpi_io)
should be called after you finish working with a unit obtained with cp_print_key_unit_nr,...
integer, parameter, public cp_p_file
integer function, public cp_print_key_should_output(iteration_info, basis_section, print_key_path, used_print_key, first_time)
returns what should be done with the given property if btest(res,cp_p_store) then the property should...
integer function, public cp_print_key_unit_nr(logger, basis_section, print_key_path, extension, middle_name, local, log_filename, ignore_should_output, file_form, file_position, file_action, file_status, do_backup, on_file, is_new_file, mpi_io, fout, file_access)
...
Utilities for hfx and admm methods.
subroutine, public tddft_hfx_matrix(matrix_ks, rho_ao, qs_env, update_energy, recalc_integrals, external_hfx_sections, external_x_data, external_para_env)
Add the hfx contributions to the Hamiltonian.
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, nspins)
computes four center derivatives for a full basis set and updates the forcesfock_4c arrays....
Types and set/get functions for HFX.
Definition hfx_types.F:16
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public sic_list_unpaired
integer, parameter, public sic_mauri_spz
integer, parameter, public cdft_beta_constraint
integer, parameter, public cdft_magnetization_constraint
integer, parameter, public sic_list_all
integer, parameter, public cdft_charge_constraint
integer, parameter, public sic_eo
integer, parameter, public do_ppl_grid
integer, parameter, public do_admm_aux_exch_func_none
integer, parameter, public sic_mauri_us
integer, parameter, public sic_none
integer, parameter, public cdft_alpha_constraint
integer, parameter, public sic_ad
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_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
sums arrays of real/complex numbers with much reduced round-off as compared to a naive implementation...
Definition kahan_sum.F:29
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
integer, parameter, public default_string_length
Definition kinds.F:57
Types and basic routines needed for a kpoint calculation.
subroutine, public get_kpoint_info(kpoint, kp_scheme, nkp_grid, kp_shift, symmetry, verbose, full_grid, use_real_wfn, eps_geo, parallel_group_size, kp_range, nkp, xkp, wkp, para_env, blacs_env_all, para_env_kp, para_env_inter_kp, blacs_env, kp_env, kp_aux_env, mpools, iogrp, nkp_groups, kp_dist, cell_to_index, index_to_cell, sab_nl, sab_nl_nosym, inversion_symmetry_only, symmetry_backend, symmetry_reduction_method, gamma_centered, lattice_fft)
Retrieve information from a kpoint environment.
Calculates integral matrices for LRIGPW method lri : local resolution of the identity.
subroutine, public v_int_ppl_update(qs_env, lri_v_int, calculate_forces)
...
contains the types and subroutines for dealing with the lri_env lri : local resolution of the identit...
Calculates forces for LRIGPW method lri : local resolution of the identity.
Definition lri_forces.F:16
subroutine, public calculate_lri_forces(lri_env, lri_density, qs_env, pmatrix, atomic_kind_set)
calculates the lri forces
Definition lri_forces.F:81
subroutine, public calculate_ri_forces(lri_env, lri_density, qs_env, pmatrix, atomic_kind_set)
calculates the ri forces
Definition lri_forces.F:673
routines that build the Kohn-Sham matrix for the LRIGPW and xc parts
subroutine, public calculate_lri_ks_matrix(lri_env, lri_v_int, h_matrix, atomic_kind_set, cell_to_index)
update of LRIGPW KS matrix
subroutine, public calculate_ri_ks_matrix(lri_env, lri_v_int, h_matrix, s_matrix, atomic_kind_set, ispin)
update of RIGPW KS matrix
Collection of simple mathematical functions and subroutines.
Definition mathlib.F:15
logical function, public abnormal_value(a)
determines if a value is not normal (e.g. for Inf and Nan) based on IO to work also under optimizatio...
Definition mathlib.F:161
Interface to the message passing library MPI.
Types containing essential information for running implicit (iterative) Poisson solver.
integer, parameter, public neumann_bc
integer, parameter, public mixed_bc
integer, parameter, public mixed_periodic_bc
integer, parameter, public periodic_bc
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
integer, parameter, public pw_poisson_implicit
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
Defines CDFT control structures.
container for information about total charges on the grids
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
subroutine, public get_qs_env(qs_env, atomic_kind_set, qs_kind_set, cell, super_cell, cell_ref, use_ref_cell, kpoints, dft_control, mos, sab_orb, sab_all, qmmm, qmmm_periodic, mimic, sac_ae, sac_ppl, sac_lri, sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, sab_cneo, particle_set, energy, force, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, matrix_vhxc, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, xcint_weights, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, rhoz_cneo_set, ecoul_1c, rho0_s_rs, rho0_s_gs, rhoz_cneo_s_rs, rhoz_cneo_s_gs, do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, lri_env, lri_density, exstate_env, ec_env, harris_env, dispersion_env, gcp_env, vee, rho_external, external_vxc, mask, mp2_env, bs_env, kg_env, wanniercentres, atprop, ls_scf_env, do_transport, transport_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, mscfg_env, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, eeq, rhs, do_rixs, tb_tblite)
Get the QUICKSTEP environment.
Integrate single or product functions over a potential on a RS grid.
Define the quickstep kind type and their sub types.
subroutine, public get_qs_kind(qs_kind, basis_set, basis_type, ncgf, nsgf, all_potential, tnadd_potential, gth_potential, sgp_potential, upf_potential, cneo_potential, se_parameter, dftb_parameter, xtb_parameter, dftb3_param, zatom, zeff, elec_conf, mao, lmax_dftb, alpha_core_charge, ccore_charge, core_charge, core_charge_radius, paw_proj_set, paw_atom, hard_radius, hard0_radius, max_rad_local, covalent_radius, vdw_radius, gpw_type_forced, harmonics, max_iso_not0, max_s_harm, grid_atom, ngrid_ang, ngrid_rad, lmax_rho0, dft_plus_u_atom, l_of_dft_plus_u, n_of_dft_plus_u, u_minus_j, hund_j, u_of_dft_plus_u, j_of_dft_plus_u, alpha_of_dft_plus_u, beta_of_dft_plus_u, j0_of_dft_plus_u, occupation_of_dft_plus_u, dispersion, bs_occupation, magnetization, no_optimize, addel, laddel, naddel, orbitals, max_scf, eps_scf, smear, u_ramping, u_minus_j_target, eps_u_ramping, proj_shell_charge, lr_atom, do_mtlr, u_j_loop, ao_coef, init_u_ramping_each_scf, reltmat, ghost, monovalent, floating, name, element_symbol, pao_basis_size, pao_model_file, pao_potentials, pao_descriptors, nelec)
Get attributes of an atomic kind.
subroutine, public get_qs_kind_set(qs_kind_set, all_potential_present, tnadd_potential_present, gth_potential_present, sgp_potential_present, paw_atom_present, dft_plus_u_atom_present, maxcgf, maxsgf, maxco, maxco_proj, maxgtops, maxlgto, maxlprj, maxnset, maxsgf_set, ncgf, npgf, nset, nsgf, nshell, maxpol, maxlppl, maxlppnl, maxppnl, nelectron, maxder, max_ngrid_rad, max_sph_harm, maxg_iso_not0, lmax_rho0, basis_rcut, do_mtlr_present, basis_type, total_zeff_corr, npgf_seg, cneo_potential_present, nkind_q, natom_q)
Get attributes of an atomic kind set.
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:144
subroutine, public qmmm_modify_hartree_pot(v_hartree, v_qmmm, scale)
Modify the hartree potential in order to include the QM/MM correction.
subroutine, public get_ks_env(ks_env, v_hartree_rspace, s_mstruct_changed, rho_changed, exc_accint, potential_changed, forces_up_to_date, complex_ks, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, kinetic, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, matrix_vhxc, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_ks_im_kp, rho, rho_xc, vppl, xcint_weights, rho_core, rho_nlcc, rho_nlcc_g, vee, neighbor_list_id, sab_orb, sab_all, sac_ae, sac_ppl, sac_lri, sap_ppnl, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_vdw, sab_scp, sab_almo, sab_kp, sab_kp_nosym, sab_cneo, task_list, task_list_soft, kpoints, do_kpoints, atomic_kind_set, qs_kind_set, cell, cell_ref, use_ref_cell, particle_set, energy, force, local_particles, local_molecules, molecule_kind_set, molecule_set, subsys, cp_subsys, virial, results, atprop, nkind, natom, dft_control, dbcsr_dist, distribution_2d, pw_env, para_env, blacs_env, nelectron_total, nelectron_spin)
...
routines that build the Kohn-Sham matrix (i.e calculate the coulomb and xc parts
Definition qs_ks_utils.F:22
subroutine, public print_densities(qs_env, rho)
...
subroutine, public get_embed_potential_energy(qs_env, rho, v_rspace_embed, dft_control, embed_corr, just_energy)
...
subroutine, public low_spin_roks(energy, qs_env, dft_control, do_hfx, just_energy, calculate_forces, auxbas_pw_pool)
do ROKS calculations yielding low spin states
subroutine, public check_sum_energies(energy)
Check each term of the energy and sum to total.
subroutine, public compute_matrix_vxc(qs_env, v_rspace, matrix_vxc, gapw_full_basis)
Integrate the scalar XC potential into spin/image-resolved AO matrices. Gamma-only calculations have ...
subroutine, public sum_up_and_integrate(qs_env, ks_matrix, rho, my_rho, vppl_rspace, v_rspace_new, v_rspace_new_aux_fit, v_tau_rspace, v_tau_rspace_aux_fit, v_sic_rspace, v_spin_ddapc_rest_r, v_sccs_rspace, v_rspace_embed, cdft_control, calculate_forces)
Sum up all potentials defined on the grid and integrate.
subroutine, public print_detailed_energy(qs_env, dft_control, input, energy, mulliken_order_p)
Print detailed energies.
subroutine, public calculate_zmp_potential(qs_env, v_rspace_new, rho, exc)
Calculate the ZMP potential and energy as in Zhao, Morrison Parr PRA 50i, 2138 (1994) V_c^\lambda def...
subroutine, public calc_v_sic_rspace(v_sic_rspace, energy, qs_env, dft_control, rho, poisson_env, just_energy, calculate_forces, auxbas_pw_pool)
do sic calculations on the spin density
subroutine, public sic_explicit_orbitals(energy, qs_env, dft_control, poisson_env, just_energy, calculate_forces, auxbas_pw_pool)
do sic calculations on explicit orbitals
Definition and initialisation of the mo data type.
Definition qs_mo_types.F:22
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, cmo_coeff)
Get the components of a MO set data structure.
Define the neighbor list data types and the corresponding functionality.
subroutine, public calculate_rho_atom(para_env, rho_atom_set, qs_kind, atom_list, natom, nspins, tot_rho1_h, tot_rho1_s, rho1_h_spin, rho1_s_spin, rho1_h_aspin, rho1_s_aspin)
...
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)
...
subroutine, public deallocate_rho_atom_set(rho_atom_set)
...
subroutine, public zero_rho_atom_integrals(rho_atom_set)
...
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_vxc_atom(qs_env, energy_only, exc1, adiabatic_rescale_factor, kind_set_external, rho_atom_set_external, xc_section_external, calculate_forces, composite_vxc_rho, composite_vxc_tau, composite_reference_active, direct_valence_atom_grid, atom_composite_grid)
...
Experimental CP2K-native GPW real-space-grid path for SKALA TorchScript models.
logical function, public native_skala_gapw_composite_direct_ao(xc_section)
Return true if the GAPW composite reference uses direct full-ORB collocation.
logical function, public native_skala_gapw_composite_reference(xc_section)
Return true if native SKALA should use the full GAPW ORB density on one common grid.
types for task lists
type(xc_rho_cflags_type) function, public xc_functionals_get_needs(functionals, lsd, calc_potential)
...
subroutine, public apply_gauxc(qs_env, xc_section, calculate_forces, rho_ao_external, exc_external, matrix_vxc_external)
Evaluate molecular GauXC, optionally for an explicit configuration density.
contains the structure
Exchange and Correlation functional calculations.
Definition xc.F:17
real(kind=dp) function, public xc_exc_calc(rho_r, rho_g, tau, xc_section, weights, pw_pool)
calculates just the exchange and correlation energy (no vxc)
Definition xc.F:795
subroutine, public xc_vxc_pw_create(vxc_rho, vxc_tau, exc, rho_r, rho_g, tau, xc_section, weights, pw_pool, compute_virial, virial_xc, exc_r)
Exchange and Correlation functional calculations.
Definition xc.F:478
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:60
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...
stores some data used in construction of Kohn-Sham matrix
Definition hfx_types.F:474
Contains information about kpoints.
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 ...
Container for information about total charges on the grids.
Provides all information about a quickstep kind.
calculation environment to calculate the ks matrix, holds all the needed vars. assumes that the core ...
keeps the density in various representations, keeping track of which ones are valid.
contains a flag for each component of xc_rho_set, so that you can use it to tell which components you...