(git:4cf809f)
Loading...
Searching...
No Matches
hfx_ace_methods.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 Adaptively Compressed Exchange (ACE) operator for HFX.
10!> Reference: Lin, J. Chem. Theory Comput. 2016, 12, 5, 2242-2249
11!>
12!> Algorithm (per spin):
13!>
14!> BUILD (first call, or every rebuild_frequency steps):
15!> 1. Full HFX: ks_matrix = K_HFX + H_core, energy%ex = E_x(full)
16!> 2. K_AO = ks_matrix - H_core (nao x nao, negative semidefinite)
17!> 3. C_occ = first nocc columns of mo_coeff, redistributed to a layout
18!> compatible with K_AO so that PDGEMM works correctly
19!> 4. xi = K_AO * C_occ (nao x nocc)
20!> 5. M = C_occ^T * xi (nocc x nocc, negative definite)
21!> 6. -M = U^T U via Cholesky (U upper triangular, stored in M_fm)
22!> 7. W = xi * U^{-1} (nao x nocc, the ACE projector)
23!> 8. Apply (see below) to update ks_matrix and energy%ex
24!>
25!> APPLY (all other steps):
26!> ks_matrix = H_core - W * W^T
27!> E_x = -0.5 * Tr[W^T * P * W]
28!>
29!> Diagnostics (controlled by DBG_STALE / DBG_EXACT_EX module flags):
30!>
31!> DIAG A projector staleness (cheap, runs every APPLY step)
32!> Computes ||W^T C_occ^current||_F / ||W^T C_occ^BUILD||_F.
33!> Ratio = 1 → W still accurate. Ratio -> 0 → W is stale.
34!>
35!> DIAG B exact vs ACE exchange energy (expensive: one full HFX per APPLY)
36!> Calls full HFX with just_energy=.TRUE. to get E_x^exact[P^k] and
37!> compares to E_x^ACE[P^k]. Growing |delta| confirms stale W.
38!> ACE ks_matrix and energy%ex are restored after the diagnostic.
39!>
40!> \author Ritama Kar
41! **************************************************************************************************
42
44
45 USE admm_types, ONLY: admm_type,&
47 USE bibliography, ONLY: lin2016ace,&
48 cite_reference
51 USE cp_dbcsr_api, ONLY: dbcsr_add,&
56 dbcsr_set,&
67 USE cp_fm_types, ONLY: cp_fm_create,&
76 USE hfx_types, ONLY: hfx_type
78 USE kinds, ONLY: dp
81 USE pw_types, ONLY: pw_r3d_rs_type
85 USE qs_mo_types, ONLY: get_mo_set,&
87 USE qs_rho_types, ONLY: qs_rho_get,&
90#include "./base/base_uses.f90"
91
92 IMPLICIT NONE
93 PRIVATE
94
95 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'hfx_ace_methods'
96
97 ! -----------------------------------------------------------------------
98 ! Module-level state: persists across SCF steps within one run.
99 !
100 ! ace_W(1,ispin) ACE projector W, shape nao x nocc
101 ! ace_is_built .FALSE. until at least one successful BUILD
102 ! ace_step_counter counts calls since last BUILD
103 ! ace_W_ref_norm ||W^T C_occ^BUILD||_F stored at BUILD for DIAG A
104 ! -----------------------------------------------------------------------
105 TYPE(cp_fm_type), ALLOCATABLE, SAVE :: ace_W(:, :)
106 LOGICAL, SAVE :: ace_is_built = .false.
107 INTEGER, SAVE :: ace_step_counter = 0
108 REAL(dp), SAVE :: ace_W_ref_norm = 0.0_dp
109 INTEGER, SAVE :: ace_geo_step = 0 ! NEW
110
111 ! -----------------------------------------------------------------------
112 ! Debug / diagnostic flags — set all .FALSE. for production.
113 !
114 ! DBG_ROUTING BUILD/APPLY/DEFER decisions, counters
115 ! DBG_BUILD norms during BUILD
116 ! DBG_ENERGY E_x(ACE) at every step; DIAG C on BUILD steps
117 ! DBG_STALE DIAG A: staleness ratio at every APPLY step (cheap)
118 ! DBG_EXACT_EX DIAG B: full HFX energy at every APPLY step (expensive)
119 ! -----------------------------------------------------------------------
120 LOGICAL, PARAMETER, PRIVATE :: DBG_ROUTING = .false.
121 LOGICAL, PARAMETER, PRIVATE :: DBG_BUILD = .false.
122 LOGICAL, PARAMETER, PRIVATE :: DBG_ENERGY = .false.
123 LOGICAL, PARAMETER, PRIVATE :: DBG_STALE = .false.
124 LOGICAL, PARAMETER, PRIVATE :: DBG_EXACT_EX = .false.
125
126 LOGICAL, SAVE :: ace_dynamic_mode = .false.
127 ! Set to .TRUE. by hfx_ace_set_dynamic_mode before geo_opt/MD starts.
128 ! Stays .FALSE. for ENERGY/ENERGY_FORCE single-point runs.
129
131
132CONTAINS
133
134! **************************************************************************************************
135!> \brief Main ACE entry point, replacing hfx_ks_matrix in qs_ks_methods.
136!> \param qs_env ...
137!> \param ks_matrix ...
138!> \param rho ...
139!> \param energy ...
140!> \param calculate_forces ...
141!> \param just_energy ...
142!> \param v_rspace_new ...
143!> \param v_tau_rspace ...
144!> \param ace_rebuild_frequency ...
145!> \param ext_xc_section ...
146! **************************************************************************************************
147 SUBROUTINE hfx_ace_ks_matrix(qs_env, ks_matrix, rho, energy, &
148 calculate_forces, just_energy, &
149 v_rspace_new, v_tau_rspace, &
150 ace_rebuild_frequency, ext_xc_section)
151
152 TYPE(qs_environment_type), POINTER :: qs_env
153 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: ks_matrix
154 TYPE(qs_rho_type), POINTER :: rho
155 TYPE(qs_energy_type), POINTER :: energy
156 LOGICAL, INTENT(IN) :: calculate_forces, just_energy
157 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: v_rspace_new, v_tau_rspace
158 INTEGER, INTENT(IN) :: ace_rebuild_frequency
159 TYPE(section_vals_type), OPTIONAL, POINTER :: ext_xc_section
160
161 CHARACTER(LEN=*), PARAMETER :: routinen = 'hfx_ace_ks_matrix'
162
163 INTEGER :: handle, iw, n_rep_hf, nspins, &
164 rebuild_freq
165 LOGICAL :: ace_built_now, rebuild_ace
166 REAL(dp) :: ex_ace
167 TYPE(cp_logger_type), POINTER :: logger
168 TYPE(dft_control_type), POINTER :: dft_control
169 TYPE(hfx_type), DIMENSION(:, :), POINTER :: x_data
170 TYPE(scf_control_type), POINTER :: scf_control
171
172 CALL timeset(routinen, handle)
173
174 CALL cite_reference(lin2016ace)
175 NULLIFY (logger, dft_control, x_data, scf_control)
176
177 logger => cp_get_default_logger()
179
180 CALL get_qs_env(qs_env, x_data=x_data, dft_control=dft_control)
181 n_rep_hf = SIZE(x_data, 1)
182 nspins = dft_control%nspins
183
184 IF (n_rep_hf /= 1) cpabort("ACE: only one &HF section is supported.")
185 IF (dft_control%nimages /= 1) &
186 cpabort("ACE: k-points / multiple images are not implemented.")
187
188 ! ACE requires explicit MO coefficients (C_occ) which are only available
189 ! with diagonalization-based SCF. OT never constructs mo_coeff during
190 ! the SCF, so the ACE projector build loop would silently get garbage.
191 CALL get_qs_env(qs_env, scf_control=scf_control)
192 IF (scf_control%use_ot) &
193 cpabort("ACE: OT doesn't work, use diagonalization-based SCF.")
194
195 rebuild_freq = max(1, ace_rebuild_frequency)
196
197 ! ------------------------------------------------------------------
198 ! Bypass A: energy-only call
199 ! ------------------------------------------------------------------
200 IF (just_energy) THEN
201 IF (dbg_routing .AND. iw > 0) &
202 WRITE (iw, '(T2,A)') 'ACE | just_energy=T: full HFX (no matrix update)'
203 CALL hfx_call(qs_env, ks_matrix, rho, energy, &
204 calculate_forces, just_energy, &
205 v_rspace_new, v_tau_rspace, ext_xc_section)
206 CALL timestop(handle)
207 RETURN
208 END IF
209
210 ! ------------------------------------------------------------------
211 ! Bypass B: ionic forces requested
212 ! ------------------------------------------------------------------
213 IF (calculate_forces) THEN
214 IF (dbg_routing .AND. iw > 0) &
215 WRITE (iw, '(T2,A)') 'ACE | calculate_forces=T: full HFX for exact forces'
216 CALL hfx_call(qs_env, ks_matrix, rho, energy, &
217 calculate_forces, just_energy, &
218 v_rspace_new, v_tau_rspace, ext_xc_section)
219 ace_is_built = .false.
220 ace_step_counter = 0
221 ace_geo_step = ace_geo_step + 1 ! NEW: step 0 done, ACE active from now
222 CALL timestop(handle)
223 RETURN
224 END IF
225
226 ! ------------------------------------------------------------------
227 ! Bypass C: first geometry step.
228 !
229 ! The ATOMIC initial guess gives C_occ far from self-consistency,
230 ! which would produce an inaccurate W. Running full HFX for the
231 ! entire first geometry step ensures that wavefunction extrapolation
232 ! delivers a near-converged C_occ to geometry step 1, making the
233 ! ACE BUILD there accurate from the first application.
234 ! ------------------------------------------------------------------
235 IF (ace_geo_step == 0 .AND. ace_dynamic_mode) THEN
236 IF (iw > 0) WRITE (iw, '(T2,A)') &
237 'ACE | geo_step=0 (MD/GEO_OPT): full HFX for reference wavefunction'
238 CALL hfx_call(qs_env, ks_matrix, rho, energy, &
239 .false., just_energy, &
240 v_rspace_new, v_tau_rspace, ext_xc_section)
241 CALL timestop(handle)
242 RETURN
243 END IF
244
245 ! ------------------------------------------------------------------
246 ! Rebuild decision
247 ! ------------------------------------------------------------------
248 rebuild_ace = (.NOT. ace_is_built) .OR. &
249 (mod(ace_step_counter, rebuild_freq) == 0)
250
251 IF (dbg_routing .AND. iw > 0) THEN
252 WRITE (iw, '(/,T2,A)') repeat('-', 56)
253 WRITE (iw, '(T2,A)') 'ACE | hfx_ace_ks_matrix'
254 WRITE (iw, '(T4,A,L1)') 'ace_is_built = ', ace_is_built
255 WRITE (iw, '(T4,A,L1)') 'rebuild_ace = ', rebuild_ace
256 WRITE (iw, '(T4,A,I6)') 'step_counter = ', ace_step_counter
257 WRITE (iw, '(T4,A,I6)') 'rebuild_freq = ', rebuild_freq
258 WRITE (iw, '(T4,A,I4)') 'nspins = ', nspins
259 WRITE (iw, '(T4,A)') merge('-> BUILD', '-> APPLY', rebuild_ace)
260 WRITE (iw, '(T2,A)') repeat('-', 56)
261 END IF
262
263 IF (rebuild_ace) THEN
264
265 ace_built_now = .false.
266 CALL hfx_ace_build_projector(qs_env, ks_matrix, rho, energy, &
267 just_energy, &
268 v_rspace_new, v_tau_rspace, &
269 nspins, iw, ace_built_now, &
270 ext_xc_section)
271 IF (ace_built_now) THEN
272 ace_is_built = .true.
273 ace_step_counter = 1
274 IF (dbg_routing .AND. iw > 0) &
275 WRITE (iw, '(T4,A)') 'ACE | W built. Projector live from next step.'
276 ELSE
277 ace_is_built = .false.
278 ace_step_counter = 0
279 IF (dbg_routing .AND. iw > 0) &
280 WRITE (iw, '(T4,A)') 'ACE | Build deferred (C_occ=0). Full HFX in ks_matrix.'
281 END IF
282
283 ELSE
284
285 CALL hfx_ace_apply_projector(qs_env, ks_matrix, rho, energy, nspins, iw)
286 ace_step_counter = ace_step_counter + 1
287
288 ! ----------------------------------------------------------------
289 ! DIAGNOSTIC B: compare E_x^ACE[P^k] with E_x^exact[P^k].
290 !
291 ! Calls full HFX (just_energy=.TRUE.) to get the exact exchange
292 ! energy at the current ACE-converging density P^k. Compares
293 ! with E_x^ACE[P^k] already stored in energy%ex.
294 !
295 ! Growing |delta| over the SCF confirms the root cause: W was
296 ! built from C_occ^(step 1), which is far from the converged
297 ! C_occ, so K_ACE = -WW^T no longer represents K_x accurately.
298 !
299 ! After the comparison, hfx_ace_apply_projector is called a
300 ! second time to restore ks_matrix and energy%ex to ACE values
301 ! so the SCF continues correctly. Cost: +2 full HFX per step.
302 ! ----------------------------------------------------------------
303 IF (dbg_exact_ex) THEN
304 ex_ace = energy%ex
305
306 CALL hfx_call(qs_env, ks_matrix, rho, energy, &
307 .false., .true., &
308 v_rspace_new, v_tau_rspace, ext_xc_section)
309 IF (iw > 0) THEN
310 WRITE (iw, '(/,T2,A)') repeat('-', 56)
311 WRITE (iw, '(T2,A,I6)') 'ACE DIAG B | ace_step_counter = ', ace_step_counter
312 WRITE (iw, '(T4,A,F20.10)') 'E_x(exact, P^k) = ', energy%ex
313 WRITE (iw, '(T4,A,F20.10)') 'E_x(ACE, P^k) = ', ex_ace
314 WRITE (iw, '(T4,A,ES12.4)') '|delta| = ', abs(ex_ace - energy%ex)
315 WRITE (iw, '(T4,A)') &
316 '|delta|->0 on BUILD step; growth confirms stale projector'
317 WRITE (iw, '(T2,A)') repeat('-', 56)
318 END IF
319
320 ! Restore ACE ks_matrix and energy%ex
321 CALL hfx_ace_apply_projector(qs_env, ks_matrix, rho, energy, nspins, iw)
322 END IF
323
324 END IF
325
326 IF (dbg_routing .AND. iw > 0) THEN
327 WRITE (iw, '(T4,A,F20.10)') 'energy%ex on exit = ', energy%ex
328 WRITE (iw, '(T4,A,I6)') 'step_counter now = ', ace_step_counter
329 END IF
330
331 CALL timestop(handle)
332
333 END SUBROUTINE hfx_ace_ks_matrix
334
335! **************************************************************************************************
336!> \brief Build the ACE projector W.
337!> \param qs_env ...
338!> \param ks_matrix ...
339!> \param rho ...
340!> \param energy ...
341!> \param just_energy ...
342!> \param v_rspace_new ...
343!> \param v_tau_rspace ...
344!> \param nspins ...
345!> \param iw ...
346!> \param build_succeeded ...
347!> \param ext_xc_section ...
348! **************************************************************************************************
349 SUBROUTINE hfx_ace_build_projector(qs_env, ks_matrix, rho, energy, &
350 just_energy, &
351 v_rspace_new, v_tau_rspace, &
352 nspins, iw, build_succeeded, &
353 ext_xc_section)
354
355 TYPE(qs_environment_type), POINTER :: qs_env
356 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: ks_matrix
357 TYPE(qs_rho_type), POINTER :: rho
358 TYPE(qs_energy_type), POINTER :: energy
359 LOGICAL, INTENT(IN) :: just_energy
360 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: v_rspace_new, v_tau_rspace
361 INTEGER, INTENT(IN) :: nspins, iw
362 LOGICAL, INTENT(OUT) :: build_succeeded
363 TYPE(section_vals_type), OPTIONAL, POINTER :: ext_xc_section
364
365 CHARACTER(LEN=*), PARAMETER :: routinen = 'hfx_ace_build_projector'
366
367 INTEGER :: handle, info_chol, ispin, nao, nmo, nocc
368 LOGICAL :: do_admm
369 REAL(dp) :: ehfx_full, frob
370 REAL(dp), DIMENSION(:), POINTER :: occ_nums
371 TYPE(admm_type), POINTER :: admm_env
372 TYPE(cp_blacs_env_type), POINTER :: blacs_env
373 TYPE(cp_fm_struct_type), POINTER :: fmstruct
374 TYPE(cp_fm_type) :: a_ref_fm, c_occ_fm, k_fm, m_fm, xi_fm
375 TYPE(cp_fm_type), POINTER :: mo_coeff
376 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: ks_aux_fit
377 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_h
378 TYPE(dbcsr_type) :: k_ao_dbcsr
379 TYPE(dft_control_type), POINTER :: dft_control
380 TYPE(mo_set_type), DIMENSION(:), POINTER :: mos, mos_for_ace
381 TYPE(mp_para_env_type), POINTER :: para_env
382
383! A_ref_fm: temporary nocc x nocc scratch for DIAG A reference norm
384
385 CALL timeset(routinen, handle)
386 NULLIFY (blacs_env, para_env, mos, mo_coeff, matrix_h, occ_nums, fmstruct)
387 NULLIFY (dft_control, admm_env, mos_for_ace, ks_aux_fit)
388
389 build_succeeded = .false.
390
391 CALL get_qs_env(qs_env, blacs_env=blacs_env, para_env=para_env, &
392 mos=mos, matrix_h_kp=matrix_h, &
393 dft_control=dft_control)
394
395 do_admm = dft_control%do_admm
396
397 IF (do_admm) THEN
398 CALL get_qs_env(qs_env, admm_env=admm_env)
399 CALL get_admm_env(admm_env, &
400 matrix_ks_aux_fit=ks_aux_fit, &
401 mos_aux_fit=mos_for_ace)
402 ELSE
403 mos_for_ace => mos
404 END IF
405
406 ! Step 1: full HFX
407 CALL hfx_call(qs_env, ks_matrix, rho, energy, &
408 .false., just_energy, &
409 v_rspace_new, v_tau_rspace, ext_xc_section)
410 ehfx_full = energy%ex
411
412 IF (dbg_build .AND. iw > 0) &
413 WRITE (iw, '(/,T2,A,F20.10)') 'ACE BUILD | E_x(full HFX) = ', ehfx_full
414
415 ! Allocate / resize module storage
416 IF (ALLOCATED(ace_w)) THEN
417 IF (SIZE(ace_w, 2) /= nspins) CALL hfx_ace_release()
418 END IF
419 IF (.NOT. ALLOCATED(ace_w)) ALLOCATE (ace_w(1, nspins))
420
421 ! Reset reference norm; accumulated per spin in the loop below
422 ace_w_ref_norm = 0.0_dp
423
424 ! ----------------------------------------------------------------
425 ! Per-spin build loop
426 ! ----------------------------------------------------------------
427 DO ispin = 1, nspins
428
429 IF (mos_for_ace(ispin)%use_mo_coeff_b) &
430 CALL copy_dbcsr_to_fm(mos_for_ace(ispin)%mo_coeff_b, &
431 mos_for_ace(ispin)%mo_coeff)
432
433 CALL get_mo_set(mos_for_ace(ispin), mo_coeff=mo_coeff, &
434 nao=nao, nmo=nmo, homo=nocc, &
435 occupation_numbers=occ_nums)
436
437 IF (nocc <= 0) cpabort("ACE: homo <= 0.")
438 IF (nocc > nmo) cpabort("ACE: homo > nmo.")
439 cpassert(ASSOCIATED(mo_coeff))
440
441 CALL cp_fm_trace(mo_coeff, mo_coeff, frob)
442
443 IF (dbg_build .AND. iw > 0) THEN
444 WRITE (iw, '(/,T2,A,I4)') 'ACE BUILD | ispin = ', ispin
445 WRITE (iw, '(T4,A,I8)') 'nao = ', nao
446 WRITE (iw, '(T4,A,I8)') 'nmo = ', nmo
447 WRITE (iw, '(T4,A,I8)') 'nocc = ', nocc
448 WRITE (iw, '(T4,A,L1)') 'use_mo_coeff_b = ', mos_for_ace(ispin)%use_mo_coeff_b
449 WRITE (iw, '(T4,A,ES12.4)') '||mo_coeff||_F = ', sqrt(max(frob, 0.0_dp))
450 END IF
451
452 IF (frob < 1.0e-20_dp) THEN
453 IF (dbg_build .AND. iw > 0) &
454 WRITE (iw, '(T4,A)') 'mo_coeff=0: build deferred to next step.'
455 CALL timestop(handle)
456 RETURN
457 END IF
458
459 ! Step 2: K_AO
460 IF (do_admm) THEN
461 CALL dbcsr_create(k_ao_dbcsr, template=ks_aux_fit(ispin)%matrix, &
462 name="K_ACE_aux")
463 CALL dbcsr_copy(k_ao_dbcsr, ks_aux_fit(ispin)%matrix)
464 ELSE
465 CALL dbcsr_create(k_ao_dbcsr, template=ks_matrix(ispin, 1)%matrix, &
466 name="K_AO")
467 CALL dbcsr_copy(k_ao_dbcsr, ks_matrix(ispin, 1)%matrix)
468 CALL dbcsr_add(k_ao_dbcsr, matrix_h(1, 1)%matrix, 1.0_dp, -1.0_dp)
469 END IF
470
471 NULLIFY (fmstruct)
472 CALL cp_fm_struct_create(fmstruct, context=blacs_env, para_env=para_env, &
473 nrow_global=nao, ncol_global=nao)
474 CALL cp_fm_create(k_fm, fmstruct, name="K_dense")
475 CALL cp_fm_struct_release(fmstruct)
476 CALL copy_dbcsr_to_fm(k_ao_dbcsr, k_fm)
477 CALL dbcsr_release(k_ao_dbcsr)
478
479 IF (dbg_build .AND. iw > 0) THEN
480 CALL cp_fm_trace(k_fm, k_fm, frob)
481 WRITE (iw, '(T4,A,ES12.4)') '||K_AO||_F = ', sqrt(max(frob, 0.0_dp))
482 END IF
483
484 ! Step 3: C_occ
485 NULLIFY (fmstruct)
486 CALL cp_fm_struct_create(fmstruct, context=blacs_env, para_env=para_env, &
487 nrow_global=nao, ncol_global=nocc)
488 CALL cp_fm_create(c_occ_fm, fmstruct, name="C_occ")
489 CALL cp_fm_create(xi_fm, fmstruct, name="xi")
490 CALL cp_fm_struct_release(fmstruct)
491
492 CALL cp_fm_to_fm(mo_coeff, c_occ_fm)
493
494 ! Step 4: xi = K_AO * C_occ
495 CALL parallel_gemm('N', 'N', nao, nocc, nao, &
496 1.0_dp, k_fm, c_occ_fm, 0.0_dp, xi_fm)
497 CALL cp_fm_release(k_fm)
498
499 IF (dbg_build .AND. iw > 0) THEN
500 CALL cp_fm_trace(xi_fm, xi_fm, frob)
501 WRITE (iw, '(T4,A,ES12.4)') '||xi||_F = ', sqrt(max(frob, 0.0_dp))
502 END IF
503
504 ! Step 5: M = C_occ^T * xi
505 NULLIFY (fmstruct)
506 CALL cp_fm_struct_create(fmstruct, context=blacs_env, para_env=para_env, &
507 nrow_global=nocc, ncol_global=nocc)
508 CALL cp_fm_create(m_fm, fmstruct, name="M")
509 CALL cp_fm_struct_release(fmstruct)
510
511 CALL parallel_gemm('T', 'N', nocc, nocc, nao, &
512 1.0_dp, c_occ_fm, xi_fm, 0.0_dp, m_fm)
513 CALL cp_fm_release(c_occ_fm)
514
515 IF (dbg_build .AND. iw > 0) THEN
516 CALL cp_fm_trace(m_fm, m_fm, frob)
517 WRITE (iw, '(T4,A,ES12.4)') '||M||_F = ', sqrt(max(frob, 0.0_dp))
518 END IF
519
520 ! Step 6: Cholesky of -M = U^T U
521 CALL cp_fm_scale(-1.0_dp, m_fm)
522 CALL cp_fm_cholesky_decompose(m_fm, n=nocc, info_out=info_chol)
523
524 IF (info_chol /= 0) THEN
525 IF (iw > 0) THEN
526 WRITE (iw, '(T4,A,I6)') 'ACE | Cholesky failed, info = ', info_chol
527 WRITE (iw, '(T4,A,F20.10)') 'ACE | E_x(full) = ', ehfx_full
528 WRITE (iw, '(T4,A,I8,A,I8)') 'ACE | nao=', nao, ' nocc=', nocc
529 END IF
530 cpabort("ACE: Cholesky of -M failed (not positive definite).")
531 END IF
532
533 IF (dbg_build .AND. iw > 0) &
534 WRITE (iw, '(T4,A)') 'Cholesky OK (info=0).'
535
536 ! Step 7: W = xi * U^{-1}
537 IF (ASSOCIATED(ace_w(1, ispin)%matrix_struct)) &
538 CALL cp_fm_release(ace_w(1, ispin))
539
540 CALL cp_fm_create(ace_w(1, ispin), xi_fm%matrix_struct, name="W_ACE")
541 CALL cp_fm_to_fm(xi_fm, ace_w(1, ispin))
542
543 CALL cp_fm_triangular_multiply(m_fm, ace_w(1, ispin), &
544 side='R', uplo_tr='U', &
545 transpose_tr=.false., &
546 invert_tr=.true., &
547 n_rows=nao, n_cols=nocc, &
548 alpha=1.0_dp)
549
550 CALL cp_fm_release(xi_fm)
551 CALL cp_fm_release(m_fm)
552
553 IF (dbg_build .AND. iw > 0) THEN
554 CALL cp_fm_trace(ace_w(1, ispin), ace_w(1, ispin), frob)
555 WRITE (iw, '(T4,A,I4,A,2I8,A,ES12.4)') &
556 'W spin=', ispin, ' shape=', nao, nocc, &
557 ' ||W||_F=', sqrt(max(frob, 0.0_dp))
558 END IF
559
560 ! ----------------------------------------------------------------
561 ! DIAG A reference: compute ||W^T C_occ^BUILD||_F for this spin.
562 !
563 ! C_occ_fm was released after step 5, but mo_coeff is still valid
564 ! (it is a pointer into mos_for_ace, not allocated here).
565 ! We re-create C_occ_fm from mo_coeff.
566 !
567 ! Theory: W^T C_occ^BUILD = U^{-T}(-U^T U) = -U → norm = ||U||_F
568 ! (computed directly rather than storing U).
569 ! ----------------------------------------------------------------
570 IF (dbg_stale) THEN
571 NULLIFY (fmstruct)
572 CALL cp_fm_struct_create(fmstruct, context=blacs_env, &
573 para_env=para_env, &
574 nrow_global=nao, ncol_global=nocc)
575 CALL cp_fm_create(c_occ_fm, fmstruct, name="C_occ_ref_diag")
576 CALL cp_fm_struct_release(fmstruct)
577 CALL cp_fm_to_fm(mo_coeff, c_occ_fm)
578
579 NULLIFY (fmstruct)
580 CALL cp_fm_struct_create(fmstruct, context=blacs_env, &
581 para_env=para_env, &
582 nrow_global=nocc, ncol_global=nocc)
583 CALL cp_fm_create(a_ref_fm, fmstruct, name="WtC_ref")
584 CALL cp_fm_struct_release(fmstruct)
585
586 CALL parallel_gemm('T', 'N', nocc, nocc, nao, &
587 1.0_dp, ace_w(1, ispin), c_occ_fm, 0.0_dp, a_ref_fm)
588 CALL cp_fm_trace(a_ref_fm, a_ref_fm, frob)
589 ace_w_ref_norm = ace_w_ref_norm + sqrt(max(frob, 0.0_dp))
590
591 CALL cp_fm_release(c_occ_fm)
592 CALL cp_fm_release(a_ref_fm)
593 END IF
594
595 END DO ! ispin
596
597 IF (dbg_stale .AND. iw > 0) THEN
598 WRITE (iw, '(/,T2,A)') repeat('-', 56)
599 WRITE (iw, '(T2,A)') 'ACE DIAG A | Reference norm stored at BUILD'
600 WRITE (iw, '(T4,A,ES12.4)') &
601 '||W^T C_occ^BUILD||_F (sum over spins) = ', ace_w_ref_norm
602 WRITE (iw, '(T4,A)') &
603 'Staleness ratio = 1.0 at BUILD step; decreasing means W is becoming stale'
604 WRITE (iw, '(T2,A)') repeat('-', 56)
605 END IF
606
607 build_succeeded = .true.
608
609 ! Step 8: apply immediately (DIAG C ratio printed via ehfx_full_ref)
610 CALL hfx_ace_apply_projector(qs_env, ks_matrix, rho, energy, &
611 nspins, iw, ehfx_full_ref=ehfx_full)
612
613 CALL timestop(handle)
614
615 END SUBROUTINE hfx_ace_build_projector
616
617! **************************************************************************************************
618!> \brief Apply the stored ACE projector.
619!> \param qs_env ...
620!> \param ks_matrix ...
621!> \param rho ...
622!> \param energy ...
623!> \param nspins ...
624!> \param iw ...
625!> \param ehfx_full_ref ...
626! **************************************************************************************************
627 SUBROUTINE hfx_ace_apply_projector(qs_env, ks_matrix, rho, energy, &
628 nspins, iw, ehfx_full_ref)
629
630 TYPE(qs_environment_type), POINTER :: qs_env
631 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: ks_matrix
632 TYPE(qs_rho_type), POINTER :: rho
633 TYPE(qs_energy_type), POINTER :: energy
634 INTEGER, INTENT(IN) :: nspins, iw
635 REAL(dp), INTENT(IN), OPTIONAL :: ehfx_full_ref
636
637 CHARACTER(LEN=*), PARAMETER :: routinen = 'hfx_ace_apply_projector'
638
639 INTEGER :: handle, ispin, nao, nao_d, nmo_d, nocc, &
640 nocc_d
641 LOGICAL :: do_admm
642 REAL(dp) :: ehfx_ace, frob_a, stale_norm, trace_val
643 TYPE(admm_type), POINTER :: admm_env
644 TYPE(cp_blacs_env_type), POINTER :: blacs_env
645 TYPE(cp_fm_struct_type), POINTER :: fmstruct, fmstruct_diag
646 TYPE(cp_fm_type) :: a_diag_fm, c_occ_diag, p_fm, pw_fm
647 TYPE(cp_fm_type), POINTER :: mo_coeff_diag
648 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: ks_aux_fit, ks_aux_fit_hfx
649 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_h, rho_ao
650 TYPE(dft_control_type), POINTER :: dft_control
651 TYPE(mo_set_type), DIMENSION(:), POINTER :: mos_aux_diag, mos_diag
652 TYPE(mp_para_env_type), POINTER :: para_env
653 TYPE(qs_rho_type), POINTER :: rho_aux_fit
654
655! ------------------------------------------------------------------
656! DIAG A local variables
657! stale_norm ||W^T C_occ^current||_F summed over spins
658! frob_A scratch for cp_fm_trace
659! C_occ_diag current C_occ redistributed to W layout
660! A_diag_fm nocc x nocc overlap W^T C_occ^current
661! mos_diag primary mos (non-ADMM path)
662! mos_aux_diag auxiliary mos (ADMM path)
663! mo_coeff_diag pointer to the relevant mo_coeff
664! nao_d, nmo_d, nocc_d dimensions from get_mo_set
665! ------------------------------------------------------------------
666
667 CALL timeset(routinen, handle)
668 NULLIFY (blacs_env, para_env, matrix_h, rho_ao, fmstruct)
669 NULLIFY (dft_control, admm_env, ks_aux_fit, ks_aux_fit_hfx, rho_aux_fit)
670 NULLIFY (mos_diag, mos_aux_diag, mo_coeff_diag, fmstruct_diag)
671 cpassert(ALLOCATED(ace_w))
672
673 CALL get_qs_env(qs_env, blacs_env=blacs_env, para_env=para_env, &
674 matrix_h_kp=matrix_h, dft_control=dft_control)
675 do_admm = dft_control%do_admm
676
677 IF (do_admm) THEN
678 CALL get_qs_env(qs_env, admm_env=admm_env)
679 CALL get_admm_env(admm_env, &
680 matrix_ks_aux_fit=ks_aux_fit, &
681 matrix_ks_aux_fit_hfx=ks_aux_fit_hfx, &
682 rho_aux_fit=rho_aux_fit)
683 CALL qs_rho_get(rho_aux_fit, rho_ao_kp=rho_ao)
684 ELSE
685 CALL qs_rho_get(rho, rho_ao_kp=rho_ao)
686 END IF
687
688 DO ispin = 1, nspins
689 CALL cp_fm_get_info(ace_w(1, ispin), nrow_global=nao, ncol_global=nocc)
690
691 IF (do_admm) THEN
692 CALL dbcsr_set(ks_matrix(ispin, 1)%matrix, 0.0_dp)
693 CALL dbcsr_add(ks_matrix(ispin, 1)%matrix, &
694 matrix_h(1, 1)%matrix, 1.0_dp, 1.0_dp)
695 CALL dbcsr_set(ks_aux_fit(ispin)%matrix, 0.0_dp)
697 sparse_matrix=ks_aux_fit(ispin)%matrix, &
698 matrix_v=ace_w(1, ispin), &
699 ncol=nocc, &
700 alpha=-1.0_dp, &
701 keep_sparsity=.true.)
702 CALL dbcsr_add(ks_aux_fit_hfx(ispin)%matrix, &
703 ks_aux_fit(ispin)%matrix, 0.0_dp, 1.0_dp)
704 ELSE
705 CALL dbcsr_set(ks_matrix(ispin, 1)%matrix, 0.0_dp)
707 sparse_matrix=ks_matrix(ispin, 1)%matrix, &
708 matrix_v=ace_w(1, ispin), &
709 ncol=nocc, &
710 alpha=-1.0_dp, &
711 keep_sparsity=.true.)
712 CALL dbcsr_add(ks_matrix(ispin, 1)%matrix, &
713 matrix_h(1, 1)%matrix, 1.0_dp, 1.0_dp)
714 END IF
715 END DO
716
717 ! Exchange energy: E_x = -0.5 * sum_spin Tr[ W^T * P * W ]
718 ehfx_ace = 0.0_dp
719 DO ispin = 1, nspins
720 CALL cp_fm_get_info(ace_w(1, ispin), nrow_global=nao, ncol_global=nocc)
721
722 NULLIFY (fmstruct)
723 CALL cp_fm_struct_create(fmstruct, context=blacs_env, para_env=para_env, &
724 nrow_global=nao, ncol_global=nao)
725 CALL cp_fm_create(p_fm, fmstruct, name="P_dense")
726 CALL cp_fm_struct_release(fmstruct)
727 CALL copy_dbcsr_to_fm(rho_ao(ispin, 1)%matrix, p_fm)
728
729 CALL cp_fm_create(pw_fm, ace_w(1, ispin)%matrix_struct, name="PW")
730 CALL parallel_gemm('N', 'N', nao, nocc, nao, &
731 1.0_dp, p_fm, ace_w(1, ispin), 0.0_dp, pw_fm)
732 CALL cp_fm_trace(ace_w(1, ispin), pw_fm, trace_val)
733 ehfx_ace = ehfx_ace - 0.5_dp*trace_val
734
735 CALL cp_fm_release(p_fm)
736 CALL cp_fm_release(pw_fm)
737
738 IF (dbg_energy .AND. iw > 0) &
739 WRITE (iw, '(T4,A,I4,A,F20.10)') &
740 'ispin=', ispin, ' E_x(ACE) += ', -0.5_dp*trace_val
741 END DO
742
743 energy%ex = ehfx_ace
744
745 ! DIAG C: BUILD-step consistency check (printed when ehfx_full_ref present)
746 IF (dbg_energy .AND. iw > 0) THEN
747 WRITE (iw, '(T2,A,F20.10)') 'ACE | E_x(ACE) = ', ehfx_ace
748 IF (PRESENT(ehfx_full_ref)) THEN
749 WRITE (iw, '(T2,A,F20.10)') 'ACE | E_x(full) = ', ehfx_full_ref
750 WRITE (iw, '(T2,A,ES12.4)') 'ACE | |delta| = ', abs(ehfx_ace - ehfx_full_ref)
751 WRITE (iw, '(T2,A)') '(|delta| should be ~0 on BUILD steps; small is good)'
752 END IF
753 END IF
754
755 ! ----------------------------------------------------------------
756 ! DIAG A: projector staleness check.
757 !
758 ! Computes ||W^T C_occ^current||_F (summed over spins) and divides
759 ! by ace_W_ref_norm = ||W^T C_occ^BUILD||_F stored at BUILD time.
760 !
761 ! staleness_ratio:
762 ! 1.0 → C_occ hasn't changed since BUILD; projector is fresh
763 ! < 1 → C_occ has rotated; how much depends on the SCF dynamics
764 ! → 0 → C_occ is orthogonal to the BUILD-time span; W is useless
765 !
766 ! For non-ADMM: C_occ comes from primary mos (nao_orb x nocc).
767 ! For ADMM: C_occ comes from mos_aux_fit (nao_aux x nocc_aux),
768 ! consistent with ace_W dimensions.
769 ! ----------------------------------------------------------------
770 IF (dbg_stale .AND. ace_w_ref_norm > 0.0_dp) THEN
771 stale_norm = 0.0_dp
772 CALL get_qs_env(qs_env, mos=mos_diag)
773
774 DO ispin = 1, nspins
775 CALL cp_fm_get_info(ace_w(1, ispin), nrow_global=nao_d, ncol_global=nocc_d)
776
777 IF (do_admm) THEN
778 CALL get_admm_env(admm_env, mos_aux_fit=mos_aux_diag)
779 IF (mos_aux_diag(ispin)%use_mo_coeff_b) &
780 CALL copy_dbcsr_to_fm(mos_aux_diag(ispin)%mo_coeff_b, &
781 mos_aux_diag(ispin)%mo_coeff)
782 CALL get_mo_set(mos_aux_diag(ispin), mo_coeff=mo_coeff_diag, &
783 nao=nao_d, nmo=nmo_d, homo=nocc_d)
784 ELSE
785 IF (mos_diag(ispin)%use_mo_coeff_b) &
786 CALL copy_dbcsr_to_fm(mos_diag(ispin)%mo_coeff_b, &
787 mos_diag(ispin)%mo_coeff)
788 CALL get_mo_set(mos_diag(ispin), mo_coeff=mo_coeff_diag, &
789 nao=nao_d, nmo=nmo_d, homo=nocc_d)
790 END IF
791
792 NULLIFY (fmstruct_diag)
793 CALL cp_fm_struct_create(fmstruct_diag, context=blacs_env, &
794 para_env=para_env, &
795 nrow_global=nao_d, ncol_global=nocc_d)
796 CALL cp_fm_create(c_occ_diag, fmstruct_diag, name="C_stale")
797 CALL cp_fm_struct_release(fmstruct_diag)
798 CALL cp_fm_to_fm(mo_coeff_diag, c_occ_diag)
799
800 NULLIFY (fmstruct_diag)
801 CALL cp_fm_struct_create(fmstruct_diag, context=blacs_env, &
802 para_env=para_env, &
803 nrow_global=nocc_d, ncol_global=nocc_d)
804 CALL cp_fm_create(a_diag_fm, fmstruct_diag, name="WtC_stale")
805 CALL cp_fm_struct_release(fmstruct_diag)
806
807 CALL parallel_gemm('T', 'N', nocc_d, nocc_d, nao_d, &
808 1.0_dp, ace_w(1, ispin), c_occ_diag, 0.0_dp, a_diag_fm)
809 CALL cp_fm_trace(a_diag_fm, a_diag_fm, frob_a)
810 stale_norm = stale_norm + sqrt(max(frob_a, 0.0_dp))
811
812 CALL cp_fm_release(c_occ_diag)
813 CALL cp_fm_release(a_diag_fm)
814 END DO
815 IF (iw > 0) THEN
816 WRITE (iw, '(/,T2,A)') repeat('-', 56)
817 WRITE (iw, '(T2,A,I6)') 'ACE DIAG A | ace_step_counter = ', ace_step_counter
818 WRITE (iw, '(T4,A,ES12.4)') '||W^T C_occ^current||_F = ', stale_norm
819 WRITE (iw, '(T4,A,ES12.4)') '||W^T C_occ^BUILD||_F (ref) = ', ace_w_ref_norm
820 WRITE (iw, '(T4,A,F10.6)') 'staleness ratio (1=fresh, 0=stale) = ', &
821 stale_norm/max(ace_w_ref_norm, 1.0e-30_dp)
822 WRITE (iw, '(T2,A)') repeat('-', 56)
823 END IF
824 END IF
825
826 CALL timestop(handle)
827
828 END SUBROUTINE hfx_ace_apply_projector
829
830! **************************************************************************************************
831!> \brief Release all ACE storage and reset state flags.
832!> \param iw_opt ...
833! **************************************************************************************************
834 SUBROUTINE hfx_ace_release(iw_opt)
835
836 INTEGER, INTENT(IN), OPTIONAL :: iw_opt
837
838 INTEGER :: i, iw, j
839
840 iw = -1
841 IF (PRESENT(iw_opt)) iw = iw_opt
842
843 IF (ALLOCATED(ace_w)) THEN
844 DO j = 1, SIZE(ace_w, 2)
845 DO i = 1, SIZE(ace_w, 1)
846 IF (ASSOCIATED(ace_w(i, j)%matrix_struct)) CALL cp_fm_release(ace_w(i, j))
847 END DO
848 END DO
849 DEALLOCATE (ace_w)
850 END IF
851
852 ace_is_built = .false.
853 ace_step_counter = 0
854 ace_w_ref_norm = 0.0_dp
855 ace_geo_step = 0
856 ace_dynamic_mode = .false. ! ADDED: reset dynamic mode on release, so it must be explicitly re-enabled for GEO_OPT/MD runs
857
858 IF (iw > 0) WRITE (iw, '(T2,A)') 'ACE | storage released, counters reset'
859
860 END SUBROUTINE hfx_ace_release
861
862 ! **************************************************************************************************
863 !> \brief Mark this run as dynamic (GEO_OPT/MD) so Bypass C fires for geo step 0.
864 !> Call this once from the geo_opt or MD driver before the first SCF.
865 !> \param is_dynamic .TRUE. for GEO_OPT/MD, .FALSE. to reset.
866 ! **************************************************************************************************
867! **************************************************************************************************
868!> \brief ...
869!> \param is_dynamic ...
870! **************************************************************************************************
871 SUBROUTINE hfx_ace_set_dynamic_mode(is_dynamic)
872 LOGICAL, INTENT(IN) :: is_dynamic
873
874 ace_dynamic_mode = is_dynamic
875 END SUBROUTINE hfx_ace_set_dynamic_mode
876
877 ! **************************************************************************************************
878 !> \brief Private helper: call hfx_ks_matrix with or without ext_xc_section.
879 !> \param qs_env ...
880 !> \param ks_matrix ...
881 !> \param rho ...
882 !> \param energy ...
883 !> \param calculate_forces ...
884 !> \param just_energy ...
885 !> \param v_rspace_new ...
886 !> \param v_tau_rspace ...
887 !> \param ext_xc_section ...
888 ! **************************************************************************************************
889! **************************************************************************************************
890!> \brief ...
891!> \param qs_env ...
892!> \param ks_matrix ...
893!> \param rho ...
894!> \param energy ...
895!> \param calculate_forces ...
896!> \param just_energy ...
897!> \param v_rspace_new ...
898!> \param v_tau_rspace ...
899!> \param ext_xc_section ...
900! **************************************************************************************************
901 SUBROUTINE hfx_call(qs_env, ks_matrix, rho, energy, &
902 calculate_forces, just_energy, &
903 v_rspace_new, v_tau_rspace, ext_xc_section)
904
905 TYPE(qs_environment_type), POINTER :: qs_env
906 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: ks_matrix
907 TYPE(qs_rho_type), POINTER :: rho
908 TYPE(qs_energy_type), POINTER :: energy
909 LOGICAL, INTENT(IN) :: calculate_forces, just_energy
910 TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: v_rspace_new, v_tau_rspace
911 TYPE(section_vals_type), OPTIONAL, POINTER :: ext_xc_section
912
913 IF (PRESENT(ext_xc_section)) THEN
914 CALL hfx_ks_matrix(qs_env, ks_matrix, rho, energy, &
915 calculate_forces, just_energy, &
916 v_rspace_new, v_tau_rspace, &
917 ext_xc_section=ext_xc_section)
918 ELSE
919 CALL hfx_ks_matrix(qs_env, ks_matrix, rho, energy, &
920 calculate_forces, just_energy, &
921 v_rspace_new, v_tau_rspace)
922 END IF
923
924 END SUBROUTINE hfx_call
925
926END MODULE hfx_ace_methods
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
collects all references to literature in CP2K as new algorithms / method are included from literature...
integer, save, public lin2016ace
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_release(matrix)
...
subroutine, public dbcsr_add(matrix_a, matrix_b, alpha_scalar, beta_scalar)
...
DBCSR operations in CP2K.
subroutine, public copy_dbcsr_to_fm(matrix, fm)
Copy a DBCSR matrix to a BLACS matrix.
subroutine, public cp_dbcsr_plus_fm_fm_t(sparse_matrix, matrix_v, matrix_g, ncol, alpha, keep_sparsity, symmetry_mode)
performs the multiplication sparse_matrix+dense_mat*dens_mat^T if matrix_g is not explicitly given,...
Basic linear algebra operations for full matrices.
subroutine, public cp_fm_scale(alpha, matrix_a)
scales a matrix matrix_a = alpha * matrix_b
subroutine, public cp_fm_triangular_multiply(triangular_matrix, matrix_b, side, transpose_tr, invert_tr, uplo_tr, unit_diag_tr, n_rows, n_cols, alpha)
multiplies in place by a triangular matrix: matrix_b = alpha op(triangular_matrix) matrix_b or (if si...
various cholesky decomposition related routines
subroutine, public cp_fm_cholesky_decompose(matrix, n, info_out)
used to replace a symmetric positive def. matrix M with its cholesky decomposition U: M = U^T * U,...
represent the structure of a full matrix
subroutine, public cp_fm_struct_create(fmstruct, para_env, context, nrow_global, ncol_global, nrow_block, ncol_block, descriptor, first_p_pos, local_leading_dimension, template_fmstruct, square_blocks, force_block)
allocates and initializes a full matrix structure
subroutine, public cp_fm_struct_release(fmstruct)
releases a full matrix structure
represent a full matrix distributed on many processors
Definition cp_fm_types.F:15
subroutine, public cp_fm_get_info(matrix, name, nrow_global, ncol_global, nrow_block, ncol_block, nrow_local, ncol_local, row_indices, col_indices, local_data, context, nrow_locals, ncol_locals, matrix_struct, para_env)
returns all kind of information about the full matrix
subroutine, public cp_fm_create(matrix, matrix_struct, name, use_sp, nrow, ncol, set_zero)
creates a new full matrix with the given structure
various routines to log and control the output. The idea is that decisions about where to log should ...
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
Adaptively Compressed Exchange (ACE) operator for HFX. Reference: Lin, J. Chem. Theory Comput....
subroutine, public hfx_ace_set_dynamic_mode(is_dynamic)
Mark this run as dynamic (GEO_OPT/MD) so Bypass C fires for geo step 0. Call this once from the geo_o...
subroutine, public hfx_ace_release(iw_opt)
Release all ACE storage and reset state flags.
subroutine, public hfx_ace_ks_matrix(qs_env, ks_matrix, rho, energy, calculate_forces, just_energy, v_rspace_new, v_tau_rspace, ace_rebuild_frequency, ext_xc_section)
Main ACE entry point, replacing hfx_ks_matrix in qs_ks_methods.
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, ext_xc_section)
Add the hfx contributions to the Hamiltonian.
Types and set/get functions for HFX.
Definition hfx_types.F:15
objects that represent the structure of input sections and the data contained in an input section
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
Interface to the message passing library MPI.
basic linear algebra operations for full matrixes
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, 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.
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.
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...
parameters that control an scf iteration
stores some data used in wavefunction fitting
Definition admm_types.F:120
represent a blacs multidimensional parallel environment (for the mpi corrispective see cp_paratypes/m...
keeps the information about the structure of a full matrix
represent a full matrix
type of a logger, at the moment it contains just a print level starting at which level it should be l...
stores some data used in construction of Kohn-Sham matrix
Definition hfx_types.F:511
stores all the informations relevant to an mpi environment
keeps the density in various representations, keeping track of which ones are valid.