130#include "./base/base_uses.f90"
135 LOGICAL,
PRIVATE,
PARAMETER :: debug_this_module = .true.
136 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'qs_wf_history_methods'
152 SUBROUTINE wfs_create(snapshot)
153 TYPE(qs_wf_snapshot_type),
INTENT(OUT) :: snapshot
155 NULLIFY (snapshot%wf, snapshot%rho_r, &
156 snapshot%rho_g, snapshot%rho_ao, snapshot%rho_ao_kp, &
157 snapshot%overlap, snapshot%wf_kp, snapshot%wf_kp_cfm, snapshot%overlap_cfm_kp, &
158 snapshot%kp_pbc_shift, snapshot%rho_frozen)
160 END SUBROUTINE wfs_create
173 SUBROUTINE wfs_update(snapshot, wf_history, qs_env, dt)
174 TYPE(qs_wf_snapshot_type),
POINTER :: snapshot
175 TYPE(qs_wf_history_type),
POINTER :: wf_history
176 TYPE(qs_environment_type),
POINTER :: qs_env
177 REAL(KIND=
dp),
INTENT(in),
OPTIONAL :: dt
179 CHARACTER(len=*),
PARAMETER :: routineN =
'wfs_update'
181 INTEGER :: handle, ikp, img, ispin, kplocal, nimg, &
183 INTEGER,
DIMENSION(2) :: kp_range
184 LOGICAL :: use_real_wfn
185 TYPE(cell_type),
POINTER :: cell
186 TYPE(cp_fm_pool_p_type),
DIMENSION(:),
POINTER :: ao_mo_pools
187 TYPE(cp_fm_type),
POINTER :: mo_coeff
188 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_s, rho_ao
189 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: rho_ao_kp
190 TYPE(dft_control_type),
POINTER :: dft_control
191 TYPE(kpoint_env_type),
POINTER :: kp
192 TYPE(kpoint_type),
POINTER :: kpoints
193 TYPE(mo_set_type),
DIMENSION(:),
POINTER :: mos
194 TYPE(particle_type),
DIMENSION(:),
POINTER :: particle_set
195 TYPE(pw_c1d_gs_type),
DIMENSION(:),
POINTER :: rho_g
196 TYPE(pw_env_type),
POINTER :: pw_env
197 TYPE(pw_pool_type),
POINTER :: auxbas_pw_pool
198 TYPE(pw_r3d_rs_type),
DIMENSION(:),
POINTER :: rho_r
199 TYPE(qs_rho_type),
POINTER :: rho
201 CALL timeset(routinen, handle)
203 NULLIFY (pw_env, auxbas_pw_pool, ao_mo_pools, dft_control, mos, mo_coeff, &
204 rho, rho_r, rho_g, rho_ao, matrix_s, kpoints, kp, cell, particle_set)
206 dft_control=dft_control, rho=rho, cell=cell, particle_set=particle_set)
207 CALL mpools_get(qs_env%mpools, ao_mo_fm_pools=ao_mo_pools)
208 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
210 cpassert(
ASSOCIATED(wf_history))
211 cpassert(
ASSOCIATED(dft_control))
212 IF (.NOT.
ASSOCIATED(snapshot))
THEN
214 CALL wfs_create(snapshot)
216 cpassert(wf_history%ref_count > 0)
218 nspins = dft_control%nspins
220 IF (
PRESENT(dt)) snapshot%dt = dt
221 IF (wf_history%store_wf)
THEN
223 IF (.NOT.
ASSOCIATED(snapshot%wf))
THEN
226 cpassert(nspins ==
SIZE(snapshot%wf))
229 CALL get_mo_set(mos(ispin), mo_coeff=mo_coeff)
236 IF (wf_history%store_rho_r)
THEN
238 cpassert(
ASSOCIATED(rho_r))
239 IF (.NOT.
ASSOCIATED(snapshot%rho_r))
THEN
240 ALLOCATE (snapshot%rho_r(nspins))
242 CALL auxbas_pw_pool%create_pw(snapshot%rho_r(ispin))
246 CALL pw_copy(rho_r(ispin), snapshot%rho_r(ispin))
248 ELSE IF (
ASSOCIATED(snapshot%rho_r))
THEN
249 DO ispin = 1,
SIZE(snapshot%rho_r)
250 CALL auxbas_pw_pool%give_back_pw(snapshot%rho_r(ispin))
252 DEALLOCATE (snapshot%rho_r)
255 IF (wf_history%store_rho_g)
THEN
257 cpassert(
ASSOCIATED(rho_g))
258 IF (.NOT.
ASSOCIATED(snapshot%rho_g))
THEN
259 ALLOCATE (snapshot%rho_g(nspins))
261 CALL auxbas_pw_pool%create_pw(snapshot%rho_g(ispin))
265 CALL pw_copy(rho_g(ispin), snapshot%rho_g(ispin))
267 ELSE IF (
ASSOCIATED(snapshot%rho_g))
THEN
268 DO ispin = 1,
SIZE(snapshot%rho_g)
269 CALL auxbas_pw_pool%give_back_pw(snapshot%rho_g(ispin))
271 DEALLOCATE (snapshot%rho_g)
274 IF (
ASSOCIATED(snapshot%rho_ao))
THEN
278 IF (wf_history%store_rho_ao)
THEN
280 cpassert(
ASSOCIATED(rho_ao))
284 ALLOCATE (snapshot%rho_ao(ispin)%matrix)
285 CALL dbcsr_copy(snapshot%rho_ao(ispin)%matrix, rho_ao(ispin)%matrix)
289 IF (
ASSOCIATED(snapshot%rho_ao_kp))
THEN
293 IF (wf_history%store_rho_ao_kp)
THEN
295 cpassert(
ASSOCIATED(rho_ao_kp))
297 nimg = dft_control%nimages
301 ALLOCATE (snapshot%rho_ao_kp(ispin, img)%matrix)
302 CALL dbcsr_copy(snapshot%rho_ao_kp(ispin, img)%matrix, &
303 rho_ao_kp(ispin, img)%matrix)
308 IF (
ASSOCIATED(snapshot%overlap))
THEN
312 IF (wf_history%store_overlap)
THEN
314 cpassert(
ASSOCIATED(matrix_s))
315 cpassert(
ASSOCIATED(matrix_s(1)%matrix))
316 ALLOCATE (snapshot%overlap)
317 CALL dbcsr_copy(snapshot%overlap, matrix_s(1)%matrix)
321 IF (
ASSOCIATED(kpoints))
THEN
322 IF (
ASSOCIATED(kpoints%kp_env))
THEN
324 IF (wf_history%store_wf_kp)
THEN
325 CALL get_kpoint_info(kpoints, kp_range=kp_range, use_real_wfn=use_real_wfn)
326 kplocal = kp_range(2) - kp_range(1) + 1
327 nspin_kp =
SIZE(kpoints%kp_env(1)%kpoint_env%mos)
329 CALL wfi_store_kp_pbc_shift(snapshot, cell, particle_set)
331 IF (
ASSOCIATED(snapshot%wf_kp))
THEN
334 IF (
ASSOCIATED(snapshot%wf_kp_cfm))
THEN
335 DO ikp = 1,
SIZE(snapshot%wf_kp_cfm, 1)
336 DO ispin = 1,
SIZE(snapshot%wf_kp_cfm, 2)
340 DEALLOCATE (snapshot%wf_kp_cfm)
343 IF (use_real_wfn)
THEN
344 ALLOCATE (snapshot%wf_kp(kplocal, nspin_kp))
346 ALLOCATE (snapshot%wf_kp_cfm(kplocal, nspin_kp))
349 kp => kpoints%kp_env(ikp)%kpoint_env
350 DO ispin = 1, nspin_kp
351 IF (use_real_wfn)
THEN
352 CALL get_mo_set(kp%mos(ispin), mo_coeff=mo_coeff)
353 CALL cp_fm_create(snapshot%wf_kp(ikp, ispin), mo_coeff%matrix_struct, &
355 CALL cp_fm_to_fm(mo_coeff, snapshot%wf_kp(ikp, ispin))
358 kp%mos(ispin)%cmo_coeff%matrix_struct, name=
"wfkp_snap")
359 CALL cp_cfm_to_cfm(kp%mos(ispin)%cmo_coeff, snapshot%wf_kp_cfm(ikp, ispin))
365 IF (wf_history%store_overlap_kp)
CALL wfs_overlap_kp(snapshot, qs_env)
369 IF (wf_history%store_frozen_density)
THEN
374 CALL timestop(handle)
376 END SUBROUTINE wfs_update
385 SUBROUTINE wfs_overlap_kp(snapshot, qs_env)
386 TYPE(qs_wf_snapshot_type),
INTENT(INOUT) :: snapshot
387 TYPE(qs_environment_type),
POINTER :: qs_env
389 CHARACTER(LEN=*),
PARAMETER :: routineN =
'wfs_overlap_kp'
391 INTEGER :: handle, ikp, kplocal, use_cache
392 TYPE(cp_fm_pool_type),
POINTER :: ao_ao_fm_pool
393 TYPE(cp_fm_struct_type),
POINTER :: matrix_struct
394 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_s
395 TYPE(kpoint_type),
POINTER :: kpoints
396 TYPE(mp_para_env_type),
POINTER :: para_env
397 TYPE(qs_scf_env_type),
POINTER :: scf_env
399 CALL timeset(routinen, handle)
400 CALL get_qs_env(qs_env, kpoints=kpoints, matrix_s_kp=matrix_s, scf_env=scf_env)
401 para_env => kpoints%blacs_env_all%para_env
402 kplocal =
SIZE(kpoints%kp_env)
403 cpassert(kplocal > 0)
404 CALL mpools_get(kpoints%mpools, ao_ao_fm_pool=ao_ao_fm_pool)
409 IF (
ALLOCATED(kpoints%scf_smat))
THEN
410 IF (
SIZE(kpoints%scf_smat) == kplocal)
THEN
417 CALL para_env%min(use_cache)
419 IF (
ASSOCIATED(snapshot%overlap_cfm_kp))
THEN
420 DO ikp = 1,
SIZE(snapshot%overlap_cfm_kp)
423 DEALLOCATE (snapshot%overlap_cfm_kp)
425 ALLOCATE (snapshot%overlap_cfm_kp(kplocal))
428 CALL cp_cfm_create(snapshot%overlap_cfm_kp(ikp), matrix_struct)
431 IF (use_cache == 1)
THEN
433 CALL cp_cfm_to_cfm(kpoints%scf_smat(ikp), snapshot%overlap_cfm_kp(ikp))
439 CALL timestop(handle)
441 END SUBROUTINE wfs_overlap_kp
455 SUBROUTINE wfi_create(wf_history, interpolation_method_nr, extrapolation_order, &
458 INTEGER,
INTENT(in) :: interpolation_method_nr, &
460 LOGICAL,
INTENT(IN) :: has_unit_metric
462 CHARACTER(len=*),
PARAMETER :: routinen =
'wfi_create'
466 CALL timeset(routinen, handle)
468 ALLOCATE (wf_history)
469 wf_history%ref_count = 1
470 wf_history%memory_depth = 0
471 wf_history%snapshot_count = 0
472 wf_history%last_state_index = 1
473 wf_history%store_wf = .false.
474 wf_history%store_rho_r = .false.
475 wf_history%store_rho_g = .false.
476 wf_history%store_rho_ao = .false.
477 wf_history%store_rho_ao_kp = .false.
478 wf_history%store_overlap = .false.
479 wf_history%store_wf_kp = .false.
480 wf_history%store_overlap_kp = .false.
481 wf_history%store_frozen_density = .false.
482 NULLIFY (wf_history%past_states)
484 wf_history%interpolation_method_nr = interpolation_method_nr
486 SELECT CASE (wf_history%interpolation_method_nr)
488 wf_history%memory_depth = 0
490 wf_history%memory_depth = 0
492 wf_history%memory_depth = 1
493 wf_history%store_rho_ao = .true.
495 wf_history%memory_depth = 2
496 wf_history%store_wf = .true.
498 wf_history%memory_depth = 2
499 wf_history%store_rho_ao = .true.
501 wf_history%memory_depth = 2
502 wf_history%store_wf = .true.
503 IF (.NOT. has_unit_metric) wf_history%store_overlap = .true.
506 wf_history%memory_depth = extrapolation_order + 1
507 wf_history%store_wf = .true.
508 wf_history%store_wf_kp = .true.
509 IF (.NOT. has_unit_metric)
THEN
510 wf_history%store_overlap = .true.
511 wf_history%store_overlap_kp = .true.
514 wf_history%memory_depth = 1
515 wf_history%store_frozen_density = .true.
517 wf_history%memory_depth = extrapolation_order + 2
518 wf_history%store_wf = .true.
519 wf_history%store_wf_kp = .true.
520 IF (.NOT. has_unit_metric)
THEN
521 wf_history%store_overlap = .true.
522 wf_history%store_overlap_kp = .true.
525 wf_history%memory_depth = extrapolation_order
526 wf_history%store_wf = .true.
527 wf_history%store_wf_kp = .true.
528 wf_history%store_overlap = .true.
529 wf_history%store_overlap_kp = .true.
531 wf_history%memory_depth = extrapolation_order
532 wf_history%store_wf = .true.
533 wf_history%store_wf_kp = .true.
534 wf_history%store_overlap = .true.
535 wf_history%store_overlap_kp = .true.
537 CALL cp_abort(__location__, &
538 "Unknown interpolation method: "// &
541 ALLOCATE (wf_history%past_states(wf_history%memory_depth))
543 DO i = 1,
SIZE(wf_history%past_states)
544 NULLIFY (wf_history%past_states(i)%snapshot)
547 CALL timestop(handle)
564 cpassert(
ASSOCIATED(wf_history))
565 IF (wf_history%store_rho_ao)
THEN
566 wf_history%store_rho_ao_kp = .true.
567 wf_history%store_rho_ao = .false.
573 wf_history%memory_depth = 1
574 wf_history%store_wf_kp = .true.
575 wf_history%store_wf = .false.
576 wf_history%store_overlap = .false.
577 IF (
ASSOCIATED(wf_history%past_states))
DEALLOCATE (wf_history%past_states)
578 ALLOCATE (wf_history%past_states(wf_history%memory_depth))
579 DO i = 1,
SIZE(wf_history%past_states)
580 NULLIFY (wf_history%past_states(i)%snapshot)
582 ELSE IF (wf_history%store_wf_kp)
THEN
583 wf_history%store_wf = .false.
584 wf_history%store_overlap = .false.
588 IF (wf_history%store_wf .OR. wf_history%store_overlap)
THEN
589 CALL cp_abort(__location__, &
590 "Linear WFN-based extrapolation methods not implemented for k-points.")
593 IF (wf_history%store_frozen_density)
THEN
594 cpabort(
"Frozen density initialization method not possible for kpoints.")
608 INTEGER,
INTENT(in) :: method_nr
609 CHARACTER(len=30) :: res
612 SELECT CASE (method_nr)
618 res =
"initial_guess"
628 res =
"frozen density approximation"
634 res =
"GEXT_PROJ_QTR"
636 CALL cp_abort(__location__, &
637 "Unknown interpolation method: "// &
661 REAL(kind=
dp),
INTENT(IN) :: dt
662 INTEGER,
INTENT(OUT),
OPTIONAL :: extrapolation_method_nr
663 LOGICAL,
INTENT(OUT),
OPTIONAL :: orthogonal_wf
665 CHARACTER(len=*),
PARAMETER :: routinen =
'wfi_extrapolate'
667 INTEGER :: actual_extrapolation_method_nr, handle, &
668 i, img, io_unit, ispin, k, n, nmo, &
670 LOGICAL :: do_kpoints, my_orthogonal_wf, use_overlap
671 REAL(kind=
dp) :: alpha, t0, t1, t2
672 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: coeffs
678 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_s, rho_ao, rho_frozen_ao
679 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: rho_ao_kp
684 NULLIFY (mos, ao_mo_fm_pools, t0_state, t1_state, mo_coeff, &
685 rho, rho_ao, rho_frozen_ao)
687 use_overlap = wf_history%store_overlap
689 CALL timeset(routinen, handle)
691 print_level = logger%iter_info%print_level
695 cpassert(
ASSOCIATED(wf_history))
696 cpassert(wf_history%ref_count > 0)
697 cpassert(
ASSOCIATED(qs_env))
698 CALL get_qs_env(qs_env, mos=mos, rho=rho, do_kpoints=do_kpoints)
699 CALL mpools_get(qs_env%mpools, ao_mo_fm_pools=ao_mo_fm_pools)
701 IF (wf_history%snapshot_count < 1)
THEN
704 actual_extrapolation_method_nr = wf_history%interpolation_method_nr
707 SELECT CASE (actual_extrapolation_method_nr)
709 IF (wf_history%snapshot_count < 2)
THEN
713 IF (wf_history%snapshot_count < 2)
THEN
717 IF (wf_history%snapshot_count < 2)
THEN
722 IF (
PRESENT(extrapolation_method_nr))
THEN
723 extrapolation_method_nr = actual_extrapolation_method_nr
725 my_orthogonal_wf = .false.
727 SELECT CASE (actual_extrapolation_method_nr)
729 cpassert(.NOT. do_kpoints)
731 cpassert(
ASSOCIATED(t0_state%rho_frozen))
733 nvec = min(wf_history%memory_depth, wf_history%snapshot_count)
734 CALL wfi_set_history_variables(qs_env=qs_env, nvec=nvec)
736 CALL qs_rho_get(t0_state%rho_frozen, rho_ao=rho_frozen_ao)
738 DO ispin = 1,
SIZE(rho_frozen_ao)
740 rho_frozen_ao(ispin)%matrix, &
741 keep_sparsity=.true.)
748 my_orthogonal_wf = .false.
751 nvec = min(wf_history%memory_depth, wf_history%snapshot_count)
752 CALL wfi_set_history_variables(qs_env=qs_env, nvec=nvec)
754 cpassert(
ASSOCIATED(t0_state%rho_ao_kp))
756 DO ispin = 1,
SIZE(t0_state%rho_ao_kp, 1)
757 DO img = 1,
SIZE(t0_state%rho_ao_kp, 2)
758 IF (img >
SIZE(rho_ao_kp, 2))
THEN
759 CALL cp_warn(__location__, &
760 "Change in cell neighborlist: might affect quality of initial guess")
762 CALL dbcsr_copy(rho_ao_kp(ispin, img)%matrix, &
763 t0_state%rho_ao_kp(ispin, img)%matrix, &
764 keep_sparsity=.true.)
769 cpassert(
ASSOCIATED(t0_state%rho_ao))
771 DO ispin = 1,
SIZE(t0_state%rho_ao)
773 t0_state%rho_ao(ispin)%matrix, &
774 keep_sparsity=.true.)
782 my_orthogonal_wf = .true.
783 nvec = min(wf_history%memory_depth, wf_history%snapshot_count)
784 CALL wfi_set_history_variables(qs_env=qs_env, nvec=nvec)
787 CALL wfi_use_prev_wf_kp(qs_env, io_unit, print_level)
790 DO ispin = 1,
SIZE(mos)
791 CALL get_mo_set(mos(ispin), mo_coeff=mo_coeff, nmo=nmo)
805 nvec = min(wf_history%memory_depth, wf_history%snapshot_count)
806 CALL wfi_set_history_variables(qs_env=qs_env, nvec=nvec)
808 cpassert(.NOT. do_kpoints)
811 cpassert(
ASSOCIATED(t0_state))
812 cpassert(
ASSOCIATED(t1_state))
813 cpassert(
ASSOCIATED(t0_state%wf))
814 cpassert(
ASSOCIATED(t1_state%wf))
815 nvec = min(wf_history%memory_depth, wf_history%snapshot_count)
816 CALL wfi_set_history_variables(qs_env=qs_env, nvec=nvec)
818 my_orthogonal_wf = .true.
823 DO ispin = 1,
SIZE(mos)
824 CALL get_mo_set(mos(ispin), mo_coeff=mo_coeff, &
828 matrix_b=t1_state%wf(ispin), &
829 beta=(t2 - t0)/(t1 - t0))
833 beta=(t1 - t2)/(t1 - t0), matrix_b=t0_state%wf(ispin))
838 density_matrix=rho_ao(ispin)%matrix)
847 cpassert(
ASSOCIATED(t0_state))
848 cpassert(
ASSOCIATED(t1_state))
850 cpassert(
ASSOCIATED(t0_state%rho_ao_kp))
851 cpassert(
ASSOCIATED(t1_state%rho_ao_kp))
853 cpassert(
ASSOCIATED(t0_state%rho_ao))
854 cpassert(
ASSOCIATED(t1_state%rho_ao))
856 nvec = min(wf_history%memory_depth, wf_history%snapshot_count)
857 CALL wfi_set_history_variables(qs_env=qs_env, nvec=nvec)
864 DO ispin = 1,
SIZE(rho_ao_kp, 1)
865 DO img = 1,
SIZE(rho_ao_kp, 2)
866 IF (img >
SIZE(t0_state%rho_ao_kp, 2) .OR. &
867 img >
SIZE(t1_state%rho_ao_kp, 2))
THEN
868 CALL cp_warn(__location__, &
869 "Change in cell neighborlist: might affect quality of initial guess")
871 CALL dbcsr_add(rho_ao_kp(ispin, img)%matrix, t1_state%rho_ao_kp(ispin, img)%matrix, &
872 alpha_scalar=0.0_dp, beta_scalar=(t2 - t0)/(t1 - t0))
873 CALL dbcsr_add(rho_ao_kp(ispin, img)%matrix, t0_state%rho_ao_kp(ispin, img)%matrix, &
874 alpha_scalar=1.0_dp, beta_scalar=(t1 - t2)/(t1 - t0))
880 DO ispin = 1,
SIZE(rho_ao)
881 CALL dbcsr_add(rho_ao(ispin)%matrix, t1_state%rho_ao(ispin)%matrix, &
882 alpha_scalar=0.0_dp, beta_scalar=(t2 - t0)/(t1 - t0))
883 CALL dbcsr_add(rho_ao(ispin)%matrix, t0_state%rho_ao(ispin)%matrix, &
884 alpha_scalar=1.0_dp, beta_scalar=(t1 - t2)/(t1 - t0))
892 cpassert(.NOT. do_kpoints)
895 cpassert(
ASSOCIATED(t0_state))
896 cpassert(
ASSOCIATED(t1_state))
897 cpassert(
ASSOCIATED(t0_state%wf))
898 cpassert(
ASSOCIATED(t1_state%wf))
899 IF (wf_history%store_overlap)
THEN
900 cpassert(
ASSOCIATED(t0_state%overlap))
901 cpassert(
ASSOCIATED(t1_state%overlap))
903 nvec = min(wf_history%memory_depth, wf_history%snapshot_count)
904 IF (nvec >= wf_history%memory_depth)
THEN
905 IF ((qs_env%scf_control%max_scf_hist /= 0) .AND. (qs_env%scf_control%eps_scf_hist /= 0))
THEN
906 qs_env%scf_control%max_scf = qs_env%scf_control%max_scf_hist
907 qs_env%scf_control%eps_scf = qs_env%scf_control%eps_scf_hist
908 qs_env%scf_control%outer_scf%have_scf = .false.
909 ELSE IF (qs_env%scf_control%max_scf_hist /= 0)
THEN
910 qs_env%scf_control%max_scf = qs_env%scf_control%max_scf_hist
911 qs_env%scf_control%outer_scf%have_scf = .false.
912 ELSE IF (qs_env%scf_control%eps_scf_hist /= 0)
THEN
913 qs_env%scf_control%eps_scf = qs_env%scf_control%eps_scf_hist
917 my_orthogonal_wf = .true.
921 DO ispin = 1,
SIZE(mos)
922 NULLIFY (mo_coeff, matrix_struct, matrix_struct_new)
923 CALL get_mo_set(mo_set=mos(ispin), mo_coeff=mo_coeff)
925 matrix_struct=matrix_struct)
927 nrow_global=k, ncol_global=k)
931 IF (use_overlap)
THEN
933 CALL parallel_gemm(
'T',
'N', k, k, n, 1.0_dp, t0_state%wf(ispin), mo_coeff, 0.0_dp, csc)
935 CALL parallel_gemm(
'T',
'N', k, k, n, 1.0_dp, t0_state%wf(ispin), &
936 t1_state%wf(ispin), 0.0_dp, csc)
938 CALL parallel_gemm(
'N',
'N', n, k, k, 1.0_dp, t0_state%wf(ispin), csc, 0.0_dp, mo_coeff)
945 density_matrix=rho_ao(ispin)%matrix)
952 nvec = min(wf_history%memory_depth, wf_history%snapshot_count)
954 IF (nvec >= wf_history%memory_depth)
THEN
955 IF ((qs_env%scf_control%max_scf_hist /= 0) .AND. (qs_env%scf_control%eps_scf_hist /= 0))
THEN
956 qs_env%scf_control%max_scf = qs_env%scf_control%max_scf_hist
957 qs_env%scf_control%eps_scf = qs_env%scf_control%eps_scf_hist
958 qs_env%scf_control%outer_scf%have_scf = .false.
959 ELSE IF (qs_env%scf_control%max_scf_hist /= 0)
THEN
960 qs_env%scf_control%max_scf = qs_env%scf_control%max_scf_hist
961 qs_env%scf_control%outer_scf%have_scf = .false.
962 ELSE IF (qs_env%scf_control%eps_scf_hist /= 0)
THEN
963 qs_env%scf_control%eps_scf = qs_env%scf_control%eps_scf_hist
968 CALL wfi_extrapolate_ps_aspc_kp(wf_history, qs_env, nvec, io_unit, print_level)
969 my_orthogonal_wf = .true.
971 my_orthogonal_wf = .true.
972 DO ispin = 1,
SIZE(mos)
973 NULLIFY (mo_coeff, matrix_struct, matrix_struct_new)
974 CALL get_mo_set(mo_set=mos(ispin), mo_coeff=mo_coeff)
976 matrix_struct=matrix_struct)
979 nrow_global=k, ncol_global=k)
990 IF (use_overlap)
THEN
992 CALL parallel_gemm(
'T',
'N', k, k, n, 1.0_dp, t0_state%wf(ispin), fm_tmp, 0.0_dp, csc)
994 CALL parallel_gemm(
'T',
'N', k, k, n, 1.0_dp, t0_state%wf(ispin), &
995 t1_state%wf(ispin), 0.0_dp, csc)
997 CALL parallel_gemm(
'N',
'N', n, k, k, 1.0_dp, t0_state%wf(ispin), csc, 0.0_dp, fm_tmp)
998 alpha = -1.0_dp*alpha*real(nvec - i + 1,
dp)/real(i,
dp)
1005 v_matrix=mo_coeff, &
1008 density_matrix=rho_ao(ispin)%matrix)
1018 nvec = min(wf_history%memory_depth, wf_history%snapshot_count)
1020 IF (nvec >= wf_history%memory_depth)
THEN
1021 IF ((qs_env%scf_control%max_scf_hist /= 0) .AND. &
1022 (qs_env%scf_control%eps_scf_hist /= 0))
THEN
1023 qs_env%scf_control%max_scf = qs_env%scf_control%max_scf_hist
1024 qs_env%scf_control%eps_scf = qs_env%scf_control%eps_scf_hist
1025 qs_env%scf_control%outer_scf%have_scf = .false.
1026 ELSE IF (qs_env%scf_control%max_scf_hist /= 0)
THEN
1027 qs_env%scf_control%max_scf = qs_env%scf_control%max_scf_hist
1028 qs_env%scf_control%outer_scf%have_scf = .false.
1029 ELSE IF (qs_env%scf_control%eps_scf_hist /= 0)
THEN
1030 qs_env%scf_control%eps_scf = qs_env%scf_control%eps_scf_hist
1034 IF (do_kpoints)
THEN
1035 CALL wfi_extrapolate_ps_aspc_kp(wf_history, qs_env, nvec, io_unit, print_level)
1036 my_orthogonal_wf = .true.
1038 my_orthogonal_wf = .true.
1040 DO ispin = 1,
SIZE(mos)
1041 NULLIFY (mo_coeff, matrix_struct, matrix_struct_new)
1042 CALL get_mo_set(mo_set=mos(ispin), mo_coeff=mo_coeff)
1046 matrix_struct=matrix_struct)
1047 CALL cp_fm_create(fm_tmp, matrix_struct, set_zero=.true.)
1049 template_fmstruct=matrix_struct, &
1052 CALL cp_fm_create(csc, matrix_struct_new, set_zero=.true.)
1058 alpha = real(4*nvec - 2, kind=
dp)/real(nvec + 1, kind=
dp)
1060 WRITE (unit=io_unit, fmt=
"(/,T2,A,/,/,T3,A,I0,/,/,T3,A2,I0,A4,F10.6)") &
1061 "Parameters for the always stable predictor-corrector (ASPC) method:", &
1062 "ASPC order: ", max(nvec - 2, 0), &
1063 "B(", 1,
") = ", alpha
1069 IF (use_overlap)
THEN
1071 CALL parallel_gemm(
'T',
'N', k, k, n, 1.0_dp, t0_state%wf(ispin), fm_tmp, 0.0_dp, csc)
1073 CALL parallel_gemm(
'T',
'N', k, k, n, 1.0_dp, t0_state%wf(ispin), &
1074 t1_state%wf(ispin), 0.0_dp, csc)
1076 CALL parallel_gemm(
'N',
'N', n, k, k, 1.0_dp, t0_state%wf(ispin), csc, 0.0_dp, fm_tmp)
1077 alpha = (-1.0_dp)**(i + 1)*real(i, kind=
dp)* &
1080 WRITE (unit=io_unit, fmt=
"(T3,A2,I0,A4,F10.6)") &
1081 "B(", i,
") = ", alpha
1088 v_matrix=mo_coeff, &
1091 density_matrix=rho_ao(ispin)%matrix)
1098 IF (do_kpoints)
THEN
1099 nvec = min(wf_history%memory_depth, wf_history%snapshot_count)
1101 CALL wfi_extrapolate_gext_proj_kp(wf_history, qs_env, nvec, io_unit, print_level)
1102 my_orthogonal_wf = .true.
1106 nvec = min(wf_history%memory_depth, wf_history%snapshot_count)
1107 IF (nvec >= wf_history%memory_depth)
THEN
1108 IF ((qs_env%scf_control%max_scf_hist /= 0) .AND. &
1109 (qs_env%scf_control%eps_scf_hist /= 0))
THEN
1110 qs_env%scf_control%max_scf = qs_env%scf_control%max_scf_hist
1111 qs_env%scf_control%eps_scf = qs_env%scf_control%eps_scf_hist
1112 qs_env%scf_control%outer_scf%have_scf = .false.
1113 ELSE IF (qs_env%scf_control%max_scf_hist /= 0)
THEN
1114 qs_env%scf_control%max_scf = qs_env%scf_control%max_scf_hist
1115 qs_env%scf_control%outer_scf%have_scf = .false.
1116 ELSE IF (qs_env%scf_control%eps_scf_hist /= 0)
THEN
1117 qs_env%scf_control%eps_scf = qs_env%scf_control%eps_scf_hist
1123 ALLOCATE (coeffs(nvec))
1126 CALL diff_fitting(wf_history, matrix_s(1)%matrix, coeffs, nvec, &
1127 1e-4_dp, io_unit, print_level)
1129 my_orthogonal_wf = .true.
1131 DO ispin = 1,
SIZE(mos)
1132 NULLIFY (mo_coeff, matrix_struct, matrix_struct_new)
1133 CALL get_mo_set(mo_set=mos(ispin), mo_coeff=mo_coeff)
1137 matrix_struct=matrix_struct)
1140 template_fmstruct=matrix_struct, &
1153 CALL parallel_gemm(
'T',
'N', k, k, n, 1.0_dp, t0_state%wf(ispin), fm_tmp, 0.0_dp, csc)
1154 CALL parallel_gemm(
'N',
'N', n, k, k, 1.0_dp, t0_state%wf(ispin), csc, 0.0_dp, fm_tmp)
1160 v_matrix=mo_coeff, &
1163 density_matrix=rho_ao(ispin)%matrix)
1173 IF (do_kpoints)
THEN
1174 nvec = min(wf_history%memory_depth, wf_history%snapshot_count)
1176 CALL wfi_extrapolate_gext_proj_kp(wf_history, qs_env, nvec, io_unit, print_level)
1177 my_orthogonal_wf = .true.
1181 nvec = min(wf_history%memory_depth, wf_history%snapshot_count)
1182 IF (nvec >= wf_history%memory_depth)
THEN
1183 IF ((qs_env%scf_control%max_scf_hist /= 0) .AND. &
1184 (qs_env%scf_control%eps_scf_hist /= 0))
THEN
1185 qs_env%scf_control%max_scf = qs_env%scf_control%max_scf_hist
1186 qs_env%scf_control%eps_scf = qs_env%scf_control%eps_scf_hist
1187 qs_env%scf_control%outer_scf%have_scf = .false.
1188 ELSE IF (qs_env%scf_control%max_scf_hist /= 0)
THEN
1189 qs_env%scf_control%max_scf = qs_env%scf_control%max_scf_hist
1190 qs_env%scf_control%outer_scf%have_scf = .false.
1191 ELSE IF (qs_env%scf_control%eps_scf_hist /= 0)
THEN
1192 qs_env%scf_control%eps_scf = qs_env%scf_control%eps_scf_hist
1198 ALLOCATE (coeffs(nvec))
1201 CALL tr_fitting(wf_history, matrix_s(1)%matrix, coeffs, nvec, &
1202 1e-4_dp, io_unit, print_level)
1204 my_orthogonal_wf = .true.
1206 DO ispin = 1,
SIZE(mos)
1207 NULLIFY (mo_coeff, matrix_struct, matrix_struct_new)
1208 CALL get_mo_set(mo_set=mos(ispin), mo_coeff=mo_coeff)
1212 matrix_struct=matrix_struct)
1215 template_fmstruct=matrix_struct, &
1228 CALL parallel_gemm(
'T',
'N', k, k, n, 1.0_dp, t0_state%wf(ispin), fm_tmp, 0.0_dp, csc)
1229 CALL parallel_gemm(
'N',
'N', n, k, k, 1.0_dp, t0_state%wf(ispin), csc, 0.0_dp, fm_tmp)
1235 v_matrix=mo_coeff, &
1238 density_matrix=rho_ao(ispin)%matrix)
1248 CALL cp_abort(__location__, &
1249 "Unknown interpolation method: "// &
1250 trim(adjustl(
cp_to_string(wf_history%interpolation_method_nr))))
1252 IF (
PRESENT(orthogonal_wf)) orthogonal_wf = my_orthogonal_wf
1254 "DFT%SCF%PRINT%PROGRAM_RUN_INFO")
1255 CALL timestop(handle)
1267 SUBROUTINE wfi_use_prev_wf_kp(qs_env, io_unit, print_level, pbc_shift_ref, load_snapshot_wf)
1269 INTEGER,
INTENT(IN) :: io_unit, print_level
1270 INTEGER,
DIMENSION(:, :),
INTENT(IN),
OPTIONAL :: pbc_shift_ref
1271 LOGICAL,
INTENT(IN),
OPTIONAL :: load_snapshot_wf
1273 CHARACTER(len=*),
PARAMETER :: routinen =
'wfi_use_prev_wf_kp'
1275 COMPLEX(KIND=dp),
ALLOCATABLE,
DIMENSION(:) :: col_scaling
1276 INTEGER :: chol_info, handle, ik, ikp, ispin, j, &
1277 kplocal, nao, nmo, nspin
1278 INTEGER,
ALLOCATABLE,
DIMENSION(:, :) :: pbc_shift_cur, pbc_shift_src
1279 INTEGER,
DIMENSION(2) :: kp_range
1280 LOGICAL :: reload_snapshot_wf, use_pbc_phase_ref, &
1282 REAL(kind=
dp) :: eval_thresh
1283 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: eigenvalues
1284 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: xkp
1285 TYPE(
cp_cfm_type) :: cfm_evecs, cfm_mhalf, cfm_nao_nmo_work, &
1287 TYPE(
cp_cfm_type),
ALLOCATABLE,
DIMENSION(:) :: csmat_cur
1291 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_s_kp
1301 CALL timeset(routinen, handle)
1303 NULLIFY (dft_control, scf_control, kpoints, matrix_s_kp, scf_env, kp, &
1304 mo_coeff, wf_history, t1_state)
1306 CALL get_qs_env(qs_env, kpoints=kpoints, matrix_s_kp=matrix_s_kp, scf_env=scf_env, &
1307 dft_control=dft_control, scf_control=scf_control)
1308 CALL get_kpoint_info(kpoints, xkp=xkp, use_real_wfn=use_real_wfn, kp_range=kp_range)
1309 kplocal = kp_range(2) - kp_range(1) + 1
1311 IF (use_real_wfn)
THEN
1312 CALL timestop(handle)
1316 wf_history => qs_env%wf_history
1317 reload_snapshot_wf = .false.
1318 IF (
PRESENT(load_snapshot_wf)) reload_snapshot_wf = load_snapshot_wf
1319 IF (
PRESENT(pbc_shift_ref))
THEN
1320 ALLOCATE (pbc_shift_src(3,
SIZE(pbc_shift_ref, 2)))
1321 pbc_shift_src(:, :) = pbc_shift_ref(:, :)
1322 use_pbc_phase_ref = .true.
1324 use_pbc_phase_ref = .false.
1325 IF (
ASSOCIATED(wf_history))
THEN
1326 IF (wf_history%store_wf_kp .AND. wf_history%snapshot_count > 0)
THEN
1328 cpassert(
ASSOCIATED(t1_state%wf_kp_cfm))
1329 cpassert(
ASSOCIATED(t1_state%kp_pbc_shift))
1330 reload_snapshot_wf = .true.
1331 ALLOCATE (pbc_shift_src(3,
SIZE(t1_state%kp_pbc_shift, 2)))
1332 pbc_shift_src(:, :) = t1_state%kp_pbc_shift(:, :)
1333 use_pbc_phase_ref = .true.
1337 IF (use_pbc_phase_ref)
CALL wfi_compute_kp_pbc_shift(qs_env, pbc_shift_cur)
1339 kp => kpoints%kp_env(1)%kpoint_env
1340 nspin =
SIZE(kp%mos)
1341 CALL get_mo_set(kp%mos(1), nao=nao, nmo=nmo, cmo_coeff=mo_coeff)
1344 WRITE (unit=io_unit, fmt=
"(/,T2,A)") &
1345 "Using previous wavefunctions as initial guess for k-points (with reorthogonalization)"
1349 CALL mpools_get(mpools_kp, ao_ao_fm_pool=ao_ao_fm_pool_kp)
1353 CALL cp_cfm_create(cfm_nao_nmo_work, mo_coeff%matrix_struct)
1355 NULLIFY (nmo_nmo_struct)
1357 nrow_global=nmo, ncol_global=nmo)
1361 ALLOCATE (csmat_cur(kplocal))
1371 ALLOCATE (eigenvalues(nmo))
1372 eval_thresh = 1.0e-12_dp
1375 kp => kpoints%kp_env(ikp)%kpoint_env
1377 IF (reload_snapshot_wf)
THEN
1378 CALL cp_cfm_to_cfm(t1_state%wf_kp_cfm(ikp, ispin), cmos_new)
1382 IF (use_pbc_phase_ref)
THEN
1383 ik = kp_range(1) + ikp - 1
1384 CALL wfi_apply_kp_pbc_phase_cfm(cmos_new, pbc_shift_cur - pbc_shift_src, &
1385 xkp(1:3, ik), matrix_s_kp(1, 1)%matrix)
1389 csmat_cur(ikp), cmos_new,
z_zero, cfm_nao_nmo_work)
1391 cmos_new, cfm_nao_nmo_work,
z_zero, csc_cfm)
1394 IF (chol_info == 0)
THEN
1402 ALLOCATE (col_scaling(nmo))
1404 IF (eigenvalues(j) > eval_thresh)
THEN
1405 col_scaling(j) = cmplx(1.0_dp/sqrt(eigenvalues(j)), 0.0_dp, kind=
dp)
1411 DEALLOCATE (col_scaling)
1425 kp%mos_prefilled = .true.
1427 DEALLOCATE (eigenvalues)
1433 fixed_occupations=scf_env%method ==
ot_method_nr .AND. &
1434 .NOT. (dft_control%smear .OR. scf_control%smear%do_smear))
1440 DEALLOCATE (csmat_cur)
1444 IF (
ALLOCATED(pbc_shift_cur))
DEALLOCATE (pbc_shift_cur)
1445 IF (
ALLOCATED(pbc_shift_src))
DEALLOCATE (pbc_shift_src)
1447 CALL timestop(handle)
1448 END SUBROUTINE wfi_use_prev_wf_kp
1457 SUBROUTINE wfi_store_kp_pbc_shift(snapshot, cell, particle_set)
1462 INTEGER :: iatom, natom
1463 REAL(kind=
dp),
DIMENSION(3) :: frac_pbc, frac_raw, r_pbc
1465 cpassert(
ASSOCIATED(snapshot))
1466 cpassert(
ASSOCIATED(cell))
1467 cpassert(
ASSOCIATED(particle_set))
1469 natom =
SIZE(particle_set)
1470 IF (
ASSOCIATED(snapshot%kp_pbc_shift))
THEN
1471 DEALLOCATE (snapshot%kp_pbc_shift)
1473 ALLOCATE (snapshot%kp_pbc_shift(3, natom))
1475 r_pbc(1:3) =
pbc(particle_set(iatom)%r(1:3), cell)
1478 snapshot%kp_pbc_shift(1:3, iatom) = nint(frac_pbc(1:3) - frac_raw(1:3))
1480 END SUBROUTINE wfi_store_kp_pbc_shift
1487 SUBROUTINE wfi_compute_kp_pbc_shift(qs_env, pbc_shift)
1489 INTEGER,
ALLOCATABLE,
DIMENSION(:, :),
INTENT(OUT) :: pbc_shift
1491 INTEGER :: iatom, natom
1492 REAL(kind=
dp),
DIMENSION(3) :: frac_pbc, frac_raw, r_pbc
1496 NULLIFY (cell, particle_set)
1497 CALL get_qs_env(qs_env, cell=cell, particle_set=particle_set)
1498 cpassert(
ASSOCIATED(cell))
1499 cpassert(
ASSOCIATED(particle_set))
1501 natom =
SIZE(particle_set)
1502 ALLOCATE (pbc_shift(3, natom))
1504 r_pbc(1:3) =
pbc(particle_set(iatom)%r(1:3), cell)
1507 pbc_shift(1:3, iatom) = nint(frac_pbc(1:3) - frac_raw(1:3))
1509 END SUBROUTINE wfi_compute_kp_pbc_shift
1519 SUBROUTINE wfi_apply_kp_pbc_phase_cfm(cmos, pbc_shift_delta, xk, matrix_template)
1521 INTEGER,
DIMENSION(:, :),
INTENT(IN) :: pbc_shift_delta
1522 REAL(kind=
dp),
DIMENSION(3),
INTENT(IN) :: xk
1525 COMPLEX(KIND=dp) :: phase
1526 COMPLEX(KIND=dp),
ALLOCATABLE,
DIMENSION(:, :) :: zblock
1527 INTEGER :: iatom, natom, nmo, nrow, row_start
1528 INTEGER,
DIMENSION(:),
POINTER :: row_blk_size
1529 REAL(kind=
dp) :: theta
1531 cpassert(
ASSOCIATED(matrix_template))
1533 natom =
SIZE(pbc_shift_delta, 2)
1535 NULLIFY (row_blk_size)
1537 cpassert(
SIZE(row_blk_size) >= natom)
1541 nrow = row_blk_size(iatom)
1542 IF (any(pbc_shift_delta(1:3, iatom) /= 0))
THEN
1543 theta =
twopi*sum(xk(1:3)*real(pbc_shift_delta(1:3, iatom), kind=
dp))
1544 phase = cmplx(cos(theta), sin(theta), kind=
dp)
1545 ALLOCATE (zblock(nrow, nmo))
1547 zblock = phase*zblock
1551 row_start = row_start + nrow
1553 END SUBROUTINE wfi_apply_kp_pbc_phase_cfm
1566 SUBROUTINE wfi_extrapolate_ps_aspc_kp(wf_history, qs_env, nvec, io_unit, print_level)
1569 INTEGER,
INTENT(IN) :: nvec, io_unit, print_level
1571 CHARACTER(len=*),
PARAMETER :: routinen =
'wfi_extrapolate_ps_aspc_kp'
1573 INTEGER :: handle, i, ik, ikp, ispin, kplocal, &
1574 method_nr, nao, nmo, nspin
1575 INTEGER,
DIMENSION(2) :: kp_range
1576 LOGICAL :: use_real_wfn
1577 REAL(kind=
dp) :: alpha_coeff
1578 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: xkp
1579 TYPE(
cp_cfm_type) :: cfm_nao_nmo_work, cmos_1, cmos_i, &
1583 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_s_kp
1588 method_nr = wf_history%interpolation_method_nr
1590 CALL timeset(routinen, handle)
1591 NULLIFY (kpoints, kp, mo_coeff, t0_state, t1_state, nmo_nmo_struct, &
1594 CALL get_qs_env(qs_env, kpoints=kpoints, matrix_s_kp=matrix_s_kp)
1595 CALL get_kpoint_info(kpoints, use_real_wfn=use_real_wfn, kp_range=kp_range, xkp=xkp)
1596 kplocal = kp_range(2) - kp_range(1) + 1
1598 IF (use_real_wfn)
THEN
1600 CALL cp_warn(__location__,
"ASPC with k-points requires complex wavefunctions; "// &
1601 "falling back to USE_PREV_WF.")
1603 CALL cp_warn(__location__,
"PS with k-points requires complex wavefunctions; "// &
1604 "falling back to USE_PREV_WF.")
1606 CALL wfi_use_prev_wf_kp(qs_env, io_unit, print_level)
1607 CALL timestop(handle)
1611 kp => kpoints%kp_env(1)%kpoint_env
1612 nspin =
SIZE(kp%mos)
1613 CALL get_mo_set(kp%mos(1), nao=nao, nmo=nmo, cmo_coeff=mo_coeff)
1617 WRITE (unit=io_unit, fmt=
"(/,T2,A,/,T3,A,I0)") &
1618 "Parameters for the always stable predictor-corrector (ASPC) method:", &
1619 "ASPC order: ", max(nvec - 2, 0)
1624 CALL cp_cfm_create(cmos_new, mo_coeff%matrix_struct, set_zero=.true.)
1625 CALL cp_cfm_create(cmos_1, mo_coeff%matrix_struct, set_zero=.true.)
1626 CALL cp_cfm_create(cmos_i, mo_coeff%matrix_struct, set_zero=.true.)
1627 CALL cp_cfm_create(cfm_nao_nmo_work, mo_coeff%matrix_struct, set_zero=.true.)
1632 CALL cp_cfm_create(cfm_nao_nmo_work, mo_coeff%matrix_struct)
1636 nrow_global=nmo, ncol_global=nmo)
1638 CALL cp_cfm_create(csc_cfm, nmo_nmo_struct, set_zero=.true.)
1647 alpha_coeff = real(4*nvec - 2, kind=
dp)/real(nvec + 1, kind=
dp)
1649 WRITE (unit=io_unit, fmt=
"(T3,A2,I0,A4,F10.6)")
"B(", 1,
") = ", alpha_coeff
1656 kp => kpoints%kp_env(ikp)%kpoint_env
1658 CALL cp_cfm_to_cfm(t1_state%wf_kp_cfm(ikp, ispin), cmos_new)
1668 alpha_coeff = (-1.0_dp)**(i + 1)*real(i, kind=
dp)* &
1671 WRITE (unit=io_unit, fmt=
"(T3,A2,I0,A4,F10.6)")
"B(", i,
") = ", alpha_coeff
1674 alpha_coeff = -1.0_dp*alpha_coeff*real(nvec - i + 1,
dp)/real(i,
dp)
1678 kp => kpoints%kp_env(ikp)%kpoint_env
1680 ik = kp_range(1) + ikp - 1
1686 CALL wfi_apply_kp_pbc_phase_cfm(cmos_1, t0_state%kp_pbc_shift - t1_state%kp_pbc_shift, &
1687 xkp(1:3, ik), matrix_s_kp(1, 1)%matrix)
1691 t0_state%overlap_cfm_kp(ikp), cmos_1,
z_zero, cfm_nao_nmo_work)
1693 cmos_i, cfm_nao_nmo_work,
z_zero, csc_cfm)
1695 cmos_i, csc_cfm,
z_zero, cfm_nao_nmo_work)
1700 CALL wfi_apply_kp_pbc_phase_cfm(cfm_nao_nmo_work, t1_state%kp_pbc_shift - t0_state%kp_pbc_shift, &
1701 xkp(1:3, ik), matrix_s_kp(1, 1)%matrix)
1720 CALL wfi_use_prev_wf_kp(qs_env, 0, print_level, pbc_shift_ref=t1_state%kp_pbc_shift, &
1721 load_snapshot_wf=.false.)
1723 CALL timestop(handle)
1725 END SUBROUTINE wfi_extrapolate_ps_aspc_kp
1737 SUBROUTINE wfi_extrapolate_gext_proj_kp(wf_history, qs_env, nvec, io_unit, print_level)
1740 INTEGER,
INTENT(IN) :: nvec, io_unit, print_level
1742 CHARACTER(len=*),
PARAMETER :: routinen =
'wfi_extrapolate_gext_proj_kp'
1744 INTEGER :: handle, i, ik, ikp, ispin, kplocal, &
1745 method_nr, nao, nmo, nspin
1746 INTEGER,
DIMENSION(2) :: kp_range
1747 LOGICAL :: use_real_wfn
1748 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: coeffs, weight_kp
1749 REAL(kind=
dp),
DIMENSION(:),
POINTER :: wkp
1750 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: xkp
1751 TYPE(
cp_cfm_type) :: cfm_nao_nmo_work, cmos_1, cmos_i, &
1753 TYPE(
cp_cfm_type),
ALLOCATABLE,
DIMENSION(:) :: csmat_cur
1757 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_s_kp
1765 method_nr = wf_history%interpolation_method_nr
1767 CALL timeset(routinen, handle)
1768 NULLIFY (ao_ao_struct, kp, kpoints, matrix_s_kp, mo_coeff, mpools_kp, &
1769 para_env_inter_kp, scf_env, t0_state, t1_state, wkp, xkp, nmo_nmo_struct, &
1772 CALL get_qs_env(qs_env, kpoints=kpoints, matrix_s_kp=matrix_s_kp, scf_env=scf_env)
1773 CALL get_kpoint_info(kpoints, use_real_wfn=use_real_wfn, kp_range=kp_range, &
1775 mpools=mpools_kp, para_env_inter_kp=para_env_inter_kp)
1776 kplocal = kp_range(2) - kp_range(1) + 1
1778 IF (use_real_wfn)
THEN
1779 CALL cp_warn(__location__,
"GExt with k-points requires complex wavefunctions; "// &
1780 "falling back to USE_PREV_WF.")
1781 CALL wfi_use_prev_wf_kp(qs_env, io_unit, print_level)
1782 CALL timestop(handle)
1786 IF (nvec >= wf_history%memory_depth)
THEN
1787 IF ((qs_env%scf_control%max_scf_hist /= 0) .AND. &
1788 (qs_env%scf_control%eps_scf_hist /= 0))
THEN
1789 qs_env%scf_control%max_scf = qs_env%scf_control%max_scf_hist
1790 qs_env%scf_control%eps_scf = qs_env%scf_control%eps_scf_hist
1791 qs_env%scf_control%outer_scf%have_scf = .false.
1792 ELSE IF (qs_env%scf_control%max_scf_hist /= 0)
THEN
1793 qs_env%scf_control%max_scf = qs_env%scf_control%max_scf_hist
1794 qs_env%scf_control%outer_scf%have_scf = .false.
1795 ELSE IF (qs_env%scf_control%eps_scf_hist /= 0)
THEN
1796 qs_env%scf_control%eps_scf = qs_env%scf_control%eps_scf_hist
1800 kp => kpoints%kp_env(1)%kpoint_env
1801 nspin =
SIZE(kp%mos)
1802 CALL get_mo_set(kp%mos(1), nao=nao, nmo=nmo, cmo_coeff=mo_coeff)
1804 CALL mpools_get(mpools_kp, ao_ao_fm_pool=ao_ao_fm_pool_kp)
1807 ALLOCATE (csmat_cur(kplocal), weight_kp(kplocal))
1810 weight_kp(ikp) = wkp(kp_range(1) + ikp - 1)
1816 ALLOCATE (coeffs(nvec))
1818 CALL diff_fitting(wf_history, matrix_s_kp(1, 1)%matrix, coeffs, nvec, &
1819 1e-4_dp, io_unit, print_level, current_overlap_kp=csmat_cur, &
1820 kpoint_weights=weight_kp, para_env_inter_kp=para_env_inter_kp)
1822 CALL tr_fitting(wf_history, matrix_s_kp(1, 1)%matrix, coeffs, nvec, &
1823 1e-4_dp, io_unit, print_level, current_overlap_kp=csmat_cur, &
1824 kpoint_weights=weight_kp, para_env_inter_kp=para_env_inter_kp)
1831 CALL cp_cfm_create(cfm_nao_nmo_work, mo_coeff%matrix_struct)
1833 nrow_global=nmo, ncol_global=nmo)
1839 kp => kpoints%kp_env(ikp)%kpoint_env
1848 kp => kpoints%kp_env(ikp)%kpoint_env
1849 ik = kp_range(1) + ikp - 1
1854 CALL wfi_apply_kp_pbc_phase_cfm(cmos_1, t0_state%kp_pbc_shift - t1_state%kp_pbc_shift, &
1855 xkp(1:3, ik), matrix_s_kp(1, 1)%matrix)
1858 t0_state%overlap_cfm_kp(ikp), cmos_1,
z_zero, cfm_nao_nmo_work)
1860 cmos_i, cfm_nao_nmo_work,
z_zero, csc_cfm)
1862 cmos_i, csc_cfm,
z_zero, cfm_nao_nmo_work)
1864 CALL wfi_apply_kp_pbc_phase_cfm(cfm_nao_nmo_work, t1_state%kp_pbc_shift - t0_state%kp_pbc_shift, &
1865 xkp(1:3, ik), matrix_s_kp(1, 1)%matrix)
1880 CALL wfi_use_prev_wf_kp(qs_env, 0, print_level, pbc_shift_ref=t1_state%kp_pbc_shift, &
1881 load_snapshot_wf=.false.)
1886 DEALLOCATE (csmat_cur, coeffs, weight_kp)
1888 CALL timestop(handle)
1890 END SUBROUTINE wfi_extrapolate_gext_proj_kp
1901 ELEMENTAL SUBROUTINE wfi_set_history_variables(qs_env, nvec)
1903 INTEGER,
INTENT(IN) :: nvec
1905 IF (nvec >= qs_env%wf_history%memory_depth)
THEN
1906 IF ((qs_env%scf_control%max_scf_hist /= 0) .AND. (qs_env%scf_control%eps_scf_hist /= 0))
THEN
1907 qs_env%scf_control%max_scf = qs_env%scf_control%max_scf_hist
1908 qs_env%scf_control%eps_scf = qs_env%scf_control%eps_scf_hist
1909 qs_env%scf_control%outer_scf%have_scf = .false.
1910 ELSE IF (qs_env%scf_control%max_scf_hist /= 0)
THEN
1911 qs_env%scf_control%max_scf = qs_env%scf_control%max_scf_hist
1912 qs_env%scf_control%outer_scf%have_scf = .false.
1913 ELSE IF (qs_env%scf_control%eps_scf_hist /= 0)
THEN
1914 qs_env%scf_control%eps_scf = qs_env%scf_control%eps_scf_hist
1915 qs_env%scf_control%outer_scf%eps_scf = qs_env%scf_control%eps_scf_hist
1919 END SUBROUTINE wfi_set_history_variables
1933 REAL(kind=
dp),
INTENT(in) :: dt
1935 cpassert(
ASSOCIATED(wf_history))
1936 cpassert(wf_history%ref_count > 0)
1937 cpassert(
ASSOCIATED(qs_env))
1939 wf_history%snapshot_count = wf_history%snapshot_count + 1
1940 IF (wf_history%memory_depth > 0)
THEN
1941 wf_history%last_state_index =
modulo(wf_history%snapshot_count, &
1942 wf_history%memory_depth) + 1
1943 CALL wfs_update(snapshot=wf_history%past_states &
1944 (wf_history%last_state_index)%snapshot, wf_history=wf_history, &
1945 qs_env=qs_env, dt=dt)
1961 INTEGER,
INTENT(in),
OPTIONAL :: n_col
1963 CHARACTER(len=*),
PARAMETER :: routinen =
'reorthogonalize_vectors'
1965 INTEGER :: handle, my_n_col
1966 LOGICAL :: has_unit_metric, &
1967 ortho_contains_cholesky, &
1976 NULLIFY (scf_env, scf_control, maxao_maxmo_fm_pool, matrix_s, mpools, dft_control)
1977 CALL timeset(routinen, handle)
1979 cpassert(
ASSOCIATED(qs_env))
1982 IF (
PRESENT(n_col)) my_n_col = n_col
1985 scf_control=scf_control, &
1986 matrix_s=matrix_s, &
1987 dft_control=dft_control)
1988 CALL mpools_get(mpools, maxao_maxmo_fm_pool=maxao_maxmo_fm_pool)
1989 IF (
ASSOCIATED(scf_env))
THEN
1990 ortho_contains_cholesky = (scf_env%method /=
ot_method_nr) .AND. &
1991 (scf_env%cholesky_method > 0) .AND. &
1992 ASSOCIATED(scf_env%ortho)
1994 ortho_contains_cholesky = .false.
1997 CALL get_qs_env(qs_env, has_unit_metric=has_unit_metric)
1998 smearing_is_used = .false.
1999 IF (dft_control%smear)
THEN
2000 smearing_is_used = .true.
2003 IF (has_unit_metric)
THEN
2005 ELSE IF (smearing_is_used)
THEN
2007 matrix_s=matrix_s(1)%matrix)
2008 ELSE IF (ortho_contains_cholesky)
THEN
2010 ortho=scf_env%ortho)
2014 CALL timestop(handle)
2028 CHARACTER(len=*),
PARAMETER :: routinen =
'wfi_purge_history'
2030 INTEGER :: handle, io_unit, print_level
2035 NULLIFY (dft_control, wf_history)
2037 CALL timeset(routinen, handle)
2039 print_level = logger%iter_info%print_level
2041 extension=
".scfLog")
2043 cpassert(
ASSOCIATED(qs_env))
2044 cpassert(
ASSOCIATED(qs_env%wf_history))
2045 cpassert(qs_env%wf_history%ref_count > 0)
2046 CALL get_qs_env(qs_env, dft_control=dft_control)
2048 SELECT CASE (qs_env%wf_history%interpolation_method_nr)
2055 IF (qs_env%wf_history%snapshot_count >= 2)
THEN
2056 IF (debug_this_module .AND. io_unit > 0)
THEN
2057 WRITE (io_unit, fmt=
"(T2,A)")
"QS| Purging WFN history"
2059 CALL wfi_create(wf_history, interpolation_method_nr= &
2060 dft_control%qs_control%wf_interpolation_method_nr, &
2061 extrapolation_order=dft_control%qs_control%wf_extrapolation_order, &
2062 has_unit_metric=qs_env%has_unit_metric)
2064 wf_history=wf_history)
2066 CALL wfi_update(qs_env%wf_history, qs_env=qs_env, dt=1.0_dp)
2069 cpabort(
"Unknown extrapolation method.")
2071 CALL timestop(handle)
2094 SUBROUTINE diff_fitting(wf_history, current_overlap, coeffs, nvec, eps, io_unit, print_level, &
2095 current_overlap_kp, kpoint_weights, para_env_inter_kp)
2097 TYPE(
dbcsr_type),
INTENT(IN) :: current_overlap
2098 INTEGER,
INTENT(IN) :: nvec
2099 REAL(kind=
dp),
INTENT(OUT) :: coeffs(nvec)
2100 REAL(kind=
dp),
INTENT(IN) :: eps
2101 INTEGER,
INTENT(IN) :: io_unit, print_level
2103 OPTIONAL :: current_overlap_kp
2104 REAL(kind=
dp),
DIMENSION(:),
INTENT(IN),
OPTIONAL :: kpoint_weights
2107 COMPLEX(KIND=dp) :: ztrace
2108 INTEGER :: i, icol_local, ikp, info, irow_local, j
2109 REAL(kind=
dp) :: error, norm_ref, weight
2110 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: b
2111 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: a
2112 TYPE(
cp_cfm_type) :: target_diff_cfm, tmp_conj_cfm, &
2113 tmp_i_cfm, tmp_j_cfm
2114 TYPE(
dbcsr_type) :: target_diff, tmp_i, tmp_j, tmp_k
2118 cpabort(
"Not enough vectors to do the fitting")
2119 ELSE IF (nvec == 1)
THEN
2124 IF (
PRESENT(current_overlap_kp))
THEN
2125 ALLOCATE (a(nvec - 1, nvec - 1), b(nvec - 1))
2130 CALL cp_cfm_create(target_diff_cfm, current_overlap_kp(1)%matrix_struct)
2131 CALL cp_cfm_create(tmp_i_cfm, current_overlap_kp(1)%matrix_struct)
2132 CALL cp_cfm_create(tmp_j_cfm, current_overlap_kp(1)%matrix_struct)
2133 CALL cp_cfm_create(tmp_conj_cfm, current_overlap_kp(1)%matrix_struct)
2135 DO ikp = 1,
SIZE(current_overlap_kp)
2137 IF (
PRESENT(kpoint_weights)) weight = kpoint_weights(ikp)
2139 CALL cp_cfm_to_cfm(current_overlap_kp(ikp), target_diff_cfm)
2141 ref_state%overlap_cfm_kp(ikp))
2146 ref_state%overlap_cfm_kp(ikp))
2148 DO icol_local = 1,
SIZE(tmp_conj_cfm%local_data, 2)
2149 DO irow_local = 1,
SIZE(tmp_conj_cfm%local_data, 1)
2150 tmp_conj_cfm%local_data(irow_local, icol_local) = &
2151 conjg(tmp_conj_cfm%local_data(irow_local, icol_local))
2154 CALL cp_cfm_trace(tmp_conj_cfm, target_diff_cfm, ztrace)
2155 b(i - 1) = b(i - 1) + weight*real(ztrace, kind=
dp)
2161 ref_state%overlap_cfm_kp(ikp))
2163 a(j - 1, i - 1) = a(j - 1, i - 1) + weight*real(ztrace, kind=
dp)
2170 a(i - 1, j - 1) = a(j - 1, i - 1)
2174 IF (
PRESENT(para_env_inter_kp))
THEN
2175 IF (
ASSOCIATED(para_env_inter_kp))
THEN
2176 CALL para_env_inter_kp%sum(a)
2177 CALL para_env_inter_kp%sum(b)
2182 a(i, i) = a(i, i) + eps**2
2185 CALL dposv(
'u', nvec - 1, 1, a, nvec - 1, b, nvec - 1, info)
2187 cpabort(
"DPOSV failed.")
2190 coeffs(1) = 1.0_dp - sum(b)
2191 coeffs(2:nvec) = b(:)
2196 DO ikp = 1,
SIZE(current_overlap_kp)
2198 IF (
PRESENT(kpoint_weights)) weight = kpoint_weights(ikp)
2203 state%overlap_cfm_kp(ikp))
2206 DO icol_local = 1,
SIZE(tmp_conj_cfm%local_data, 2)
2207 DO irow_local = 1,
SIZE(tmp_conj_cfm%local_data, 1)
2208 tmp_conj_cfm%local_data(irow_local, icol_local) = &
2209 conjg(tmp_conj_cfm%local_data(irow_local, icol_local))
2213 error = error + weight*real(ztrace, kind=
dp)
2214 CALL cp_cfm_to_cfm(ref_state%overlap_cfm_kp(ikp), tmp_conj_cfm)
2215 DO icol_local = 1,
SIZE(tmp_conj_cfm%local_data, 2)
2216 DO irow_local = 1,
SIZE(tmp_conj_cfm%local_data, 1)
2217 tmp_conj_cfm%local_data(irow_local, icol_local) = &
2218 conjg(tmp_conj_cfm%local_data(irow_local, icol_local))
2221 CALL cp_cfm_trace(tmp_conj_cfm, ref_state%overlap_cfm_kp(ikp), ztrace)
2222 norm_ref = norm_ref + weight*real(ztrace, kind=
dp)
2224 IF (
PRESENT(para_env_inter_kp))
THEN
2225 IF (
ASSOCIATED(para_env_inter_kp))
THEN
2226 CALL para_env_inter_kp%sum(error)
2227 CALL para_env_inter_kp%sum(norm_ref)
2230 IF (io_unit > 0)
THEN
2231 WRITE (unit=io_unit, fmt=
"(/,T2,A,F20.10)")
"GEXT overlap fitting error:", &
2232 sqrt(error/max(norm_ref, tiny(1.0_dp)))
2244 ALLOCATE (a(nvec - 1, nvec - 1), b(nvec - 1))
2250 CALL dbcsr_copy(target_diff, current_overlap)
2251 CALL dbcsr_add(target_diff, ref_state%overlap, 1.0_dp, -1.0_dp)
2260 CALL dbcsr_add(tmp_i, ref_state%overlap, 1.0_dp, -1.0_dp)
2261 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, tmp_i, target_diff, 0.0_dp, tmp_k)
2267 CALL dbcsr_add(tmp_j, ref_state%overlap, 1.0_dp, -1.0_dp)
2268 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, tmp_i, tmp_j, 0.0_dp, tmp_k)
2270 a(i - 1, j - 1) = a(j - 1, i - 1)
2276 a(i, i) = a(i, i) + eps**2
2280 CALL dposv(
'u', nvec - 1, 1, a, nvec - 1, b, nvec - 1, info)
2282 cpabort(
"DPOSV failed.")
2286 coeffs(1) = 1.0_dp - sum(b)
2287 coeffs(2:nvec) = b(:)
2295 CALL dbcsr_add(tmp_i, state%overlap, 1.0_dp, -coeffs(i))
2298 IF (io_unit > 0)
THEN
2299 WRITE (unit=io_unit, fmt=
"(/,T2,A,F20.10)")
"GEXT overlap fitting error:", error
2310 END SUBROUTINE diff_fitting
2332 SUBROUTINE tr_fitting(wf_history, current_overlap, coeffs, nvec, eps, io_unit, print_level, &
2333 current_overlap_kp, kpoint_weights, para_env_inter_kp)
2335 TYPE(
dbcsr_type),
INTENT(IN) :: current_overlap
2336 INTEGER,
INTENT(IN) :: nvec
2337 REAL(kind=
dp),
INTENT(OUT) :: coeffs(nvec)
2338 REAL(kind=
dp),
INTENT(IN) :: eps
2339 INTEGER,
INTENT(IN) :: io_unit, print_level
2341 OPTIONAL :: current_overlap_kp
2342 REAL(kind=
dp),
DIMENSION(:),
INTENT(IN),
OPTIONAL :: kpoint_weights
2345 COMPLEX(KIND=dp) :: ztrace
2346 INTEGER :: i, icol_local, ikp, info, irow_local, j, &
2348 REAL(kind=
dp) :: error, norm_ref, weight
2349 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: b
2350 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: a
2351 TYPE(
cp_cfm_type) :: target_overlap_cfm, tmp_conj_cfm, &
2352 tmp_i_cfm, tmp_j_cfm
2353 TYPE(
dbcsr_type) :: target_overlap, tmp_i, tmp_j, tmp_k
2357 cpabort(
"Not enough vectors to do the fitting")
2358 ELSE IF (nvec == 1)
THEN
2363 IF (mod(nvec, 2) == 0)
THEN
2369 IF (
PRESENT(current_overlap_kp))
THEN
2370 ALLOCATE (a(ntr, ntr), b(ntr))
2375 CALL cp_cfm_create(target_overlap_cfm, current_overlap_kp(1)%matrix_struct)
2376 CALL cp_cfm_create(tmp_i_cfm, current_overlap_kp(1)%matrix_struct)
2377 CALL cp_cfm_create(tmp_j_cfm, current_overlap_kp(1)%matrix_struct)
2378 CALL cp_cfm_create(tmp_conj_cfm, current_overlap_kp(1)%matrix_struct)
2380 DO ikp = 1,
SIZE(current_overlap_kp)
2382 IF (
PRESENT(kpoint_weights)) weight = kpoint_weights(ikp)
2384 CALL cp_cfm_to_cfm(current_overlap_kp(ikp), target_overlap_cfm)
2393 DO icol_local = 1,
SIZE(tmp_conj_cfm%local_data, 2)
2394 DO irow_local = 1,
SIZE(tmp_conj_cfm%local_data, 1)
2395 tmp_conj_cfm%local_data(irow_local, icol_local) = &
2396 conjg(tmp_conj_cfm%local_data(irow_local, icol_local))
2399 CALL cp_cfm_trace(tmp_conj_cfm, target_overlap_cfm, ztrace)
2400 b(i) = b(i) + weight*real(ztrace, kind=
dp)
2407 a(j, i) = a(j, i) + weight*real(ztrace, kind=
dp)
2418 IF (
PRESENT(para_env_inter_kp))
THEN
2419 IF (
ASSOCIATED(para_env_inter_kp))
THEN
2420 CALL para_env_inter_kp%sum(a)
2421 CALL para_env_inter_kp%sum(b)
2426 a(i, i) = a(i, i) + eps**2
2429 CALL dposv(
'u', ntr, 1, a, ntr, b, ntr, info)
2431 cpabort(
"DPOSV failed.")
2435 coeffs(nvec) = -1.0_dp
2437 coeffs(i) = coeffs(i) + b(i)
2438 coeffs(nvec - i) = coeffs(nvec - i) + b(i)
2444 DO ikp = 1,
SIZE(current_overlap_kp)
2446 IF (
PRESENT(kpoint_weights)) weight = kpoint_weights(ikp)
2451 state%overlap_cfm_kp(ikp))
2454 DO icol_local = 1,
SIZE(tmp_conj_cfm%local_data, 2)
2455 DO irow_local = 1,
SIZE(tmp_conj_cfm%local_data, 1)
2456 tmp_conj_cfm%local_data(irow_local, icol_local) = &
2457 conjg(tmp_conj_cfm%local_data(irow_local, icol_local))
2461 error = error + weight*real(ztrace, kind=
dp)
2462 CALL cp_cfm_to_cfm(ref_state%overlap_cfm_kp(ikp), tmp_conj_cfm)
2463 DO icol_local = 1,
SIZE(tmp_conj_cfm%local_data, 2)
2464 DO irow_local = 1,
SIZE(tmp_conj_cfm%local_data, 1)
2465 tmp_conj_cfm%local_data(irow_local, icol_local) = &
2466 conjg(tmp_conj_cfm%local_data(irow_local, icol_local))
2469 CALL cp_cfm_trace(tmp_conj_cfm, ref_state%overlap_cfm_kp(ikp), ztrace)
2470 norm_ref = norm_ref + weight*real(ztrace, kind=
dp)
2472 IF (
PRESENT(para_env_inter_kp))
THEN
2473 IF (
ASSOCIATED(para_env_inter_kp))
THEN
2474 CALL para_env_inter_kp%sum(error)
2475 CALL para_env_inter_kp%sum(norm_ref)
2478 IF (io_unit > 0)
THEN
2479 WRITE (unit=io_unit, fmt=
"(/,T2,A,F20.10)")
"GEXT overlap fitting error:", &
2480 sqrt(error/max(norm_ref, tiny(1.0_dp)))
2492 ALLOCATE (a(ntr, ntr), b(ntr))
2498 CALL dbcsr_copy(target_overlap, current_overlap)
2499 CALL dbcsr_add(target_overlap, ref_state%overlap, 1.0_dp, 1.0_dp)
2509 CALL dbcsr_add(tmp_i, state%overlap, 1.0_dp, 1.0_dp)
2518 CALL dbcsr_add(tmp_j, state%overlap, 1.0_dp, 1.0_dp)
2519 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, tmp_i, tmp_j, 0.0_dp, tmp_k)
2527 a(i, i) = a(i, i) + eps**2
2531 CALL dposv(
'u', ntr, 1, a, ntr, b, ntr, info)
2533 cpabort(
"DPOSV failed.")
2538 coeffs(nvec) = -1.0_dp
2540 coeffs(i) = coeffs(i) + b(i)
2541 coeffs(nvec - i) = coeffs(nvec - i) + b(i)
2550 CALL dbcsr_add(tmp_i, state%overlap, 1.0_dp, -coeffs(i))
2553 IF (io_unit > 0)
THEN
2554 WRITE (unit=io_unit, fmt=
"(/,T2,A,F20.10)")
"GEXT overlap fitting error:", error
2565 END SUBROUTINE tr_fitting
static GRID_HOST_DEVICE int modulo(int a, int m)
Equivalent of Fortran's MODULO, which always return a positive number. https://gcc....
collects all references to literature in CP2K as new algorithms / method are included from literature...
integer, save, public vandevondele2005a
integer, save, public kuhne2007
integer, save, public kolafa2004
Handles all functions related to the CELL.
subroutine, public real_to_scaled(s, r, cell)
Transform real to scaled cell coordinates. s=h_inv*r.
Basic linear algebra operations for complex full matrices.
subroutine, public cp_cfm_scale_and_add(alpha, matrix_a, beta, matrix_b)
Scale and add two BLACS matrices (a = alpha*a + beta*b).
subroutine, public cp_cfm_triangular_multiply(triangular_matrix, matrix_b, side, transa_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...
subroutine, public cp_cfm_column_scale(matrix_a, scaling, first_col, source)
Scales columns of the full matrix by corresponding factors.
subroutine, public cp_cfm_trace(matrix_a, matrix_b, trace)
Returns the trace of matrix_a^T matrix_b, i.e sum_{i,j}(matrix_a(i,j)*matrix_b(i,j)) .
various cholesky decomposition related routines
subroutine, public cp_cfm_cholesky_decompose(matrix, n, info_out)
Used to replace a symmetric positive definite matrix M with its Cholesky decomposition U: M = U^T * U...
used for collecting diagonalization schemes available for cp_cfm_type
subroutine, public cp_cfm_heevd(matrix, eigenvectors, eigenvalues)
Perform a diagonalisation of a complex matrix.
Represents a complex full matrix distributed on many processors.
subroutine, public cp_cfm_get_submatrix(fm, target_m, start_row, start_col, n_rows, n_cols, transpose)
Extract a sub-matrix from the full matrix: op(target_m)(1:n_rows,1:n_cols) = fm(start_row:start_row+n...
subroutine, public cp_cfm_release(matrix)
Releases a full matrix.
subroutine, public cp_cfm_create(matrix, matrix_struct, name, nrow, ncol, set_zero)
Creates a new full matrix with the given structure.
subroutine, public cp_cfm_get_info(matrix, name, nrow_global, ncol_global, nrow_block, ncol_block, nrow_local, ncol_local, row_indices, col_indices, local_data, context, matrix_struct, para_env)
Returns information about a full matrix.
subroutine, public cp_cfm_set_submatrix(matrix, new_values, start_row, start_col, n_rows, n_cols, alpha, beta, transpose)
Set a sub-matrix of the full matrix: matrix(start_row:start_row+n_rows,start_col:start_col+n_cols) = ...
subroutine, public cp_cfm_set_all(matrix, alpha, beta)
Set all elements of the full matrix to alpha. Besides, set all diagonal matrix elements to beta (if g...
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
subroutine, public dbcsr_deallocate_matrix(matrix)
...
subroutine, public dbcsr_copy(matrix_b, matrix_a, name, keep_sparsity, keep_imaginary)
...
subroutine, public dbcsr_multiply(transa, transb, alpha, matrix_a, matrix_b, beta, matrix_c, first_row, last_row, first_column, last_column, first_k, last_k, retain_sparsity, filter_eps, flop)
...
subroutine, public dbcsr_get_info(matrix, nblkrows_total, nblkcols_total, nfullrows_total, nfullcols_total, nblkrows_local, nblkcols_local, nfullrows_local, nfullcols_local, my_prow, my_pcol, local_rows, local_cols, proc_row_dist, proc_col_dist, row_blk_size, col_blk_size, row_blk_offset, col_blk_offset, distribution, name, matrix_type, group)
...
subroutine, public dbcsr_release(matrix)
...
subroutine, public dbcsr_add(matrix_a, matrix_b, alpha_scalar, beta_scalar)
...
subroutine, public dbcsr_trace(matrix, trace)
Computes the trace of the given matrix, also known as the sum of its diagonal elements.
real(dp) function, public dbcsr_frobenius_norm(matrix)
Compute the frobenius norm of a dbcsr 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
Basic linear algebra operations for full matrices.
subroutine, public cp_fm_scale_and_add(alpha, matrix_a, beta, matrix_b)
calc A <- alpha*A + beta*B optimized for alpha == 1.0 (just add beta*B) and beta == 0....
subroutine, public cp_fm_scale(alpha, matrix_a)
scales a matrix matrix_a = alpha * matrix_b
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
logical function, public cp_fm_struct_equivalent(fmstruct1, fmstruct2)
returns true if the two matrix structures are equivalent, false otherwise.
subroutine, public cp_fm_struct_release(fmstruct)
releases a full matrix structure
represent a full matrix distributed on many processors
subroutine, public cp_fm_get_info(matrix, name, nrow_global, ncol_global, nrow_block, ncol_block, nrow_local, ncol_local, row_indices, col_indices, local_data, context, nrow_locals, ncol_locals, matrix_struct, para_env)
returns all kind of information about the full matrix
subroutine, public cp_fm_set_all(matrix, alpha, beta)
set all elements of a matrix to the same value, and optionally the diagonal to a different one
subroutine, public cp_fm_create(matrix, matrix_struct, name, nrow, ncol, set_zero)
creates a new full matrix with the given structure
various routines to log and control the output. The idea is that decisions about where to log should ...
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
routines to handle the output, The idea is to remove the decision of wheter to output and what to out...
integer, parameter, public low_print_level
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 function, public cp_print_key_unit_nr(logger, basis_section, print_key_path, extension, middle_name, local, log_filename, ignore_should_output, file_form, file_position, file_action, file_status, do_backup, on_file, is_new_file, mpi_io, fout, file_access)
...
Defines the basic variable types.
integer, parameter, public dp
Types and basic routines needed for a kpoint calculation.
subroutine, public get_kpoint_info(kpoint, kp_scheme, nkp_grid, kp_shift, symmetry, verbose, full_grid, use_real_wfn, eps_geo, parallel_group_size, kp_range, nkp, xkp, wkp, para_env, blacs_env_all, para_env_kp, para_env_inter_kp, blacs_env, kp_env, kp_aux_env, mpools, iogrp, nkp_groups, kp_dist, cell_to_index, index_to_cell, sab_nl, sab_nl_nosym, inversion_symmetry_only, symmetry_backend, symmetry_reduction_method, gamma_centered, lattice_fft)
Retrieve information from a kpoint environment.
Definition of mathematical constants and functions.
complex(kind=dp), parameter, public z_one
real(kind=dp), parameter, public twopi
complex(kind=dp), parameter, public z_zero
Collection of simple mathematical functions and subroutines.
elemental real(kind=dp) function, public binomial(n, k)
The binomial coefficient n over k for 0 <= k <= n is calculated, otherwise zero is returned.
Interface to the message passing library MPI.
basic linear algebra operations for full matrixes
Define the data structure for the particle information.
container for various plainwaves related things
subroutine, public pw_env_get(pw_env, pw_pools, cube_info, gridlevel_info, auxbas_pw_pool, auxbas_grid, auxbas_rs_desc, auxbas_rs_grid, rs_descs, rs_grids, xc_pw_pool, vdw_pw_pool, poisson_env, interp_section)
returns the various attributes of the pw env
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
collects routines that calculate density matrices
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.
Assembly of real and complex k-point operators from real-space DBCSR matrices. Outputs use the distri...
integer, parameter, public kpoint_spin_free
Row of rsmat that carries the spin-free operator image. S and T carry no spin copies: drivers launch ...
integer, parameter, public kpoint_slot_s
subroutine, public kpoint_operator_get_all(kpoints, ao_ao_fm, rsmat, slot, cmat, matrix_row)
Fill caller-owned matrices for one operator row, including independent history snapshots....
Methods for preparing and committing k-point orbital states to the QS environment.
subroutine, public qs_kpoint_state_commit(qs_env, update_occupations, separate_spin_occupations, fixed_occupations)
Rebuilds the physical density from the current k-point orbitals and occupations.
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_pool, 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)
collects routines that perform operations directly related to MOs
subroutine, public make_basis_simple(vmatrix, ncol)
given a set of vectors, return an orthogonal (C^T C == 1) set spanning the same space (notice,...
subroutine, public make_basis_lowdin(vmatrix, ncol, matrix_s)
return a set of S orthonormal vectors (C^T S C == 1) where a Loedwin transformation is applied to kee...
subroutine, public make_basis_cholesky(vmatrix, ncol, ortho)
return a set of S orthonormal vectors (C^T S C == 1) where the cholesky decomposed form of S is passe...
subroutine, public make_basis_sm(vmatrix, ncol, matrix_s)
returns an S-orthonormal basis v (v^T S v ==1)
Definition and initialisation of the mo data type.
subroutine, public get_mo_set(mo_set, maxocc, homo, lfomo, nao, nelectron, n_el_f, nmo, eigenvalues, occupation_numbers, mo_coeff, mo_coeff_b, uniform_occupation, kts, mu, flexible_electron_count, cmo_coeff)
Get the components of a MO set data structure.
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...
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...
module that contains the definitions of the scf types
integer, parameter, public ot_method_nr
Storage of past states of the qs_env. Methods to interpolate (or actually normally extrapolate) the n...
subroutine, public wfi_create_for_kp(wf_history)
Adapts wf_history storage flags for k-point calculations. For ASPC, switches from Gamma WFN storage t...
subroutine, public wfi_purge_history(qs_env)
purges wf_history retaining only the latest snapshot
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
subroutine, public wfi_create(wf_history, interpolation_method_nr, extrapolation_order, has_unit_metric)
...
interpolate the wavefunctions to speed up the convergence when doing MD
type(qs_wf_snapshot_type) function, pointer, public wfi_get_snapshot(wf_history, wf_index)
returns a snapshot, the first being the latest snapshot
subroutine, public wfi_release(wf_history)
releases a wf_history of a wavefunction (see doc/ReferenceCounting.html)
parameters that control an scf iteration
Type defining parameters related to the simulation cell.
Represent a complex full matrix.
to create arrays of pools
represent a pool of elements with the same structure
keeps the information about the structure of a full matrix
type of a logger, at the moment it contains just a print level starting at which level it should be l...
Keeps information about a specific k-point.
Contains information about kpoints.
stores all the informations relevant to an mpi environment
contained for different pw related things
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
container for the pools of matrixes used by qs
keeps the density in various representations, keeping track of which ones are valid.
keeps track of the previous wavefunctions and can extrapolate them for the next step of md
represent a past snapshot of the wavefunction. some elements might not be associated (to spare memory...