59 dbcsr_type_no_symmetry
245#include "./base/base_uses.f90"
251 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'qs_scf'
252 INTEGER,
PARAMETER,
PRIVATE :: kp_ot_entry_initial = 1, &
253 kp_ot_entry_reuse = 2, &
254 kp_ot_entry_resized = 3, &
255 kp_ot_entry_refresh = 4
256 LOGICAL,
PRIVATE :: reuse_precond = .false.
257 LOGICAL,
PRIVATE :: used_history = .false.
273 SUBROUTINE scf(qs_env, has_converged, total_scf_steps)
275 LOGICAL,
INTENT(OUT),
OPTIONAL :: has_converged
276 INTEGER,
INTENT(OUT),
OPTIONAL :: total_scf_steps
278 INTEGER :: ihistory, max_scf_tmp, tsteps
279 LOGICAL :: converged, outer_scf_loop, should_stop
280 LOGICAL,
SAVE :: first_step_flag = .true.
281 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: gradient_history, variable_history
290 cpassert(
ASSOCIATED(qs_env))
291 IF (
PRESENT(has_converged))
THEN
292 has_converged = .false.
294 IF (
PRESENT(total_scf_steps))
THEN
297 CALL get_qs_env(qs_env, scf_env=scf_env, input=input, &
298 dft_control=dft_control, scf_control=scf_control)
300 qs_env%scf_convergence_available = .false.
301 qs_env%scf_converged = .false.
302 IF (scf_control%max_scf > 0)
THEN
307 IF (.NOT.
ASSOCIATED(scf_env))
THEN
315 IF ((scf_control%density_guess ==
history_guess) .AND. (first_step_flag))
THEN
316 max_scf_tmp = scf_control%max_scf
317 scf_control%max_scf = 1
318 outer_scf_loop = scf_control%outer_scf%have_scf
319 scf_control%outer_scf%have_scf = .false.
322 IF (.NOT. dft_control%qs_control%cdft)
THEN
323 CALL scf_env_do_scf(scf_env=scf_env, scf_control=scf_control, qs_env=qs_env, &
324 converged=converged, should_stop=should_stop, total_scf_steps=tsteps)
327 CALL cdft_scf(qs_env=qs_env, should_stop=should_stop, &
328 has_converged=converged, total_scf_steps=tsteps)
331 qs_env%scf_convergence_available = .true.
332 qs_env%scf_converged = converged
335 IF (
ASSOCIATED(qs_env%mp2_env)) qs_env%mp2_env%hf_fail = .NOT. converged
338 IF (scf_control%outer_scf%have_scf)
THEN
339 ihistory = scf_env%outer_scf%iter_count
340 CALL get_qs_env(qs_env, gradient_history=gradient_history, &
341 variable_history=variable_history)
343 gradient_history(:, 1) = gradient_history(:, 2)
344 gradient_history(:, 2) = scf_env%outer_scf%gradient(:, ihistory)
345 variable_history(:, 1) = variable_history(:, 2)
346 variable_history(:, 2) = scf_env%outer_scf%variables(:, ihistory)
348 IF (used_history) used_history = .false.
350 IF (
ASSOCIATED(scf_env%outer_scf%inv_jacobian))
THEN
351 scf_control%outer_scf%cdft_opt_control%ijacobian(2) = scf_control%outer_scf%cdft_opt_control%ijacobian(2) + 1
352 IF (scf_control%outer_scf%cdft_opt_control%ijacobian(2) >= &
353 scf_control%outer_scf%cdft_opt_control%jacobian_freq(2) .AND. &
354 scf_control%outer_scf%cdft_opt_control%jacobian_freq(2) > 0)
THEN
355 scf_env%outer_scf%deallocate_jacobian = .true.
360 IF ((
ASSOCIATED(qs_env%wf_history)) .AND. &
362 (.NOT. first_step_flag)))
THEN
363 IF (.NOT. dft_control%qs_control%cdft)
THEN
365 IF (.NOT. qs_env%skip_wf_history)
THEN
366 CALL wfi_update(qs_env%wf_history, qs_env=qs_env, dt=1.0_dp)
369 IF (dft_control%qs_control%cdft_control%should_purge)
THEN
372 dft_control%qs_control%cdft_control%should_purge = .false.
374 CALL wfi_update(qs_env%wf_history, qs_env=qs_env, dt=1.0_dp)
377 ELSE IF ((scf_control%density_guess ==
history_guess) .AND. &
378 (first_step_flag))
THEN
379 scf_control%max_scf = max_scf_tmp
380 scf_control%outer_scf%have_scf = outer_scf_loop
381 first_step_flag = .false.
388 IF (.NOT. (should_stop))
THEN
397 IF (dft_control%qs_control%cdft)
THEN
398 CALL cdft_control_cleanup(dft_control%qs_control%cdft_control)
401 IF (
PRESENT(has_converged))
THEN
402 has_converged = converged
404 IF (
PRESENT(total_scf_steps))
THEN
405 total_scf_steps = tsteps
429 SUBROUTINE scf_env_do_scf(scf_env, scf_control, qs_env, converged, should_stop, total_scf_steps)
434 LOGICAL,
INTENT(OUT) :: converged, should_stop
435 INTEGER,
INTENT(OUT) :: total_scf_steps
437 CHARACTER(LEN=*),
PARAMETER :: routinen =
'scf_env_do_scf'
438 INTEGER,
PARAMETER :: max_ot_kp_subspace_refreshes = 4
439 REAL(kind=
dp),
PARAMETER :: adiis_stagnation_ratio = 1.0e-2_dp
441 CHARACTER(LEN=default_string_length) :: description, name
442 INTEGER :: accepted_ot_kp_searches, ext_master_id, handle, handle2, i_tmp, ic, ispin, &
443 iter_count, kp_ot_entry_reason, ot_kp_subspace_refresh_count, &
444 ot_kp_subspace_refresh_iter_count, output_unit, scf_energy_message_tag, total_steps
445 LOGICAL :: added_mos_auto_grow, adiis_pushed, adiis_restarted, adiis_stagnated, &
446 adiis_validation, density_full_step, diis_step, do_kpoints, energy_only, exit_inner_loop, &
447 exit_outer_loop, inner_loop_converged, internal_tblite_density_full_step, &
448 internal_tblite_mixer, just_energy, ot_kp_subspace_refresh, &
449 ot_kp_subspace_refresh_pending, outer_loop_converged, tblite_native_mixer, u_changed
450 REAL(
dp),
POINTER :: subspace_density(:, :), &
452 REAL(kind=
dp) :: adiis_raw_delta, adiis_step_delta, t1, t2
453 REAL(kind=
dp),
DIMENSION(3) :: res_val_3
458 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_ks_kp, rho_ao_kp
462 TYPE(
mo_set_type),
DIMENSION(:),
POINTER :: mos, mos_last_converged
469 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
477 CALL timeset(routinen, handle)
479 NULLIFY (dft_control, rho, energy, &
480 logger, qs_charges, ks_env, mos, atomic_kind_set, qs_kind_set, &
481 particle_set, dft_section, input, &
482 scf_section, para_env, results, kpoints, pw_env, matrix_ks, &
483 matrix_ks_kp, rho_ao_kp, mos_last_converged)
485 cpassert(
ASSOCIATED(scf_env))
486 cpassert(
ASSOCIATED(qs_env))
493 particle_set=particle_set, &
494 qs_charges=qs_charges, &
496 atomic_kind_set=atomic_kind_set, &
497 qs_kind_set=qs_kind_set, &
500 matrix_ks_kp=matrix_ks_kp, &
502 dft_control=dft_control, &
503 do_kpoints=do_kpoints, &
508 tblite_native_mixer = dft_control%qs_control%xtb_control%do_tblite .AND. &
511 internal_tblite_mixer = (dft_control%qs_control%dftb .AND. &
513 (dft_control%qs_control%xtb .AND. &
514 .NOT. dft_control%qs_control%xtb_control%do_tblite .AND. &
516 internal_tblite_density_full_step = dft_control%qs_control%xtb .AND. &
517 .NOT. dft_control%qs_control%xtb_control%do_tblite .AND. &
528 IF (scf_control%gce%do_gce .AND. output_unit > 0)
THEN
529 WRITE (unit=output_unit, fmt=
"(/,T2,78('-'))")
530 WRITE (unit=output_unit, fmt=
"(T31,A)") &
531 "GRAND-CANONICAL SCF"
532 WRITE (unit=output_unit, fmt=
"(T20,A,F12.6,A)") &
533 "Target work function (TWF):", &
534 evolt*scf_control%gce%target_workfunction,
" eV"
535 WRITE (unit=output_unit, fmt=
"(T2,78('-'))")
538 IF (output_unit > 0)
WRITE (unit=output_unit, fmt=
"(/,/,T2,A)") &
539 "SCF WAVEFUNCTION OPTIMIZATION"
542 IF (dft_control%switch_surf_dip)
THEN
543 CALL get_qs_env(qs_env, mos_last_converged=mos_last_converged)
544 DO ispin = 1, dft_control%nspins
547 IF (output_unit > 0)
WRITE (unit=output_unit, fmt=
"(/,/,T2,A)") &
548 "COPIED mos_last_converged ---> mos"
551 IF ((output_unit > 0) .AND. (.NOT. scf_control%use_ot))
THEN
552 WRITE (unit=output_unit, &
553 fmt=
"(/,T3,A,T12,A,T31,A,T39,A,T59,A,T75,A,/,T3,A)") &
554 "Step",
"Update method",
"Time",
"Convergence",
"Total energy",
"Change", &
560 res_val_3(:) = -1.0_dp
561 description =
"[EXT_SCF_ENER_COMM]"
563 CALL get_results(results, description=description, &
564 values=res_val_3, n_entries=i_tmp)
566 IF (all(res_val_3(:) <= 0.0_dp))
THEN
567 CALL cp_abort(__location__, &
568 " Trying to access result ("//trim(description)// &
569 ") which is not correctly stored.")
571 CALL external_comm%set_handle(nint(res_val_3(1)))
573 ext_master_id = nint(res_val_3(2))
574 scf_energy_message_tag = nint(res_val_3(3))
578 scf_env%outer_scf%iter_count = 0
579 accepted_ot_kp_searches = 0
581 kp_ot_entry_reason = kp_ot_entry_initial
582 ot_kp_subspace_refresh_count = 0
583 ot_kp_subspace_refresh_iter_count = 0
584 ot_kp_subspace_refresh_pending = .false.
586 energy%tot_old = 0.0_dp
591 scf_section=scf_section, &
592 kp_ot_entry_reason=kp_ot_entry_reason)
593 kp_ot_entry_reason = kp_ot_entry_reuse
594 scf_env%adiis_shift = scf_control%diagonalization%adiis_shift
597 energy_only, just_energy, exit_inner_loop)
598 IF (ot_kp_subspace_refresh_pending)
THEN
599 scf_env%iter_count = ot_kp_subspace_refresh_iter_count
600 ot_kp_subspace_refresh_pending = .false.
604 dft_control%surf_dip_correct_switch = dft_control%correct_surf_dip
605 IF ((dft_control%correct_surf_dip) .AND. (scf_control%outer_scf%have_scf) .AND. &
606 (scf_env%outer_scf%iter_count > floor(scf_control%outer_scf%max_scf/2.0_dp)))
THEN
607 IF (dft_control%switch_surf_dip)
THEN
608 dft_control%surf_dip_correct_switch = .false.
609 IF (output_unit > 0)
WRITE (unit=output_unit, fmt=
"(/,/,T2,A)") &
610 "SURFACE DIPOLE CORRECTION switched off"
616 CALL timeset(routinen//
"_inner_loop", handle2)
618 IF (.NOT. just_energy) scf_env%iter_count = scf_env%iter_count + 1
619 iter_count = iter_count + 1
620 CALL cp_iterate(logger%iter_info, last=.false., iter_nr=iter_count)
622 IF (output_unit > 0)
CALL m_flush(output_unit)
624 total_steps = total_steps + 1
625 just_energy = energy_only
628 calculate_forces=.false.)
630 scf_env%raw_map_delta = 0.0_dp
631 scf_env%raw_map_delta_valid = .false.
635 added_mos_auto_grow = .false.
636 ot_kp_subspace_refresh = .false.
638 scf_env%adiis_check_next
639 adiis_step_delta = scf_env%step_norm
640 scf_env%adiis_validated = .false.
643 NULLIFY (subspace_density, subspace_fock)
645 IF (
ALLOCATED(kpoints%lowdin_q))
THEN
646 subspace_density => kpoints%lowdin_q
647 subspace_fock => kpoints%lowdin_v
654 cpassert(
ASSOCIATED(scf_env%scf_subspace_buffer))
655 scf_env%scf_subspace_buffer%last_restart = .false.
656 scf_env%scf_subspace_buffer%use_combined_fock = .false.
657 scf_env%scf_subspace_buffer%last_old_fock_weight = 0.0_dp
658 IF (.NOT. adiis_validation .AND. scf_env%iter_count > 1)
THEN
663 IF (scf_control%diagonalization%adiis_shift > 0.0_dp .OR. &
664 scf_env%scf_subspace_buffer%diis_weight < 1.0_dp .OR. &
665 scf_env%iter_delta >= scf_control%eps_diis)
THEN
667 energy%total, adiis_pushed, subspace_density, subspace_fock)
668 IF (.NOT. adiis_pushed) cpabort(
"Failed to append the accepted ADIIS SCF state")
670 IF (scf_control%diagonalization%adiis_shift > 0.0_dp)
THEN
677 added_mos_auto_grow=added_mos_auto_grow)
679 CALL qs_scf_new_mos(qs_env, scf_env, scf_control, scf_section, diis_step, energy_only)
682 IF (adiis_validation)
THEN
684 scf_env%raw_map_delta = adiis_raw_delta
685 scf_env%raw_map_delta_valid = .true.
686 IF (adiis_raw_delta < scf_control%eps_scf)
THEN
687 scf_env%iter_delta = adiis_raw_delta
688 scf_env%iter_param = 0.0_dp
689 scf_env%iter_method =
"ADIIS/Chk."
690 scf_env%adiis_validated = .true.
691 scf_env%adiis_check_next = .false.
693 adiis_stagnated = adiis_step_delta <= adiis_stagnation_ratio*adiis_raw_delta
694 IF (adiis_stagnated)
THEN
701 energy%total, adiis_restarted, subspace_density, subspace_fock)
702 IF (.NOT. adiis_restarted)
THEN
703 cpabort(
"Failed to restart the ADIIS history from the current SCF state")
705 scf_env%iter_delta = adiis_raw_delta
706 scf_env%iter_param = 0.0_dp
707 scf_env%iter_method =
"ADIIS/Rst."
708 scf_env%adiis_check_next = .false.
714 energy%total, adiis_pushed, subspace_density, subspace_fock)
715 IF (.NOT. adiis_pushed) cpabort(
"Failed to append the accepted ADIIS SCF state")
719 added_mos_auto_grow=added_mos_auto_grow)
721 CALL qs_scf_new_mos(qs_env, scf_env, scf_control, scf_section, diis_step, energy_only)
724 scf_env%adiis_validated = scf_env%iter_delta < scf_control%eps_scf
725 IF (scf_env%adiis_validated .AND. .NOT. diis_step)
THEN
726 scf_env%iter_param = 0.0_dp
727 scf_env%iter_method =
"ADIIS/Chk."
731 scf_env%adiis_check_next = .false.
736 IF (.NOT. adiis_validation)
THEN
738 scf_env%adiis_check_next = .NOT. diis_step .AND. &
739 scf_env%iter_delta < scf_control%eps_scf
745 IF (dft_control%hairy_probes .EQV. .true.)
THEN
746 scf_control%smear%do_smear = .false.
747 CALL qs_scf_new_mos_kp(qs_env, scf_env, scf_control, diis_step, dft_control%probe, &
748 energy_only=energy_only)
751 qs_env, scf_env, scf_control, diis_step, &
752 ot_kp_subspace_refresh=ot_kp_subspace_refresh, &
753 allow_ot_kp_subspace_refresh= &
754 ot_kp_subspace_refresh_count == 0, &
755 allow_ot_kp_exit_refresh= &
756 ot_kp_subspace_refresh_count > 0 .AND. &
757 ot_kp_subspace_refresh_count < max_ot_kp_subspace_refreshes, &
758 accepted_ot_kp_searches=accepted_ot_kp_searches, &
759 added_mos_auto_grow=added_mos_auto_grow, energy_only=energy_only)
763 IF (dft_control%hairy_probes .EQV. .true.)
THEN
764 scf_control%smear%do_smear = .false.
765 CALL qs_scf_new_mos(qs_env, scf_env, scf_control, scf_section, diis_step, energy_only, &
768 CALL qs_scf_new_mos(qs_env, scf_env, scf_control, scf_section, diis_step, energy_only)
773 IF (added_mos_auto_grow)
THEN
774 CALL qs_scf_grow_added_mos_auto_kp(qs_env, scf_env, scf_control, output_unit)
775 kp_ot_entry_reason = kp_ot_entry_resized
776 total_steps = max(0, total_steps - 1)
777 iter_count = max(0, iter_count - 1)
778 IF (.NOT. just_energy) scf_env%iter_count = max(0, scf_env%iter_count - 1)
779 CALL timestop(handle2)
783 IF (ot_kp_subspace_refresh)
THEN
784 IF (output_unit > 0)
THEN
785 WRITE (unit=output_unit, fmt=
"(T2,A)") &
786 "K-point OT: rebuilding physical virtual subspace by full KS diagonalization."
789 IF (
ASSOCIATED(scf_env%qs_ot_env))
THEN
790 DO ispin = 1,
SIZE(scf_env%qs_ot_env)
793 DEALLOCATE (scf_env%qs_ot_env)
794 NULLIFY (scf_env%qs_ot_env)
796 IF (
ASSOCIATED(kpoints%scf_diis_buffer))
THEN
799 reuse_precond = .false.
800 accepted_ot_kp_searches = 0
801 ot_kp_subspace_refresh_count = ot_kp_subspace_refresh_count + 1
802 total_steps = max(0, total_steps - 1)
803 iter_count = max(0, iter_count - 1)
804 IF (.NOT. just_energy) scf_env%iter_count = max(0, scf_env%iter_count - 1)
805 ot_kp_subspace_refresh_iter_count = scf_env%iter_count
806 ot_kp_subspace_refresh_pending = .true.
807 kp_ot_entry_reason = kp_ot_entry_refresh
808 CALL timestop(handle2)
812 IF (do_kpoints .AND. scf_env%method ==
ot_method_nr .AND. &
814 accepted_ot_kp_searches = accepted_ot_kp_searches + 1
820 IF (dft_control%qs_control%xtb_control%do_tblite)
THEN
825 cpassert(scf_env%mixing_method > 0)
834 density_full_step = .true.
836 density_full_step = diis_step .OR. tblite_native_mixer .OR. internal_tblite_density_full_step
839 IF (dft_control%qs_control%xtb_control%do_tblite .AND. &
840 .NOT. (dft_control%qs_control%do_ls_scf .OR. scf_control%use_ot))
THEN
841 scf_env%iter_delta = max(scf_env%iter_delta, &
843 scf_control%eps_scf))
845 IF (dft_control%qs_control%dftb .OR. &
846 (dft_control%qs_control%xtb .AND. .NOT. dft_control%qs_control%xtb_control%do_tblite))
THEN
847 scf_env%iter_delta = max(scf_env%iter_delta, &
850 IF (tblite_native_mixer)
THEN
851 scf_env%iter_param = dft_control%qs_control%xtb_control%tblite_mixer_damping
852 scf_env%iter_method =
"TBLite/Diag"
853 ELSE IF (internal_tblite_mixer)
THEN
854 scf_env%iter_method =
"TBLite/Diag"
855 IF (dft_control%qs_control%dftb)
THEN
856 scf_env%iter_param = dft_control%qs_control%dftb_control%tblite_mixer_damping
858 scf_env%iter_param = dft_control%qs_control%xtb_control%tblite_mixer_damping
861 scf_env%step_norm = scf_env%iter_delta
866 scf_control%diagonalization%adiis_verbose)
868 IF (scf_control%gce%do_gce)
THEN
872 IF (.NOT. just_energy) energy%tot_old = energy%total
875 IF (scf_energy_message_tag > 0)
THEN
876 CALL external_comm%send(energy%total, ext_master_id, scf_energy_message_tag)
880 exit_inner_loop, inner_loop_converged, output_unit, u_changed)
883 IF (scf_env%mixing_method > 1)
THEN
884 CALL get_qs_env(qs_env, rho_atom_set=rho_atom)
885 CALL mixing_init(scf_env%mixing_method, rho, scf_env%mixing_store, para_env, &
886 rho_atom=rho_atom, auxiliary=kpoints%lowdin_q)
888 CALL init_scf_loop(scf_env, qs_env, scf_section, kp_ot_entry_reuse)
889 energy_only = .false.
890 just_energy = .false.
891 CALL timestop(handle2)
897 IF (exit_inner_loop)
THEN
902 outer_loop_converged, exit_outer_loop)
905 IF (exit_outer_loop)
CALL cp_iterate(logger%iter_info, last=.true., iter_nr=iter_count)
912 IF (.NOT. dft_control%mtlr_dft_with_perturbation)
THEN
916 CALL get_ks_env(ks_env=ks_env, matrix_ks=matrix_ks)
926 IF (exit_inner_loop)
THEN
927 CALL timestop(handle2)
932 scf_section,
"PRINT%ITERATION_INFO/TIME_CUMUL"),
cp_p_file))
THEN
937 IF (scf_env%mixing_method > 0)
THEN
938 DO ic = 1,
SIZE(rho_ao_kp, 2)
939 DO ispin = 1, dft_control%nspins
941 CALL dbcsr_copy(rho_ao_kp(ispin, ic)%matrix, scf_env%p_mix_new(ispin, ic)%matrix, name=name)
949 CALL timestop(handle2)
953 IF (.NOT. scf_control%outer_scf%have_scf)
EXIT scf_outer_loop
957 energy, total_steps, should_stop, outer_loop_converged)
960 IF (exit_outer_loop)
THEN
961 IF ((dft_control%switch_surf_dip) .AND. (outer_loop_converged) .AND. &
962 (dft_control%surf_dip_correct_switch))
THEN
963 DO ispin = 1, dft_control%nspins
966 IF (output_unit > 0)
WRITE (unit=output_unit, fmt=
"(/,/,T2,A)") &
967 "COPIED mos ---> mos_last_converged"
971 IF (exit_outer_loop)
EXIT scf_outer_loop
978 END DO scf_outer_loop
980 converged = inner_loop_converged .AND. outer_loop_converged
981 total_scf_steps = total_steps
983 IF (dft_control%qs_control%cdft)
THEN
984 dft_control%qs_control%cdft_control%total_steps = &
985 dft_control%qs_control%cdft_control%total_steps + total_steps
988 IF (.NOT. converged)
THEN
989 IF (scf_control%ignore_convergence_failure .OR. should_stop)
THEN
990 CALL cp_warn(__location__,
"SCF run NOT converged")
992 CALL cp_abort(__location__, &
993 "SCF run NOT converged. To continue the calculation "// &
994 "regardless, please set the keyword IGNORE_CONVERGENCE_FAILURE.")
999 IF (qs_env%energy_correction)
THEN
1001 ec_env%do_skip = .false.
1002 IF (ec_env%skip_ec .AND. .NOT. converged) ec_env%do_skip = .true.
1006 DO ispin = 1,
SIZE(mos)
1007 IF (mos(ispin)%use_mo_coeff_b)
THEN
1008 IF (.NOT.
ASSOCIATED(mos(ispin)%mo_coeff_b))
THEN
1010 cpabort(
"mo_coeff_b is not allocated")
1013 mos(ispin)%mo_coeff)
1018 CALL timestop(handle)
1029 SUBROUTINE qs_scf_grow_added_mos_auto_kp(qs_env, scf_env, scf_control, output_unit)
1034 INTEGER,
INTENT(IN) :: output_unit
1036 CHARACTER(LEN=*),
PARAMETER :: routinen =
'qs_scf_grow_added_mos_auto_kp'
1038 INTEGER :: base_nmo, common_base_nmo, current_added, current_target_nmo, grow_by, handle, &
1039 ic, ik, ispin, nmo_mat, nspins, old_nmo, target_nmo
1040 INTEGER,
DIMENSION(2) :: base_nmo_spin, new_added, new_nmo
1041 LOGICAL :: diag_step, has_unit_metric, need_resize, &
1043 REAL(kind=
dp) :: energy_step, flexible_electron_count, &
1045 REAL(kind=
dp),
DIMENSION(:),
POINTER :: eigenvalues, occupation_numbers, &
1046 old_eigenvalues, old_occupation_numbers
1051 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_ks, matrix_s
1055 TYPE(
mo_set_type),
ALLOCATABLE,
DIMENSION(:) :: old_mos
1059 CALL timeset(routinen, handle)
1061 NULLIFY (ao_mo_fm_pools, blacs_env, dft_control, eigenvalues, kpoints, matrix_ks, matrix_s, &
1062 mo_coeff, mo_derivs, mos, occupation_numbers, old_eigenvalues, &
1063 old_occupation_numbers, para_env)
1065 CALL get_qs_env(qs_env=qs_env, blacs_env=blacs_env, dft_control=dft_control, &
1066 kpoints=kpoints, matrix_ks_kp=matrix_ks, matrix_s_kp=matrix_s, &
1067 mo_derivs=mo_derivs, mos=mos, para_env=para_env, &
1068 has_unit_metric=has_unit_metric)
1070 cpassert(
ASSOCIATED(mos))
1071 cpassert(
ASSOCIATED(kpoints))
1072 cpassert(
ASSOCIATED(dft_control))
1073 cpassert(
ASSOCIATED(scf_control))
1074 cpassert(
ASSOCIATED(matrix_ks))
1075 cpassert(
ASSOCIATED(matrix_s))
1077 nspins = dft_control%nspins
1078 cpassert(nspins >= 1 .AND. nspins <=
SIZE(new_nmo))
1079 new_added = scf_control%added_mos
1081 need_resize = .false.
1082 shared_spin_auto = nspins == 2 .AND. all(scf_control%added_mos_auto(1:2))
1084 IF (shared_spin_auto)
THEN
1085 DO ispin = 1, nspins
1086 current_added = max(0, scf_control%added_mos(ispin))
1087 base_nmo_spin(ispin) = max(0, mos(ispin)%nmo - current_added)
1089 common_base_nmo = maxval(base_nmo_spin(1:nspins))
1090 current_target_nmo = maxval(mos(1:nspins)%nmo)
1091 current_added = max(0, current_target_nmo - common_base_nmo)
1092 grow_by = max(4, current_added)
1093 target_nmo = min(minval(mos(1:nspins)%nao), current_target_nmo + grow_by)
1094 DO ispin = 1, nspins
1095 new_nmo(ispin) = target_nmo
1096 new_added(ispin) = target_nmo - base_nmo_spin(ispin)
1097 need_resize = need_resize .OR. new_nmo(ispin) > mos(ispin)%nmo
1100 DO ispin = 1, nspins
1101 old_nmo = mos(ispin)%nmo
1102 new_nmo(ispin) = old_nmo
1103 IF (.NOT. scf_control%added_mos_auto(ispin)) cycle
1104 current_added = max(0, scf_control%added_mos(ispin))
1105 base_nmo = max(0, old_nmo - current_added)
1106 grow_by = max(4, current_added)
1107 new_added(ispin) = min(mos(ispin)%nao - base_nmo, current_added + grow_by)
1108 new_nmo(ispin) = base_nmo + new_added(ispin)
1109 need_resize = need_resize .OR. new_nmo(ispin) > old_nmo
1112 IF (nspins == 2)
THEN
1113 target_nmo = maxval(new_nmo(1:nspins))
1114 DO ispin = 1, nspins
1115 IF (target_nmo > mos(ispin)%nao)
THEN
1116 CALL cp_abort(__location__, &
1117 "K-point ADDED_MOS AUTO exhausted the AO basis while matching spin bands.")
1119 IF (target_nmo > mos(ispin)%nmo .AND. .NOT. scf_control%added_mos_auto(ispin))
THEN
1120 CALL cp_abort(__location__, &
1121 "K-point ADDED_MOS AUTO needs to grow a spin channel with explicit ADDED_MOS.")
1123 base_nmo = max(0, mos(ispin)%nmo - max(0, scf_control%added_mos(ispin)))
1124 new_nmo(ispin) = target_nmo
1125 new_added(ispin) = target_nmo - base_nmo
1126 need_resize = need_resize .OR. new_nmo(ispin) > mos(ispin)%nmo
1131 IF (.NOT. need_resize)
THEN
1132 CALL cp_abort(__location__, &
1133 "K-point ADDED_MOS AUTO cannot grow further although the highest band is still occupied.")
1136 scf_control%added_mos(1:nspins) = new_added(1:nspins)
1137 IF (output_unit > 0)
THEN
1138 IF (nspins == 2)
THEN
1139 WRITE (unit=output_unit, fmt=
"(T2,A,2I5)") &
1140 "K-point ADDED_MOS AUTO: growing virtual-space buffer to:", &
1141 scf_control%added_mos(1:nspins)
1143 WRITE (unit=output_unit, fmt=
"(T2,A,I0)") &
1144 "K-point ADDED_MOS AUTO: growing virtual-space buffer to: ", &
1145 scf_control%added_mos(1)
1149 ALLOCATE (old_mos(nspins))
1150 DO ispin = 1, nspins
1152 CALL get_mo_set(old_mos(ispin), maxocc=maxocc, n_el_f=n_el_f, &
1153 flexible_electron_count=flexible_electron_count)
1155 CALL allocate_mo_set(mo_set=mos(ispin), nao=old_mos(ispin)%nao, nmo=new_nmo(ispin), &
1156 nelectron=old_mos(ispin)%nelectron, n_el_f=n_el_f, maxocc=maxocc, &
1157 flexible_electron_count=flexible_electron_count)
1158 mos(ispin)%use_mo_coeff_b = old_mos(ispin)%use_mo_coeff_b
1162 CALL mpools_get(qs_env%mpools, ao_mo_fm_pools=ao_mo_fm_pools)
1164 DO ispin = 1, nspins
1165 CALL init_mo_set(mos(ispin), fm_pool=ao_mo_fm_pools(ispin)%pool, &
1167 CALL get_mo_set(mos(ispin), mo_coeff=mo_coeff, eigenvalues=eigenvalues, &
1168 occupation_numbers=occupation_numbers)
1169 CALL get_mo_set(old_mos(ispin), eigenvalues=old_eigenvalues, &
1170 occupation_numbers=old_occupation_numbers)
1172 old_nmo = old_mos(ispin)%nmo
1174 IF (has_unit_metric)
THEN
1177 CALL make_basis_sm(mo_coeff, mos(ispin)%nmo, matrix_s(1, 1)%matrix)
1180 eigenvalues(1:old_nmo) = old_eigenvalues(1:old_nmo)
1181 occupation_numbers(:) = 0.0_dp
1182 occupation_numbers(1:old_nmo) = old_occupation_numbers(1:old_nmo)
1183 IF (mos(ispin)%nmo > old_nmo)
THEN
1184 energy_step = max(scf_control%smear%electronic_temperature, 1.0e-3_dp)
1185 DO ic = old_nmo + 1, mos(ispin)%nmo
1186 eigenvalues(ic) = eigenvalues(old_nmo) + energy_step*real(ic - old_nmo, kind=
dp)
1189 mos(ispin)%homo = old_mos(ispin)%homo
1190 mos(ispin)%lfomo = old_mos(ispin)%lfomo
1191 mos(ispin)%kTS = old_mos(ispin)%kTS
1192 mos(ispin)%mu = old_mos(ispin)%mu
1193 mos(ispin)%uniform_occupation = old_mos(ispin)%uniform_occupation
1198 DO ispin = 1, nspins
1199 IF (.NOT. mos(ispin)%use_mo_coeff_b) cycle
1200 CALL get_mo_set(mos(ispin), mo_coeff=mo_coeff)
1203 n=mos(ispin)%nmo, sym=dbcsr_type_no_symmetry)
1207 IF (
ASSOCIATED(mo_derivs))
THEN
1208 DO ispin = 1,
SIZE(mo_derivs)
1209 IF (
ASSOCIATED(mo_derivs(ispin)%matrix))
CALL dbcsr_release_p(mo_derivs(ispin)%matrix)
1211 DEALLOCATE (mo_derivs)
1215 IF (qs_env%requires_mo_derivs)
THEN
1216 nmo_mat = merge(1, nspins, dft_control%restricted)
1217 ALLOCATE (mo_derivs(nmo_mat))
1218 DO ispin = 1, nmo_mat
1219 NULLIFY (mo_derivs(ispin)%matrix)
1221 CALL dbcsr_create(mo_derivs(ispin)%matrix, template=mos(ispin)%mo_coeff_b, &
1222 name=
"mo_derivs", matrix_type=dbcsr_type_no_symmetry)
1227 DO ik = 1,
SIZE(kpoints%kp_env)
1228 kp => kpoints%kp_env(ik)%kpoint_env
1229 IF (
ASSOCIATED(kp%mos))
THEN
1230 DO ispin = 1,
SIZE(kp%mos)
1244 CALL do_general_diag_kp(matrix_ks, matrix_s, kpoints, scf_env, scf_control, .false., diag_step)
1247 qs_env, update_occupations=.true., &
1248 separate_spin_occupations=dft_control%restricted, &
1249 fixed_occupations=.NOT. (dft_control%smear .OR. scf_control%smear%do_smear))
1251 IF (
ASSOCIATED(kpoints%scf_diis_buffer))
CALL qs_diis_b_clear_kp(kpoints%scf_diis_buffer)
1252 IF (
ASSOCIATED(scf_env%qs_ot_env))
THEN
1253 DO ispin = 1,
SIZE(scf_env%qs_ot_env)
1256 DEALLOCATE (scf_env%qs_ot_env)
1257 NULLIFY (scf_env%qs_ot_env)
1259 reuse_precond = .false.
1261 DO ispin = 1, nspins
1264 DEALLOCATE (old_mos)
1266 CALL timestop(handle)
1268 END SUBROUTINE qs_scf_grow_added_mos_auto_kp
1286 INTEGER,
INTENT(IN),
OPTIONAL :: kp_ot_entry_reason
1288 CHARACTER(LEN=*),
PARAMETER :: routinen =
'init_scf_loop'
1290 INTEGER :: entry_reason, handle, ikind, ispin, &
1291 nkpoint, nmo, nspin_ot
1292 INTEGER,
DIMENSION(2) :: kp_range
1293 LOGICAL :: do_adiis, do_kpoints, do_rotation, fixed_density_prepared, has_unit_metric, &
1294 kp_diis_step, kpoint_mos_initialized
1295 REAL(kind=
dp) :: u_ramping
1296 REAL(kind=
dp),
DIMENSION(:),
POINTER :: wkp
1298 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_ks, matrix_s
1299 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_ks_kp, matrix_s_kp, matrix_t_kp, &
1301 TYPE(
dbcsr_type),
POINTER :: orthogonality_metric
1305 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
1309 CALL timeset(routinen, handle)
1311 NULLIFY (scf_control, matrix_ks_kp, matrix_s, matrix_s_kp, matrix_t_kp, matrix_ks, &
1312 rho_ao_kp, dft_control, mos, mo_coeff, kpoints, qs_kind_set, rho, wkp)
1314 cpassert(
ASSOCIATED(scf_env))
1315 cpassert(
ASSOCIATED(qs_env))
1316 entry_reason = kp_ot_entry_initial
1317 IF (
PRESENT(kp_ot_entry_reason)) entry_reason = kp_ot_entry_reason
1318 fixed_density_prepared = .false.
1321 scf_control=scf_control, &
1322 dft_control=dft_control, &
1323 do_kpoints=do_kpoints, &
1327 qs_kind_set=qs_kind_set)
1331 nspin_ot = dft_control%nspins
1332 IF (dft_control%restricted) nspin_ot = 1
1333 IF (do_kpoints)
THEN
1334 CALL get_kpoint_info(kpoints, nkp=nkpoint, kp_range=kp_range, wkp=wkp)
1338 DO ispin = 1,
SIZE(mos)
1339 IF (mos(1)%use_mo_coeff_b)
THEN
1345 DO ispin = 1, dft_control%nspins
1347 IF (.NOT. scf_control%diagonalization%mom)
THEN
1350 IF (dft_control%hairy_probes .EQV. .true.)
THEN
1351 IF (scf_env%outer_scf%iter_count > 0)
THEN
1352 scf_control%smear%do_smear = .false.
1354 smear=scf_control%smear, &
1355 probe=dft_control%probe)
1358 IF (.NOT. scf_control%gce%do_gce)
THEN
1360 smear=scf_control%smear, &
1361 emit_warnings=.NOT. do_kpoints)
1364 smear=scf_control%smear, &
1365 gce=scf_control%gce, &
1366 emit_warnings=.NOT. do_kpoints)
1375 cpabort(
"ADIIS currently requires SCF%DIAGONALIZATION ALGORITHM STANDARD")
1378 cpabort(
"ADIIS is not yet compatible with CHOLESKY INVERSE_DBCSR")
1380 IF (dft_control%qs_control%dftb .OR. dft_control%qs_control%xtb .OR. &
1381 dft_control%qs_control%semi_empirical)
THEN
1382 cpabort(
"ADIIS currently requires a Quickstep DFT KS matrix")
1384 IF (dft_control%do_admm_mo)
THEN
1385 cpabort(
"ADIIS is not yet compatible with ADMM-MO")
1387 IF (dft_control%sic_method_id ==
sic_eo)
THEN
1388 cpabort(
"ADIIS is not yet compatible with explicit-orbital SIC")
1390 IF (dft_control%apply_period_efield)
THEN
1391 cpabort(
"ADIIS is not yet compatible with PERIODIC_EFIELD")
1393 IF (dft_control%dft_plus_u)
THEN
1394 cpassert(
ASSOCIATED(qs_kind_set))
1395 DO ikind = 1,
SIZE(qs_kind_set)
1396 CALL get_qs_kind(qs_kind_set(ikind), u_ramping=u_ramping)
1397 IF (u_ramping > 0.0_dp .AND. &
1398 (.NOT. do_kpoints .OR. dft_control%plus_u_method_id /=
plus_u_lowdin))
THEN
1399 cpabort(
"ADIIS is not yet compatible with DFT+U U_RAMPING")
1403 IF (dft_control%smear .OR. scf_control%smear%do_smear)
THEN
1404 cpabort(
"ADIIS finite-temperature smearing support is not implemented yet")
1406 IF (dft_control%roks .OR. scf_control%diagonalization%mom .OR. &
1407 dft_control%hairy_probes .OR. scf_control%gce%do_gce)
THEN
1408 cpabort(
"ADIIS currently supports ordinary RKS/UKS occupations only")
1410 IF (scf_control%do_diag_sub)
THEN
1411 cpabort(
"ADIIS is not yet compatible with DIAG_SUB_SCF")
1413 IF (scf_control%diagonalization%max_history < 1)
THEN
1414 cpabort(
"ADIIS requires SCF%ADIIS%MAX_HISTORY >= 1")
1416 IF (.NOT.
ASSOCIATED(scf_env%scf_subspace_buffer))
THEN
1417 ALLOCATE (scf_env%scf_subspace_buffer)
1419 scf_control%diagonalization%max_history)
1420 ELSE IF (scf_env%scf_subspace_buffer%nbuffer /= scf_control%diagonalization%max_history)
THEN
1423 scf_control%diagonalization%max_history)
1428 SELECT CASE (scf_env%method)
1431 CALL cp_abort(__location__, &
1432 "Unknown SCF method <"//trim(
cp_to_string(scf_env%method))//
"> found. Check the code!")
1436 IF (.NOT. scf_env%skip_diis)
THEN
1437 IF (.NOT.
ASSOCIATED(scf_env%scf_diis_buffer))
THEN
1438 ALLOCATE (scf_env%scf_diis_buffer)
1439 CALL qs_diis_b_create(scf_env%scf_diis_buffer, nbuffer=scf_control%max_diis)
1445 IF (.NOT. scf_env%skip_diis)
THEN
1446 IF (do_kpoints)
THEN
1447 IF (.NOT.
ASSOCIATED(kpoints%scf_diis_buffer))
THEN
1448 ALLOCATE (kpoints%scf_diis_buffer)
1453 IF (.NOT.
ASSOCIATED(scf_env%scf_diis_buffer))
THEN
1454 ALLOCATE (scf_env%scf_diis_buffer)
1455 CALL qs_diis_b_create(scf_env%scf_diis_buffer, nbuffer=scf_control%max_diis)
1462 IF (scf_control%diagonalization%ot_settings%preconditioner_type == &
1464 (dft_control%qs_control%dftb .OR. dft_control%qs_control%xtb .OR. &
1465 dft_control%qs_control%semi_empirical))
THEN
1466 CALL cp_warn(__location__, &
1467 "FULL_KINETIC is unavailable for semi-empirical DIAGONALIZATION%OT; "// &
1468 "falling back to FULL_S_INVERSE.")
1470 scf_control%diagonalization%ot_settings%preconditioner_name =
"FULL_S_INVERSE"
1472 IF (do_kpoints)
THEN
1473 IF (.NOT. scf_env%skip_diis)
THEN
1474 IF (.NOT.
ASSOCIATED(kpoints%scf_diis_buffer))
THEN
1475 ALLOCATE (kpoints%scf_diis_buffer)
1480 CALL timestop(handle)
1483 CALL get_qs_env(qs_env, matrix_ks=matrix_ks, matrix_s=matrix_s)
1485 IF (.NOT. scf_env%skip_diis)
THEN
1486 IF (.NOT.
ASSOCIATED(scf_env%scf_diis_buffer))
THEN
1487 ALLOCATE (scf_env%scf_diis_buffer)
1488 CALL qs_diis_b_create(scf_env%scf_diis_buffer, nbuffer=scf_control%max_diis)
1496 scf_control%diagonalization%ot_settings%preconditioner_type, &
1500 scf_control%diagonalization%ot_settings%preconditioner_type, &
1501 scf_control%diagonalization%ot_settings%precond_solver_type, &
1502 scf_control%diagonalization%ot_settings%energy_gap, dft_control%nspins, &
1503 chebyshev_degree=scf_control%diagonalization%ot_settings%chebyshev_degree, &
1504 low_rank_base=scf_control%diagonalization%ot_settings%low_rank_base, &
1505 fermi_low_rank_max_rank= &
1506 scf_control%diagonalization%ot_settings%fermi_low_rank_max_rank, &
1507 lattice_fft=scf_control%diagonalization%ot_settings%lattice_fft, &
1508 lattice_fft_local_cells= &
1509 scf_control%diagonalization%ot_settings%lattice_fft_local_cells)
1514 IF (do_kpoints)
THEN
1515 IF (.NOT.
ASSOCIATED(scf_env%qs_ot_env))
THEN
1516 CALL get_qs_env(qs_env, matrix_s_kp=matrix_s_kp, &
1517 kinetic_kp=matrix_t_kp)
1518 cpassert(
ASSOCIATED(matrix_s_kp))
1519 CALL allocate_qs_ot_envs(scf_env=scf_env, &
1520 scf_control=scf_control, &
1521 dft_control=dft_control, &
1522 scf_section=scf_section, &
1523 do_kpoints=do_kpoints, &
1525 nspin_ot=nspin_ot, &
1526 kp_range=kp_range, &
1531 IF (.NOT. scf_env%qs_ot_env(1)%settings%do_ener)
THEN
1535 kpoints, require_full_space=scf_env%qs_ot_env(1)%settings%do_ener)
1536 SELECT CASE (entry_reason)
1537 CASE (kp_ot_entry_initial)
1538 IF (kpoint_mos_initialized)
THEN
1539 IF (dft_control%restricted)
THEN
1543 qs_env, update_occupations=.true., &
1544 separate_spin_occupations=dft_control%restricted, &
1545 fixed_occupations=.NOT. (dft_control%smear .OR. scf_control%smear%do_smear))
1547 CASE (kp_ot_entry_reuse, kp_ot_entry_resized, kp_ot_entry_refresh)
1548 cpassert(kpoint_mos_initialized)
1550 cpabort(
"Invalid k-point OT workspace entry reason.")
1556 IF (entry_reason == kp_ot_entry_initial .AND. .NOT. kpoint_mos_initialized .AND. &
1557 .NOT. scf_env%qs_ot_env(1)%settings%do_ener)
THEN
1558 cpassert(
ASSOCIATED(rho))
1560 cpassert(
ASSOCIATED(rho_ao_kp))
1563 IF (
SIZE(rho_ao_kp, 1) < nspin_ot)
THEN
1564 cpassert(
SIZE(rho_ao_kp, 1) == 1)
1567 IF (dft_control%restricted)
THEN
1571 qs_env, update_occupations=.true., &
1572 separate_spin_occupations=dft_control%restricted, fixed_occupations=.true.)
1577 fixed_density_prepared = .true.
1583 CALL get_qs_env(qs_env, matrix_ks_kp=matrix_ks_kp)
1584 cpassert(
ASSOCIATED(matrix_ks_kp))
1588 IF ((entry_reason == kp_ot_entry_initial .AND. .NOT. kpoint_mos_initialized) .OR. &
1589 entry_reason == kp_ot_entry_refresh)
THEN
1590 kp_diis_step = .false.
1592 scf_control, .false., kp_diis_step)
1593 IF (
SIZE(matrix_ks_kp, 1) < nspin_ot)
THEN
1594 cpassert(
SIZE(matrix_ks_kp, 1) == 1)
1597 IF (dft_control%restricted)
THEN
1601 qs_env, update_occupations=.true., &
1602 separate_spin_occupations=dft_control%restricted, &
1603 fixed_occupations=.NOT. (dft_control%smear .OR. scf_control%smear%do_smear))
1608 calculate_forces=.false.)
1612 CALL get_qs_env(qs_env, matrix_ks_kp=matrix_ks_kp)
1613 cpassert(
ASSOCIATED(matrix_ks_kp))
1624 CALL allocate_qs_ot_kpoint_state(qs_env=qs_env, &
1626 dft_control=dft_control, &
1628 matrix_ks_kp=matrix_ks_kp, &
1629 matrix_s_kp=matrix_s_kp, &
1630 matrix_t_kp=matrix_t_kp, &
1634 CALL timestop(handle)
1639 has_unit_metric=has_unit_metric, &
1640 matrix_s=matrix_s, &
1641 matrix_ks=matrix_ks)
1647 IF (scf_control%do_outer_scf_reortho)
THEN
1648 IF (scf_control%outer_scf%have_scf .AND. .NOT. dft_control%restricted)
THEN
1649 IF (scf_env%outer_scf%iter_count > 0)
THEN
1650 DO ispin = 1, dft_control%nspins
1651 CALL get_mo_set(mo_set=mos(ispin), mo_coeff=mo_coeff, nmo=nmo)
1652 IF (has_unit_metric)
THEN
1664 IF (.NOT.
ASSOCIATED(scf_env%qs_ot_env))
THEN
1666 CALL allocate_qs_ot_envs(scf_env=scf_env, &
1667 scf_control=scf_control, &
1668 dft_control=dft_control, &
1669 scf_section=scf_section, &
1670 do_kpoints=do_kpoints, &
1672 nspin_ot=nspin_ot, &
1673 kp_range=kp_range, &
1676 IF (scf_env%qs_ot_env(1)%settings%preconditioner_type == &
1678 IF (.NOT. do_kpoints)
THEN
1679 DO ispin = 1,
SIZE(mos)
1680 IF (.NOT. mos(ispin)%uniform_occupation)
THEN
1681 CALL cp_abort(__location__, &
1682 'PRECONDITIONER FULL_ALL_COVARIANT currently requires uniform occupations.')
1690 calculate_forces=.false.)
1694 IF (.NOT. reuse_precond)
THEN
1696 scf_env%qs_ot_env(1)%settings%preconditioner_type, &
1704 IF (has_unit_metric)
THEN
1705 NULLIFY (orthogonality_metric)
1707 orthogonality_metric => matrix_s(1)%matrix
1710 IF (.NOT. reuse_precond)
THEN
1712 scf_env%qs_ot_env(1)%settings%preconditioner_type, &
1713 scf_env%qs_ot_env(1)%settings%precond_solver_type, &
1714 scf_env%qs_ot_env(1)%settings%energy_gap, dft_control%nspins, &
1715 has_unit_metric=has_unit_metric, &
1716 chol_type=scf_env%qs_ot_env(1)%settings%cholesky_type, &
1717 chebyshev_degree=scf_env%qs_ot_env(1)%settings%chebyshev_degree, &
1718 low_rank_base=scf_env%qs_ot_env(1)%settings%low_rank_base, &
1719 fermi_low_rank_max_rank= &
1720 scf_env%qs_ot_env(1)%settings%fermi_low_rank_max_rank, &
1721 lattice_fft=scf_env%qs_ot_env(1)%settings%lattice_fft, &
1722 lattice_fft_local_cells= &
1723 scf_env%qs_ot_env(1)%settings%lattice_fft_local_cells)
1725 IF (reuse_precond) reuse_precond = .false.
1727 CALL ot_scf_init(mo_array=mos, matrix_s=orthogonality_metric, &
1728 broyden_adaptive_sigma=qs_env%broyden_adaptive_sigma, &
1729 qs_ot_env=scf_env%qs_ot_env, matrix_ks=matrix_ks(1)%matrix)
1731 SELECT CASE (scf_env%qs_ot_env(1)%settings%preconditioner_type)
1735 DO ispin = 1,
SIZE(scf_env%qs_ot_env)
1737 scf_env%ot_preconditioner(ispin)%preconditioner)
1740 DO ispin = 1,
SIZE(scf_env%qs_ot_env)
1742 scf_env%ot_preconditioner(1)%preconditioner)
1745 DO ispin = 1,
SIZE(scf_env%qs_ot_env)
1747 scf_env%ot_preconditioner(1)%preconditioner)
1753 do_rotation = scf_env%qs_ot_env(1)%settings%do_rotation
1754 DO ispin = 1,
SIZE(mos)
1755 IF (.NOT. mos(ispin)%uniform_occupation)
THEN
1756 cpassert(do_rotation)
1762 IF (dft_control%low_spin_roks)
THEN
1764 do_rotation = scf_env%qs_ot_env(1)%settings%do_rotation
1765 cpassert(do_rotation)
1768 CALL timestop(handle)
1784 SUBROUTINE allocate_qs_ot_envs(scf_env, scf_control, dft_control, scf_section, &
1785 do_kpoints, nkpoint, nspin_ot, kp_range, wkp)
1790 LOGICAL,
INTENT(IN) :: do_kpoints
1791 INTEGER,
INTENT(IN) :: nkpoint, nspin_ot
1792 INTEGER,
DIMENSION(2),
INTENT(IN) :: kp_range
1793 REAL(kind=
dp),
DIMENSION(:),
POINTER :: wkp
1795 CHARACTER(len=*),
PARAMETER :: kpoint_precond_error = &
1796 "Complex K-point OT supports PRECONDITIONER NONE, FERMI_LOW_RANK, "// &
1797 "FULL_S_INVERSE, FULL_KINETIC, FULL_SINGLE, FULL_SINGLE_INVERSE, FULL_ALL, or "// &
1798 "FULL_ALL_COVARIANT.", kpoint_solver_error = &
1799 "Complex K-point FERMI_LOW_RANK, FULL_SINGLE, FULL_ALL, and FULL_ALL_COVARIANT "// &
1800 "support PRECOND_SOLVER DEFAULT; FULL_S_INVERSE, FULL_KINETIC, and "// &
1801 "FULL_SINGLE_INVERSE support DEFAULT or INVERSE_CHOLESKY."
1803 INTEGER :: ikpoint, ispin, local_kpoint, &
1804 number_of_ot_envs, ot_channel
1805 LOGICAL :: do_rotation, do_smear, is_full_all
1806 REAL(kind=
dp) :: kpoint_weight
1808 cpassert(.NOT.
ASSOCIATED(scf_env%qs_ot_env))
1813 restricted=dft_control%restricted)
1815 ALLOCATE (scf_env%qs_ot_env(number_of_ot_envs))
1818 IF (scf_env%outer_scf%iter_count > 0)
THEN
1819 IF (scf_env%iter_delta < scf_control%eps_diis)
THEN
1820 scf_env%qs_ot_env(1)%settings%ot_state = 1
1826 IF (dft_control%restricted .AND. .NOT. do_kpoints .AND. &
1827 scf_env%qs_ot_env(1)%settings%preconditioner_type == &
1829 cpabort(
'Gamma-point PRECONDITIONER FULL_ALL_COVARIANT does not currently support ROKS.')
1832 IF (do_kpoints)
THEN
1833 do_smear = dft_control%smear .OR. scf_control%smear%do_smear
1835 IF (.NOT. scf_env%qs_ot_env(1)%settings%do_ener)
THEN
1836 cpabort(
"K-point OT smearing requires OT%ENERGIES and OT%ROTATION.")
1838 IF (.NOT. scf_env%qs_ot_env(1)%settings%do_rotation)
THEN
1839 cpabort(
"K-point OT smearing requires OT%ROTATION.")
1841 SELECT CASE (scf_control%smear%method)
1845 cpabort(
"K-point Mermin OT does not support the selected smearing method.")
1847 IF (scf_env%qs_ot_env(1)%settings%ot_algorithm /=
"TOD" .AND. &
1848 scf_env%qs_ot_env(1)%settings%ot_algorithm /=
"REF")
THEN
1849 cpabort(
"K-point Mermin OT currently supports OT%ALGORITHM STRICT or IRAC.")
1851 IF (scf_env%qs_ot_env(1)%settings%OT_METHOD /=
"CG" .AND. &
1852 scf_env%qs_ot_env(1)%settings%OT_METHOD /=
"SD" .AND. &
1853 scf_env%qs_ot_env(1)%settings%OT_METHOD /=
"DIIS" .AND. &
1854 scf_env%qs_ot_env(1)%settings%OT_METHOD /=
"BROY" .AND. &
1855 scf_env%qs_ot_env(1)%settings%OT_METHOD /=
"LBFG")
THEN
1856 cpabort(
"K-point Mermin OT supports OT%MINIMIZER CG, SD, DIIS, BROYDEN, or LBFGS.")
1858 ELSE IF (scf_env%qs_ot_env(1)%settings%do_ener)
THEN
1859 cpabort(
"OT%ENERGIES requires smearing in the complex K-point path.")
1861 IF (scf_env%qs_ot_env(1)%settings%ot_algorithm /=
"TOD" .AND. &
1862 scf_env%qs_ot_env(1)%settings%ot_algorithm /=
"REF")
THEN
1863 cpabort(
"K-point OT currently supports OT%ALGORITHM STRICT or IRAC.")
1865 IF (scf_env%qs_ot_env(1)%settings%OT_METHOD /=
"CG" .AND. &
1866 scf_env%qs_ot_env(1)%settings%OT_METHOD /=
"SD" .AND. &
1867 scf_env%qs_ot_env(1)%settings%OT_METHOD /=
"DIIS" .AND. &
1868 scf_env%qs_ot_env(1)%settings%OT_METHOD /=
"BROY" .AND. &
1869 scf_env%qs_ot_env(1)%settings%OT_METHOD /=
"LBFG")
THEN
1870 cpabort(
"K-point OT currently supports OT%MINIMIZER CG, SD, DIIS, BROYDEN, or LBFGS.")
1873 scf_env%qs_ot_env(1)%settings%preconditioner_type, .false.))
THEN
1874 cpabort(kpoint_precond_error)
1877 (dft_control%qs_control%semi_empirical .OR. dft_control%qs_control%dftb .OR. &
1878 dft_control%qs_control%xtb))
THEN
1879 cpabort(
"FULL_KINETIC is unavailable for semi-empirical methods")
1882 scf_env%qs_ot_env(1)%settings%preconditioner_type, &
1883 scf_env%qs_ot_env(1)%settings%precond_solver_type, .false.))
THEN
1884 cpabort(kpoint_solver_error)
1886 IF (scf_env%qs_ot_env(1)%settings%occupation_preconditioner .AND. .NOT. do_smear)
THEN
1887 cpabort(
"K-point OCCUPATION_PRECONDITIONER requires smearing.")
1891 IF (scf_env%outer_scf%iter_count > 0)
THEN
1892 IF (scf_env%qs_ot_env(1)%settings%ot_state == 1)
THEN
1893 scf_control%max_scf = max(scf_env%qs_ot_env(1)%settings%max_scf_diis, &
1894 scf_control%max_scf)
1899 IF (dft_control%restricted)
THEN
1900 scf_env%qs_ot_env(:)%restricted = .true.
1902 IF (.NOT. scf_env%qs_ot_env(1)%settings%do_rotation)
THEN
1903 CALL cp_abort(__location__, &
1904 "Restricted calculation with OT requires orbital rotation. Please "// &
1905 "activate the OT%ROTATION keyword!")
1908 scf_env%qs_ot_env(:)%restricted = .false.
1913 do_rotation = scf_env%qs_ot_env(1)%settings%do_rotation
1916 IF (do_rotation .AND. is_full_all .AND. .NOT. do_kpoints)
THEN
1917 cpabort(
'PRECONDITIONER FULL_ALL is not compatible with ROTATION.')
1920 DO ikpoint = 1, nkpoint
1922 IF (do_kpoints)
THEN
1923 IF (ikpoint >= kp_range(1) .AND. ikpoint <= kp_range(2))
THEN
1924 local_kpoint = ikpoint - kp_range(1) + 1
1927 DO ispin = 1, nspin_ot
1929 IF (do_kpoints)
THEN
1930 kpoint_weight = 1.0_dp
1931 IF (
ASSOCIATED(wkp)) kpoint_weight = wkp(ikpoint)
1934 kpoint_index=ikpoint, &
1935 local_kpoint_index=local_kpoint, &
1936 kpoint_weight=kpoint_weight)
1945 restricted=dft_control%restricted, &
1946 require_kpoint=do_kpoints, &
1947 kp_range=kp_range, &
1950 END SUBROUTINE allocate_qs_ot_envs
1963 SUBROUTINE allocate_qs_ot_kpoint_state(qs_env, scf_env, dft_control, &
1964 kpoints, matrix_ks_kp, matrix_s_kp, matrix_t_kp, nspin_ot)
1969 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_ks_kp, matrix_s_kp, matrix_t_kp
1970 INTEGER,
INTENT(IN) :: nspin_ot
1972 CHARACTER(LEN=*),
PARAMETER :: routinen =
'allocate_qs_ot_kpoint_state'
1974 INTEGER :: energy_dimension, energy_spin, &
1975 energy_start, handle, ikpoint, &
1976 ikpoint_local, ispin, nao, nmo, nocc, &
1978 LOGICAL :: use_real_wfn
1979 REAL(kind=
dp),
DIMENSION(:),
POINTER :: eigenvalues
1981 TYPE(
cp_fm_type) :: active_mo_coeff, active_mo_coeff_im, &
1982 mo_coeff, mo_coeff_im
1983 TYPE(
dbcsr_type),
POINTER :: matrix_sk_im, matrix_sk_re
1987 CALL timeset(routinen, handle)
1989 NULLIFY (active_mo_struct, eigenvalues, kp, matrix_sk_im, matrix_sk_re, mo_set)
1991 cpassert(
ASSOCIATED(qs_env))
1992 cpassert(
ASSOCIATED(scf_env%qs_ot_env))
1993 cpassert(
ASSOCIATED(kpoints))
1994 cpassert(
ASSOCIATED(kpoints%kp_env))
1995 cpassert(
ASSOCIATED(matrix_ks_kp))
1996 cpassert(
ASSOCIATED(matrix_s_kp))
1997 cpassert(
ASSOCIATED(matrix_s_kp(1, 1)%matrix))
1998 cpassert(.NOT. dft_control%restricted .OR. nspin_ot == 1)
2001 cpassert(.NOT. use_real_wfn)
2003 DO ikpoint_local = 1,
SIZE(kpoints%kp_env)
2004 kp => kpoints%kp_env(ikpoint_local)%kpoint_env
2005 cpassert(
ASSOCIATED(kp))
2006 cpassert(
ASSOCIATED(kp%mos))
2007 cpassert(
ASSOCIATED(kp%ot_smat))
2008 cpassert(nspin_ot <=
SIZE(kp%mos))
2009 ikpoint = kp%nkpoint
2010 cpassert(ikpoint >= 1)
2011 cpassert(
SIZE(kp%ot_smat) >= 2)
2013 kp%ot_smat(1), kp%ot_smat(2), &
2014 matrix_sk_re, matrix_sk_im)
2015 DO ispin = 1, nspin_ot
2017 cpassert(.NOT. scf_env%qs_ot_env(ot_channel)%state_allocated)
2019 mo_set => kp%mos(ispin)
2020 CALL get_mo_set(mo_set=mo_set, eigenvalues=eigenvalues, &
2021 homo=nocc, nao=nao, nmo=nmo)
2022 cpassert(
ASSOCIATED(mo_set%cmo_coeff))
2023 cpassert(
ASSOCIATED(eigenvalues))
2026 IF (scf_env%qs_ot_env(ot_channel)%settings%do_ener) nocc = nmo
2027 IF (nocc < 1 .OR. nocc > nmo)
THEN
2028 CALL cp_abort(__location__, &
2029 "K-point OT requires at least one occupied orbital in every spin channel.")
2032 CALL cp_fm_create(mo_coeff, mo_set%cmo_coeff%matrix_struct)
2033 CALL cp_fm_create(mo_coeff_im, mo_set%cmo_coeff%matrix_struct)
2034 CALL cp_cfm_to_fm(mo_set%cmo_coeff, mo_coeff, mo_coeff_im)
2035 CALL cp_fm_struct_create(active_mo_struct, template_fmstruct=mo_set%cmo_coeff%matrix_struct, &
2040 energy_dimension = nocc
2041 IF (dft_control%restricted .AND. &
2042 scf_env%qs_ot_env(ot_channel)%settings%do_ener)
THEN
2043 energy_dimension = nocc*
SIZE(kp%mos)
2047 active_mo_struct, energy_dimension=energy_dimension)
2049 CALL dbcsr_set(scf_env%qs_ot_env(ot_channel)%matrix_c0, 0.0_dp)
2050 CALL copy_fm_to_dbcsr(active_mo_coeff, scf_env%qs_ot_env(ot_channel)%matrix_c0)
2052 CALL cp_fm_create(active_mo_coeff_im, active_mo_struct)
2053 CALL cp_fm_to_fm(mo_coeff_im, active_mo_coeff_im, nocc)
2055 CALL dbcsr_set(scf_env%qs_ot_env(ot_channel)%matrix_c0_im, 0.0_dp)
2056 CALL dbcsr_set(scf_env%qs_ot_env(ot_channel)%matrix_sc0_im, 0.0_dp)
2057 CALL copy_fm_to_dbcsr(active_mo_coeff_im, scf_env%qs_ot_env(ot_channel)%matrix_c0_im)
2059 scf_env%qs_ot_env(ot_channel)%matrix_c0, 0.0_dp, &
2060 scf_env%qs_ot_env(ot_channel)%matrix_sc0)
2062 scf_env%qs_ot_env(ot_channel)%matrix_c0_im, 0.0_dp, &
2063 scf_env%qs_ot_env(ot_channel)%matrix_x)
2064 CALL dbcsr_add(scf_env%qs_ot_env(ot_channel)%matrix_sc0, &
2065 scf_env%qs_ot_env(ot_channel)%matrix_x, &
2066 alpha_scalar=1.0_dp, beta_scalar=-1.0_dp)
2069 scf_env%qs_ot_env(ot_channel)%matrix_c0_im, 0.0_dp, &
2070 scf_env%qs_ot_env(ot_channel)%matrix_sc0_im)
2072 scf_env%qs_ot_env(ot_channel)%matrix_c0, 0.0_dp, &
2073 scf_env%qs_ot_env(ot_channel)%matrix_x)
2074 CALL dbcsr_add(scf_env%qs_ot_env(ot_channel)%matrix_sc0_im, &
2075 scf_env%qs_ot_env(ot_channel)%matrix_x, &
2076 alpha_scalar=1.0_dp, beta_scalar=1.0_dp)
2078 CALL qs_ot_init(scf_env%qs_ot_env(ot_channel))
2079 IF (scf_env%qs_ot_env(ot_channel)%settings%do_ener)
THEN
2080 IF (dft_control%restricted)
THEN
2081 DO energy_spin = 1,
SIZE(kp%mos)
2082 CALL get_mo_set(kp%mos(energy_spin), eigenvalues=eigenvalues)
2083 energy_start = (energy_spin - 1)*nocc + 1
2084 scf_env%qs_ot_env(ot_channel)%ener_x(energy_start:energy_start + nocc - 1) = &
2088 scf_env%qs_ot_env(ot_channel)%ener_x(:) = eigenvalues(1:nocc)
2091 scf_env%qs_ot_env(ot_channel)%broyden_adaptive_sigma = qs_env%broyden_adaptive_sigma
2093 CALL dbcsr_set(scf_env%qs_ot_env(ot_channel)%matrix_x, 0.0_dp)
2094 CALL dbcsr_set(scf_env%qs_ot_env(ot_channel)%matrix_sx, 0.0_dp)
2095 CALL dbcsr_set(scf_env%qs_ot_env(ot_channel)%matrix_x_im, 0.0_dp)
2096 CALL dbcsr_set(scf_env%qs_ot_env(ot_channel)%matrix_sx_im, 0.0_dp)
2098 SELECT CASE (scf_env%qs_ot_env(ot_channel)%settings%ot_algorithm)
2101 scf_env%qs_ot_env(ot_channel)%matrix_x_im, &
2102 scf_env%qs_ot_env(ot_channel)%matrix_sx, &
2103 scf_env%qs_ot_env(ot_channel)%matrix_sx_im, &
2104 scf_env%qs_ot_env(ot_channel))
2106 CALL dbcsr_copy(scf_env%qs_ot_env(ot_channel)%matrix_x, &
2107 scf_env%qs_ot_env(ot_channel)%matrix_c0)
2108 CALL dbcsr_copy(scf_env%qs_ot_env(ot_channel)%matrix_sx, &
2109 scf_env%qs_ot_env(ot_channel)%matrix_sc0)
2110 CALL dbcsr_copy(scf_env%qs_ot_env(ot_channel)%matrix_x_im, &
2111 scf_env%qs_ot_env(ot_channel)%matrix_c0_im)
2112 CALL dbcsr_copy(scf_env%qs_ot_env(ot_channel)%matrix_sx_im, &
2113 scf_env%qs_ot_env(ot_channel)%matrix_sc0_im)
2115 scf_env%qs_ot_env(ot_channel)%matrix_c0_im, &
2116 matrix_sk_re, matrix_sk_im, &
2117 scf_env%qs_ot_env(ot_channel))
2119 cpabort(
"Algorithm not yet implemented")
2122 cpassert(scf_env%qs_ot_env(ot_channel)%state_allocated)
2123 cpassert(scf_env%qs_ot_env(ot_channel)%has_complex_kpoint_state)
2135 nkpoint=kpoints%nkp, &
2136 restricted=any(scf_env%qs_ot_env(:)%restricted), &
2137 require_kpoint=.true., &
2138 kp_range=kpoints%kp_range, &
2139 require_local_state=.true., &
2140 require_complex_state=.true.)
2142 CALL prepare_qs_ot_kpoint_preconditioners(scf_env, kpoints, matrix_ks_kp, &
2143 matrix_s_kp, matrix_t_kp, nspin_ot)
2145 CALL timestop(handle)
2147 END SUBROUTINE allocate_qs_ot_kpoint_state
2158 SUBROUTINE prepare_qs_ot_kpoint_preconditioners(scf_env, kpoints, matrix_ks, matrix_s, matrix_t, nspin_ot)
2161 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: matrix_ks, matrix_s, matrix_t
2162 INTEGER,
INTENT(IN) :: nspin_ot
2164 CHARACTER(LEN=*),
PARAMETER :: routinen =
'prepare_qs_ot_kpoint_preconditioners'
2166 INTEGER :: handle, ikpoint, ispin, ks_spin, local_kpoint, n_ot_channels, nocc, &
2167 occupation_spin, ot_channel, prec_type, source_channel
2168 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: occupation_signature
2169 REAL(kind=
dp),
DIMENSION(:),
POINTER :: occupation_numbers
2170 TYPE(
dbcsr_type),
POINTER :: matrix_h_im, matrix_h_re, matrix_s_im, &
2171 matrix_s_re, matrix_t_im, matrix_t_re
2174 CALL timeset(routinen, handle)
2176 NULLIFY (kp, matrix_h_im, matrix_h_re, matrix_s_im, matrix_s_re, matrix_t_im, matrix_t_re, &
2178 cpassert(
ASSOCIATED(scf_env%qs_ot_env))
2179 cpassert(
ASSOCIATED(kpoints))
2180 cpassert(
ASSOCIATED(matrix_ks))
2181 cpassert(
ASSOCIATED(matrix_s))
2183 prec_type = scf_env%qs_ot_env(1)%settings%preconditioner_type
2185 CALL timestop(handle)
2188 SELECT CASE (prec_type)
2193 cpabort(
"Unsupported complex K-point OT preconditioner")
2195 n_ot_channels =
SIZE(scf_env%qs_ot_env)
2196 IF (
ASSOCIATED(scf_env%ot_preconditioner))
THEN
2197 DO ot_channel = 1,
SIZE(scf_env%ot_preconditioner)
2198 IF (
ASSOCIATED(scf_env%ot_preconditioner(ot_channel)%preconditioner))
THEN
2200 DEALLOCATE (scf_env%ot_preconditioner(ot_channel)%preconditioner)
2203 DEALLOCATE (scf_env%ot_preconditioner)
2204 NULLIFY (scf_env%ot_preconditioner)
2206 ALLOCATE (scf_env%ot_preconditioner(n_ot_channels))
2207 DO local_kpoint = 1,
SIZE(kpoints%kp_env)
2208 kp => kpoints%kp_env(local_kpoint)%kpoint_env
2209 ikpoint = kp%nkpoint
2210 DO ispin = 1, nspin_ot
2212 cpassert(scf_env%qs_ot_env(ot_channel)%state_allocated)
2213 ALLOCATE (scf_env%ot_preconditioner(ot_channel)%preconditioner)
2215 para_env=scf_env%qs_ot_env(ot_channel)%para_env, &
2216 blacs_env=scf_env%qs_ot_env(ot_channel)%blacs_env)
2220 DO local_kpoint = 1,
SIZE(kpoints%kp_env)
2221 kp => kpoints%kp_env(local_kpoint)%kpoint_env
2222 cpassert(
ASSOCIATED(kp))
2223 cpassert(
ASSOCIATED(kp%ot_hmat))
2224 cpassert(
ASSOCIATED(kp%ot_smat))
2225 cpassert(
SIZE(kp%ot_smat) >= 2)
2226 ikpoint = kp%nkpoint
2228 kp%ot_smat(1), kp%ot_smat(2), &
2229 matrix_s_re, matrix_s_im)
2231 cpassert(
ASSOCIATED(matrix_t))
2232 cpassert(
ASSOCIATED(kp%ot_tmat))
2233 cpassert(
SIZE(kp%ot_tmat) >= 2)
2235 kp%ot_tmat(1), kp%ot_tmat(2), &
2236 matrix_t_re, matrix_t_im)
2238 DO ispin = 1, nspin_ot
2240 IF (ispin > 1 .AND. &
2243 IF (.NOT. (
ASSOCIATED(scf_env%ot_preconditioner(source_channel)%preconditioner%complex_fm)))
THEN
2244 CALL cp_abort(__location__,
"Missing shared complex OT preconditioner")
2246 scf_env%ot_preconditioner(ot_channel)%preconditioner%complex_fm => &
2247 scf_env%ot_preconditioner(source_channel)%preconditioner%complex_fm
2248 scf_env%ot_preconditioner(ot_channel)%preconditioner%owns_complex_fm = .false.
2249 scf_env%ot_preconditioner(ot_channel)%preconditioner%energy_gap = &
2250 scf_env%ot_preconditioner(source_channel)%preconditioner%energy_gap
2251 scf_env%ot_preconditioner(ot_channel)%preconditioner%in_use = &
2252 scf_env%ot_preconditioner(source_channel)%preconditioner%in_use
2253 scf_env%ot_preconditioner(ot_channel)%preconditioner%solver = &
2254 scf_env%ot_preconditioner(source_channel)%preconditioner%solver
2256 scf_env%ot_preconditioner(ot_channel)%preconditioner)
2264 ks_spin = min(ispin,
SIZE(kp%ot_hmat, 2))
2265 cpassert(
SIZE(kp%ot_hmat, 1) >= 2)
2266 IF (
ALLOCATED(kpoints%lowdin_v))
THEN
2274 CALL cp_fm_to_cfm(kp%ot_hmat(1, ks_spin), kp%ot_hmat(2, ks_spin), h)
2289 kp%ot_hmat(1, ks_spin), kp%ot_hmat(2, ks_spin), &
2290 matrix_h_re, matrix_h_im)
2293 SELECT CASE (prec_type)
2296 scf_env%ot_preconditioner(ot_channel)%preconditioner, &
2297 scf_env%qs_ot_env(ot_channel)%matrix_c0, &
2298 scf_env%qs_ot_env(ot_channel)%matrix_c0_im, &
2299 matrix_h_re, matrix_h_im, matrix_s_re, matrix_s_im, &
2300 scf_env%qs_ot_env(ot_channel)%settings%energy_gap, &
2301 scf_env%qs_ot_env(ot_channel)%settings%fermi_low_rank_max_rank, &
2302 scf_env%qs_ot_env(ot_channel)%settings%precond_solver_type)
2305 scf_env%ot_preconditioner(ot_channel)%preconditioner, &
2306 scf_env%qs_ot_env(ot_channel)%matrix_c0, &
2307 scf_env%qs_ot_env(ot_channel)%matrix_c0_im, &
2308 matrix_h_re, matrix_h_im, matrix_s_re, matrix_s_im, &
2310 scf_env%qs_ot_env(ot_channel)%settings%energy_gap, &
2311 scf_env%qs_ot_env(ot_channel)%settings%precond_solver_type)
2314 scf_env%ot_preconditioner(ot_channel)%preconditioner, &
2315 matrix_h_re, matrix_h_im, matrix_s_re, matrix_s_im, &
2317 scf_env%qs_ot_env(ot_channel)%settings%energy_gap, &
2318 scf_env%qs_ot_env(ot_channel)%settings%precond_solver_type)
2320 IF (nspin_ot == 1 .AND.
SIZE(kp%mos) > 1)
THEN
2322 nfullcols_total=nocc)
2323 ALLOCATE (occupation_signature(nocc,
SIZE(kp%mos)))
2324 DO occupation_spin = 1,
SIZE(kp%mos)
2326 occupation_numbers=occupation_numbers)
2327 cpassert(
ASSOCIATED(occupation_numbers))
2328 cpassert(
SIZE(occupation_numbers) >= nocc)
2329 occupation_signature(:, occupation_spin) = occupation_numbers(1:nocc)
2332 scf_env%ot_preconditioner(ot_channel)%preconditioner, &
2333 scf_env%qs_ot_env(ot_channel)%matrix_c0, &
2334 scf_env%qs_ot_env(ot_channel)%matrix_c0_im, &
2335 matrix_h_re, matrix_h_im, matrix_s_re, matrix_s_im, &
2336 scf_env%qs_ot_env(ot_channel)%settings%energy_gap, &
2337 scf_env%qs_ot_env(ot_channel)%settings%precond_solver_type, &
2338 occupation_signature)
2339 DEALLOCATE (occupation_signature)
2342 scf_env%ot_preconditioner(ot_channel)%preconditioner, &
2343 scf_env%qs_ot_env(ot_channel)%matrix_c0, &
2344 scf_env%qs_ot_env(ot_channel)%matrix_c0_im, &
2345 matrix_h_re, matrix_h_im, matrix_s_re, matrix_s_im, &
2346 scf_env%qs_ot_env(ot_channel)%settings%energy_gap, &
2347 scf_env%qs_ot_env(ot_channel)%settings%precond_solver_type)
2351 scf_env%ot_preconditioner(ot_channel)%preconditioner, &
2352 scf_env%qs_ot_env(ot_channel)%matrix_c0, &
2353 scf_env%qs_ot_env(ot_channel)%matrix_c0_im, &
2354 matrix_h_re, matrix_h_im, matrix_s_re, matrix_s_im, &
2355 scf_env%qs_ot_env(ot_channel)%settings%energy_gap, &
2356 scf_env%qs_ot_env(ot_channel)%settings%precond_solver_type)
2359 scf_env%ot_preconditioner(ot_channel)%preconditioner, &
2360 matrix_t_re, matrix_t_im, matrix_s_re, matrix_s_im, &
2361 scf_env%qs_ot_env(ot_channel)%settings%energy_gap, &
2362 scf_env%qs_ot_env(ot_channel)%settings%precond_solver_type)
2365 scf_env%ot_preconditioner(ot_channel)%preconditioner, &
2366 matrix_s_re, matrix_s_im, &
2367 scf_env%qs_ot_env(ot_channel)%settings%precond_solver_type)
2370 scf_env%ot_preconditioner(ot_channel)%preconditioner)
2380 CALL timestop(handle)
2382 END SUBROUTINE prepare_qs_ot_kpoint_preconditioners
2393 TYPE(qs_scf_env_type),
INTENT(INOUT) :: scf_env
2395 CHARACTER(len=*),
PARAMETER :: routinen =
'scf_env_cleanup'
2399 CALL timeset(routinen, handle)
2402 CALL cp_fm_release(scf_env%scf_work1)
2404 IF (
ASSOCIATED(scf_env%scf_work1_red))
THEN
2405 CALL cp_fm_release(scf_env%scf_work1_red)
2407 IF (
ASSOCIATED(scf_env%scf_work2))
THEN
2408 CALL cp_fm_release(scf_env%scf_work2)
2409 DEALLOCATE (scf_env%scf_work2)
2410 NULLIFY (scf_env%scf_work2)
2412 IF (
ASSOCIATED(scf_env%scf_work2_red))
THEN
2413 CALL cp_fm_release(scf_env%scf_work2_red)
2414 DEALLOCATE (scf_env%scf_work2_red)
2415 NULLIFY (scf_env%scf_work2_red)
2417 IF (
ASSOCIATED(scf_env%ortho))
THEN
2418 CALL cp_fm_release(scf_env%ortho)
2419 DEALLOCATE (scf_env%ortho)
2420 NULLIFY (scf_env%ortho)
2422 IF (
ASSOCIATED(scf_env%ortho_red))
THEN
2423 CALL cp_fm_release(scf_env%ortho_red)
2424 DEALLOCATE (scf_env%ortho_red)
2425 NULLIFY (scf_env%ortho_red)
2427 IF (
ASSOCIATED(scf_env%ortho_m1))
THEN
2428 CALL cp_fm_release(scf_env%ortho_m1)
2429 DEALLOCATE (scf_env%ortho_m1)
2430 NULLIFY (scf_env%ortho_m1)
2432 IF (
ASSOCIATED(scf_env%ortho_m1_red))
THEN
2433 CALL cp_fm_release(scf_env%ortho_m1_red)
2434 DEALLOCATE (scf_env%ortho_m1_red)
2435 NULLIFY (scf_env%ortho_m1_red)
2438 IF (
ASSOCIATED(scf_env%ortho_dbcsr))
THEN
2439 CALL dbcsr_deallocate_matrix(scf_env%ortho_dbcsr)
2441 IF (
ASSOCIATED(scf_env%buf1_dbcsr))
THEN
2442 CALL dbcsr_deallocate_matrix(scf_env%buf1_dbcsr)
2444 IF (
ASSOCIATED(scf_env%buf2_dbcsr))
THEN
2445 CALL dbcsr_deallocate_matrix(scf_env%buf2_dbcsr)
2448 IF (
ASSOCIATED(scf_env%p_mix_new))
THEN
2449 CALL dbcsr_deallocate_matrix_set(scf_env%p_mix_new)
2452 IF (
ASSOCIATED(scf_env%p_delta))
THEN
2453 CALL dbcsr_deallocate_matrix_set(scf_env%p_delta)
2457 SELECT CASE (scf_env%method)
2460 CASE (ot_diag_method_nr)
2462 CASE (general_diag_method_nr)
2464 CASE (special_diag_method_nr)
2466 CASE (block_krylov_diag_method_nr)
2467 CASE (block_davidson_diag_method_nr)
2468 CALL block_davidson_deallocate(scf_env%block_davidson_env)
2469 CASE (filter_matrix_diag_method_nr)
2471 CASE (smeagol_method_nr)
2474 cpabort(
"unknown scf method method:"//cp_to_string(scf_env%method))
2477 IF (
ASSOCIATED(scf_env%outer_scf%variables))
THEN
2478 DEALLOCATE (scf_env%outer_scf%variables)
2480 IF (
ASSOCIATED(scf_env%outer_scf%count))
THEN
2481 DEALLOCATE (scf_env%outer_scf%count)
2483 IF (
ASSOCIATED(scf_env%outer_scf%gradient))
THEN
2484 DEALLOCATE (scf_env%outer_scf%gradient)
2486 IF (
ASSOCIATED(scf_env%outer_scf%energy))
THEN
2487 DEALLOCATE (scf_env%outer_scf%energy)
2489 IF (
ASSOCIATED(scf_env%outer_scf%inv_jacobian) .AND. &
2490 scf_env%outer_scf%deallocate_jacobian)
THEN
2491 DEALLOCATE (scf_env%outer_scf%inv_jacobian)
2494 CALL timestop(handle)
2508 SUBROUTINE cdft_scf(qs_env, should_stop, has_converged, total_scf_steps)
2509 TYPE(qs_environment_type),
POINTER :: qs_env
2510 LOGICAL,
INTENT(OUT) :: should_stop, has_converged
2511 INTEGER,
INTENT(OUT) :: total_scf_steps
2513 CHARACTER(len=*),
PARAMETER :: routinen =
'cdft_scf'
2515 INTEGER :: handle, iatom, iimage, ispin, ivar, nmo, &
2516 nvar, output_unit, tsteps
2517 LOGICAL :: cdft_loop_converged, converged, &
2518 exit_cdft_loop, first_iteration, &
2519 my_uocc, uniform_occupation
2520 REAL(kind=dp),
ALLOCATABLE,
DIMENSION(:) :: gapw_cdft_values
2521 REAL(kind=dp),
DIMENSION(:),
POINTER :: mo_occupations
2522 TYPE(atomic_kind_type),
DIMENSION(:),
POINTER :: atomic_kind_set
2523 TYPE(cdft_control_type),
POINTER :: cdft_control
2524 TYPE(cp_logger_type),
POINTER :: logger
2525 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: gapw_wmat, matrix_s, rho_ao
2526 TYPE(dft_control_type),
POINTER :: dft_control
2527 TYPE(local_rho_type),
POINTER :: gapw_operator_rho
2528 TYPE(mo_set_type),
DIMENSION(:),
POINTER :: mos
2529 TYPE(mp_para_env_type),
POINTER :: para_env
2530 TYPE(pw_env_type),
POINTER :: pw_env
2531 TYPE(pw_pool_type),
POINTER :: auxbas_pw_pool
2532 TYPE(qs_energy_type),
POINTER :: energy
2533 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
2534 TYPE(qs_ks_env_type),
POINTER :: ks_env
2535 TYPE(qs_rho_type),
POINTER :: rho
2536 TYPE(qs_scf_env_type),
POINTER :: scf_env
2537 TYPE(scf_control_type),
POINTER :: scf_control
2538 TYPE(section_vals_type),
POINTER :: dft_section, input, scf_section
2540 NULLIFY (atomic_kind_set, gapw_operator_rho, gapw_wmat, para_env, qs_kind_set, &
2541 scf_env, ks_env, energy, rho, matrix_s, rho_ao, cdft_control, logger, &
2542 dft_control, pw_env, auxbas_pw_pool, energy, ks_env, scf_env, dft_section, &
2543 input, scf_section, scf_control, mos, mo_occupations)
2544 logger => cp_get_default_logger()
2546 cpassert(
ASSOCIATED(qs_env))
2547 CALL get_qs_env(qs_env, scf_env=scf_env, energy=energy, &
2548 dft_control=dft_control, scf_control=scf_control, &
2549 ks_env=ks_env, input=input)
2551 CALL timeset(routinen//
"_loop", handle)
2552 dft_section => section_vals_get_subs_vals(input,
"DFT")
2553 scf_section => section_vals_get_subs_vals(dft_section,
"SCF")
2554 output_unit = cp_print_key_unit_nr(logger, scf_section,
"PRINT%PROGRAM_RUN_INFO", &
2555 extension=
".scfLog")
2556 first_iteration = .true.
2558 cdft_control => dft_control%qs_control%cdft_control
2560 scf_env%outer_scf%iter_count = 0
2561 cdft_control%total_steps = 0
2565 IF (output_unit > 0)
THEN
2566 WRITE (unit=output_unit, fmt=
"(/,/,T2,A)") &
2567 "CDFT EXTERNAL SCF WAVEFUNCTION OPTIMIZATION"
2568 CALL qs_scf_cdft_initial_info(output_unit, cdft_control)
2570 IF (cdft_control%reuse_precond)
THEN
2571 reuse_precond = .false.
2572 cdft_control%nreused = 0
2576 CALL outer_loop_switch(scf_env, scf_control, cdft_control, cdft2ot)
2578 CALL scf_env_do_scf(scf_env=scf_env, scf_control=scf_control, qs_env=qs_env, &
2579 converged=converged, should_stop=should_stop, total_scf_steps=tsteps)
2580 total_scf_steps = total_scf_steps + tsteps
2582 IF (cdft_control%reuse_precond)
THEN
2586 IF (scf_env%outer_scf%iter_count == 1 .AND. scf_env%iter_count == 1 &
2587 .AND. cdft_control%total_steps /= 1)
THEN
2588 cdft_control%nreused = cdft_control%nreused - 1
2591 IF (scf_env%outer_scf%iter_count == 1 .AND. scf_env%iter_count <= cdft_control%precond_freq .AND. &
2592 cdft_control%total_steps /= 1 .AND. cdft_control%nreused < cdft_control%max_reuse)
THEN
2593 reuse_precond = .true.
2594 cdft_control%nreused = cdft_control%nreused + 1
2596 reuse_precond = .false.
2597 cdft_control%nreused = 0
2601 IF (first_iteration .AND. cdft_control%purge_history)
THEN
2602 cdft_control%istep = cdft_control%istep + 1
2603 IF (scf_env%outer_scf%iter_count > 1)
THEN
2604 cdft_control%nbad_conv = cdft_control%nbad_conv + 1
2605 IF (cdft_control%nbad_conv >= cdft_control%purge_freq .AND. &
2606 cdft_control%istep >= cdft_control%purge_offset)
THEN
2607 cdft_control%nbad_conv = 0
2608 cdft_control%istep = 0
2609 cdft_control%should_purge = .true.
2613 first_iteration = .false.
2615 CALL outer_loop_switch(scf_env, scf_control, cdft_control, ot2cdft)
2616 CALL qs_scf_check_outer_exit(qs_env, scf_env, scf_control, should_stop, &
2617 cdft_loop_converged, exit_cdft_loop)
2618 CALL qs_scf_cdft_info(output_unit, scf_control, scf_env, cdft_control, &
2619 energy, cdft_control%total_steps, &
2620 should_stop, cdft_loop_converged, cdft_loop=.true.)
2621 IF (exit_cdft_loop)
EXIT cdft_outer_loop
2623 CALL qs_calculate_inverse_jacobian(qs_env)
2625 CALL qs_cdft_line_search(qs_env)
2627 CALL outer_loop_optimize(scf_env, scf_control)
2628 CALL outer_loop_update_qs_env(qs_env, scf_env)
2629 CALL qs_ks_did_change(ks_env, potential_changed=.true.)
2630 END DO cdft_outer_loop
2632 has_converged = converged .AND. cdft_loop_converged
2633 cdft_control%ienergy = cdft_control%ienergy + 1
2636 IF (cdft_control%do_et)
THEN
2637 CALL get_qs_env(qs_env=qs_env, matrix_s=matrix_s, mos=mos)
2638 nvar =
SIZE(cdft_control%target)
2639 IF (dft_control%qs_control%gapw)
THEN
2640 IF (dft_control%nimages /= 1)
THEN
2641 CALL cp_abort(__location__, &
2642 "GAPW CDFT-CI currently requires a Gamma-point calculation.")
2644 CALL get_qs_env(qs_env, atomic_kind_set=atomic_kind_set, para_env=para_env, &
2645 qs_kind_set=qs_kind_set, rho=rho)
2646 CALL qs_rho_get(rho, rho_ao=rho_ao)
2647 CALL local_rho_set_create(gapw_operator_rho)
2648 CALL allocate_rho_atom_internals(gapw_operator_rho%rho_atom_set, atomic_kind_set, &
2649 qs_kind_set, dft_control, para_env)
2650 ALLOCATE (gapw_cdft_values(nvar), gapw_wmat(dft_control%nspins*dft_control%nimages))
2651 DO iimage = 1, dft_control%nimages
2652 DO ispin = 1, dft_control%nspins
2653 CALL dbcsr_init_p(gapw_wmat(dft_control%nspins*(iimage - 1) + ispin)%matrix)
2654 CALL dbcsr_copy(gapw_wmat(dft_control%nspins*(iimage - 1) + ispin)%matrix, &
2655 matrix_s(iimage)%matrix, name=
"GAPW CDFT WEIGHT MATRIX")
2660 ALLOCATE (cdft_control%wmat(nvar))
2662 CALL dbcsr_init_p(cdft_control%wmat(ivar)%matrix)
2663 CALL dbcsr_copy(cdft_control%wmat(ivar)%matrix, matrix_s(1)%matrix, &
2664 name=
"ET_RESTRAINT_MATRIX")
2665 CALL dbcsr_set(cdft_control%wmat(ivar)%matrix, 0.0_dp)
2666 CALL integrate_v_rspace(cdft_control%group(ivar)%weight, &
2667 hmat=cdft_control%wmat(ivar), qs_env=qs_env, &
2668 calculate_forces=.false., &
2669 gapw=dft_control%qs_control%gapw)
2670 IF (dft_control%qs_control%gapw)
THEN
2671 DO ispin = 1,
SIZE(gapw_wmat)
2672 CALL dbcsr_set(gapw_wmat(ispin)%matrix, 0.0_dp)
2674 CALL zero_rho_atom_integrals(gapw_operator_rho%rho_atom_set)
2675 CALL gapw_cdft_one_center(qs_env, energy_only=.false., calculate_forces=.false., &
2676 values=gapw_cdft_values, operator_group=ivar, &
2677 rho_atom_operator_set=gapw_operator_rho%rho_atom_set)
2678 CALL update_ks_atom(qs_env, gapw_wmat, rho_ao, forces=.false., &
2679 rho_atom_external=gapw_operator_rho%rho_atom_set)
2680 CALL dbcsr_add(cdft_control%wmat(ivar)%matrix, gapw_wmat(1)%matrix, 1.0_dp, 1.0_dp)
2683 IF (dft_control%qs_control%gapw)
THEN
2684 CALL dbcsr_deallocate_matrix_set(gapw_wmat)
2685 CALL local_rho_set_release(gapw_operator_rho)
2686 DEALLOCATE (gapw_cdft_values)
2689 CALL dbcsr_init_p(cdft_control%matrix_s%matrix)
2690 CALL dbcsr_copy(cdft_control%matrix_s%matrix, matrix_s(1)%matrix, &
2693 NULLIFY (cdft_control%mo_coeff)
2694 ALLOCATE (cdft_control%mo_coeff(dft_control%nspins))
2695 DO ispin = 1, dft_control%nspins
2696 CALL cp_fm_create(matrix=cdft_control%mo_coeff(ispin), &
2697 matrix_struct=qs_env%mos(ispin)%mo_coeff%matrix_struct, &
2698 name=
"MO_COEFF_A"//trim(adjustl(cp_to_string(ispin)))//
"MATRIX")
2699 CALL cp_fm_to_fm(qs_env%mos(ispin)%mo_coeff, &
2700 cdft_control%mo_coeff(ispin))
2703 IF (cdft_control%calculate_metric)
THEN
2704 CALL get_qs_env(qs_env, rho=rho)
2705 CALL qs_rho_get(rho, rho_ao=rho_ao)
2706 ALLOCATE (cdft_control%matrix_p(dft_control%nspins))
2707 DO ispin = 1, dft_control%nspins
2708 NULLIFY (cdft_control%matrix_p(ispin)%matrix)
2709 CALL dbcsr_init_p(cdft_control%matrix_p(ispin)%matrix)
2710 CALL dbcsr_copy(cdft_control%matrix_p(ispin)%matrix, rho_ao(ispin)%matrix, &
2711 name=
"DENSITY MATRIX")
2715 uniform_occupation = .true.
2716 DO ispin = 1, dft_control%nspins
2717 CALL get_mo_set(mo_set=mos(ispin), uniform_occupation=my_uocc)
2718 uniform_occupation = uniform_occupation .AND. my_uocc
2720 IF (.NOT. uniform_occupation)
THEN
2721 ALLOCATE (cdft_control%occupations(dft_control%nspins))
2722 DO ispin = 1, dft_control%nspins
2723 CALL get_mo_set(mo_set=mos(ispin), &
2725 occupation_numbers=mo_occupations)
2726 ALLOCATE (cdft_control%occupations(ispin)%array(nmo))
2727 cdft_control%occupations(ispin)%array(1:nmo) = mo_occupations(1:nmo)
2735 IF (.NOT. (cdft_control%save_pot .OR. cdft_control%transfer_pot))
THEN
2736 CALL get_qs_env(qs_env, pw_env=pw_env)
2737 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
2738 DO iatom = 1,
SIZE(cdft_control%group)
2739 CALL auxbas_pw_pool%give_back_pw(cdft_control%group(iatom)%weight)
2740 DEALLOCATE (cdft_control%group(iatom)%weight)
2742 IF (cdft_control%atomic_charges)
THEN
2743 DO iatom = 1, cdft_control%natoms
2744 CALL auxbas_pw_pool%give_back_pw(cdft_control%charge(iatom))
2746 DEALLOCATE (cdft_control%charge)
2748 IF (cdft_control%type == outer_scf_becke_constraint .AND. &
2749 cdft_control%becke_control%cavity_confine)
THEN
2750 IF (.NOT.
ASSOCIATED(cdft_control%becke_control%cavity_mat))
THEN
2751 CALL auxbas_pw_pool%give_back_pw(cdft_control%becke_control%cavity)
2753 DEALLOCATE (cdft_control%becke_control%cavity_mat)
2755 ELSE IF (cdft_control%type == outer_scf_hirshfeld_constraint)
THEN
2756 IF (
ASSOCIATED(cdft_control%hirshfeld_control%hirshfeld_env%fnorm))
THEN
2757 CALL auxbas_pw_pool%give_back_pw(cdft_control%hirshfeld_control%hirshfeld_env%fnorm)
2760 IF (
ASSOCIATED(cdft_control%charges_fragment))
DEALLOCATE (cdft_control%charges_fragment)
2761 cdft_control%need_pot = .true.
2762 cdft_control%external_control = .false.
2765 CALL timestop(handle)
2776 SUBROUTINE cdft_control_cleanup(cdft_control)
2777 TYPE(cdft_control_type),
POINTER :: cdft_control
2779 IF (
ASSOCIATED(cdft_control%constraint%variables))
THEN
2780 DEALLOCATE (cdft_control%constraint%variables)
2782 IF (
ASSOCIATED(cdft_control%constraint%count))
THEN
2783 DEALLOCATE (cdft_control%constraint%count)
2785 IF (
ASSOCIATED(cdft_control%constraint%gradient))
THEN
2786 DEALLOCATE (cdft_control%constraint%gradient)
2788 IF (
ASSOCIATED(cdft_control%constraint%energy))
THEN
2789 DEALLOCATE (cdft_control%constraint%energy)
2791 IF (
ASSOCIATED(cdft_control%constraint%inv_jacobian) .AND. &
2792 cdft_control%constraint%deallocate_jacobian)
THEN
2793 DEALLOCATE (cdft_control%constraint%inv_jacobian)
2796 END SUBROUTINE cdft_control_cleanup
2804 SUBROUTINE qs_calculate_inverse_jacobian(qs_env)
2805 TYPE(qs_environment_type),
POINTER :: qs_env
2807 CHARACTER(LEN=*),
PARAMETER :: routinen =
'qs_calculate_inverse_jacobian'
2809 CHARACTER(len=default_path_length) :: project_name
2810 INTEGER :: counter, handle, i, ispin, iter_count, &
2811 iwork, j, max_scf, nspins, nsteps, &
2812 nvar, nwork, output_unit, pwork, &
2814 LOGICAL :: converged, explicit_jacobian, &
2815 should_build, should_stop, &
2817 REAL(kind=dp) :: inv_error, step_size
2818 REAL(kind=dp),
ALLOCATABLE,
DIMENSION(:) :: coeff, dh, step_multiplier
2819 REAL(kind=dp),
ALLOCATABLE,
DIMENSION(:, :) :: jacobian
2820 REAL(kind=dp),
DIMENSION(:),
POINTER :: energy
2821 REAL(kind=dp),
DIMENSION(:, :),
POINTER :: gradient, inv_jacobian
2822 TYPE(cdft_control_type),
POINTER :: cdft_control
2823 TYPE(cp_logger_type),
POINTER :: logger, tmp_logger
2824 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: p_rmpv
2825 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: rho_ao_kp
2826 TYPE(dft_control_type),
POINTER :: dft_control
2827 TYPE(mo_set_type),
ALLOCATABLE,
DIMENSION(:) :: mos_stashed
2828 TYPE(mo_set_type),
DIMENSION(:),
POINTER :: mos
2829 TYPE(mp_para_env_type),
POINTER :: para_env
2830 TYPE(qs_energy_type),
POINTER :: energy_qs
2831 TYPE(qs_ks_env_type),
POINTER :: ks_env
2832 TYPE(qs_rho_type),
POINTER :: rho
2833 TYPE(qs_scf_env_type),
POINTER :: scf_env
2834 TYPE(scf_control_type),
POINTER :: scf_control
2836 NULLIFY (energy, gradient, p_rmpv, rho_ao_kp, mos, rho, &
2837 ks_env, scf_env, scf_control, dft_control, cdft_control, &
2838 inv_jacobian, para_env, tmp_logger, energy_qs)
2839 logger => cp_get_default_logger()
2841 cpassert(
ASSOCIATED(qs_env))
2842 CALL get_qs_env(qs_env, scf_env=scf_env, ks_env=ks_env, &
2843 scf_control=scf_control, mos=mos, rho=rho, &
2844 dft_control=dft_control, &
2845 para_env=para_env, energy=energy_qs)
2846 explicit_jacobian = .false.
2847 should_build = .false.
2848 use_md_history = .false.
2849 iter_count = scf_env%outer_scf%iter_count
2851 IF (.NOT.
ASSOCIATED(scf_control%outer_scf%cdft_opt_control))
RETURN
2853 CALL timeset(routinen, handle)
2854 CALL initialize_inverse_jacobian(scf_control, scf_env, explicit_jacobian, should_build, used_history)
2855 IF (scf_control%outer_scf%cdft_opt_control%jacobian_restart)
THEN
2857 should_build = .false.
2858 CALL restart_inverse_jacobian(qs_env)
2860 IF (should_build)
THEN
2861 scf_env%outer_scf%deallocate_jacobian = .false.
2863 IF (explicit_jacobian)
THEN
2865 cdft_control => dft_control%qs_control%cdft_control
2866 IF (.NOT.
ASSOCIATED(cdft_control))
THEN
2867 CALL cp_abort(__location__, &
2868 "Optimizers that need the explicit Jacobian can"// &
2869 " only be used together with a valid CDFT constraint.")
2872 project_name = logger%iter_info%project_name
2873 CALL create_tmp_logger(para_env, project_name,
"-JacobianInfo.out", output_unit, tmp_logger)
2875 nspins = dft_control%nspins
2876 ALLOCATE (mos_stashed(nspins))
2877 DO ispin = 1, nspins
2878 CALL duplicate_mo_set(mos_stashed(ispin), mos(ispin))
2880 CALL qs_rho_get(rho, rho_ao_kp=rho_ao_kp)
2881 p_rmpv => rho_ao_kp(:, 1)
2883 nvar =
SIZE(scf_env%outer_scf%variables, 1)
2884 max_scf = scf_control%outer_scf%max_scf + 1
2885 ALLOCATE (gradient(nvar, max_scf))
2886 gradient = scf_env%outer_scf%gradient
2887 ALLOCATE (energy(max_scf))
2888 energy = scf_env%outer_scf%energy
2889 ALLOCATE (jacobian(nvar, nvar))
2891 nsteps = cdft_control%total_steps
2893 CALL prepare_jacobian_stencil(qs_env, output_unit, nwork, pwork, coeff, step_multiplier, dh)
2894 twork = pwork - nwork
2896 jacobian(i, :) = coeff(0)*scf_env%outer_scf%gradient(i, iter_count)
2899 CALL cp_add_default_logger(tmp_logger)
2901 IF (output_unit > 0)
THEN
2902 WRITE (output_unit, fmt=
"(A)")
" "
2903 WRITE (output_unit, fmt=
"(A)")
" #####################################"
2904 WRITE (output_unit,
'(A,I3,A,I3,A)') &
2905 " ### Constraint ", i,
" of ", nvar,
" ###"
2906 WRITE (output_unit, fmt=
"(A)")
" #####################################"
2909 DO iwork = nwork, pwork
2910 IF (iwork == 0) cycle
2911 counter = counter + 1
2912 IF (output_unit > 0)
THEN
2913 WRITE (output_unit, fmt=
"(A)")
" #####################################"
2914 WRITE (output_unit,
'(A,I3,A,I3,A)') &
2915 " ### Energy evaluation ", counter,
" of ", twork,
" ###"
2916 WRITE (output_unit, fmt=
"(A)")
" #####################################"
2918 IF (
SIZE(scf_control%outer_scf%cdft_opt_control%jacobian_step) == 1)
THEN
2919 step_size = scf_control%outer_scf%cdft_opt_control%jacobian_step(1)
2921 step_size = scf_control%outer_scf%cdft_opt_control%jacobian_step(i)
2923 scf_env%outer_scf%variables(:, iter_count + 1) = scf_env%outer_scf%variables(:, iter_count)
2924 scf_env%outer_scf%variables(i, iter_count + 1) = scf_env%outer_scf%variables(i, iter_count) + &
2925 step_multiplier(iwork)*step_size
2926 CALL outer_loop_update_qs_env(qs_env, scf_env)
2927 CALL qs_ks_did_change(ks_env, potential_changed=.true.)
2928 CALL outer_loop_switch(scf_env, scf_control, cdft_control, cdft2ot)
2929 CALL scf_env_do_scf(scf_env=scf_env, scf_control=scf_control, qs_env=qs_env, &
2930 converged=converged, should_stop=should_stop, total_scf_steps=tsteps)
2931 CALL outer_loop_switch(scf_env, scf_control, cdft_control, ot2cdft)
2933 scf_env%outer_scf%iter_count = scf_env%outer_scf%iter_count + 1
2934 CALL outer_loop_gradient(qs_env, scf_env)
2935 CALL qs_scf_cdft_info(output_unit, scf_control, scf_env, cdft_control, &
2936 energy_qs, cdft_control%total_steps, &
2937 should_stop=.false., outer_loop_converged=.false., cdft_loop=.false.)
2938 scf_env%outer_scf%iter_count = scf_env%outer_scf%iter_count - 1
2941 jacobian(j, i) = jacobian(j, i) + coeff(iwork)*scf_env%outer_scf%gradient(j, iter_count + 1)
2944 scf_env%outer_scf%variables(:, iter_count + 1) = 0.0_dp
2945 scf_env%outer_scf%gradient = gradient
2946 scf_env%outer_scf%energy = energy
2947 cdft_control%total_steps = nsteps
2948 DO ispin = 1, nspins
2949 CALL deallocate_mo_set(mos(ispin))
2950 CALL duplicate_mo_set(mos(ispin), mos_stashed(ispin))
2951 CALL calculate_density_matrix(mos(ispin), &
2952 p_rmpv(ispin)%matrix)
2954 CALL qs_rho_update_rho(rho, qs_env=qs_env)
2955 CALL qs_ks_did_change(qs_env%ks_env, rho_changed=.true.)
2958 CALL cp_rm_default_logger()
2959 CALL cp_logger_release(tmp_logger)
2963 jacobian(i, j) = jacobian(i, j)/dh(j)
2966 IF (.NOT.
ASSOCIATED(scf_env%outer_scf%inv_jacobian))
THEN
2967 ALLOCATE (scf_env%outer_scf%inv_jacobian(nvar, nvar))
2969 inv_jacobian => scf_env%outer_scf%inv_jacobian
2970 CALL invert_matrix(jacobian, inv_jacobian, inv_error)
2971 scf_control%outer_scf%cdft_opt_control%broyden_update = .false.
2973 DO ispin = 1, nspins
2974 CALL deallocate_mo_set(mos_stashed(ispin))
2976 DEALLOCATE (mos_stashed, jacobian, gradient, energy, coeff, step_multiplier, dh)
2977 IF (output_unit > 0)
THEN
2978 WRITE (output_unit, fmt=
"(/,A)") &
2979 " ================================== JACOBIAN CALCULATED =================================="
2980 CALL close_file(unit_number=output_unit)
2984 CALL build_diagonal_jacobian(qs_env, used_history)
2987 IF (
ASSOCIATED(scf_env%outer_scf%inv_jacobian) .AND. para_env%is_source())
THEN
2989 CALL print_inverse_jacobian(logger, scf_env%outer_scf%inv_jacobian, iter_count)
2992 scf_control%outer_scf%cdft_opt_control%ijacobian(1) = scf_control%outer_scf%cdft_opt_control%ijacobian(1) + 1
2993 CALL timestop(handle)
2995 END SUBROUTINE qs_calculate_inverse_jacobian
3005 SUBROUTINE qs_cdft_line_search(qs_env)
3006 TYPE(qs_environment_type),
POINTER :: qs_env
3008 CHARACTER(LEN=*),
PARAMETER :: routinen =
'qs_cdft_line_search'
3010 CHARACTER(len=default_path_length) :: project_name
3011 INTEGER :: handle, i, ispin, iter_count, &
3012 max_linesearch, max_scf, nspins, &
3013 nsteps, nvar, output_unit, tsteps
3014 LOGICAL :: continue_ls, continue_ls_exit, converged, do_linesearch, found_solution, &
3015 reached_maxls, should_exit, should_stop, sign_changed
3016 LOGICAL,
ALLOCATABLE,
DIMENSION(:) :: positive_sign
3017 REAL(kind=dp) :: alpha, alpha_ls, factor, norm_ls
3018 REAL(kind=dp),
DIMENSION(:),
POINTER :: energy
3019 REAL(kind=dp),
DIMENSION(:, :),
POINTER :: gradient, inv_jacobian
3020 REAL(kind=dp),
EXTERNAL :: dnrm2
3021 TYPE(cdft_control_type),
POINTER :: cdft_control
3022 TYPE(cp_logger_type),
POINTER :: logger, tmp_logger
3023 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: p_rmpv
3024 TYPE(dbcsr_p_type),
DIMENSION(:, :),
POINTER :: rho_ao_kp
3025 TYPE(dft_control_type),
POINTER :: dft_control
3026 TYPE(mo_set_type),
DIMENSION(:),
POINTER :: mos
3027 TYPE(mp_para_env_type),
POINTER :: para_env
3028 TYPE(qs_energy_type),
POINTER :: energy_qs
3029 TYPE(qs_ks_env_type),
POINTER :: ks_env
3030 TYPE(qs_rho_type),
POINTER :: rho
3031 TYPE(qs_scf_env_type),
POINTER :: scf_env
3032 TYPE(scf_control_type),
POINTER :: scf_control
3034 CALL timeset(routinen, handle)
3036 NULLIFY (energy, gradient, p_rmpv, rho_ao_kp, mos, rho, &
3037 ks_env, scf_env, scf_control, dft_control, &
3038 cdft_control, inv_jacobian, para_env, &
3039 tmp_logger, energy_qs)
3040 logger => cp_get_default_logger()
3042 cpassert(
ASSOCIATED(qs_env))
3043 CALL get_qs_env(qs_env, scf_env=scf_env, ks_env=ks_env, &
3044 scf_control=scf_control, mos=mos, rho=rho, &
3045 dft_control=dft_control, &
3046 para_env=para_env, energy=energy_qs)
3047 do_linesearch = .false.
3048 SELECT CASE (scf_control%outer_scf%optimizer)
3050 do_linesearch = .false.
3051 CASE (outer_scf_optimizer_newton_ls)
3052 do_linesearch = .true.
3053 CASE (outer_scf_optimizer_broyden)
3054 SELECT CASE (scf_control%outer_scf%cdft_opt_control%broyden_type)
3055 CASE (broyden_type_1, broyden_type_2, broyden_type_1_explicit, broyden_type_2_explicit)
3056 do_linesearch = .false.
3057 CASE (broyden_type_1_ls, broyden_type_1_explicit_ls, broyden_type_2_ls, broyden_type_2_explicit_ls)
3058 cdft_control => dft_control%qs_control%cdft_control
3059 IF (.NOT.
ASSOCIATED(cdft_control))
THEN
3060 CALL cp_abort(__location__, &
3061 "Optimizers that perform a line search can"// &
3062 " only be used together with a valid CDFT constraint")
3064 IF (
ASSOCIATED(scf_env%outer_scf%inv_jacobian))
THEN
3065 do_linesearch = .true.
3069 IF (do_linesearch)
THEN
3071 TYPE(mo_set_type),
DIMENSION(:),
ALLOCATABLE :: mos_ls, mos_stashed
3072 cdft_control => dft_control%qs_control%cdft_control
3073 IF (.NOT.
ASSOCIATED(cdft_control))
THEN
3074 CALL cp_abort(__location__, &
3075 "Optimizers that perform a line search can"// &
3076 " only be used together with a valid CDFT constraint")
3078 cpassert(
ASSOCIATED(scf_env%outer_scf%inv_jacobian))
3079 cpassert(
ASSOCIATED(scf_control%outer_scf%cdft_opt_control))
3080 alpha = scf_control%outer_scf%cdft_opt_control%newton_step_save
3081 iter_count = scf_env%outer_scf%iter_count
3083 project_name = logger%iter_info%project_name
3084 CALL create_tmp_logger(para_env, project_name,
"-LineSearch.out", output_unit, tmp_logger)
3086 nspins = dft_control%nspins
3087 ALLOCATE (mos_stashed(nspins))
3088 DO ispin = 1, nspins
3089 CALL duplicate_mo_set(mos_stashed(ispin), mos(ispin))
3091 CALL qs_rho_get(rho, rho_ao_kp=rho_ao_kp)
3092 p_rmpv => rho_ao_kp(:, 1)
3093 nsteps = cdft_control%total_steps
3095 nvar =
SIZE(scf_env%outer_scf%variables, 1)
3096 max_scf = scf_control%outer_scf%max_scf + 1
3097 max_linesearch = scf_control%outer_scf%cdft_opt_control%max_ls
3098 continue_ls = scf_control%outer_scf%cdft_opt_control%continue_ls
3099 factor = scf_control%outer_scf%cdft_opt_control%factor_ls
3100 continue_ls_exit = .false.
3101 found_solution = .false.
3102 ALLOCATE (gradient(nvar, max_scf))
3103 gradient = scf_env%outer_scf%gradient
3104 ALLOCATE (energy(max_scf))
3105 energy = scf_env%outer_scf%energy
3106 reached_maxls = .false.
3108 IF (scf_control%outer_scf%cdft_opt_control%broyden_update)
THEN
3109 CALL outer_loop_optimize(scf_env, scf_control)
3111 scf_env%outer_scf%variables(:, iter_count + 1) = 0
3112 scf_control%outer_scf%cdft_opt_control%broyden_update = .false.
3115 IF (output_unit > 0)
THEN
3116 WRITE (output_unit, fmt=
"(/,A)") &
3117 " ================================== LINE SEARCH STARTED =================================="
3118 WRITE (output_unit, fmt=
"(A,I5,A)") &
3119 " Evaluating optimal step size for optimizer using a maximum of", max_linesearch,
" steps"
3120 IF (continue_ls)
THEN
3121 WRITE (output_unit, fmt=
"(A)") &
3122 " Line search continues until best step size is found or max steps are reached"
3124 WRITE (output_unit,
'(/,A,F5.3)') &
3125 " Initial step size: ", alpha
3126 WRITE (output_unit,
'(/,A,F5.3)') &
3127 " Step size update factor: ", factor
3128 WRITE (output_unit,
'(/,A,I10,A,I10)') &
3129 " Energy evaluation: ", cdft_control%ienergy,
", CDFT SCF iteration: ", iter_count
3132 CALL cp_add_default_logger(tmp_logger)
3133 DO i = 1, max_linesearch
3134 IF (output_unit > 0)
THEN
3135 WRITE (output_unit, fmt=
"(A)")
" "
3136 WRITE (output_unit, fmt=
"(A)")
" #####################################"
3137 WRITE (output_unit,
'(A,I10,A)') &
3138 " ### Line search step: ", i,
" ###"
3139 WRITE (output_unit, fmt=
"(A)")
" #####################################"
3141 inv_jacobian => scf_env%outer_scf%inv_jacobian
3143 scf_env%outer_scf%variables(:, iter_count + 1) = scf_env%outer_scf%variables(:, iter_count) - alpha* &
3144 matmul(inv_jacobian, scf_env%outer_scf%gradient(:, iter_count))
3146 CALL outer_loop_update_qs_env(qs_env, scf_env)
3147 CALL qs_ks_did_change(ks_env, potential_changed=.true.)
3148 CALL outer_loop_switch(scf_env, scf_control, cdft_control, cdft2ot)
3149 CALL scf_env_do_scf(scf_env=scf_env, scf_control=scf_control, qs_env=qs_env, &
3150 converged=converged, should_stop=should_stop, total_scf_steps=tsteps)
3151 CALL outer_loop_switch(scf_env, scf_control, cdft_control, ot2cdft)
3153 scf_env%outer_scf%iter_count = scf_env%outer_scf%iter_count + 1
3154 CALL outer_loop_gradient(qs_env, scf_env)
3155 CALL qs_scf_cdft_info(output_unit, scf_control, scf_env, cdft_control, &
3156 energy_qs, cdft_control%total_steps, &
3157 should_stop=.false., outer_loop_converged=.false., cdft_loop=.false.)
3158 scf_env%outer_scf%iter_count = scf_env%outer_scf%iter_count - 1
3160 IF (continue_ls .AND. .NOT.
ALLOCATED(positive_sign))
THEN
3161 ALLOCATE (positive_sign(nvar))
3163 positive_sign(ispin) = scf_env%outer_scf%gradient(ispin, iter_count + 1) >= 0.0_dp
3167 inv_jacobian => scf_env%outer_scf%inv_jacobian
3168 IF (dnrm2(nvar, scf_env%outer_scf%gradient(:, iter_count + 1), 1) < &
3169 dnrm2(nvar, scf_env%outer_scf%gradient(:, iter_count), 1))
THEN
3171 IF (.NOT. continue_ls)
THEN
3172 should_exit = .true.
3176 IF (found_solution)
THEN
3178 IF (dnrm2(nvar, scf_env%outer_scf%gradient(:, iter_count + 1), 1) > norm_ls)
THEN
3180 continue_ls_exit = .true.
3184 IF (.NOT. continue_ls_exit)
THEN
3185 should_exit = .false.
3187 found_solution = .true.
3188 norm_ls = dnrm2(nvar, scf_env%outer_scf%gradient(:, iter_count + 1), 1)
3191 sign_changed = .true.
3193 sign_changed = sign_changed .AND. (positive_sign(ispin) .NEQV. &
3194 scf_env%outer_scf%gradient(ispin, iter_count + 1) >= 0.0_dp)
3196 IF (.NOT.
ALLOCATED(mos_ls))
THEN
3197 ALLOCATE (mos_ls(nspins))
3199 DO ispin = 1, nspins
3200 CALL deallocate_mo_set(mos_ls(ispin))
3203 DO ispin = 1, nspins
3204 CALL duplicate_mo_set(mos_ls(ispin), mos(ispin))
3206 alpha = alpha*factor
3208 IF (i == max_linesearch) continue_ls_exit = .true.
3210 IF (sqrt(maxval(scf_env%outer_scf%gradient(:, scf_env%outer_scf%iter_count + 1)**2)) < &
3211 scf_control%outer_scf%eps_scf)
THEN
3212 continue_ls_exit = .true.
3215 IF (sign_changed) continue_ls_exit = .true.
3220 should_exit = .false.
3222 alpha = alpha*factor
3224 IF (continue_ls_exit)
THEN
3227 DO ispin = 1, nspins
3228 CALL deallocate_mo_set(mos(ispin))
3229 CALL duplicate_mo_set(mos(ispin), mos_ls(ispin))
3230 CALL calculate_density_matrix(mos(ispin), &
3231 p_rmpv(ispin)%matrix)
3232 CALL deallocate_mo_set(mos_ls(ispin))
3234 CALL qs_rho_update_rho(rho, qs_env=qs_env)
3235 CALL qs_ks_did_change(qs_env%ks_env, rho_changed=.true.)
3237 should_exit = .true.
3240 IF (.NOT. should_exit .AND. &
3241 (i == max_linesearch .AND. converged .AND. .NOT. found_solution))
THEN
3242 should_exit = .true.
3243 reached_maxls = .true.
3244 alpha = alpha*(1.0_dp/factor)
3247 scf_env%outer_scf%variables(:, iter_count + 1) = 0.0_dp
3248 scf_env%outer_scf%gradient = gradient
3249 scf_env%outer_scf%energy = energy
3251 IF (should_exit)
EXIT
3253 cdft_control%total_steps = nsteps
3254 DO ispin = 1, nspins
3255 CALL deallocate_mo_set(mos(ispin))
3256 CALL duplicate_mo_set(mos(ispin), mos_stashed(ispin))
3257 CALL calculate_density_matrix(mos(ispin), &
3258 p_rmpv(ispin)%matrix)
3260 CALL qs_rho_update_rho(rho, qs_env=qs_env)
3261 CALL qs_ks_did_change(qs_env%ks_env, rho_changed=.true.)
3263 scf_control%outer_scf%cdft_opt_control%newton_step = alpha
3264 IF (.NOT. should_exit)
THEN
3265 CALL cp_warn(__location__, &
3266 "Line search did not converge. CDFT SCF proceeds with fixed step size.")
3267 scf_control%outer_scf%cdft_opt_control%newton_step = scf_control%outer_scf%cdft_opt_control%newton_step_save
3269 IF (reached_maxls)
THEN
3270 CALL cp_warn(__location__, &
3271 "Line search did not converge. CDFT SCF proceeds with lasted iterated step size.")
3273 CALL cp_rm_default_logger()
3274 CALL cp_logger_release(tmp_logger)
3276 DO ispin = 1, nspins
3277 CALL deallocate_mo_set(mos_stashed(ispin))
3279 DEALLOCATE (mos_stashed, gradient, energy)
3280 IF (
ALLOCATED(positive_sign))
DEALLOCATE (positive_sign)
3281 IF (output_unit > 0)
THEN
3282 WRITE (output_unit, fmt=
"(/,A)") &
3283 " ================================== LINE SEARCH COMPLETE =================================="
3284 CALL close_file(unit_number=output_unit)
3289 CALL timestop(handle)
3291 END SUBROUTINE qs_cdft_line_search
Define the atomic kind types and their sub types.
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_multiply(transa, transb, alpha, matrix_a, matrix_b, beta, matrix_c, first_row, last_row, first_column, last_column, first_k, last_k, retain_sparsity, filter_eps, flop)
...
subroutine, public dbcsr_get_info(matrix, nblkrows_total, nblkcols_total, nfullrows_total, nfullcols_total, nblkrows_local, nblkcols_local, nfullrows_local, nfullcols_local, my_prow, my_pcol, local_rows, local_cols, proc_row_dist, proc_col_dist, row_blk_size, col_blk_size, row_blk_offset, col_blk_offset, distribution, name, matrix_type, group)
...
subroutine, public dbcsr_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)
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. Tracking of preconnections.
subroutine, public close_file(unit_number, file_status, keep_preconnection)
Close an open file given by its logical unit number. Optionally, keep the file and unit preconnected.
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...
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)
...
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
subroutine, public cp_rm_iter_level(iteration_info, level_name, n_rlevel_att)
Removes an iteration level.
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_add_iter_level(iteration_info, level_name, n_rlevel_new)
Adds an iteration level.
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_all(preconditioner_env, matrix_c_re, matrix_c_im, matrix_h_re, matrix_h_im, matrix_s_re, matrix_s_im, mo_set, energy_gap, solver_type)
Construct FULL_ALL directly from one complex H(k), S(k), and C(k) channel.
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_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_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_store(kpoints, ao_ao_fm, 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_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 mpools_get(mpools, ao_mo_fm_pools, ao_ao_fm_pools, mo_mo_fm_pools, ao_mosub_fm_pools, mosub_mosub_fm_pools, maxao_maxmo_fm_pool, maxao_maxao_fm_pool, maxmo_maxmo_fm_pool)
returns various attributes of the mpools (notably the pools contained in it)
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
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_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_new_preconditioner(qs_ot_env, preconditioner)
gets ready to use the preconditioner/ or renew the preconditioner only keeps a pointer to the precond...
subroutine, public qs_ot_get_p_complex(matrix_x, matrix_x_im, matrix_sx, matrix_sx_im, qs_ot_env)
compute P=X^H*S*X and the STRICT matrix functions for a complex K-point channel
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
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...
Represent a complex full matrix.
to create arrays of pools
keeps the information about the structure of a full matrix
type of a logger, at the moment it contains just a print level starting at which level it should be l...
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.