(git:15c1bfc)
Loading...
Searching...
No Matches
qs_ks_methods.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2025 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
8! **************************************************************************************************
9!> \brief routines that build the Kohn-Sham matrix (i.e calculate the coulomb
10!> and xc parts
11!> \author Fawzi Mohamed
12!> \par History
13!> - 05.2002 moved from qs_scf (see there the history) [fawzi]
14!> - JGH [30.08.02] multi-grid arrays independent from density and potential
15!> - 10.2002 introduced pools, uses updated rho as input,
16!> removed most temporary variables, renamed may vars,
17!> began conversion to LSD [fawzi]
18!> - 10.2004 moved calculate_w_matrix here [Joost VandeVondele]
19!> introduced energy derivative wrt MOs [Joost VandeVondele]
20!> - SCCS implementation (16.10.2013,MK)
21! **************************************************************************************************
32 USE admm_types, ONLY: admm_type,&
34 USE cell_types, ONLY: cell_type
36 USE cp_dbcsr_api, ONLY: &
38 dbcsr_p_type, dbcsr_release, dbcsr_set, dbcsr_type, dbcsr_type_antisymmetric, &
39 dbcsr_type_symmetric
43 USE cp_ddapc, ONLY: qs_ks_ddapc
44 USE cp_fm_types, ONLY: cp_fm_type
48 USE cp_output_handling, ONLY: cp_p_file,&
50 USE dft_plus_u, ONLY: plus_u
53 USE hfx_admm_utils, ONLY: hfx_admm_init,&
56 USE input_constants, ONLY: do_ppl_grid,&
65 USE kinds, ONLY: default_string_length,&
66 dp
67 USE kpoint_types, ONLY: get_kpoint_info,&
73 USE mathlib, ONLY: abnormal_value
75 USE pw_env_types, ONLY: pw_env_get,&
77 USE pw_methods, ONLY: pw_axpy,&
78 pw_copy,&
81 pw_scale,&
88 USE pw_types, ONLY: pw_c1d_gs_type,&
105 USE qs_integrate_potential, ONLY: integrate_ppl_rspace,&
106 integrate_rho_nlcc,&
107 integrate_v_core_rspace
111 USE qs_ks_atom, ONLY: update_ks_atom
114 USE qs_ks_types, ONLY: qs_ks_env_type,&
116 USE qs_ks_utils, ONLY: &
121 USE qs_mo_types, ONLY: get_mo_set,&
125 USE qs_rho_types, ONLY: qs_rho_get,&
127 USE qs_sccs, ONLY: sccs
129 USE qs_vxc, ONLY: qs_vxc_create
137 USE virial_types, ONLY: virial_type
139#include "./base/base_uses.f90"
140
141 IMPLICIT NONE
142
143 PRIVATE
144
145 LOGICAL, PARAMETER :: debug_this_module = .true.
146 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_ks_methods'
147
150
151CONTAINS
152
153! **************************************************************************************************
154!> \brief routine where the real calculations are made: the
155!> KS matrix is calculated
156!> \param qs_env the qs_env to update
157!> \param calculate_forces if true calculate the quantities needed
158!> to calculate the forces. Defaults to false.
159!> \param just_energy if true updates the energies but not the
160!> ks matrix. Defaults to false
161!> \param print_active ...
162!> \param ext_ks_matrix ...
163!> \par History
164!> 06.2002 moved from qs_scf to qs_ks_methods, use of ks_env
165!> new did_change scheme [fawzi]
166!> 10.2002 introduced pools, uses updated rho as input, LSD [fawzi]
167!> 10.2004 build_kohn_sham matrix now also computes the derivatives
168!> of the total energy wrt to the MO coefs, if instructed to
169!> do so. This appears useful for orbital dependent functionals
170!> where the KS matrix alone (however this might be defined)
171!> does not contain the info to construct this derivative.
172!> \author Matthias Krack
173!> \note
174!> make rho, energy and qs_charges optional, defaulting
175!> to qs_env components?
176! **************************************************************************************************
177 SUBROUTINE qs_ks_build_kohn_sham_matrix(qs_env, calculate_forces, just_energy, &
178 print_active, ext_ks_matrix)
179 TYPE(qs_environment_type), POINTER :: qs_env
180 LOGICAL, INTENT(in) :: calculate_forces, just_energy
181 LOGICAL, INTENT(IN), OPTIONAL :: print_active
182 TYPE(dbcsr_p_type), DIMENSION(:), OPTIONAL, &
183 POINTER :: ext_ks_matrix
184
185 CHARACTER(LEN=*), PARAMETER :: routinen = 'qs_ks_build_kohn_sham_matrix'
186
187 CHARACTER(len=default_string_length) :: name
188 INTEGER :: handle, iatom, img, ispin, nimages, &
189 nspins
190 LOGICAL :: do_adiabatic_rescaling, do_ddapc, do_hfx, do_ppl, dokp, gapw, gapw_xc, &
191 hfx_treat_lsd_in_core, just_energy_xc, lrigpw, my_print, rigpw, use_virial
192 REAL(kind=dp) :: ecore_ppl, edisp, ee_ener, ekin_mol, &
193 mulliken_order_p, vscale
194 REAL(kind=dp), DIMENSION(3, 3) :: h_stress, pv_loc
195 TYPE(admm_type), POINTER :: admm_env
196 TYPE(cdft_control_type), POINTER :: cdft_control
197 TYPE(cell_type), POINTER :: cell
198 TYPE(cp_logger_type), POINTER :: logger
199 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: ksmat, matrix_vxc, mo_derivs
200 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: ks_matrix, ks_matrix_im, matrix_h, &
201 matrix_h_im, matrix_s, my_rho, rho_ao
202 TYPE(dft_control_type), POINTER :: dft_control
203 TYPE(ecoul_1center_type), DIMENSION(:), POINTER :: ecoul_1c
204 TYPE(harris_type), POINTER :: harris_env
205 TYPE(local_rho_type), POINTER :: local_rho_set
206 TYPE(lri_density_type), POINTER :: lri_density
207 TYPE(lri_environment_type), POINTER :: lri_env
208 TYPE(lri_kind_type), DIMENSION(:), POINTER :: lri_v_int
209 TYPE(mp_para_env_type), POINTER :: para_env
210 TYPE(pw_c1d_gs_type) :: rho_tot_gspace, v_hartree_gspace
211 TYPE(pw_c1d_gs_type), POINTER :: rho_core
212 TYPE(pw_env_type), POINTER :: pw_env
213 TYPE(pw_poisson_type), POINTER :: poisson_env
214 TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
215 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: rho_r, v_rspace_embed, v_rspace_new, &
216 v_rspace_new_aux_fit, v_tau_rspace, &
217 v_tau_rspace_aux_fit
218 TYPE(pw_r3d_rs_type), POINTER :: rho0_s_rs, rho_nlcc, rhoz_cneo_s_rs, v_hartree_rspace, &
219 v_sccs_rspace, v_sic_rspace, v_spin_ddapc_rest_r, vee, vppl_rspace
220 TYPE(qs_energy_type), POINTER :: energy
221 TYPE(qs_ks_env_type), POINTER :: ks_env
222 TYPE(qs_rho_type), POINTER :: rho, rho_struct, rho_xc
223 TYPE(section_vals_type), POINTER :: adiabatic_rescaling_section, &
224 hfx_sections, input, scf_section, &
225 xc_section
226 TYPE(virial_type), POINTER :: virial
227
228 CALL timeset(routinen, handle)
229 NULLIFY (admm_env, cell, dft_control, logger, mo_derivs, my_rho, &
230 rho_struct, para_env, pw_env, virial, vppl_rspace, &
231 adiabatic_rescaling_section, hfx_sections, &
232 input, scf_section, xc_section, matrix_h, matrix_h_im, matrix_s, &
233 auxbas_pw_pool, poisson_env, v_rspace_new, v_rspace_new_aux_fit, &
234 v_tau_rspace, v_tau_rspace_aux_fit, matrix_vxc, vee, rho_nlcc, &
235 ks_env, ks_matrix, ks_matrix_im, rho, energy, rho_xc, rho_r, rho_ao, rho_core)
236
237 cpassert(ASSOCIATED(qs_env))
238
239 logger => cp_get_default_logger()
240 my_print = .true.
241 IF (PRESENT(print_active)) my_print = print_active
242
243 CALL get_qs_env(qs_env, &
244 ks_env=ks_env, &
245 dft_control=dft_control, &
246 matrix_h_kp=matrix_h, &
247 matrix_h_im_kp=matrix_h_im, &
248 matrix_s_kp=matrix_s, &
249 matrix_ks_kp=ks_matrix, &
250 matrix_ks_im_kp=ks_matrix_im, &
251 matrix_vxc=matrix_vxc, &
252 pw_env=pw_env, &
253 cell=cell, &
254 para_env=para_env, &
255 input=input, &
256 virial=virial, &
257 v_hartree_rspace=v_hartree_rspace, &
258 vee=vee, &
259 rho_nlcc=rho_nlcc, &
260 rho=rho, &
261 rho_core=rho_core, &
262 rho_xc=rho_xc, &
263 energy=energy)
264
265 CALL qs_rho_get(rho, rho_r=rho_r, rho_ao_kp=rho_ao)
266
267 nimages = dft_control%nimages
268 nspins = dft_control%nspins
269
270 ! remap pointer to allow for non-kpoint external ks matrix
271 IF (PRESENT(ext_ks_matrix)) ks_matrix(1:nspins, 1:1) => ext_ks_matrix(1:nspins)
272
273 use_virial = virial%pv_availability .AND. (.NOT. virial%pv_numer)
274
275 hfx_sections => section_vals_get_subs_vals(input, "DFT%XC%HF")
276 CALL section_vals_get(hfx_sections, explicit=do_hfx)
277 IF (do_hfx) THEN
278 CALL section_vals_val_get(hfx_sections, "TREAT_LSD_IN_CORE", l_val=hfx_treat_lsd_in_core, &
279 i_rep_section=1)
280 END IF
281 adiabatic_rescaling_section => section_vals_get_subs_vals(input, "DFT%XC%ADIABATIC_RESCALING")
282 CALL section_vals_get(adiabatic_rescaling_section, explicit=do_adiabatic_rescaling)
283 just_energy_xc = just_energy
284 IF (do_adiabatic_rescaling) THEN
285 !! If we perform adiabatic rescaling, the xc potential has to be scaled by the xc- and
286 !! HFX-energy. Thus, let us first calculate the energy
287 just_energy_xc = .true.
288 END IF
289
290 cpassert(ASSOCIATED(matrix_h))
291 cpassert(ASSOCIATED(matrix_s))
292 cpassert(ASSOCIATED(rho))
293 cpassert(ASSOCIATED(pw_env))
294 cpassert(SIZE(ks_matrix, 1) > 0)
295 dokp = (nimages > 1)
296
297 ! Setup the possible usage of DDAPC charges
298 do_ddapc = dft_control%qs_control%ddapc_restraint .OR. &
299 qs_env%cp_ddapc_ewald%do_decoupling .OR. &
300 qs_env%cp_ddapc_ewald%do_qmmm_periodic_decpl .OR. &
301 qs_env%cp_ddapc_ewald%do_solvation
302
303 ! Check if LRIGPW is used
304 lrigpw = dft_control%qs_control%lrigpw
305 rigpw = dft_control%qs_control%rigpw
306 IF (rigpw) THEN
307 cpassert(nimages == 1)
308 END IF
309 IF (lrigpw .AND. rigpw) THEN
310 cpabort(" LRI and RI are not compatible")
311 END IF
312
313 ! Check for GAPW method : additional terms for local densities
314 gapw = dft_control%qs_control%gapw
315 gapw_xc = dft_control%qs_control%gapw_xc
316 IF (gapw_xc .AND. gapw) THEN
317 cpabort(" GAPW and GAPW_XC are not compatible")
318 END IF
319 IF ((gapw .AND. lrigpw) .OR. (gapw_xc .AND. lrigpw)) THEN
320 cpabort(" GAPW/GAPW_XC and LRIGPW are not compatible")
321 END IF
322 IF ((gapw .AND. rigpw) .OR. (gapw_xc .AND. rigpw)) THEN
323 cpabort(" GAPW/GAPW_XC and RIGPW are not compatible")
324 END IF
325
326 do_ppl = dft_control%qs_control%do_ppl_method == do_ppl_grid
327 IF (do_ppl) THEN
328 cpassert(.NOT. gapw)
329 CALL get_qs_env(qs_env=qs_env, vppl=vppl_rspace)
330 END IF
331
332 IF (gapw_xc) THEN
333 cpassert(ASSOCIATED(rho_xc))
334 END IF
335
336 ! gets the tmp grids
337 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool, poisson_env=poisson_env)
338
339 IF (gapw .AND. (poisson_env%parameters%solver .EQ. pw_poisson_implicit)) THEN
340 cpabort("The implicit Poisson solver cannot be used in conjunction with GAPW.")
341 END IF
342
343 ! *** Prepare densities for gapw ***
344 IF (gapw .OR. gapw_xc) THEN
345 CALL prepare_gapw_den(qs_env, do_rho0=(.NOT. gapw_xc))
346 END IF
347
348 ! Calculate the Hartree potential
349 CALL auxbas_pw_pool%create_pw(v_hartree_gspace)
350 CALL auxbas_pw_pool%create_pw(rho_tot_gspace)
351
352 scf_section => section_vals_get_subs_vals(input, "DFT%SCF")
353 IF (btest(cp_print_key_should_output(logger%iter_info, scf_section, &
354 "PRINT%DETAILED_ENERGY"), &
355 cp_p_file) .AND. &
356 (.NOT. gapw) .AND. (.NOT. gapw_xc) .AND. &
357 (.NOT. (poisson_env%parameters%solver .EQ. pw_poisson_implicit))) THEN
358 CALL pw_zero(rho_tot_gspace)
359 CALL calc_rho_tot_gspace(rho_tot_gspace, qs_env, rho, skip_nuclear_density=.true.)
360 CALL pw_poisson_solve(poisson_env, rho_tot_gspace, energy%e_hartree, &
361 v_hartree_gspace)
362 CALL pw_zero(rho_tot_gspace)
363 CALL pw_zero(v_hartree_gspace)
364 END IF
365
366 ! Get the total density in g-space [ions + electrons]
367 CALL calc_rho_tot_gspace(rho_tot_gspace, qs_env, rho)
368
369 IF (my_print) THEN
370 CALL print_densities(qs_env, rho)
371 END IF
372
373 IF (dft_control%do_sccs) THEN
374 ! Self-consistent continuum solvation (SCCS) model
375 NULLIFY (v_sccs_rspace)
376 ALLOCATE (v_sccs_rspace)
377 CALL auxbas_pw_pool%create_pw(v_sccs_rspace)
378
379 IF (poisson_env%parameters%solver .EQ. pw_poisson_implicit) THEN
380 cpabort("The implicit Poisson solver cannot be used together with SCCS.")
381 END IF
382
383 IF (use_virial .AND. calculate_forces) THEN
384 CALL sccs(qs_env, rho_tot_gspace, v_hartree_gspace, v_sccs_rspace, &
385 h_stress=h_stress)
386 virial%pv_ehartree = virial%pv_ehartree + h_stress/real(para_env%num_pe, dp)
387 virial%pv_virial = virial%pv_virial + h_stress/real(para_env%num_pe, dp)
388 ELSE
389 CALL sccs(qs_env, rho_tot_gspace, v_hartree_gspace, v_sccs_rspace)
390 END IF
391 ELSE
392 ! Getting the Hartree energy and Hartree potential. Also getting the stress tensor
393 ! from the Hartree term if needed. No nuclear force information here
394 IF (use_virial .AND. calculate_forces) THEN
395 h_stress(:, :) = 0.0_dp
396 CALL pw_poisson_solve(poisson_env, rho_tot_gspace, energy%hartree, &
397 v_hartree_gspace, h_stress=h_stress, &
398 rho_core=rho_core)
399 virial%pv_ehartree = virial%pv_ehartree + h_stress/real(para_env%num_pe, dp)
400 virial%pv_virial = virial%pv_virial + h_stress/real(para_env%num_pe, dp)
401 ELSE
402 CALL pw_poisson_solve(poisson_env, rho_tot_gspace, energy%hartree, &
403 v_hartree_gspace, rho_core=rho_core)
404 END IF
405 END IF
406
407 ! In case decouple periodic images and/or apply restraints to charges
408 IF (do_ddapc) THEN
409 CALL qs_ks_ddapc(qs_env, auxbas_pw_pool, rho_tot_gspace, v_hartree_gspace, &
410 v_spin_ddapc_rest_r, energy, calculate_forces, ks_matrix, &
411 just_energy)
412 ELSE
413 dft_control%qs_control%ddapc_explicit_potential = .false.
414 dft_control%qs_control%ddapc_restraint_is_spin = .false.
415 IF (.NOT. just_energy) THEN
416 CALL pw_transfer(v_hartree_gspace, v_hartree_rspace)
417 CALL pw_scale(v_hartree_rspace, v_hartree_rspace%pw_grid%dvol)
418 END IF
419 END IF
420 CALL auxbas_pw_pool%give_back_pw(v_hartree_gspace)
421
422 IF (dft_control%correct_surf_dip) THEN
423 IF (dft_control%surf_dip_correct_switch) THEN
424 CALL calc_dipsurf_potential(qs_env, energy)
425 energy%hartree = energy%hartree + energy%surf_dipole
426 END IF
427 END IF
428
429 ! SIC
430 CALL calc_v_sic_rspace(v_sic_rspace, energy, qs_env, dft_control, rho, poisson_env, &
431 just_energy, calculate_forces, auxbas_pw_pool)
432
433 ! Check if CDFT constraint is needed
434 CALL qs_ks_cdft_constraint(qs_env, auxbas_pw_pool, calculate_forces, cdft_control)
435
436 ! Adds the External Potential if requested
437 IF (dft_control%apply_external_potential) THEN
438 ! Compute the energy due to the external potential
439 ee_ener = 0.0_dp
440 DO ispin = 1, nspins
441 ee_ener = ee_ener + pw_integral_ab(rho_r(ispin), vee)
442 END DO
443 IF (.NOT. just_energy) THEN
444 IF (gapw) THEN
445 CALL get_qs_env(qs_env=qs_env, &
446 rho0_s_rs=rho0_s_rs, &
447 rhoz_cneo_s_rs=rhoz_cneo_s_rs)
448 cpassert(ASSOCIATED(rho0_s_rs))
449 IF (ASSOCIATED(rhoz_cneo_s_rs)) THEN
450 CALL pw_axpy(rhoz_cneo_s_rs, rho0_s_rs)
451 END IF
452 ee_ener = ee_ener + pw_integral_ab(rho0_s_rs, vee)
453 IF (ASSOCIATED(rhoz_cneo_s_rs)) THEN
454 CALL pw_axpy(rhoz_cneo_s_rs, rho0_s_rs, -1.0_dp)
455 END IF
456 END IF
457 END IF
458 ! the sign accounts for the charge of the electrons
459 energy%ee = -ee_ener
460 END IF
461
462 ! Adds the QM/MM potential
463 IF (qs_env%qmmm) THEN
464 CALL qmmm_calculate_energy(qs_env=qs_env, &
465 rho=rho_r, &
466 v_qmmm=qs_env%ks_qmmm_env%v_qmmm_rspace, &
467 qmmm_energy=energy%qmmm_el)
468 IF (qs_env%qmmm_env_qm%image_charge) THEN
469 CALL calculate_image_pot(v_hartree_rspace=v_hartree_rspace, &
470 rho_hartree_gspace=rho_tot_gspace, &
471 energy=energy, &
472 qmmm_env=qs_env%qmmm_env_qm, &
473 qs_env=qs_env)
474 IF (.NOT. just_energy) THEN
475 CALL add_image_pot_to_hartree_pot(v_hartree=v_hartree_rspace, &
476 v_metal=qs_env%ks_qmmm_env%v_metal_rspace, &
477 qs_env=qs_env)
478 IF (calculate_forces) THEN
480 potential=v_hartree_rspace, coeff=qs_env%image_coeff, &
481 forces=qs_env%qmmm_env_qm%image_charge_pot%image_forcesMM, &
482 qmmm_env=qs_env%qmmm_env_qm, qs_env=qs_env)
483 END IF
484 END IF
485 CALL qs_env%ks_qmmm_env%v_metal_rspace%release()
486 DEALLOCATE (qs_env%ks_qmmm_env%v_metal_rspace)
487 END IF
488 IF (.NOT. just_energy) THEN
489 CALL qmmm_modify_hartree_pot(v_hartree=v_hartree_rspace, &
490 v_qmmm=qs_env%ks_qmmm_env%v_qmmm_rspace, scale=1.0_dp)
491 END IF
492 END IF
493 CALL auxbas_pw_pool%give_back_pw(rho_tot_gspace)
494
495 ! SMEAGOL interface
496 IF (dft_control%smeagol_control%smeagol_enabled .AND. &
497 dft_control%smeagol_control%run_type == smeagol_runtype_emtransport) THEN
498 cpassert(ASSOCIATED(dft_control%smeagol_control%aux))
499 CALL smeagol_shift_v_hartree(v_hartree_rspace, cell, &
500 dft_control%smeagol_control%aux%HartreeLeadsLeft, &
501 dft_control%smeagol_control%aux%HartreeLeadsRight, &
502 dft_control%smeagol_control%aux%HartreeLeadsBottom, &
503 dft_control%smeagol_control%aux%VBias, &
504 dft_control%smeagol_control%aux%minL, &
505 dft_control%smeagol_control%aux%maxR, &
506 dft_control%smeagol_control%aux%isexplicit_maxR, &
507 dft_control%smeagol_control%aux%isexplicit_HartreeLeadsBottom)
508 END IF
509
510 ! calculate the density matrix for the fitted mo_coeffs
511 IF (dft_control%do_admm) THEN
512 CALL hfx_admm_init(qs_env, calculate_forces)
513
514 IF (dft_control%do_admm_mo) THEN
515 IF (qs_env%run_rtp) THEN
516 CALL rtp_admm_calc_rho_aux(qs_env)
517 ELSE
518 IF (dokp) THEN
519 CALL admm_mo_calc_rho_aux_kp(qs_env)
520 ELSE
521 CALL admm_mo_calc_rho_aux(qs_env)
522 END IF
523 END IF
524 ELSEIF (dft_control%do_admm_dm) THEN
525 CALL admm_dm_calc_rho_aux(qs_env)
526 END IF
527 END IF
528
529 ! only activate stress calculation if
530 IF (use_virial .AND. calculate_forces) virial%pv_calculate = .true.
531
532 ! *** calculate the xc potential on the pw density ***
533 ! *** associates v_rspace_new if the xc potential needs to be computed.
534 ! If we do wavefunction fitting, we need the vxc_potential in the auxiliary basis set
535 IF (dft_control%do_admm) THEN
536 CALL get_qs_env(qs_env, admm_env=admm_env)
537 xc_section => admm_env%xc_section_aux
538 CALL get_admm_env(admm_env, rho_aux_fit=rho_struct)
539
540 ! here we ignore a possible vdW section in admm_env%xc_section_aux
541 CALL qs_vxc_create(ks_env=ks_env, rho_struct=rho_struct, xc_section=xc_section, &
542 vxc_rho=v_rspace_new_aux_fit, vxc_tau=v_tau_rspace_aux_fit, exc=energy%exc_aux_fit, &
543 just_energy=just_energy_xc)
544
545 IF (admm_env%do_gapw) THEN
546 !compute the potential due to atomic densities
547 CALL calculate_vxc_atom(qs_env, energy_only=just_energy_xc, exc1=energy%exc1_aux_fit, &
548 kind_set_external=admm_env%admm_gapw_env%admm_kind_set, &
549 xc_section_external=xc_section, &
550 rho_atom_set_external=admm_env%admm_gapw_env%local_rho_set%rho_atom_set)
551
552 END IF
553
554 NULLIFY (rho_struct)
555
556 IF (use_virial .AND. calculate_forces) THEN
557 vscale = 1.0_dp
558 !Note: ADMMS and ADMMP stress tensor only for closed-shell calculations
559 IF (admm_env%do_admms) vscale = admm_env%gsi(1)**(2.0_dp/3.0_dp)
560 IF (admm_env%do_admmp) vscale = admm_env%gsi(1)**2
561 virial%pv_exc = virial%pv_exc - vscale*virial%pv_xc
562 virial%pv_virial = virial%pv_virial - vscale*virial%pv_xc
563 ! virial%pv_xc will be zeroed in the xc routines
564 END IF
565 xc_section => admm_env%xc_section_primary
566 ELSE
567 xc_section => section_vals_get_subs_vals(input, "DFT%XC")
568 END IF
569
570 IF (gapw_xc) THEN
571 CALL get_qs_env(qs_env=qs_env, rho_xc=rho_struct)
572 ELSE
573 CALL get_qs_env(qs_env=qs_env, rho=rho_struct)
574 END IF
575
576 ! zmp
577 IF (dft_control%apply_external_density .OR. dft_control%apply_external_vxc) THEN
578 energy%exc = 0.0_dp
579 CALL calculate_zmp_potential(qs_env, v_rspace_new, rho, exc=energy%exc)
580 ELSE
581 ! Embedding potential
582 IF (dft_control%apply_embed_pot) THEN
583 NULLIFY (v_rspace_embed)
584 energy%embed_corr = 0.0_dp
585 CALL get_embed_potential_energy(qs_env, rho, v_rspace_embed, dft_control, &
586 energy%embed_corr, just_energy)
587 END IF
588 ! Everything else
589 CALL qs_vxc_create(ks_env=ks_env, rho_struct=rho_struct, xc_section=xc_section, &
590 vxc_rho=v_rspace_new, vxc_tau=v_tau_rspace, exc=energy%exc, &
591 edisp=edisp, dispersion_env=qs_env%dispersion_env, &
592 just_energy=just_energy_xc)
593 IF (edisp /= 0.0_dp) energy%dispersion = edisp
594 IF (qs_env%requires_matrix_vxc .AND. ASSOCIATED(v_rspace_new)) THEN
595 CALL compute_matrix_vxc(qs_env=qs_env, v_rspace=v_rspace_new, matrix_vxc=matrix_vxc)
596 CALL set_ks_env(ks_env, matrix_vxc=matrix_vxc)
597 END IF
598
599 IF (gapw .OR. gapw_xc) THEN
600 CALL calculate_vxc_atom(qs_env, just_energy_xc, energy%exc1, xc_section_external=xc_section)
601 ! test for not implemented (bug) option
602 IF (use_virial .AND. calculate_forces) THEN
603 IF (ASSOCIATED(v_tau_rspace)) THEN
604 cpabort("MGGA STRESS with GAPW/GAPW_XC not implemneted")
605 END IF
606 END IF
607 END IF
608
609 END IF
610
611 ! set hartree and xc potentials for use in Harris method
612 IF (qs_env%harris_method) THEN
613 CALL get_qs_env(qs_env, harris_env=harris_env)
614 CALL harris_set_potentials(harris_env, v_hartree_rspace, v_rspace_new)
615 END IF
616
617 NULLIFY (rho_struct)
618 IF (use_virial .AND. calculate_forces) THEN
619 virial%pv_exc = virial%pv_exc - virial%pv_xc
620 virial%pv_virial = virial%pv_virial - virial%pv_xc
621 END IF
622
623 ! *** Add Hartree-Fock contribution if required ***
624 IF (do_hfx) THEN
625 IF (dokp) THEN
626 CALL hfx_ks_matrix_kp(qs_env, ks_matrix, energy, calculate_forces)
627 ELSE
628 CALL hfx_ks_matrix(qs_env, ks_matrix, rho, energy, calculate_forces, &
629 just_energy, v_rspace_new, v_tau_rspace)
630 END IF
631!! Adiabatic rescaling only if do_hfx; right?????
632 END IF !do_hfx
633
634 IF (do_ppl .AND. calculate_forces) THEN
635 cpassert(.NOT. gapw)
636 DO ispin = 1, nspins
637 CALL integrate_ppl_rspace(rho_r(ispin), qs_env)
638 END DO
639 END IF
640
641 IF (ASSOCIATED(rho_nlcc) .AND. calculate_forces) THEN
642 DO ispin = 1, nspins
643 CALL integrate_rho_nlcc(v_rspace_new(ispin), qs_env)
644 IF (dft_control%do_admm) CALL integrate_rho_nlcc(v_rspace_new_aux_fit(ispin), qs_env)
645 END DO
646 END IF
647
648 ! calculate KG correction
649 IF (dft_control%qs_control%do_kg .AND. just_energy) THEN
650
651 cpassert(.NOT. (gapw .OR. gapw_xc))
652 cpassert(nimages == 1)
653 ksmat => ks_matrix(:, 1)
654 CALL kg_ekin_subset(qs_env, ksmat, ekin_mol, calculate_forces, do_kernel=.false.)
655
656 ! subtract kg corr from the total energy
657 energy%exc = energy%exc - ekin_mol
658
659 END IF
660
661 ! *** Single atom contributions ***
662 IF (.NOT. just_energy) THEN
663 IF (calculate_forces) THEN
664 ! Getting nuclear force contribution from the core charge density
665 IF ((poisson_env%parameters%solver .EQ. pw_poisson_implicit) .AND. &
666 (poisson_env%parameters%dielectric_params%dielec_core_correction)) THEN
667 block
668 TYPE(pw_r3d_rs_type) :: v_minus_veps
669 CALL auxbas_pw_pool%create_pw(v_minus_veps)
670 CALL pw_copy(v_hartree_rspace, v_minus_veps)
671 CALL pw_axpy(poisson_env%implicit_env%v_eps, v_minus_veps, -v_hartree_rspace%pw_grid%dvol)
672 CALL integrate_v_core_rspace(v_minus_veps, qs_env)
673 CALL auxbas_pw_pool%give_back_pw(v_minus_veps)
674 END block
675 ELSE
676 CALL integrate_v_core_rspace(v_hartree_rspace, qs_env)
677 END IF
678 END IF
679
680 IF (.NOT. do_hfx) THEN
681 ! Initialize the Kohn-Sham matrix with the core Hamiltonian matrix
682 ! (sets ks sparsity equal to matrix_h sparsity)
683 DO ispin = 1, nspins
684 DO img = 1, nimages
685 CALL dbcsr_get_info(ks_matrix(ispin, img)%matrix, name=name) ! keep the name
686 CALL dbcsr_copy(ks_matrix(ispin, img)%matrix, matrix_h(1, img)%matrix, name=name)
687 END DO
688 END DO
689 ! imaginary part if required
690 IF (qs_env%run_rtp) THEN
691 IF (dft_control%rtp_control%velocity_gauge) THEN
692 cpassert(ASSOCIATED(matrix_h_im))
693 cpassert(ASSOCIATED(ks_matrix_im))
694 DO ispin = 1, nspins
695 DO img = 1, nimages
696 CALL dbcsr_get_info(ks_matrix_im(ispin, img)%matrix, name=name) ! keep the name
697 CALL dbcsr_copy(ks_matrix_im(ispin, img)%matrix, matrix_h_im(1, img)%matrix, name=name)
698 END DO
699 END DO
700 END IF
701 END IF
702 END IF
703
704 IF (use_virial .AND. calculate_forces) THEN
705 pv_loc = virial%pv_virial
706 END IF
707 ! sum up potentials and integrate
708 ! Pointing my_rho to the density matrix rho_ao
709 my_rho => rho_ao
710
711 CALL sum_up_and_integrate(qs_env, ks_matrix, rho, my_rho, vppl_rspace, &
712 v_rspace_new, v_rspace_new_aux_fit, v_tau_rspace, v_tau_rspace_aux_fit, &
713 v_sic_rspace, v_spin_ddapc_rest_r, v_sccs_rspace, v_rspace_embed, &
714 cdft_control, calculate_forces)
715
716 IF (use_virial .AND. calculate_forces) THEN
717 virial%pv_ehartree = virial%pv_ehartree + (virial%pv_virial - pv_loc)
718 END IF
719 IF (dft_control%qs_control%do_kg) THEN
720 cpassert(.NOT. (gapw .OR. gapw_xc))
721 cpassert(nimages == 1)
722 ksmat => ks_matrix(:, 1)
723
724 IF (use_virial .AND. calculate_forces) THEN
725 pv_loc = virial%pv_virial
726 END IF
727
728 CALL kg_ekin_subset(qs_env, ksmat, ekin_mol, calculate_forces, do_kernel=.false.)
729 ! subtract kg corr from the total energy
730 energy%exc = energy%exc - ekin_mol
731
732 ! virial corrections
733 IF (use_virial .AND. calculate_forces) THEN
734
735 ! Integral contribution
736 virial%pv_ehartree = virial%pv_ehartree + (virial%pv_virial - pv_loc)
737
738 ! GGA contribution
739 virial%pv_exc = virial%pv_exc + virial%pv_xc
740 virial%pv_virial = virial%pv_virial + virial%pv_xc
741 virial%pv_xc = 0.0_dp
742 END IF
743 END IF
744
745 ELSE
746 IF (do_hfx) THEN
747 IF (.false.) THEN
748 cpwarn("KS matrix not longer correct. Check possible problems with property calculations!")
749 END IF
750 END IF
751 END IF ! .NOT. just energy
752
753 IF (dft_control%qs_control%ddapc_explicit_potential) THEN
754 CALL auxbas_pw_pool%give_back_pw(v_spin_ddapc_rest_r)
755 DEALLOCATE (v_spin_ddapc_rest_r)
756 END IF
757
758 IF (calculate_forces .AND. dft_control%qs_control%cdft) THEN
759 IF (.NOT. cdft_control%transfer_pot) THEN
760 DO iatom = 1, SIZE(cdft_control%group)
761 CALL auxbas_pw_pool%give_back_pw(cdft_control%group(iatom)%weight)
762 DEALLOCATE (cdft_control%group(iatom)%weight)
763 END DO
764 IF (cdft_control%atomic_charges) THEN
765 DO iatom = 1, cdft_control%natoms
766 CALL auxbas_pw_pool%give_back_pw(cdft_control%charge(iatom))
767 END DO
768 DEALLOCATE (cdft_control%charge)
769 END IF
770 IF (cdft_control%type == outer_scf_becke_constraint .AND. &
771 cdft_control%becke_control%cavity_confine) THEN
772 IF (.NOT. ASSOCIATED(cdft_control%becke_control%cavity_mat)) THEN
773 CALL auxbas_pw_pool%give_back_pw(cdft_control%becke_control%cavity)
774 ELSE
775 DEALLOCATE (cdft_control%becke_control%cavity_mat)
776 END IF
777 ELSE IF (cdft_control%type == outer_scf_hirshfeld_constraint) THEN
778 IF (ASSOCIATED(cdft_control%hirshfeld_control%hirshfeld_env%fnorm)) THEN
779 CALL auxbas_pw_pool%give_back_pw(cdft_control%hirshfeld_control%hirshfeld_env%fnorm)
780 END IF
781 END IF
782 IF (ASSOCIATED(cdft_control%charges_fragment)) DEALLOCATE (cdft_control%charges_fragment)
783 cdft_control%save_pot = .false.
784 cdft_control%need_pot = .true.
785 cdft_control%external_control = .false.
786 END IF
787 END IF
788
789 IF (dft_control%do_sccs) THEN
790 CALL auxbas_pw_pool%give_back_pw(v_sccs_rspace)
791 DEALLOCATE (v_sccs_rspace)
792 END IF
793
794 IF (gapw) THEN
795 IF (dft_control%apply_external_potential) THEN
796 ! Integrals of the Hartree potential with g0_soft
797 CALL qmmm_modify_hartree_pot(v_hartree=v_hartree_rspace, &
798 v_qmmm=vee, scale=-1.0_dp)
799 END IF
800 CALL integrate_vhg0_rspace(qs_env, v_hartree_rspace, para_env, calculate_forces)
801 ! Place Vh_1c_gg_integrals after integrate_vhg0_rspace for CNEO calculations
802 ! because vhg0 integral is needed to build the complete nuclear equation
803 CALL get_qs_env(qs_env, ecoul_1c=ecoul_1c, local_rho_set=local_rho_set)
804 CALL vh_1c_gg_integrals(qs_env, energy%hartree_1c, ecoul_1c, local_rho_set, para_env, tddft=.false., &
805 core_2nd=.false.)
806 ! CNEO quantum nuclear core energy (kinetic + Z*erfc(r)/r potential from classical nuclei)
807 energy%core_cneo = 0.0_dp
808 IF (ASSOCIATED(local_rho_set%rhoz_cneo_set)) THEN
809 DO iatom = 1, SIZE(local_rho_set%rhoz_cneo_set)
810 energy%core_cneo = energy%core_cneo + local_rho_set%rhoz_cneo_set(iatom)%e_core
811 END DO
812 END IF
813 END IF
814
815 IF (gapw .OR. gapw_xc) THEN
816 ! Single atom contributions in the KS matrix ***
817 CALL update_ks_atom(qs_env, ks_matrix, rho_ao, calculate_forces)
818 IF (dft_control%do_admm) THEN
819 !Single atom contribution to the AUX matrices
820 !Note: also update ks_aux_fit matrix in case of rtp
821 CALL admm_update_ks_atom(qs_env, calculate_forces)
822 END IF
823 END IF
824
825 !Calculation of Mulliken restraint, if requested
826 CALL qs_ks_mulliken_restraint(energy, dft_control, just_energy, para_env, &
827 ks_matrix, matrix_s, rho, mulliken_order_p)
828
829 ! Add DFT+U contribution, if requested
830 IF (dft_control%dft_plus_u) THEN
831 cpassert(nimages == 1)
832 IF (just_energy) THEN
833 CALL plus_u(qs_env=qs_env)
834 ELSE
835 ksmat => ks_matrix(:, 1)
836 CALL plus_u(qs_env=qs_env, matrix_h=ksmat)
837 END IF
838 ELSE
839 energy%dft_plus_u = 0.0_dp
840 END IF
841
842 ! At this point the ks matrix should be up to date, filter it if requested
843 DO ispin = 1, nspins
844 DO img = 1, nimages
845 CALL dbcsr_filter(ks_matrix(ispin, img)%matrix, &
846 dft_control%qs_control%eps_filter_matrix)
847 END DO
848 END DO
849
850 !** merge the auxiliary KS matrix and the primary one
851 IF (dft_control%do_admm_mo) THEN
852 IF (qs_env%run_rtp) THEN
853 CALL rtp_admm_merge_ks_matrix(qs_env)
854 ELSE
855 CALL admm_mo_merge_ks_matrix(qs_env)
856 END IF
857 ELSEIF (dft_control%do_admm_dm) THEN
858 CALL admm_dm_merge_ks_matrix(qs_env)
859 END IF
860
861 ! External field (nonperiodic case)
862 CALL qs_efield_local_operator(qs_env, just_energy, calculate_forces)
863
864 ! Right now we can compute the orbital derivative here, as it depends currently only on the available
865 ! Kohn-Sham matrix. This might change in the future, in which case more pieces might need to be assembled
866 ! from this routine, notice that this part of the calculation in not linear scaling
867 ! right now this operation is only non-trivial because of occupation numbers and the restricted keyword
868 IF (qs_env%requires_mo_derivs .AND. .NOT. just_energy .AND. .NOT. qs_env%run_rtp) THEN
869 CALL get_qs_env(qs_env, mo_derivs=mo_derivs)
870 cpassert(nimages == 1)
871 ksmat => ks_matrix(:, 1)
872 CALL calc_mo_derivatives(qs_env, ksmat, mo_derivs)
873 END IF
874
875 ! ADMM overlap forces
876 IF (calculate_forces .AND. dft_control%do_admm) THEN
877 IF (dokp) THEN
878 CALL calc_admm_ovlp_forces_kp(qs_env)
879 ELSE
880 CALL calc_admm_ovlp_forces(qs_env)
881 END IF
882 END IF
883
884 ! deal with low spin roks
885 CALL low_spin_roks(energy, qs_env, dft_control, do_hfx, just_energy, &
886 calculate_forces, auxbas_pw_pool)
887
888 ! deal with sic on explicit orbitals
889 CALL sic_explicit_orbitals(energy, qs_env, dft_control, poisson_env, just_energy, &
890 calculate_forces, auxbas_pw_pool)
891
892 ! Periodic external field
893 CALL qs_efield_berry_phase(qs_env, just_energy, calculate_forces)
894
895 ! adds s2_restraint energy and orbital derivatives
896 CALL qs_ks_s2_restraint(dft_control, qs_env, matrix_s, &
897 energy, calculate_forces, just_energy)
898
899 IF (do_ppl) THEN
900 ! update core energy for grid based local pseudopotential
901 ecore_ppl = 0._dp
902 DO ispin = 1, nspins
903 ecore_ppl = ecore_ppl + pw_integral_ab(vppl_rspace, rho_r(ispin))
904 END DO
905 energy%core = energy%core + ecore_ppl
906 END IF
907
908 IF (lrigpw) THEN
909 ! update core energy for ppl_ri method
910 CALL get_qs_env(qs_env, lri_env=lri_env, lri_density=lri_density)
911 IF (lri_env%ppl_ri) THEN
912 ecore_ppl = 0._dp
913 DO ispin = 1, nspins
914 lri_v_int => lri_density%lri_coefs(ispin)%lri_kinds
915 CALL v_int_ppl_energy(qs_env, lri_v_int, ecore_ppl)
916 END DO
917 energy%core = energy%core + ecore_ppl
918 END IF
919 END IF
920
921 ! Sum all energy terms to obtain the total energy
922 energy%total = energy%core_overlap + energy%core_self + energy%core_cneo + energy%core + &
923 energy%hartree + energy%hartree_1c + energy%exc + energy%exc1 + energy%ex + &
924 energy%dispersion + energy%gcp + energy%qmmm_el + energy%mulliken + &
925 sum(energy%ddapc_restraint) + energy%s2_restraint + &
926 energy%dft_plus_u + energy%kTS + &
927 energy%efield + energy%efield_core + energy%ee + &
928 energy%ee_core + energy%exc_aux_fit + energy%image_charge + &
929 energy%sccs_pol + energy%cdft + energy%exc1_aux_fit
930
931 IF (dft_control%apply_embed_pot) energy%total = energy%total + energy%embed_corr
932
933 IF (abnormal_value(energy%total)) &
934 cpabort("KS energy is an abnormal value (NaN/Inf).")
935
936 ! Print detailed energy
937 IF (my_print) THEN
938 CALL print_detailed_energy(qs_env, dft_control, input, energy, mulliken_order_p)
939 END IF
940
941 CALL timestop(handle)
942
943 END SUBROUTINE qs_ks_build_kohn_sham_matrix
944
945! **************************************************************************************************
946!> \brief ...
947!> \param rho_tot_gspace ...
948!> \param qs_env ...
949!> \param rho ...
950!> \param skip_nuclear_density ...
951! **************************************************************************************************
952 SUBROUTINE calc_rho_tot_gspace(rho_tot_gspace, qs_env, rho, skip_nuclear_density)
953 TYPE(pw_c1d_gs_type), INTENT(INOUT) :: rho_tot_gspace
954 TYPE(qs_environment_type), POINTER :: qs_env
955 TYPE(qs_rho_type), POINTER :: rho
956 LOGICAL, INTENT(IN), OPTIONAL :: skip_nuclear_density
957
958 INTEGER :: ispin
959 LOGICAL :: my_skip
960 TYPE(dft_control_type), POINTER :: dft_control
961 TYPE(pw_c1d_gs_type), DIMENSION(:), POINTER :: rho_g
962 TYPE(pw_c1d_gs_type), POINTER :: rho0_s_gs, rho_core, rhoz_cneo_s_gs
963 TYPE(qs_charges_type), POINTER :: qs_charges
964
965 my_skip = .false.
966 IF (PRESENT(skip_nuclear_density)) my_skip = skip_nuclear_density
967
968 CALL qs_rho_get(rho, rho_g=rho_g)
969 CALL get_qs_env(qs_env=qs_env, dft_control=dft_control)
970
971 IF (.NOT. my_skip) THEN
972 NULLIFY (rho_core)
973 CALL get_qs_env(qs_env=qs_env, rho_core=rho_core)
974 IF (dft_control%qs_control%gapw) THEN
975 NULLIFY (rho0_s_gs, rhoz_cneo_s_gs)
976 CALL get_qs_env(qs_env=qs_env, rho0_s_gs=rho0_s_gs, rhoz_cneo_s_gs=rhoz_cneo_s_gs)
977 cpassert(ASSOCIATED(rho0_s_gs))
978 CALL pw_copy(rho0_s_gs, rho_tot_gspace)
979 IF (ASSOCIATED(rhoz_cneo_s_gs)) THEN
980 CALL pw_axpy(rhoz_cneo_s_gs, rho_tot_gspace)
981 END IF
982 IF (dft_control%qs_control%gapw_control%nopaw_as_gpw) THEN
983 CALL pw_axpy(rho_core, rho_tot_gspace)
984 END IF
985 ELSE
986 CALL pw_copy(rho_core, rho_tot_gspace)
987 END IF
988 DO ispin = 1, dft_control%nspins
989 CALL pw_axpy(rho_g(ispin), rho_tot_gspace)
990 END DO
991 CALL get_qs_env(qs_env=qs_env, qs_charges=qs_charges)
992 qs_charges%total_rho_gspace = pw_integrate_function(rho_tot_gspace, isign=-1)
993 ELSE
994 DO ispin = 1, dft_control%nspins
995 CALL pw_axpy(rho_g(ispin), rho_tot_gspace)
996 END DO
997 END IF
998
999 END SUBROUTINE calc_rho_tot_gspace
1000
1001! **************************************************************************************************
1002!> \brief compute MO derivatives
1003!> \param qs_env the qs_env to update
1004!> \param ks_matrix ...
1005!> \param mo_derivs ...
1006!> \par History
1007!> 01.2014 created, transferred from qs_ks_build_kohn_sham_matrix in
1008!> separate subroutine
1009!> \author Dorothea Golze
1010! **************************************************************************************************
1011 SUBROUTINE calc_mo_derivatives(qs_env, ks_matrix, mo_derivs)
1012 TYPE(qs_environment_type), POINTER :: qs_env
1013 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: ks_matrix, mo_derivs
1014
1015 INTEGER :: ispin
1016 LOGICAL :: uniform_occupation
1017 REAL(kind=dp), DIMENSION(:), POINTER :: occupation_numbers
1018 TYPE(cp_fm_type), POINTER :: mo_coeff
1019 TYPE(dbcsr_type) :: mo_derivs2_tmp1, mo_derivs2_tmp2
1020 TYPE(dbcsr_type), POINTER :: mo_coeff_b
1021 TYPE(dft_control_type), POINTER :: dft_control
1022 TYPE(mo_set_type), DIMENSION(:), POINTER :: mo_array
1023
1024 NULLIFY (dft_control, mo_array, mo_coeff, mo_coeff_b, occupation_numbers)
1025
1026 CALL get_qs_env(qs_env, &
1027 dft_control=dft_control, &
1028 mos=mo_array)
1029
1030 DO ispin = 1, SIZE(mo_derivs)
1031
1032 CALL get_mo_set(mo_set=mo_array(ispin), mo_coeff=mo_coeff, &
1033 mo_coeff_b=mo_coeff_b, occupation_numbers=occupation_numbers)
1034 CALL dbcsr_multiply('n', 'n', 1.0_dp, ks_matrix(ispin)%matrix, mo_coeff_b, &
1035 0.0_dp, mo_derivs(ispin)%matrix)
1036
1037 IF (dft_control%restricted) THEN
1038 ! only the first mo_set are actual variables, but we still need both
1039 cpassert(ispin == 1)
1040 cpassert(SIZE(mo_array) == 2)
1041 ! use a temporary array with the same size as the first spin for the second spin
1042
1043 ! uniform_occupation is needed for this case, otherwise we can no
1044 ! reconstruct things in ot, since we irreversibly sum
1045 CALL get_mo_set(mo_set=mo_array(1), uniform_occupation=uniform_occupation)
1046 cpassert(uniform_occupation)
1047 CALL get_mo_set(mo_set=mo_array(2), uniform_occupation=uniform_occupation)
1048 cpassert(uniform_occupation)
1049
1050 ! The beta-spin might have fewer orbitals than alpa-spin...
1051 ! create tempoary matrices with beta_nmo columns
1052 CALL get_mo_set(mo_set=mo_array(2), mo_coeff_b=mo_coeff_b)
1053 CALL dbcsr_create(mo_derivs2_tmp1, template=mo_coeff_b)
1054
1055 ! calculate beta derivatives
1056 CALL dbcsr_multiply('n', 'n', 1.0_dp, ks_matrix(2)%matrix, mo_coeff_b, 0.0_dp, mo_derivs2_tmp1)
1057
1058 ! create larger matrix with alpha_nmo columns
1059 CALL dbcsr_create(mo_derivs2_tmp2, template=mo_derivs(1)%matrix)
1060 CALL dbcsr_set(mo_derivs2_tmp2, 0.0_dp)
1061
1062 ! copy into larger matrix, fills the first beta_nmo columns
1063 CALL dbcsr_copy_columns_hack(mo_derivs2_tmp2, mo_derivs2_tmp1, &
1064 mo_array(2)%nmo, 1, 1, &
1065 para_env=mo_array(1)%mo_coeff%matrix_struct%para_env, &
1066 blacs_env=mo_array(1)%mo_coeff%matrix_struct%context)
1067
1068 ! add beta contribution to alpa mo_derivs
1069 CALL dbcsr_add(mo_derivs(1)%matrix, mo_derivs2_tmp2, 1.0_dp, 1.0_dp)
1070 CALL dbcsr_release(mo_derivs2_tmp1)
1071 CALL dbcsr_release(mo_derivs2_tmp2)
1072 END IF
1073 END DO
1074
1075 IF (dft_control%do_admm_mo) THEN
1076 CALL calc_admm_mo_derivatives(qs_env, mo_derivs)
1077 END IF
1078
1079 END SUBROUTINE calc_mo_derivatives
1080
1081! **************************************************************************************************
1082!> \brief updates the Kohn Sham matrix of the given qs_env (facility method)
1083!> \param qs_env the qs_env to update
1084!> \param calculate_forces if true calculate the quantities needed
1085!> to calculate the forces. Defaults to false.
1086!> \param just_energy if true updates the energies but not the
1087!> ks matrix. Defaults to false
1088!> \param print_active ...
1089!> \par History
1090!> 4.2002 created [fawzi]
1091!> 8.2014 kpoints [JGH]
1092!> 10.2014 refractored [Ole Schuett]
1093!> \author Fawzi Mohamed
1094! **************************************************************************************************
1095 SUBROUTINE qs_ks_update_qs_env(qs_env, calculate_forces, just_energy, &
1096 print_active)
1097 TYPE(qs_environment_type), POINTER :: qs_env
1098 LOGICAL, INTENT(IN), OPTIONAL :: calculate_forces, just_energy, &
1099 print_active
1100
1101 CHARACTER(LEN=*), PARAMETER :: routinen = 'qs_ks_update_qs_env'
1102
1103 INTEGER :: handle, unit_nr
1104 LOGICAL :: c_forces, do_rebuild, energy_only, &
1105 forces_up_to_date, potential_changed, &
1106 rho_changed, s_mstruct_changed
1107 TYPE(qs_ks_env_type), POINTER :: ks_env
1108
1109 NULLIFY (ks_env)
1110 unit_nr = cp_logger_get_default_io_unit()
1111
1112 c_forces = .false.
1113 energy_only = .false.
1114 IF (PRESENT(just_energy)) energy_only = just_energy
1115 IF (PRESENT(calculate_forces)) c_forces = calculate_forces
1116
1117 IF (c_forces) THEN
1118 CALL timeset(routinen//'_forces', handle)
1119 ELSE
1120 CALL timeset(routinen, handle)
1121 END IF
1122
1123 cpassert(ASSOCIATED(qs_env))
1124
1125 CALL get_qs_env(qs_env, &
1126 ks_env=ks_env, &
1127 rho_changed=rho_changed, &
1128 s_mstruct_changed=s_mstruct_changed, &
1129 potential_changed=potential_changed, &
1130 forces_up_to_date=forces_up_to_date)
1131
1132 do_rebuild = .false.
1133 do_rebuild = do_rebuild .OR. rho_changed
1134 do_rebuild = do_rebuild .OR. s_mstruct_changed
1135 do_rebuild = do_rebuild .OR. potential_changed
1136 do_rebuild = do_rebuild .OR. (c_forces .AND. .NOT. forces_up_to_date)
1137
1138 IF (do_rebuild) THEN
1139 CALL evaluate_core_matrix_traces(qs_env)
1140
1141 ! the ks matrix will be rebuilt so this is fine now
1142 CALL set_ks_env(ks_env, potential_changed=.false.)
1143
1144 CALL rebuild_ks_matrix(qs_env, &
1145 calculate_forces=c_forces, &
1146 just_energy=energy_only, &
1147 print_active=print_active)
1148
1149 IF (.NOT. energy_only) THEN
1150 CALL set_ks_env(ks_env, &
1151 rho_changed=.false., &
1152 s_mstruct_changed=.false., &
1153 forces_up_to_date=forces_up_to_date .OR. c_forces)
1154 END IF
1155 END IF
1156
1157 CALL timestop(handle)
1158
1159 END SUBROUTINE qs_ks_update_qs_env
1160
1161! **************************************************************************************************
1162!> \brief Calculates the traces of the core matrices and the density matrix.
1163!> \param qs_env ...
1164!> \author Ole Schuett
1165! **************************************************************************************************
1166 SUBROUTINE evaluate_core_matrix_traces(qs_env)
1167 TYPE(qs_environment_type), POINTER :: qs_env
1168
1169 CHARACTER(LEN=*), PARAMETER :: routinen = 'evaluate_core_matrix_traces'
1170
1171 INTEGER :: handle
1172 REAL(kind=dp) :: energy_core_im
1173 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrixkp_h, matrixkp_t, rho_ao_kp
1174 TYPE(dft_control_type), POINTER :: dft_control
1175 TYPE(qs_energy_type), POINTER :: energy
1176 TYPE(qs_rho_type), POINTER :: rho
1177
1178 CALL timeset(routinen, handle)
1179 NULLIFY (energy, rho, dft_control, rho_ao_kp, matrixkp_t, matrixkp_h)
1180
1181 CALL get_qs_env(qs_env, &
1182 rho=rho, &
1183 energy=energy, &
1184 dft_control=dft_control, &
1185 kinetic_kp=matrixkp_t, &
1186 matrix_h_kp=matrixkp_h)
1187
1188 CALL qs_rho_get(rho, rho_ao_kp=rho_ao_kp)
1189
1190 CALL calculate_ptrace(matrixkp_h, rho_ao_kp, energy%core, dft_control%nspins)
1191
1192 ! Add the imaginary part in the RTP case
1193 IF (qs_env%run_rtp) THEN
1194 IF (dft_control%rtp_control%velocity_gauge) THEN
1195 CALL get_qs_env(qs_env, matrix_h_im_kp=matrixkp_h)
1196 CALL qs_rho_get(rho, rho_ao_im_kp=rho_ao_kp)
1197 CALL calculate_ptrace(matrixkp_h, rho_ao_kp, energy_core_im, dft_control%nspins)
1198 energy%core = energy%core - energy_core_im
1199 END IF
1200 END IF
1201
1202 ! kinetic energy
1203 IF (ASSOCIATED(matrixkp_t)) &
1204 CALL calculate_ptrace(matrixkp_t, rho_ao_kp, energy%kinetic, dft_control%nspins)
1205
1206 CALL timestop(handle)
1207 END SUBROUTINE evaluate_core_matrix_traces
1208
1209! **************************************************************************************************
1210!> \brief Calculates the traces of the core matrices and the density matrix.
1211!> \param qs_env ...
1212!> \author Johann Pototschnig
1213! **************************************************************************************************
1215 TYPE(qs_environment_type), POINTER :: qs_env
1216
1217 CHARACTER(LEN=*), PARAMETER :: routinen = 'evaluate_core_matrix_p_mix_new'
1218
1219 INTEGER :: handle
1220 REAL(kind=dp) :: energy_core_im
1221 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrixkp_h, matrixkp_t
1222 TYPE(dft_control_type), POINTER :: dft_control
1223 TYPE(qs_energy_type), POINTER :: energy
1224 TYPE(qs_scf_env_type), POINTER :: scf_env
1225
1226 CALL timeset(routinen, handle)
1227 NULLIFY (energy, dft_control, matrixkp_t, matrixkp_h)
1228
1229 CALL get_qs_env(qs_env, &
1230 energy=energy, &
1231 dft_control=dft_control, &
1232 kinetic_kp=matrixkp_t, &
1233 matrix_h_kp=matrixkp_h, &
1234 scf_env=scf_env)
1235
1236 CALL calculate_ptrace(matrixkp_h, scf_env%p_mix_new, energy%core, dft_control%nspins)
1237
1238 ! Add the imaginary part in the RTP case
1239 IF (qs_env%run_rtp) THEN
1240 IF (dft_control%rtp_control%velocity_gauge) THEN
1241 CALL get_qs_env(qs_env, matrix_h_im_kp=matrixkp_h)
1242 CALL calculate_ptrace(matrixkp_h, scf_env%p_mix_new, energy_core_im, dft_control%nspins)
1243 energy%core = energy%core - energy_core_im
1244 END IF
1245 END IF
1246
1247 ! kinetic energy
1248 IF (ASSOCIATED(matrixkp_t)) &
1249 CALL calculate_ptrace(matrixkp_t, scf_env%p_mix_new, energy%kinetic, dft_control%nspins)
1250
1251 CALL timestop(handle)
1252 END SUBROUTINE evaluate_core_matrix_p_mix_new
1253
1254! **************************************************************************************************
1255!> \brief Constructs a new Khon-Sham matrix
1256!> \param qs_env ...
1257!> \param calculate_forces ...
1258!> \param just_energy ...
1259!> \param print_active ...
1260!> \author Ole Schuett
1261! **************************************************************************************************
1262 SUBROUTINE rebuild_ks_matrix(qs_env, calculate_forces, just_energy, print_active)
1263 TYPE(qs_environment_type), POINTER :: qs_env
1264 LOGICAL, INTENT(IN) :: calculate_forces, just_energy
1265 LOGICAL, INTENT(IN), OPTIONAL :: print_active
1266
1267 CHARACTER(LEN=*), PARAMETER :: routinen = 'rebuild_ks_matrix'
1268
1269 INTEGER :: handle
1270 TYPE(dft_control_type), POINTER :: dft_control
1271
1272 CALL timeset(routinen, handle)
1273 NULLIFY (dft_control)
1274
1275 CALL get_qs_env(qs_env, dft_control=dft_control)
1276
1277 IF (dft_control%qs_control%semi_empirical) THEN
1278 CALL build_se_fock_matrix(qs_env, &
1279 calculate_forces=calculate_forces, &
1280 just_energy=just_energy)
1281
1282 ELSEIF (dft_control%qs_control%dftb) THEN
1283 CALL build_dftb_ks_matrix(qs_env, &
1284 calculate_forces=calculate_forces, &
1285 just_energy=just_energy)
1286
1287 ELSEIF (dft_control%qs_control%xtb) THEN
1288 IF (dft_control%qs_control%xtb_control%do_tblite) THEN
1289 CALL build_tblite_ks_matrix(qs_env, &
1290 calculate_forces=calculate_forces, &
1291 just_energy=just_energy)
1292 ELSE
1293 CALL build_xtb_ks_matrix(qs_env, &
1294 calculate_forces=calculate_forces, &
1295 just_energy=just_energy)
1296 END IF
1297 ELSE
1298 CALL qs_ks_build_kohn_sham_matrix(qs_env, &
1299 calculate_forces=calculate_forces, &
1300 just_energy=just_energy, &
1301 print_active=print_active)
1302 END IF
1303
1304 CALL timestop(handle)
1305
1306 END SUBROUTINE rebuild_ks_matrix
1307
1308! **************************************************************************************************
1309!> \brief Allocate ks_matrix if necessary, take current overlap matrix as template
1310!> \param qs_env ...
1311!> \param is_complex ...
1312!> \par History
1313!> refactoring 04.03.2011 [MI]
1314!> \author
1315! **************************************************************************************************
1316
1317 SUBROUTINE qs_ks_allocate_basics(qs_env, is_complex)
1318 TYPE(qs_environment_type), POINTER :: qs_env
1319 LOGICAL, INTENT(in) :: is_complex
1320
1321 CHARACTER(LEN=default_string_length) :: headline
1322 INTEGER :: ic, ispin, nimages, nspins
1323 LOGICAL :: do_kpoints
1324 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_s_kp, matrixkp_im_ks, matrixkp_ks
1325 TYPE(dbcsr_type), POINTER :: refmatrix
1326 TYPE(dft_control_type), POINTER :: dft_control
1327 TYPE(kpoint_type), POINTER :: kpoints
1328 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
1329 POINTER :: sab_orb
1330 TYPE(qs_ks_env_type), POINTER :: ks_env
1331
1332 NULLIFY (dft_control, ks_env, matrix_s_kp, sab_orb, matrixkp_ks, refmatrix, matrixkp_im_ks, kpoints)
1333
1334 CALL get_qs_env(qs_env, &
1335 dft_control=dft_control, &
1336 matrix_s_kp=matrix_s_kp, &
1337 ks_env=ks_env, &
1338 kpoints=kpoints, &
1339 do_kpoints=do_kpoints, &
1340 matrix_ks_kp=matrixkp_ks, &
1341 matrix_ks_im_kp=matrixkp_im_ks)
1342
1343 IF (do_kpoints) THEN
1344 CALL get_kpoint_info(kpoints, sab_nl=sab_orb)
1345 ELSE
1346 CALL get_qs_env(qs_env, sab_orb=sab_orb)
1347 END IF
1348
1349 nspins = dft_control%nspins
1350 nimages = dft_control%nimages
1351
1352 IF (.NOT. ASSOCIATED(matrixkp_ks)) THEN
1353 CALL dbcsr_allocate_matrix_set(matrixkp_ks, nspins, nimages)
1354 refmatrix => matrix_s_kp(1, 1)%matrix
1355 DO ispin = 1, nspins
1356 DO ic = 1, nimages
1357 IF (nspins > 1) THEN
1358 IF (ispin == 1) THEN
1359 headline = "KOHN-SHAM MATRIX FOR ALPHA SPIN"
1360 ELSE
1361 headline = "KOHN-SHAM MATRIX FOR BETA SPIN"
1362 END IF
1363 ELSE
1364 headline = "KOHN-SHAM MATRIX"
1365 END IF
1366 ALLOCATE (matrixkp_ks(ispin, ic)%matrix)
1367 CALL dbcsr_create(matrix=matrixkp_ks(ispin, ic)%matrix, template=refmatrix, &
1368 name=trim(headline), matrix_type=dbcsr_type_symmetric)
1369 CALL cp_dbcsr_alloc_block_from_nbl(matrixkp_ks(ispin, ic)%matrix, sab_orb)
1370 CALL dbcsr_set(matrixkp_ks(ispin, ic)%matrix, 0.0_dp)
1371 END DO
1372 END DO
1373 CALL set_ks_env(ks_env, matrix_ks_kp=matrixkp_ks)
1374 END IF
1375
1376 IF (is_complex) THEN
1377 IF (.NOT. ASSOCIATED(matrixkp_im_ks)) THEN
1378 cpassert(nspins .EQ. SIZE(matrixkp_ks, 1))
1379 cpassert(nimages .EQ. SIZE(matrixkp_ks, 2))
1380 CALL dbcsr_allocate_matrix_set(matrixkp_im_ks, nspins, nimages)
1381 DO ispin = 1, nspins
1382 DO ic = 1, nimages
1383 IF (nspins > 1) THEN
1384 IF (ispin == 1) THEN
1385 headline = "IMAGINARY KOHN-SHAM MATRIX FOR ALPHA SPIN"
1386 ELSE
1387 headline = "IMAGINARY KOHN-SHAM MATRIX FOR BETA SPIN"
1388 END IF
1389 ELSE
1390 headline = "IMAGINARY KOHN-SHAM MATRIX"
1391 END IF
1392 ALLOCATE (matrixkp_im_ks(ispin, ic)%matrix)
1393 refmatrix => matrixkp_ks(ispin, ic)%matrix ! base on real part, but anti-symmetric
1394 CALL dbcsr_create(matrix=matrixkp_im_ks(ispin, ic)%matrix, template=refmatrix, &
1395 name=trim(headline), matrix_type=dbcsr_type_antisymmetric)
1396 CALL cp_dbcsr_alloc_block_from_nbl(matrixkp_im_ks(ispin, ic)%matrix, sab_orb)
1397 CALL dbcsr_set(matrixkp_im_ks(ispin, ic)%matrix, 0.0_dp)
1398 END DO
1399 END DO
1400 CALL set_ks_env(ks_env, matrix_ks_im_kp=matrixkp_im_ks)
1401 END IF
1402 END IF
1403
1404 END SUBROUTINE qs_ks_allocate_basics
1405
1406END MODULE qs_ks_methods
Contains ADMM methods which only require the density matrix.
subroutine, public admm_dm_merge_ks_matrix(qs_env)
Entry methods: Merges auxiliary Kohn-Sham matrix into primary one.
subroutine, public admm_dm_calc_rho_aux(qs_env)
Entry methods: Calculates auxiliary density matrix from primary one.
Contains ADMM methods which require molecular orbitals.
subroutine, public admm_mo_calc_rho_aux_kp(qs_env)
...
subroutine, public admm_mo_merge_ks_matrix(qs_env)
...
subroutine, public admm_update_ks_atom(qs_env, calculate_forces)
Adds the GAPW exchange contribution to the aux_fit ks matrices.
subroutine, public calc_admm_ovlp_forces_kp(qs_env)
Calculate the forces due to the AUX/ORB basis overlap in ADMM, in the KP case.
subroutine, public admm_mo_calc_rho_aux(qs_env)
...
subroutine, public calc_admm_ovlp_forces(qs_env)
Calculate the forces due to the AUX/ORB basis overlap in ADMM.
subroutine, public calc_admm_mo_derivatives(qs_env, mo_derivs)
Calculate the derivative of the AUX_FIT mo, based on the ORB mo_derivs.
Types and set/get functions for auxiliary density matrix methods.
Definition admm_types.F:15
subroutine, public get_admm_env(admm_env, mo_derivs_aux_fit, mos_aux_fit, sab_aux_fit, sab_aux_fit_asymm, sab_aux_fit_vs_orb, matrix_s_aux_fit, matrix_s_aux_fit_kp, matrix_s_aux_fit_vs_orb, matrix_s_aux_fit_vs_orb_kp, task_list_aux_fit, matrix_ks_aux_fit, matrix_ks_aux_fit_kp, matrix_ks_aux_fit_im, matrix_ks_aux_fit_dft, matrix_ks_aux_fit_hfx, matrix_ks_aux_fit_dft_kp, matrix_ks_aux_fit_hfx_kp, rho_aux_fit, rho_aux_fit_buffer, admm_dm)
Get routine for the ADMM env.
Definition admm_types.F:593
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_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_filter(matrix, eps)
...
subroutine, public dbcsr_set(matrix, alpha)
...
subroutine, public dbcsr_release(matrix)
...
subroutine, public dbcsr_add(matrix_a, matrix_b, alpha_scalar, beta_scalar)
...
DBCSR operations in CP2K.
subroutine, public dbcsr_copy_columns_hack(matrix_b, matrix_a, ncol, source_start, target_start, para_env, blacs_env)
hack for dbcsr_copy_columns
Density Derived atomic point charges from a QM calculation (see Bloechl, J. Chem. Phys....
Definition cp_ddapc.F:15
subroutine, public qs_ks_ddapc(qs_env, auxbas_pw_pool, rho_tot_gspace, v_hartree_gspace, v_spin_ddapc_rest_r, energy, calculate_forces, ks_matrix, just_energy)
Set of methods using DDAPC charges.
Definition cp_ddapc.F:81
represent a full matrix distributed on many processors
Definition cp_fm_types.F:15
various routines to log and control the output. The idea is that decisions about where to log should ...
integer function, public cp_logger_get_default_io_unit(logger)
returns the unit nr for the ionode (-1 on all other processors) skips as well checks if the procs cal...
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
routines to handle the output, The idea is to remove the decision of wheter to output and what to out...
integer, 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...
Add the DFT+U contribution to the Hamiltonian matrix.
Definition dft_plus_u.F:18
subroutine, public plus_u(qs_env, matrix_h, matrix_w)
Add the DFT+U contribution to the Hamiltonian matrix. Wrapper routine for all "+U" methods.
Definition dft_plus_u.F:99
subroutine, public vh_1c_gg_integrals(qs_env, energy_hartree_1c, ecoul_1c, local_rho_set, para_env, tddft, local_rho_set_2nd, core_2nd)
Calculates one center GAPW Hartree energies and matrix elements Hartree potentials are input Takes po...
Utilities for hfx and admm methods.
subroutine, public hfx_ks_matrix(qs_env, matrix_ks, rho, energy, calculate_forces, just_energy, v_rspace_new, v_tau_rspace)
Add the hfx contributions to the Hamiltonian.
subroutine, public hfx_admm_init(qs_env, calculate_forces)
...
subroutine, public hfx_ks_matrix_kp(qs_env, matrix_ks, energy, calculate_forces)
Add the HFX K-point contribution to the real-space Hamiltonians.
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public smeagol_runtype_emtransport
integer, parameter, public do_ppl_grid
integer, parameter, public outer_scf_becke_constraint
integer, parameter, public outer_scf_hirshfeld_constraint
objects that represent the structure of input sections and the data contained in an input section
recursive type(section_vals_type) function, pointer, public section_vals_get_subs_vals(section_vals, subsection_name, i_rep_section, can_return_null)
returns the values of the requested subsection
subroutine, public section_vals_get(section_vals, ref_count, n_repetition, n_subs_vals_rep, section, explicit)
returns various attributes about the section_vals
subroutine, public section_vals_val_get(section_vals, keyword_name, i_rep_section, i_rep_val, n_rep_val, val, l_val, i_val, r_val, c_val, l_vals, i_vals, r_vals, c_vals, explicit)
returns the requested value
Routines for a Kim-Gordon-like partitioning into molecular subunits.
subroutine, public kg_ekin_subset(qs_env, ks_matrix, ekin_mol, calc_force, do_kernel, pmat_ext)
Calculates the subsystem Hohenberg-Kohn kinetic energy and the forces.
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)
Retrieve information from a kpoint environment.
Calculates integral matrices for LRIGPW method lri : local resolution of the identity.
subroutine, public v_int_ppl_energy(qs_env, lri_v_int, ecore_ppl_ri)
...
contains the types and subroutines for dealing with the lri_env lri : local resolution of the identit...
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:151
Interface to the message passing library MPI.
container for various plainwaves related things
subroutine, public pw_env_get(pw_env, pw_pools, cube_info, gridlevel_info, auxbas_pw_pool, auxbas_grid, auxbas_rs_desc, auxbas_rs_grid, rs_descs, rs_grids, xc_pw_pool, vdw_pw_pool, poisson_env, interp_section)
returns the various attributes of the pw env
functions related to the poisson solver on regular grids
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 ...
Routines for image charge calculation within QM/MM.
subroutine, public calculate_image_pot(v_hartree_rspace, rho_hartree_gspace, energy, qmmm_env, qs_env)
determines coefficients by solving image_matrix*coeff=-pot_const by Gaussian elimination or in an ite...
subroutine, public integrate_potential_devga_rspace(potential, coeff, forces, qmmm_env, qs_env)
calculates the image forces on the MM atoms
subroutine, public add_image_pot_to_hartree_pot(v_hartree, v_metal, qs_env)
Add potential of metal (image charge pot) to Hartree Potential.
Defines CDFT control structures.
container for information about total charges on the grids
Calculation of the energies concerning the core charge distribution.
Calculation of Overlap and Hamiltonian matrices in DFTB.
subroutine, public build_dftb_ks_matrix(qs_env, calculate_forces, just_energy)
...
Calculates the energy contribution and the mo_derivative of a static periodic electric field.
subroutine, public qs_efield_berry_phase(qs_env, just_energy, calculate_forces)
...
Calculates the energy contribution and the mo_derivative of a static electric field (nonperiodic)
subroutine, public qs_efield_local_operator(qs_env, just_energy, calculate_forces)
...
subroutine, public get_qs_env(qs_env, atomic_kind_set, qs_kind_set, cell, super_cell, cell_ref, use_ref_cell, kpoints, dft_control, mos, sab_orb, sab_all, qmmm, qmmm_periodic, sac_ae, sac_ppl, sac_lri, sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, 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, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, rhoz_cneo_set, ecoul_1c, rho0_s_rs, rho0_s_gs, rhoz_cneo_s_rs, rhoz_cneo_s_gs, do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, lri_env, lri_density, exstate_env, ec_env, harris_env, dispersion_env, gcp_env, vee, rho_external, external_vxc, mask, mp2_env, bs_env, kg_env, wanniercentres, atprop, ls_scf_env, do_transport, transport_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, mscfg_env, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, eeq, rhs, do_rixs, tb_tblite)
Get the QUICKSTEP environment.
subroutine, public prepare_gapw_den(qs_env, local_rho_set, do_rho0, kind_set_external, pw_env_sub)
...
Types needed for a for a Harris model calculation.
Harris method environment setup and handling.
subroutine, public harris_set_potentials(harris_env, vh_rspace, vxc_rspace)
...
Integrate single or product functions over a potential on a RS grid.
Set of routines to apply restraints to the KS hamiltonian.
subroutine, public qs_ks_s2_restraint(dft_control, qs_env, matrix_s, energy, calculate_forces, just_energy)
...
subroutine, public qs_ks_mulliken_restraint(energy, dft_control, just_energy, para_env, ks_matrix, matrix_s, rho, mulliken_order_p)
...
subroutine, public qs_ks_cdft_constraint(qs_env, auxbas_pw_pool, calculate_forces, cdft_control)
Apply a CDFT constraint.
routines that build the Kohn-Sham matrix contributions coming from local atomic densities
Definition qs_ks_atom.F:12
subroutine, public update_ks_atom(qs_env, ksmat, pmat, forces, tddft, rho_atom_external, kind_set_external, oce_external, sab_external, kscale, kintegral, kforce, fscale)
The correction to the KS matrix due to the GAPW local terms to the hartree and XC contributions is he...
Definition qs_ks_atom.F:110
routines that build the Kohn-Sham matrix (i.e calculate the coulomb and xc parts
subroutine, public evaluate_core_matrix_p_mix_new(qs_env)
Calculates the traces of the core matrices and the density matrix.
subroutine, public qs_ks_build_kohn_sham_matrix(qs_env, calculate_forces, just_energy, print_active, ext_ks_matrix)
routine where the real calculations are made: the KS matrix is calculated
subroutine, public qs_ks_update_qs_env(qs_env, calculate_forces, just_energy, print_active)
updates the Kohn Sham matrix of the given qs_env (facility method)
subroutine, public qs_ks_allocate_basics(qs_env, is_complex)
Allocate ks_matrix if necessary, take current overlap matrix as template.
subroutine, public calc_rho_tot_gspace(rho_tot_gspace, qs_env, rho, skip_nuclear_density)
...
subroutine, public qmmm_calculate_energy(qs_env, rho, v_qmmm, qmmm_energy)
Computes the contribution to the total energy of the QM/MM electrostatic coupling.
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 set_ks_env(ks_env, v_hartree_rspace, s_mstruct_changed, rho_changed, 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_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, vppl, rho_core, rho_nlcc, rho_nlcc_g, vee, neighbor_list_id, kpoints, 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, subsys, dft_control, dbcsr_dist, distribution_2d, pw_env, para_env, blacs_env)
...
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 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
subroutine, public compute_matrix_vxc(qs_env, v_rspace, matrix_vxc)
compute matrix_vxc, defined via the potential created by qs_vxc_create ignores things like tau functi...
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)
Get the components of a MO set data structure.
Define the neighbor list data types and the corresponding functionality.
subroutine, public integrate_vhg0_rspace(qs_env, v_rspace, para_env, calculate_forces, local_rho_set, local_rho_set_2nd, atener, kforce, my_pools, my_rs_descs)
...
superstucture that hold various representations of the density and keeps track of which ones are vali...
subroutine, public qs_rho_get(rho_struct, rho_ao, rho_ao_im, rho_ao_kp, rho_ao_im_kp, rho_r, drho_r, rho_g, drho_g, tau_r, tau_g, rho_r_valid, drho_r_valid, rho_g_valid, drho_g_valid, tau_r_valid, tau_g_valid, tot_rho_r, tot_rho_g, rho_r_sccs, soft_valid, complex_rho_ao)
returns info about the density described by this object. If some representation is not available an e...
Self-consistent continuum solvation (SCCS) model implementation.
Definition qs_sccs.F:29
subroutine, public sccs(qs_env, rho_tot_gspace, v_hartree_gspace, v_sccs, h_stress)
Self-consistent continuum solvation (SCCS) model implementation.
Definition qs_sccs.F:122
module that contains the definitions of the scf types
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, gradient_atom_set, adiabatic_rescale_factor, kind_set_external, rho_atom_set_external, xc_section_external)
...
Definition qs_vxc_atom.F:85
subroutine, public qs_vxc_create(ks_env, rho_struct, xc_section, vxc_rho, vxc_tau, exc, just_energy, edisp, dispersion_env, adiabatic_rescale_factor, pw_env_external)
calculates and allocates the xc potential, already reducing it to the dependence on rho and the one o...
Definition qs_vxc.F:98
Utilities for rtp in combination with admm methods adapted routines from admm_method (author Manuel G...
subroutine, public rtp_admm_merge_ks_matrix(qs_env)
...
subroutine, public rtp_admm_calc_rho_aux(qs_env)
Compute the ADMM density matrix in case of rtp (complex MO's)
Calculation of the Fock matrix for SE methods.
subroutine, public build_se_fock_matrix(qs_env, calculate_forces, just_energy)
Construction of the Fock matrix for NDDO methods.
CP2K+SMEAGOL interface.
subroutine, public smeagol_shift_v_hartree(v_hartree_rspace, cell, hartreeleadsleft, hartreeleadsright, hartreeleadsbottom, vbias, zleft, zright, isexplicit_zright, isexplicit_bottom)
Align Hatree potential of semi-infinite leads to match bulk-transport calculation and apply external ...
subroutine, public calc_dipsurf_potential(qs_env, energy)
compute the surface dipole and the correction to the hartree potential
tblite matrix build
subroutine, public build_tblite_ks_matrix(qs_env, calculate_forces, just_energy, ext_ks_matrix)
...
Calculation of KS matrix in xTB Reference: Stefan Grimme, Christoph Bannwarth, Philip Shushkov JCTC 1...
subroutine, public build_xtb_ks_matrix(qs_env, calculate_forces, just_energy, ext_ks_matrix)
...
stores some data used in wavefunction fitting
Definition admm_types.F:120
Type defining parameters related to the simulation cell.
Definition cell_types.F:55
represent a full matrix
type of a logger, at the moment it contains just a print level starting at which level it should be l...
Contains information 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.
Contains information on the Harris method.
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.