251#include "./base/base_uses.f90"
257 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'qs_scf'
258 INTEGER,
PARAMETER,
PRIVATE :: kp_ot_entry_initial = 1, &
259 kp_ot_entry_reuse = 2, &
260 kp_ot_entry_resized = 3, &
261 kp_ot_entry_refresh = 4
262 LOGICAL,
PRIVATE :: reuse_precond = .false.
263 LOGICAL,
PRIVATE :: used_history = .false.
279 SUBROUTINE scf(qs_env, has_converged, total_scf_steps)
281 LOGICAL,
INTENT(OUT),
OPTIONAL :: has_converged
282 INTEGER,
INTENT(OUT),
OPTIONAL :: total_scf_steps
284 INTEGER :: ihistory, max_scf_tmp, tsteps
285 LOGICAL :: converged, outer_scf_loop, should_stop
286 LOGICAL,
SAVE :: first_step_flag = .true.
287 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: gradient_history, variable_history
296 cpassert(
ASSOCIATED(qs_env))
297 IF (
PRESENT(has_converged))
THEN
298 has_converged = .false.
300 IF (
PRESENT(total_scf_steps))
THEN
303 CALL get_qs_env(qs_env, scf_env=scf_env, input=input, &
304 dft_control=dft_control, scf_control=scf_control)
306 qs_env%scf_convergence_available = .false.
307 qs_env%scf_converged = .false.
308 IF (scf_control%max_scf > 0)
THEN
313 IF (.NOT.
ASSOCIATED(scf_env))
THEN
321 IF ((scf_control%density_guess ==
history_guess) .AND. (first_step_flag))
THEN
322 max_scf_tmp = scf_control%max_scf
323 scf_control%max_scf = 1
324 outer_scf_loop = scf_control%outer_scf%have_scf
325 scf_control%outer_scf%have_scf = .false.
328 IF (.NOT. dft_control%qs_control%cdft)
THEN
329 CALL scf_env_do_scf(scf_env=scf_env, scf_control=scf_control, qs_env=qs_env, &
330 converged=converged, should_stop=should_stop, total_scf_steps=tsteps)
333 CALL cdft_scf(qs_env=qs_env, should_stop=should_stop, &
334 has_converged=converged, total_scf_steps=tsteps)
337 qs_env%scf_convergence_available = .true.
338 qs_env%scf_converged = converged
341 IF (
ASSOCIATED(qs_env%mp2_env)) qs_env%mp2_env%hf_fail = .NOT. converged
347 IF (scf_control%outer_scf%have_scf)
THEN
348 ihistory = scf_env%outer_scf%iter_count
349 CALL get_qs_env(qs_env, gradient_history=gradient_history, &
350 variable_history=variable_history)
352 gradient_history(:, 1) = gradient_history(:, 2)
353 gradient_history(:, 2) = scf_env%outer_scf%gradient(:, ihistory)
354 variable_history(:, 1) = variable_history(:, 2)
355 variable_history(:, 2) = scf_env%outer_scf%variables(:, ihistory)
357 IF (used_history) used_history = .false.
359 IF (
ASSOCIATED(scf_env%outer_scf%inv_jacobian))
THEN
360 scf_control%outer_scf%cdft_opt_control%ijacobian(2) = scf_control%outer_scf%cdft_opt_control%ijacobian(2) + 1
361 IF (scf_control%outer_scf%cdft_opt_control%ijacobian(2) >= &
362 scf_control%outer_scf%cdft_opt_control%jacobian_freq(2) .AND. &
363 scf_control%outer_scf%cdft_opt_control%jacobian_freq(2) > 0)
THEN
364 scf_env%outer_scf%deallocate_jacobian = .true.
369 IF ((
ASSOCIATED(qs_env%wf_history)) .AND. &
371 (.NOT. first_step_flag)))
THEN
372 IF (.NOT. dft_control%qs_control%cdft)
THEN
374 IF (.NOT. qs_env%skip_wf_history)
THEN
375 CALL wfi_update(qs_env%wf_history, qs_env=qs_env, dt=1.0_dp)
378 IF (dft_control%qs_control%cdft_control%should_purge)
THEN
381 dft_control%qs_control%cdft_control%should_purge = .false.
383 CALL wfi_update(qs_env%wf_history, qs_env=qs_env, dt=1.0_dp)
386 ELSE IF ((scf_control%density_guess ==
history_guess) .AND. &
387 (first_step_flag))
THEN
388 scf_control%max_scf = max_scf_tmp
389 scf_control%outer_scf%have_scf = outer_scf_loop
390 first_step_flag = .false.
397 IF (.NOT. (should_stop))
THEN
406 IF (dft_control%qs_control%cdft)
THEN
407 CALL cdft_control_cleanup(dft_control%qs_control%cdft_control)
410 IF (
PRESENT(has_converged))
THEN
411 has_converged = converged
413 IF (
PRESENT(total_scf_steps))
THEN
414 total_scf_steps = tsteps
438 SUBROUTINE scf_env_do_scf(scf_env, scf_control, qs_env, converged, should_stop, total_scf_steps)
443 LOGICAL,
INTENT(OUT) :: converged, should_stop
444 INTEGER,
INTENT(OUT) :: total_scf_steps
446 CHARACTER(LEN=*),
PARAMETER :: routinen =
'scf_env_do_scf'
447 INTEGER,
PARAMETER :: max_ot_kp_subspace_refreshes = 4
448 REAL(kind=
dp),
PARAMETER :: adiis_stagnation_ratio = 1.0e-2_dp
450 CHARACTER(LEN=default_string_length) :: description, name
451 INTEGER :: accepted_ot_kp_searches, ext_master_id, handle, handle2, i_tmp, ic, ispin, &
452 iter_count, kp_ot_entry_reason, ot_kp_subspace_refresh_count, &
453 ot_kp_subspace_refresh_iter_count, output_unit, scf_energy_message_tag, total_steps
454 LOGICAL :: added_mos_auto_grow, adiis_pushed, adiis_restarted, adiis_stagnated, &
455 adiis_validation, density_full_step, diis_step, do_kpoints, energy_only, exit_inner_loop, &
456 exit_outer_loop, inner_loop_converged, internal_tblite_density_full_step, &
457 internal_tblite_mixer, just_energy, ot_kp_subspace_refresh, &
458 ot_kp_subspace_refresh_pending, outer_loop_converged, tblite_native_mixer, u_changed
459 REAL(
dp),
POINTER :: subspace_density(:, :), &
461 REAL(kind=
dp) :: adiis_raw_delta, adiis_step_delta, t1, t2
462 REAL(kind=
dp),
DIMENSION(3) :: res_val_3
467 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_ks_kp, rho_ao_kp
471 TYPE(
mo_set_type),
DIMENSION(:),
POINTER :: mos, mos_last_converged
478 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
486 CALL timeset(routinen, handle)
488 NULLIFY (dft_control, rho, energy, &
489 logger, qs_charges, ks_env, mos, atomic_kind_set, qs_kind_set, &
490 particle_set, dft_section, input, &
491 scf_section, para_env, results, kpoints, pw_env, matrix_ks, &
492 matrix_ks_kp, rho_ao_kp, mos_last_converged)
494 cpassert(
ASSOCIATED(scf_env))
495 cpassert(
ASSOCIATED(qs_env))
502 particle_set=particle_set, &
503 qs_charges=qs_charges, &
505 atomic_kind_set=atomic_kind_set, &
506 qs_kind_set=qs_kind_set, &
509 matrix_ks_kp=matrix_ks_kp, &
511 dft_control=dft_control, &
512 do_kpoints=do_kpoints, &
517 tblite_native_mixer = dft_control%qs_control%xtb_control%do_tblite .AND. &
520 internal_tblite_mixer = (dft_control%qs_control%dftb .AND. &
522 (dft_control%qs_control%xtb .AND. &
523 .NOT. dft_control%qs_control%xtb_control%do_tblite .AND. &
525 internal_tblite_density_full_step = dft_control%qs_control%xtb .AND. &
526 .NOT. dft_control%qs_control%xtb_control%do_tblite .AND. &
537 IF (scf_control%gce%do_gce .AND. output_unit > 0)
THEN
538 WRITE (unit=output_unit, fmt=
"(/,T2,78('-'))")
539 WRITE (unit=output_unit, fmt=
"(T31,A)") &
540 "GRAND-CANONICAL SCF"
541 WRITE (unit=output_unit, fmt=
"(T20,A,F12.6,A)") &
542 "Target work function (TWF):", &
543 evolt*scf_control%gce%target_workfunction,
" eV"
544 WRITE (unit=output_unit, fmt=
"(T2,78('-'))")
547 IF (output_unit > 0)
WRITE (unit=output_unit, fmt=
"(/,/,T2,A)") &
548 "SCF WAVEFUNCTION OPTIMIZATION"
551 IF (dft_control%switch_surf_dip)
THEN
552 CALL get_qs_env(qs_env, mos_last_converged=mos_last_converged)
553 DO ispin = 1, dft_control%nspins
556 IF (output_unit > 0)
WRITE (unit=output_unit, fmt=
"(/,/,T2,A)") &
557 "COPIED mos_last_converged ---> mos"
560 IF ((output_unit > 0) .AND. (.NOT. scf_control%use_ot))
THEN
561 WRITE (unit=output_unit, &
562 fmt=
"(/,T3,A,T12,A,T31,A,T39,A,T59,A,T75,A,/,T3,A)") &
563 "Step",
"Update method",
"Time",
"Convergence",
"Total energy",
"Change", &
569 res_val_3(:) = -1.0_dp
570 description =
"[EXT_SCF_ENER_COMM]"
572 CALL get_results(results, description=description, &
573 values=res_val_3, n_entries=i_tmp)
575 IF (all(res_val_3(:) <= 0.0_dp))
THEN
576 CALL cp_abort(__location__, &
577 " Trying to access result ("//trim(description)// &
578 ") which is not correctly stored.")
580 CALL external_comm%set_handle(nint(res_val_3(1)))
582 ext_master_id = nint(res_val_3(2))
583 scf_energy_message_tag = nint(res_val_3(3))
587 scf_env%outer_scf%iter_count = 0
588 accepted_ot_kp_searches = 0
590 kp_ot_entry_reason = kp_ot_entry_initial
591 ot_kp_subspace_refresh_count = 0
592 ot_kp_subspace_refresh_iter_count = 0
593 ot_kp_subspace_refresh_pending = .false.
595 energy%tot_old = 0.0_dp
600 scf_section=scf_section, &
601 kp_ot_entry_reason=kp_ot_entry_reason)
602 kp_ot_entry_reason = kp_ot_entry_reuse
603 scf_env%adiis_shift = scf_control%diagonalization%adiis_shift
606 energy_only, just_energy, exit_inner_loop)
607 IF (ot_kp_subspace_refresh_pending)
THEN
608 scf_env%iter_count = ot_kp_subspace_refresh_iter_count
609 ot_kp_subspace_refresh_pending = .false.
613 dft_control%surf_dip_correct_switch = dft_control%correct_surf_dip
614 IF ((dft_control%correct_surf_dip) .AND. (scf_control%outer_scf%have_scf) .AND. &
615 (scf_env%outer_scf%iter_count > floor(scf_control%outer_scf%max_scf/2.0_dp)))
THEN
616 IF (dft_control%switch_surf_dip)
THEN
617 dft_control%surf_dip_correct_switch = .false.
618 IF (output_unit > 0)
WRITE (unit=output_unit, fmt=
"(/,/,T2,A)") &
619 "SURFACE DIPOLE CORRECTION switched off"
625 CALL timeset(routinen//
"_inner_loop", handle2)
627 IF (.NOT. just_energy) scf_env%iter_count = scf_env%iter_count + 1
628 iter_count = iter_count + 1
629 CALL cp_iterate(logger%iter_info, last=.false., iter_nr=iter_count)
631 IF (output_unit > 0)
CALL m_flush(output_unit)
633 total_steps = total_steps + 1
634 just_energy = energy_only
637 calculate_forces=.false.)
639 scf_env%raw_map_delta = 0.0_dp
640 scf_env%raw_map_delta_valid = .false.
644 added_mos_auto_grow = .false.
645 ot_kp_subspace_refresh = .false.
647 scf_env%adiis_check_next
648 adiis_step_delta = scf_env%step_norm
649 scf_env%adiis_validated = .false.
652 NULLIFY (subspace_density, subspace_fock)
654 IF (
ALLOCATED(kpoints%lowdin_q))
THEN
655 subspace_density => kpoints%lowdin_q
656 subspace_fock => kpoints%lowdin_v
663 cpassert(
ASSOCIATED(scf_env%scf_subspace_buffer))
664 scf_env%scf_subspace_buffer%last_restart = .false.
665 scf_env%scf_subspace_buffer%use_combined_fock = .false.
666 scf_env%scf_subspace_buffer%last_old_fock_weight = 0.0_dp
667 IF (.NOT. adiis_validation .AND. scf_env%iter_count > 1)
THEN
672 IF (scf_control%diagonalization%adiis_shift > 0.0_dp .OR. &
673 scf_env%scf_subspace_buffer%diis_weight < 1.0_dp .OR. &
674 scf_env%iter_delta >= scf_control%eps_diis)
THEN
676 energy%total, adiis_pushed, subspace_density, subspace_fock)
677 IF (.NOT. adiis_pushed) cpabort(
"Failed to append the accepted ADIIS SCF state")
679 IF (scf_control%diagonalization%adiis_shift > 0.0_dp)
THEN
686 added_mos_auto_grow=added_mos_auto_grow)
688 CALL qs_scf_new_mos(qs_env, scf_env, scf_control, scf_section, diis_step, energy_only)
691 IF (adiis_validation)
THEN
693 scf_env%raw_map_delta = adiis_raw_delta
694 scf_env%raw_map_delta_valid = .true.
695 IF (adiis_raw_delta < scf_control%eps_scf)
THEN
696 scf_env%iter_delta = adiis_raw_delta
697 scf_env%iter_param = 0.0_dp
698 scf_env%iter_method =
"ADIIS/Chk."
699 scf_env%adiis_validated = .true.
700 scf_env%adiis_check_next = .false.
702 adiis_stagnated = adiis_step_delta <= adiis_stagnation_ratio*adiis_raw_delta
703 IF (adiis_stagnated)
THEN
710 energy%total, adiis_restarted, subspace_density, subspace_fock)
711 IF (.NOT. adiis_restarted)
THEN
712 cpabort(
"Failed to restart the ADIIS history from the current SCF state")
714 scf_env%iter_delta = adiis_raw_delta
715 scf_env%iter_param = 0.0_dp
716 scf_env%iter_method =
"ADIIS/Rst."
717 scf_env%adiis_check_next = .false.
723 energy%total, adiis_pushed, subspace_density, subspace_fock)
724 IF (.NOT. adiis_pushed) cpabort(
"Failed to append the accepted ADIIS SCF state")
728 added_mos_auto_grow=added_mos_auto_grow)
730 CALL qs_scf_new_mos(qs_env, scf_env, scf_control, scf_section, diis_step, energy_only)
733 scf_env%adiis_validated = scf_env%iter_delta < scf_control%eps_scf
734 IF (scf_env%adiis_validated .AND. .NOT. diis_step)
THEN
735 scf_env%iter_param = 0.0_dp
736 scf_env%iter_method =
"ADIIS/Chk."
740 scf_env%adiis_check_next = .false.
745 IF (.NOT. adiis_validation)
THEN
747 scf_env%adiis_check_next = .NOT. diis_step .AND. &
748 scf_env%iter_delta < scf_control%eps_scf
754 IF (dft_control%hairy_probes .EQV. .true.)
THEN
755 scf_control%smear%do_smear = .false.
756 CALL qs_scf_new_mos_kp(qs_env, scf_env, scf_control, diis_step, dft_control%probe, &
757 energy_only=energy_only)
760 qs_env, scf_env, scf_control, diis_step, &
761 ot_kp_subspace_refresh=ot_kp_subspace_refresh, &
762 allow_ot_kp_subspace_refresh= &
763 ot_kp_subspace_refresh_count == 0, &
764 allow_ot_kp_exit_refresh= &
765 ot_kp_subspace_refresh_count > 0 .AND. &
766 ot_kp_subspace_refresh_count < max_ot_kp_subspace_refreshes, &
767 accepted_ot_kp_searches=accepted_ot_kp_searches, &
768 added_mos_auto_grow=added_mos_auto_grow, energy_only=energy_only)
772 IF (dft_control%hairy_probes .EQV. .true.)
THEN
773 scf_control%smear%do_smear = .false.
774 CALL qs_scf_new_mos(qs_env, scf_env, scf_control, scf_section, diis_step, energy_only, &
777 CALL qs_scf_new_mos(qs_env, scf_env, scf_control, scf_section, diis_step, energy_only)
782 IF (added_mos_auto_grow)
THEN
783 CALL qs_scf_grow_added_mos_auto_kp(qs_env, scf_env, scf_control, output_unit)
784 kp_ot_entry_reason = kp_ot_entry_resized
785 total_steps = max(0, total_steps - 1)
786 iter_count = max(0, iter_count - 1)
787 IF (.NOT. just_energy) scf_env%iter_count = max(0, scf_env%iter_count - 1)
788 CALL timestop(handle2)
792 IF (ot_kp_subspace_refresh)
THEN
793 IF (output_unit > 0)
THEN
794 WRITE (unit=output_unit, fmt=
"(T2,A)") &
795 "K-point OT: rebuilding physical virtual subspace by full KS diagonalization."
798 IF (
ASSOCIATED(scf_env%qs_ot_env))
THEN
799 DO ispin = 1,
SIZE(scf_env%qs_ot_env)
802 DEALLOCATE (scf_env%qs_ot_env)
803 NULLIFY (scf_env%qs_ot_env)
805 IF (
ASSOCIATED(kpoints%scf_diis_buffer))
THEN
808 reuse_precond = .false.
809 accepted_ot_kp_searches = 0
810 ot_kp_subspace_refresh_count = ot_kp_subspace_refresh_count + 1
811 total_steps = max(0, total_steps - 1)
812 iter_count = max(0, iter_count - 1)
813 IF (.NOT. just_energy) scf_env%iter_count = max(0, scf_env%iter_count - 1)
814 ot_kp_subspace_refresh_iter_count = scf_env%iter_count
815 ot_kp_subspace_refresh_pending = .true.
816 kp_ot_entry_reason = kp_ot_entry_refresh
817 CALL timestop(handle2)
821 IF (do_kpoints .AND. scf_env%method ==
ot_method_nr .AND. &
823 accepted_ot_kp_searches = accepted_ot_kp_searches + 1
829 IF (dft_control%qs_control%xtb_control%do_tblite)
THEN
834 cpassert(scf_env%mixing_method > 0)
843 density_full_step = .true.
845 density_full_step = diis_step .OR. tblite_native_mixer .OR. internal_tblite_density_full_step
848 IF (dft_control%qs_control%xtb_control%do_tblite .AND. &
849 .NOT. (dft_control%qs_control%do_ls_scf .OR. scf_control%use_ot))
THEN
850 scf_env%iter_delta = max(scf_env%iter_delta, &
852 scf_control%eps_scf))
854 IF (dft_control%qs_control%dftb .OR. &
855 (dft_control%qs_control%xtb .AND. .NOT. dft_control%qs_control%xtb_control%do_tblite))
THEN
856 scf_env%iter_delta = max(scf_env%iter_delta, &
859 IF (tblite_native_mixer)
THEN
860 scf_env%iter_param = dft_control%qs_control%xtb_control%tblite_mixer_damping
861 scf_env%iter_method =
"TBLite/Diag"
862 ELSE IF (internal_tblite_mixer)
THEN
863 scf_env%iter_method =
"TBLite/Diag"
864 IF (dft_control%qs_control%dftb)
THEN
865 scf_env%iter_param = dft_control%qs_control%dftb_control%tblite_mixer_damping
867 scf_env%iter_param = dft_control%qs_control%xtb_control%tblite_mixer_damping
870 scf_env%step_norm = scf_env%iter_delta
874 CALL rebuild_xtb_total_energy(energy, dft_control)
876 scf_control%diagonalization%adiis_verbose)
878 IF (scf_control%gce%do_gce)
THEN
882 IF (.NOT. just_energy) energy%tot_old = energy%total
885 IF (scf_energy_message_tag > 0)
THEN
886 CALL external_comm%send(energy%total, ext_master_id, scf_energy_message_tag)
890 exit_inner_loop, inner_loop_converged, output_unit, u_changed)
893 IF (scf_env%mixing_method > 1)
THEN
894 CALL get_qs_env(qs_env, rho_atom_set=rho_atom)
895 CALL mixing_init(scf_env%mixing_method, rho, scf_env%mixing_store, para_env, &
896 rho_atom=rho_atom, auxiliary=kpoints%lowdin_q)
898 CALL init_scf_loop(scf_env, qs_env, scf_section, kp_ot_entry_reuse)
899 energy_only = .false.
900 just_energy = .false.
901 CALL timestop(handle2)
907 IF (exit_inner_loop)
THEN
912 outer_loop_converged, exit_outer_loop)
915 IF (exit_outer_loop)
CALL cp_iterate(logger%iter_info, last=.true., iter_nr=iter_count)
922 IF (.NOT. dft_control%mtlr_dft_with_perturbation)
THEN
927 .NOT. (dft_control%low_spin_roks .AND. dft_control%qs_control%gapw))
THEN
929 CALL get_ks_env(ks_env=ks_env, matrix_ks=matrix_ks)
939 IF (exit_inner_loop)
THEN
940 CALL timestop(handle2)
945 scf_section,
"PRINT%ITERATION_INFO/TIME_CUMUL"),
cp_p_file))
THEN
950 IF (scf_env%mixing_method > 0)
THEN
951 DO ic = 1,
SIZE(rho_ao_kp, 2)
952 DO ispin = 1, dft_control%nspins
954 CALL dbcsr_copy(rho_ao_kp(ispin, ic)%matrix, scf_env%p_mix_new(ispin, ic)%matrix, name=name)
962 CALL timestop(handle2)
966 IF (.NOT. scf_control%outer_scf%have_scf)
EXIT scf_outer_loop
970 energy, total_steps, should_stop, outer_loop_converged)
973 IF (exit_outer_loop)
THEN
974 IF ((dft_control%switch_surf_dip) .AND. (outer_loop_converged) .AND. &
975 (dft_control%surf_dip_correct_switch))
THEN
976 DO ispin = 1, dft_control%nspins
979 IF (output_unit > 0)
WRITE (unit=output_unit, fmt=
"(/,/,T2,A)") &
980 "COPIED mos ---> mos_last_converged"
984 IF (exit_outer_loop)
EXIT scf_outer_loop
991 END DO scf_outer_loop
993 converged = inner_loop_converged .AND. outer_loop_converged
994 total_scf_steps = total_steps
996 IF (dft_control%qs_control%cdft)
THEN
997 dft_control%qs_control%cdft_control%total_steps = &
998 dft_control%qs_control%cdft_control%total_steps + total_steps
1001 IF (.NOT. converged)
THEN
1002 IF (scf_control%ignore_convergence_failure .OR. should_stop)
THEN
1003 CALL cp_warn(__location__,
"SCF run NOT converged")
1005 CALL cp_abort(__location__, &
1006 "SCF run NOT converged. To continue the calculation "// &
1007 "regardless, please set the keyword IGNORE_CONVERGENCE_FAILURE.")
1012 IF (qs_env%energy_correction)
THEN
1014 ec_env%do_skip = .false.
1015 IF (ec_env%skip_ec .AND. .NOT. converged) ec_env%do_skip = .true.
1019 DO ispin = 1,
SIZE(mos)
1020 IF (mos(ispin)%use_mo_coeff_b)
THEN
1021 IF (.NOT.
ASSOCIATED(mos(ispin)%mo_coeff_b))
THEN
1023 cpabort(
"mo_coeff_b is not allocated")
1026 mos(ispin)%mo_coeff)
1031 CALL timestop(handle)
1042 SUBROUTINE qs_scf_grow_added_mos_auto_kp(qs_env, scf_env, scf_control, output_unit)
1047 INTEGER,
INTENT(IN) :: output_unit
1049 CHARACTER(LEN=*),
PARAMETER :: routinen =
'qs_scf_grow_added_mos_auto_kp'
1051 INTEGER :: base_nmo, common_base_nmo, current_added, current_target_nmo, grow_by, handle, &
1052 ic, ik, ispin, nmo_mat, nspins, old_nmo, target_nmo
1053 INTEGER,
DIMENSION(2) :: base_nmo_spin, new_added, new_nmo
1054 LOGICAL :: diag_step, has_unit_metric, need_resize, &
1056 REAL(kind=
dp) :: energy_step, flexible_electron_count, &
1058 REAL(kind=
dp),
DIMENSION(:),
POINTER :: eigenvalues, occupation_numbers, &
1059 old_eigenvalues, old_occupation_numbers
1064 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_ks, matrix_s
1068 TYPE(
mo_set_type),
ALLOCATABLE,
DIMENSION(:) :: old_mos
1072 CALL timeset(routinen, handle)
1074 NULLIFY (ao_mo_fm_pools, blacs_env, dft_control, eigenvalues, kpoints, matrix_ks, matrix_s, &
1075 mo_coeff, mo_derivs, mos, occupation_numbers, old_eigenvalues, &
1076 old_occupation_numbers, para_env)
1078 CALL get_qs_env(qs_env=qs_env, blacs_env=blacs_env, dft_control=dft_control, &
1079 kpoints=kpoints, matrix_ks_kp=matrix_ks, matrix_s_kp=matrix_s, &
1080 mo_derivs=mo_derivs, mos=mos, para_env=para_env, &
1081 has_unit_metric=has_unit_metric)
1083 cpassert(
ASSOCIATED(mos))
1084 cpassert(
ASSOCIATED(kpoints))
1085 cpassert(
ASSOCIATED(dft_control))
1086 cpassert(
ASSOCIATED(scf_control))
1087 cpassert(
ASSOCIATED(matrix_ks))
1088 cpassert(
ASSOCIATED(matrix_s))
1090 nspins = dft_control%nspins
1091 cpassert(nspins >= 1 .AND. nspins <=
SIZE(new_nmo))
1092 new_added = scf_control%added_mos
1094 need_resize = .false.
1095 shared_spin_auto = nspins == 2 .AND. all(scf_control%added_mos_auto(1:2))
1097 IF (shared_spin_auto)
THEN
1098 DO ispin = 1, nspins
1099 current_added = max(0, scf_control%added_mos(ispin))
1100 base_nmo_spin(ispin) = max(0, mos(ispin)%nmo - current_added)
1102 common_base_nmo = maxval(base_nmo_spin(1:nspins))
1103 current_target_nmo = maxval(mos(1:nspins)%nmo)
1104 current_added = max(0, current_target_nmo - common_base_nmo)
1105 grow_by = max(4, current_added)
1106 target_nmo = min(minval(mos(1:nspins)%nao), current_target_nmo + grow_by)
1107 DO ispin = 1, nspins
1108 new_nmo(ispin) = target_nmo
1109 new_added(ispin) = target_nmo - base_nmo_spin(ispin)
1110 need_resize = need_resize .OR. new_nmo(ispin) > mos(ispin)%nmo
1113 DO ispin = 1, nspins
1114 old_nmo = mos(ispin)%nmo
1115 new_nmo(ispin) = old_nmo
1116 IF (.NOT. scf_control%added_mos_auto(ispin)) cycle
1117 current_added = max(0, scf_control%added_mos(ispin))
1118 base_nmo = max(0, old_nmo - current_added)
1119 grow_by = max(4, current_added)
1120 new_added(ispin) = min(mos(ispin)%nao - base_nmo, current_added + grow_by)
1121 new_nmo(ispin) = base_nmo + new_added(ispin)
1122 need_resize = need_resize .OR. new_nmo(ispin) > old_nmo
1125 IF (nspins == 2)
THEN
1126 target_nmo = maxval(new_nmo(1:nspins))
1127 DO ispin = 1, nspins
1128 IF (target_nmo > mos(ispin)%nao)
THEN
1129 CALL cp_abort(__location__, &
1130 "K-point ADDED_MOS AUTO exhausted the AO basis while matching spin bands.")
1132 IF (target_nmo > mos(ispin)%nmo .AND. .NOT. scf_control%added_mos_auto(ispin))
THEN
1133 CALL cp_abort(__location__, &
1134 "K-point ADDED_MOS AUTO needs to grow a spin channel with explicit ADDED_MOS.")
1136 base_nmo = max(0, mos(ispin)%nmo - max(0, scf_control%added_mos(ispin)))
1137 new_nmo(ispin) = target_nmo
1138 new_added(ispin) = target_nmo - base_nmo
1139 need_resize = need_resize .OR. new_nmo(ispin) > mos(ispin)%nmo
1144 IF (.NOT. need_resize)
THEN
1145 CALL cp_abort(__location__, &
1146 "K-point ADDED_MOS AUTO cannot grow further although the highest band is still occupied.")
1149 scf_control%added_mos(1:nspins) = new_added(1:nspins)
1150 IF (output_unit > 0)
THEN
1151 IF (nspins == 2)
THEN
1152 WRITE (unit=output_unit, fmt=
"(T2,A,2I5)") &
1153 "K-point ADDED_MOS AUTO: growing virtual-space buffer to:", &
1154 scf_control%added_mos(1:nspins)
1156 WRITE (unit=output_unit, fmt=
"(T2,A,I0)") &
1157 "K-point ADDED_MOS AUTO: growing virtual-space buffer to: ", &
1158 scf_control%added_mos(1)
1163 ALLOCATE (old_mos(nspins))
1164 DO ispin = 1, nspins
1166 CALL get_mo_set(old_mos(ispin), maxocc=maxocc, n_el_f=n_el_f, &
1167 flexible_electron_count=flexible_electron_count)
1169 CALL allocate_mo_set(mo_set=mos(ispin), nao=old_mos(ispin)%nao, nmo=new_nmo(ispin), &
1170 nelectron=old_mos(ispin)%nelectron, n_el_f=n_el_f, maxocc=maxocc, &
1171 flexible_electron_count=flexible_electron_count)
1172 mos(ispin)%use_mo_coeff_b = old_mos(ispin)%use_mo_coeff_b
1176 CALL mpools_get(qs_env%mpools, ao_mo_fm_pools=ao_mo_fm_pools)
1178 DO ispin = 1, nspins
1179 CALL init_mo_set(mos(ispin), fm_pool=ao_mo_fm_pools(ispin)%pool, &
1181 CALL get_mo_set(mos(ispin), mo_coeff=mo_coeff, eigenvalues=eigenvalues, &
1182 occupation_numbers=occupation_numbers)
1183 CALL get_mo_set(old_mos(ispin), eigenvalues=old_eigenvalues, &
1184 occupation_numbers=old_occupation_numbers)
1186 old_nmo = old_mos(ispin)%nmo
1188 IF (has_unit_metric)
THEN
1191 CALL make_basis_sm(mo_coeff, mos(ispin)%nmo, matrix_s(1, 1)%matrix)
1194 eigenvalues(1:old_nmo) = old_eigenvalues(1:old_nmo)
1195 occupation_numbers(:) = 0.0_dp
1196 occupation_numbers(1:old_nmo) = old_occupation_numbers(1:old_nmo)
1197 IF (mos(ispin)%nmo > old_nmo)
THEN
1198 energy_step = max(scf_control%smear%electronic_temperature, 1.0e-3_dp)
1199 DO ic = old_nmo + 1, mos(ispin)%nmo
1200 eigenvalues(ic) = eigenvalues(old_nmo) + energy_step*real(ic - old_nmo, kind=
dp)
1203 mos(ispin)%homo = old_mos(ispin)%homo
1204 mos(ispin)%lfomo = old_mos(ispin)%lfomo
1205 mos(ispin)%kTS = old_mos(ispin)%kTS
1206 mos(ispin)%mu = old_mos(ispin)%mu
1207 mos(ispin)%uniform_occupation = old_mos(ispin)%uniform_occupation
1212 DO ispin = 1, nspins
1213 IF (.NOT. mos(ispin)%use_mo_coeff_b) cycle
1214 CALL get_mo_set(mos(ispin), mo_coeff=mo_coeff)
1217 n=mos(ispin)%nmo, sym=dbcsr_type_no_symmetry)
1221 IF (
ASSOCIATED(mo_derivs))
THEN
1222 DO ispin = 1,
SIZE(mo_derivs)
1223 IF (
ASSOCIATED(mo_derivs(ispin)%matrix))
CALL dbcsr_release_p(mo_derivs(ispin)%matrix)
1225 DEALLOCATE (mo_derivs)
1229 IF (qs_env%requires_mo_derivs)
THEN
1230 nmo_mat = merge(1, nspins, dft_control%restricted)
1231 ALLOCATE (mo_derivs(nmo_mat))
1232 DO ispin = 1, nmo_mat
1233 NULLIFY (mo_derivs(ispin)%matrix)
1235 CALL dbcsr_create(mo_derivs(ispin)%matrix, template=mos(ispin)%mo_coeff_b, &
1236 name=
"mo_derivs", matrix_type=dbcsr_type_no_symmetry)
1241 DO ik = 1,
SIZE(kpoints%kp_env)
1242 kp => kpoints%kp_env(ik)%kpoint_env
1243 IF (
ASSOCIATED(kp%mos))
THEN
1244 DO ispin = 1,
SIZE(kp%mos)
1258 CALL do_general_diag_kp(matrix_ks, matrix_s, kpoints, scf_env, scf_control, .false., diag_step)
1261 qs_env, update_occupations=.true., &
1262 separate_spin_occupations=dft_control%restricted, &
1263 fixed_occupations=.NOT. (dft_control%smear .OR. scf_control%smear%do_smear))
1265 IF (
ASSOCIATED(kpoints%scf_diis_buffer))
CALL qs_diis_b_clear_kp(kpoints%scf_diis_buffer)
1266 IF (
ASSOCIATED(scf_env%qs_ot_env))
THEN
1267 DO ispin = 1,
SIZE(scf_env%qs_ot_env)
1270 DEALLOCATE (scf_env%qs_ot_env)
1271 NULLIFY (scf_env%qs_ot_env)
1273 reuse_precond = .false.
1275 DO ispin = 1, nspins
1278 DEALLOCATE (old_mos)
1280 CALL timestop(handle)
1282 END SUBROUTINE qs_scf_grow_added_mos_auto_kp
1300 INTEGER,
INTENT(IN),
OPTIONAL :: kp_ot_entry_reason
1302 CHARACTER(LEN=*),
PARAMETER :: routinen =
'init_scf_loop'
1304 INTEGER :: entry_reason, handle, ikind, ispin, &
1305 nkpoint, nmo, nspin_ot
1306 INTEGER,
DIMENSION(2) :: kp_range
1307 LOGICAL :: do_adiis, do_kpoints, do_rotation, fixed_density_prepared, has_unit_metric, &
1308 kp_diis_step, kpoint_mos_initialized
1309 REAL(kind=
dp) :: u_ramping
1310 REAL(kind=
dp),
DIMENSION(:),
POINTER :: wkp
1312 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_ks, matrix_s
1313 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_ks_kp, matrix_s_kp, matrix_t_kp, &
1315 TYPE(
dbcsr_type),
POINTER :: orthogonality_metric
1319 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
1323 CALL timeset(routinen, handle)
1325 NULLIFY (scf_control, matrix_ks_kp, matrix_s, matrix_s_kp, matrix_t_kp, matrix_ks, &
1326 rho_ao_kp, dft_control, mos, mo_coeff, kpoints, qs_kind_set, rho, wkp)
1328 cpassert(
ASSOCIATED(scf_env))
1329 cpassert(
ASSOCIATED(qs_env))
1330 entry_reason = kp_ot_entry_initial
1331 IF (
PRESENT(kp_ot_entry_reason)) entry_reason = kp_ot_entry_reason
1332 fixed_density_prepared = .false.
1335 scf_control=scf_control, &
1336 dft_control=dft_control, &
1337 do_kpoints=do_kpoints, &
1341 qs_kind_set=qs_kind_set)
1345 nspin_ot = dft_control%nspins
1346 IF (dft_control%restricted) nspin_ot = 1
1347 IF (do_kpoints)
THEN
1348 CALL get_kpoint_info(kpoints, nkp=nkpoint, kp_range=kp_range, wkp=wkp)
1352 DO ispin = 1,
SIZE(mos)
1353 IF (mos(1)%use_mo_coeff_b)
THEN
1359 DO ispin = 1, dft_control%nspins
1361 IF (.NOT. scf_control%diagonalization%mom)
THEN
1364 IF (dft_control%hairy_probes .EQV. .true.)
THEN
1365 IF (scf_env%outer_scf%iter_count > 0)
THEN
1366 scf_control%smear%do_smear = .false.
1368 smear=scf_control%smear, &
1369 probe=dft_control%probe)
1372 IF (.NOT. scf_control%gce%do_gce)
THEN
1374 smear=scf_control%smear, &
1375 emit_warnings=.NOT. do_kpoints)
1378 smear=scf_control%smear, &
1379 gce=scf_control%gce, &
1380 emit_warnings=.NOT. do_kpoints)
1389 cpabort(
"ADIIS currently requires SCF%DIAGONALIZATION ALGORITHM STANDARD")
1392 cpabort(
"ADIIS is not yet compatible with CHOLESKY INVERSE_DBCSR")
1394 IF (dft_control%qs_control%dftb .OR. dft_control%qs_control%xtb .OR. &
1395 dft_control%qs_control%semi_empirical)
THEN
1396 cpabort(
"ADIIS currently requires a Quickstep DFT KS matrix")
1398 IF (dft_control%do_admm_mo)
THEN
1399 cpabort(
"ADIIS is not yet compatible with ADMM-MO")
1401 IF (dft_control%sic_method_id ==
sic_eo)
THEN
1402 cpabort(
"ADIIS is not yet compatible with explicit-orbital SIC")
1404 IF (dft_control%apply_period_efield)
THEN
1405 cpabort(
"ADIIS is not yet compatible with PERIODIC_EFIELD")
1407 IF (dft_control%dft_plus_u)
THEN
1408 cpassert(
ASSOCIATED(qs_kind_set))
1409 DO ikind = 1,
SIZE(qs_kind_set)
1410 CALL get_qs_kind(qs_kind_set(ikind), u_ramping=u_ramping)
1411 IF (u_ramping > 0.0_dp .AND. &
1412 (.NOT. do_kpoints .OR. dft_control%plus_u_method_id /=
plus_u_lowdin))
THEN
1413 cpabort(
"ADIIS is not yet compatible with DFT+U U_RAMPING")
1417 IF (dft_control%smear .OR. scf_control%smear%do_smear)
THEN
1418 cpabort(
"ADIIS finite-temperature smearing support is not implemented yet")
1420 IF (dft_control%roks .OR. scf_control%diagonalization%mom .OR. &
1421 dft_control%hairy_probes .OR. scf_control%gce%do_gce)
THEN
1422 cpabort(
"ADIIS currently supports ordinary RKS/UKS occupations only")
1424 IF (scf_control%do_diag_sub)
THEN
1425 cpabort(
"ADIIS is not yet compatible with DIAG_SUB_SCF")
1427 IF (scf_control%diagonalization%max_history < 1)
THEN
1428 cpabort(
"ADIIS requires SCF%ADIIS%MAX_HISTORY >= 1")
1430 IF (.NOT.
ASSOCIATED(scf_env%scf_subspace_buffer))
THEN
1431 ALLOCATE (scf_env%scf_subspace_buffer)
1433 scf_control%diagonalization%max_history)
1434 ELSE IF (scf_env%scf_subspace_buffer%nbuffer /= scf_control%diagonalization%max_history)
THEN
1437 scf_control%diagonalization%max_history)
1442 SELECT CASE (scf_env%method)
1445 CALL cp_abort(__location__, &
1446 "Unknown SCF method <"//trim(
cp_to_string(scf_env%method))//
"> found. Check the code!")
1450 IF (.NOT. scf_env%skip_diis)
THEN
1451 IF (.NOT.
ASSOCIATED(scf_env%scf_diis_buffer))
THEN
1452 ALLOCATE (scf_env%scf_diis_buffer)
1453 CALL qs_diis_b_create(scf_env%scf_diis_buffer, nbuffer=scf_control%max_diis)
1459 IF (.NOT. scf_env%skip_diis)
THEN
1460 IF (do_kpoints)
THEN
1461 IF (.NOT.
ASSOCIATED(kpoints%scf_diis_buffer))
THEN
1462 ALLOCATE (kpoints%scf_diis_buffer)
1467 IF (.NOT.
ASSOCIATED(scf_env%scf_diis_buffer))
THEN
1468 ALLOCATE (scf_env%scf_diis_buffer)
1469 CALL qs_diis_b_create(scf_env%scf_diis_buffer, nbuffer=scf_control%max_diis)
1476 IF (scf_control%diagonalization%ot_settings%preconditioner_type == &
1478 (dft_control%qs_control%dftb .OR. dft_control%qs_control%xtb .OR. &
1479 dft_control%qs_control%semi_empirical))
THEN
1480 CALL cp_warn(__location__, &
1481 "FULL_KINETIC is unavailable for semi-empirical DIAGONALIZATION%OT; "// &
1482 "falling back to FULL_S_INVERSE.")
1484 scf_control%diagonalization%ot_settings%preconditioner_name =
"FULL_S_INVERSE"
1486 IF (do_kpoints)
THEN
1487 IF (.NOT. scf_env%skip_diis)
THEN
1488 IF (.NOT.
ASSOCIATED(kpoints%scf_diis_buffer))
THEN
1489 ALLOCATE (kpoints%scf_diis_buffer)
1494 CALL timestop(handle)
1497 CALL get_qs_env(qs_env, matrix_ks=matrix_ks, matrix_s=matrix_s)
1499 IF (.NOT. scf_env%skip_diis)
THEN
1500 IF (.NOT.
ASSOCIATED(scf_env%scf_diis_buffer))
THEN
1501 ALLOCATE (scf_env%scf_diis_buffer)
1502 CALL qs_diis_b_create(scf_env%scf_diis_buffer, nbuffer=scf_control%max_diis)
1510 scf_control%diagonalization%ot_settings%preconditioner_type, &
1514 scf_control%diagonalization%ot_settings%preconditioner_type, &
1515 scf_control%diagonalization%ot_settings%precond_solver_type, &
1516 scf_control%diagonalization%ot_settings%energy_gap, dft_control%nspins, &
1517 chebyshev_degree=scf_control%diagonalization%ot_settings%chebyshev_degree, &
1518 low_rank_base=scf_control%diagonalization%ot_settings%low_rank_base, &
1519 fermi_low_rank_max_rank= &
1520 scf_control%diagonalization%ot_settings%fermi_low_rank_max_rank, &
1521 lattice_fft=scf_control%diagonalization%ot_settings%lattice_fft, &
1522 lattice_fft_local_cells= &
1523 scf_control%diagonalization%ot_settings%lattice_fft_local_cells)
1528 IF (do_kpoints)
THEN
1529 IF (.NOT.
ASSOCIATED(scf_env%qs_ot_env))
THEN
1530 CALL get_qs_env(qs_env, matrix_s_kp=matrix_s_kp, &
1531 kinetic_kp=matrix_t_kp)
1532 cpassert(
ASSOCIATED(matrix_s_kp))
1533 CALL allocate_qs_ot_envs(scf_env=scf_env, &
1534 scf_control=scf_control, &
1535 dft_control=dft_control, &
1536 scf_section=scf_section, &
1537 do_kpoints=do_kpoints, &
1539 nspin_ot=nspin_ot, &
1540 kp_range=kp_range, &
1544 ALLOCATE (scf_env%ot_operator_ctx)
1546 scf_env%scf_work1(1), dft_control%nspins)
1550 IF (.NOT. scf_env%qs_ot_env(1)%settings%do_ener)
THEN
1554 kpoints, require_full_space=scf_env%qs_ot_env(1)%settings%do_ener)
1555 SELECT CASE (entry_reason)
1556 CASE (kp_ot_entry_initial)
1557 IF (kpoint_mos_initialized)
THEN
1558 IF (dft_control%restricted)
THEN
1562 qs_env, update_occupations=.true., &
1563 separate_spin_occupations=dft_control%restricted, &
1564 fixed_occupations=.NOT. (dft_control%smear .OR. scf_control%smear%do_smear))
1566 CASE (kp_ot_entry_reuse, kp_ot_entry_resized, kp_ot_entry_refresh)
1567 cpassert(kpoint_mos_initialized)
1569 cpabort(
"Invalid k-point OT workspace entry reason.")
1575 IF (entry_reason == kp_ot_entry_initial .AND. .NOT. kpoint_mos_initialized .AND. &
1576 .NOT. scf_env%qs_ot_env(1)%settings%do_ener)
THEN
1577 cpassert(
ASSOCIATED(rho))
1579 cpassert(
ASSOCIATED(rho_ao_kp))
1582 IF (
SIZE(rho_ao_kp, 1) < nspin_ot)
THEN
1583 cpassert(
SIZE(rho_ao_kp, 1) == 1)
1586 IF (dft_control%restricted)
THEN
1590 qs_env, update_occupations=.true., &
1591 separate_spin_occupations=dft_control%restricted, fixed_occupations=.true.)
1596 fixed_density_prepared = .true.
1602 CALL get_qs_env(qs_env, matrix_ks_kp=matrix_ks_kp)
1603 cpassert(
ASSOCIATED(matrix_ks_kp))
1607 IF ((entry_reason == kp_ot_entry_initial .AND. .NOT. kpoint_mos_initialized) .OR. &
1608 entry_reason == kp_ot_entry_refresh)
THEN
1609 kp_diis_step = .false.
1611 scf_control, .false., kp_diis_step)
1612 IF (
SIZE(matrix_ks_kp, 1) < nspin_ot)
THEN
1613 cpassert(
SIZE(matrix_ks_kp, 1) == 1)
1616 IF (dft_control%restricted)
THEN
1620 qs_env, update_occupations=.true., &
1621 separate_spin_occupations=dft_control%restricted, &
1622 fixed_occupations=.NOT. (dft_control%smear .OR. scf_control%smear%do_smear))
1627 calculate_forces=.false.)
1631 CALL get_qs_env(qs_env, matrix_ks_kp=matrix_ks_kp)
1632 cpassert(
ASSOCIATED(matrix_ks_kp))
1641 scf_env%ot_ks_valid = .true.
1648 CALL allocate_qs_ot_kpoint_state(qs_env=qs_env, &
1650 dft_control=dft_control, &
1652 matrix_ks_kp=matrix_ks_kp, &
1653 matrix_s_kp=matrix_s_kp, &
1654 matrix_t_kp=matrix_t_kp, &
1658 CALL timestop(handle)
1663 has_unit_metric=has_unit_metric, &
1664 matrix_s=matrix_s, &
1665 matrix_ks=matrix_ks)
1671 IF (scf_control%do_outer_scf_reortho)
THEN
1672 IF (scf_control%outer_scf%have_scf .AND. .NOT. dft_control%restricted)
THEN
1673 IF (scf_env%outer_scf%iter_count > 0)
THEN
1674 DO ispin = 1, dft_control%nspins
1675 CALL get_mo_set(mo_set=mos(ispin), mo_coeff=mo_coeff, nmo=nmo)
1676 IF (has_unit_metric)
THEN
1688 IF (.NOT.
ASSOCIATED(scf_env%qs_ot_env))
THEN
1690 CALL allocate_qs_ot_envs(scf_env=scf_env, &
1691 scf_control=scf_control, &
1692 dft_control=dft_control, &
1693 scf_section=scf_section, &
1694 do_kpoints=do_kpoints, &
1696 nspin_ot=nspin_ot, &
1697 kp_range=kp_range, &
1700 IF (scf_env%qs_ot_env(1)%settings%preconditioner_type == &
1702 IF (.NOT. do_kpoints)
THEN
1703 DO ispin = 1,
SIZE(mos)
1704 IF (.NOT. mos(ispin)%uniform_occupation)
THEN
1705 CALL cp_abort(__location__, &
1706 'PRECONDITIONER FULL_ALL_COVARIANT currently requires uniform occupations.')
1714 calculate_forces=.false.)
1718 IF (.NOT. reuse_precond)
THEN
1720 scf_env%qs_ot_env(1)%settings%preconditioner_type, &
1728 IF (has_unit_metric)
THEN
1729 NULLIFY (orthogonality_metric)
1731 orthogonality_metric => matrix_s(1)%matrix
1734 IF (.NOT. reuse_precond)
THEN
1736 scf_env%qs_ot_env(1)%settings%preconditioner_type, &
1737 scf_env%qs_ot_env(1)%settings%precond_solver_type, &
1738 scf_env%qs_ot_env(1)%settings%energy_gap, dft_control%nspins, &
1739 has_unit_metric=has_unit_metric, &
1740 chol_type=scf_env%qs_ot_env(1)%settings%cholesky_type, &
1741 chebyshev_degree=scf_env%qs_ot_env(1)%settings%chebyshev_degree, &
1742 low_rank_base=scf_env%qs_ot_env(1)%settings%low_rank_base, &
1743 fermi_low_rank_max_rank= &
1744 scf_env%qs_ot_env(1)%settings%fermi_low_rank_max_rank, &
1745 lattice_fft=scf_env%qs_ot_env(1)%settings%lattice_fft, &
1746 lattice_fft_local_cells= &
1747 scf_env%qs_ot_env(1)%settings%lattice_fft_local_cells)
1749 IF (reuse_precond) reuse_precond = .false.
1751 CALL ot_scf_init(mo_array=mos, matrix_s=orthogonality_metric, &
1752 broyden_adaptive_sigma=qs_env%broyden_adaptive_sigma, &
1753 qs_ot_env=scf_env%qs_ot_env, matrix_ks=matrix_ks(1)%matrix)
1755 SELECT CASE (scf_env%qs_ot_env(1)%settings%preconditioner_type)
1759 DO ispin = 1,
SIZE(scf_env%qs_ot_env)
1761 scf_env%ot_preconditioner(ispin)%preconditioner)
1764 DO ispin = 1,
SIZE(scf_env%qs_ot_env)
1766 scf_env%ot_preconditioner(1)%preconditioner)
1769 DO ispin = 1,
SIZE(scf_env%qs_ot_env)
1771 scf_env%ot_preconditioner(1)%preconditioner)
1777 do_rotation = scf_env%qs_ot_env(1)%settings%do_rotation
1778 DO ispin = 1,
SIZE(mos)
1779 IF (.NOT. mos(ispin)%uniform_occupation)
THEN
1780 cpassert(do_rotation)
1786 IF (dft_control%low_spin_roks)
THEN
1788 do_rotation = scf_env%qs_ot_env(1)%settings%do_rotation
1789 cpassert(do_rotation)
1792 CALL timestop(handle)
1808 SUBROUTINE allocate_qs_ot_envs(scf_env, scf_control, dft_control, scf_section, &
1809 do_kpoints, nkpoint, nspin_ot, kp_range, wkp)
1814 LOGICAL,
INTENT(IN) :: do_kpoints
1815 INTEGER,
INTENT(IN) :: nkpoint, nspin_ot
1816 INTEGER,
DIMENSION(2),
INTENT(IN) :: kp_range
1817 REAL(kind=
dp),
DIMENSION(:),
POINTER :: wkp
1819 CHARACTER(len=*),
PARAMETER :: kpoint_precond_error = &
1820 "Complex K-point OT supports PRECONDITIONER NONE, FERMI_LOW_RANK, "// &
1821 "FULL_S_INVERSE, FULL_KINETIC, FULL_SINGLE, FULL_SINGLE_INVERSE, FULL_ALL, or "// &
1822 "FULL_ALL_COVARIANT.", kpoint_solver_error = &
1823 "Complex K-point FERMI_LOW_RANK, FULL_SINGLE, FULL_ALL, and FULL_ALL_COVARIANT "// &
1824 "support PRECOND_SOLVER DEFAULT; FULL_S_INVERSE, FULL_KINETIC, and "// &
1825 "FULL_SINGLE_INVERSE support DEFAULT or INVERSE_CHOLESKY."
1827 INTEGER :: ikpoint, ispin, local_kpoint, &
1828 number_of_ot_envs, ot_channel
1829 LOGICAL :: do_rotation, do_smear, is_full_all
1830 REAL(kind=
dp) :: kpoint_weight
1832 cpassert(.NOT.
ASSOCIATED(scf_env%qs_ot_env))
1837 restricted=dft_control%restricted)
1839 ALLOCATE (scf_env%qs_ot_env(number_of_ot_envs))
1842 IF (scf_env%outer_scf%iter_count > 0)
THEN
1843 IF (scf_env%iter_delta < scf_control%eps_diis)
THEN
1844 scf_env%qs_ot_env(1)%settings%ot_state = 1
1850 IF (dft_control%restricted .AND. .NOT. do_kpoints .AND. &
1851 scf_env%qs_ot_env(1)%settings%preconditioner_type == &
1853 cpabort(
'Gamma-point PRECONDITIONER FULL_ALL_COVARIANT does not currently support ROKS.')
1856 IF (do_kpoints)
THEN
1857 do_smear = dft_control%smear .OR. scf_control%smear%do_smear
1859 IF (.NOT. scf_env%qs_ot_env(1)%settings%do_ener)
THEN
1860 cpabort(
"K-point OT smearing requires OT%ENERGIES and OT%ROTATION.")
1862 IF (.NOT. scf_env%qs_ot_env(1)%settings%do_rotation)
THEN
1863 cpabort(
"K-point OT smearing requires OT%ROTATION.")
1865 SELECT CASE (scf_control%smear%method)
1869 cpabort(
"K-point Mermin OT does not support the selected smearing method.")
1871 IF (scf_env%qs_ot_env(1)%settings%ot_algorithm /=
"TOD" .AND. &
1872 scf_env%qs_ot_env(1)%settings%ot_algorithm /=
"REF")
THEN
1873 cpabort(
"K-point Mermin OT currently supports OT%ALGORITHM STRICT or IRAC.")
1875 IF (scf_env%qs_ot_env(1)%settings%OT_METHOD /=
"CG" .AND. &
1876 scf_env%qs_ot_env(1)%settings%OT_METHOD /=
"SD" .AND. &
1877 scf_env%qs_ot_env(1)%settings%OT_METHOD /=
"DIIS" .AND. &
1878 scf_env%qs_ot_env(1)%settings%OT_METHOD /=
"BROY" .AND. &
1879 scf_env%qs_ot_env(1)%settings%OT_METHOD /=
"LBFG")
THEN
1880 cpabort(
"K-point Mermin OT supports OT%MINIMIZER CG, SD, DIIS, BROYDEN, or LBFGS.")
1882 ELSE IF (scf_env%qs_ot_env(1)%settings%do_ener)
THEN
1883 cpabort(
"OT%ENERGIES requires smearing in the complex K-point path.")
1885 IF (scf_env%qs_ot_env(1)%settings%ot_algorithm /=
"TOD" .AND. &
1886 scf_env%qs_ot_env(1)%settings%ot_algorithm /=
"REF")
THEN
1887 cpabort(
"K-point OT currently supports OT%ALGORITHM STRICT or IRAC.")
1889 IF (scf_env%qs_ot_env(1)%settings%OT_METHOD /=
"CG" .AND. &
1890 scf_env%qs_ot_env(1)%settings%OT_METHOD /=
"SD" .AND. &
1891 scf_env%qs_ot_env(1)%settings%OT_METHOD /=
"DIIS" .AND. &
1892 scf_env%qs_ot_env(1)%settings%OT_METHOD /=
"BROY" .AND. &
1893 scf_env%qs_ot_env(1)%settings%OT_METHOD /=
"LBFG")
THEN
1894 cpabort(
"K-point OT currently supports OT%MINIMIZER CG, SD, DIIS, BROYDEN, or LBFGS.")
1897 scf_env%qs_ot_env(1)%settings%preconditioner_type, .false.))
THEN
1898 cpabort(kpoint_precond_error)
1901 (dft_control%qs_control%semi_empirical .OR. dft_control%qs_control%dftb .OR. &
1902 dft_control%qs_control%xtb))
THEN
1903 cpabort(
"FULL_KINETIC is unavailable for semi-empirical methods")
1906 scf_env%qs_ot_env(1)%settings%preconditioner_type, &
1907 scf_env%qs_ot_env(1)%settings%precond_solver_type, .false.))
THEN
1908 cpabort(kpoint_solver_error)
1910 IF (scf_env%qs_ot_env(1)%settings%occupation_preconditioner .AND. .NOT. do_smear)
THEN
1911 cpabort(
"K-point OCCUPATION_PRECONDITIONER requires smearing.")
1915 IF (scf_env%outer_scf%iter_count > 0)
THEN
1916 IF (scf_env%qs_ot_env(1)%settings%ot_state == 1)
THEN
1917 scf_control%max_scf = max(scf_env%qs_ot_env(1)%settings%max_scf_diis, &
1918 scf_control%max_scf)
1923 IF (dft_control%restricted)
THEN
1924 scf_env%qs_ot_env(:)%restricted = .true.
1926 IF (.NOT. scf_env%qs_ot_env(1)%settings%do_rotation)
THEN
1927 CALL cp_abort(__location__, &
1928 "Restricted calculation with OT requires orbital rotation. Please "// &
1929 "activate the OT%ROTATION keyword!")
1932 scf_env%qs_ot_env(:)%restricted = .false.
1937 do_rotation = scf_env%qs_ot_env(1)%settings%do_rotation
1940 IF (do_rotation .AND. is_full_all .AND. .NOT. do_kpoints)
THEN
1941 cpabort(
'PRECONDITIONER FULL_ALL is not compatible with ROTATION.')
1944 DO ikpoint = 1, nkpoint
1946 IF (do_kpoints)
THEN
1947 IF (ikpoint >= kp_range(1) .AND. ikpoint <= kp_range(2))
THEN
1948 local_kpoint = ikpoint - kp_range(1) + 1
1951 DO ispin = 1, nspin_ot
1953 IF (do_kpoints)
THEN
1954 kpoint_weight = 1.0_dp
1955 IF (
ASSOCIATED(wkp)) kpoint_weight = wkp(ikpoint)
1958 kpoint_index=ikpoint, &
1959 local_kpoint_index=local_kpoint, &
1960 kpoint_weight=kpoint_weight)
1969 restricted=dft_control%restricted, &
1970 require_kpoint=do_kpoints, &
1971 kp_range=kp_range, &
1974 END SUBROUTINE allocate_qs_ot_envs
1987 SUBROUTINE allocate_qs_ot_kpoint_state(qs_env, scf_env, dft_control, &
1988 kpoints, matrix_ks_kp, matrix_s_kp, matrix_t_kp, nspin_ot)
1993 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_ks_kp, matrix_s_kp, matrix_t_kp
1994 INTEGER,
INTENT(IN) :: nspin_ot
1996 CHARACTER(LEN=*),
PARAMETER :: routinen =
'allocate_qs_ot_kpoint_state'
1998 INTEGER :: energy_dimension, energy_spin, energy_start, first_channel, handle, ikpoint, &
1999 ikpoint_local, ispin, local_channel, nao, nmo, nocc, ot_channel
2000 LOGICAL :: local_init, use_real_wfn
2001 REAL(kind=
dp),
DIMENSION(:),
POINTER :: eigenvalues
2005 TYPE(
cp_fm_type) :: active_mo_coeff, active_mo_coeff_im, &
2006 mo_coeff, mo_coeff_im
2007 TYPE(
dbcsr_type),
POINTER :: matrix_sk_im, matrix_sk_re
2011 CALL timeset(routinen, handle)
2013 NULLIFY (active_mo_struct, eigenvalues, kp, matrix_sk_im, matrix_sk_re, mo_set)
2015 cpassert(
ASSOCIATED(qs_env))
2016 cpassert(
ASSOCIATED(scf_env%qs_ot_env))
2017 cpassert(
ASSOCIATED(kpoints))
2018 cpassert(
ASSOCIATED(kpoints%kp_env))
2019 cpassert(
ASSOCIATED(matrix_ks_kp))
2020 cpassert(
ASSOCIATED(matrix_s_kp))
2021 cpassert(
ASSOCIATED(matrix_s_kp(1, 1)%matrix))
2022 cpassert(.NOT. dft_control%restricted .OR. nspin_ot == 1)
2025 cpassert(.NOT. use_real_wfn)
2027 local_init = kpoints%para_env_kp%num_pe == 1
2029 IF (local_init)
ALLOCATE (local_s(2,
SIZE(kpoints%kp_env)*nspin_ot), local_c(
SIZE(kpoints%kp_env)*nspin_ot))
2031 DO ikpoint_local = 1,
SIZE(kpoints%kp_env)
2032 kp => kpoints%kp_env(ikpoint_local)%kpoint_env
2033 cpassert(
ASSOCIATED(kp))
2034 cpassert(
ASSOCIATED(kp%mos))
2035 cpassert(
ASSOCIATED(kp%ot_smat))
2036 cpassert(nspin_ot <=
SIZE(kp%mos))
2037 ikpoint = kp%nkpoint
2038 cpassert(ikpoint >= 1)
2039 cpassert(
SIZE(kp%ot_smat) >= 2)
2041 kp%ot_smat(1), kp%ot_smat(2), &
2042 matrix_sk_re, matrix_sk_im)
2043 DO ispin = 1, nspin_ot
2045 cpassert(.NOT. scf_env%qs_ot_env(ot_channel)%state_allocated)
2047 mo_set => kp%mos(ispin)
2048 CALL get_mo_set(mo_set=mo_set, eigenvalues=eigenvalues, &
2049 homo=nocc, nao=nao, nmo=nmo)
2050 cpassert(
ASSOCIATED(mo_set%cmo_coeff))
2051 cpassert(
ASSOCIATED(eigenvalues))
2054 IF (scf_env%qs_ot_env(ot_channel)%settings%do_ener) nocc = nmo
2055 IF (nocc < 1 .OR. nocc > nmo)
THEN
2056 CALL cp_abort(__location__, &
2057 "K-point OT requires at least one occupied orbital in every spin channel.")
2060 CALL cp_fm_struct_create(active_mo_struct, template_fmstruct=mo_set%cmo_coeff%matrix_struct, &
2062 energy_dimension = nocc
2063 IF (dft_control%restricted .AND. &
2064 scf_env%qs_ot_env(ot_channel)%settings%do_ener)
THEN
2065 energy_dimension = nocc*
SIZE(kp%mos)
2069 active_mo_struct, energy_dimension=energy_dimension)
2072 IF (local_init)
THEN
2073 local_channel = ot_channel - first_channel + 1
2074 local_s(1, local_channel)%matrix => kp%ot_smat(1)
2075 local_s(2, local_channel)%matrix => kp%ot_smat(2)
2076 local_c(local_channel)%matrix => mo_set%cmo_coeff
2078 CALL cp_fm_create(mo_coeff, mo_set%cmo_coeff%matrix_struct)
2079 CALL cp_fm_create(mo_coeff_im, mo_set%cmo_coeff%matrix_struct)
2080 CALL cp_cfm_to_fm(mo_set%cmo_coeff, mo_coeff, mo_coeff_im)
2083 CALL dbcsr_set(scf_env%qs_ot_env(ot_channel)%matrix_c0, 0.0_dp)
2084 CALL copy_fm_to_dbcsr(active_mo_coeff, scf_env%qs_ot_env(ot_channel)%matrix_c0)
2086 CALL cp_fm_create(active_mo_coeff_im, active_mo_struct)
2087 CALL cp_fm_to_fm(mo_coeff_im, active_mo_coeff_im, nocc)
2088 CALL dbcsr_set(scf_env%qs_ot_env(ot_channel)%matrix_c0_im, 0.0_dp)
2089 CALL dbcsr_set(scf_env%qs_ot_env(ot_channel)%matrix_sc0_im, 0.0_dp)
2090 CALL copy_fm_to_dbcsr(active_mo_coeff_im, scf_env%qs_ot_env(ot_channel)%matrix_c0_im)
2092 scf_env%qs_ot_env(ot_channel)%matrix_c0, &
2093 scf_env%qs_ot_env(ot_channel)%matrix_c0_im, &
2094 scf_env%qs_ot_env(ot_channel)%matrix_sc0, &
2095 scf_env%qs_ot_env(ot_channel)%matrix_sc0_im, &
2096 scf_env%qs_ot_env(ot_channel)%matrix_x)
2104 CALL qs_ot_init(scf_env%qs_ot_env(ot_channel))
2105 IF (scf_env%qs_ot_env(ot_channel)%settings%do_ener)
THEN
2106 IF (dft_control%restricted)
THEN
2107 DO energy_spin = 1,
SIZE(kp%mos)
2108 CALL get_mo_set(kp%mos(energy_spin), eigenvalues=eigenvalues)
2109 energy_start = (energy_spin - 1)*nocc + 1
2110 scf_env%qs_ot_env(ot_channel)%ener_x(energy_start:energy_start + nocc - 1) = &
2114 scf_env%qs_ot_env(ot_channel)%ener_x(:) = eigenvalues(1:nocc)
2117 scf_env%qs_ot_env(ot_channel)%broyden_adaptive_sigma = qs_env%broyden_adaptive_sigma
2119 SELECT CASE (scf_env%qs_ot_env(ot_channel)%settings%ot_algorithm)
2121 CALL dbcsr_set(scf_env%qs_ot_env(ot_channel)%matrix_x, 0.0_dp)
2122 CALL dbcsr_set(scf_env%qs_ot_env(ot_channel)%matrix_sx, 0.0_dp)
2123 CALL dbcsr_set(scf_env%qs_ot_env(ot_channel)%matrix_x_im, 0.0_dp)
2124 CALL dbcsr_set(scf_env%qs_ot_env(ot_channel)%matrix_sx_im, 0.0_dp)
2126 scf_env%qs_ot_env(ot_channel)%matrix_x_im, &
2127 scf_env%qs_ot_env(ot_channel)%matrix_sx, &
2128 scf_env%qs_ot_env(ot_channel)%matrix_sx_im, &
2129 scf_env%qs_ot_env(ot_channel), zero_coordinates=.true.)
2131 IF (.NOT. local_init)
THEN
2132 CALL dbcsr_copy(scf_env%qs_ot_env(ot_channel)%matrix_x, &
2133 scf_env%qs_ot_env(ot_channel)%matrix_c0)
2134 CALL dbcsr_copy(scf_env%qs_ot_env(ot_channel)%matrix_x_im, &
2135 scf_env%qs_ot_env(ot_channel)%matrix_c0_im)
2137 scf_env%qs_ot_env(ot_channel)%matrix_c0_im, &
2138 matrix_sk_re, matrix_sk_im, &
2139 scf_env%qs_ot_env(ot_channel))
2142 cpabort(
"Algorithm not yet implemented")
2145 cpassert(scf_env%qs_ot_env(ot_channel)%state_allocated)
2146 cpassert(scf_env%qs_ot_env(ot_channel)%has_complex_kpoint_state)
2153 IF (local_init)
THEN
2155 scf_env%qs_ot_env(first_channel:first_channel +
SIZE(local_c) - 1), &
2156 local_s, local_c, initialize=.true.)
2160 nkpoint=kpoints%nkp, &
2161 restricted=any(scf_env%qs_ot_env(:)%restricted), &
2162 require_kpoint=.true., &
2163 kp_range=kpoints%kp_range, &
2164 require_local_state=.true., &
2165 require_complex_state=.true.)
2167 CALL prepare_qs_ot_kpoint_preconditioners(scf_env, kpoints, matrix_ks_kp, &
2168 matrix_s_kp, matrix_t_kp, nspin_ot)
2170 CALL timestop(handle)
2172 END SUBROUTINE allocate_qs_ot_kpoint_state
2183 SUBROUTINE prepare_qs_ot_kpoint_preconditioners(scf_env, kpoints, matrix_ks, matrix_s, matrix_t, nspin_ot)
2186 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_ks, matrix_s, matrix_t
2187 INTEGER,
INTENT(IN) :: nspin_ot
2189 CHARACTER(LEN=*),
PARAMETER :: routinen =
'prepare_qs_ot_kpoint_preconditioners'
2191 INTEGER :: first_channel, handle, ikpoint, ispin, ks_spin, local_channel, local_kpoint, &
2192 n_ot_channels, nlocal, nocc, occupation_spin, ot_channel, prec_type, source_channel
2194 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: occupation_signature
2195 REAL(kind=
dp),
DIMENSION(:),
POINTER :: occupation_numbers
2196 TYPE(
cp_fm_p_type),
ALLOCATABLE :: local_h(:, :), local_s(:, :)
2198 TYPE(
dbcsr_type),
POINTER :: matrix_h_im, matrix_h_re, matrix_s_im, &
2199 matrix_s_re, matrix_t_im, matrix_t_re
2202 CALL timeset(routinen, handle)
2204 NULLIFY (kp, matrix_h_im, matrix_h_re, matrix_s_im, matrix_s_re, matrix_t_im, matrix_t_re, &
2206 cpassert(
ASSOCIATED(scf_env%qs_ot_env))
2207 cpassert(
ASSOCIATED(kpoints))
2208 cpassert(
ASSOCIATED(matrix_ks))
2209 cpassert(
ASSOCIATED(matrix_s))
2211 prec_type = scf_env%qs_ot_env(1)%settings%preconditioner_type
2213 CALL timestop(handle)
2216 SELECT CASE (prec_type)
2221 cpabort(
"Unsupported complex K-point OT preconditioner")
2223 n_ot_channels =
SIZE(scf_env%qs_ot_env)
2224 IF (
ASSOCIATED(scf_env%ot_preconditioner))
THEN
2225 DO ot_channel = 1,
SIZE(scf_env%ot_preconditioner)
2226 IF (
ASSOCIATED(scf_env%ot_preconditioner(ot_channel)%preconditioner))
THEN
2228 DEALLOCATE (scf_env%ot_preconditioner(ot_channel)%preconditioner)
2231 DEALLOCATE (scf_env%ot_preconditioner)
2232 NULLIFY (scf_env%ot_preconditioner)
2234 ALLOCATE (scf_env%ot_preconditioner(n_ot_channels))
2235 DO local_kpoint = 1,
SIZE(kpoints%kp_env)
2236 kp => kpoints%kp_env(local_kpoint)%kpoint_env
2237 ikpoint = kp%nkpoint
2238 DO ispin = 1, nspin_ot
2240 cpassert(scf_env%qs_ot_env(ot_channel)%state_allocated)
2241 ALLOCATE (scf_env%ot_preconditioner(ot_channel)%preconditioner)
2243 para_env=scf_env%qs_ot_env(ot_channel)%para_env, &
2244 blacs_env=scf_env%qs_ot_env(ot_channel)%blacs_env)
2250 nlocal =
SIZE(kpoints%kp_env)*nspin_ot
2251 ALLOCATE (local_c(2, nlocal), local_h(2, nlocal), local_s(2, nlocal))
2252 DO local_kpoint = 1,
SIZE(kpoints%kp_env)
2253 kp => kpoints%kp_env(local_kpoint)%kpoint_env
2254 DO ispin = 1, nspin_ot
2256 local_channel = ot_channel - first_channel + 1
2257 ks_spin = min(ispin,
SIZE(kp%ot_hmat, 2))
2258 local_c(1, local_channel)%matrix => scf_env%qs_ot_env(ot_channel)%matrix_c0
2259 local_c(2, local_channel)%matrix => scf_env%qs_ot_env(ot_channel)%matrix_c0_im
2260 local_h(1, local_channel)%matrix => kp%ot_hmat(1, ks_spin)
2261 local_h(2, local_channel)%matrix => kp%ot_hmat(2, ks_spin)
2262 local_s(1, local_channel)%matrix => kp%ot_smat(1)
2263 local_s(2, local_channel)%matrix => kp%ot_smat(2)
2267 scf_env%ot_preconditioner(first_channel:first_channel + nlocal - 1), local_c, local_h, local_s, &
2268 scf_env%qs_ot_env(1)%settings%energy_gap, scf_env%qs_ot_env(1)%settings%precond_solver_type, handled)
2270 DO ot_channel = first_channel, first_channel + nlocal - 1
2272 scf_env%ot_preconditioner(ot_channel)%preconditioner)
2274 CALL timestop(handle)
2279 DO local_kpoint = 1,
SIZE(kpoints%kp_env)
2280 kp => kpoints%kp_env(local_kpoint)%kpoint_env
2281 cpassert(
ASSOCIATED(kp))
2282 cpassert(
ASSOCIATED(kp%ot_hmat))
2283 cpassert(
ASSOCIATED(kp%ot_smat))
2284 cpassert(
SIZE(kp%ot_smat) >= 2)
2285 ikpoint = kp%nkpoint
2287 kp%ot_smat(1), kp%ot_smat(2), &
2288 matrix_s_re, matrix_s_im)
2290 cpassert(
ASSOCIATED(matrix_t))
2291 cpassert(
ASSOCIATED(kp%ot_tmat))
2292 cpassert(
SIZE(kp%ot_tmat) >= 2)
2294 kp%ot_tmat(1), kp%ot_tmat(2), &
2295 matrix_t_re, matrix_t_im)
2297 DO ispin = 1, nspin_ot
2299 IF (ispin > 1 .AND. &
2302 IF (.NOT. (
ASSOCIATED(scf_env%ot_preconditioner(source_channel)%preconditioner%complex_fm)))
THEN
2303 CALL cp_abort(__location__,
"Missing shared complex OT preconditioner")
2305 scf_env%ot_preconditioner(ot_channel)%preconditioner%complex_fm => &
2306 scf_env%ot_preconditioner(source_channel)%preconditioner%complex_fm
2307 scf_env%ot_preconditioner(ot_channel)%preconditioner%owns_complex_fm = .false.
2308 scf_env%ot_preconditioner(ot_channel)%preconditioner%energy_gap = &
2309 scf_env%ot_preconditioner(source_channel)%preconditioner%energy_gap
2310 scf_env%ot_preconditioner(ot_channel)%preconditioner%in_use = &
2311 scf_env%ot_preconditioner(source_channel)%preconditioner%in_use
2312 scf_env%ot_preconditioner(ot_channel)%preconditioner%solver = &
2313 scf_env%ot_preconditioner(source_channel)%preconditioner%solver
2315 scf_env%ot_preconditioner(ot_channel)%preconditioner)
2323 ks_spin = min(ispin,
SIZE(kp%ot_hmat, 2))
2324 cpassert(
SIZE(kp%ot_hmat, 1) >= 2)
2325 IF (
ALLOCATED(kpoints%lowdin_v))
THEN
2333 CALL cp_fm_to_cfm(kp%ot_hmat(1, ks_spin), kp%ot_hmat(2, ks_spin), h)
2348 kp%ot_hmat(1, ks_spin), kp%ot_hmat(2, ks_spin), &
2349 matrix_h_re, matrix_h_im)
2352 SELECT CASE (prec_type)
2355 scf_env%ot_preconditioner(ot_channel)%preconditioner, &
2356 scf_env%qs_ot_env(ot_channel)%matrix_c0, &
2357 scf_env%qs_ot_env(ot_channel)%matrix_c0_im, &
2358 matrix_h_re, matrix_h_im, matrix_s_re, matrix_s_im, &
2359 scf_env%qs_ot_env(ot_channel)%settings%energy_gap, &
2360 scf_env%qs_ot_env(ot_channel)%settings%fermi_low_rank_max_rank, &
2361 scf_env%qs_ot_env(ot_channel)%settings%precond_solver_type)
2364 scf_env%ot_preconditioner(ot_channel)%preconditioner, &
2365 scf_env%qs_ot_env(ot_channel)%matrix_c0, &
2366 scf_env%qs_ot_env(ot_channel)%matrix_c0_im, &
2367 matrix_h_re, matrix_h_im, matrix_s_re, matrix_s_im, &
2368 scf_env%qs_ot_env(ot_channel)%settings%energy_gap, &
2369 scf_env%qs_ot_env(ot_channel)%settings%precond_solver_type)
2372 scf_env%ot_preconditioner(ot_channel)%preconditioner, &
2373 matrix_h_re, matrix_h_im, matrix_s_re, matrix_s_im, &
2375 scf_env%qs_ot_env(ot_channel)%settings%energy_gap, &
2376 scf_env%qs_ot_env(ot_channel)%settings%precond_solver_type)
2378 IF (nspin_ot == 1 .AND.
SIZE(kp%mos) > 1)
THEN
2380 nfullcols_total=nocc)
2381 ALLOCATE (occupation_signature(nocc,
SIZE(kp%mos)))
2382 DO occupation_spin = 1,
SIZE(kp%mos)
2384 occupation_numbers=occupation_numbers)
2385 cpassert(
ASSOCIATED(occupation_numbers))
2386 cpassert(
SIZE(occupation_numbers) >= nocc)
2387 occupation_signature(:, occupation_spin) = occupation_numbers(1:nocc)
2390 scf_env%ot_preconditioner(ot_channel)%preconditioner, &
2391 scf_env%qs_ot_env(ot_channel)%matrix_c0, &
2392 scf_env%qs_ot_env(ot_channel)%matrix_c0_im, &
2393 matrix_h_re, matrix_h_im, matrix_s_re, matrix_s_im, &
2394 scf_env%qs_ot_env(ot_channel)%settings%energy_gap, &
2395 scf_env%qs_ot_env(ot_channel)%settings%precond_solver_type, &
2396 occupation_signature)
2397 DEALLOCATE (occupation_signature)
2400 scf_env%ot_preconditioner(ot_channel)%preconditioner, &
2401 scf_env%qs_ot_env(ot_channel)%matrix_c0, &
2402 scf_env%qs_ot_env(ot_channel)%matrix_c0_im, &
2403 matrix_h_re, matrix_h_im, matrix_s_re, matrix_s_im, &
2404 scf_env%qs_ot_env(ot_channel)%settings%energy_gap, &
2405 scf_env%qs_ot_env(ot_channel)%settings%precond_solver_type)
2409 scf_env%ot_preconditioner(ot_channel)%preconditioner, &
2410 scf_env%qs_ot_env(ot_channel)%matrix_c0, &
2411 scf_env%qs_ot_env(ot_channel)%matrix_c0_im, &
2412 matrix_h_re, matrix_h_im, matrix_s_re, matrix_s_im, &
2413 scf_env%qs_ot_env(ot_channel)%settings%energy_gap, &
2414 scf_env%qs_ot_env(ot_channel)%settings%precond_solver_type)
2417 scf_env%ot_preconditioner(ot_channel)%preconditioner, &
2418 matrix_t_re, matrix_t_im, matrix_s_re, matrix_s_im, &
2419 scf_env%qs_ot_env(ot_channel)%settings%energy_gap, &
2420 scf_env%qs_ot_env(ot_channel)%settings%precond_solver_type)
2423 scf_env%ot_preconditioner(ot_channel)%preconditioner, &
2424 matrix_s_re, matrix_s_im, &
2425 scf_env%qs_ot_env(ot_channel)%settings%precond_solver_type)
2428 scf_env%ot_preconditioner(ot_channel)%preconditioner)
2438 CALL timestop(handle)
2440 END SUBROUTINE prepare_qs_ot_kpoint_preconditioners
2451 TYPE(qs_scf_env_type),
INTENT(INOUT) :: scf_env
2453 CHARACTER(len=*),
PARAMETER :: routinen =
'scf_env_cleanup'
2457 CALL timeset(routinen, handle)
2460 IF (
ALLOCATED(scf_env%fm_copy_plan))
DEALLOCATE (scf_env%fm_copy_plan)
2461 CALL cp_fm_release(scf_env%scf_work1)
2463 IF (
ASSOCIATED(scf_env%scf_work1_red))
THEN
2464 CALL cp_fm_release(scf_env%scf_work1_red)
2466 IF (
ASSOCIATED(scf_env%scf_work2))
THEN
2467 CALL cp_fm_release(scf_env%scf_work2)
2468 DEALLOCATE (scf_env%scf_work2)
2469 NULLIFY (scf_env%scf_work2)
2471 IF (
ASSOCIATED(scf_env%scf_work2_red))
THEN
2472 CALL cp_fm_release(scf_env%scf_work2_red)
2473 DEALLOCATE (scf_env%scf_work2_red)
2474 NULLIFY (scf_env%scf_work2_red)
2476 IF (
ASSOCIATED(scf_env%ortho))
THEN
2477 CALL cp_fm_release(scf_env%ortho)
2478 DEALLOCATE (scf_env%ortho)
2479 NULLIFY (scf_env%ortho)
2481 IF (
ASSOCIATED(scf_env%ortho_red))
THEN
2482 CALL cp_fm_release(scf_env%ortho_red)
2483 DEALLOCATE (scf_env%ortho_red)
2484 NULLIFY (scf_env%ortho_red)
2486 IF (
ASSOCIATED(scf_env%ortho_m1))
THEN
2487 CALL cp_fm_release(scf_env%ortho_m1)
2488 DEALLOCATE (scf_env%ortho_m1)
2489 NULLIFY (scf_env%ortho_m1)
2491 IF (
ASSOCIATED(scf_env%ortho_m1_red))
THEN
2492 CALL cp_fm_release(scf_env%ortho_m1_red)
2493 DEALLOCATE (scf_env%ortho_m1_red)
2494 NULLIFY (scf_env%ortho_m1_red)
2497 IF (
ASSOCIATED(scf_env%ortho_dbcsr))
THEN
2498 CALL dbcsr_deallocate_matrix(scf_env%ortho_dbcsr)
2500 IF (
ASSOCIATED(scf_env%buf1_dbcsr))
THEN
2501 CALL dbcsr_deallocate_matrix(scf_env%buf1_dbcsr)
2503 IF (
ASSOCIATED(scf_env%buf2_dbcsr))
THEN
2504 CALL dbcsr_deallocate_matrix(scf_env%buf2_dbcsr)
2507 IF (
ASSOCIATED(scf_env%p_mix_new))
THEN
2508 CALL dbcsr_deallocate_matrix_set(scf_env%p_mix_new)
2511 IF (
ASSOCIATED(scf_env%p_delta))
THEN
2512 CALL dbcsr_deallocate_matrix_set(scf_env%p_delta)
2516 SELECT CASE (scf_env%method)
2519 CASE (ot_diag_method_nr)
2521 CASE (general_diag_method_nr)
2523 CASE (special_diag_method_nr)
2525 CASE (block_krylov_diag_method_nr)
2526 CASE (block_davidson_diag_method_nr)
2527 CALL block_davidson_deallocate(scf_env%block_davidson_env)
2528 CASE (filter_matrix_diag_method_nr)
2530 CASE (smeagol_method_nr)
2533 cpabort(
"unknown scf method method:"//cp_to_string(scf_env%method))
2536 IF (
ASSOCIATED(scf_env%outer_scf%variables))
THEN
2537 DEALLOCATE (scf_env%outer_scf%variables)
2539 IF (
ASSOCIATED(scf_env%outer_scf%count))
THEN
2540 DEALLOCATE (scf_env%outer_scf%count)
2542 IF (
ASSOCIATED(scf_env%outer_scf%gradient))
THEN
2543 DEALLOCATE (scf_env%outer_scf%gradient)
2545 IF (
ASSOCIATED(scf_env%outer_scf%energy))
THEN
2546 DEALLOCATE (scf_env%outer_scf%energy)
2548 IF (
ASSOCIATED(scf_env%outer_scf%inv_jacobian) .AND. &
2549 scf_env%outer_scf%deallocate_jacobian)
THEN
2550 DEALLOCATE (scf_env%outer_scf%inv_jacobian)
2553 CALL timestop(handle)
2567 SUBROUTINE cdft_scf(qs_env, should_stop, has_converged, total_scf_steps)
2568 TYPE(qs_environment_type),
POINTER :: qs_env
2569 LOGICAL,
INTENT(OUT) :: should_stop, has_converged
2570 INTEGER,
INTENT(OUT) :: total_scf_steps
2572 CHARACTER(len=*),
PARAMETER :: routinen =
'cdft_scf'
2574 INTEGER :: handle, iatom, iimage, ispin, ivar, nmo, &
2575 nvar, output_unit, tsteps
2576 LOGICAL :: cdft_loop_converged, converged, &
2577 exit_cdft_loop, first_iteration, &
2578 my_uocc, uniform_occupation
2579 REAL(kind=dp),
ALLOCATABLE,
DIMENSION(:) :: gapw_cdft_values
2580 REAL(kind=dp),
DIMENSION(:),
POINTER :: mo_occupations
2581 TYPE(atomic_kind_type),
DIMENSION(:),
POINTER :: atomic_kind_set
2582 TYPE(cdft_control_type),
POINTER :: cdft_control
2583 TYPE(cp_logger_type),
POINTER :: logger
2584 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: gapw_wmat, matrix_s, rho_ao
2585 TYPE(dft_control_type),
POINTER :: dft_control
2586 TYPE(local_rho_type),
POINTER :: gapw_operator_rho
2587 TYPE(mo_set_type),
DIMENSION(:),
POINTER :: mos
2588 TYPE(mp_para_env_type),
POINTER :: para_env
2589 TYPE(pw_env_type),
POINTER :: pw_env
2590 TYPE(pw_pool_type),
POINTER :: auxbas_pw_pool
2591 TYPE(qs_energy_type),
POINTER :: energy
2592 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
2593 TYPE(qs_ks_env_type),
POINTER :: ks_env
2594 TYPE(qs_rho_type),
POINTER :: rho
2595 TYPE(qs_scf_env_type),
POINTER :: scf_env
2596 TYPE(scf_control_type),
POINTER :: scf_control
2597 TYPE(section_vals_type),
POINTER :: dft_section, input, scf_section
2599 NULLIFY (atomic_kind_set, gapw_operator_rho, gapw_wmat, para_env, qs_kind_set, &
2600 scf_env, ks_env, energy, rho, matrix_s, rho_ao, cdft_control, logger, &
2601 dft_control, pw_env, auxbas_pw_pool, energy, ks_env, scf_env, dft_section, &
2602 input, scf_section, scf_control, mos, mo_occupations)
2603 logger => cp_get_default_logger()
2605 cpassert(
ASSOCIATED(qs_env))
2606 CALL get_qs_env(qs_env, scf_env=scf_env, energy=energy, &
2607 dft_control=dft_control, scf_control=scf_control, &
2608 ks_env=ks_env, input=input)
2610 CALL timeset(routinen//
"_loop", handle)
2611 dft_section => section_vals_get_subs_vals(input,
"DFT")
2612 scf_section => section_vals_get_subs_vals(dft_section,
"SCF")
2613 output_unit = cp_print_key_unit_nr(logger, scf_section,
"PRINT%PROGRAM_RUN_INFO", &
2614 extension=
".scfLog")
2615 first_iteration = .true.
2617 cdft_control => dft_control%qs_control%cdft_control
2619 scf_env%outer_scf%iter_count = 0
2620 cdft_control%total_steps = 0
2624 IF (output_unit > 0)
THEN
2625 WRITE (unit=output_unit, fmt=
"(/,/,T2,A)") &
2626 "CDFT EXTERNAL SCF WAVEFUNCTION OPTIMIZATION"
2627 CALL qs_scf_cdft_initial_info(output_unit, cdft_control)
2629 IF (cdft_control%reuse_precond)
THEN
2630 reuse_precond = .false.
2631 cdft_control%nreused = 0
2635 CALL outer_loop_switch(scf_env, scf_control, cdft_control, cdft2ot)
2637 CALL scf_env_do_scf(scf_env=scf_env, scf_control=scf_control, qs_env=qs_env, &
2638 converged=converged, should_stop=should_stop, total_scf_steps=tsteps)
2639 total_scf_steps = total_scf_steps + tsteps
2641 IF (cdft_control%reuse_precond)
THEN
2645 IF (scf_env%outer_scf%iter_count == 1 .AND. scf_env%iter_count == 1 &
2646 .AND. cdft_control%total_steps /= 1)
THEN
2647 cdft_control%nreused = cdft_control%nreused - 1
2650 IF (scf_env%outer_scf%iter_count == 1 .AND. scf_env%iter_count <= cdft_control%precond_freq .AND. &
2651 cdft_control%total_steps /= 1 .AND. cdft_control%nreused < cdft_control%max_reuse)
THEN
2652 reuse_precond = .true.
2653 cdft_control%nreused = cdft_control%nreused + 1
2655 reuse_precond = .false.
2656 cdft_control%nreused = 0
2660 IF (first_iteration .AND. cdft_control%purge_history)
THEN
2661 cdft_control%istep = cdft_control%istep + 1
2662 IF (scf_env%outer_scf%iter_count > 1)
THEN
2663 cdft_control%nbad_conv = cdft_control%nbad_conv + 1
2664 IF (cdft_control%nbad_conv >= cdft_control%purge_freq .AND. &
2665 cdft_control%istep >= cdft_control%purge_offset)
THEN
2666 cdft_control%nbad_conv = 0
2667 cdft_control%istep = 0
2668 cdft_control%should_purge = .true.
2672 first_iteration = .false.
2674 CALL outer_loop_switch(scf_env, scf_control, cdft_control, ot2cdft)
2675 CALL qs_scf_check_outer_exit(qs_env, scf_env, scf_control, should_stop, &
2676 cdft_loop_converged, exit_cdft_loop)
2677 CALL qs_scf_cdft_info(output_unit, scf_control, scf_env, cdft_control, &
2678 energy, cdft_control%total_steps, &
2679 should_stop, cdft_loop_converged, cdft_loop=.true.)
2680 IF (exit_cdft_loop)
EXIT cdft_outer_loop
2682 CALL qs_calculate_inverse_jacobian(qs_env)
2684 CALL qs_cdft_line_search(qs_env)
2686 CALL outer_loop_optimize(scf_env, scf_control)
2687 CALL outer_loop_update_qs_env(qs_env, scf_env)
2688 CALL qs_ks_did_change(ks_env, potential_changed=.true.)
2689 END DO cdft_outer_loop
2691 has_converged = converged .AND. cdft_loop_converged
2692 cdft_control%ienergy = cdft_control%ienergy + 1
2695 IF (cdft_control%do_et)
THEN
2696 CALL get_qs_env(qs_env=qs_env, matrix_s=matrix_s, mos=mos)
2697 nvar =
SIZE(cdft_control%target)
2698 IF (dft_control%qs_control%gapw)
THEN
2699 IF (dft_control%nimages /= 1)
THEN
2700 CALL cp_abort(__location__, &
2701 "GAPW CDFT-CI currently requires a Gamma-point calculation.")
2703 CALL get_qs_env(qs_env, atomic_kind_set=atomic_kind_set, para_env=para_env, &
2704 qs_kind_set=qs_kind_set, rho=rho)
2705 CALL qs_rho_get(rho, rho_ao=rho_ao)
2706 CALL local_rho_set_create(gapw_operator_rho)
2707 CALL allocate_rho_atom_internals(gapw_operator_rho%rho_atom_set, atomic_kind_set, &
2708 qs_kind_set, dft_control, para_env)
2709 ALLOCATE (gapw_cdft_values(nvar), gapw_wmat(dft_control%nspins*dft_control%nimages))
2710 DO iimage = 1, dft_control%nimages
2711 DO ispin = 1, dft_control%nspins
2712 CALL dbcsr_init_p(gapw_wmat(dft_control%nspins*(iimage - 1) + ispin)%matrix)
2713 CALL dbcsr_copy(gapw_wmat(dft_control%nspins*(iimage - 1) + ispin)%matrix, &
2714 matrix_s(iimage)%matrix, name=
"GAPW CDFT WEIGHT MATRIX")
2719 ALLOCATE (cdft_control%wmat(nvar))
2721 CALL dbcsr_init_p(cdft_control%wmat(ivar)%matrix)
2722 CALL dbcsr_copy(cdft_control%wmat(ivar)%matrix, matrix_s(1)%matrix, &
2723 name=
"ET_RESTRAINT_MATRIX")
2724 CALL dbcsr_set(cdft_control%wmat(ivar)%matrix, 0.0_dp)
2725 CALL integrate_v_rspace(cdft_control%group(ivar)%weight, &
2726 hmat=cdft_control%wmat(ivar), qs_env=qs_env, &
2727 calculate_forces=.false., &
2728 gapw=dft_control%qs_control%gapw)
2729 IF (dft_control%qs_control%gapw)
THEN
2730 DO ispin = 1,
SIZE(gapw_wmat)
2731 CALL dbcsr_set(gapw_wmat(ispin)%matrix, 0.0_dp)
2733 CALL zero_rho_atom_integrals(gapw_operator_rho%rho_atom_set)
2734 CALL gapw_cdft_one_center(qs_env, energy_only=.false., calculate_forces=.false., &
2735 values=gapw_cdft_values, operator_group=ivar, &
2736 rho_atom_operator_set=gapw_operator_rho%rho_atom_set)
2737 CALL update_ks_atom(qs_env, gapw_wmat, rho_ao, forces=.false., &
2738 rho_atom_external=gapw_operator_rho%rho_atom_set)
2739 CALL dbcsr_add(cdft_control%wmat(ivar)%matrix, gapw_wmat(1)%matrix, 1.0_dp, 1.0_dp)
2742 IF (dft_control%qs_control%gapw)
THEN
2743 CALL dbcsr_deallocate_matrix_set(gapw_wmat)
2744 CALL local_rho_set_release(gapw_operator_rho)
2745 DEALLOCATE (gapw_cdft_values)
2748 CALL dbcsr_init_p(cdft_control%matrix_s%matrix)
2749 CALL dbcsr_copy(cdft_control%matrix_s%matrix, matrix_s(1)%matrix, &
2752 NULLIFY (cdft_control%mo_coeff)
2753 ALLOCATE (cdft_control%mo_coeff(dft_control%nspins))
2754 DO ispin = 1, dft_control%nspins
2755 CALL cp_fm_create(matrix=cdft_control%mo_coeff(ispin), &
2756 matrix_struct=qs_env%mos(ispin)%mo_coeff%matrix_struct, &
2757 name=
"MO_COEFF_A"//trim(adjustl(cp_to_string(ispin)))//
"MATRIX")
2758 CALL cp_fm_to_fm(qs_env%mos(ispin)%mo_coeff, &
2759 cdft_control%mo_coeff(ispin))
2762 IF (cdft_control%calculate_metric)
THEN
2763 CALL get_qs_env(qs_env, rho=rho)
2764 CALL qs_rho_get(rho, rho_ao=rho_ao)
2765 ALLOCATE (cdft_control%matrix_p(dft_control%nspins))
2766 DO ispin = 1, dft_control%nspins
2767 NULLIFY (cdft_control%matrix_p(ispin)%matrix)
2768 CALL dbcsr_init_p(cdft_control%matrix_p(ispin)%matrix)
2769 CALL dbcsr_copy(cdft_control%matrix_p(ispin)%matrix, rho_ao(ispin)%matrix, &
2770 name=
"DENSITY MATRIX")
2774 uniform_occupation = .true.
2775 DO ispin = 1, dft_control%nspins
2776 CALL get_mo_set(mo_set=mos(ispin), uniform_occupation=my_uocc)
2777 uniform_occupation = uniform_occupation .AND. my_uocc
2779 IF (.NOT. uniform_occupation)
THEN
2780 ALLOCATE (cdft_control%occupations(dft_control%nspins))
2781 DO ispin = 1, dft_control%nspins
2782 CALL get_mo_set(mo_set=mos(ispin), &
2784 occupation_numbers=mo_occupations)
2785 ALLOCATE (cdft_control%occupations(ispin)%array(nmo))
2786 cdft_control%occupations(ispin)%array(1:nmo) = mo_occupations(1:nmo)
2794 IF (.NOT. (cdft_control%save_pot .OR. cdft_control%transfer_pot))
THEN
2795 CALL get_qs_env(qs_env, pw_env=pw_env)
2796 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
2797 DO iatom = 1,
SIZE(cdft_control%group)
2798 CALL auxbas_pw_pool%give_back_pw(cdft_control%group(iatom)%weight)
2799 DEALLOCATE (cdft_control%group(iatom)%weight)
2801 IF (cdft_control%atomic_charges)
THEN
2802 DO iatom = 1, cdft_control%natoms
2803 CALL auxbas_pw_pool%give_back_pw(cdft_control%charge(iatom))
2805 DEALLOCATE (cdft_control%charge)
2807 IF (cdft_control%type == outer_scf_becke_constraint .AND. &
2808 cdft_control%becke_control%cavity_confine)
THEN
2809 IF (.NOT.
ASSOCIATED(cdft_control%becke_control%cavity_mat))
THEN
2810 CALL auxbas_pw_pool%give_back_pw(cdft_control%becke_control%cavity)
2812 DEALLOCATE (cdft_control%becke_control%cavity_mat)
2814 ELSE IF (cdft_control%type == outer_scf_hirshfeld_constraint)
THEN
2815 IF (
ASSOCIATED(cdft_control%hirshfeld_control%hirshfeld_env%fnorm))
THEN
2816 CALL auxbas_pw_pool%give_back_pw(cdft_control%hirshfeld_control%hirshfeld_env%fnorm)
2819 IF (
ASSOCIATED(cdft_control%charges_fragment))
DEALLOCATE (cdft_control%charges_fragment)
2820 cdft_control%need_pot = .true.
2821 cdft_control%external_control = .false.
2824 CALL timestop(handle)
2835 SUBROUTINE cdft_control_cleanup(cdft_control)
2836 TYPE(cdft_control_type),
POINTER :: cdft_control
2838 IF (
ASSOCIATED(cdft_control%constraint%variables))
THEN
2839 DEALLOCATE (cdft_control%constraint%variables)
2841 IF (
ASSOCIATED(cdft_control%constraint%count))
THEN
2842 DEALLOCATE (cdft_control%constraint%count)
2844 IF (
ASSOCIATED(cdft_control%constraint%gradient))
THEN
2845 DEALLOCATE (cdft_control%constraint%gradient)
2847 IF (
ASSOCIATED(cdft_control%constraint%energy))
THEN
2848 DEALLOCATE (cdft_control%constraint%energy)
2850 IF (
ASSOCIATED(cdft_control%constraint%inv_jacobian) .AND. &
2851 cdft_control%constraint%deallocate_jacobian)
THEN
2852 DEALLOCATE (cdft_control%constraint%inv_jacobian)
2855 END SUBROUTINE cdft_control_cleanup
2863 SUBROUTINE qs_calculate_inverse_jacobian(qs_env)
2864 TYPE(qs_environment_type),
POINTER :: qs_env
2866 CHARACTER(LEN=*),
PARAMETER :: routinen =
'qs_calculate_inverse_jacobian'
2868 CHARACTER(len=default_path_length) :: project_name
2869 INTEGER :: counter, handle, i, ispin, iter_count, &
2870 iwork, j, max_scf, nspins, nsteps, &
2871 nvar, nwork, output_unit, pwork, &
2873 LOGICAL :: converged, explicit_jacobian, &
2874 should_build, should_stop, &
2876 REAL(kind=dp) :: inv_error, step_size
2877 REAL(kind=dp),
ALLOCATABLE,
DIMENSION(:) :: coeff, dh, step_multiplier
2878 REAL(kind=dp),
ALLOCATABLE,
DIMENSION(:, :) :: jacobian
2879 REAL(kind=dp),
DIMENSION(:),
POINTER :: energy
2880 REAL(kind=dp),
DIMENSION(:, :),
POINTER :: gradient, inv_jacobian
2881 TYPE(cdft_control_type),
POINTER :: cdft_control
2882 TYPE(cp_logger_type),
POINTER :: logger, tmp_logger
2883 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: p_rmpv
2884 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: rho_ao_kp
2885 TYPE(dft_control_type),
POINTER :: dft_control
2886 TYPE(mo_set_type),
ALLOCATABLE,
DIMENSION(:) :: mos_stashed
2887 TYPE(mo_set_type),
DIMENSION(:),
POINTER :: mos
2888 TYPE(mp_para_env_type),
POINTER :: para_env
2889 TYPE(qs_energy_type),
POINTER :: energy_qs
2890 TYPE(qs_ks_env_type),
POINTER :: ks_env
2891 TYPE(qs_rho_type),
POINTER :: rho
2892 TYPE(qs_scf_env_type),
POINTER :: scf_env
2893 TYPE(scf_control_type),
POINTER :: scf_control
2895 NULLIFY (energy, gradient, p_rmpv, rho_ao_kp, mos, rho, &
2896 ks_env, scf_env, scf_control, dft_control, cdft_control, &
2897 inv_jacobian, para_env, tmp_logger, energy_qs)
2898 logger => cp_get_default_logger()
2900 cpassert(
ASSOCIATED(qs_env))
2901 CALL get_qs_env(qs_env, scf_env=scf_env, ks_env=ks_env, &
2902 scf_control=scf_control, mos=mos, rho=rho, &
2903 dft_control=dft_control, &
2904 para_env=para_env, energy=energy_qs)
2905 explicit_jacobian = .false.
2906 should_build = .false.
2907 use_md_history = .false.
2908 iter_count = scf_env%outer_scf%iter_count
2910 IF (.NOT.
ASSOCIATED(scf_control%outer_scf%cdft_opt_control))
RETURN
2912 CALL timeset(routinen, handle)
2913 CALL initialize_inverse_jacobian(scf_control, scf_env, explicit_jacobian, should_build, used_history)
2914 IF (scf_control%outer_scf%cdft_opt_control%jacobian_restart)
THEN
2916 should_build = .false.
2917 CALL restart_inverse_jacobian(qs_env)
2919 IF (should_build)
THEN
2920 scf_env%outer_scf%deallocate_jacobian = .false.
2922 IF (explicit_jacobian)
THEN
2924 cdft_control => dft_control%qs_control%cdft_control
2925 IF (.NOT.
ASSOCIATED(cdft_control))
THEN
2926 CALL cp_abort(__location__, &
2927 "Optimizers that need the explicit Jacobian can"// &
2928 " only be used together with a valid CDFT constraint.")
2931 project_name = logger%iter_info%project_name
2932 CALL create_tmp_logger(para_env, project_name,
"-JacobianInfo.out", output_unit, tmp_logger)
2934 nspins = dft_control%nspins
2935 ALLOCATE (mos_stashed(nspins))
2936 DO ispin = 1, nspins
2937 CALL duplicate_mo_set(mos_stashed(ispin), mos(ispin))
2939 CALL qs_rho_get(rho, rho_ao_kp=rho_ao_kp)
2940 p_rmpv => rho_ao_kp(:, 1)
2942 nvar =
SIZE(scf_env%outer_scf%variables, 1)
2943 max_scf = scf_control%outer_scf%max_scf + 1
2944 ALLOCATE (gradient(nvar, max_scf))
2945 gradient = scf_env%outer_scf%gradient
2946 ALLOCATE (energy(max_scf))
2947 energy = scf_env%outer_scf%energy
2948 ALLOCATE (jacobian(nvar, nvar))
2950 nsteps = cdft_control%total_steps
2952 CALL prepare_jacobian_stencil(qs_env, output_unit, nwork, pwork, coeff, step_multiplier, dh)
2953 twork = pwork - nwork
2955 jacobian(i, :) = coeff(0)*scf_env%outer_scf%gradient(i, iter_count)
2958 CALL cp_add_default_logger(tmp_logger)
2960 IF (output_unit > 0)
THEN
2961 WRITE (output_unit, fmt=
"(A)")
" "
2962 WRITE (output_unit, fmt=
"(A)")
" #####################################"
2963 WRITE (output_unit,
'(A,I3,A,I3,A)') &
2964 " ### Constraint ", i,
" of ", nvar,
" ###"
2965 WRITE (output_unit, fmt=
"(A)")
" #####################################"
2968 DO iwork = nwork, pwork
2969 IF (iwork == 0) cycle
2970 counter = counter + 1
2971 IF (output_unit > 0)
THEN
2972 WRITE (output_unit, fmt=
"(A)")
" #####################################"
2973 WRITE (output_unit,
'(A,I3,A,I3,A)') &
2974 " ### Energy evaluation ", counter,
" of ", twork,
" ###"
2975 WRITE (output_unit, fmt=
"(A)")
" #####################################"
2977 IF (
SIZE(scf_control%outer_scf%cdft_opt_control%jacobian_step) == 1)
THEN
2978 step_size = scf_control%outer_scf%cdft_opt_control%jacobian_step(1)
2980 step_size = scf_control%outer_scf%cdft_opt_control%jacobian_step(i)
2982 scf_env%outer_scf%variables(:, iter_count + 1) = scf_env%outer_scf%variables(:, iter_count)
2983 scf_env%outer_scf%variables(i, iter_count + 1) = scf_env%outer_scf%variables(i, iter_count) + &
2984 step_multiplier(iwork)*step_size
2985 CALL outer_loop_update_qs_env(qs_env, scf_env)
2986 CALL qs_ks_did_change(ks_env, potential_changed=.true.)
2987 CALL outer_loop_switch(scf_env, scf_control, cdft_control, cdft2ot)
2988 CALL scf_env_do_scf(scf_env=scf_env, scf_control=scf_control, qs_env=qs_env, &
2989 converged=converged, should_stop=should_stop, total_scf_steps=tsteps)
2990 CALL outer_loop_switch(scf_env, scf_control, cdft_control, ot2cdft)
2992 scf_env%outer_scf%iter_count = scf_env%outer_scf%iter_count + 1
2993 CALL outer_loop_gradient(qs_env, scf_env)
2994 CALL qs_scf_cdft_info(output_unit, scf_control, scf_env, cdft_control, &
2995 energy_qs, cdft_control%total_steps, &
2996 should_stop=.false., outer_loop_converged=.false., cdft_loop=.false.)
2997 scf_env%outer_scf%iter_count = scf_env%outer_scf%iter_count - 1
3000 jacobian(j, i) = jacobian(j, i) + coeff(iwork)*scf_env%outer_scf%gradient(j, iter_count + 1)
3003 scf_env%outer_scf%variables(:, iter_count + 1) = 0.0_dp
3004 scf_env%outer_scf%gradient = gradient
3005 scf_env%outer_scf%energy = energy
3006 cdft_control%total_steps = nsteps
3007 DO ispin = 1, nspins
3008 CALL deallocate_mo_set(mos(ispin))
3009 CALL duplicate_mo_set(mos(ispin), mos_stashed(ispin))
3010 CALL calculate_density_matrix(mos(ispin), &
3011 p_rmpv(ispin)%matrix)
3013 CALL qs_rho_update_rho(rho, qs_env=qs_env)
3014 CALL qs_ks_did_change(qs_env%ks_env, rho_changed=.true.)
3017 CALL cp_rm_default_logger()
3018 CALL cp_logger_release(tmp_logger)
3022 jacobian(i, j) = jacobian(i, j)/dh(j)
3025 IF (.NOT.
ASSOCIATED(scf_env%outer_scf%inv_jacobian))
THEN
3026 ALLOCATE (scf_env%outer_scf%inv_jacobian(nvar, nvar))
3028 inv_jacobian => scf_env%outer_scf%inv_jacobian
3029 CALL invert_matrix(jacobian, inv_jacobian, inv_error)
3030 scf_control%outer_scf%cdft_opt_control%broyden_update = .false.
3032 DO ispin = 1, nspins
3033 CALL deallocate_mo_set(mos_stashed(ispin))
3035 DEALLOCATE (mos_stashed, jacobian, gradient, energy, coeff, step_multiplier, dh)
3036 IF (output_unit > 0)
THEN
3037 WRITE (output_unit, fmt=
"(/,A)") &
3038 " ================================== JACOBIAN CALCULATED =================================="
3039 CALL close_file(unit_number=output_unit)
3043 CALL build_diagonal_jacobian(qs_env, used_history)
3046 IF (
ASSOCIATED(scf_env%outer_scf%inv_jacobian) .AND. para_env%is_source())
THEN
3048 CALL print_inverse_jacobian(logger, scf_env%outer_scf%inv_jacobian, iter_count)
3051 scf_control%outer_scf%cdft_opt_control%ijacobian(1) = scf_control%outer_scf%cdft_opt_control%ijacobian(1) + 1
3052 CALL timestop(handle)
3054 END SUBROUTINE qs_calculate_inverse_jacobian
3064 SUBROUTINE qs_cdft_line_search(qs_env)
3065 TYPE(qs_environment_type),
POINTER :: qs_env
3067 CHARACTER(LEN=*),
PARAMETER :: routinen =
'qs_cdft_line_search'
3069 CHARACTER(len=default_path_length) :: project_name
3070 INTEGER :: handle, i, ispin, iter_count, &
3071 max_linesearch, max_scf, nspins, &
3072 nsteps, nvar, output_unit, tsteps
3073 LOGICAL :: continue_ls, continue_ls_exit, converged, do_linesearch, found_solution, &
3074 reached_maxls, should_exit, should_stop, sign_changed
3075 LOGICAL,
ALLOCATABLE,
DIMENSION(:) :: positive_sign
3076 REAL(kind=dp) :: alpha, alpha_ls, factor, norm_ls
3077 REAL(kind=dp),
DIMENSION(:),
POINTER :: energy
3078 REAL(kind=dp),
DIMENSION(:, :),
POINTER :: gradient, inv_jacobian
3079 REAL(kind=dp),
EXTERNAL :: dnrm2
3080 TYPE(cdft_control_type),
POINTER :: cdft_control
3081 TYPE(cp_logger_type),
POINTER :: logger, tmp_logger
3082 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: p_rmpv
3083 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: rho_ao_kp
3084 TYPE(dft_control_type),
POINTER :: dft_control
3085 TYPE(mo_set_type),
DIMENSION(:),
POINTER :: mos
3086 TYPE(mp_para_env_type),
POINTER :: para_env
3087 TYPE(qs_energy_type),
POINTER :: energy_qs
3088 TYPE(qs_ks_env_type),
POINTER :: ks_env
3089 TYPE(qs_rho_type),
POINTER :: rho
3090 TYPE(qs_scf_env_type),
POINTER :: scf_env
3091 TYPE(scf_control_type),
POINTER :: scf_control
3093 CALL timeset(routinen, handle)
3095 NULLIFY (energy, gradient, p_rmpv, rho_ao_kp, mos, rho, &
3096 ks_env, scf_env, scf_control, dft_control, &
3097 cdft_control, inv_jacobian, para_env, &
3098 tmp_logger, energy_qs)
3099 logger => cp_get_default_logger()
3101 cpassert(
ASSOCIATED(qs_env))
3102 CALL get_qs_env(qs_env, scf_env=scf_env, ks_env=ks_env, &
3103 scf_control=scf_control, mos=mos, rho=rho, &
3104 dft_control=dft_control, &
3105 para_env=para_env, energy=energy_qs)
3106 do_linesearch = .false.
3107 SELECT CASE (scf_control%outer_scf%optimizer)
3109 do_linesearch = .false.
3110 CASE (outer_scf_optimizer_newton_ls)
3111 do_linesearch = .true.
3112 CASE (outer_scf_optimizer_broyden)
3113 SELECT CASE (scf_control%outer_scf%cdft_opt_control%broyden_type)
3114 CASE (broyden_type_1, broyden_type_2, broyden_type_1_explicit, broyden_type_2_explicit)
3115 do_linesearch = .false.
3116 CASE (broyden_type_1_ls, broyden_type_1_explicit_ls, broyden_type_2_ls, broyden_type_2_explicit_ls)
3117 cdft_control => dft_control%qs_control%cdft_control
3118 IF (.NOT.
ASSOCIATED(cdft_control))
THEN
3119 CALL cp_abort(__location__, &
3120 "Optimizers that perform a line search can"// &
3121 " only be used together with a valid CDFT constraint")
3123 IF (
ASSOCIATED(scf_env%outer_scf%inv_jacobian))
THEN
3124 do_linesearch = .true.
3128 IF (do_linesearch)
THEN
3130 TYPE(mo_set_type),
DIMENSION(:),
ALLOCATABLE :: mos_ls, mos_stashed
3131 cdft_control => dft_control%qs_control%cdft_control
3132 IF (.NOT.
ASSOCIATED(cdft_control))
THEN
3133 CALL cp_abort(__location__, &
3134 "Optimizers that perform a line search can"// &
3135 " only be used together with a valid CDFT constraint")
3137 cpassert(
ASSOCIATED(scf_env%outer_scf%inv_jacobian))
3138 cpassert(
ASSOCIATED(scf_control%outer_scf%cdft_opt_control))
3139 alpha = scf_control%outer_scf%cdft_opt_control%newton_step_save
3140 iter_count = scf_env%outer_scf%iter_count
3142 project_name = logger%iter_info%project_name
3143 CALL create_tmp_logger(para_env, project_name,
"-LineSearch.out", output_unit, tmp_logger)
3145 nspins = dft_control%nspins
3146 ALLOCATE (mos_stashed(nspins))
3147 DO ispin = 1, nspins
3148 CALL duplicate_mo_set(mos_stashed(ispin), mos(ispin))
3150 CALL qs_rho_get(rho, rho_ao_kp=rho_ao_kp)
3151 p_rmpv => rho_ao_kp(:, 1)
3152 nsteps = cdft_control%total_steps
3154 nvar =
SIZE(scf_env%outer_scf%variables, 1)
3155 max_scf = scf_control%outer_scf%max_scf + 1
3156 max_linesearch = scf_control%outer_scf%cdft_opt_control%max_ls
3157 continue_ls = scf_control%outer_scf%cdft_opt_control%continue_ls
3158 factor = scf_control%outer_scf%cdft_opt_control%factor_ls
3159 continue_ls_exit = .false.
3160 found_solution = .false.
3161 ALLOCATE (gradient(nvar, max_scf))
3162 gradient = scf_env%outer_scf%gradient
3163 ALLOCATE (energy(max_scf))
3164 energy = scf_env%outer_scf%energy
3165 reached_maxls = .false.
3167 IF (scf_control%outer_scf%cdft_opt_control%broyden_update)
THEN
3168 CALL outer_loop_optimize(scf_env, scf_control)
3170 scf_env%outer_scf%variables(:, iter_count + 1) = 0
3171 scf_control%outer_scf%cdft_opt_control%broyden_update = .false.
3174 IF (output_unit > 0)
THEN
3175 WRITE (output_unit, fmt=
"(/,A)") &
3176 " ================================== LINE SEARCH STARTED =================================="
3177 WRITE (output_unit, fmt=
"(A,I5,A)") &
3178 " Evaluating optimal step size for optimizer using a maximum of", max_linesearch,
" steps"
3179 IF (continue_ls)
THEN
3180 WRITE (output_unit, fmt=
"(A)") &
3181 " Line search continues until best step size is found or max steps are reached"
3183 WRITE (output_unit,
'(/,A,F5.3)') &
3184 " Initial step size: ", alpha
3185 WRITE (output_unit,
'(/,A,F5.3)') &
3186 " Step size update factor: ", factor
3187 WRITE (output_unit,
'(/,A,I10,A,I10)') &
3188 " Energy evaluation: ", cdft_control%ienergy,
", CDFT SCF iteration: ", iter_count
3191 CALL cp_add_default_logger(tmp_logger)
3192 DO i = 1, max_linesearch
3193 IF (output_unit > 0)
THEN
3194 WRITE (output_unit, fmt=
"(A)")
" "
3195 WRITE (output_unit, fmt=
"(A)")
" #####################################"
3196 WRITE (output_unit,
'(A,I10,A)') &
3197 " ### Line search step: ", i,
" ###"
3198 WRITE (output_unit, fmt=
"(A)")
" #####################################"
3200 inv_jacobian => scf_env%outer_scf%inv_jacobian
3202 scf_env%outer_scf%variables(:, iter_count + 1) = scf_env%outer_scf%variables(:, iter_count) - alpha* &
3203 matmul(inv_jacobian, scf_env%outer_scf%gradient(:, iter_count))
3205 CALL outer_loop_update_qs_env(qs_env, scf_env)
3206 CALL qs_ks_did_change(ks_env, potential_changed=.true.)
3207 CALL outer_loop_switch(scf_env, scf_control, cdft_control, cdft2ot)
3208 CALL scf_env_do_scf(scf_env=scf_env, scf_control=scf_control, qs_env=qs_env, &
3209 converged=converged, should_stop=should_stop, total_scf_steps=tsteps)
3210 CALL outer_loop_switch(scf_env, scf_control, cdft_control, ot2cdft)
3212 scf_env%outer_scf%iter_count = scf_env%outer_scf%iter_count + 1
3213 CALL outer_loop_gradient(qs_env, scf_env)
3214 CALL qs_scf_cdft_info(output_unit, scf_control, scf_env, cdft_control, &
3215 energy_qs, cdft_control%total_steps, &
3216 should_stop=.false., outer_loop_converged=.false., cdft_loop=.false.)
3217 scf_env%outer_scf%iter_count = scf_env%outer_scf%iter_count - 1
3219 IF (continue_ls .AND. .NOT.
ALLOCATED(positive_sign))
THEN
3220 ALLOCATE (positive_sign(nvar))
3222 positive_sign(ispin) = scf_env%outer_scf%gradient(ispin, iter_count + 1) >= 0.0_dp
3226 inv_jacobian => scf_env%outer_scf%inv_jacobian
3227 IF (dnrm2(nvar, scf_env%outer_scf%gradient(:, iter_count + 1), 1) < &
3228 dnrm2(nvar, scf_env%outer_scf%gradient(:, iter_count), 1))
THEN
3230 IF (.NOT. continue_ls)
THEN
3231 should_exit = .true.
3235 IF (found_solution)
THEN
3237 IF (dnrm2(nvar, scf_env%outer_scf%gradient(:, iter_count + 1), 1) > norm_ls)
THEN
3239 continue_ls_exit = .true.
3243 IF (.NOT. continue_ls_exit)
THEN
3244 should_exit = .false.
3246 found_solution = .true.
3247 norm_ls = dnrm2(nvar, scf_env%outer_scf%gradient(:, iter_count + 1), 1)
3250 sign_changed = .true.
3252 sign_changed = sign_changed .AND. (positive_sign(ispin) .NEQV. &
3253 scf_env%outer_scf%gradient(ispin, iter_count + 1) >= 0.0_dp)
3255 IF (.NOT.
ALLOCATED(mos_ls))
THEN
3256 ALLOCATE (mos_ls(nspins))
3258 DO ispin = 1, nspins
3259 CALL deallocate_mo_set(mos_ls(ispin))
3262 DO ispin = 1, nspins
3263 CALL duplicate_mo_set(mos_ls(ispin), mos(ispin))
3265 alpha = alpha*factor
3267 IF (i == max_linesearch) continue_ls_exit = .true.
3269 IF (sqrt(maxval(scf_env%outer_scf%gradient(:, scf_env%outer_scf%iter_count + 1)**2)) < &
3270 scf_control%outer_scf%eps_scf)
THEN
3271 continue_ls_exit = .true.
3274 IF (sign_changed) continue_ls_exit = .true.
3279 should_exit = .false.
3281 alpha = alpha*factor
3283 IF (continue_ls_exit)
THEN
3286 DO ispin = 1, nspins
3287 CALL deallocate_mo_set(mos(ispin))
3288 CALL duplicate_mo_set(mos(ispin), mos_ls(ispin))
3289 CALL calculate_density_matrix(mos(ispin), &
3290 p_rmpv(ispin)%matrix)
3291 CALL deallocate_mo_set(mos_ls(ispin))
3293 CALL qs_rho_update_rho(rho, qs_env=qs_env)
3294 CALL qs_ks_did_change(qs_env%ks_env, rho_changed=.true.)
3296 should_exit = .true.
3299 IF (.NOT. should_exit .AND. &
3300 (i == max_linesearch .AND. converged .AND. .NOT. found_solution))
THEN
3301 should_exit = .true.
3302 reached_maxls = .true.
3303 alpha = alpha*(1.0_dp/factor)
3306 scf_env%outer_scf%variables(:, iter_count + 1) = 0.0_dp
3307 scf_env%outer_scf%gradient = gradient
3308 scf_env%outer_scf%energy = energy
3310 IF (should_exit)
EXIT
3312 cdft_control%total_steps = nsteps
3313 DO ispin = 1, nspins
3314 CALL deallocate_mo_set(mos(ispin))
3315 CALL duplicate_mo_set(mos(ispin), mos_stashed(ispin))
3316 CALL calculate_density_matrix(mos(ispin), &
3317 p_rmpv(ispin)%matrix)
3319 CALL qs_rho_update_rho(rho, qs_env=qs_env)
3320 CALL qs_ks_did_change(qs_env%ks_env, rho_changed=.true.)
3322 scf_control%outer_scf%cdft_opt_control%newton_step = alpha
3323 IF (.NOT. should_exit)
THEN
3324 CALL cp_warn(__location__, &
3325 "Line search did not converge. CDFT SCF proceeds with fixed step size.")
3326 scf_control%outer_scf%cdft_opt_control%newton_step = scf_control%outer_scf%cdft_opt_control%newton_step_save
3328 IF (reached_maxls)
THEN
3329 CALL cp_warn(__location__, &
3330 "Line search did not converge. CDFT SCF proceeds with lasted iterated step size.")
3332 CALL cp_rm_default_logger()
3333 CALL cp_logger_release(tmp_logger)
3335 DO ispin = 1, nspins
3336 CALL deallocate_mo_set(mos_stashed(ispin))
3338 DEALLOCATE (mos_stashed, gradient, energy)
3339 IF (
ALLOCATED(positive_sign))
DEALLOCATE (positive_sign)
3340 IF (output_unit > 0)
THEN
3341 WRITE (output_unit, fmt=
"(/,A)") &
3342 " ================================== LINE SEARCH COMPLETE =================================="
3343 CALL close_file(unit_number=output_unit)
3348 CALL timestop(handle)
3350 END SUBROUTINE qs_cdft_line_search
3360 SUBROUTINE rebuild_xtb_total_energy(energy, dft_control)
3361 TYPE(qs_energy_type),
POINTER :: energy
3362 TYPE(dft_control_type),
POINTER :: dft_control
3364 IF (.NOT. dft_control%qs_control%xtb)
RETURN
3365 IF (dft_control%qs_control%xtb_control%do_tblite)
RETURN
3367 SELECT CASE (dft_control%qs_control%xtb_control%gfn_type)
3369 energy%total = energy%core + energy%eeq + energy%efield + energy%qmmm_el + &
3370 energy%repulsive + energy%dispersion + energy%kTS
3372 energy%total = energy%core + energy%repulsive + energy%hartree + &
3373 energy%xtb_spinpol + energy%efield + energy%qmmm_el + &
3374 energy%dispersion + energy%dftb3 + energy%kTS
3377 END SUBROUTINE rebuild_xtb_total_energy
Define the atomic kind types and their sub types.
Molecular and Gamma-point periodic CC4S export from restricted RI-HF. RI_FLAVOR MO stores a weighted ...
subroutine, public write_cc4s(qs_env, converged)
Check the requested export, canonicalize private Fock/overlap copies and write tensors.
methods related to the blacs parallel environment
Represents a complex full matrix distributed on many processors.
subroutine, public cp_cfm_release(matrix)
Releases a full matrix.
subroutine, public cp_fm_to_cfm(msourcer, msourcei, mtarget)
Construct a complex full matrix by taking its real and imaginary parts from two separate real-value f...
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_to_fm(msource, mtargetr, mtargeti)
Copy real and imaginary parts of a complex full matrix into separate real-value full matrices.
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
subroutine, public dbcsr_release_p(matrix)
...
subroutine, public dbcsr_deallocate_matrix(matrix)
...
subroutine, public dbcsr_copy(matrix_b, matrix_a, name, keep_sparsity, keep_imaginary)
...
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_init_p(matrix)
...
subroutine, public dbcsr_set(matrix, alpha)
...
subroutine, public dbcsr_add(matrix_a, matrix_b, alpha_scalar, beta_scalar)
...
DBCSR operations in CP2K.
subroutine, public copy_dbcsr_to_fm(matrix, fm, plan, check_plan)
Copy a DBCSR matrix to a BLACS matrix.
subroutine, public copy_fm_to_dbcsr_bc(fm, bc_mat)
Copy a BLACS matrix to a dbcsr matrix with a special block-cyclic distribution, which requires no com...
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.
Utility routines to open and close files.
subroutine, public close_file(unit_number, file_status)
Closes an open file given by its logical unit number.
pool for for elements that are retained and released
represent the structure of a full matrix
subroutine, public cp_fm_struct_create(fmstruct, para_env, context, nrow_global, ncol_global, nrow_block, ncol_block, descriptor, first_p_pos, local_leading_dimension, template_fmstruct, square_blocks, force_block)
allocates and initializes a full matrix structure
subroutine, public cp_fm_struct_release(fmstruct)
releases a full matrix structure
represent a full matrix distributed on many processors
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_init_random(matrix, ncol, start_col)
fills a matrix with random numbers
various routines to log and control the output. The idea is that decisions about where to log should ...
subroutine, public cp_rm_default_logger()
the cousin of cp_add_default_logger, decrements the stack, so that the default logger is what it has ...
subroutine, public cp_logger_release(logger)
releases this logger
subroutine, public cp_add_default_logger(logger)
adds a default logger. MUST be called before logging occours
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...
subroutine, public cp_add_iter_level(logger, level_name, n_rlevel_new)
Adds an iteration level.
integer, parameter, public cp_p_file
subroutine, public cp_iterate(iteration_info, last, iter_nr, increment, iter_nr_out)
adds one to the actual iteration
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 cp_rm_iter_level(logger, level_name, n_rlevel_att)
Removes an iteration level.
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)
...
set of type/routines to handle the storage of results in force_envs
logical function, public test_for_result(results, description)
test for a certain result in the result_list
set of type/routines to handle the storage of results in force_envs
Add the DFT+U contribution to the Hamiltonian matrix.
subroutine, public lowdin_kp_apply(kp, v, rmat, cmat)
Add B diag(v) B**H before any solver, DIIS residual, or history storage uses H(k).
Types needed for a for a Energy Correction.
Defines the basic variable types.
integer, parameter, public dp
integer, parameter, public default_string_length
integer, parameter, public default_path_length
Restart file for k point calculations.
subroutine, public write_kpoints_restart(denmat, kpoints, scf_env, dft_section, particle_set, qs_kind_set)
...
Routines needed for kpoint calculation.
subroutine, public kpoint_initialize_mo_set(kpoint)
...
subroutine, public kpoint_initialize_mos(kpoint, mos, added_mos, for_aux_fit)
Initialize a set of MOs and density matrix for each kpoint (kpoint group).
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.
Machine interface based on Fortran 2003 and POSIX.
subroutine, public m_flush(lunit)
flushes units if the &GLOBAL flag is set accordingly
real(kind=dp) function, public m_walltime()
returns time from a real-time clock, protected against rolling early/easily
Collection of simple mathematical functions and subroutines.
Interface to the message passing library MPI.
Define the data structure for the particle information.
Definition of physical constants:
real(kind=dp), parameter, public evolt
subroutine, public init_preconditioner(preconditioner_env, para_env, blacs_env)
...
subroutine, public destroy_preconditioner(preconditioner_env)
...
computes preconditioners, and implements methods to apply them currently used in qs_ot
subroutine, public make_preconditioner_complex_full_s_inverse(preconditioner_env, matrix_s_re, matrix_s_im, solver_type)
Construct a complex FULL_S_INVERSE preconditioner.
subroutine, public make_preconditioner_complex_full_single(preconditioner_env, matrix_h_re, matrix_h_im, matrix_s_re, matrix_s_im, mo_set, energy_gap, solver_type)
Construct a complex FULL_SINGLE preconditioner from H(k) and S(k).
subroutine, public make_preconditioner_complex_full_single_inverse(preconditioner_env, matrix_c_re, matrix_c_im, matrix_h_re, matrix_h_im, matrix_s_re, matrix_s_im, energy_gap, solver_type)
Construct a complex FULL_SINGLE_INVERSE preconditioner without discarding Im(H,S,C).
subroutine, public make_preconditioner_complex_full_all_batch(preconditioners, matrix_c, matrix_h, matrix_s, energy_gap, solver_type, handled)
Build local FULL_ALL preconditioners from cached operators in bounded batches. Only the independent e...
subroutine, public make_preconditioner_complex_full_all_covariant(preconditioner_env, matrix_c_re, matrix_c_im, matrix_h_re, matrix_h_im, matrix_s_re, matrix_s_im, energy_gap, solver_type, occupation_signature)
Construct rotation-covariant FULL_ALL for one complex k-point channel.
subroutine, public restart_preconditioner(qs_env, preconditioner, prec_type, nspins)
Allows for a restart of the preconditioner depending on the method it purges all arrays or keeps them...
subroutine, public prepare_preconditioner(qs_env, mos, matrix_ks, matrix_s, ot_preconditioner, prec_type, solver_type, energy_gap, nspins, has_unit_metric, convert_to_dbcsr, chol_type, full_mo_set, chebyshev_degree, low_rank_base, fermi_low_rank_max_rank, lattice_fft, lattice_fft_local_cells)
...
subroutine, public make_preconditioner_complex_full_all(preconditioner_env, matrix_c_re, matrix_c_im, matrix_h_re, matrix_h_im, matrix_s_re, matrix_s_im, energy_gap, solver_type)
Construct FULL_ALL directly from one complex H(k), S(k), and C(k) channel.
subroutine, public make_preconditioner_complex_fermi_low_rank(preconditioner_env, matrix_c_re, matrix_c_im, matrix_h_re, matrix_h_im, matrix_s_re, matrix_s_im, energy_gap, max_rank, solver_type)
Construct FERMI_LOW_RANK directly for one complex k-point channel.
subroutine, public make_preconditioner_complex_full_kinetic(preconditioner_env, matrix_t_re, matrix_t_im, matrix_s_re, matrix_s_im, energy_gap, solver_type)
Construct a complex FULL_KINETIC preconditioner.
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 ...
module that contains the algorithms to perform an iterative diagonalization by the block-Davidson app...
subroutine, public block_davidson_deallocate(bdav_env)
...
Auxiliary routines for performing a constrained DFT SCF run with Quickstep.
subroutine, public prepare_jacobian_stencil(qs_env, output_unit, nwork, pwork, coeff, step_multiplier, dh)
Prepares the finite difference stencil for computing the Jacobian. The constraints are re-evaluated b...
subroutine, public build_diagonal_jacobian(qs_env, used_history)
Builds a strictly diagonal inverse Jacobian from MD/SCF history.
subroutine, public print_inverse_jacobian(logger, inv_jacobian, iter_count)
Prints the finite difference inverse Jacobian to file.
subroutine, public create_tmp_logger(para_env, project_name, suffix, output_unit, tmp_logger)
Creates a temporary logger for redirecting output to a new file.
subroutine, public restart_inverse_jacobian(qs_env)
Restarts the finite difference inverse Jacobian.
subroutine, public initialize_inverse_jacobian(scf_control, scf_env, explicit_jacobian, should_build, used_history)
Checks if the inverse Jacobian should be calculated and initializes the calculation.
Defines CDFT control structures.
real(kind=dp) function, public charge_mixing_scc_error(mixing_store, eps_scf)
Return the CP2K-side tblite SCC-mixer residual on the CP2K EPS_SCF scale.
container for information about total charges on the grids
collects routines that calculate density matrices
module that contains the definitions of the scf types
integer, parameter, public gspace_mixing_nr
Apply the direct inversion in the iterative subspace (DIIS) of Pulay in the framework of an SCF itera...
pure subroutine, public qs_diis_b_clear(diis_buffer)
clears the buffer
subroutine, public qs_diis_b_create(diis_buffer, nbuffer)
Allocates an SCF DIIS buffer.
subroutine, public qs_diis_b_create_kp(diis_buffer, nbuffer)
Allocates an SCF DIIS buffer for k-points.
pure subroutine, public qs_diis_b_clear_kp(diis_buffer)
clears the buffer
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.
Fractional occupation number weighted density (Grimme and Hansen).
subroutine, public qs_fod_validate(input, logger, qs_env)
Reject unsupported FOD settings before starting an expensive SCF calculation.
Integrate single or product functions over a potential on a RS grid.
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.
Assembly of real and complex k-point operators from real-space DBCSR matrices. Outputs use the distri...
subroutine, public kpoint_operator_context_create(ctx, kpoints, ao_ao_fm, nspin)
Create an empty operator context. The context owns no buffers after this call; they are created on fi...
subroutine, public kpoint_operator_store(ctx, matrix_ks, matrix_s, matrix_t)
Prepare owned split-FM operators for OT without entering an SCF eigensolver. H (or the initialization...
subroutine, public kpoint_operator_get_local(matrix_rs, kpoints, kp, ispin, cache_re, cache_im, matrix_re, matrix_im)
Read an operator inside a group-local OT loop, after collective cache preparation....
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_kpoint_state_prepare_fixed_density(kpoints)
Reconstructs fixed-rank complex k-point orbitals from a density kernel. The density and overlap must ...
subroutine, public qs_kpoint_set_fixed_occupations(kpoints)
Restores the fixed occupied rank required by k-point OT.
logical function, public qs_kpoint_mos_initialized(kpoints, require_full_space)
Checks whether every local k-point channel contains nonzero occupied orbitals.
subroutine, public qs_kpoint_copy_spin_mos(kpoints, nspin)
Copies the first k-point spin channel into the remaining channels.
subroutine, public qs_kpoint_state_canonicalize_fixed(kpoints)
Rotates a uniformly occupied k-point subspace into Ritz states of the current Hamiltonian and stores ...
routines that build the Kohn-Sham matrix contributions coming from local atomic densities
subroutine, public update_ks_atom(qs_env, ksmat, pmat, forces, tddft, rho_atom_external, kind_set_external, oce_external, sab_external, kscale, kintegral, kforce, fscale)
The correction to the KS matrix due to the GAPW local terms to the hartree and XC contributions is he...
routines that build the Kohn-Sham matrix (i.e calculate the coulomb and xc parts
subroutine, public evaluate_core_matrix_traces(qs_env, rho_ao_ext)
Calculates the traces of the core matrices and the density matrix.
subroutine, public qs_ks_update_qs_env(qs_env, calculate_forces, just_energy, print_active)
updates the Kohn Sham matrix of the given qs_env (facility method)
subroutine, public qs_ks_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...
subroutine, public get_ks_env(ks_env, v_hartree_rspace, s_mstruct_changed, rho_changed, exc_accint, potential_changed, forces_up_to_date, complex_ks, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, kinetic, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, matrix_vhxc, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_ks_im_kp, rho, rho_xc, vppl, xcint_weights, rho_core, rho_nlcc, rho_nlcc_g, vee, neighbor_list_id, sab_orb, sab_all, sac_ae, sac_ppl, sac_lri, sap_ppnl, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_vdw, sab_scp, sab_almo, sab_kp, sab_kp_nosym, sab_cneo, task_list, task_list_soft, kpoints, do_kpoints, atomic_kind_set, qs_kind_set, cell, cell_ref, use_ref_cell, particle_set, energy, force, local_particles, local_molecules, molecule_kind_set, molecule_set, subsys, cp_subsys, virial, results, atprop, nkind, natom, dft_control, dbcsr_dist, distribution_2d, pw_env, para_env, blacs_env, nelectron_total, nelectron_spin)
...
subroutine, public local_rho_set_create(local_rho_set)
...
subroutine, public local_rho_set_release(local_rho_set)
...
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)
subroutine, public mpools_release(mpools)
releases the given mpools
subroutine, public mpools_rebuild_fm_pools(mpools, mos, blacs_env, para_env, nmosub)
rebuilds the pools of the (ao x mo, ao x ao , mo x mo) full matrixes
subroutine, public mixing_init(mixing_method, rho, mixing_store, para_env, rho_atom, auxiliary)
initialiation needed when gspace mixing is used
Definition and initialisation of the mo data type.
subroutine, public write_mo_set_to_restart(mo_array, particle_set, dft_section, qs_kind_set, matrix_ks)
...
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_sm(vmatrix, ncol, matrix_s)
returns an S-orthonormal basis v (v^T S v ==1)
Set occupation of molecular orbitals.
Definition and initialisation of the mo data type.
subroutine, public duplicate_mo_set(mo_set_new, mo_set_old)
allocate a new mo_set, and copy the old data
subroutine, public init_mo_set(mo_set, fm_pool, fm_ref, fm_struct, name, counter, complex_coeff)
initializes an allocated mo_set. eigenvalues, mo_coeff, occupation_numbers are valid only after this ...
subroutine, public allocate_mo_set(mo_set, nao, nmo, nelectron, n_el_f, maxocc, flexible_electron_count)
Allocates a mo set and partially initializes it (nao,nmo,nelectron, and flexible_electron_count are v...
subroutine, public mo_set_restrict(mo_array, convert_dbcsr)
make the beta orbitals explicitly equal to the alpha orbitals effectively copying the orbital data
subroutine, public deallocate_mo_set(mo_set)
Deallocate a wavefunction data structure.
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.
subroutine, public reassign_allocated_mos(mo_set_new, mo_set_old)
reassign an already allocated mo_set
Complex k-point orbital transformations, response kernels and local batch execution....
subroutine, public qs_ot_get_orbitals_local_batch(qs_ot_env, matrix_s, matrix_c, initialize)
Rebuild single-rank STRICT/IRAC orbitals in bounded batches using cached overlaps....
subroutine, public qs_ot_get_orbitals_ref_complex(matrix_c, matrix_c_im, matrix_s, matrix_s_im, qs_ot_env, qs_ot_env1)
update complex REF k-point orbitals and their S(k)C(k) images
subroutine, public qs_ot_get_p_complex(matrix_x, matrix_x_im, matrix_sx, matrix_sx_im, qs_ot_env, zero_coordinates)
compute P=X^H*S*X and the STRICT matrix functions for a complex K-point channel
basic functionality for using ot in the scf routines.
subroutine, public ot_scf_init(mo_array, matrix_s, qs_ot_env, matrix_ks, broyden_adaptive_sigma)
initialises qs_ot_env so that mo_coeff is the current point and that the minization can be started.
subroutine, public ot_scf_read_input(qs_ot_env, scf_section, do_kpoints)
...
subroutine, public ot_scf_destroy(qs_ot_env)
...
subroutine, public qs_ot_init(qs_ot_env)
init matrices, needs c0 and sc0 so that c0*sc0=1
pure elemental logical function, public qs_ot_kpoint_preconditioner_supported(preconditioner_type, use_real_wfn)
Return whether a preconditioner is implemented for complex k-point OT.
subroutine, public qs_ot_allocate(qs_ot_env, matrix_s, fm_struct_ref, ortho_k, energy_dimension)
allocates the data in qs_ot_env, for a calculation with fm_struct_ref ortho_k allows for specifying a...
subroutine, public qs_ot_allocate_complex_state(qs_ot_env, matrix_s)
...
subroutine, public qs_ot_check_channel_context(qs_ot_env, nspin, nkpoint, restricted, require_kpoint, kp_range, wkp, require_local_state, require_complex_state)
validate the flat OT channel identity for spin and optional irreducible k-points
integer function, public qs_ot_number_of_channels(nspin, nkpoint, restricted)
number of OT optimization channels for spin and k-point resolved state
subroutine, public qs_ot_set_context(qs_ot_env, spin_index, kpoint_index, local_kpoint_index, kpoint_weight)
label an OT environment by spin and optional irreducible k-point context
integer function, public qs_ot_channel_index(ispin, ikpoint, nspin)
flat OT channel index for a spin/k-point pair
pure elemental logical function, public qs_ot_kpoint_preconditioner_solver_supported(preconditioner_type, solver_type, use_real_wfn)
Return whether a solver is implemented for a complex k-point OT preconditioner.
subroutine, public qs_ot_complex_multiply(op_a, op_b, a_re, a_im, b_re, b_im, c_re, c_im, tmp)
multiply paired real/imaginary DBCSR matrices, with optional conjugate transposes
subroutine, public qs_ot_new_preconditioner(qs_ot_env, preconditioner)
gets ready to use the preconditioner/ or renew the preconditioner only keeps a pointer to the precond...
Routines for performing an outer scf loop.
subroutine, public outer_loop_purge_history(qs_env)
purges outer_scf_history zeroing everything except the latest value of the outer_scf variable stored ...
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_optimize(scf_env, scf_control)
optimizes the parameters of the outer_scf
subroutine, public outer_loop_update_qs_env(qs_env, scf_env)
propagates the updated variables to wherever they need to be set in qs_env
subroutine, public outer_loop_gradient(qs_env, scf_env)
computes the gradient wrt to the outer loop variables
subroutine, public allocate_rho_atom_internals(rho_atom_set, atomic_kind_set, qs_kind_set, dft_control, para_env)
...
subroutine, public zero_rho_atom_integrals(rho_atom_set)
...
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...
Different diagonalization schemes that can be used for the iterative solution of the eigenvalue probl...
subroutine, public do_general_diag_kp(matrix_ks, matrix_s, kpoints, scf_env, scf_control, update_p, diis_step, diis_error, qs_env, probe, added_mos_auto_grow, potential)
Kpoint diagonalization routine Transforms matrices to kpoint, distributes kpoint groups,...
Utility routines for qs_scf.
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...
Utility routines for qs_scf.
subroutine, public qs_scf_new_mos_kp(qs_env, scf_env, scf_control, diis_step, probe, ot_kp_subspace_refresh, allow_ot_kp_subspace_refresh, allow_ot_kp_exit_refresh, accepted_ot_kp_searches, added_mos_auto_grow, energy_only)
Updates MOs and density matrix using diagonalization Kpoint code.
subroutine, public qs_scf_inner_finalize(scf_env, qs_env, diis_step, output_unit)
Performs the necessary steps before leaving innner scf loop.
pure logical function, public qs_scf_kp_search_endpoint(method)
identify an accepted OT search endpoint from its iteration label
subroutine, public qs_scf_set_loop_flags(scf_env, diis_step, energy_only, just_energy, exit_inner_loop)
computes properties for a given hamiltonian using the current wfn
subroutine, public qs_scf_check_inner_exit(qs_env, scf_env, scf_control, should_stop, just_energy, exit_inner_loop, inner_loop_converged, output_unit, u_changed)
checks whether exit conditions for inner loop are satisfied
subroutine, public qs_scf_rho_update(rho, qs_env, scf_env, ks_env, mix_rho)
Performs the updates rho (takes care of mixing as well).
subroutine, public qs_scf_check_outer_exit(qs_env, scf_env, scf_control, should_stop, outer_loop_converged, exit_outer_loop)
checks whether exit conditions for outer loop are satisfied
subroutine, public qs_scf_density_mixing(scf_env, rho, para_env, diis_step, kpoints)
Performs the requested density mixing if any needed.
subroutine, public qs_scf_commit_density_candidate(scf_env, rho)
Commit the diagonalized candidate density without numerical mixing.
subroutine, public qs_scf_new_mos(qs_env, scf_env, scf_control, scf_section, diis_step, energy_only, probe)
takes known energy and derivatives and produces new wfns and or density matrix
subroutine, public qs_scf_candidate_density_delta(scf_env, rho, para_env, delta, kpoints)
Measure the distance between the diagonalized candidate density and the current density.
subroutine, public qs_scf_loop_info(scf_env, output_unit, just_energy, t1, t2, energy, adiis_verbose)
writes basic information obtained in a scf step
subroutine, public qs_scf_loop_print(qs_env, scf_env, para_env)
collects the 'heavy duty' printing tasks out of the SCF loop
subroutine, public qs_scf_outer_loop_info(output_unit, scf_control, scf_env, energy, total_steps, should_stop, outer_loop_converged)
writes basic information obtained in a scf outer loop step
subroutine, public qs_scf_write_mos(qs_env, scf_env, final_mos)
Write the MO eigenvector, eigenvalues, and occupation numbers to the output unit.
subroutine, public qs_scf_cdft_info(output_unit, scf_control, scf_env, cdft_control, energy, total_steps, should_stop, outer_loop_converged, cdft_loop)
writes CDFT constraint information and optionally CDFT scf loop info
subroutine, public qs_scf_cdft_initial_info(output_unit, cdft_control)
writes information about the CDFT env
subroutine, public qs_scf_gce_info(output_unit, qs_env, just_energy)
Print grand canonical SCF information for the current SCF iteration.
Utility routines for qs_scf.
subroutine, public qs_scf_compute_properties(qs_env, wf_type, do_mp2)
computes properties for a given hamilonian using the current wfn
Data types for the ADIIS SCF subspace accelerator.
pure subroutine, public qs_scf_subspace_buffer_create(buffer, nbuffer)
Initialize SCF subspace history metadata.
subroutine, public qs_scf_subspace_buffer_release(buffer)
Release all matrices and scalar storage owned by a subspace buffer.
pure subroutine, public qs_scf_subspace_buffer_clear(buffer)
Clear logical history while retaining allocated matrix storage.
History management and matrix combination for ADIIS.
subroutine, public qs_scf_subspace_push(buffer, fock, density, state_energy, pushed, density_aux, fock_aux)
Append one accepted, evaluated P,F[P] state to the ADIIS history.
subroutine, public qs_scf_subspace_restart(buffer, fock, density, state_energy, restarted, density_aux, fock_aux)
Restart the ADIIS history from the current strictly paired P, F[P] state.
subroutine, public qs_scf_subspace_build(buffer)
Solve the ADIIS model from previously accepted history and form an effective KS matrix.
subroutine, public qs_scf_subspace_update_shift(buffer, shift)
Adapt candidate regularization from two evaluated states; no trial KS builds.
module that contains the definitions of the scf types
integer, parameter, public ot_diag_method_nr
integer, parameter, public filter_matrix_diag_method_nr
integer, parameter, public block_davidson_diag_method_nr
subroutine, public scf_env_release_ot_operators(scf_env)
Drop k-point OT operator caches before their pools or layout can change.
integer, parameter, public smeagol_method_nr
integer, parameter, public ot_method_nr
integer, parameter, public special_diag_method_nr
integer, parameter, public block_krylov_diag_method_nr
integer, parameter, public general_diag_method_nr
Routines for the Quickstep SCF run.
subroutine, public cdft_scf(qs_env, should_stop, has_converged, total_scf_steps)
perform a CDFT scf procedure in the given qs_env
subroutine, public scf(qs_env, has_converged, total_scf_steps)
perform an scf procedure in the given qs_env
subroutine, public scf_env_cleanup(scf_env)
perform cleanup operations (like releasing temporary storage) at the end of the scf
subroutine, public init_scf_loop(scf_env, qs_env, scf_section, kp_ot_entry_reason)
inits those objects needed if you want to restart the scf with, say only a new initial guess,...
subroutine, public scf_env_do_scf(scf_env, scf_control, qs_env, converged, should_stop, total_scf_steps)
perform an scf loop
routines that build the integrals of the Vxc potential calculated for the atomic density in the basis...
subroutine, public gapw_cdft_one_center(qs_env, energy_only, calculate_forces, values, electronic_charge, operator_group, rho_atom_operator_set)
Add the GAPW one-center correction to CDFT values and operators.
Storage of past states of the qs_env. Methods to interpolate (or actually normally extrapolate) the n...
subroutine, public wfi_purge_history(qs_env)
purges wf_history retaining only the latest snapshot
subroutine, public wfi_update(wf_history, qs_env, dt)
updates the snapshot buffer, taking a new snapshot
parameters that control an scf iteration
subroutine, public run_smeagol_emtrans(qs_env, last, iter, rho_ao_kp)
Run NEGF/SMEAGOL transport calculation.
subroutine, public run_smeagol_bulktrans(qs_env)
Save overlap, Kohn-Sham, electron density, and energy-density matrices of semi-infinite electrodes in...
logical function, public tb_native_scc_mixer_active(dft_control)
Return whether the tblite native SCC mixer is active for this run.
subroutine, public tb_update_charges(qs_env, dft_control, tb, calculate_forces, use_rho)
...
subroutine, public tb_get_energy(qs_env, tb, energy)
...
real(kind=dp) function, public tb_scf_mixer_error(dft_control, tb, eps_scf)
Return the native tblite SCC mixer residual on the CP2K iter_delta scale.
Provides all information about an atomic kind.
represent a blacs multidimensional parallel environment (for the mpi corrispective see cp_paratypes/m...
Just to build arrays of pointers to matrices.
Represent a complex full matrix.
to create arrays of pools
keeps the information about the structure of a full matrix
just to build arrays of pointers to matrices
type of a logger, at the moment it contains just a print level starting at which level it should be l...
contains arbitrary information which need to be stored
Contains information on the energy correction functional for KG.
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 information about total charges on the grids.
Provides all information about a quickstep kind.
calculation environment to calculate the ks matrix, holds all the needed vars. assumes that the core ...
keeps the density in various representations, keeping track of which ones are valid.