101#include "./base/base_uses.f90"
107 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'almo_scf'
111 LOGICAL,
PARAMETER :: debug_mode = .false.
112 LOGICAL,
PARAMETER :: safe_mode = .false.
126 LOGICAL,
INTENT(IN) :: calc_forces
128 CHARACTER(len=*),
PARAMETER :: routinen =
'almo_entry_scf'
133 CALL timeset(routinen, handle)
138 CALL get_qs_env(qs_env, almo_scf_env=almo_scf_env)
141 CALL almo_scf_init(qs_env, almo_scf_env, calc_forces)
144 CALL almo_scf_initial_guess(qs_env, almo_scf_env)
147 CALL almo_scf_main(qs_env, almo_scf_env)
150 CALL almo_scf_delocalization(qs_env, almo_scf_env)
153 CALL construct_nlmos(qs_env, almo_scf_env)
159 CALL almo_scf_post(qs_env, almo_scf_env)
162 CALL almo_scf_clean_up(almo_scf_env)
164 CALL timestop(handle)
178 SUBROUTINE almo_scf_init(qs_env, almo_scf_env, calc_forces)
181 LOGICAL,
INTENT(IN) :: calc_forces
183 CHARACTER(len=*),
PARAMETER :: routinen =
'almo_scf_init'
185 INTEGER :: ao, handle, i, iao, idomain, ispin, &
186 multip, naos, natoms, ndomains, nelec, &
187 nelec_a, nelec_b, nmols, nspins, &
195 CALL timeset(routinen, handle)
199 IF (logger%para_env%is_source())
THEN
207 almo_scf_env%opt_block_diag_pcg%optimizer_type =
optimizer_pcg
217 nelectron_total=almo_scf_env%nelectrons_total, &
219 dft_control=dft_control, &
220 molecule_set=molecule_set, &
222 has_unit_metric=almo_scf_env%orthogonal_basis, &
223 para_env=almo_scf_env%para_env, &
224 blacs_env=almo_scf_env%blacs_env, &
225 nelectron_spin=almo_scf_env%nelectrons_spin)
226 CALL almo_scf_env%para_env%retain()
227 CALL almo_scf_env%blacs_env%retain()
230 almo_scf_env%nspins = dft_control%nspins
231 almo_scf_env%nmolecules =
SIZE(molecule_set)
233 nfullrows_total=almo_scf_env%naos, nblkrows_total=almo_scf_env%natoms)
236 almo_scf_env%smear = dft_control%smear
237 IF (almo_scf_env%smear)
THEN
239 IF ((almo_scf_env%almo_update_algorithm .NE.
almo_scf_diag) .OR. &
241 (almo_scf_env%xalmo_update_algorithm .NE.
almo_scf_diag)))
THEN
242 cpabort(
"ALMO smearing is currently implemented for DIAG algorithm only")
245 cpabort(
"Only Fermi-Dirac smearing is currently compatible with ALMO")
247 almo_scf_env%smear_e_temp = qs_env%scf_control%smear%electronic_temperature
250 cpabort(
"ALMO smearing was designed to work with molecular fragments only")
255 nspins = almo_scf_env%nspins
256 nmols = almo_scf_env%nmolecules
257 natoms = almo_scf_env%natoms
258 naos = almo_scf_env%naos
262 almo_scf_env%ndomains = almo_scf_env%nmolecules
264 almo_scf_env%ndomains = almo_scf_env%natoms
268 ndomains = almo_scf_env%ndomains
269 ALLOCATE (almo_scf_env%domain_index_of_atom(natoms))
270 ALLOCATE (almo_scf_env%domain_index_of_ao(naos))
271 ALLOCATE (almo_scf_env%first_atom_of_domain(ndomains))
272 ALLOCATE (almo_scf_env%last_atom_of_domain(ndomains))
273 ALLOCATE (almo_scf_env%nbasis_of_domain(ndomains))
274 ALLOCATE (almo_scf_env%nocc_of_domain(ndomains, nspins))
275 ALLOCATE (almo_scf_env%real_ne_of_domain(ndomains, nspins))
276 ALLOCATE (almo_scf_env%nvirt_full_of_domain(ndomains, nspins))
277 ALLOCATE (almo_scf_env%nvirt_of_domain(ndomains, nspins))
278 ALLOCATE (almo_scf_env%nvirt_disc_of_domain(ndomains, nspins))
279 ALLOCATE (almo_scf_env%mu_of_domain(ndomains, nspins))
280 ALLOCATE (almo_scf_env%cpu_of_domain(ndomains))
281 ALLOCATE (almo_scf_env%charge_of_domain(ndomains))
282 ALLOCATE (almo_scf_env%multiplicity_of_domain(ndomains))
288 atom_to_mol=almo_scf_env%domain_index_of_atom, &
289 mol_to_first_atom=almo_scf_env%first_atom_of_domain, &
290 mol_to_last_atom=almo_scf_env%last_atom_of_domain, &
291 mol_to_nelectrons=almo_scf_env%nocc_of_domain(1:ndomains, 1), &
292 mol_to_nbasis=almo_scf_env%nbasis_of_domain, &
293 mol_to_charge=almo_scf_env%charge_of_domain, &
294 mol_to_multiplicity=almo_scf_env%multiplicity_of_domain)
299 DO idomain = 1, ndomains
300 nelec = almo_scf_env%nocc_of_domain(idomain, 1)
301 multip = almo_scf_env%multiplicity_of_domain(idomain)
302 nelec_a = (nelec + multip - 1)/2
303 nelec_b = nelec - nelec_a
305 IF (almo_scf_env%smear)
THEN
306 cpwarn_if(multip .GT. 1,
"BEWARE: Non singlet state detected, treating it as closed-shell")
309 almo_scf_env%real_ne_of_domain(idomain, :) = real(nelec, kind=
dp)/2.0_dp
312 almo_scf_env%nocc_of_domain(idomain, :) = ceiling(almo_scf_env%real_ne_of_domain(idomain, :)) &
313 + (almo_scf_env%last_atom_of_domain(idomain) &
314 - almo_scf_env%first_atom_of_domain(idomain) + 1)
316 almo_scf_env%nocc_of_domain(idomain, 1) = nelec_a
317 IF (nelec_a .NE. nelec_b)
THEN
318 IF (nspins .EQ. 1)
THEN
319 WRITE (*, *)
"Domain ", idomain,
" out of ", ndomains,
". Electrons = ", nelec
320 cpabort(
"odd e- -- use unrestricted methods")
322 almo_scf_env%nocc_of_domain(idomain, 2) = nelec_b
325 cpabort(
"Unrestricted ALMO methods are NYI")
331 almo_scf_env%nvirt_full_of_domain(:, ispin) = &
332 almo_scf_env%nbasis_of_domain(:) - &
333 almo_scf_env%nocc_of_domain(:, ispin)
335 SELECT CASE (almo_scf_env%deloc_truncate_virt)
337 almo_scf_env%nvirt_of_domain(:, ispin) = &
338 almo_scf_env%nvirt_full_of_domain(:, ispin)
339 almo_scf_env%nvirt_disc_of_domain(:, ispin) = 0
341 DO idomain = 1, ndomains
342 almo_scf_env%nvirt_of_domain(idomain, ispin) = &
343 min(almo_scf_env%deloc_virt_per_domain, &
344 almo_scf_env%nvirt_full_of_domain(idomain, ispin))
345 almo_scf_env%nvirt_disc_of_domain(idomain, ispin) = &
346 almo_scf_env%nvirt_full_of_domain(idomain, ispin) - &
347 almo_scf_env%nvirt_of_domain(idomain, ispin)
350 DO idomain = 1, ndomains
351 almo_scf_env%nvirt_of_domain(idomain, ispin) = &
352 min(almo_scf_env%nocc_of_domain(idomain, ispin), &
353 almo_scf_env%nvirt_full_of_domain(idomain, ispin))
354 almo_scf_env%nvirt_disc_of_domain(idomain, ispin) = &
355 almo_scf_env%nvirt_full_of_domain(idomain, ispin) - &
356 almo_scf_env%nvirt_of_domain(idomain, ispin)
359 cpabort(
"illegal method for virtual space truncation")
364 almo_scf_env%domain_index_of_atom(1:natoms) = (/(i, i=1, natoms)/)
368 DO idomain = 1, ndomains
369 DO iao = 1, almo_scf_env%nbasis_of_domain(idomain)
370 almo_scf_env%domain_index_of_ao(ao) = idomain
375 almo_scf_env%mu_of_domain(:, :) = almo_scf_env%mu
380 ALLOCATE (almo_scf_env%domain_index_of_ao_block(natoms))
381 almo_scf_env%domain_index_of_ao_block(:) = &
382 almo_scf_env%domain_index_of_atom(:)
384 ALLOCATE (almo_scf_env%domain_index_of_ao_block(nmols))
386 almo_scf_env%domain_index_of_ao_block(:) = (/(i, i=1, nmols)/)
390 ALLOCATE (almo_scf_env%domain_index_of_mo_block(natoms))
391 almo_scf_env%domain_index_of_mo_block(:) = &
392 almo_scf_env%domain_index_of_atom(:)
394 ALLOCATE (almo_scf_env%domain_index_of_mo_block(nmols))
396 almo_scf_env%domain_index_of_mo_block(:) = (/(i, i=1, nmols)/)
402 almo_scf_env%need_previous_ks = .true.
408 almo_scf_env%need_virtuals = .true.
409 almo_scf_env%need_orbital_energies = .true.
412 almo_scf_env%calc_forces = calc_forces
413 IF (calc_forces)
THEN
418 cpabort(
"Forces for perturbative methods are NYI. Change DELOCALIZE_METHOD")
421 IF (almo_scf_env%almo_history%istore .GT. (almo_scf_env%almo_history%nstore + 1))
THEN
422 IF (almo_scf_env%opt_block_diag_pcg%eps_error_early .GT. 0.0_dp)
THEN
423 almo_scf_env%opt_block_diag_pcg%eps_error = almo_scf_env%opt_block_diag_pcg%eps_error_early
424 almo_scf_env%opt_block_diag_pcg%early_stopping_on = .true.
425 IF (unit_nr > 0)
WRITE (*, *)
"ALMO_OPTIMIZER_PCG: EPS_ERROR_EARLY is on"
427 IF (almo_scf_env%opt_block_diag_diis%eps_error_early .GT. 0.0_dp)
THEN
428 almo_scf_env%opt_block_diag_diis%eps_error = almo_scf_env%opt_block_diag_diis%eps_error_early
429 almo_scf_env%opt_block_diag_diis%early_stopping_on = .true.
430 IF (unit_nr > 0)
WRITE (*, *)
"ALMO_OPTIMIZER_DIIS: EPS_ERROR_EARLY is on"
432 IF (almo_scf_env%opt_block_diag_pcg%max_iter_early .GT. 0)
THEN
433 almo_scf_env%opt_block_diag_pcg%max_iter = almo_scf_env%opt_block_diag_pcg%max_iter_early
434 almo_scf_env%opt_block_diag_pcg%early_stopping_on = .true.
435 IF (unit_nr > 0)
WRITE (*, *)
"ALMO_OPTIMIZER_PCG: MAX_ITER_EARLY is on"
437 IF (almo_scf_env%opt_block_diag_diis%max_iter_early .GT. 0)
THEN
438 almo_scf_env%opt_block_diag_diis%max_iter = almo_scf_env%opt_block_diag_diis%max_iter_early
439 almo_scf_env%opt_block_diag_diis%early_stopping_on = .true.
440 IF (unit_nr > 0)
WRITE (*, *)
"ALMO_OPTIMIZER_DIIS: MAX_ITER_EARLY is on"
443 almo_scf_env%opt_block_diag_diis%early_stopping_on = .false.
444 almo_scf_env%opt_block_diag_pcg%early_stopping_on = .false.
446 IF (almo_scf_env%xalmo_history%istore .GT. (almo_scf_env%xalmo_history%nstore + 1))
THEN
447 IF (almo_scf_env%opt_xalmo_pcg%eps_error_early .GT. 0.0_dp)
THEN
448 almo_scf_env%opt_xalmo_pcg%eps_error = almo_scf_env%opt_xalmo_pcg%eps_error_early
449 almo_scf_env%opt_xalmo_pcg%early_stopping_on = .true.
450 IF (unit_nr > 0)
WRITE (*, *)
"XALMO_OPTIMIZER_PCG: EPS_ERROR_EARLY is on"
452 IF (almo_scf_env%opt_xalmo_pcg%max_iter_early .GT. 0.0_dp)
THEN
453 almo_scf_env%opt_xalmo_pcg%max_iter = almo_scf_env%opt_xalmo_pcg%max_iter_early
454 almo_scf_env%opt_xalmo_pcg%early_stopping_on = .true.
455 IF (unit_nr > 0)
WRITE (*, *)
"XALMO_OPTIMIZER_PCG: MAX_ITER_EARLY is on"
458 almo_scf_env%opt_xalmo_pcg%early_stopping_on = .false.
463 CALL almo_scf_env_create_matrices(almo_scf_env, matrix_s(1)%matrix)
466 almo_scf_env%s_inv_done = .false.
467 almo_scf_env%s_sqrt_done = .false.
468 CALL almo_scf_init_ao_overlap(matrix_s(1)%matrix, almo_scf_env)
475 CALL almo_scf_print_job_info(almo_scf_env, unit_nr)
478 ALLOCATE (almo_scf_env%domain_preconditioner(ndomains, nspins))
482 ALLOCATE (almo_scf_env%domain_ks_xx(ndomains, nspins))
486 ALLOCATE (almo_scf_env%domain_s_inv(ndomains, nspins))
488 ALLOCATE (almo_scf_env%domain_s_sqrt_inv(ndomains, nspins))
490 ALLOCATE (almo_scf_env%domain_s_sqrt(ndomains, nspins))
492 ALLOCATE (almo_scf_env%domain_t(ndomains, nspins))
494 ALLOCATE (almo_scf_env%domain_err(ndomains, nspins))
496 ALLOCATE (almo_scf_env%domain_r_down_up(ndomains, nspins))
501 almo_scf_env%matrix_ks, &
502 almo_scf_env%mat_distr_aos, &
503 almo_scf_env%eps_filter)
506 CALL timestop(handle)
508 END SUBROUTINE almo_scf_init
519 SUBROUTINE almo_scf_initial_guess(qs_env, almo_scf_env)
523 CHARACTER(len=*),
PARAMETER :: routinen =
'almo_scf_initial_guess'
525 CHARACTER(LEN=default_path_length) :: file_name, project_name
526 INTEGER :: handle, iaspc, ispin, istore, naspc, &
528 INTEGER,
DIMENSION(2) :: nelectron_spin
529 LOGICAL :: aspc_guess, has_unit_metric
530 REAL(kind=
dp) :: alpha, cs_pos, energy, kts_sum
534 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: matrix_s, rho_ao
539 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
542 CALL timeset(routinen, handle)
544 NULLIFY (rho, rho_ao)
548 IF (logger%para_env%is_source())
THEN
556 dft_control=dft_control, &
558 atomic_kind_set=atomic_kind_set, &
559 qs_kind_set=qs_kind_set, &
560 particle_set=particle_set, &
561 has_unit_metric=has_unit_metric, &
563 nelectron_spin=nelectron_spin, &
564 mscfg_env=mscfg_env, &
568 cpassert(
ASSOCIATED(mscfg_env))
574 IF (almo_scf_env%almo_history%istore == 0)
THEN
580 nspins = almo_scf_env%nspins
583 IF (.NOT. aspc_guess)
THEN
585 SELECT CASE (almo_scf_env%almo_scf_guess)
594 almo_scf_env%matrix_t_blk(ispin), ispin)
596 almo_scf_env%eps_filter)
602 IF (dft_control%qs_control%dftb .OR. dft_control%qs_control%semi_empirical .OR. &
603 dft_control%qs_control%xtb)
THEN
605 matrix_s(1)%matrix, has_unit_metric, &
606 dft_control, particle_set, atomic_kind_set, qs_kind_set, &
607 nspins, nelectron_spin, &
611 nspins, nelectron_spin, unit_nr, para_env)
617 almo_scf_env%matrix_p_blk(ispin), almo_scf_env%mat_distr_aos)
619 almo_scf_env%eps_filter)
628 project_name = logger%iter_info%project_name
631 WRITE (file_name,
'(A,I0,A)') trim(project_name)//
"_ALMO_SPIN_", ispin,
"_RESTART.mo"
632 CALL dbcsr_get_info(almo_scf_env%matrix_t_blk(ispin), distribution=dist)
633 CALL dbcsr_binary_read(file_name, distribution=dist, matrix_new=almo_scf_env%matrix_t_blk(ispin))
634 cs_pos =
dbcsr_checksum(almo_scf_env%matrix_t_blk(ispin), pos=.true.)
635 IF (unit_nr > 0)
THEN
636 WRITE (unit_nr,
'(T2,A,E20.8)')
"Read restart ALMO "//trim(file_name)//
" with checksum: ", cs_pos
646 naspc = min(almo_scf_env%almo_history%istore, almo_scf_env%almo_history%nstore)
647 IF (unit_nr > 0)
THEN
648 WRITE (unit_nr, fmt=
"(/,T2,A,/,/,T3,A,I0)") &
649 "Parameters for the always stable predictor-corrector (ASPC) method:", &
650 "ASPC order: ", naspc
657 istore = mod(almo_scf_env%almo_history%istore - iaspc, almo_scf_env%almo_history%nstore) + 1
658 alpha = (-1.0_dp)**(iaspc + 1)*real(iaspc, kind=
dp)* &
660 IF (unit_nr > 0)
THEN
661 WRITE (unit_nr, fmt=
"(T3,A2,I0,A4,F10.6)") &
662 "B(", iaspc,
") = ", alpha
665 CALL dbcsr_copy(almo_scf_env%matrix_t_blk(ispin), &
666 almo_scf_env%almo_history%matrix_t(ispin), &
667 keep_sparsity=.true.)
668 CALL dbcsr_scale(almo_scf_env%matrix_t_blk(ispin), alpha)
671 almo_scf_env%almo_history%matrix_p_up_down(ispin, istore), &
672 almo_scf_env%almo_history%matrix_t(ispin), &
673 1.0_dp, almo_scf_env%matrix_t_blk(ispin), &
674 retain_sparsity=.true.)
685 overlap=almo_scf_env%matrix_sigma_blk(ispin), &
686 metric=almo_scf_env%matrix_s_blk(1), &
687 retain_locality=.true., &
688 only_normalize=.false., &
689 nocc_of_domain=almo_scf_env%nocc_of_domain(:, ispin), &
690 eps_filter=almo_scf_env%eps_filter, &
691 order_lanczos=almo_scf_env%order_lanczos, &
692 eps_lanczos=almo_scf_env%eps_lanczos, &
693 max_iter_lanczos=almo_scf_env%max_iter_lanczos)
696 IF (almo_scf_env%smear)
THEN
698 mo_energies=almo_scf_env%mo_energies(:, ispin), &
699 mu_of_domain=almo_scf_env%mu_of_domain(:, ispin), &
700 real_ne_of_domain=almo_scf_env%real_ne_of_domain(:, ispin), &
701 spin_kts=almo_scf_env%kTS(ispin), &
702 smear_e_temp=almo_scf_env%smear_e_temp, &
703 ndomains=almo_scf_env%ndomains, &
704 nocc_of_domain=almo_scf_env%nocc_of_domain(:, ispin))
708 p=almo_scf_env%matrix_p(ispin), &
709 eps_filter=almo_scf_env%eps_filter, &
710 orthog_orbs=.false., &
711 nocc_of_domain=almo_scf_env%nocc_of_domain(:, ispin), &
712 s=almo_scf_env%matrix_s(1), &
713 sigma=almo_scf_env%matrix_sigma(ispin), &
714 sigma_inv=almo_scf_env%matrix_sigma_inv(ispin), &
716 smear=almo_scf_env%smear, &
717 algorithm=almo_scf_env%sigma_inv_algorithm, &
718 eps_lanczos=almo_scf_env%eps_lanczos, &
719 max_iter_lanczos=almo_scf_env%max_iter_lanczos, &
720 inv_eps_factor=almo_scf_env%matrix_iter_eps_error_factor, &
721 para_env=almo_scf_env%para_env, &
722 blacs_env=almo_scf_env%blacs_env)
727 IF (nspins == 1)
THEN
730 IF (almo_scf_env%smear)
THEN
731 almo_scf_env%kTS(1) = almo_scf_env%kTS(1)*2.0_dp
735 IF (almo_scf_env%smear)
THEN
736 kts_sum = sum(almo_scf_env%kTS)
742 almo_scf_env%matrix_p, &
743 almo_scf_env%matrix_ks, &
745 almo_scf_env%eps_filter, &
746 almo_scf_env%mat_distr_aos, &
747 smear=almo_scf_env%smear, &
750 IF (unit_nr > 0)
THEN
752 WRITE (unit_nr,
'(T2,A38,F40.10)')
"Single-molecule energy:", &
753 sum(mscfg_env%energy_of_frag)
755 WRITE (unit_nr,
'(T2,A38,F40.10)')
"Energy of the initial guess:", energy
756 WRITE (unit_nr,
'()')
759 CALL timestop(handle)
761 END SUBROUTINE almo_scf_initial_guess
770 SUBROUTINE almo_scf_store_extrapolation_data(almo_scf_env)
773 CHARACTER(len=*),
PARAMETER :: routinen =
'almo_scf_store_extrapolation_data'
775 INTEGER :: handle, ispin, istore, unit_nr
776 LOGICAL :: delocalization_uses_extrapolation
778 TYPE(
dbcsr_type) :: matrix_no_tmp1, matrix_no_tmp2, &
779 matrix_no_tmp3, matrix_no_tmp4
781 CALL timeset(routinen, handle)
785 IF (logger%para_env%is_source())
THEN
791 IF (almo_scf_env%almo_history%nstore > 0)
THEN
793 almo_scf_env%almo_history%istore = almo_scf_env%almo_history%istore + 1
795 DO ispin = 1,
SIZE(almo_scf_env%matrix_t_blk)
797 istore = mod(almo_scf_env%almo_history%istore - 1, almo_scf_env%almo_history%nstore) + 1
799 IF (almo_scf_env%almo_history%istore == 1)
THEN
800 CALL dbcsr_create(almo_scf_env%almo_history%matrix_t(ispin), &
801 template=almo_scf_env%matrix_t_blk(ispin), &
802 matrix_type=dbcsr_type_no_symmetry)
804 CALL dbcsr_copy(almo_scf_env%almo_history%matrix_t(ispin), &
805 almo_scf_env%matrix_t_blk(ispin))
807 IF (almo_scf_env%almo_history%istore <= almo_scf_env%almo_history%nstore)
THEN
808 CALL dbcsr_create(almo_scf_env%almo_history%matrix_p_up_down(ispin, istore), &
809 template=almo_scf_env%matrix_s(1), &
810 matrix_type=dbcsr_type_no_symmetry)
813 CALL dbcsr_create(matrix_no_tmp1, template=almo_scf_env%matrix_t_blk(ispin), &
814 matrix_type=dbcsr_type_no_symmetry)
815 CALL dbcsr_create(matrix_no_tmp2, template=almo_scf_env%matrix_t_blk(ispin), &
816 matrix_type=dbcsr_type_no_symmetry)
820 almo_scf_env%matrix_t_blk(ispin), &
821 0.0_dp, matrix_no_tmp1, &
822 filter_eps=almo_scf_env%eps_filter)
824 almo_scf_env%matrix_sigma_inv_0deloc(ispin), &
825 0.0_dp, matrix_no_tmp2, &
826 filter_eps=almo_scf_env%eps_filter)
828 almo_scf_env%matrix_t_blk(ispin), &
830 0.0_dp, almo_scf_env%almo_history%matrix_p_up_down(ispin, istore), &
831 filter_eps=almo_scf_env%eps_filter)
841 delocalization_uses_extrapolation = &
844 IF (almo_scf_env%xalmo_history%nstore > 0 .AND. &
845 delocalization_uses_extrapolation)
THEN
847 almo_scf_env%xalmo_history%istore = almo_scf_env%xalmo_history%istore + 1
849 DO ispin = 1,
SIZE(almo_scf_env%matrix_t)
851 istore = mod(almo_scf_env%xalmo_history%istore - 1, almo_scf_env%xalmo_history%nstore) + 1
853 IF (almo_scf_env%xalmo_history%istore == 1)
THEN
854 CALL dbcsr_create(almo_scf_env%xalmo_history%matrix_t(ispin), &
855 template=almo_scf_env%matrix_t(ispin), &
856 matrix_type=dbcsr_type_no_symmetry)
858 CALL dbcsr_copy(almo_scf_env%xalmo_history%matrix_t(ispin), &
859 almo_scf_env%matrix_t(ispin))
861 IF (almo_scf_env%xalmo_history%istore <= almo_scf_env%xalmo_history%nstore)
THEN
866 CALL dbcsr_create(almo_scf_env%xalmo_history%matrix_p_up_down(ispin, istore), &
867 template=almo_scf_env%matrix_s(1), &
868 matrix_type=dbcsr_type_no_symmetry)
871 CALL dbcsr_create(matrix_no_tmp3, template=almo_scf_env%matrix_t(ispin), &
872 matrix_type=dbcsr_type_no_symmetry)
873 CALL dbcsr_create(matrix_no_tmp4, template=almo_scf_env%matrix_t(ispin), &
874 matrix_type=dbcsr_type_no_symmetry)
878 almo_scf_env%matrix_t(ispin), &
879 0.0_dp, matrix_no_tmp3, &
880 filter_eps=almo_scf_env%eps_filter)
882 almo_scf_env%matrix_sigma_inv(ispin), &
883 0.0_dp, matrix_no_tmp4, &
884 filter_eps=almo_scf_env%eps_filter)
886 almo_scf_env%matrix_t(ispin), &
888 0.0_dp, almo_scf_env%xalmo_history%matrix_p_up_down(ispin, istore), &
889 filter_eps=almo_scf_env%eps_filter)
904 CALL timestop(handle)
906 END SUBROUTINE almo_scf_store_extrapolation_data
916 SUBROUTINE almo_scf_print_job_info(almo_scf_env, unit_nr)
919 INTEGER,
INTENT(IN) :: unit_nr
921 CHARACTER(len=*),
PARAMETER :: routinen =
'almo_scf_print_job_info'
923 CHARACTER(len=13) :: neig_string
924 CHARACTER(len=33) :: deloc_method_string
925 INTEGER :: handle, idomain, index1_prev, sum_temp
926 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: nneighbors
928 CALL timeset(routinen, handle)
930 IF (unit_nr > 0)
THEN
931 WRITE (unit_nr,
'()')
932 WRITE (unit_nr,
'(T2,A,A,A)') repeat(
"-", 32),
" ALMO SETTINGS ", repeat(
"-", 32)
934 WRITE (unit_nr,
'(T2,A,T48,E33.3)')
"eps_filter:", almo_scf_env%eps_filter
936 IF (almo_scf_env%almo_update_algorithm .EQ.
almo_scf_skip)
THEN
937 WRITE (unit_nr,
'(T2,A)')
"skip optimization of block-diagonal ALMOs"
939 WRITE (unit_nr,
'(T2,A)')
"optimization of block-diagonal ALMOs:"
940 SELECT CASE (almo_scf_env%almo_update_algorithm)
953 SELECT CASE (almo_scf_env%deloc_method)
955 deloc_method_string =
"NONE"
957 deloc_method_string =
"FULL_X"
959 deloc_method_string =
"FULL_SCF"
961 deloc_method_string =
"FULL_X_THEN_SCF"
963 deloc_method_string =
"XALMO_1DIAG"
965 deloc_method_string =
"XALMO_X"
967 deloc_method_string =
"XALMO_SCF"
969 WRITE (unit_nr,
'(T2,A,T48,A33)')
"delocalization:", trim(deloc_method_string)
973 SELECT CASE (almo_scf_env%deloc_method)
975 WRITE (unit_nr,
'(T2,A,T48,A33)')
"delocalization cutoff radius:", &
977 deloc_method_string =
"FULL_X_THEN_SCF"
979 WRITE (unit_nr,
'(T2,A,T48,F33.5)')
"XALMO cutoff radius:", &
980 almo_scf_env%quencher_r0_factor
986 WRITE (unit_nr,
'(T2,A)')
"optimization of extended orbitals:"
987 SELECT CASE (almo_scf_env%xalmo_update_algorithm)
1030 WRITE (unit_nr,
'(T2,A)') repeat(
"-", 79)
1031 WRITE (unit_nr,
'(T2,A,T48,I33)')
"Total fragments:", &
1032 almo_scf_env%ndomains
1034 sum_temp = sum(almo_scf_env%nbasis_of_domain(:))
1035 WRITE (unit_nr,
'(T2,A,T53,I5,F9.2,I5,I9)') &
1036 "Basis set size per fragment (min, av, max, total):", &
1037 minval(almo_scf_env%nbasis_of_domain(:)), &
1038 (1.0_dp*sum_temp)/almo_scf_env%ndomains, &
1039 maxval(almo_scf_env%nbasis_of_domain(:)), &
1047 sum_temp = sum(almo_scf_env%nocc_of_domain(:, :))
1048 WRITE (unit_nr,
'(T2,A,T53,I5,F9.2,I5,I9)') &
1049 "Occupied MOs per fragment (min, av, max, total):", &
1050 minval(sum(almo_scf_env%nocc_of_domain, dim=2)), &
1051 (1.0_dp*sum_temp)/almo_scf_env%ndomains, &
1052 maxval(sum(almo_scf_env%nocc_of_domain, dim=2)), &
1060 sum_temp = sum(almo_scf_env%nvirt_of_domain(:, :))
1061 WRITE (unit_nr,
'(T2,A,T53,I5,F9.2,I5,I9)') &
1062 "Virtual MOs per fragment (min, av, max, total):", &
1063 minval(sum(almo_scf_env%nvirt_of_domain, dim=2)), &
1064 (1.0_dp*sum_temp)/almo_scf_env%ndomains, &
1065 maxval(sum(almo_scf_env%nvirt_of_domain, dim=2)), &
1073 sum_temp = sum(almo_scf_env%charge_of_domain(:))
1074 WRITE (unit_nr,
'(T2,A,T53,I5,F9.2,I5,I9)') &
1075 "Charges per fragment (min, av, max, total):", &
1076 minval(almo_scf_env%charge_of_domain(:)), &
1077 (1.0_dp*sum_temp)/almo_scf_env%ndomains, &
1078 maxval(almo_scf_env%charge_of_domain(:)), &
1087 ALLOCATE (nneighbors(almo_scf_env%ndomains))
1089 DO idomain = 1, almo_scf_env%ndomains
1091 IF (idomain .EQ. 1)
THEN
1094 index1_prev = almo_scf_env%domain_map(1)%index1(idomain - 1)
1097 SELECT CASE (almo_scf_env%deloc_method)
1099 nneighbors(idomain) = 0
1101 nneighbors(idomain) = almo_scf_env%ndomains - 1
1103 nneighbors(idomain) = almo_scf_env%domain_map(1)%index1(idomain) - index1_prev - 1
1105 nneighbors(idomain) = -1
1110 sum_temp = sum(nneighbors(:))
1111 WRITE (unit_nr,
'(T2,A,T53,I5,F9.2,I5,I9)') &
1112 "Deloc. neighbors of fragment (min, av, max, total):", &
1113 minval(nneighbors(:)), &
1114 (1.0_dp*sum_temp)/almo_scf_env%ndomains, &
1115 maxval(nneighbors(:)), &
1118 WRITE (unit_nr,
'(T2,A)') repeat(
"-", 79)
1119 WRITE (unit_nr,
'()')
1121 IF (almo_scf_env%ndomains .LE. 64)
THEN
1124 WRITE (unit_nr,
'(T2,A10,A13,A13,A13,A13,A13)') &
1125 "Fragment",
"Basis Set",
"Occupied",
"Virtual",
"Charge",
"Deloc Neig"
1126 WRITE (unit_nr,
'(T2,A)') repeat(
"-", 79)
1127 DO idomain = 1, almo_scf_env%ndomains
1129 SELECT CASE (almo_scf_env%deloc_method)
1131 neig_string =
"NONE"
1135 WRITE (neig_string,
'(I13)') nneighbors(idomain)
1140 WRITE (unit_nr,
'(T2,I10,I13,I13,I13,I13,A13)') &
1141 idomain, almo_scf_env%nbasis_of_domain(idomain), &
1142 sum(almo_scf_env%nocc_of_domain(idomain, :)), &
1143 sum(almo_scf_env%nvirt_of_domain(idomain, :)), &
1145 almo_scf_env%charge_of_domain(idomain), &
1146 adjustr(trim(neig_string))
1150 SELECT CASE (almo_scf_env%deloc_method)
1153 WRITE (unit_nr,
'(T2,A)') repeat(
"-", 79)
1156 WRITE (unit_nr,
'(T2,A78)') &
1157 "Neighbor lists (including self)"
1158 WRITE (unit_nr,
'(T2,A)') repeat(
"-", 79)
1159 DO idomain = 1, almo_scf_env%ndomains
1161 IF (idomain .EQ. 1)
THEN
1164 index1_prev = almo_scf_env%domain_map(1)%index1(idomain - 1)
1167 WRITE (unit_nr,
'(T2,I10,":")') idomain
1168 WRITE (unit_nr,
'(T12,11I6)') &
1169 almo_scf_env%domain_map(1)%pairs &
1170 (index1_prev:almo_scf_env%domain_map(1)%index1(idomain) - 1, 1)
1178 WRITE (unit_nr,
'(T2,A)')
"The system is too big to print details for each fragment."
1182 WRITE (unit_nr,
'(T2,A)') repeat(
"-", 79)
1184 WRITE (unit_nr,
'()')
1186 DEALLOCATE (nneighbors)
1190 CALL timestop(handle)
1192 END SUBROUTINE almo_scf_print_job_info
1203 SUBROUTINE almo_scf_init_ao_overlap(matrix_s, almo_scf_env)
1207 CHARACTER(len=*),
PARAMETER :: routinen =
'almo_scf_init_ao_overlap'
1209 INTEGER :: handle, unit_nr
1212 CALL timeset(routinen, handle)
1216 IF (logger%para_env%is_source())
THEN
1224 IF (almo_scf_env%orthogonal_basis)
THEN
1225 CALL dbcsr_set(almo_scf_env%matrix_s(1), 0.0_dp)
1227 CALL dbcsr_set(almo_scf_env%matrix_s_blk(1), 0.0_dp)
1230 CALL matrix_qs_to_almo(matrix_s, almo_scf_env%matrix_s(1), almo_scf_env%mat_distr_aos)
1231 CALL dbcsr_copy(almo_scf_env%matrix_s_blk(1), &
1232 almo_scf_env%matrix_s(1), keep_sparsity=.true.)
1235 CALL dbcsr_filter(almo_scf_env%matrix_s(1), almo_scf_env%eps_filter)
1236 CALL dbcsr_filter(almo_scf_env%matrix_s_blk(1), almo_scf_env%eps_filter)
1238 IF (almo_scf_env%almo_update_algorithm .EQ.
almo_scf_diag)
THEN
1240 almo_scf_env%matrix_s_blk_sqrt_inv(1), &
1241 almo_scf_env%matrix_s_blk(1), &
1242 threshold=almo_scf_env%eps_filter, &
1243 order=almo_scf_env%order_lanczos, &
1245 eps_lanczos=almo_scf_env%eps_lanczos, &
1246 max_iter_lanczos=almo_scf_env%max_iter_lanczos)
1249 almo_scf_env%matrix_s_blk(1), &
1250 threshold=almo_scf_env%eps_filter, &
1251 filter_eps=almo_scf_env%eps_filter)
1254 CALL timestop(handle)
1256 END SUBROUTINE almo_scf_init_ao_overlap
1267 SUBROUTINE almo_scf_main(qs_env, almo_scf_env)
1271 CHARACTER(len=*),
PARAMETER :: routinen =
'almo_scf_main'
1273 INTEGER :: handle, ispin, unit_nr
1276 CALL timeset(routinen, handle)
1280 IF (logger%para_env%is_source())
THEN
1286 SELECT CASE (almo_scf_env%almo_update_algorithm)
1289 SELECT CASE (almo_scf_env%almo_update_algorithm)
1294 almo_scf_env=almo_scf_env, &
1295 optimizer=almo_scf_env%opt_block_diag_pcg, &
1296 quench_t=almo_scf_env%quench_t_blk, &
1297 matrix_t_in=almo_scf_env%matrix_t_blk, &
1298 matrix_t_out=almo_scf_env%matrix_t_blk, &
1299 assume_t0_q0x=.false., &
1300 perturbation_only=.false., &
1306 almo_scf_env=almo_scf_env, &
1307 optimizer=almo_scf_env%opt_block_diag_trustr, &
1308 quench_t=almo_scf_env%quench_t_blk, &
1309 matrix_t_in=almo_scf_env%matrix_t_blk, &
1310 matrix_t_out=almo_scf_env%matrix_t_blk, &
1311 perturbation_only=.false., &
1316 DO ispin = 1, almo_scf_env%nspins
1318 overlap=almo_scf_env%matrix_sigma_blk(ispin), &
1319 metric=almo_scf_env%matrix_s_blk(1), &
1320 retain_locality=.true., &
1321 only_normalize=.false., &
1322 nocc_of_domain=almo_scf_env%nocc_of_domain(:, ispin), &
1323 eps_filter=almo_scf_env%eps_filter, &
1324 order_lanczos=almo_scf_env%order_lanczos, &
1325 eps_lanczos=almo_scf_env%eps_lanczos, &
1326 max_iter_lanczos=almo_scf_env%max_iter_lanczos)
1333 almo_scf_env%opt_block_diag_diis)
1338 DO ispin = 1, almo_scf_env%nspins
1339 CALL dbcsr_copy(almo_scf_env%matrix_ks_0deloc(ispin), &
1340 almo_scf_env%matrix_ks(ispin))
1341 CALL dbcsr_copy(almo_scf_env%matrix_sigma_inv_0deloc(ispin), &
1342 almo_scf_env%matrix_sigma_inv(ispin))
1345 CALL timestop(handle)
1347 END SUBROUTINE almo_scf_main
1357 SUBROUTINE almo_scf_delocalization(qs_env, almo_scf_env)
1362 CHARACTER(len=*),
PARAMETER :: routinen =
'almo_scf_delocalization'
1364 INTEGER :: handle, ispin, unit_nr
1365 LOGICAL :: almo_experimental
1367 TYPE(
dbcsr_type),
ALLOCATABLE,
DIMENSION(:) :: no_quench
1370 CALL timeset(routinen, handle)
1374 IF (logger%para_env%is_source())
THEN
1385 arbitrary_optimizer%max_iter = 3
1386 arbitrary_optimizer%eps_error = 1.0e-6_dp
1387 arbitrary_optimizer%ndiis = 2
1389 SELECT CASE (almo_scf_env%deloc_method)
1396 ALLOCATE (no_quench(almo_scf_env%nspins))
1398 template=almo_scf_env%matrix_t(1), &
1399 matrix_type=dbcsr_type_no_symmetry)
1402 IF (almo_scf_env%nspins .GT. 1)
THEN
1403 DO ispin = 2, almo_scf_env%nspins
1405 template=almo_scf_env%matrix_t(1), &
1406 matrix_type=dbcsr_type_no_symmetry)
1407 CALL dbcsr_copy(no_quench(ispin), no_quench(1))
1413 SELECT CASE (almo_scf_env%deloc_method)
1416 DO ispin = 1, almo_scf_env%nspins
1417 CALL dbcsr_copy(almo_scf_env%matrix_t(ispin), &
1418 almo_scf_env%matrix_t_blk(ispin))
1446 IF (almo_scf_env%xalmo_update_algorithm .EQ.
almo_scf_pcg)
THEN
1449 almo_scf_env=almo_scf_env, &
1450 optimizer=almo_scf_env%opt_xalmo_pcg, &
1451 quench_t=no_quench, &
1452 matrix_t_in=almo_scf_env%matrix_t_blk, &
1453 matrix_t_out=almo_scf_env%matrix_t, &
1455 perturbation_only=.true., &
1458 ELSE IF (almo_scf_env%xalmo_update_algorithm .EQ.
almo_scf_trustr)
THEN
1461 almo_scf_env=almo_scf_env, &
1462 optimizer=almo_scf_env%opt_xalmo_trustr, &
1463 quench_t=no_quench, &
1464 matrix_t_in=almo_scf_env%matrix_t_blk, &
1465 matrix_t_out=almo_scf_env%matrix_t, &
1466 perturbation_only=.true., &
1471 cpabort(
"Other algorithms do not exist")
1477 IF (almo_scf_env%xalmo_update_algorithm .EQ.
almo_scf_diag)
THEN
1479 almo_scf_env%perturbative_delocalization = .true.
1480 DO ispin = 1, almo_scf_env%nspins
1481 CALL dbcsr_copy(almo_scf_env%matrix_t(ispin), &
1482 almo_scf_env%matrix_t_blk(ispin))
1485 arbitrary_optimizer)
1489 cpabort(
"Other algorithms do not exist")
1495 IF (almo_scf_env%xalmo_update_algorithm .EQ.
almo_scf_pcg)
THEN
1498 almo_scf_env=almo_scf_env, &
1499 optimizer=almo_scf_env%opt_xalmo_pcg, &
1500 quench_t=almo_scf_env%quench_t, &
1501 matrix_t_in=almo_scf_env%matrix_t_blk, &
1502 matrix_t_out=almo_scf_env%matrix_t, &
1504 perturbation_only=.true., &
1507 ELSE IF (almo_scf_env%xalmo_update_algorithm .EQ.
almo_scf_trustr)
THEN
1510 almo_scf_env=almo_scf_env, &
1511 optimizer=almo_scf_env%opt_xalmo_trustr, &
1512 quench_t=almo_scf_env%quench_t, &
1513 matrix_t_in=almo_scf_env%matrix_t_blk, &
1514 matrix_t_out=almo_scf_env%matrix_t, &
1515 perturbation_only=.true., &
1520 cpabort(
"Other algorithms do not exist")
1526 IF (almo_scf_env%xalmo_update_algorithm .EQ.
almo_scf_diag)
THEN
1528 cpabort(
"Should not be here: convergence will fail!")
1530 almo_scf_env%perturbative_delocalization = .false.
1531 DO ispin = 1, almo_scf_env%nspins
1532 CALL dbcsr_copy(almo_scf_env%matrix_t(ispin), &
1533 almo_scf_env%matrix_t_blk(ispin))
1536 arbitrary_optimizer)
1538 ELSE IF (almo_scf_env%xalmo_update_algorithm .EQ.
almo_scf_pcg)
THEN
1541 almo_scf_env=almo_scf_env, &
1542 optimizer=almo_scf_env%opt_xalmo_pcg, &
1543 quench_t=almo_scf_env%quench_t, &
1544 matrix_t_in=almo_scf_env%matrix_t_blk, &
1545 matrix_t_out=almo_scf_env%matrix_t, &
1547 perturbation_only=.false., &
1551 almo_experimental = .false.
1552 IF (almo_experimental)
THEN
1553 almo_scf_env%perturbative_delocalization = .true.
1559 arbitrary_optimizer)
1562 ELSE IF (almo_scf_env%xalmo_update_algorithm .EQ.
almo_scf_trustr)
THEN
1565 almo_scf_env=almo_scf_env, &
1566 optimizer=almo_scf_env%opt_xalmo_trustr, &
1567 quench_t=almo_scf_env%quench_t, &
1568 matrix_t_in=almo_scf_env%matrix_t_blk, &
1569 matrix_t_out=almo_scf_env%matrix_t, &
1570 perturbation_only=.false., &
1575 cpabort(
"Other algorithms do not exist")
1581 cpabort(
"Illegal delocalization method")
1585 SELECT CASE (almo_scf_env%deloc_method)
1588 IF (almo_scf_env%deloc_truncate_virt .NE.
virt_full)
THEN
1589 cpabort(
"full scf is NYI for truncated virtual space")
1592 IF (almo_scf_env%xalmo_update_algorithm .EQ.
almo_scf_pcg)
THEN
1595 almo_scf_env=almo_scf_env, &
1596 optimizer=almo_scf_env%opt_xalmo_pcg, &
1597 quench_t=no_quench, &
1598 matrix_t_in=almo_scf_env%matrix_t, &
1599 matrix_t_out=almo_scf_env%matrix_t, &
1600 assume_t0_q0x=.false., &
1601 perturbation_only=.false., &
1604 ELSE IF (almo_scf_env%xalmo_update_algorithm .EQ.
almo_scf_trustr)
THEN
1607 almo_scf_env=almo_scf_env, &
1608 optimizer=almo_scf_env%opt_xalmo_trustr, &
1609 quench_t=no_quench, &
1610 matrix_t_in=almo_scf_env%matrix_t, &
1611 matrix_t_out=almo_scf_env%matrix_t, &
1612 perturbation_only=.false., &
1617 cpabort(
"Other algorithms do not exist")
1624 SELECT CASE (almo_scf_env%deloc_method)
1626 DO ispin = 1, almo_scf_env%nspins
1629 DEALLOCATE (no_quench)
1632 CALL timestop(handle)
1634 END SUBROUTINE almo_scf_delocalization
1644 SUBROUTINE construct_nlmos(qs_env, almo_scf_env)
1651 IF (almo_scf_env%construct_nlmos)
THEN
1653 DO ispin = 1, almo_scf_env%nspins
1656 overlap=almo_scf_env%matrix_sigma(ispin), &
1657 metric=almo_scf_env%matrix_s(1), &
1658 retain_locality=.false., &
1659 only_normalize=.false., &
1660 nocc_of_domain=almo_scf_env%nocc_of_domain(:, ispin), &
1661 eps_filter=almo_scf_env%eps_filter, &
1662 order_lanczos=almo_scf_env%order_lanczos, &
1663 eps_lanczos=almo_scf_env%eps_lanczos, &
1664 max_iter_lanczos=almo_scf_env%max_iter_lanczos)
1667 CALL construct_nlmos_wrapper(qs_env, almo_scf_env, virtuals=.false.)
1669 IF (almo_scf_env%opt_nlmo_pcg%opt_penalty%virtual_nlmos)
THEN
1670 CALL construct_virtuals(almo_scf_env)
1671 CALL construct_nlmos_wrapper(qs_env, almo_scf_env, virtuals=.true.)
1674 IF (almo_scf_env%opt_nlmo_pcg%opt_penalty%compactification_filter_start .GT. 0.0_dp)
THEN
1675 CALL nlmo_compactification(qs_env, almo_scf_env, almo_scf_env%matrix_t)
1680 END SUBROUTINE construct_nlmos
1691 SUBROUTINE construct_nlmos_wrapper(qs_env, almo_scf_env, virtuals)
1695 LOGICAL,
INTENT(IN) :: virtuals
1697 REAL(kind=
dp) :: det_diff, prev_determinant
1699 almo_scf_env%overlap_determinant = 1.0
1701 almo_scf_env%opt_nlmo_pcg%opt_penalty%penalty_strength = &
1702 -1.0_dp*almo_scf_env%opt_nlmo_pcg%opt_penalty%penalty_strength
1705 prev_determinant = 10.0_dp
1706 DO WHILE (almo_scf_env%overlap_determinant .GT. almo_scf_env%opt_nlmo_pcg%opt_penalty%final_determinant)
1708 IF (.NOT. virtuals)
THEN
1710 optimizer=almo_scf_env%opt_nlmo_pcg, &
1711 matrix_s=almo_scf_env%matrix_s(1), &
1712 matrix_mo_in=almo_scf_env%matrix_t, &
1713 matrix_mo_out=almo_scf_env%matrix_t, &
1714 template_matrix_sigma=almo_scf_env%matrix_sigma_inv, &
1715 overlap_determinant=almo_scf_env%overlap_determinant, &
1716 mat_distr_aos=almo_scf_env%mat_distr_aos, &
1717 virtuals=virtuals, &
1718 eps_filter=almo_scf_env%eps_filter)
1721 optimizer=almo_scf_env%opt_nlmo_pcg, &
1722 matrix_s=almo_scf_env%matrix_s(1), &
1723 matrix_mo_in=almo_scf_env%matrix_v, &
1724 matrix_mo_out=almo_scf_env%matrix_v, &
1725 template_matrix_sigma=almo_scf_env%matrix_sigma_vv, &
1726 overlap_determinant=almo_scf_env%overlap_determinant, &
1727 mat_distr_aos=almo_scf_env%mat_distr_aos, &
1728 virtuals=virtuals, &
1729 eps_filter=almo_scf_env%eps_filter)
1733 det_diff = prev_determinant - almo_scf_env%overlap_determinant
1734 almo_scf_env%opt_nlmo_pcg%opt_penalty%penalty_strength = &
1735 almo_scf_env%opt_nlmo_pcg%opt_penalty%penalty_strength/ &
1736 abs(almo_scf_env%opt_nlmo_pcg%opt_penalty%penalty_strength_dec_factor)
1738 IF (det_diff < almo_scf_env%opt_nlmo_pcg%opt_penalty%determinant_tolerance)
THEN
1741 prev_determinant = almo_scf_env%overlap_determinant
1745 END SUBROUTINE construct_nlmos_wrapper
1754 SUBROUTINE construct_virtuals(almo_scf_env)
1759 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: eigenvalues
1760 TYPE(
dbcsr_type) :: tempnv1, tempvocc1, tempvocc2, tempvv1, &
1763 DO ispin = 1, almo_scf_env%nspins
1766 template=almo_scf_env%matrix_v(ispin), &
1767 matrix_type=dbcsr_type_no_symmetry)
1769 template=almo_scf_env%matrix_vo(ispin), &
1770 matrix_type=dbcsr_type_no_symmetry)
1772 template=almo_scf_env%matrix_vo(ispin), &
1773 matrix_type=dbcsr_type_no_symmetry)
1775 template=almo_scf_env%matrix_sigma_vv(ispin), &
1776 matrix_type=dbcsr_type_no_symmetry)
1778 template=almo_scf_env%matrix_sigma_vv(ispin), &
1779 matrix_type=dbcsr_type_no_symmetry)
1783 keep_sparsity=.false.)
1787 almo_scf_env%matrix_s(1), &
1788 almo_scf_env%matrix_v(ispin), &
1790 filter_eps=almo_scf_env%eps_filter)
1794 almo_scf_env%matrix_t(ispin), &
1795 0.0_dp, tempvocc1, &
1796 filter_eps=almo_scf_env%eps_filter)
1800 almo_scf_env%matrix_sigma_inv(ispin), &
1801 0.0_dp, tempvocc2, &
1802 filter_eps=almo_scf_env%eps_filter)
1805 almo_scf_env%matrix_t(ispin), &
1808 filter_eps=almo_scf_env%eps_filter)
1810 CALL dbcsr_add(almo_scf_env%matrix_v(ispin), tempnv1, 1.0_dp, -1.0_dp)
1814 almo_scf_env%matrix_s(1), &
1815 almo_scf_env%matrix_v(ispin), &
1817 filter_eps=almo_scf_env%eps_filter)
1820 almo_scf_env%matrix_v(ispin), &
1823 filter_eps=almo_scf_env%eps_filter)
1827 metric=almo_scf_env%matrix_s(1), &
1828 retain_locality=.false., &
1829 only_normalize=.false., &
1830 nocc_of_domain=almo_scf_env%nocc_of_domain(:, ispin), &
1831 eps_filter=almo_scf_env%eps_filter, &
1832 order_lanczos=almo_scf_env%order_lanczos, &
1833 eps_lanczos=almo_scf_env%eps_lanczos, &
1834 max_iter_lanczos=almo_scf_env%max_iter_lanczos)
1838 almo_scf_env%matrix_ks(ispin), &
1839 almo_scf_env%matrix_v(ispin), &
1841 filter_eps=almo_scf_env%eps_filter)
1844 almo_scf_env%matrix_v(ispin), &
1847 filter_eps=almo_scf_env%eps_filter)
1850 ALLOCATE (eigenvalues(n))
1853 para_env=almo_scf_env%para_env, &
1854 blacs_env=almo_scf_env%blacs_env)
1855 DEALLOCATE (eigenvalues)
1858 almo_scf_env%matrix_v(ispin), &
1861 filter_eps=almo_scf_env%eps_filter)
1863 CALL dbcsr_copy(almo_scf_env%matrix_v(ispin), tempnv1)
1873 END SUBROUTINE construct_virtuals
1884 SUBROUTINE nlmo_compactification(qs_env, almo_scf_env, matrix)
1888 TYPE(
dbcsr_type),
ALLOCATABLE,
DIMENSION(:), &
1889 INTENT(IN) :: matrix
1891 INTEGER :: iblock_col, iblock_col_size, iblock_row, &
1892 iblock_row_size, icol, irow, ispin, &
1893 ncols, nrows, nspins, unit_nr
1894 LOGICAL :: element_by_element
1895 REAL(kind=
dp) :: energy, eps_local, eps_start, &
1896 max_element, spin_factor
1897 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: occ, retained
1898 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: data_p
1901 TYPE(
dbcsr_type),
ALLOCATABLE,
DIMENSION(:) :: matrix_p_tmp, matrix_t_tmp
1906 IF (logger%para_env%is_source())
THEN
1912 nspins =
SIZE(matrix)
1913 element_by_element = .false.
1915 IF (nspins .EQ. 1)
THEN
1916 spin_factor = 2.0_dp
1918 spin_factor = 1.0_dp
1921 ALLOCATE (matrix_t_tmp(nspins))
1922 ALLOCATE (matrix_p_tmp(nspins))
1923 ALLOCATE (retained(nspins))
1926 DO ispin = 1, nspins
1930 template=matrix(ispin), &
1931 matrix_type=dbcsr_type_no_symmetry)
1932 CALL dbcsr_copy(matrix_t_tmp(ispin), matrix(ispin))
1935 template=almo_scf_env%matrix_p(ispin), &
1936 matrix_type=dbcsr_type_no_symmetry)
1937 CALL dbcsr_copy(matrix_p_tmp(ispin), almo_scf_env%matrix_p(ispin))
1941 IF (unit_nr > 0)
THEN
1943 WRITE (unit_nr,
'(T2,A)') &
1944 "Energy dependence on the (block-by-block) filtering of the NLMO coefficients"
1945 IF (unit_nr > 0)
WRITE (unit_nr,
'(T2,A13,A20,A20,A25)') &
1946 "EPS filter",
"Occupation Alpha",
"Occupation Beta",
"Energy"
1949 eps_start = almo_scf_env%opt_nlmo_pcg%opt_penalty%compactification_filter_start
1950 eps_local = max(eps_start, 10e-14_dp)
1954 IF (eps_local > 0.11_dp)
EXIT
1956 DO ispin = 1, nspins
1963 row_size=iblock_row_size, col_size=iblock_col_size)
1964 DO icol = 1, iblock_col_size
1966 IF (element_by_element)
THEN
1968 DO irow = 1, iblock_row_size
1969 IF (abs(data_p(irow, icol)) .LT. eps_local)
THEN
1970 data_p(irow, icol) = 0.0_dp
1972 retained(ispin) = retained(ispin) + 1
1978 max_element = 0.0_dp
1979 DO irow = 1, iblock_row_size
1980 IF (abs(data_p(irow, icol)) .GT. max_element)
THEN
1981 max_element = abs(data_p(irow, icol))
1984 IF (max_element .LT. eps_local)
THEN
1985 DO irow = 1, iblock_row_size
1986 data_p(irow, icol) = 0.0_dp
1989 retained(ispin) = retained(ispin) + iblock_row_size
2001 nfullrows_total=nrows, &
2002 nfullcols_total=ncols)
2003 CALL group%sum(retained(ispin))
2006 occ(ispin) = retained(ispin)/nrows/ncols
2010 t=matrix_t_tmp(ispin), &
2011 p=matrix_p_tmp(ispin), &
2012 eps_filter=almo_scf_env%eps_filter, &
2013 orthog_orbs=.false., &
2014 nocc_of_domain=almo_scf_env%nocc_of_domain(:, ispin), &
2015 s=almo_scf_env%matrix_s(1), &
2016 sigma=almo_scf_env%matrix_sigma(ispin), &
2017 sigma_inv=almo_scf_env%matrix_sigma_inv(ispin), &
2018 use_guess=.false., &
2019 algorithm=almo_scf_env%sigma_inv_algorithm, &
2020 inv_eps_factor=almo_scf_env%matrix_iter_eps_error_factor, &
2021 inverse_accelerator=almo_scf_env%order_lanczos, &
2022 eps_lanczos=almo_scf_env%eps_lanczos, &
2023 max_iter_lanczos=almo_scf_env%max_iter_lanczos, &
2024 para_env=almo_scf_env%para_env, &
2025 blacs_env=almo_scf_env%blacs_env)
2028 CALL dbcsr_scale(matrix_p_tmp(ispin), spin_factor)
2035 almo_scf_env%matrix_ks, &
2037 almo_scf_env%eps_filter, &
2038 almo_scf_env%mat_distr_aos)
2040 IF (nspins .LT. 2) occ(2) = occ(1)
2041 IF (unit_nr > 0)
WRITE (unit_nr,
'(T2,E13.3,F20.10,F20.10,F25.15)') &
2042 eps_local, occ(1), occ(2), energy
2044 eps_local = 2.0_dp*eps_local
2048 DO ispin = 1, nspins
2055 DEALLOCATE (matrix_t_tmp)
2056 DEALLOCATE (matrix_p_tmp)
2058 DEALLOCATE (retained)
2060 END SUBROUTINE nlmo_compactification
2071 SUBROUTINE almo_scf_post(qs_env, almo_scf_env)
2075 CHARACTER(len=*),
PARAMETER :: routinen =
'almo_scf_post'
2077 INTEGER :: handle, ispin
2080 TYPE(
dbcsr_type),
ALLOCATABLE,
DIMENSION(:) :: matrix_t_processed
2084 CALL timeset(routinen, handle)
2087 CALL almo_scf_store_extrapolation_data(almo_scf_env)
2090 ALLOCATE (matrix_t_processed(almo_scf_env%nspins))
2093 DO ispin = 1, almo_scf_env%nspins
2096 template=almo_scf_env%matrix_t(ispin), &
2097 matrix_type=dbcsr_type_no_symmetry)
2100 almo_scf_env%matrix_t(ispin))
2109 IF (almo_scf_env%return_orthogonalized_mos)
THEN
2112 overlap=almo_scf_env%matrix_sigma(ispin), &
2113 metric=almo_scf_env%matrix_s(1), &
2114 retain_locality=.false., &
2115 only_normalize=.false., &
2116 nocc_of_domain=almo_scf_env%nocc_of_domain(:, ispin), &
2117 eps_filter=almo_scf_env%eps_filter, &
2118 order_lanczos=almo_scf_env%order_lanczos, &
2119 eps_lanczos=almo_scf_env%eps_lanczos, &
2120 max_iter_lanczos=almo_scf_env%max_iter_lanczos, &
2121 smear=almo_scf_env%smear)
2137 NULLIFY (mos, mo_coeff, scf_env)
2139 CALL get_qs_env(qs_env, mos=mos, scf_env=scf_env)
2141 DO ispin = 1, almo_scf_env%nspins
2144 CALL get_mo_set(mos(ispin), mo_coeff=mo_coeff)
2148 DO ispin = 1, almo_scf_env%nspins
2151 DEALLOCATE (matrix_t_processed)
2155 CALL almo_post_scf_compute_properties(qs_env)
2158 IF (almo_scf_env%calc_forces)
THEN
2160 IF (
ASSOCIATED(matrix_w))
THEN
2163 cpabort(
"Matrix W is needed but not associated")
2167 CALL timestop(handle)
2169 END SUBROUTINE almo_scf_post
2179 SUBROUTINE almo_scf_env_create_matrices(almo_scf_env, matrix_s0)
2184 CHARACTER(len=*),
PARAMETER :: routinen =
'almo_scf_env_create_matrices'
2186 INTEGER :: handle, ispin, nspins
2188 CALL timeset(routinen, handle)
2190 nspins = almo_scf_env%nspins
2194 matrix_qs=matrix_s0, &
2195 almo_scf_env=almo_scf_env, &
2198 symmetry_new=dbcsr_type_symmetric, &
2200 init_domains=.false.)
2202 matrix_qs=matrix_s0, &
2203 almo_scf_env=almo_scf_env, &
2206 symmetry_new=dbcsr_type_symmetric, &
2208 init_domains=.true.)
2209 IF (almo_scf_env%almo_update_algorithm .EQ.
almo_scf_diag)
THEN
2211 matrix_qs=matrix_s0, &
2212 almo_scf_env=almo_scf_env, &
2213 name_new=
"S_BLK_SQRT_INV", &
2215 symmetry_new=dbcsr_type_symmetric, &
2217 init_domains=.true.)
2219 matrix_qs=matrix_s0, &
2220 almo_scf_env=almo_scf_env, &
2221 name_new=
"S_BLK_SQRT", &
2223 symmetry_new=dbcsr_type_symmetric, &
2225 init_domains=.true.)
2228 matrix_qs=matrix_s0, &
2229 almo_scf_env=almo_scf_env, &
2230 name_new=
"S_BLK_INV", &
2232 symmetry_new=dbcsr_type_symmetric, &
2234 init_domains=.true.)
2238 ALLOCATE (almo_scf_env%matrix_t_blk(nspins))
2239 ALLOCATE (almo_scf_env%quench_t_blk(nspins))
2240 ALLOCATE (almo_scf_env%matrix_err_blk(nspins))
2241 ALLOCATE (almo_scf_env%matrix_err_xx(nspins))
2242 ALLOCATE (almo_scf_env%matrix_sigma(nspins))
2243 ALLOCATE (almo_scf_env%matrix_sigma_inv(nspins))
2244 ALLOCATE (almo_scf_env%matrix_sigma_sqrt(nspins))
2245 ALLOCATE (almo_scf_env%matrix_sigma_sqrt_inv(nspins))
2246 ALLOCATE (almo_scf_env%matrix_sigma_blk(nspins))
2247 ALLOCATE (almo_scf_env%matrix_sigma_inv_0deloc(nspins))
2248 ALLOCATE (almo_scf_env%matrix_t(nspins))
2249 ALLOCATE (almo_scf_env%matrix_t_tr(nspins))
2250 DO ispin = 1, nspins
2253 matrix_qs=matrix_s0, &
2254 almo_scf_env=almo_scf_env, &
2257 symmetry_new=dbcsr_type_no_symmetry, &
2259 init_domains=.true.)
2262 matrix_qs=matrix_s0, &
2263 almo_scf_env=almo_scf_env, &
2266 symmetry_new=dbcsr_type_no_symmetry, &
2268 init_domains=.true.)
2271 matrix_qs=matrix_s0, &
2272 almo_scf_env=almo_scf_env, &
2273 name_new=
"ERR_BLK", &
2275 symmetry_new=dbcsr_type_no_symmetry, &
2277 init_domains=.true.)
2280 matrix_qs=matrix_s0, &
2281 almo_scf_env=almo_scf_env, &
2282 name_new=
"ERR_XX", &
2284 symmetry_new=dbcsr_type_no_symmetry, &
2286 init_domains=.false.)
2290 matrix_qs=matrix_s0, &
2291 almo_scf_env=almo_scf_env, &
2294 symmetry_new=dbcsr_type_no_symmetry, &
2296 init_domains=.false.)
2299 matrix_qs=matrix_s0, &
2300 almo_scf_env=almo_scf_env, &
2303 symmetry_new=dbcsr_type_symmetric, &
2305 init_domains=.false.)
2308 matrix_qs=matrix_s0, &
2309 almo_scf_env=almo_scf_env, &
2310 name_new=
"SIG_BLK", &
2312 symmetry_new=dbcsr_type_symmetric, &
2314 init_domains=.true.)
2317 matrix_qs=matrix_s0, &
2318 almo_scf_env=almo_scf_env, &
2319 name_new=
"SIGINV_BLK", &
2321 symmetry_new=dbcsr_type_symmetric, &
2323 init_domains=.true.)
2326 matrix_new=almo_scf_env%matrix_sigma_inv(ispin), &
2327 matrix_qs=matrix_s0, &
2328 almo_scf_env=almo_scf_env, &
2329 name_new=
"SIGINV", &
2331 symmetry_new=dbcsr_type_symmetric, &
2333 init_domains=.false.)
2336 matrix_new=almo_scf_env%matrix_t(ispin), &
2337 matrix_qs=matrix_s0, &
2338 almo_scf_env=almo_scf_env, &
2341 symmetry_new=dbcsr_type_no_symmetry, &
2343 init_domains=.false.)
2344 CALL dbcsr_create(almo_scf_env%matrix_sigma_sqrt(ispin), &
2345 template=almo_scf_env%matrix_sigma(ispin), &
2346 matrix_type=dbcsr_type_no_symmetry)
2347 CALL dbcsr_create(almo_scf_env%matrix_sigma_sqrt_inv(ispin), &
2348 template=almo_scf_env%matrix_sigma(ispin), &
2349 matrix_type=dbcsr_type_no_symmetry)
2353 IF (almo_scf_env%need_virtuals)
THEN
2354 ALLOCATE (almo_scf_env%matrix_v_blk(nspins))
2355 ALLOCATE (almo_scf_env%matrix_v_full_blk(nspins))
2356 ALLOCATE (almo_scf_env%matrix_v(nspins))
2357 ALLOCATE (almo_scf_env%matrix_vo(nspins))
2358 ALLOCATE (almo_scf_env%matrix_x(nspins))
2359 ALLOCATE (almo_scf_env%matrix_ov(nspins))
2360 ALLOCATE (almo_scf_env%matrix_ov_full(nspins))
2361 ALLOCATE (almo_scf_env%matrix_sigma_vv(nspins))
2362 ALLOCATE (almo_scf_env%matrix_sigma_vv_blk(nspins))
2363 ALLOCATE (almo_scf_env%matrix_sigma_vv_sqrt(nspins))
2364 ALLOCATE (almo_scf_env%matrix_sigma_vv_sqrt_inv(nspins))
2365 ALLOCATE (almo_scf_env%matrix_vv_full_blk(nspins))
2367 IF (almo_scf_env%deloc_truncate_virt .NE.
virt_full)
THEN
2368 ALLOCATE (almo_scf_env%matrix_k_blk(nspins))
2369 ALLOCATE (almo_scf_env%matrix_k_blk_ones(nspins))
2370 ALLOCATE (almo_scf_env%matrix_k_tr(nspins))
2371 ALLOCATE (almo_scf_env%matrix_v_disc(nspins))
2372 ALLOCATE (almo_scf_env%matrix_v_disc_blk(nspins))
2373 ALLOCATE (almo_scf_env%matrix_ov_disc(nspins))
2374 ALLOCATE (almo_scf_env%matrix_vv_disc_blk(nspins))
2375 ALLOCATE (almo_scf_env%matrix_vv_disc(nspins))
2376 ALLOCATE (almo_scf_env%opt_k_t_dd(nspins))
2377 ALLOCATE (almo_scf_env%opt_k_t_rr(nspins))
2378 ALLOCATE (almo_scf_env%opt_k_denom(nspins))
2381 DO ispin = 1, nspins
2383 matrix_qs=matrix_s0, &
2384 almo_scf_env=almo_scf_env, &
2385 name_new=
"V_FULL_BLK", &
2387 symmetry_new=dbcsr_type_no_symmetry, &
2389 init_domains=.false.)
2391 matrix_qs=matrix_s0, &
2392 almo_scf_env=almo_scf_env, &
2395 symmetry_new=dbcsr_type_no_symmetry, &
2397 init_domains=.false.)
2399 matrix_qs=matrix_s0, &
2400 almo_scf_env=almo_scf_env, &
2403 symmetry_new=dbcsr_type_no_symmetry, &
2405 init_domains=.false.)
2407 matrix_qs=matrix_s0, &
2408 almo_scf_env=almo_scf_env, &
2409 name_new=
"OV_FULL", &
2411 symmetry_new=dbcsr_type_no_symmetry, &
2413 init_domains=.false.)
2415 matrix_qs=matrix_s0, &
2416 almo_scf_env=almo_scf_env, &
2419 symmetry_new=dbcsr_type_no_symmetry, &
2421 init_domains=.false.)
2423 matrix_qs=matrix_s0, &
2424 almo_scf_env=almo_scf_env, &
2427 symmetry_new=dbcsr_type_no_symmetry, &
2429 init_domains=.false.)
2431 matrix_qs=matrix_s0, &
2432 almo_scf_env=almo_scf_env, &
2435 symmetry_new=dbcsr_type_no_symmetry, &
2437 init_domains=.false.)
2439 matrix_qs=matrix_s0, &
2440 almo_scf_env=almo_scf_env, &
2441 name_new=
"SIG_VV", &
2443 symmetry_new=dbcsr_type_symmetric, &
2445 init_domains=.false.)
2447 matrix_qs=matrix_s0, &
2448 almo_scf_env=almo_scf_env, &
2449 name_new=
"VV_FULL_BLK", &
2451 symmetry_new=dbcsr_type_no_symmetry, &
2453 init_domains=.true.)
2455 matrix_qs=matrix_s0, &
2456 almo_scf_env=almo_scf_env, &
2457 name_new=
"SIG_VV_BLK", &
2459 symmetry_new=dbcsr_type_symmetric, &
2461 init_domains=.true.)
2462 CALL dbcsr_create(almo_scf_env%matrix_sigma_vv_sqrt(ispin), &
2463 template=almo_scf_env%matrix_sigma_vv(ispin), &
2464 matrix_type=dbcsr_type_no_symmetry)
2465 CALL dbcsr_create(almo_scf_env%matrix_sigma_vv_sqrt_inv(ispin), &
2466 template=almo_scf_env%matrix_sigma_vv(ispin), &
2467 matrix_type=dbcsr_type_no_symmetry)
2469 IF (almo_scf_env%deloc_truncate_virt .NE.
virt_full)
THEN
2471 matrix_qs=matrix_s0, &
2472 almo_scf_env=almo_scf_env, &
2473 name_new=
"OPT_K_U_RR", &
2475 symmetry_new=dbcsr_type_no_symmetry, &
2477 init_domains=.false.)
2479 matrix_qs=matrix_s0, &
2480 almo_scf_env=almo_scf_env, &
2481 name_new=
"VV_DISC", &
2483 symmetry_new=dbcsr_type_symmetric, &
2485 init_domains=.false.)
2487 matrix_qs=matrix_s0, &
2488 almo_scf_env=almo_scf_env, &
2489 name_new=
"OPT_K_U_DD", &
2491 symmetry_new=dbcsr_type_no_symmetry, &
2493 init_domains=.false.)
2495 matrix_qs=matrix_s0, &
2496 almo_scf_env=almo_scf_env, &
2497 name_new=
"VV_DISC_BLK", &
2499 symmetry_new=dbcsr_type_symmetric, &
2501 init_domains=.true.)
2503 matrix_qs=matrix_s0, &
2504 almo_scf_env=almo_scf_env, &
2507 symmetry_new=dbcsr_type_no_symmetry, &
2509 init_domains=.true.)
2511 matrix_qs=matrix_s0, &
2512 almo_scf_env=almo_scf_env, &
2513 name_new=
"K_BLK_1", &
2515 symmetry_new=dbcsr_type_no_symmetry, &
2517 init_domains=.true.)
2519 matrix_qs=matrix_s0, &
2520 almo_scf_env=almo_scf_env, &
2521 name_new=
"OPT_K_DENOM", &
2523 symmetry_new=dbcsr_type_no_symmetry, &
2525 init_domains=.false.)
2527 matrix_qs=matrix_s0, &
2528 almo_scf_env=almo_scf_env, &
2531 symmetry_new=dbcsr_type_no_symmetry, &
2533 init_domains=.false.)
2535 matrix_qs=matrix_s0, &
2536 almo_scf_env=almo_scf_env, &
2537 name_new=
"V_DISC_BLK", &
2539 symmetry_new=dbcsr_type_no_symmetry, &
2541 init_domains=.false.)
2543 matrix_qs=matrix_s0, &
2544 almo_scf_env=almo_scf_env, &
2545 name_new=
"V_DISC", &
2547 symmetry_new=dbcsr_type_no_symmetry, &
2549 init_domains=.false.)
2551 matrix_qs=matrix_s0, &
2552 almo_scf_env=almo_scf_env, &
2553 name_new=
"OV_DISC", &
2555 symmetry_new=dbcsr_type_no_symmetry, &
2557 init_domains=.false.)
2565 IF (almo_scf_env%need_orbital_energies)
THEN
2566 ALLOCATE (almo_scf_env%matrix_eoo(nspins))
2567 ALLOCATE (almo_scf_env%matrix_evv_full(nspins))
2568 DO ispin = 1, nspins
2570 matrix_qs=matrix_s0, &
2571 almo_scf_env=almo_scf_env, &
2574 symmetry_new=dbcsr_type_no_symmetry, &
2576 init_domains=.false.)
2578 matrix_qs=matrix_s0, &
2579 almo_scf_env=almo_scf_env, &
2580 name_new=
"E_VIRT", &
2582 symmetry_new=dbcsr_type_no_symmetry, &
2584 init_domains=.false.)
2589 ALLOCATE (almo_scf_env%matrix_p(nspins))
2590 ALLOCATE (almo_scf_env%matrix_p_blk(nspins))
2591 ALLOCATE (almo_scf_env%matrix_ks(nspins))
2592 ALLOCATE (almo_scf_env%matrix_ks_blk(nspins))
2593 IF (almo_scf_env%need_previous_ks) &
2594 ALLOCATE (almo_scf_env%matrix_ks_0deloc(nspins))
2595 DO ispin = 1, nspins
2598 template=almo_scf_env%matrix_s(1), &
2599 matrix_type=dbcsr_type_symmetric)
2601 template=almo_scf_env%matrix_s(1), &
2602 matrix_type=dbcsr_type_symmetric)
2603 IF (almo_scf_env%need_previous_ks)
THEN
2604 CALL dbcsr_create(almo_scf_env%matrix_ks_0deloc(ispin), &
2605 template=almo_scf_env%matrix_s(1), &
2606 matrix_type=dbcsr_type_symmetric)
2609 matrix_qs=matrix_s0, &
2610 almo_scf_env=almo_scf_env, &
2613 symmetry_new=dbcsr_type_symmetric, &
2615 init_domains=.true.)
2617 matrix_qs=matrix_s0, &
2618 almo_scf_env=almo_scf_env, &
2619 name_new=
"KS_BLK", &
2621 symmetry_new=dbcsr_type_symmetric, &
2623 init_domains=.true.)
2626 CALL timestop(handle)
2628 END SUBROUTINE almo_scf_env_create_matrices
2638 SUBROUTINE almo_scf_clean_up(almo_scf_env)
2642 CHARACTER(len=*),
PARAMETER :: routinen =
'almo_scf_clean_up'
2644 INTEGER :: handle, ispin, unit_nr
2647 CALL timeset(routinen, handle)
2651 IF (logger%para_env%is_source())
THEN
2660 IF (almo_scf_env%almo_update_algorithm .EQ.
almo_scf_diag)
THEN
2666 DO ispin = 1, almo_scf_env%nspins
2675 CALL dbcsr_release(almo_scf_env%matrix_sigma_inv_0deloc(ispin))
2679 CALL dbcsr_release(almo_scf_env%matrix_sigma_sqrt_inv(ispin))
2684 IF (almo_scf_env%need_previous_ks)
THEN
2687 IF (almo_scf_env%need_virtuals)
THEN
2697 CALL dbcsr_release(almo_scf_env%matrix_sigma_vv_sqrt(ispin))
2698 CALL dbcsr_release(almo_scf_env%matrix_sigma_vv_sqrt_inv(ispin))
2700 IF (almo_scf_env%deloc_truncate_virt .NE.
virt_full)
THEN
2714 IF (almo_scf_env%need_orbital_energies)
THEN
2721 DEALLOCATE (almo_scf_env%matrix_p)
2722 DEALLOCATE (almo_scf_env%matrix_p_blk)
2723 DEALLOCATE (almo_scf_env%matrix_ks)
2724 DEALLOCATE (almo_scf_env%matrix_ks_blk)
2725 DEALLOCATE (almo_scf_env%matrix_t_blk)
2726 DEALLOCATE (almo_scf_env%matrix_err_blk)
2727 DEALLOCATE (almo_scf_env%matrix_err_xx)
2728 DEALLOCATE (almo_scf_env%matrix_t)
2729 DEALLOCATE (almo_scf_env%matrix_t_tr)
2730 DEALLOCATE (almo_scf_env%matrix_sigma)
2731 DEALLOCATE (almo_scf_env%matrix_sigma_blk)
2732 DEALLOCATE (almo_scf_env%matrix_sigma_inv_0deloc)
2733 DEALLOCATE (almo_scf_env%matrix_sigma_sqrt)
2734 DEALLOCATE (almo_scf_env%matrix_sigma_sqrt_inv)
2735 DEALLOCATE (almo_scf_env%matrix_sigma_inv)
2736 DEALLOCATE (almo_scf_env%quench_t)
2737 DEALLOCATE (almo_scf_env%quench_t_blk)
2738 IF (almo_scf_env%need_virtuals)
THEN
2739 DEALLOCATE (almo_scf_env%matrix_v_blk)
2740 DEALLOCATE (almo_scf_env%matrix_v_full_blk)
2741 DEALLOCATE (almo_scf_env%matrix_v)
2742 DEALLOCATE (almo_scf_env%matrix_vo)
2743 DEALLOCATE (almo_scf_env%matrix_x)
2744 DEALLOCATE (almo_scf_env%matrix_ov)
2745 DEALLOCATE (almo_scf_env%matrix_ov_full)
2746 DEALLOCATE (almo_scf_env%matrix_sigma_vv)
2747 DEALLOCATE (almo_scf_env%matrix_sigma_vv_blk)
2748 DEALLOCATE (almo_scf_env%matrix_sigma_vv_sqrt)
2749 DEALLOCATE (almo_scf_env%matrix_sigma_vv_sqrt_inv)
2750 DEALLOCATE (almo_scf_env%matrix_vv_full_blk)
2751 IF (almo_scf_env%deloc_truncate_virt .NE.
virt_full)
THEN
2752 DEALLOCATE (almo_scf_env%matrix_k_tr)
2753 DEALLOCATE (almo_scf_env%matrix_k_blk)
2754 DEALLOCATE (almo_scf_env%matrix_v_disc)
2755 DEALLOCATE (almo_scf_env%matrix_v_disc_blk)
2756 DEALLOCATE (almo_scf_env%matrix_ov_disc)
2757 DEALLOCATE (almo_scf_env%matrix_vv_disc_blk)
2758 DEALLOCATE (almo_scf_env%matrix_vv_disc)
2759 DEALLOCATE (almo_scf_env%matrix_k_blk_ones)
2760 DEALLOCATE (almo_scf_env%opt_k_t_dd)
2761 DEALLOCATE (almo_scf_env%opt_k_t_rr)
2762 DEALLOCATE (almo_scf_env%opt_k_denom)
2765 IF (almo_scf_env%need_previous_ks)
THEN
2766 DEALLOCATE (almo_scf_env%matrix_ks_0deloc)
2768 IF (almo_scf_env%need_orbital_energies)
THEN
2769 DEALLOCATE (almo_scf_env%matrix_eoo)
2770 DEALLOCATE (almo_scf_env%matrix_evv_full)
2774 DO ispin = 1, almo_scf_env%nspins
2776 almo_scf_env%domain_preconditioner(:, ispin))
2785 DEALLOCATE (almo_scf_env%domain_preconditioner)
2786 DEALLOCATE (almo_scf_env%domain_s_inv)
2787 DEALLOCATE (almo_scf_env%domain_s_sqrt_inv)
2788 DEALLOCATE (almo_scf_env%domain_s_sqrt)
2789 DEALLOCATE (almo_scf_env%domain_ks_xx)
2790 DEALLOCATE (almo_scf_env%domain_t)
2791 DEALLOCATE (almo_scf_env%domain_err)
2792 DEALLOCATE (almo_scf_env%domain_r_down_up)
2793 DO ispin = 1, almo_scf_env%nspins
2794 DEALLOCATE (almo_scf_env%domain_map(ispin)%pairs)
2795 DEALLOCATE (almo_scf_env%domain_map(ispin)%index1)
2797 DEALLOCATE (almo_scf_env%domain_map)
2798 DEALLOCATE (almo_scf_env%domain_index_of_ao)
2799 DEALLOCATE (almo_scf_env%domain_index_of_atom)
2800 DEALLOCATE (almo_scf_env%first_atom_of_domain)
2801 DEALLOCATE (almo_scf_env%last_atom_of_domain)
2802 DEALLOCATE (almo_scf_env%nbasis_of_domain)
2803 DEALLOCATE (almo_scf_env%nocc_of_domain)
2804 DEALLOCATE (almo_scf_env%real_ne_of_domain)
2805 DEALLOCATE (almo_scf_env%nvirt_full_of_domain)
2806 DEALLOCATE (almo_scf_env%nvirt_of_domain)
2807 DEALLOCATE (almo_scf_env%nvirt_disc_of_domain)
2808 DEALLOCATE (almo_scf_env%mu_of_domain)
2809 DEALLOCATE (almo_scf_env%cpu_of_domain)
2810 DEALLOCATE (almo_scf_env%charge_of_domain)
2811 DEALLOCATE (almo_scf_env%multiplicity_of_domain)
2812 IF (almo_scf_env%smear)
THEN
2813 DEALLOCATE (almo_scf_env%mo_energies)
2814 DEALLOCATE (almo_scf_env%kTS)
2817 DEALLOCATE (almo_scf_env%domain_index_of_ao_block)
2818 DEALLOCATE (almo_scf_env%domain_index_of_mo_block)
2823 CALL timestop(handle)
2825 END SUBROUTINE almo_scf_clean_up
2836 SUBROUTINE almo_post_scf_compute_properties(qs_env)
2841 END SUBROUTINE almo_post_scf_compute_properties
Subroutines for ALMO SCF.
subroutine, public distribute_domains(almo_scf_env)
Load balancing of the submatrix computations.
subroutine, public almo_scf_p_blk_to_t_blk(almo_scf_env, ionic)
computes occupied ALMOs from the superimposed atomic density blocks
subroutine, public almo_scf_t_to_proj(t, p, eps_filter, orthog_orbs, nocc_of_domain, s, sigma, sigma_inv, use_guess, smear, algorithm, para_env, blacs_env, eps_lanczos, max_iter_lanczos, inverse_accelerator, inv_eps_factor)
computes the idempotent density matrix from MOs MOs can be either orthogonal or non-orthogonal
subroutine, public orthogonalize_mos(ket, overlap, metric, retain_locality, only_normalize, nocc_of_domain, eps_filter, order_lanczos, eps_lanczos, max_iter_lanczos, overlap_sqrti, smear)
orthogonalize MOs
subroutine, public almo_scf_t_rescaling(matrix_t, mo_energies, mu_of_domain, real_ne_of_domain, spin_kts, smear_e_temp, ndomains, nocc_of_domain)
Apply an occupation-rescaling trick to ALMOs for smearing. Partially occupied orbitals are considered...
Optimization routines for all ALMO-based SCF methods.
subroutine, public almo_scf_xalmo_trustr(qs_env, almo_scf_env, optimizer, quench_t, matrix_t_in, matrix_t_out, perturbation_only, special_case)
Optimization of ALMOs using trust region minimizers.
subroutine, public almo_scf_xalmo_pcg(qs_env, almo_scf_env, optimizer, quench_t, matrix_t_in, matrix_t_out, assume_t0_q0x, perturbation_only, special_case)
Optimization of ALMOs using PCG-like minimizers.
subroutine, public almo_scf_xalmo_eigensolver(qs_env, almo_scf_env, optimizer)
An eigensolver-based SCF to optimize extended ALMOs (i.e. ALMOs on overlapping domains)
subroutine, public almo_scf_construct_nlmos(qs_env, optimizer, matrix_s, matrix_mo_in, matrix_mo_out, template_matrix_sigma, overlap_determinant, mat_distr_aos, virtuals, eps_filter)
Optimization of NLMOs using PCG minimizers.
subroutine, public almo_scf_block_diagonal(qs_env, almo_scf_env, optimizer)
An SCF procedure that optimizes block-diagonal ALMOs using DIIS.
Interface between ALMO SCF and QS.
subroutine, public construct_qs_mos(qs_env, almo_scf_env)
Create MOs in the QS env to be able to return ALMOs to QS.
subroutine, public almo_dm_to_almo_ks(qs_env, matrix_p, matrix_ks, energy_total, eps_filter, mat_distr_aos, smear, kts_sum)
uses the ALMO density matrix to compute ALMO KS matrix and the new energy
subroutine, public calculate_w_matrix_almo(matrix_w, almo_scf_env)
Compute matrix W (energy-weighted density matrix) that is needed for the evaluation of forces.
subroutine, public matrix_almo_create(matrix_new, matrix_qs, almo_scf_env, name_new, size_keys, symmetry_new, spin_key, init_domains)
create the ALMO matrix templates
subroutine, public init_almo_ks_matrix_via_qs(qs_env, matrix_ks, mat_distr_aos, eps_filter)
Initialization of the QS and ALMO KS matrix.
subroutine, public matrix_qs_to_almo(matrix_qs, matrix_almo, mat_distr_aos)
convert between two types of matrices: QS style to ALMO style
subroutine, public almo_scf_construct_quencher(qs_env, almo_scf_env)
Creates the matrix that imposes absolute locality on MOs.
Types for all ALMO-based methods.
integer, parameter, public almo_mat_dim_occ
integer, parameter, public almo_mat_dim_virt_full
integer, parameter, public almo_mat_dim_aobasis
subroutine, public print_optimizer_options(optimizer, unit_nr)
Prints out the options of an optimizer.
integer, parameter, public almo_mat_dim_virt
integer, parameter, public almo_mat_dim_virt_disc
Routines for all ALMO-based SCF methods 'RZK-warning' marks unresolved issues.
subroutine, public almo_entry_scf(qs_env, calc_forces)
The entry point into ALMO SCF routines.
Define the atomic kind types and their sub types.
collects all references to literature in CP2K as new algorithms / method are included from literature...
integer, save, public scheiber2018
integer, save, public kuhne2007
integer, save, public staub2019
integer, save, public khaliullin2013
integer, save, public kolafa2004
methods related to the blacs parallel environment
subroutine, public cp_blacs_env_release(blacs_env)
releases the given blacs_env
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
subroutine, public dbcsr_scale(matrix, alpha_scalar)
...
subroutine, public dbcsr_iterator_next_block(iterator, row, column, block, block_number_argument_has_been_removed, row_size, col_size, row_offset, col_offset)
...
logical function, public dbcsr_iterator_blocks_left(iterator)
...
subroutine, public dbcsr_iterator_stop(iterator)
...
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_work_create(matrix, nblks_guess, sizedata_guess, n, work_mutable)
...
subroutine, public dbcsr_filter(matrix, eps)
...
subroutine, public dbcsr_finalize(matrix)
...
subroutine, public dbcsr_iterator_start(iterator, matrix, shared, dynamic, dynamic_byrows)
...
subroutine, public dbcsr_set(matrix, alpha)
...
subroutine, public dbcsr_release(matrix)
...
subroutine, public dbcsr_binary_read(filepath, distribution, matrix_new)
...
subroutine, public dbcsr_add(matrix_a, matrix_b, alpha_scalar, beta_scalar)
...
real(kind=dp) function, public dbcsr_checksum(matrix, pos)
Calculates the checksum of a DBCSR matrix.
subroutine, public dbcsr_add_on_diag(matrix, alpha)
Adds the given scalar to the diagonal of the matrix. Reserves any missing diagonal blocks.
subroutine, public dbcsr_reserve_all_blocks(matrix)
Reserves all blocks.
subroutine, public dbcsr_init_random(matrix, keep_sparsity)
Fills the given matrix with random numbers.
Interface to (sca)lapack for the Cholesky based procedures.
subroutine, public cp_dbcsr_syevd(matrix, eigenvectors, eigenvalues, para_env, blacs_env)
...
DBCSR operations in CP2K.
subroutine, public copy_dbcsr_to_fm(matrix, fm)
Copy a DBCSR matrix to a BLACS matrix.
represent a full matrix distributed on many processors
various routines to log and control the output. The idea is that decisions about where to log should ...
recursive integer function, public cp_logger_get_default_unit_nr(logger, local, skip_not_ionode)
asks the default unit number of the given logger. try to use cp_logger_get_unit_nr
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
Subroutines to handle submatrices.
Routines useful for iterative matrix calculations.
subroutine, public invert_hotelling(matrix_inverse, matrix, threshold, use_inv_as_guess, norm_convergence, filter_eps, accelerator_order, max_iter_lanczos, eps_lanczos, silent)
invert a symmetric positive definite matrix by Hotelling's method explicit symmetrization makes this ...
subroutine, public matrix_sqrt_newton_schulz(matrix_sqrt, matrix_sqrt_inv, matrix, threshold, order, eps_lanczos, max_iter_lanczos, symmetrize, converged, iounit)
compute the sqrt of a matrix via the sign function and the corresponding Newton-Schulz iterations the...
Defines the basic variable types.
integer, parameter, public dp
integer, parameter, public default_path_length
Collection of simple mathematical functions and subroutines.
elemental real(kind=dp) function, public binomial(n, k)
The binomial coefficient n over k for 0 <= k <= n is calculated, otherwise zero is returned.
Interface to the message passing library MPI.
subroutine, public mp_para_env_release(para_env)
releases the para object (to be called when you don't want anymore the shared copy of this object)
Define the data structure for the molecule information.
subroutine, public get_molecule_set_info(molecule_set, atom_to_mol, mol_to_first_atom, mol_to_last_atom, mol_to_nelectrons, mol_to_nbasis, mol_to_charge, mol_to_multiplicity)
returns information about molecules in the set.
Types used to generate the molecular SCF guess.
subroutine, public get_matrix_from_submatrices(mscfg_env, matrix_out, iset)
Creates a distributed matrix from MOs on fragments.
Define the data structure for the particle information.
Routine to return block diagonal density matrix. Blocks correspond to the atomic densities.
subroutine, public calculate_atomic_block_dm(pmatrix, matrix_s, atomic_kind_set, qs_kind_set, nspin, nelectron_spin, ounit, para_env)
returns a block diagonal density matrix. Blocks correspond to the atomic densities.
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, 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, particle_set, energy, force, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, 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, ecoul_1c, rho0_s_rs, rho0_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)
Get the QUICKSTEP environment.
Routines to somehow generate an initial guess.
subroutine, public calculate_mopac_dm(pmat, matrix_s, has_unit_metric, dft_control, particle_set, atomic_kind_set, qs_kind_set, nspin, nelectron_spin, para_env)
returns a block diagonal density matrix. Blocks correspond to the mopac initial guess.
Define the quickstep kind type and their sub types.
Definition and initialisation of the mo data type.
subroutine, public get_mo_set(mo_set, maxocc, homo, lfomo, nao, nelectron, n_el_f, nmo, eigenvalues, occupation_numbers, mo_coeff, mo_coeff_b, uniform_occupation, kts, mu, flexible_electron_count)
Get the components of a MO set data structure.
superstucture that hold various representations of the density and keeps track of which ones are vali...
subroutine, public qs_rho_get(rho_struct, rho_ao, rho_ao_im, rho_ao_kp, rho_ao_im_kp, rho_r, drho_r, rho_g, drho_g, tau_r, tau_g, rho_r_valid, drho_r_valid, rho_g_valid, drho_g_valid, tau_r_valid, tau_g_valid, tot_rho_r, tot_rho_g, rho_r_sccs, soft_valid, complex_rho_ao)
returns info about the density described by this object. If some representation is not available an e...
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
module that contains the definitions of the scf types
Provides all information about an atomic kind.
type of a logger, at the moment it contains just a print level starting at which level it should be l...
stores all the informations relevant to an mpi environment
Provides all information about a quickstep kind.
keeps the density in various representations, keeping track of which ones are valid.