(git:d1312bc)
Loading...
Searching...
No Matches
qs_core_hamiltonian.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 Calculation of the core Hamiltonian integral matrix <a|H|b> over
10!> Cartesian Gaussian-type functions.
11!>
12!> <a|H|b> = <a|T|b> + <a|V|b>
13!>
14!> Kinetic energy:
15!>
16!> <a|T|b> = <a|-nabla**2/2|b>
17!> \_______________/
18!> |
19!> kinetic
20!>
21!> Nuclear potential energy:
22!>
23!> a) Allelectron calculation:
24!>
25!> erfc(r)
26!> <a|V|b> = -Z*<a|---------|b>
27!> r
28!>
29!> 1 - erf(r)
30!> = -Z*<a|------------|b>
31!> r
32!>
33!> 1 erf(r)
34!> = -Z*(<a|---|b> - <a|--------|b>)
35!> r r
36!>
37!> 1
38!> = -Z*(<a|---|b> - N*<ab||c>)
39!> r
40!>
41!> -Z
42!> = <a|---|b> + Z*N*<ab||c>
43!> r
44!> \_______/ \_____/
45!> | |
46!> nuclear coulomb
47!>
48!> b) Pseudopotential calculation (Goedecker, Teter and Hutter; GTH):
49!>
50!> <a|V|b> = <a|(V(local) + V(non-local))|b>
51!>
52!> = <a|(V(local)|b> + <a|V(non-local))|b>
53!>
54!> <a|V(local)|b> = <a|-Z(eff)*erf(SQRT(2)*alpha*r)/r +
55!> (C1 + C2*(alpha*r)**2 + C3*(alpha*r)**4 +
56!> C4*(alpha*r)**6)*exp(-(alpha*r)**2/2))|b>
57!>
58!> <a|V(non-local)|b> = <a|p(l,i)>*h(i,j)*<p(l,j)|b>
59!> \par Literature
60!> S. Goedecker, M. Teter and J. Hutter, Phys. Rev. B 54, 1703 (1996)
61!> C. Hartwigsen, S. Goedecker and J. Hutter, Phys. Rev. B 58, 3641 (1998)
62!> M. Krack and M. Parrinello, Phys. Chem. Chem. Phys. 2, 2105 (2000)
63!> S. Obara and A. Saika, J. Chem. Phys. 84, 3963 (1986)
64!> \par History
65!> - Joost VandeVondele (April 2003) : added LSD forces
66!> - Non-redundant calculation of the non-local part of the GTH PP
67!> (22.05.2003,MK)
68!> - New parallelization scheme (27.06.2003,MK)
69!> - OpenMP version (07.12.2003,JGH)
70!> - Binary search loop for VPPNL operators (09.01.2004,JGH,MK)
71!> - Refactoring of pseudopotential and nuclear attraction integrals (25.02.2009,JGH)
72!> - General refactoring (01.10.2010,JGH)
73!> - Refactoring related to the new kinetic energy and overlap routines (07.2014,JGH)
74!> - k-point functionality (07.2015,JGH)
75!> \author Matthias Krack (14.09.2000,21.03.02)
76! **************************************************************************************************
81 USE cp_dbcsr_api, ONLY: dbcsr_add,&
86 dbcsr_set,&
88 dbcsr_type_antisymmetric
96 USE cp_output_handling, ONLY: cp_p_file,&
106 USE kinds, ONLY: default_string_length,&
107 dp
111 USE qs_condnum, ONLY: overlap_condnum
118 USE qs_kind_types, ONLY: get_qs_kind,&
120 USE qs_ks_types, ONLY: get_ks_env,&
125 USE qs_oce_types, ONLY: allocate_oce_set,&
129 USE qs_rho_types, ONLY: qs_rho_get,&
131 USE virial_types, ONLY: virial_type
132#include "./base/base_uses.f90"
133
134 IMPLICIT NONE
135
136 PRIVATE
137
138 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_core_hamiltonian'
139
142
143CONTAINS
144
145! **************************************************************************************************
146!> \brief Cosntruction of the QS Core Hamiltonian Matrix
147!> \param qs_env ...
148!> \param calculate_forces ...
149!> \author Creation (11.03.2002,MK)
150!> Non-redundant calculation of the non-local part of the GTH PP (22.05.2003,MK)
151!> New parallelization scheme (27.06.2003,MK)
152! **************************************************************************************************
153 SUBROUTINE build_core_hamiltonian_matrix(qs_env, calculate_forces)
154
155 TYPE(qs_environment_type), POINTER :: qs_env
156 LOGICAL, INTENT(IN) :: calculate_forces
157
158 CHARACTER(LEN=*), PARAMETER :: routinen = 'build_core_hamiltonian_matrix'
159
160 INTEGER :: handle, ikind, img, iw, nder, nders, &
161 nimages, nkind
162 LOGICAL :: dft_plus_u_atom, h_is_complex, norml1, &
163 norml2, ofdft, &
164 tensorial_plus_u_forces, use_arnoldi, &
165 use_virial
166 REAL(kind=dp) :: eps_filter, eps_fit
167 REAL(kind=dp), DIMENSION(2) :: condnum
168 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
169 TYPE(cp_blacs_env_type), POINTER :: blacs_env
170 TYPE(cp_logger_type), POINTER :: logger
171 TYPE(dbcsr_distribution_type), POINTER :: dbcsr_dist
172 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_h, matrix_p, matrix_s, matrix_t, &
173 matrix_w
174 TYPE(dft_control_type), POINTER :: dft_control
175 TYPE(kg_environment_type), POINTER :: kg_env
176 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
177 POINTER :: sab_orb, sap_oce
178 TYPE(oce_matrix_type), POINTER :: oce
179 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
180 TYPE(qs_force_type), DIMENSION(:), POINTER :: force
181 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
182 TYPE(qs_ks_env_type), POINTER :: ks_env
183 TYPE(qs_rho_type), POINTER :: rho
184 TYPE(virial_type), POINTER :: virial
185
186 IF (calculate_forces) THEN
187 CALL timeset(routinen//"_forces", handle)
188 ELSE
189 CALL timeset(routinen, handle)
190 END IF
191
192 NULLIFY (logger)
193 logger => cp_get_default_logger()
194
195 NULLIFY (dft_control)
196 CALL get_qs_env(qs_env=qs_env, dft_control=dft_control)
197
198 NULLIFY (qs_kind_set)
199 CALL get_qs_env(qs_env=qs_env, qs_kind_set=qs_kind_set)
200
201 ! is this a orbital-free method calculation
202 ofdft = dft_control%qs_control%ofgpw
203
204 nimages = dft_control%nimages
205 IF (ofdft) THEN
206 cpassert(nimages == 1)
207 END IF
208
209 nders = 0
210 IF (calculate_forces) THEN
211 nder = 1
212 ELSE
213 IF (cp_print_key_should_output(logger%iter_info, qs_env%input, &
214 "DFT%PRINT%AO_MATRICES/DERIVATIVES") /= 0) THEN
215 nder = 1
216 ELSE
217 nder = 0
218 END IF
219 END IF
220
221 IF ((cp_print_key_should_output(logger%iter_info, qs_env%input, &
222 "DFT%PRINT%AO_MATRICES/OVERLAP") /= 0 .AND. &
223 btest(cp_print_key_should_output(logger%iter_info, qs_env%input, &
224 "DFT%PRINT%AO_MATRICES/DERIVATIVES"), cp_p_file))) THEN
225 nders = 1
226 END IF
227
228 ! the delta pulse in the periodic case needs the momentum operator,
229 ! which is equivalent to the derivative of the overlap matrix
230 IF (ASSOCIATED(dft_control%rtp_control)) THEN
231 IF (dft_control%rtp_control%apply_delta_pulse .AND. &
232 dft_control%rtp_control%periodic) THEN
233 nders = 1
234 END IF
235 END IF
236
237 tensorial_plus_u_forces = .false.
238 IF (dft_control%plus_u_method_id == plus_u_tensorial) THEN
239 IF (ASSOCIATED(qs_kind_set)) THEN
240 DO ikind = 1, SIZE(qs_kind_set)
241 CALL get_qs_kind(qs_kind_set(ikind), &
242 dft_plus_u_atom=dft_plus_u_atom)
243 IF (dft_plus_u_atom) THEN
244 tensorial_plus_u_forces = .true.
245 EXIT
246 END IF
247 END DO
248 END IF
249 END IF
250 IF (tensorial_plus_u_forces) THEN
251 nders = 1
252 END IF
253
254 IF (dft_control%tddfpt2_control%enabled) THEN
255 nders = 1
256 IF (dft_control%do_admm) THEN
257 IF (dft_control%admm_control%purification_method /= do_admm_purify_none) THEN
258 CALL cp_abort(__location__, &
259 "Only purification method NONE is possible with TDDFT at the moment")
260 END IF
261 END IF
262 END IF
263
264 ! filter for new matrices
265 eps_filter = dft_control%qs_control%eps_filter_matrix
266 !
267 NULLIFY (ks_env)
268 CALL get_qs_env(qs_env=qs_env, ks_env=ks_env)
269 NULLIFY (matrix_s, matrix_t)
270 CALL get_qs_env(qs_env=qs_env, kinetic_kp=matrix_t, matrix_s_kp=matrix_s)
271 NULLIFY (sab_orb)
272 CALL get_qs_env(qs_env=qs_env, sab_orb=sab_orb)
273 NULLIFY (rho, force, matrix_p, matrix_w)
274 IF (calculate_forces) THEN
275 CALL get_qs_env(qs_env=qs_env, force=force, matrix_w_kp=matrix_w)
276 CALL get_qs_env(qs_env=qs_env, rho=rho)
277 CALL qs_rho_get(rho, rho_ao_kp=matrix_p)
278 ! *** If LSD, then combine alpha density and beta density to
279 ! *** total density: alpha <- alpha + beta and
280 ! *** spin density: beta <- alpha - beta
281 ! (since all things can be computed based on the sum of these matrices anyway)
282 ! (matrix_p is restored at the end of the run, matrix_w is left in its modified state
283 ! (as it should not be needed afterwards)
284 IF (SIZE(matrix_p, 1) == 2) THEN
285 DO img = 1, nimages
286 CALL dbcsr_add(matrix_p(1, img)%matrix, matrix_p(2, img)%matrix, &
287 alpha_scalar=1.0_dp, beta_scalar=1.0_dp)
288 CALL dbcsr_add(matrix_p(2, img)%matrix, matrix_p(1, img)%matrix, &
289 alpha_scalar=-2.0_dp, beta_scalar=1.0_dp)
290 CALL dbcsr_add(matrix_w(1, img)%matrix, matrix_w(2, img)%matrix, &
291 alpha_scalar=1.0_dp, beta_scalar=1.0_dp)
292 END DO
293 END IF
294 ELSE
295 NULLIFY (matrix_p, matrix_w)
296 END IF
297
298 ! S matrix
299 CALL build_overlap_matrix(ks_env, nderivative=nders, matrixkp_s=matrix_s, &
300 matrix_name="OVERLAP MATRIX", &
301 basis_type_a="ORB", &
302 basis_type_b="ORB", &
303 sab_nl=sab_orb, calculate_forces=calculate_forces, &
304 matrixkp_p=matrix_w)
305
306 IF (calculate_forces) THEN
307 ! *** If LSD, then recover alpha density and beta density ***
308 ! *** from the total density (1) and the spin density (2) ***
309 ! *** The W matrix is neglected, since it will be destroyed ***
310 ! *** in the calling force routine after leaving this routine ***
311 IF (SIZE(matrix_p, 1) == 2) THEN
312 DO img = 1, nimages
313 CALL dbcsr_add(matrix_p(1, img)%matrix, matrix_p(2, img)%matrix, &
314 alpha_scalar=0.5_dp, beta_scalar=0.5_dp)
315 CALL dbcsr_add(matrix_p(2, img)%matrix, matrix_p(1, img)%matrix, &
316 alpha_scalar=-1.0_dp, beta_scalar=1.0_dp)
317 END DO
318 END IF
319 END IF
320
321 ! T matrix
322 CALL kinetic_energy_matrix(qs_env, matrixkp_t=matrix_t, &
323 matrix_p=matrix_p, &
324 matrix_name="KINETIC ENERGY MATRIX", &
325 basis_type="ORB", &
326 sab_orb=sab_orb, &
327 calculate_forces=calculate_forces, &
328 eps_filter=eps_filter)
329
330 ! (Re-)allocate H matrix based on overlap matrix
331 CALL get_ks_env(ks_env, complex_ks=h_is_complex)
332 CALL qs_matrix_h_allocate(qs_env, matrix_s(1, 1)%matrix, is_complex=h_is_complex)
333
334 NULLIFY (matrix_h)
335 CALL get_qs_env(qs_env, matrix_h_kp=matrix_h)
336
337 IF (.NOT. ofdft) THEN
338 DO img = 1, nimages
339 CALL dbcsr_copy(matrix_h(1, img)%matrix, matrix_t(1, img)%matrix, &
340 keep_sparsity=.true., name="CORE HAMILTONIAN MATRIX")
341 END DO
342 END IF
343
344 NULLIFY (qs_kind_set, atomic_kind_set, particle_set)
345 CALL get_qs_env(qs_env=qs_env, qs_kind_set=qs_kind_set, atomic_kind_set=atomic_kind_set, &
346 particle_set=particle_set)
347
348 ! *** core and pseudopotentials
349 CALL core_matrices(qs_env, matrix_h, matrix_p, calculate_forces, nder)
350
351 ! *** CNEO nuclear V_core
352 CALL cneo_core_matrices(qs_env, calculate_forces, nder)
353
354 ! *** GAPW one-center-expansion (oce) matrices
355 NULLIFY (sap_oce)
356 CALL get_qs_env(qs_env=qs_env, sap_oce=sap_oce)
357 NULLIFY (oce)
358 IF (dft_control%qs_control%gapw .OR. dft_control%qs_control%gapw_xc) THEN
359 CALL get_qs_env(qs_env=qs_env, oce=oce)
360 CALL create_oce_set(oce)
361 nkind = SIZE(atomic_kind_set)
362 CALL allocate_oce_set(oce, nkind)
363 eps_fit = dft_control%qs_control%gapw_control%eps_fit
364 IF (ASSOCIATED(sap_oce)) THEN
365 CALL build_oce_matrices(oce%intac, calculate_forces, nder, qs_kind_set, particle_set, &
366 sap_oce, eps_fit)
367 END IF
368 END IF
369
370 ! *** KG atomic potentials for nonadditive kinetic energy
371 IF (dft_control%qs_control%do_kg) THEN
372 IF (qs_env%kg_env%tnadd_method == kg_tnadd_atomic) THEN
373 CALL get_qs_env(qs_env=qs_env, kg_env=kg_env, virial=virial, dbcsr_dist=dbcsr_dist)
374 use_virial = virial%pv_availability .AND. (.NOT. virial%pv_numer)
375 CALL build_tnadd_mat(kg_env, matrix_p, force, virial, calculate_forces, use_virial, &
376 qs_kind_set, atomic_kind_set, particle_set, sab_orb, dbcsr_dist)
377 END IF
378 END IF
379
380 ! *** Put the core Hamiltonian matrix in the QS environment ***
381 CALL set_qs_env(qs_env, oce=oce)
382 CALL set_ks_env(ks_env, matrix_s_kp=matrix_s, kinetic_kp=matrix_t, matrix_h_kp=matrix_h)
383
384 ! *** Print matrices if requested
385 CALL dump_info_core_hamiltonian(qs_env, calculate_forces)
386
387 ! *** Overlap condition number
388 IF (.NOT. calculate_forces) THEN
389 IF (cp_print_key_should_output(logger%iter_info, qs_env%input, &
390 "DFT%PRINT%OVERLAP_CONDITION") /= 0) THEN
391 iw = cp_print_key_unit_nr(logger, qs_env%input, "DFT%PRINT%OVERLAP_CONDITION", &
392 extension=".Log")
393 CALL section_vals_val_get(qs_env%input, "DFT%PRINT%OVERLAP_CONDITION%1-NORM", l_val=norml1)
394 CALL section_vals_val_get(qs_env%input, "DFT%PRINT%OVERLAP_CONDITION%DIAGONALIZATION", l_val=norml2)
395 CALL section_vals_val_get(qs_env%input, "DFT%PRINT%OVERLAP_CONDITION%ARNOLDI", l_val=use_arnoldi)
396 CALL get_qs_env(qs_env=qs_env, blacs_env=blacs_env)
397 CALL overlap_condnum(matrix_s, condnum, iw, norml1, norml2, use_arnoldi, blacs_env)
398 END IF
399 END IF
400
401 CALL timestop(handle)
402
403 END SUBROUTINE build_core_hamiltonian_matrix
404
405! **************************************************************************************************
406!> \brief Possibly prints matrices after the construction of the Core
407!> Hamiltonian Matrix
408!> \param qs_env ...
409!> \param calculate_forces ...
410! **************************************************************************************************
411 SUBROUTINE dump_info_core_hamiltonian(qs_env, calculate_forces)
412 TYPE(qs_environment_type), POINTER :: qs_env
413 LOGICAL, INTENT(IN) :: calculate_forces
414
415 CHARACTER(LEN=*), PARAMETER :: routinen = 'dump_info_core_hamiltonian'
416
417 INTEGER :: after, handle, i, ic, iw, output_unit
418 LOGICAL :: omit_headers
419 TYPE(cp_logger_type), POINTER :: logger
420 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_v
421 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrixkp_h, matrixkp_s, matrixkp_t
422 TYPE(mp_para_env_type), POINTER :: para_env
423
424 CALL timeset(routinen, handle)
425
426 NULLIFY (logger, matrix_v, para_env)
427 logger => cp_get_default_logger()
428 CALL get_qs_env(qs_env, para_env=para_env)
429
430 ! Print the distribution of the overlap matrix blocks
431 ! this duplicates causes duplicate printing at the force calc
432 IF (.NOT. calculate_forces) THEN
433 IF (btest(cp_print_key_should_output(logger%iter_info, &
434 qs_env%input, "PRINT%DISTRIBUTION"), cp_p_file)) THEN
435 output_unit = cp_print_key_unit_nr(logger, qs_env%input, "PRINT%DISTRIBUTION", &
436 extension=".distribution")
437 CALL get_qs_env(qs_env, matrix_s_kp=matrixkp_s)
438 CALL cp_dbcsr_write_matrix_dist(matrixkp_s(1, 1)%matrix, output_unit, para_env)
439 CALL cp_print_key_finished_output(output_unit, logger, qs_env%input, "PRINT%DISTRIBUTION")
440 END IF
441 END IF
442
443 CALL section_vals_val_get(qs_env%input, "DFT%PRINT%AO_MATRICES%OMIT_HEADERS", l_val=omit_headers)
444 ! Print the overlap integral matrix, if requested
445 IF (btest(cp_print_key_should_output(logger%iter_info, &
446 qs_env%input, "DFT%PRINT%AO_MATRICES/OVERLAP"), cp_p_file)) THEN
447 iw = cp_print_key_unit_nr(logger, qs_env%input, "DFT%PRINT%AO_MATRICES/OVERLAP", &
448 extension=".Log")
449 CALL section_vals_val_get(qs_env%input, "DFT%PRINT%AO_MATRICES%NDIGITS", i_val=after)
450 after = min(max(after, 1), 16)
451 CALL get_qs_env(qs_env, matrix_s_kp=matrixkp_s)
452 IF (ASSOCIATED(matrixkp_s)) THEN
453 DO ic = 1, SIZE(matrixkp_s, 2)
454 CALL cp_dbcsr_write_sparse_matrix(matrixkp_s(1, ic)%matrix, 4, after, qs_env, para_env, &
455 output_unit=iw, omit_headers=omit_headers)
456 END DO
457 IF (btest(cp_print_key_should_output(logger%iter_info, qs_env%input, &
458 "DFT%PRINT%AO_MATRICES/DERIVATIVES"), cp_p_file)) THEN
459 DO ic = 1, SIZE(matrixkp_s, 2)
460 DO i = 2, SIZE(matrixkp_s, 1)
461 CALL cp_dbcsr_write_sparse_matrix(matrixkp_s(i, ic)%matrix, 4, after, qs_env, para_env, &
462 output_unit=iw, omit_headers=omit_headers)
463 END DO
464 END DO
465 END IF
466 END IF
467 CALL cp_print_key_finished_output(iw, logger, qs_env%input, &
468 "DFT%PRINT%AO_MATRICES/OVERLAP")
469 END IF
470
471 ! Print the kinetic energy integral matrix, if requested
472 IF (btest(cp_print_key_should_output(logger%iter_info, &
473 qs_env%input, "DFT%PRINT%AO_MATRICES/KINETIC_ENERGY"), cp_p_file)) THEN
474 iw = cp_print_key_unit_nr(logger, qs_env%input, "DFT%PRINT%AO_MATRICES/KINETIC_ENERGY", &
475 extension=".Log")
476 CALL section_vals_val_get(qs_env%input, "DFT%PRINT%AO_MATRICES%NDIGITS", i_val=after)
477 after = min(max(after, 1), 16)
478 CALL get_qs_env(qs_env, kinetic_kp=matrixkp_t)
479 IF (ASSOCIATED(matrixkp_t)) THEN
480 DO ic = 1, SIZE(matrixkp_t, 2)
481 CALL cp_dbcsr_write_sparse_matrix(matrixkp_t(1, ic)%matrix, 4, after, qs_env, para_env, &
482 output_unit=iw, omit_headers=omit_headers)
483 END DO
484 END IF
485 CALL cp_print_key_finished_output(iw, logger, qs_env%input, &
486 "DFT%PRINT%AO_MATRICES/KINETIC_ENERGY")
487 END IF
488
489 ! Print the potential energy matrix, if requested
490 IF (btest(cp_print_key_should_output(logger%iter_info, &
491 qs_env%input, "DFT%PRINT%AO_MATRICES/POTENTIAL_ENERGY"), cp_p_file)) THEN
492 iw = cp_print_key_unit_nr(logger, qs_env%input, "DFT%PRINT%AO_MATRICES/POTENTIAL_ENERGY", &
493 extension=".Log")
494 CALL section_vals_val_get(qs_env%input, "DFT%PRINT%AO_MATRICES%NDIGITS", i_val=after)
495 after = min(max(after, 1), 16)
496 CALL get_qs_env(qs_env, matrix_h_kp=matrixkp_h, kinetic_kp=matrixkp_t)
497 IF (ASSOCIATED(matrixkp_h)) THEN
498 IF (SIZE(matrixkp_h, 2) == 1) THEN
499 CALL dbcsr_allocate_matrix_set(matrix_v, 1)
500 ALLOCATE (matrix_v(1)%matrix)
501 CALL dbcsr_copy(matrix_v(1)%matrix, matrixkp_h(1, 1)%matrix, name="POTENTIAL ENERGY MATRIX")
502 CALL dbcsr_add(matrix_v(1)%matrix, matrixkp_t(1, 1)%matrix, &
503 alpha_scalar=1.0_dp, beta_scalar=-1.0_dp)
504 CALL cp_dbcsr_write_sparse_matrix(matrix_v(1)%matrix, 4, after, qs_env, &
505 para_env, output_unit=iw, omit_headers=omit_headers)
506 CALL dbcsr_deallocate_matrix_set(matrix_v)
507 ELSE
508 cpwarn("Printing of potential energy matrix not implemented for k-points")
509 END IF
510 END IF
511 CALL cp_print_key_finished_output(iw, logger, qs_env%input, &
512 "DFT%PRINT%AO_MATRICES/POTENTIAL_ENERGY")
513 END IF
514
515 ! Print the core Hamiltonian matrix, if requested
516 IF (btest(cp_print_key_should_output(logger%iter_info, &
517 qs_env%input, "DFT%PRINT%AO_MATRICES/CORE_HAMILTONIAN"), cp_p_file)) THEN
518 iw = cp_print_key_unit_nr(logger, qs_env%input, "DFT%PRINT%AO_MATRICES/CORE_HAMILTONIAN", &
519 extension=".Log")
520 CALL section_vals_val_get(qs_env%input, "DFT%PRINT%AO_MATRICES%NDIGITS", i_val=after)
521 after = min(max(after, 1), 16)
522 CALL get_qs_env(qs_env, matrix_h_kp=matrixkp_h)
523 IF (ASSOCIATED(matrixkp_h)) THEN
524 DO ic = 1, SIZE(matrixkp_h, 2)
525 CALL cp_dbcsr_write_sparse_matrix(matrixkp_h(1, ic)%matrix, 4, after, qs_env, para_env, &
526 output_unit=iw, omit_headers=omit_headers)
527 END DO
528 END IF
529 CALL cp_print_key_finished_output(iw, logger, qs_env%input, &
530 "DFT%PRINT%AO_MATRICES/CORE_HAMILTONIAN")
531 END IF
532
533 CALL timestop(handle)
534
535 END SUBROUTINE dump_info_core_hamiltonian
536
537! **************************************************************************************************
538!> \brief (Re-)allocate matrix_h based on the template (typically the overlap matrix)
539!> \param qs_env ...
540!> \param template ...
541!> \param is_complex ...
542! **************************************************************************************************
543 SUBROUTINE qs_matrix_h_allocate(qs_env, template, is_complex)
544 TYPE(qs_environment_type) :: qs_env
545 TYPE(dbcsr_type), INTENT(in) :: template
546 LOGICAL, INTENT(in) :: is_complex
547
548 CHARACTER(LEN=default_string_length) :: headline
549 INTEGER :: img, nimages
550 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_h, matrix_h_im
551 TYPE(dft_control_type), POINTER :: dft_control
552 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
553 POINTER :: sab_orb
554 TYPE(qs_ks_env_type), POINTER :: ks_env
555
556 NULLIFY (matrix_h, matrix_h_im, sab_orb, dft_control, ks_env)
557 CALL get_qs_env(qs_env=qs_env, &
558 matrix_h_kp=matrix_h, &
559 matrix_h_im_kp=matrix_h_im, &
560 sab_orb=sab_orb, &
561 dft_control=dft_control, &
562 ks_env=ks_env)
563
564 nimages = dft_control%nimages
565 CALL dbcsr_allocate_matrix_set(matrix_h, 1, nimages)
566 headline = "CORE HAMILTONIAN MATRIX"
567 DO img = 1, nimages
568 ALLOCATE (matrix_h(1, img)%matrix)
569 CALL dbcsr_create(matrix_h(1, img)%matrix, name=trim(headline), template=template)
570 CALL cp_dbcsr_alloc_block_from_nbl(matrix_h(1, img)%matrix, sab_orb)
571 CALL dbcsr_set(matrix_h(1, img)%matrix, 0.0_dp)
572 END DO
573 CALL set_ks_env(ks_env, matrix_h_kp=matrix_h)
574
575 IF (is_complex) THEN
576 headline = "IMAGINARY PART OF CORE HAMILTONIAN MATRIX"
577 CALL dbcsr_allocate_matrix_set(matrix_h_im, 1, nimages)
578 DO img = 1, nimages
579 ALLOCATE (matrix_h_im(1, img)%matrix)
580 CALL dbcsr_create(matrix_h_im(1, img)%matrix, name=trim(headline), template=template, &
581 matrix_type=dbcsr_type_antisymmetric)
582 CALL cp_dbcsr_alloc_block_from_nbl(matrix_h_im(1, img)%matrix, sab_orb)
583 CALL dbcsr_set(matrix_h_im(1, img)%matrix, 0.0_dp)
584 END DO
585 CALL set_ks_env(ks_env, matrix_h_im_kp=matrix_h_im)
586 END IF
587
588 END SUBROUTINE qs_matrix_h_allocate
589
590! **************************************************************************************************
591!> \brief (Re-)allocates matrix_h_im from matrix_h
592!> \param qs_env ...
593! **************************************************************************************************
595 TYPE(qs_environment_type) :: qs_env
596
597 CHARACTER(LEN=default_string_length) :: headline
598 INTEGER :: image, nimages
599 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_h, matrix_h_im
600 TYPE(dbcsr_type), POINTER :: template
601 TYPE(dft_control_type), POINTER :: dft_control
602 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
603 POINTER :: sab_orb
604 TYPE(qs_ks_env_type), POINTER :: ks_env
605
606 NULLIFY (matrix_h_im, matrix_h, dft_control, template, sab_orb, ks_env)
607
608 CALL get_qs_env(qs_env, &
609 matrix_h_im_kp=matrix_h_im, &
610 matrix_h_kp=matrix_h, &
611 dft_control=dft_control, &
612 sab_orb=sab_orb, &
613 ks_env=ks_env)
614
615 nimages = dft_control%nimages
616
617 cpassert(nimages == SIZE(matrix_h, 2))
618
619 CALL dbcsr_allocate_matrix_set(matrix_h_im, 1, nimages)
620
621 DO image = 1, nimages
622 headline = "IMAGINARY CORE HAMILTONIAN MATRIX"
623 ALLOCATE (matrix_h_im(1, image)%matrix)
624 template => matrix_h(1, image)%matrix ! base on real part, but anti-symmetric
625 CALL dbcsr_create(matrix=matrix_h_im(1, image)%matrix, template=template, &
626 name=trim(headline), matrix_type=dbcsr_type_antisymmetric)
627 CALL cp_dbcsr_alloc_block_from_nbl(matrix_h_im(1, image)%matrix, sab_orb)
628 CALL dbcsr_set(matrix_h_im(1, image)%matrix, 0.0_dp)
629 END DO
630 CALL set_ks_env(ks_env, matrix_h_im_kp=matrix_h_im)
631
633
634END MODULE qs_core_hamiltonian
Define the atomic kind types and their sub types.
methods related to the blacs parallel environment
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
subroutine, public dbcsr_copy(matrix_b, matrix_a, name, keep_sparsity, keep_imaginary)
...
subroutine, public dbcsr_set(matrix, alpha)
...
subroutine, public dbcsr_add(matrix_a, matrix_b, alpha_scalar, beta_scalar)
...
DBCSR operations in CP2K.
DBCSR output in CP2K.
subroutine, public cp_dbcsr_write_matrix_dist(matrix, output_unit, para_env)
Print the distribution of a sparse matrix.
subroutine, public cp_dbcsr_write_sparse_matrix(sparse_matrix, before, after, qs_env, para_env, first_row, last_row, first_col, last_col, scale, output_unit, omit_headers, cartesian_basis)
...
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...
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)
...
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...
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public do_admm_purify_none
integer, parameter, public kg_tnadd_atomic
integer, parameter, public plus_u_tensorial
objects that represent the structure of input sections and the data contained in an input section
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
Types needed for a Kim-Gordon-like partitioning into molecular subunits.
Calculation of the local potential contribution of the nonadditive kinetic energy <a|V(local)|b> = <a...
subroutine, public build_tnadd_mat(kg_env, matrix_p, force, virial, calculate_forces, use_virial, qs_kind_set, atomic_kind_set, particle_set, sab_orb, dbcsr_dist)
...
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
integer, parameter, public default_string_length
Definition kinds.F:57
Interface to the message passing library MPI.
Define the data structure for the particle information.
A collection of functions used by CNEO-DFT (see J. Chem. Theory Comput. 2025, 21, 16,...
subroutine, public cneo_core_matrices(qs_env, calculate_forces, nder)
...
Calculation of overlap matrix condition numbers.
Definition qs_condnum.F:13
subroutine, public overlap_condnum(matrixkp_s, condnum, iunit, norml1, norml2, use_arnoldi, blacs_env)
Calculation of the overlap matrix Condition Number.
Definition qs_condnum.F:66
Calculation of the core Hamiltonian integral matrix <a|H|b> over Cartesian Gaussian-type functions.
subroutine, public build_core_hamiltonian_matrix(qs_env, calculate_forces)
Cosntruction of the QS Core Hamiltonian Matrix.
subroutine, public dump_info_core_hamiltonian(qs_env, calculate_forces)
Possibly prints matrices after the construction of the Core Hamiltonian Matrix.
subroutine, public qs_matrix_h_allocate_imag_from_real(qs_env)
(Re-)allocates matrix_h_im from matrix_h
Calculation of the core Hamiltonian integral matrix <a|H|b> over Cartesian Gaussian-type functions.
subroutine, public core_matrices(qs_env, matrix_h, matrix_p, calculate_forces, nder, ec_env, dcdr_env, ec_env_matrices, ext_kpoints, basis_type, debug_forces, debug_stress, atcore)
...
subroutine, public kinetic_energy_matrix(qs_env, matrixkp_t, matrix_t, matrix_p, ext_kpoints, matrix_name, calculate_forces, nderivative, sab_orb, eps_filter, basis_type, debug_forces, debug_stress)
Calculate kinetic energy matrix and possible relativistic correction.
subroutine, public 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.
subroutine, public set_qs_env(qs_env, super_cell, mos, qmmm, qmmm_periodic, mimic, ewald_env, ewald_pw, mpools, rho_external, external_vxc, mask, scf_control, rel_control, qs_charges, ks_env, ks_qmmm_env, wf_history, scf_env, active_space, input, oce, rho_atom_set, rho0_atom_set, rho0_mpole, run_rtp, rtp, rhoz_set, rhoz_tot, ecoul_1c, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, efield, rhoz_cneo_set, linres_control, xas_env, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, ls_scf_env, do_transport, transport_env, lri_env, lri_density, exstate_env, ec_env, dispersion_env, harris_env, gcp_env, mp2_env, bs_env, kg_env, force, kpoints, wanniercentres, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, eeq, rhs, do_rixs, tb_tblite)
Set the QUICKSTEP environment.
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 set_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, vppl, xcint_weights, 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)
...
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)
...
Define the neighbor list data types and the corresponding functionality.
Routines for the construction of the coefficients for the expansion of the atomic densities rho1_hard...
subroutine, public build_oce_matrices(intac, calculate_forces, nder, qs_kind_set, particle_set, sap_oce, eps_fit)
Set up the sparse matrix for the coefficients of one center expansions This routine uses the same log...
subroutine, public allocate_oce_set(oce_set, nkind)
Allocate and initialize the matrix set of oce coefficients.
subroutine, public create_oce_set(oce_set)
...
Calculation of overlap matrix, its derivatives and forces.
Definition qs_overlap.F:19
subroutine, public build_overlap_matrix(ks_env, matrix_s, matrixkp_s, matrix_name, nderivative, basis_type_a, basis_type_b, sab_nl, calculate_forces, matrix_p, matrixkp_p, ext_kpoints)
Calculation of the overlap matrix over Cartesian Gaussian functions.
Definition qs_overlap.F:121
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...
Provides all information about an atomic kind.
represent a blacs multidimensional parallel environment (for the mpi corrispective see cp_paratypes/m...
type of a logger, at the moment it contains just a print level starting at which level it should be l...
Contains all the info needed for KG runs...
stores all the informations relevant to an mpi environment
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.