(git:a145afa)
Loading...
Searching...
No Matches
qs_scf_initialization.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 Utility routines for qs_scf
10! **************************************************************************************************
15 USE cp_dbcsr_api, ONLY: dbcsr_create,&
19 dbcsr_type_no_symmetry
34 diag_type,&
42 USE cp_fm_types, ONLY: cp_fm_create,&
52 USE cp_output_handling, ONLY: cp_p_file,&
57 USE input_constants, ONLY: &
66 USE kinds, ONLY: dp
67 USE kpoint_types, ONLY: kpoint_type
71 USE pw_types, ONLY: pw_c1d_gs_type
93 USE qs_kind_types, ONLY: get_qs_kind,&
102 USE qs_mo_types, ONLY: get_mo_set,&
112 USE qs_rho_types, ONLY: qs_rho_create,&
113 qs_rho_get,&
119 USE qs_scf_types, ONLY: &
131#include "./base/base_uses.f90"
132
133 IMPLICIT NONE
134
135 PRIVATE
136
137 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_scf_initialization'
138
140
141CONTAINS
142
143! **************************************************************************************************
144!> \brief initializes input parameters if needed or restores values from
145!> previous runs to fill scf_env with the values required for scf
146!> \param qs_env the qs_environment where to perform the scf procedure
147!> \param scf_env ...
148!> \param scf_control ...
149!> \param scf_section ...
150! **************************************************************************************************
151 SUBROUTINE qs_scf_env_initialize(qs_env, scf_env, scf_control, scf_section)
152 TYPE(qs_environment_type), POINTER :: qs_env
153 TYPE(qs_scf_env_type), POINTER :: scf_env
154 TYPE(scf_control_type), OPTIONAL, POINTER :: scf_control
155 TYPE(section_vals_type), OPTIONAL, POINTER :: scf_section
156
157 INTEGER :: ip, np
158 TYPE(atomic_kind_type), POINTER :: atomic_kind_set(:)
159 TYPE(dft_control_type), POINTER :: dft_control
160 TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
161 TYPE(particle_type), POINTER :: particle_set(:)
162 TYPE(qs_kind_type), POINTER :: qs_kind_set(:)
163 TYPE(scf_control_type), POINTER :: my_scf_control
164 TYPE(section_vals_type), POINTER :: dft_section, input, my_scf_section
165
166 CALL get_qs_env(qs_env, input=input, dft_control=dft_control)
167
168 !Initialize Hairy Probe calculation
169 IF (dft_control%hairy_probes .EQV. .true.) THEN
170 CALL get_qs_env(qs_env, &
171 mos=mos, &
172 atomic_kind_set=atomic_kind_set, &
173 qs_kind_set=qs_kind_set, &
174 particle_set=particle_set)
175 np = SIZE(dft_control%probe)
176 DO ip = 1, np
177 CALL ao_boundaries(probe=dft_control%probe(ip), atomic_kind_set=atomic_kind_set, qs_kind_set=qs_kind_set, &
178 particle_set=particle_set, nao=mos(1)%nao) !FIX THIS!
179 END DO
180 END IF
181
182 IF (PRESENT(scf_control)) THEN
183 my_scf_control => scf_control
184 ELSE
185 CALL get_qs_env(qs_env, scf_control=my_scf_control)
186 END IF
187
188 dft_section => section_vals_get_subs_vals(input, "DFT")
189 IF (PRESENT(scf_section)) THEN
190 my_scf_section => scf_section
191 ELSE
192 my_scf_section => section_vals_get_subs_vals(dft_section, "SCF")
193 END IF
194
195 CALL qs_scf_ensure_scf_env(qs_env, scf_env)
196
197 CALL section_vals_val_get(my_scf_section, "CHOLESKY", i_val=scf_env%cholesky_method)
198
199 CALL qs_scf_ensure_mos(qs_env)
200
201 ! set flags for diagonalization
202 CALL qs_scf_ensure_diagonalization(scf_env, my_scf_section, qs_env, &
203 my_scf_control, qs_env%has_unit_metric)
204 ! set parameters for mixing/DIIS during scf
205 CALL qs_scf_ensure_mixing(my_scf_control, my_scf_section, scf_env, dft_control)
206
207 CALL qs_scf_ensure_work_matrices(qs_env, scf_env)
208
209 CALL qs_scf_ensure_mixing_store(qs_env, scf_env)
210
211 ! Initialize outer loop variables: handle CDFT and regular outer loop separately
212 IF (dft_control%qs_control%cdft) THEN
213 CALL qs_scf_ensure_cdft_loop_vars(qs_env, scf_env, dft_control, &
214 scf_control=my_scf_control)
215 ELSE
216 CALL qs_scf_ensure_outer_loop_vars(scf_env, my_scf_control)
217 END IF
218
219 CALL init_scf_run(scf_env, qs_env, my_scf_section, my_scf_control)
220
221 END SUBROUTINE qs_scf_env_initialize
222
223! **************************************************************************************************
224!> \brief initializes input parameters if needed for non-scf calclulations using diagonalization
225!> \param qs_env the qs_environment where to perform the scf procedure
226!> \param scf_env ...
227! **************************************************************************************************
228 SUBROUTINE qs_scf_env_init_basic(qs_env, scf_env)
229 TYPE(qs_environment_type), POINTER :: qs_env
230 TYPE(qs_scf_env_type), POINTER :: scf_env
231
232 TYPE(dft_control_type), POINTER :: dft_control
233 TYPE(scf_control_type), POINTER :: scf_control
234 TYPE(section_vals_type), POINTER :: dft_section, input, scf_section
235
236 CALL get_qs_env(qs_env, input=input, dft_control=dft_control)
237
238 CALL get_qs_env(qs_env, scf_control=scf_control)
239 dft_section => section_vals_get_subs_vals(input, "DFT")
240 scf_section => section_vals_get_subs_vals(dft_section, "SCF")
241
242 CALL qs_scf_ensure_scf_env(qs_env, scf_env)
243
244 CALL section_vals_val_get(scf_section, "CHOLESKY", i_val=scf_env%cholesky_method)
245 scf_control%use_diag = .true.
246 scf_control%diagonalization%method = diag_standard
247
248 CALL qs_scf_ensure_mos(qs_env)
249
250 ! set flags for diagonalization
251 CALL qs_scf_ensure_diagonalization(scf_env, scf_section, qs_env, &
252 scf_control, qs_env%has_unit_metric)
253 CALL qs_scf_ensure_work_matrices(qs_env, scf_env)
254
255 CALL init_scf_run(scf_env, qs_env, scf_section, scf_control)
256
257 END SUBROUTINE qs_scf_env_init_basic
258
259! **************************************************************************************************
260!> \brief makes sure scf_env is allocated (might already be from before)
261!> in case it is present the g-space mixing storage is reset
262!> \param qs_env ...
263!> \param scf_env ...
264! **************************************************************************************************
265 SUBROUTINE qs_scf_ensure_scf_env(qs_env, scf_env)
266 TYPE(qs_environment_type), POINTER :: qs_env
267 TYPE(qs_scf_env_type), POINTER :: scf_env
268
269 TYPE(pw_c1d_gs_type), DIMENSION(:), POINTER :: rho_g
270 TYPE(qs_rho_type), POINTER :: rho
271
272 NULLIFY (rho_g)
273
274 IF (.NOT. ASSOCIATED(scf_env)) THEN ! i.e. for MD this is associated on the second step (it so seems)
275 ALLOCATE (scf_env)
276 CALL scf_env_create(scf_env)
277 ELSE
278 ! Reallocate mixing store, if the g space grid (cell) has changed
279 SELECT CASE (scf_env%mixing_method)
281 IF (ASSOCIATED(scf_env%mixing_store)) THEN
282 ! The current mixing_store data structure does not allow for an unique
283 ! grid comparison, but the probability that the 1d lengths of the old and
284 ! the new grid are accidentily equal is rather low
285 CALL get_qs_env(qs_env, rho=rho)
286 CALL qs_rho_get(rho, rho_g=rho_g)
287 IF (ASSOCIATED(scf_env%mixing_store%rhoin)) THEN
288 IF (SIZE(rho_g(1)%pw_grid%gsq) /= SIZE(scf_env%mixing_store%rhoin(1)%cc)) THEN
289 CALL mixing_storage_release(scf_env%mixing_store)
290 DEALLOCATE (scf_env%mixing_store)
291 END IF
292 END IF
293 END IF
294 END SELECT
295 END IF
296
297 END SUBROUTINE qs_scf_ensure_scf_env
298
299! **************************************************************************************************
300!> \brief performs allocation of outer SCF variables
301!> \param scf_env the SCF environment which contains the outer SCF variables
302!> \param scf_control control settings for the outer SCF loop
303!> \param nvar (optional) set number of outer SCF variables externally if CDFT SCF is active
304! **************************************************************************************************
305 SUBROUTINE qs_scf_ensure_outer_loop_vars(scf_env, scf_control, nvar)
306 TYPE(qs_scf_env_type), POINTER :: scf_env
307 TYPE(scf_control_type), POINTER :: scf_control
308 INTEGER, OPTIONAL :: nvar
309
310 INTEGER :: nhistory, nvariables
311
312 IF (scf_control%outer_scf%have_scf) THEN
313 nhistory = scf_control%outer_scf%max_scf + 1
314 IF (PRESENT(nvar)) THEN
315 IF (nvar > 0) THEN
316 nvariables = nvar
317 ELSE
318 nvariables = outer_loop_variables_count(scf_control)
319 END IF
320 ELSE
321 nvariables = outer_loop_variables_count(scf_control)
322 END IF
323 ALLOCATE (scf_env%outer_scf%variables(nvariables, nhistory))
324 ALLOCATE (scf_env%outer_scf%count(nhistory))
325 scf_env%outer_scf%count = 0
326 ALLOCATE (scf_env%outer_scf%gradient(nvariables, nhistory))
327 ALLOCATE (scf_env%outer_scf%energy(nhistory))
328 END IF
329
330 END SUBROUTINE qs_scf_ensure_outer_loop_vars
331
332! **************************************************************************************************
333!> \brief performs allocation of CDFT SCF variables
334!> \param qs_env the qs_env where to perform the allocation
335!> \param scf_env the currently active scf_env
336!> \param dft_control the dft_control that holds the cdft_control type
337!> \param scf_control the currently active scf_control
338! **************************************************************************************************
339 SUBROUTINE qs_scf_ensure_cdft_loop_vars(qs_env, scf_env, dft_control, scf_control)
340 TYPE(qs_environment_type), POINTER :: qs_env
341 TYPE(qs_scf_env_type), POINTER :: scf_env
342 TYPE(dft_control_type), POINTER :: dft_control
343 TYPE(scf_control_type), POINTER :: scf_control
344
345 INTEGER :: nhistory, nvariables
346 LOGICAL :: do_kpoints
347 REAL(kind=dp), DIMENSION(:, :), POINTER :: gradient_history, outer_scf_history, &
348 variable_history
349
350 NULLIFY (outer_scf_history, gradient_history, variable_history)
351 CALL get_qs_env(qs_env=qs_env, do_kpoints=do_kpoints)
352 ! Test kpoints
353 IF (do_kpoints) THEN
354 cpabort("CDFT calculation not possible with kpoints")
355 END IF
356 ! Check that OUTER_SCF section in DFT&SCF is active
357 ! This section must always be active to facilitate
358 ! switching of the CDFT and SCF control parameters in outer_loop_switch
359 IF (.NOT. scf_control%outer_scf%have_scf) THEN
360 cpabort("Section SCF&OUTER_SCF must be active for CDFT calculations.")
361 END IF
362 ! Initialize CDFT and outer_loop variables (constraint settings active in scf_control)
363 IF (dft_control%qs_control%cdft_control%constraint_control%have_scf) THEN
364 nhistory = dft_control%qs_control%cdft_control%constraint_control%max_scf + 1
365 IF (scf_control%outer_scf%type /= outer_scf_none) THEN
366 nvariables = outer_loop_variables_count(scf_control, &
367 dft_control%qs_control%cdft_control)
368 ELSE
369 ! First iteration: scf_control has not yet been updated
370 nvariables = SIZE(dft_control%qs_control%cdft_control%target)
371 END IF
372 ALLOCATE (dft_control%qs_control%cdft_control%constraint%variables(nvariables, nhistory))
373 ALLOCATE (dft_control%qs_control%cdft_control%constraint%count(nhistory))
374 dft_control%qs_control%cdft_control%constraint%count = 0
375 ALLOCATE (dft_control%qs_control%cdft_control%constraint%gradient(nvariables, nhistory))
376 ALLOCATE (dft_control%qs_control%cdft_control%constraint%energy(nhistory))
377 CALL qs_scf_ensure_outer_loop_vars(scf_env, scf_control, nvariables)
378 END IF
379 ! Executed only on first call (OT settings active in scf_control)
380 ! Save OT settings and constraint initial values in CDFT control
381 ! Then switch to constraint outer_scf settings for proper initialization of history
382 IF (scf_control%outer_scf%have_scf) THEN
383 IF (scf_control%outer_scf%type == outer_scf_none) THEN
384 dft_control%qs_control%cdft_control%ot_control%have_scf = .true.
385 dft_control%qs_control%cdft_control%ot_control%max_scf = scf_control%outer_scf%max_scf
386 dft_control%qs_control%cdft_control%ot_control%eps_scf = scf_control%outer_scf%eps_scf
387 dft_control%qs_control%cdft_control%ot_control%step_size = scf_control%outer_scf%step_size
388 dft_control%qs_control%cdft_control%ot_control%type = scf_control%outer_scf%type
389 dft_control%qs_control%cdft_control%ot_control%optimizer = scf_control%outer_scf%optimizer
390 dft_control%qs_control%cdft_control%ot_control%diis_buffer_length = scf_control%outer_scf%diis_buffer_length
391 dft_control%qs_control%cdft_control%ot_control%bisect_trust_count = scf_control%outer_scf%bisect_trust_count
392 CALL cdft_opt_type_copy(dft_control%qs_control%cdft_control%ot_control%cdft_opt_control, &
393 scf_control%outer_scf%cdft_opt_control)
394 ! In case constraint and OT extrapolation orders are different, make sure to use former
395 nvariables = SIZE(dft_control%qs_control%cdft_control%target)
396 IF (scf_control%outer_scf%extrapolation_order /= &
397 dft_control%qs_control%cdft_control%constraint_control%extrapolation_order &
398 .OR. nvariables /= 1) THEN
399 DEALLOCATE (qs_env%outer_scf_history)
400 DEALLOCATE (qs_env%gradient_history)
401 DEALLOCATE (qs_env%variable_history)
402 nhistory = dft_control%qs_control%cdft_control%constraint_control%extrapolation_order
403 ALLOCATE (outer_scf_history(nvariables, nhistory))
404 ALLOCATE (gradient_history(nvariables, 2))
405 gradient_history = 0.0_dp
406 ALLOCATE (variable_history(nvariables, 2))
407 variable_history = 0.0_dp
408 CALL set_qs_env(qs_env, outer_scf_history=outer_scf_history, &
409 gradient_history=gradient_history, variable_history=variable_history)
410 END IF
411 CALL outer_loop_switch(scf_env, scf_control, dft_control%qs_control%cdft_control, ot2cdft)
412 END IF
413 END IF
414
415 END SUBROUTINE qs_scf_ensure_cdft_loop_vars
416
417! **************************************************************************************************
418!> \brief performs allocation of the mixing storage
419!> \param qs_env ...
420!> \param scf_env ...
421! **************************************************************************************************
422 SUBROUTINE qs_scf_ensure_mixing_store(qs_env, scf_env)
423 TYPE(qs_environment_type), POINTER :: qs_env
424 TYPE(qs_scf_env_type), POINTER :: scf_env
425
426 TYPE(dft_control_type), POINTER :: dft_control
427
428 NULLIFY (dft_control)
429 CALL get_qs_env(qs_env=qs_env, dft_control=dft_control)
430
431 IF (scf_env%mixing_method > 0) THEN
432 CALL mixing_allocate(qs_env, scf_env%mixing_method, scf_env%p_mix_new, &
433 scf_env%p_delta, dft_control%nspins, &
434 scf_env%mixing_store)
435 ELSE
436 NULLIFY (scf_env%p_mix_new)
437 END IF
438
439 END SUBROUTINE qs_scf_ensure_mixing_store
440
441! **************************************************************************************************
442!> \brief Performs allocation of the SCF work matrices
443!> In case of kpoints we probably don't need most of these matrices,
444!> maybe we have to initialize some matrices in the fm_pool in kpoints
445!> \param qs_env ...
446!> \param scf_env ...
447! **************************************************************************************************
448 SUBROUTINE qs_scf_ensure_work_matrices(qs_env, scf_env)
449
450 TYPE(qs_environment_type), POINTER :: qs_env
451 TYPE(qs_scf_env_type), POINTER :: scf_env
452
453 CHARACTER(LEN=*), PARAMETER :: routinen = 'qs_scf_ensure_work_matrices'
454
455 INTEGER :: handle, is, nao, nrow_block, nw
456 LOGICAL :: do_kpoints
457 TYPE(cp_fm_pool_p_type), DIMENSION(:), POINTER :: ao_mo_fm_pools
458 TYPE(cp_fm_struct_type), POINTER :: ao_ao_fmstruct, ao_mo_fmstruct
459 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_s
460 TYPE(dbcsr_type), POINTER :: ref_matrix
461 TYPE(dft_control_type), POINTER :: dft_control
462 TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
463 TYPE(scf_control_type), POINTER :: scf_control
464
465 CALL timeset(routinen, handle)
466
467 NULLIFY (ao_mo_fm_pools, ao_mo_fmstruct, ao_ao_fmstruct, dft_control, matrix_s, mos)
468
469 CALL get_qs_env(qs_env=qs_env, &
470 dft_control=dft_control, &
471 matrix_s_kp=matrix_s, &
472 mos=mos, &
473 scf_control=scf_control, &
474 do_kpoints=do_kpoints)
475 CALL mpools_get(qs_env%mpools, ao_mo_fm_pools=ao_mo_fm_pools)
476
477 ! create an ao_ao parallel matrix structure
478 ao_mo_fmstruct => fm_pool_get_el_struct(ao_mo_fm_pools(1)%pool)
479 CALL cp_fm_struct_get(ao_mo_fmstruct, nrow_block=nrow_block)
480 CALL get_mo_set(mos(1), nao=nao)
481 CALL cp_fm_struct_create(fmstruct=ao_ao_fmstruct, &
482 nrow_block=nrow_block, &
483 ncol_block=nrow_block, &
484 nrow_global=nao, &
485 ncol_global=nao, &
486 template_fmstruct=ao_mo_fmstruct)
487
488 IF ((scf_env%method /= ot_method_nr) .AND. &
489 (scf_env%method /= block_davidson_diag_method_nr)) THEN
490 IF (.NOT. ASSOCIATED(scf_env%scf_work1)) THEN
491 nw = dft_control%nspins
492 IF (do_kpoints) nw = 4
493 ALLOCATE (scf_env%scf_work1(nw))
494 DO is = 1, SIZE(scf_env%scf_work1)
495 CALL cp_fm_create(scf_env%scf_work1(is), &
496 matrix_struct=ao_ao_fmstruct, &
497 name="SCF-WORK_MATRIX-1-"//trim(adjustl(cp_to_string(is))))
498 END DO
499 END IF
500 IF ((.NOT. ASSOCIATED(scf_env%ortho)) .AND. &
501 (scf_env%method /= ot_diag_method_nr) .AND. &
502 (scf_env%method /= special_diag_method_nr)) THEN
503 ! Initialize fm matrix to store the Cholesky decomposition
504 ALLOCATE (scf_env%ortho)
505 CALL cp_fm_create(scf_env%ortho, &
506 matrix_struct=ao_ao_fmstruct, &
507 name="SCF-ORTHO_MATRIX")
508 ! Initialize dbcsr matrix to store the Cholesky decomposition
509 IF (scf_env%cholesky_method == cholesky_dbcsr) THEN
510 ref_matrix => matrix_s(1, 1)%matrix
511 CALL dbcsr_init_p(scf_env%ortho_dbcsr)
512 CALL dbcsr_create(scf_env%ortho_dbcsr, template=ref_matrix, &
513 matrix_type=dbcsr_type_no_symmetry)
514 CALL dbcsr_init_p(scf_env%buf1_dbcsr)
515 CALL dbcsr_create(scf_env%buf1_dbcsr, template=ref_matrix, &
516 matrix_type=dbcsr_type_no_symmetry)
517 CALL dbcsr_init_p(scf_env%buf2_dbcsr)
518 CALL dbcsr_create(scf_env%buf2_dbcsr, template=ref_matrix, &
519 matrix_type=dbcsr_type_no_symmetry)
520 ELSE IF (scf_env%cholesky_method == cholesky_inverse .OR. &
521 (scf_control%level_shift /= 0.0_dp .AND. &
522 scf_env%cholesky_method == cholesky_off)) THEN
523 ALLOCATE (scf_env%ortho_m1)
524 CALL cp_fm_create(scf_env%ortho_m1, &
525 matrix_struct=ao_ao_fmstruct, &
526 name="SCF-ORTHO_MATRIX-1")
527 END IF
528 END IF
529 IF (.NOT. ASSOCIATED(scf_env%scf_work2)) THEN
530 ALLOCATE (scf_env%scf_work2)
531 CALL cp_fm_create(scf_env%scf_work2, &
532 matrix_struct=ao_ao_fmstruct, &
533 name="SCF-WORK_MATRIX-2")
534 END IF
535 END IF
536
537 IF (dft_control%dft_plus_u) THEN
538 IF (dft_control%plus_u_method_id == plus_u_lowdin) THEN
539 IF (.NOT. ASSOCIATED(scf_env%s_half)) THEN
540 ALLOCATE (scf_env%s_half)
541 CALL cp_fm_create(scf_env%s_half, &
542 matrix_struct=ao_ao_fmstruct, &
543 name="S**(1/2) MATRIX")
544 END IF
545 END IF
546 END IF
547
548 IF (do_kpoints) THEN
549 IF (.NOT. ASSOCIATED(scf_env%scf_work1)) THEN
550 nw = 4
551 ALLOCATE (scf_env%scf_work1(nw))
552 DO is = 1, SIZE(scf_env%scf_work1)
553 CALL cp_fm_create(scf_env%scf_work1(is), &
554 matrix_struct=ao_ao_fmstruct, &
555 name="SCF-WORK_MATRIX-1-"//trim(adjustl(cp_to_string(is))))
556 END DO
557 END IF
558 END IF
559
560 CALL cp_fm_struct_release(ao_ao_fmstruct)
561
562 CALL timestop(handle)
563
564 END SUBROUTINE qs_scf_ensure_work_matrices
565
566! **************************************************************************************************
567!> \brief performs allocation of the MO matrices
568!> \param qs_env ...
569! **************************************************************************************************
570 SUBROUTINE qs_scf_ensure_mos(qs_env)
571 TYPE(qs_environment_type), POINTER :: qs_env
572
573 CHARACTER(len=*), PARAMETER :: routinen = 'qs_scf_ensure_mos'
574
575 INTEGER :: handle, ic, ik, ikk, ispin, nmo, nmo_mat
576 TYPE(cp_fm_pool_p_type), DIMENSION(:), POINTER :: ao_mo_fm_pools
577 TYPE(cp_fm_type), POINTER :: mo_coeff, mo_coeff_last
578 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: mo_derivs
579 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_s
580 TYPE(dbcsr_type), POINTER :: mo_coeff_b
581 TYPE(dft_control_type), POINTER :: dft_control
582 TYPE(kpoint_type), POINTER :: kpoints
583 TYPE(mo_set_type), DIMENSION(:), POINTER :: mos, mos_last_converged
584 TYPE(mo_set_type), DIMENSION(:, :), POINTER :: mos_k
585 TYPE(xas_environment_type), POINTER :: xas_env
586
587 CALL timeset(routinen, handle)
588
589 NULLIFY (ao_mo_fm_pools, dft_control, mos, xas_env, matrix_s, mos_last_converged, mo_coeff_last)
590
591 CALL get_qs_env(qs_env=qs_env, &
592 dft_control=dft_control, &
593 mos=mos, &
594 matrix_s_kp=matrix_s, &
595 xas_env=xas_env)
596 CALL mpools_get(qs_env%mpools, ao_mo_fm_pools=ao_mo_fm_pools)
597 IF (dft_control%switch_surf_dip) THEN
598 CALL get_qs_env(qs_env, mos_last_converged=mos_last_converged)
599 END IF
600
601 nmo_mat = dft_control%nspins
602 IF (dft_control%restricted) nmo_mat = 1 ! right now, there might be more mos than needed derivs
603
604 ! Finish initialization of the MOs
605 cpassert(ASSOCIATED(mos))
606 DO ispin = 1, SIZE(mos)
607 CALL get_mo_set(mos(ispin), mo_coeff=mo_coeff, mo_coeff_b=mo_coeff_b)
608 IF (.NOT. ASSOCIATED(mo_coeff)) THEN
609 CALL init_mo_set(mos(ispin), &
610 fm_pool=ao_mo_fm_pools(ispin)%pool, &
611 name="qs_env%mo"//trim(adjustl(cp_to_string(ispin))))
612 END IF
613 IF (.NOT. ASSOCIATED(mo_coeff_b)) THEN
614 CALL cp_fm_get_info(mos(ispin)%mo_coeff, ncol_global=nmo)
615 CALL dbcsr_init_p(mos(ispin)%mo_coeff_b)
616 CALL cp_dbcsr_m_by_n_from_row_template(mos(ispin)%mo_coeff_b, template=matrix_s(1, 1)%matrix, n=nmo, &
617 sym=dbcsr_type_no_symmetry)
618 END IF
619 END DO
620 ! Get the mo_derivs OK if needed
621 IF (qs_env%requires_mo_derivs) THEN
622 CALL get_qs_env(qs_env, mo_derivs=mo_derivs)
623 IF (.NOT. ASSOCIATED(mo_derivs)) THEN
624 ALLOCATE (mo_derivs(nmo_mat))
625 DO ispin = 1, nmo_mat
626 CALL get_mo_set(mos(ispin), mo_coeff_b=mo_coeff_b)
627 NULLIFY (mo_derivs(ispin)%matrix)
628 CALL dbcsr_init_p(mo_derivs(ispin)%matrix)
629 CALL dbcsr_create(mo_derivs(ispin)%matrix, template=mo_coeff_b, &
630 name="mo_derivs", matrix_type=dbcsr_type_no_symmetry)
631 END DO
632 CALL set_qs_env(qs_env, mo_derivs=mo_derivs)
633 END IF
634
635 ELSE
636 ! nothing should be done
637 END IF
638
639 ! Finish initialization of the MOs for ADMM and derivs if needed ***
640 IF (dft_control%do_admm) THEN
641 IF (dft_control%restricted) cpabort("ROKS with ADMM is not implemented")
642 END IF
643
644 ! Finish initialization of mos_last_converged [SGh]
645 IF (dft_control%switch_surf_dip) THEN
646 cpassert(ASSOCIATED(mos_last_converged))
647 DO ispin = 1, SIZE(mos_last_converged)
648 CALL get_mo_set(mos_last_converged(ispin), mo_coeff=mo_coeff_last)
649 IF (.NOT. ASSOCIATED(mo_coeff_last)) THEN
650 CALL init_mo_set(mos_last_converged(ispin), &
651 fm_ref=mos(ispin)%mo_coeff, &
652 name="qs_env%mos_last_converged"//trim(adjustl(cp_to_string(ispin))))
653 END IF
654 END DO
655 END IF
656 ! kpoints: we have to initialize all the k-point MOs
657 CALL get_qs_env(qs_env=qs_env, kpoints=kpoints)
658 IF (kpoints%nkp /= 0) THEN
659 ! check for some incompatible options
660 IF (qs_env%requires_mo_derivs) THEN
661 cpwarn("MO derivative methods flag has been switched off for kpoint calculation")
662 ! we switch it off to make band structure calculations
663 ! possible for OT gamma point calculations
664 qs_env%requires_mo_derivs = .false.
665 END IF
666 IF (dft_control%do_xas_calculation) THEN
667 cpabort("No XAS implemented with kpoints")
668 END IF
669 IF (qs_env%do_rixs) THEN
670 cpabort("RIXS not implemented with kpoints")
671 END IF
672 DO ik = 1, SIZE(kpoints%kp_env)
673 CALL mpools_get(kpoints%mpools, ao_mo_fm_pools=ao_mo_fm_pools)
674 mos_k => kpoints%kp_env(ik)%kpoint_env%mos
675 ikk = kpoints%kp_range(1) + ik - 1
676 cpassert(ASSOCIATED(mos_k))
677 DO ispin = 1, SIZE(mos_k, 2)
678 DO ic = 1, SIZE(mos_k, 1)
679 CALL get_mo_set(mos_k(ic, ispin), mo_coeff=mo_coeff, mo_coeff_b=mo_coeff_b)
680 IF (.NOT. ASSOCIATED(mo_coeff)) THEN
681 CALL init_mo_set(mos_k(ic, ispin), &
682 fm_pool=ao_mo_fm_pools(ispin)%pool, &
683 name="kpoints_"//trim(adjustl(cp_to_string(ikk)))// &
684 "%mo"//trim(adjustl(cp_to_string(ispin))))
685 END IF
686 ! no sparse matrix representation of kpoint MO vectors
687 cpassert(.NOT. ASSOCIATED(mo_coeff_b))
688 END DO
689 END DO
690 END DO
691 END IF
692
693 CALL timestop(handle)
694
695 END SUBROUTINE qs_scf_ensure_mos
696
697! **************************************************************************************************
698!> \brief sets flag for mixing/DIIS during scf
699!> \param scf_control ...
700!> \param scf_section ...
701!> \param scf_env ...
702!> \param dft_control ...
703! **************************************************************************************************
704 SUBROUTINE qs_scf_ensure_mixing(scf_control, scf_section, scf_env, dft_control)
705 TYPE(scf_control_type), POINTER :: scf_control
706 TYPE(section_vals_type), POINTER :: scf_section
707 TYPE(qs_scf_env_type), POINTER :: scf_env
708 TYPE(dft_control_type), POINTER :: dft_control
709
710 TYPE(section_vals_type), POINTER :: mixing_section
711
712 SELECT CASE (scf_control%mixing_method)
713 CASE (no_mix)
714 scf_env%mixing_method = no_mixing_nr
715 scf_env%p_mix_alpha = 1.0_dp
718 scf_env%mixing_method = scf_control%mixing_method
719 mixing_section => section_vals_get_subs_vals(scf_section, "MIXING")
720 IF (.NOT. ASSOCIATED(scf_env%mixing_store)) THEN
721 ALLOCATE (scf_env%mixing_store)
722 CALL mixing_storage_create(scf_env%mixing_store, mixing_section, scf_env%mixing_method, &
723 dft_control%qs_control%cutoff)
724 END IF
725 CASE DEFAULT
726 cpabort("Unknown mixing method")
727 END SELECT
728
729 ! Disable DIIS for OT and g-space density mixing methods
730 IF (scf_env%method == ot_method_nr) THEN
731 ! No mixing is used with OT
732 scf_env%mixing_method = no_mixing_nr
733 scf_env%p_mix_alpha = 1.0_dp
734 scf_env%skip_diis = .true.
735 END IF
736
737 IF (scf_control%use_diag .AND. scf_env%mixing_method == no_mixing_nr) THEN
738 cpabort("Diagonalization procedures without mixing are not recommendable")
739 END IF
740
741 IF (scf_env%mixing_method > direct_mixing_nr) THEN
742 scf_env%skip_diis = .true.
743 scf_env%p_mix_alpha = scf_env%mixing_store%alpha
744 IF (scf_env%mixing_store%beta == 0.0_dp) THEN
745 cpabort("Mixing employing the Kerker damping factor needs BETA /= 0.0")
746 END IF
747 END IF
748
749 IF (scf_env%mixing_method == direct_mixing_nr) THEN
750 scf_env%p_mix_alpha = scf_env%mixing_store%alpha
751 IF (scf_control%eps_diis < scf_control%eps_scf) THEN
752 scf_env%skip_diis = .true.
753 cpwarn("the DIIS scheme is disabled, since EPS_DIIS < EPS_SCF")
754 END IF
755 END IF
756
757 END SUBROUTINE qs_scf_ensure_mixing
758
759! **************************************************************************************************
760!> \brief sets flags for diagonalization and ensure that everything is
761!> allocated
762!> \param scf_env ...
763!> \param scf_section ...
764!> \param qs_env ...
765!> \param scf_control ...
766!> \param has_unit_metric ...
767! **************************************************************************************************
768 SUBROUTINE qs_scf_ensure_diagonalization(scf_env, scf_section, qs_env, &
769 scf_control, has_unit_metric)
770 TYPE(qs_scf_env_type), POINTER :: scf_env
771 TYPE(section_vals_type), POINTER :: scf_section
772 TYPE(qs_environment_type), POINTER :: qs_env
773 TYPE(scf_control_type), POINTER :: scf_control
774 LOGICAL :: has_unit_metric
775
776 INTEGER :: ispin, nao, nmo
777 LOGICAL :: do_kpoints, need_coeff_b, not_se_or_tb
778 TYPE(cp_fm_type), POINTER :: mo_coeff
779 TYPE(dft_control_type), POINTER :: dft_control
780 TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
781
782 CALL get_qs_env(qs_env=qs_env, do_kpoints=do_kpoints, dft_control=dft_control, mos=mos)
783 not_se_or_tb = .NOT. (dft_control%qs_control%dftb .OR. dft_control%qs_control%xtb .OR. &
784 dft_control%qs_control%semi_empirical)
785 need_coeff_b = .false.
786 scf_env%needs_ortho = .false.
787
788 IF (dft_control%smeagol_control%smeagol_enabled .AND. &
789 dft_control%smeagol_control%run_type == smeagol_runtype_emtransport) THEN
790 scf_env%method = smeagol_method_nr
791 scf_env%skip_diis = .true.
792 scf_control%use_diag = .false.
793
794 IF (.NOT. do_kpoints) THEN
795 cpabort("SMEAGOL requires kpoint calculations")
796 END IF
797 cpwarn_if(scf_control%use_ot, "OT is irrelevant to NEGF method")
798 END IF
799
800 IF (scf_control%use_diag) THEN
801 ! sanity check whether combinations are allowed
802 IF (dft_control%restricted) THEN
803 cpabort("OT only for restricted (ROKS)")
804 END IF
805 SELECT CASE (scf_control%diagonalization%method)
807 IF (.NOT. not_se_or_tb) THEN
808 cpabort("TB and SE not possible with OT diagonalization")
809 END IF
810 END SELECT
811 SELECT CASE (scf_control%diagonalization%method)
812 ! Diagonalization: additional check whether we are in an orthonormal basis
813 CASE (diag_standard)
814 scf_env%method = general_diag_method_nr
815 scf_env%needs_ortho = (.NOT. has_unit_metric) .AND. (.NOT. do_kpoints)
816 IF (diag_type == fm_diag_type_cusolver .AND. &
818 scf_control%level_shift == 0.0_dp .AND. &
819 scf_env%cholesky_method /= cholesky_off) THEN
820 CALL get_mo_set(mos(1), nao=nao)
821 IF (nao >= cusolver_n_min) THEN
822 scf_env%needs_ortho = .false.
823 END IF
824 END IF
825 IF (has_unit_metric) THEN
826 scf_env%method = special_diag_method_nr
827 END IF
828 ! OT Diagonalization: not possible with ROKS
829 CASE (diag_ot)
830 IF (dft_control%roks) THEN
831 cpabort("ROKS with OT diagonalization not possible")
832 END IF
833 IF (do_kpoints) THEN
834 cpabort("OT diagonalization not possible with kpoint calculations")
835 END IF
836 scf_env%method = ot_diag_method_nr
837 need_coeff_b = .true.
838 ! Block Krylov diagonlization: not possible with ROKS,
839 ! allocation of additional matrices is needed
840 CASE (diag_block_krylov)
841 IF (dft_control%roks) THEN
842 cpabort("ROKS with block PF diagonalization not possible")
843 END IF
844 IF (do_kpoints) THEN
845 cpabort("Block Krylov diagonalization not possible with kpoint calculations")
846 END IF
847 scf_env%method = block_krylov_diag_method_nr
848 scf_env%needs_ortho = .true.
849 IF (.NOT. ASSOCIATED(scf_env%krylov_space)) THEN
850 CALL krylov_space_create(scf_env%krylov_space, scf_section)
851 END IF
852 CALL krylov_space_allocate(scf_env%krylov_space, scf_control, mos)
853 ! Block davidson diagonlization: allocation of additional matrices is needed
855 IF (do_kpoints) THEN
856 cpabort("Block Davidson diagonalization not possible with kpoint calculations")
857 END IF
858 scf_env%method = block_davidson_diag_method_nr
859 IF (.NOT. ASSOCIATED(scf_env%block_davidson_env)) THEN
860 CALL block_davidson_env_create(scf_env%block_davidson_env, dft_control%nspins, &
861 scf_section)
862 END IF
863 DO ispin = 1, dft_control%nspins
864 CALL get_mo_set(mo_set=mos(ispin), mo_coeff=mo_coeff, nao=nao, nmo=nmo)
865 CALL block_davidson_allocate(scf_env%block_davidson_env(ispin), mo_coeff, nao, nmo)
866 END DO
867 need_coeff_b = .true.
868 ! Filter matrix diagonalisation method
869 CASE (diag_filter_matrix)
870 scf_env%method = filter_matrix_diag_method_nr
871 IF (.NOT. fb_env_has_data(scf_env%filter_matrix_env)) THEN
872 CALL fb_env_create(scf_env%filter_matrix_env)
873 END IF
874 CALL fb_env_read_input(scf_env%filter_matrix_env, scf_section)
875 CALL fb_env_build_rcut_auto(scf_env%filter_matrix_env, qs_env)
876 CALL fb_env_write_info(scf_env%filter_matrix_env, qs_env, scf_section)
877 CALL fb_distribution_build(scf_env%filter_matrix_env, qs_env, scf_section)
878 CALL fb_env_build_atomic_halos(scf_env%filter_matrix_env, qs_env, scf_section)
879 CASE DEFAULT
880 cpabort("Unknown diagonalization method")
881 END SELECT
882 ! Check if subspace diagonlization is requested: allocation of additional matrices is needed
883 IF (scf_control%do_diag_sub) THEN
884 scf_env%needs_ortho = .true.
885 IF (.NOT. ASSOCIATED(scf_env%subspace_env)) THEN
886 CALL diag_subspace_env_create(scf_env%subspace_env, scf_section, &
887 dft_control%qs_control%cutoff)
888 END IF
889 CALL diag_subspace_allocate(scf_env%subspace_env, qs_env, mos)
890 IF (do_kpoints) THEN
891 cpabort("No subspace diagonlization with kpoint calculation")
892 END IF
893 END IF
894 ! OT: check if OT is used instead of diagonalization. Not possible with added MOS at the moment
895 ELSE IF (scf_control%use_ot) THEN
896 scf_env%method = ot_method_nr
897 need_coeff_b = .true.
898 IF (sum(abs(scf_control%added_mos)) > 0) THEN
899 cpabort("OT with ADDED_MOS/=0 not implemented")
900 END IF
901 IF (dft_control%restricted .AND. dft_control%nspins /= 2) THEN
902 cpabort("nspin must be 2 for restricted (ROKS)")
903 END IF
904 IF (do_kpoints) THEN
905 cpabort("OT not possible with kpoint calculations")
906 END IF
907 ELSE IF (scf_env%method /= smeagol_method_nr) THEN
908 cpabort("OT or DIAGONALIZATION have to be set")
909 END IF
910 DO ispin = 1, dft_control%nspins
911 mos(ispin)%use_mo_coeff_b = need_coeff_b
912 END DO
913
914 END SUBROUTINE qs_scf_ensure_diagonalization
915
916! **************************************************************************************************
917!> \brief performs those initialisations that need to be done only once
918!> (e.g. that only depend on the atomic positions)
919!> this will be called in scf
920!> \param scf_env ...
921!> \param qs_env ...
922!> \param scf_section ...
923!> \param scf_control ...
924!> \par History
925!> 03.2006 created [Joost VandeVondele]
926! **************************************************************************************************
927 SUBROUTINE init_scf_run(scf_env, qs_env, scf_section, scf_control)
928
929 TYPE(qs_scf_env_type), POINTER :: scf_env
930 TYPE(qs_environment_type), POINTER :: qs_env
931 TYPE(section_vals_type), POINTER :: scf_section
932 TYPE(scf_control_type), POINTER :: scf_control
933
934 CHARACTER(LEN=*), PARAMETER :: routinen = 'init_scf_run'
935
936 INTEGER :: after, handle, homo, ii, ikind, ispin, &
937 iw, nao, ndep, needed_evals, nmo, &
938 output_unit
939 LOGICAL :: dft_plus_u_atom, do_kpoints, &
940 init_u_ramping_each_scf, omit_headers, &
941 s_minus_half_available
942 REAL(kind=dp) :: u_ramping
943 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: evals
944 REAL(kind=dp), DIMENSION(:), POINTER :: eigenvalues
945 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
946 TYPE(cp_fm_struct_type), POINTER :: fm_struct
947 TYPE(cp_fm_type) :: evecs, fm_w
948 TYPE(cp_fm_type), POINTER :: mo_coeff
949 TYPE(cp_logger_type), POINTER :: logger
950 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_s
951 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_s_kp
952 TYPE(dft_control_type), POINTER :: dft_control
953 TYPE(kpoint_type), POINTER :: kpoints
954 TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
955 TYPE(mp_para_env_type), POINTER :: para_env
956 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
957 TYPE(qs_kind_type), POINTER :: qs_kind
958 TYPE(qs_rho_type), POINTER :: rho
959 TYPE(xas_environment_type), POINTER :: xas_env
960
961 CALL timeset(routinen, handle)
962
963 NULLIFY (qs_kind_set, matrix_s, dft_control, mos, qs_kind, rho, xas_env, mo_coeff)
964
965 logger => cp_get_default_logger()
966
967 cpassert(ASSOCIATED(scf_env))
968 cpassert(ASSOCIATED(qs_env))
969 NULLIFY (para_env)
970
971 s_minus_half_available = .false.
972 CALL get_qs_env(qs_env, &
973 dft_control=dft_control, &
974 qs_kind_set=qs_kind_set, &
975 mos=mos, &
976 rho=rho, &
977 nelectron_total=scf_env%nelectron, &
978 do_kpoints=do_kpoints, &
979 para_env=para_env, &
980 xas_env=xas_env)
981
982 ! Check restricted optimizers available for tblite library
983 IF (dft_control%qs_control%xtb_control%do_tblite) THEN
984 IF (scf_env%method == ot_method_nr) THEN
985 CALL cp_warn(__location__, &
986 "CP2K/tblite with OT is restricted to Gamma-point calculations without smearing. "// &
987 "The tblite SCC variables are updated directly from the OT density; XTB/SCC_MIXER is ignored.")
988 END IF
989 END IF
990
991 ! Calculate ortho matrix
992 ndep = 0
993 IF (scf_env%needs_ortho) THEN
994 CALL get_qs_env(qs_env, matrix_s=matrix_s)
995 CALL copy_dbcsr_to_fm(matrix_s(1)%matrix, scf_env%ortho)
996 IF (scf_env%cholesky_method > cholesky_off) THEN
997 CALL cp_fm_cholesky_decompose(scf_env%ortho)
998 IF (scf_env%cholesky_method == cholesky_dbcsr) THEN
999 CALL cp_fm_triangular_invert(scf_env%ortho)
1000 CALL cp_fm_set_all(scf_env%scf_work2, 0.0_dp)
1001 CALL cp_fm_to_fm_triangular(scf_env%ortho, scf_env%scf_work2, "U")
1002 CALL copy_fm_to_dbcsr(scf_env%scf_work2, scf_env%ortho_dbcsr)
1003 ELSE IF (scf_env%cholesky_method == cholesky_inverse) THEN
1004 CALL cp_fm_to_fm(scf_env%ortho, scf_env%ortho_m1)
1005 CALL cp_fm_triangular_invert(scf_env%ortho_m1)
1006 END IF
1007 ELSE
1008 CALL cp_fm_get_info(scf_env%ortho, ncol_global=nao)
1009 ALLOCATE (evals(nao))
1010 evals = 0
1011
1012 CALL cp_fm_create(evecs, scf_env%ortho%matrix_struct)
1013
1014 ! Perform an EVD
1015 CALL choose_eigv_solver(scf_env%ortho, evecs, evals)
1016
1017 ! Determine the number of neglectable eigenvalues assuming that the eigenvalues are in ascending order
1018 ! (Required by Lapack)
1019 ndep = 0
1020 DO ii = 1, nao
1021 IF (evals(ii) > scf_control%eps_eigval) THEN
1022 ndep = ii - 1
1023 EXIT
1024 END IF
1025 END DO
1026 needed_evals = nao - ndep
1027
1028 ! Set the eigenvalue of the eigenvectors belonging to the linear subspace to zero
1029 evals(1:ndep) = 0.0_dp
1030 ! Determine the eigenvalues of the inverse square root
1031 evals(ndep + 1:nao) = 1.0_dp/sqrt(evals(ndep + 1:nao))
1032
1033 ! Create reduced matrices
1034 NULLIFY (fm_struct)
1035 CALL cp_fm_struct_create(fm_struct, template_fmstruct=scf_env%ortho%matrix_struct, &
1036 nrow_global=nao, ncol_global=needed_evals)
1037
1038 ALLOCATE (scf_env%ortho_red, scf_env%scf_work2_red)
1039 CALL cp_fm_create(scf_env%ortho_red, fm_struct)
1040 CALL cp_fm_create(scf_env%scf_work2_red, fm_struct)
1041 CALL cp_fm_struct_release(fm_struct)
1042
1043 IF (scf_control%level_shift /= 0.0_dp) THEN
1044 CALL cp_fm_struct_create(fm_struct, template_fmstruct=scf_env%ortho%matrix_struct, &
1045 nrow_global=needed_evals, ncol_global=nao)
1046
1047 ALLOCATE (scf_env%ortho_m1_red)
1048 CALL cp_fm_create(scf_env%ortho_m1_red, fm_struct)
1049 CALL cp_fm_struct_release(fm_struct)
1050 END IF
1051
1052 ALLOCATE (scf_env%scf_work1_red(SIZE(scf_env%scf_work1)))
1053 DO ispin = 1, SIZE(scf_env%scf_work1)
1054 CALL cp_fm_struct_create(fm_struct, template_fmstruct=scf_env%ortho%matrix_struct, &
1055 nrow_global=needed_evals, ncol_global=needed_evals)
1056 CALL cp_fm_create(scf_env%scf_work1_red(ispin), fm_struct)
1057 CALL cp_fm_struct_release(fm_struct)
1058 END DO
1059
1060 ! Scale the eigenvalues and copy them to
1061 CALL cp_fm_to_fm(evecs, scf_env%ortho_red, needed_evals, ndep + 1, 1)
1062
1063 IF (scf_control%level_shift /= 0.0_dp) THEN
1064 CALL cp_fm_transpose(scf_env%ortho_red, scf_env%ortho_m1_red)
1065 END IF
1066
1067 CALL cp_fm_column_scale(scf_env%ortho_red, evals(ndep + 1:))
1068
1069 ! Copy the linear dependent columns to the MO sets and set their orbital energies
1070 ! to a very large value to reduce the probability of occupying them
1071 DO ispin = 1, SIZE(mos)
1072 CALL get_mo_set(mos(ispin), nmo=nmo, mo_coeff=mo_coeff, homo=homo, eigenvalues=eigenvalues)
1073 IF (needed_evals < nmo) THEN
1074 IF (needed_evals < homo) THEN
1075 CALL cp_abort(__location__, &
1076 "The numerical rank of the overlap matrix is lower than the "// &
1077 "number of orbitals to be occupied! Check the geometry or increase "// &
1078 "EPS_DEFAULT or EPS_PGF_ORB!")
1079 END IF
1080 CALL cp_warn(__location__, &
1081 "The numerical rank of the overlap matrix is lower than the number of requested MOs! "// &
1082 "Reduce the number of MOs to the number of available MOs. If necessary, "// &
1083 "request a lower number of MOs or increase EPS_DEFAULT or EPS_PGF_ORB.")
1084 CALL set_mo_set(mos(ispin), nmo=needed_evals)
1085 END IF
1086 ! Copy the last columns to mo_coeff if the container is large enough
1087 CALL cp_fm_to_fm(evecs, mo_coeff, min(ndep, max(0, nmo - needed_evals)), 1, needed_evals + 1)
1088 ! Set the corresponding eigenvalues to a large value
1089 ! This prevents their occupation but still keeps the information on them
1090 eigenvalues(needed_evals + 1:min(nao, nmo)) = 1.0_dp/scf_control%eps_eigval
1091 END DO
1092
1093 ! Obtain ortho from (P)DGEMM, skip the linear dependent columns
1094 CALL parallel_gemm("N", "T", nao, nao, needed_evals, 1.0_dp, scf_env%ortho_red, evecs, &
1095 0.0_dp, scf_env%ortho, b_first_col=ndep + 1)
1096
1097 IF (scf_control%level_shift /= 0.0_dp) THEN
1098 ! We need SQRT(evals) of the eigenvalues of H, so 1/SQRT(evals) of ortho_red
1099 evals(ndep + 1:nao) = 1.0_dp/evals(ndep + 1:nao)
1100 CALL cp_fm_row_scale(scf_env%ortho_m1_red, evals(ndep + 1:))
1101
1102 CALL parallel_gemm("T", "T", nao, nao, needed_evals, 1.0_dp, scf_env%ortho_m1_red, evecs, &
1103 0.0_dp, scf_env%ortho_m1, b_first_col=ndep + 1)
1104 END IF
1105
1106 CALL cp_fm_release(evecs)
1107
1108 s_minus_half_available = .true.
1109 END IF
1110
1111 IF (btest(cp_print_key_should_output(logger%iter_info, &
1112 qs_env%input, "DFT%PRINT%AO_MATRICES/ORTHO"), cp_p_file)) THEN
1113 iw = cp_print_key_unit_nr(logger, qs_env%input, "DFT%PRINT%AO_MATRICES/ORTHO", &
1114 extension=".Log")
1115 CALL section_vals_val_get(qs_env%input, "DFT%PRINT%AO_MATRICES%NDIGITS", i_val=after)
1116 CALL section_vals_val_get(qs_env%input, "DFT%PRINT%AO_MATRICES%OMIT_HEADERS", l_val=omit_headers)
1117 after = min(max(after, 1), 16)
1118 CALL write_fm_with_basis_info(scf_env%ortho, 4, after, qs_env, &
1119 para_env, output_unit=iw, omit_headers=omit_headers)
1120 CALL cp_print_key_finished_output(iw, logger, qs_env%input, &
1121 "DFT%PRINT%AO_MATRICES/ORTHO")
1122 END IF
1123 END IF
1124
1125 CALL get_mo_set(mo_set=mos(1), nao=nao)
1126
1127 ! DFT+U methods based on Lowdin charges need S^(1/2)
1128 IF (dft_control%dft_plus_u) THEN
1129 IF (dft_control%plus_u_method_id == plus_u_lowdin) THEN
1130 IF (do_kpoints) THEN
1131 CALL get_qs_env(qs_env, kpoints=kpoints, matrix_s_kp=matrix_s_kp)
1132 CALL diag_kp_smat(matrix_s_kp, kpoints, scf_env%scf_work1)
1133 ELSE
1134 CALL get_qs_env(qs_env, matrix_s=matrix_s)
1135 IF (s_minus_half_available) THEN
1136 CALL cp_dbcsr_sm_fm_multiply(matrix_s(1)%matrix, scf_env%ortho, &
1137 scf_env%s_half, nao)
1138 ELSE
1139 CALL copy_dbcsr_to_fm(matrix_s(1)%matrix, scf_env%s_half)
1140 CALL cp_fm_create(fm_w, scf_env%s_half%matrix_struct)
1141 CALL cp_fm_power(scf_env%s_half, fm_w, 0.5_dp, scf_control%eps_eigval, ndep)
1142 CALL cp_fm_release(fm_w)
1143 END IF
1144 END IF
1145 END IF
1146 DO ikind = 1, SIZE(qs_kind_set)
1147 qs_kind => qs_kind_set(ikind)
1148 CALL get_qs_kind(qs_kind=qs_kind, &
1149 dft_plus_u_atom=dft_plus_u_atom, &
1150 u_ramping=u_ramping, &
1151 init_u_ramping_each_scf=init_u_ramping_each_scf)
1152 IF (dft_plus_u_atom .AND. (u_ramping /= 0.0_dp)) THEN
1153 IF (init_u_ramping_each_scf) THEN
1154 CALL set_qs_kind(qs_kind=qs_kind, u_minus_j=0.0_dp)
1155 END IF
1156 END IF
1157 END DO
1158 END IF
1159
1160 IF (dft_control%dft_plus_u) THEN
1161 IF (dft_control%plus_u_method_id == plus_u_tensorial) THEN
1162 CALL get_qs_env(qs_env, atomic_kind_set=atomic_kind_set, qs_kind_set=qs_kind_set)
1163 DO ikind = 1, SIZE(atomic_kind_set)
1164 qs_kind => qs_kind_set(ikind)
1165 CALL get_qs_kind(qs_kind=qs_kind, dft_plus_u_atom=dft_plus_u_atom)
1166 IF (.NOT. dft_plus_u_atom) cycle
1167 CALL calculate_atomic_orbitals(atomic_kind=atomic_kind_set(ikind), &
1168 qs_kind=qs_kind_set(ikind), &
1169 which_l=qs_kind%dft_plus_u%l, &
1170 which_n=qs_kind%dft_plus_u%n, &
1171 proj_shell_charge=qs_kind%dft_plus_u%proj_shell_charge, &
1172 ao_coef=qs_kind%dft_plus_u%ao_coef)
1173 END DO
1174 END IF
1175 END IF
1176
1177 ! extrapolate outer loop variables
1178 IF (scf_control%outer_scf%have_scf) THEN
1179 CALL outer_loop_extrapolate(qs_env)
1180 END IF
1181
1182 ! initializes rho and the mos
1183 IF (ASSOCIATED(qs_env%xas_env)) THEN
1184 ! if just optimized wfn, e.g. ground state
1185 ! changes come from a perturbation, e.g., the occupation numbers
1186 ! it could be generalized for other cases, at the moment used only for core level spectroscopy
1187 ! initialize the density with the localized mos
1188 CALL xas_initialize_rho(qs_env, scf_env, scf_control)
1189 ELSE
1190 CALL scf_env_initial_rho_setup(scf_env, qs_env=qs_env, &
1191 scf_section=scf_section, scf_control=scf_control)
1192 END IF
1193
1194 ! Frozen density approximation
1195 IF (ASSOCIATED(qs_env%wf_history)) THEN
1196 IF (qs_env%wf_history%interpolation_method_nr == wfi_frozen_method_nr) THEN
1197 IF (.NOT. ASSOCIATED(qs_env%wf_history%past_states(1)%snapshot)) THEN
1198 CALL wfi_update(qs_env%wf_history, qs_env=qs_env, dt=1.0_dp)
1199 ALLOCATE (qs_env%wf_history%past_states(1)%snapshot%rho_frozen)
1200 CALL qs_rho_create(qs_env%wf_history%past_states(1)%snapshot%rho_frozen)
1201 CALL duplicate_rho_type(rho_input=rho, &
1202 rho_output=qs_env%wf_history%past_states(1)%snapshot%rho_frozen, &
1203 qs_env=qs_env)
1204 END IF
1205 END IF
1206 END IF
1207
1208 !image charge method, calculate image_matrix if required
1209 IF (qs_env%qmmm) THEN
1210 IF (qs_env%qmmm .AND. qs_env%qmmm_env_qm%image_charge) THEN
1211 CALL conditional_calc_image_matrix(qs_env=qs_env, &
1212 qmmm_env=qs_env%qmmm_env_qm)
1213 END IF
1214 END IF
1215
1216 output_unit = cp_print_key_unit_nr(logger, scf_section, "PRINT%PROGRAM_RUN_INFO", &
1217 extension=".scfLog")
1218 CALL qs_scf_initial_info(output_unit, mos, dft_control, ndep)
1219 CALL cp_print_key_finished_output(output_unit, logger, scf_section, &
1220 "PRINT%PROGRAM_RUN_INFO")
1221
1222 CALL timestop(handle)
1223
1224 END SUBROUTINE init_scf_run
1225
1226! **************************************************************************************************
1227!> \brief Initializes rho and the mos, so that an scf cycle can start
1228!> \param scf_env the scf env in which to do the scf
1229!> \param qs_env the qs env the scf_env lives in
1230!> \param scf_section ...
1231!> \param scf_control ...
1232!> \par History
1233!> 02.2003 created [fawzi]
1234!> \author fawzi
1235! **************************************************************************************************
1236 SUBROUTINE scf_env_initial_rho_setup(scf_env, qs_env, scf_section, scf_control)
1237 TYPE(qs_scf_env_type), POINTER :: scf_env
1238 TYPE(qs_environment_type), POINTER :: qs_env
1239 TYPE(section_vals_type), POINTER :: scf_section
1240 TYPE(scf_control_type), POINTER :: scf_control
1241
1242 CHARACTER(len=*), PARAMETER :: routinen = 'scf_env_initial_rho_setup'
1243
1244 INTEGER :: extrapolation_method_nr, handle, ispin, &
1245 nmo, output_unit
1246 LOGICAL :: do_harris, orthogonal_wf
1247 TYPE(cp_fm_type), POINTER :: mo_coeff
1248 TYPE(cp_logger_type), POINTER :: logger
1249 TYPE(dft_control_type), POINTER :: dft_control
1250 TYPE(harris_type), POINTER :: harris_env
1251 TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
1252 TYPE(mp_para_env_type), POINTER :: para_env
1253 TYPE(qs_rho_type), POINTER :: rho
1254 TYPE(rho_atom_type), DIMENSION(:), POINTER :: rho_atom
1255
1256 CALL timeset(routinen, handle)
1257 NULLIFY (mo_coeff, rho, dft_control, para_env, mos)
1258 logger => cp_get_default_logger()
1259 cpassert(ASSOCIATED(scf_env))
1260 cpassert(ASSOCIATED(qs_env))
1261
1262 CALL get_qs_env(qs_env, &
1263 rho=rho, &
1264 mos=mos, &
1265 dft_control=dft_control, &
1266 para_env=para_env)
1267
1268 do_harris = qs_env%harris_method
1269
1270 extrapolation_method_nr = wfi_use_guess_method_nr
1271 IF (ASSOCIATED(qs_env%wf_history)) THEN
1272 CALL wfi_extrapolate(qs_env%wf_history, &
1273 qs_env=qs_env, dt=1.0_dp, &
1274 extrapolation_method_nr=extrapolation_method_nr, &
1275 orthogonal_wf=orthogonal_wf)
1276 ! wfi_use_guess_method_nr the wavefunctions are not yet initialized
1277 IF ((.NOT. orthogonal_wf) .AND. &
1278 (scf_env%method == ot_method_nr) .AND. &
1279 (.NOT. (extrapolation_method_nr == wfi_use_guess_method_nr))) THEN
1280 DO ispin = 1, SIZE(mos)
1281 CALL get_mo_set(mos(ispin), mo_coeff=mo_coeff, nmo=nmo)
1282 CALL reorthogonalize_vectors(qs_env, v_matrix=mo_coeff, n_col=nmo)
1283 IF (dft_control%hairy_probes .EQV. .true.) THEN
1284 scf_control%smear%do_smear = .false.
1285 CALL set_mo_occupation(mo_set=mos(ispin), &
1286 smear=scf_control%smear, probe=dft_control%probe)
1287 ELSE
1288 CALL set_mo_occupation(mo_set=mos(ispin), &
1289 smear=scf_control%smear)
1290 END IF
1291 END DO
1292 END IF
1293 END IF
1294
1295 IF (.NOT. do_harris) THEN
1296 output_unit = cp_print_key_unit_nr(logger, scf_section, "PRINT%PROGRAM_RUN_INFO", &
1297 extension=".scfLog")
1298 IF (output_unit > 0) THEN
1299 WRITE (unit=output_unit, fmt="(/,T2,A,I0)") &
1300 "Extrapolation method: "// &
1301 trim(wfi_get_method_label(extrapolation_method_nr))
1302 IF (extrapolation_method_nr == wfi_ps_method_nr) THEN
1303 WRITE (unit=output_unit, fmt="(T2,A,I0,A)") &
1304 "Extrapolation order: ", &
1305 max((min(qs_env%wf_history%memory_depth, qs_env%wf_history%snapshot_count) - 1), 0)
1306 END IF
1307 END IF
1308 CALL cp_print_key_finished_output(output_unit, logger, scf_section, &
1309 "PRINT%PROGRAM_RUN_INFO")
1310 END IF
1311
1312 IF (do_harris) THEN
1313 CALL get_qs_env(qs_env, harris_env=harris_env)
1314 CALL harris_density_update(qs_env, harris_env)
1315 CALL qs_rho_update_rho(rho, qs_env=qs_env)
1316 CALL qs_ks_did_change(qs_env%ks_env, rho_changed=.true.)
1317 ELSE IF (extrapolation_method_nr == wfi_use_guess_method_nr) THEN
1318 CALL calculate_first_density_matrix(scf_env=scf_env, qs_env=qs_env)
1319 CALL qs_rho_update_rho(rho, qs_env=qs_env)
1320 CALL qs_ks_did_change(qs_env%ks_env, rho_changed=.true.)
1321 END IF
1322
1323 ! Some preparation for the mixing
1324 IF (scf_env%mixing_method > 1) THEN
1325 IF (dft_control%qs_control%gapw) THEN
1326 CALL get_qs_env(qs_env=qs_env, rho_atom_set=rho_atom)
1327 CALL mixing_init(scf_env%mixing_method, rho, scf_env%mixing_store, &
1328 para_env, rho_atom=rho_atom)
1329 ELSE IF (dft_control%qs_control%dftb .OR. dft_control%qs_control%xtb) THEN
1330 CALL charge_mixing_init(scf_env%mixing_store)
1331 ELSE IF (dft_control%qs_control%semi_empirical) THEN
1332 cpabort('SE Code not possible')
1333 ELSE
1334 CALL mixing_init(scf_env%mixing_method, rho, scf_env%mixing_store, &
1335 para_env)
1336 END IF
1337 END IF
1338
1339 DO ispin = 1, SIZE(mos) !fm->dbcsr
1340 IF (mos(ispin)%use_mo_coeff_b) THEN
1341 CALL copy_fm_to_dbcsr(mos(ispin)%mo_coeff, &
1342 mos(ispin)%mo_coeff_b) !fm->dbcsr
1343 END IF
1344 END DO !fm->dbcsr
1345
1346 CALL timestop(handle)
1347
1348 END SUBROUTINE scf_env_initial_rho_setup
1349
1350END MODULE qs_scf_initialization
calculate the orbitals for a given atomic kind type
subroutine, public calculate_atomic_orbitals(atomic_kind, qs_kind, agrid, iunit, pmat, fmat, density, wavefunction, wfninfo, confine, xc_section, nocc, which_l, which_n, proj_shell_charge, ao_coef)
...
Define the atomic kind types and their sub types.
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
subroutine, public dbcsr_init_p(matrix)
...
DBCSR operations in CP2K.
subroutine, public cp_dbcsr_sm_fm_multiply(matrix, fm_in, fm_out, ncol, alpha, beta)
multiply a dbcsr with a fm matrix
subroutine, public copy_dbcsr_to_fm(matrix, fm)
Copy a DBCSR matrix to a BLACS matrix.
subroutine, public cp_dbcsr_m_by_n_from_row_template(matrix, template, n, sym)
Utility function to create dbcsr matrix, m x n matrix (n arbitrary) with the same processor grid and ...
subroutine, public copy_fm_to_dbcsr(fm, matrix, keep_sparsity)
Copy a BLACS matrix to a dbcsr matrix.
DBCSR output in CP2K.
subroutine, public write_fm_with_basis_info(blacs_matrix, before, after, qs_env, para_env, first_row, last_row, first_col, last_col, output_unit, omit_headers)
Print a spherical matrix of blacs type.
Basic linear algebra operations for full matrices.
subroutine, public cp_fm_row_scale(matrixa, scaling)
scales row i of matrix a with scaling(i)
subroutine, public cp_fm_column_scale(matrixa, scaling)
scales column i of matrix a with scaling(i)
subroutine, public cp_fm_transpose(matrix, matrixt)
transposes a matrix matrixt = matrix ^ T
subroutine, public cp_fm_triangular_invert(matrix_a, uplo_tr)
inverts a triangular matrix
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,...
used for collecting some of the diagonalization schemes available for cp_fm_type. cp_fm_power also mo...
Definition cp_fm_diag.F:17
subroutine, public cp_fm_power(matrix, work, exponent, threshold, n_dependent, verbose, eigvals)
...
integer, parameter, public fm_diag_type_cusolver
Definition cp_fm_diag.F:106
logical, save, public direct_generalized_diagonalization
Definition cp_fm_diag.F:100
subroutine, public choose_eigv_solver(matrix, eigenvectors, eigenvalues, info)
Choose the Eigensolver depending on which library is available ELPA seems to be unstable for small sy...
Definition cp_fm_diag.F:245
integer, save, public diag_type
Definition cp_fm_diag.F:88
integer, parameter, public cusolver_n_min
Definition cp_fm_diag.F:94
pool for for elements that are retained and released
type(cp_fm_struct_type) function, pointer, public fm_pool_get_el_struct(pool)
returns the structure of the elements in this pool
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_get(fmstruct, para_env, context, descriptor, ncol_block, nrow_block, nrow_global, ncol_global, first_p_pos, row_indices, col_indices, nrow_local, ncol_local, nrow_locals, ncol_locals, local_leading_dimension)
returns the values of various attributes of the matrix structure
subroutine, public cp_fm_struct_release(fmstruct)
releases a full matrix structure
represent a full matrix distributed on many processors
Definition cp_fm_types.F:15
subroutine, public cp_fm_get_info(matrix, name, nrow_global, ncol_global, nrow_block, ncol_block, nrow_local, ncol_local, row_indices, col_indices, local_data, context, nrow_locals, ncol_locals, matrix_struct, para_env)
returns all kind of information about the full matrix
subroutine, public cp_fm_set_all(matrix, alpha, beta)
set all elements of a matrix to the same value, and optionally the diagonal to a different one
subroutine, public cp_fm_create(matrix, matrix_struct, name, nrow, ncol, set_zero)
creates a new full matrix with the given structure
subroutine, public cp_fm_to_fm_triangular(msource, mtarget, uplo)
copy just a triangular matrix
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...
subroutine, public ao_boundaries(probe, atomic_kind_set, qs_kind_set, particle_set, nao)
...
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public smeagol_runtype_emtransport
integer, parameter, public wfi_frozen_method_nr
integer, parameter, public diag_block_krylov
integer, parameter, public broy_mix
integer, parameter, public plus_u_lowdin
integer, parameter, public pulay_mix
integer, parameter, public cholesky_dbcsr
integer, parameter, public direct_p_mix
integer, parameter, public wfi_use_guess_method_nr
integer, parameter, public modified_broy_mix
integer, parameter, public cholesky_off
integer, parameter, public no_mix
integer, parameter, public kerker_mix
integer, parameter, public cholesky_inverse
integer, parameter, public diag_ot
integer, parameter, public plus_u_tensorial
integer, parameter, public diag_filter_matrix
integer, parameter, public multisec_mix
integer, parameter, public new_pulay_mix
integer, parameter, public diag_block_davidson
integer, parameter, public wfi_ps_method_nr
integer, parameter, public outer_scf_none
integer, parameter, public diag_standard
integer, parameter, public ot2cdft
objects that represent the structure of input sections and the data contained in an input section
recursive type(section_vals_type) function, pointer, public section_vals_get_subs_vals(section_vals, subsection_name, i_rep_section, can_return_null)
returns the values of the requested subsection
subroutine, public section_vals_val_get(section_vals, keyword_name, i_rep_section, i_rep_val, n_rep_val, val, l_val, i_val, r_val, c_val, l_vals, i_vals, r_vals, c_vals, explicit)
returns the requested value
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
Types and basic routines needed for a kpoint calculation.
Interface to the message passing library MPI.
basic linear algebra operations for full matrixes
Define the data structure for the particle information.
Routines for image charge calculation within QM/MM.
subroutine, public conditional_calc_image_matrix(qs_env, qmmm_env)
calculate image matrix T depending on constraints on image atoms in case coefficients are estimated n...
module that contains the algorithms to perform an iterative diagonalization by the block-Davidson app...
subroutine, public block_davidson_allocate(bdav_env, mo_coeff, nao, nmo)
...
subroutine, public block_davidson_env_create(bdav_env, nspins, scf_section)
...
Control parameters for optimizers that work with CDFT constraints.
subroutine, public cdft_opt_type_copy(new, old)
copies settings between two CDFT optimizer control objects retaining both
module that contains the definitions of the scf types
subroutine, public mixing_storage_release(mixing_store)
releases a mixing_storage
integer, parameter, public no_mixing_nr
integer, parameter, public direct_mixing_nr
subroutine, public mixing_storage_create(mixing_store, mixing_section, mixing_method, ecut)
creates a mixing_storage
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.
subroutine, public fb_distribution_build(fb_env, qs_env, scf_section)
Build local atoms associated to filter matrix algorithm for each MPI process, trying to balance the l...
subroutine, public fb_env_read_input(fb_env, scf_section)
Read input sections for filter matrix method.
subroutine, public fb_env_build_atomic_halos(fb_env, qs_env, scf_section)
Builds an fb_atomic_halo_list object using information from fb_env.
subroutine, public fb_env_write_info(fb_env, qs_env, scf_section)
Write out parameters used for the filter matrix method to output.
subroutine, public fb_env_build_rcut_auto(fb_env, qs_env)
Automatically generate the cutoff radii of atoms used for constructing the atomic halos,...
logical function, public fb_env_has_data(fb_env)
Checks if a fb_env object is associated with an actual data content or not.
subroutine, public fb_env_create(fb_env)
creates an empty fb_env object
Types needed for a for a Harris model calculation.
Harris method environment setup and handling.
subroutine, public harris_density_update(qs_env, harris_env)
...
Routines to somehow generate an initial guess.
subroutine, public calculate_first_density_matrix(scf_env, qs_env)
can use a variety of methods to come up with an initial density matrix and optionally an initial wave...
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_qs_kind(qs_kind, paw_atom, ghost, floating, hard_radius, hard0_radius, covalent_radius, vdw_radius, lmax_rho0, zeff, no_optimize, dispersion, u_minus_j, hund_j, reltmat, dftb_parameter, xtb_parameter, elec_conf, pao_basis_size)
Set the components of an atomic kind data set.
subroutine, public qs_ks_did_change(ks_env, s_mstruct_changed, rho_changed, potential_changed, full_reset)
tells that some of the things relevant to the ks calculation did change. has to be called when change...
wrapper for the pools of matrixes
subroutine, public mpools_get(mpools, ao_mo_fm_pools, ao_ao_fm_pools, mo_mo_fm_pools, ao_mosub_fm_pools, mosub_mosub_fm_pools, maxao_maxmo_fm_pool, maxao_maxao_fm_pool, maxmo_maxmo_fm_pool)
returns various attributes of the mpools (notably the pools contained in it)
elemental subroutine, public charge_mixing_init(mixing_store)
initialiation needed when charge mixing is used
subroutine, public mixing_init(mixing_method, rho, mixing_store, para_env, rho_atom)
initialiation needed when gspace mixing is used
subroutine, public mixing_allocate(qs_env, mixing_method, p_mix_new, p_delta, nspins, mixing_store)
allocation needed when density mixing is used
Set occupation of molecular orbitals.
Definition and initialisation of the mo data type.
Definition qs_mo_types.F:22
subroutine, public set_mo_set(mo_set, maxocc, homo, lfomo, nao, nelectron, n_el_f, nmo, eigenvalues, occupation_numbers, uniform_occupation, kts, mu, flexible_electron_count)
Set the components of a MO set data structure.
subroutine, public init_mo_set(mo_set, fm_pool, fm_ref, fm_struct, name, counter)
initializes an allocated mo_set. eigenvalues, mo_coeff, occupation_numbers are valid only after this ...
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.
Routines for performing an outer scf loop.
subroutine, public outer_loop_switch(scf_env, scf_control, cdft_control, dir)
switch between two outer_scf envs stored in cdft_control
subroutine, public outer_loop_extrapolate(qs_env)
uses the outer_scf_history to extrapolate new values for the variables and updates their value in qs_...
integer function, public outer_loop_variables_count(scf_control, cdft_control)
returns the number of variables that is employed in the outer loop. with a CDFT constraint this value...
methods of the rho structure (defined in qs_rho_types)
subroutine, public qs_rho_update_rho(rho_struct, qs_env, rho_xc_external, local_rho_set, task_list_external, task_list_external_soft, pw_env_external, para_env_external)
updates rho_r and rho_g to the rhorho_ao. if use_kinetic_energy_density also computes tau_r and tau_g...
subroutine, public duplicate_rho_type(rho_input, rho_output, qs_env)
Duplicates a pointer physically.
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...
subroutine, public qs_rho_create(rho)
Allocates a new instance of rho.
Different diagonalization schemes that can be used for the iterative solution of the eigenvalue probl...
subroutine, public diag_subspace_allocate(subspace_env, qs_env, mos)
...
subroutine, public diag_kp_smat(matrix_s, kpoints, fmwork)
Kpoint diagonalization routine Transforms matrices to kpoint, distributes kpoint groups,...
Utility routines for qs_scf.
subroutine, public qs_scf_env_init_basic(qs_env, scf_env)
initializes input parameters if needed for non-scf calclulations using diagonalization
subroutine, public qs_scf_env_initialize(qs_env, scf_env, scf_control, scf_section)
initializes input parameters if needed or restores values from previous runs to fill scf_env with the...
module that contains the algorithms to perform an iterative diagonalization by the block-Lanczos appr...
subroutine, public krylov_space_allocate(krylov_space, scf_control, mos)
allocates matrices and vectors used in the construction of the krylov space and for the lanczos refin...
subroutine, public qs_scf_initial_info(output_unit, mos, dft_control, ndep)
writes basic information at the beginning of an scf run
module that contains the definitions of the scf types
integer, parameter, public ot_diag_method_nr
subroutine, public krylov_space_create(krylov_space, scf_section)
creates krylov space
subroutine, public diag_subspace_env_create(subspace_env, scf_section, ecut)
creates subspace-rotation environment
integer, parameter, public filter_matrix_diag_method_nr
integer, parameter, public block_davidson_diag_method_nr
integer, parameter, public smeagol_method_nr
integer, parameter, public ot_method_nr
subroutine, public scf_env_create(scf_env)
allocates and initialize an scf_env
integer, parameter, public special_diag_method_nr
integer, parameter, public block_krylov_diag_method_nr
integer, parameter, public general_diag_method_nr
Storage of past states of the qs_env. Methods to interpolate (or actually normally extrapolate) the n...
character(len=30) function, public wfi_get_method_label(method_nr)
returns a string describing the interpolation method
subroutine, public reorthogonalize_vectors(qs_env, v_matrix, n_col)
reorthogonalizes the mos
subroutine, public wfi_update(wf_history, qs_env, dt)
updates the snapshot buffer, taking a new snapshot
subroutine, public wfi_extrapolate(wf_history, qs_env, dt, extrapolation_method_nr, orthogonal_wf)
calculates the new starting state for the scf for the next wf optimization
parameters that control an scf iteration
define create destroy get and put information in xas_env to calculate the x-ray absorption spectra
Initialize the XAS orbitals for specific core excitations Either the GS orbitals are used as initial ...
Definition xas_restart.F:20
subroutine, public xas_initialize_rho(qs_env, scf_env, scf_control)
Once the mos and the occupation numbers are initialized the electronic density of the excited state c...
Provides all information about an atomic kind.
keeps the information about the structure of a full matrix
represent a full matrix
type of a logger, at the moment it contains just a print level starting at which level it should be l...
Contains information about kpoints.
stores all the informations relevant to an mpi environment
Contains information on the Harris method.
Provides all information about a quickstep kind.
keeps the density in various representations, keeping track of which ones are valid.