74 USE iso_c_binding,
ONLY: c_null_char
184#include "./base/base_uses.f90"
189 CHARACTER(LEN=*),
PARAMETER,
PRIVATE :: moduleN =
'qs_active_space_methods'
194 INTEGER :: unit_nr = -1, bra_start = -1, ket_start = -1
195 INTEGER :: nalpha = 0, nbeta = 0
196 REAL(KIND=
dp) :: determinant_energy = 0.0_dp
198 PROCEDURE :: func => eri_fcidump_print_func
199 END TYPE eri_fcidump_print
202 INTEGER :: bra_start = 0, ket_start = 0
203 REAL(KIND=
dp) :: checksum = 0.0_dp
206 PROCEDURE :: func => eri_fcidump_checksum_func
207 END TYPE eri_fcidump_checksum
218 CLASS(eri_fcidump_checksum) :: this
219 INTEGER,
INTENT(IN) :: bra_start, ket_start
221 this%bra_start = bra_start
222 this%ket_start = ket_start
232 CHARACTER(LEN=*),
PARAMETER :: routinen =
'active_space_main'
234 CHARACTER(LEN=10) :: cshell, lnam(5)
235 CHARACTER(LEN=default_path_length) :: qcschema_filename
236 CHARACTER(LEN=default_string_length) :: basis_type, kp_scheme
237 INTEGER :: as_solver, eri_method, eri_operator, eri_print, group_size, handle, i, iatom, &
238 ishell, isp, ispin, iw, j, jm, m, max_orb_ind, mselect, n1, n2, nao, natom, nel, &
239 nelec_active, nelec_inactive, nelec_total, nkp, nmo, nmo_active, nmo_available, &
240 nmo_inactive, nmo_inactive_remaining, nmo_occ, nmo_virtual, nn1, nn2, nrow_global, nspins
241 INTEGER,
DIMENSION(5) :: nshell
242 INTEGER,
DIMENSION(:),
POINTER :: invals
243 LOGICAL :: do_ddapc, do_kpoints, ex_omega, &
244 ex_operator, ex_perd, ex_rcut, &
245 explicit, stop_after_print, store_wfn, &
247 REAL(kind=
dp) :: eri_eps_filter, eri_eps_grid, eri_eps_int, eri_gpw_cutoff, eri_op_omega, &
248 eri_rcut, eri_rel_cutoff, fel, focc, max_offdiag, maxocc, nze_percentage
249 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: eigenvalues
250 REAL(kind=
dp),
DIMENSION(:),
POINTER :: evals_virtual
257 TYPE(
cp_fm_type),
POINTER :: fm_target_active, fm_target_inactive, &
258 fmat, mo_coeff, mo_ref, mo_target
261 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: ks_matrix, rho_ao, s_matrix
262 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: ks_matrix_kp, rho_ao_kp, s_matrix_kp
267 TYPE(
mo_set_type),
POINTER :: mo_set, mo_set_active, mo_set_inactive
273 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
278 hfx_section, input, loc_print, &
279 loc_section, print_orb, xc_section
286 IF (.NOT. explicit)
RETURN
287 CALL timeset(routinen, handle)
293 WRITE (iw,
'(/,T2,A)') &
294 '!-----------------------------------------------------------------------------!'
295 WRITE (iw,
'(T26,A)')
"Active Space Embedding Module"
296 WRITE (iw,
'(T2,A)') &
297 '!-----------------------------------------------------------------------------!'
302 CALL get_qs_env(qs_env, do_kpoints=do_kpoints, dft_control=dft_control, kpoints=kpoints)
304 IF (.NOT.
ASSOCIATED(kpoints))
THEN
305 CALL cp_abort(__location__,
"Missing Gamma-point environment for active space module")
307 CALL get_kpoint_info(kpoints, kp_scheme=kp_scheme, nkp=nkp, use_real_wfn=use_real_wfn)
308 IF (trim(kp_scheme) /=
"GAMMA" .OR. nkp /= 1 .OR. .NOT. use_real_wfn)
THEN
309 CALL cp_abort(__location__, &
310 "Only Gamma-point DFT%KPOINTS are supported in the active space module")
312 IF (.NOT.
ASSOCIATED(kpoints%kp_env))
THEN
313 CALL cp_abort(__location__,
"Missing Gamma-point environment for active space module")
315 IF (.NOT.
ASSOCIATED(kpoints%kp_env(1)%kpoint_env))
THEN
316 CALL cp_abort(__location__,
"Missing Gamma-point environment for active space module")
318 IF (.NOT.
ASSOCIATED(kpoints%kp_env(1)%kpoint_env%mos))
THEN
319 CALL cp_abort(__location__,
"Missing Gamma-point MOs for active space module")
327 CALL cp_abort(__location__,
"Adiabatic rescaling not supported in active space module")
331 do_ddapc = dft_control%qs_control%ddapc_restraint .OR. &
332 qs_env%cp_ddapc_ewald%do_decoupling .OR. &
333 qs_env%cp_ddapc_ewald%do_qmmm_periodic_decpl .OR. &
334 qs_env%cp_ddapc_ewald%do_solvation
336 CALL cp_abort(__location__,
"DDAPC charges are not supported in the active space module")
338 IF (dft_control%do_sccs)
THEN
339 CALL cp_abort(__location__,
"SCCS is not supported in the active space module")
341 IF (dft_control%correct_surf_dip)
THEN
342 IF (dft_control%surf_dip_correct_switch)
THEN
343 CALL cp_abort(__location__,
"Surface dipole correction not supported in the AS module")
346 IF (dft_control%smeagol_control%smeagol_enabled)
THEN
347 CALL cp_abort(__location__,
"SMEAGOL is not supported in the active space module")
349 IF (dft_control%qs_control%do_kg)
THEN
350 CALL cp_abort(__location__,
"KG correction not supported in the active space module")
353 NULLIFY (active_space_env)
355 active_space_env%energy_total = 0.0_dp
356 active_space_env%energy_ref = 0.0_dp
357 active_space_env%energy_inactive = 0.0_dp
358 active_space_env%energy_active = 0.0_dp
363 IF (.NOT. (active_space_env%eps_fci > 0.0_dp))
THEN
364 cpabort(
"ACTIVE_SPACE%EPS_FCI must be positive.")
369 active_space_env%fcidump = .true.
374 active_space_env%qcschema = .true.
375 active_space_env%qcschema_filename = qcschema_filename
379 CALL get_qs_env(qs_env, nelectron_total=nelec_total)
381 IF (nelec_active <= 0) cpabort(
"Specify a positive number of active electrons.")
382 IF (nelec_active > nelec_total) cpabort(
"More active electrons than total electrons.")
384 nelec_inactive = nelec_total - nelec_active
385 IF (mod(nelec_inactive, 2) /= 0)
THEN
386 cpabort(
"The remaining number of inactive electrons has to be even.")
390 WRITE (iw,
'(T3,A,T70,I10)')
"Total number of electrons", nelec_total
391 WRITE (iw,
'(T3,A,T70,I10)')
"Number of inactive electrons", nelec_inactive
392 WRITE (iw,
'(T3,A,T70,I10)')
"Number of active electrons", nelec_active
395 CALL get_qs_env(qs_env, dft_control=dft_control)
396 nspins = dft_control%nspins
398 active_space_env%nelec_active = nelec_active
399 active_space_env%nelec_inactive = nelec_inactive
400 active_space_env%nelec_total = nelec_total
401 active_space_env%nspins = nspins
402 active_space_env%multiplicity = dft_control%multiplicity
403 active_space_env%restricted_orbitals = dft_control%roks
407 IF (.NOT. explicit)
THEN
408 CALL cp_abort(__location__,
"Number of Active Orbitals has to be specified.")
410 active_space_env%nmo_active = nmo_active
412 nmo_inactive = nelec_inactive/2
413 active_space_env%nmo_inactive = nmo_inactive
419 SELECT CASE (mselect)
421 cpabort(
"Unknown orbital selection method")
423 WRITE (iw,
'(/,T3,A)') &
424 "Active space orbitals selected using energy ordered canonical orbitals"
426 WRITE (iw,
'(/,T3,A)') &
427 "Active space orbitals selected using projected Wannier orbitals"
429 WRITE (iw,
'(/,T3,A)') &
430 "Active space orbitals selected using modified atomic orbitals (MAO)"
432 WRITE (iw,
'(/,T3,A)') &
433 "Active space orbitals selected manually"
436 WRITE (iw,
'(T3,A,T70,I10)')
"Number of inactive orbitals", nmo_inactive
437 WRITE (iw,
'(T3,A,T70,I10)')
"Number of active orbitals", nmo_active
444 IF (iatom <= 0 .OR. iatom > natom)
THEN
446 WRITE (iw,
'(/,T3,A,I3)')
"ERROR: SUBSPACE_ATOM number is not valid", iatom
448 cpabort(
"Select a valid SUBSPACE_ATOM")
455 cshell = adjustl(cshell)
459 IF (cshell(n1:n1) ==
" ")
THEN
463 READ (cshell(n1:),
"(I1,A1)") nshell(i), lnam(i)
469 SELECT CASE (mselect)
471 cpabort(
"Unknown orbital selection method")
474 mos => kpoints%kp_env(1)%kpoint_env%mos(:)
480 nmo_occ = nmo_inactive + nmo_active
483 ALLOCATE (active_space_env%inactive_orbitals(nmo_inactive, nspins))
485 DO i = 1, nmo_inactive
486 active_space_env%inactive_orbitals(i, ispin) = i
491 ALLOCATE (active_space_env%active_orbitals(nmo_active, nspins))
494 active_space_env%active_orbitals(i, ispin) = nmo_inactive + i
503 IF (nspins > 1) maxocc = 1.0_dp
504 ALLOCATE (active_space_env%mos_active(nspins))
505 ALLOCATE (active_space_env%mos_inactive(nspins))
507 CALL get_mo_set(mos(ispin), mo_coeff=mo_ref, nao=nao)
508 CALL cp_fm_get_info(mo_ref, context=context, para_env=para_env, nrow_global=nrow_global)
510 CALL allocate_mo_set(active_space_env%mos_active(ispin), nao, nmo_occ, 0, 0.0_dp, maxocc, 0.0_dp)
512 nrow_global=nrow_global, ncol_global=nmo_occ)
513 CALL init_mo_set(active_space_env%mos_active(ispin), fm_struct=fm_struct_tmp, name=
"Active Space MO")
515 IF (nspins == 2)
THEN
516 nel = nelec_inactive/2
520 CALL allocate_mo_set(active_space_env%mos_inactive(ispin), nao, nmo_occ, nel, &
521 REAL(nel, kind=
dp), maxocc, 0.0_dp)
523 nrow_global=nrow_global, ncol_global=nmo_occ)
524 CALL init_mo_set(active_space_env%mos_inactive(ispin), fm_struct=fm_struct_tmp, name=
"Inactive Space MO")
529 CALL get_qs_env(qs_env, scf_control=scf_control)
530 IF (dft_control%roks .AND. scf_control%roks_scheme /=
high_spin_roks)
THEN
531 CALL cp_abort(__location__, &
532 "Only high-spin ROKS is supported for ACTIVE_SPACE FCI; "// &
533 "general ROKS MO definitions are not implemented.")
535 IF (dft_control%do_admm)
THEN
536 IF (dft_control%do_admm_mo)
THEN
537 cpabort(
"ADMM currently possible only with purification none_dm")
541 ALLOCATE (eigenvalues(nmo_occ, nspins))
544 CALL get_qs_env(qs_env, matrix_ks_kp=ks_matrix_kp, matrix_s_kp=s_matrix_kp, &
545 scf_control=scf_control)
546 ks_matrix => ks_matrix_kp(:, 1)
547 s_matrix => s_matrix_kp(:, 1)
549 CALL get_qs_env(qs_env, matrix_ks=ks_matrix, matrix_s=s_matrix, scf_control=scf_control)
554 WRITE (iw,
'(/,T3,A)')
"Calculating virtual MOs..."
558 CALL ensure_canonical_orbitals(qs_env, mos(ispin), ks_matrix(ispin)%matrix, ispin, &
559 .false., do_kpoints, iw)
563 CALL get_mo_set(mos(ispin), mo_coeff=mo_ref, nmo=nmo_available)
566 nmo_virtual = nmo_occ - nmo_available
567 nmo_virtual = max(nmo_virtual, 0)
569 NULLIFY (evals_virtual)
570 ALLOCATE (evals_virtual(nmo_virtual))
573 nrow_global=nrow_global)
576 nrow_global=nrow_global, ncol_global=nmo_virtual)
577 CALL cp_fm_create(mo_virtual, fm_struct_tmp, name=
"virtual")
582 CALL virtual_orbital_preconditioner(local_preconditioner, mos(ispin), ks_matrix(ispin)%matrix, &
583 s_matrix(1)%matrix, nmo_virtual, para_env, context)
584 CALL ot_eigensolver(matrix_h=ks_matrix(ispin)%matrix, matrix_s=s_matrix(1)%matrix, &
585 matrix_c_fm=mo_virtual, matrix_orthogonal_space_fm=mo_ref, &
586 eps_gradient=scf_control%eps_lumos, &
588 iter_max=scf_control%max_iter_lumos, &
589 size_ortho_space=nmo_available)
590 IF (
ASSOCIATED(local_preconditioner))
THEN
592 DEALLOCATE (local_preconditioner)
600 eigenvalues(:, ispin), max_offdiag)
603 mo_set => active_space_env%mos_inactive(ispin)
605 DO i = 1,
SIZE(active_space_env%inactive_orbitals, 1)
606 m = active_space_env%inactive_orbitals(i, ispin)
608 mo_set%eigenvalues(m) = eigenvalues(m, ispin)
610 mo_set%occupation_numbers(m) = 1.0_dp
612 mo_set%occupation_numbers(m) = 2.0_dp
617 mo_set => active_space_env%mos_active(ispin)
620 IF (nspins == 2)
THEN
622 nel = (nelec_active + active_space_env%multiplicity - 1)/2
624 nel = (nelec_active - active_space_env%multiplicity + 1)/2
629 mo_set%nelectron = nel
630 mo_set%n_el_f = real(nel, kind=
dp)
632 m = active_space_env%active_orbitals(i, ispin)
633 IF (m > nmo_available)
THEN
634 CALL cp_fm_to_fm(mo_virtual, mo_target, 1, m - nmo_available, m)
635 eigenvalues(m, ispin) = evals_virtual(m - nmo_available)
636 mo_set%occupation_numbers(m) = 0.0_dp
639 mo_set%occupation_numbers(m) = mos(ispin)%occupation_numbers(m)
641 mo_set%eigenvalues(m) = eigenvalues(m, ispin)
644 DEALLOCATE (evals_virtual)
650 WRITE (iw,
'(/,T3,A,I3,T66,A)')
"Canonical Orbital Selection for spin", ispin, &
652 DO i = 1, nmo_inactive, 4
653 jm = min(3, nmo_inactive - i)
654 WRITE (iw,
'(T3,4(F14.6,A5))') (eigenvalues(i + j, ispin),
" [I]", j=0, jm)
656 DO i = nmo_inactive + 1, nmo_inactive + nmo_active, 4
657 jm = min(3, nmo_inactive + nmo_active - i)
658 WRITE (iw,
'(T3,4(F14.6,A5))') (eigenvalues(i + j, ispin),
" [A]", j=0, jm)
660 WRITE (iw,
'(/,T3,A,I3)')
"Active Orbital Indices for spin", ispin
661 DO i = 1,
SIZE(active_space_env%active_orbitals, 1), 4
662 jm = min(3,
SIZE(active_space_env%active_orbitals, 1) - i)
663 WRITE (iw,
'(T3,4(I4))') (active_space_env%active_orbitals(i + j, ispin), j=0, jm)
667 DEALLOCATE (eigenvalues)
672 IF (dft_control%roks)
THEN
673 CALL cp_abort(__location__, &
674 "Manual ACTIVE_SPACE orbital selection is not supported for ROKS; "// &
675 "use canonical high-spin ROKS.")
677 IF (dft_control%do_admm)
THEN
682 IF (dft_control%do_admm_mo)
THEN
683 cpabort(
"ADMM currently possible only with purification none_dm")
688 IF (.NOT. explicit)
THEN
689 CALL cp_abort(__location__,
"Manual orbital selection requires to explicitly "// &
690 "set the active orbital indices via ACTIVE_ORBITAL_INDICES")
693 IF (nspins == 1)
THEN
694 cpassert(
SIZE(invals) == nmo_active)
696 cpassert(
SIZE(invals) == 2*nmo_active)
698 ALLOCATE (active_space_env%inactive_orbitals(nmo_inactive, nspins))
699 ALLOCATE (active_space_env%active_orbitals(nmo_active, nspins))
703 active_space_env%active_orbitals(i, ispin) = invals(i + (ispin - 1)*nmo_active)
708 mos => kpoints%kp_env(1)%kpoint_env%mos(:)
714 max_orb_ind = maxval(invals)
716 IF (nspins > 1) maxocc = 1.0_dp
717 ALLOCATE (active_space_env%mos_active(nspins))
718 ALLOCATE (active_space_env%mos_inactive(nspins))
721 CALL get_mo_set(mos(ispin), mo_coeff=mo_ref, nao=nao)
722 CALL cp_fm_get_info(mo_ref, context=context, para_env=para_env, nrow_global=nrow_global)
723 CALL allocate_mo_set(active_space_env%mos_active(ispin), nao, max_orb_ind, 0, 0.0_dp, maxocc, 0.0_dp)
725 nrow_global=nrow_global, ncol_global=max_orb_ind)
726 CALL init_mo_set(active_space_env%mos_active(ispin), fm_struct=fm_struct_tmp, name=
"Active Space MO")
730 IF (nspins == 2)
THEN
731 nel = nelec_inactive/2
735 CALL allocate_mo_set(active_space_env%mos_inactive(ispin), nao, max_orb_ind, nel, real(nel, kind=
dp), maxocc, 0.0_dp)
737 nrow_global=nrow_global, ncol_global=max_orb_ind)
738 CALL init_mo_set(active_space_env%mos_inactive(ispin), fm_struct=fm_struct_tmp, name=
"Inactive Space MO")
740 active_space_env%mos_inactive(ispin)%occupation_numbers = 0.0_dp
744 ALLOCATE (eigenvalues(max_orb_ind, nspins))
747 CALL get_qs_env(qs_env, matrix_ks_kp=ks_matrix_kp, matrix_s_kp=s_matrix_kp, &
748 scf_control=scf_control)
749 ks_matrix => ks_matrix_kp(:, 1)
750 s_matrix => s_matrix_kp(:, 1)
752 CALL get_qs_env(qs_env, matrix_ks=ks_matrix, matrix_s=s_matrix, scf_control=scf_control)
757 WRITE (iw,
'(/,T3,A)')
"Calculating virtual MOs..."
761 CALL ensure_canonical_orbitals(qs_env, mos(ispin), ks_matrix(ispin)%matrix, ispin, &
762 .true., do_kpoints, iw)
763 CALL get_mo_set(mos(ispin), mo_coeff=mo_ref, nmo=nmo_available)
764 nmo_virtual = max_orb_ind - nmo_available
765 nmo_virtual = max(nmo_virtual, 0)
767 NULLIFY (evals_virtual)
768 ALLOCATE (evals_virtual(nmo_virtual))
771 nrow_global=nrow_global)
774 nrow_global=nrow_global, ncol_global=nmo_virtual)
775 CALL cp_fm_create(mo_virtual, fm_struct_tmp, name=
"virtual")
779 CALL virtual_orbital_preconditioner(local_preconditioner, mos(ispin), ks_matrix(ispin)%matrix, &
780 s_matrix(1)%matrix, nmo_virtual, para_env, context)
781 CALL ot_eigensolver(matrix_h=ks_matrix(ispin)%matrix, matrix_s=s_matrix(1)%matrix, &
782 matrix_c_fm=mo_virtual, matrix_orthogonal_space_fm=mo_ref, &
783 eps_gradient=scf_control%eps_lumos, &
785 iter_max=scf_control%max_iter_lumos, &
786 size_ortho_space=nmo_available)
787 IF (
ASSOCIATED(local_preconditioner))
THEN
789 DEALLOCATE (local_preconditioner)
797 eigenvalues(:, ispin), max_offdiag)
799 mo_set_active => active_space_env%mos_active(ispin)
800 CALL get_mo_set(mo_set_active, mo_coeff=fm_target_active)
801 mo_set_inactive => active_space_env%mos_inactive(ispin)
802 CALL get_mo_set(mo_set_inactive, mo_coeff=fm_target_inactive)
805 nmo_inactive_remaining = nmo_inactive
806 DO i = 1, max_orb_ind
808 IF (any(active_space_env%active_orbitals(:, ispin) == i))
THEN
809 IF (i > nmo_available)
THEN
810 CALL cp_fm_to_fm(mo_virtual, fm_target_active, 1, i - nmo_available, i)
811 eigenvalues(i, ispin) = evals_virtual(i - nmo_available)
812 mo_set_active%occupation_numbers(i) = 0.0_dp
814 CALL cp_fm_to_fm(mo_ref, fm_target_active, 1, i, i)
815 mo_set_active%occupation_numbers(i) = mos(ispin)%occupation_numbers(i)
817 mo_set_active%eigenvalues(i) = eigenvalues(i, ispin)
819 ELSE IF (nmo_inactive_remaining > 0)
THEN
820 CALL cp_fm_to_fm(mo_ref, fm_target_inactive, 1, i, i)
822 active_space_env%inactive_orbitals(nmo_inactive - nmo_inactive_remaining + 1, ispin) = i
823 mo_set_inactive%eigenvalues(i) = eigenvalues(i, ispin)
824 mo_set_inactive%occupation_numbers(i) = mos(ispin)%occupation_numbers(i)
826 IF (nmo_inactive_remaining == 1)
THEN
827 mo_set_inactive%homo = i
828 mo_set_inactive%lfomo = i + 1
830 nmo_inactive_remaining = nmo_inactive_remaining - 1
837 DEALLOCATE (evals_virtual)
843 WRITE (iw,
'(/,T3,A,I3,T66,A)')
"Orbital Energies and Selection for spin", ispin,
"[atomic units]"
845 DO i = 1, max_orb_ind, 4
846 jm = min(3, max_orb_ind - i)
847 WRITE (iw,
'(T4)', advance=
"no")
849 IF (any(active_space_env%active_orbitals(:, ispin) == i + j))
THEN
850 WRITE (iw,
'(T3,F12.6,A5)', advance=
"no") eigenvalues(i + j, ispin),
" [A]"
851 ELSE IF (any(active_space_env%inactive_orbitals(:, ispin) == i + j))
THEN
852 WRITE (iw,
'(T3,F12.6,A5)', advance=
"no") eigenvalues(i + j, ispin),
" [I]"
854 WRITE (iw,
'(T3,F12.6,A5)', advance=
"no") eigenvalues(i + j, ispin),
" [V]"
859 WRITE (iw,
'(/,T3,A,I3)')
"Active Orbital Indices for spin", ispin
860 DO i = 1,
SIZE(active_space_env%active_orbitals, 1), 4
861 jm = min(3,
SIZE(active_space_env%active_orbitals, 1) - i)
862 WRITE (iw,
'(T3,4(I4))') (active_space_env%active_orbitals(i + j, ispin), j=0, jm)
866 DEALLOCATE (eigenvalues)
870 NULLIFY (loc_section, loc_print)
872 cpassert(
ASSOCIATED(loc_section))
875 cpabort(
"not yet available")
879 cpabort(
"not yet available")
884 CALL check_active_space_degeneracy(active_space_env, mos)
892 CALL print_orbital_cubes(print_orb, qs_env, active_space_env%mos_active)
894 IF (stop_after_print)
THEN
897 WRITE (iw,
'(/,T2,A)') &
898 '!----------------- Early End of Active Space Interface -----------------------!'
901 CALL timestop(handle)
911 rho_ao => rho_ao_kp(:, 1)
915 cpassert(
ASSOCIATED(rho_ao))
920 mo_set => active_space_env%mos_inactive(ispin)
922 active_space_env%pmat_inactive(ispin)%matrix => denmat
927 active_space_env%eri%method = eri_method
929 active_space_env%eri%operator = eri_operator
931 active_space_env%eri%omega = eri_op_omega
933 active_space_env%eri%cutoff_radius = eri_rcut
936 active_space_env%eri%eps_integral = eri_eps_int
939 IF (
SIZE(invals) == 1)
THEN
940 active_space_env%eri%periodicity(1:3) = invals(1)
942 active_space_env%eri%periodicity(1:3) = invals(1:3)
946 active_space_env%eri%periodicity(1:3) = cell%perd(1:3)
949 WRITE (iw,
'(/,T3,A)')
"Calculation of Electron Repulsion Integrals"
951 SELECT CASE (eri_method)
953 WRITE (iw,
'(T3,A,T50,A)')
"Integration method",
"GPW Fourier transform over MOs"
955 WRITE (iw,
'(T3,A,T44,A)')
"Integration method",
"Half transformed integrals from GPW"
957 cpabort(
"Unknown ERI method")
960 SELECT CASE (eri_operator)
962 WRITE (iw,
'(T3,A,T73,A)')
"ERI operator",
"Coulomb"
965 WRITE (iw,
'(T3,A,T74,A)')
"ERI operator",
"Yukawa"
966 IF (.NOT. ex_omega)
CALL cp_abort(__location__, &
967 "Yukawa operator requires OMEGA to be explicitly set")
968 WRITE (iw,
'(T3,A,T66,F14.3)')
"ERI operator parameter OMEGA", eri_op_omega
971 WRITE (iw,
'(T3,A,T63,A)')
"ERI operator",
"Longrange Coulomb"
972 IF (.NOT. ex_omega)
CALL cp_abort(__location__, &
973 "Longrange operator requires OMEGA to be explicitly set")
974 WRITE (iw,
'(T3,A,T66,F14.3)')
"ERI operator parameter OMEGA", eri_op_omega
977 WRITE (iw,
'(T3,A,T62,A)')
"ERI operator",
"Shortrange Coulomb"
978 IF (.NOT. ex_omega)
CALL cp_abort(__location__, &
979 "Shortrange operator requires OMEGA to be explicitly set")
980 WRITE (iw,
'(T3,A,T66,F14.3)')
"ERI operator parameter OMEGA", eri_op_omega
983 WRITE (iw,
'(T3,A,T63,A)')
"ERI operator",
"Truncated Coulomb"
984 IF (.NOT. ex_rcut)
CALL cp_abort(__location__, &
985 "Cutoff radius not specified for trunc. Coulomb operator")
986 WRITE (iw,
'(T3,A,T66,F14.3)')
"ERI operator cutoff radius (au)", eri_rcut
989 WRITE (iw,
'(T3,A,T53,A)')
"ERI operator",
"Longrange truncated Coulomb"
990 IF (.NOT. ex_rcut)
CALL cp_abort(__location__, &
991 "Cutoff radius not specified for trunc. longrange operator")
992 WRITE (iw,
'(T3,A,T66,F14.3)')
"ERI operator cutoff radius (au)", eri_rcut
993 IF (.NOT. ex_omega)
CALL cp_abort(__location__, &
994 "LR truncated operator requires OMEGA to be explicitly set")
995 WRITE (iw,
'(T3,A,T66,F14.3)')
"ERI operator parameter OMEGA", eri_op_omega
996 IF (eri_op_omega < 0.01_dp)
THEN
997 cpabort(
"LR truncated operator requires OMEGA >= 0.01 to be stable")
1001 cpabort(
"Unknown ERI operator")
1005 WRITE (iw,
'(T3,A,T68,E12.4)')
"Accuracy of ERIs", eri_eps_int
1006 WRITE (iw,
'(T3,A,T71,3I3)')
"Periodicity", active_space_env%eri%periodicity(1:3)
1009 IF (nspins < 2)
THEN
1010 WRITE (iw,
'(T3,A,T68,I12)')
"Total Number of ERI", (nmo_active**4)/8
1012 WRITE (iw,
'(T3,A,T68,I12)')
"Total Number of ERI (aa|aa)", (nmo_active**4)/8
1013 WRITE (iw,
'(T3,A,T68,I12)')
"Total Number of ERI (bb|bb)", (nmo_active**4)/8
1014 WRITE (iw,
'(T3,A,T68,I12)')
"Total Number of ERI (aa|bb)", (nmo_active**4)/4
1020 m = (nspins*(nspins + 1))/2
1022 IF (dft_control%roks) m = 1
1023 ALLOCATE (active_space_env%eri%eri(m))
1025 CALL get_mo_set(active_space_env%mos_active(1), nmo=nmo)
1026 ALLOCATE (active_space_env%eri%eri(i)%csr_mat)
1027 eri_mat => active_space_env%eri%eri(i)%csr_mat
1031 ELSE IF (i == 2)
THEN
1038 nn1 = (n1*(n1 + 1))/2
1039 nn2 = (n2*(n2 + 1))/2
1040 CALL dbcsr_csr_create(eri_mat, nn1, nn2, 0_int_8, 0, 0, para_env%get_handle())
1041 active_space_env%eri%norb = nmo
1044 SELECT CASE (eri_method)
1047 active_space_env%eri%eri_gpw%eps_grid = eri_eps_grid
1049 active_space_env%eri%eri_gpw%eps_filter = eri_eps_filter
1051 active_space_env%eri%eri_gpw%cutoff = eri_gpw_cutoff
1053 active_space_env%eri%eri_gpw%rel_cutoff = eri_rel_cutoff
1055 active_space_env%eri%eri_gpw%print_level = eri_print
1057 active_space_env%eri%eri_gpw%store_wfn = store_wfn
1059 active_space_env%eri%eri_gpw%group_size = group_size
1061 active_space_env%eri%eri_gpw%redo_poisson = .true.
1064 WRITE (iw,
'(/,T2,A,T71,F10.1)')
"ERI_GPW| Energy cutoff [Ry]", eri_gpw_cutoff
1065 WRITE (iw,
'(T2,A,T71,F10.1)')
"ERI_GPW| Relative energy cutoff [Ry]", eri_rel_cutoff
1068 CALL calculate_eri_gpw(active_space_env%mos_active, active_space_env%active_orbitals, active_space_env%eri, qs_env, iw, &
1072 cpabort(
"Unknown ERI method")
1075 DO isp = 1,
SIZE(active_space_env%eri%eri)
1076 eri_mat => active_space_env%eri%eri(isp)%csr_mat
1077 nze_percentage = 100.0_dp*(real(eri_mat%nze_total, kind=
dp) &
1078 /real(eri_mat%nrows_total, kind=
dp))/real(eri_mat%ncols_total, kind=
dp)
1079 WRITE (iw,
'(/,T2,A,I2,T30,A,T68,I12)')
"ERI_GPW| Spinmatrix:", isp, &
1080 "Number of CSR non-zero elements:", eri_mat%nze_total
1081 WRITE (iw,
'(T2,A,I2,T30,A,T68,F12.4)')
"ERI_GPW| Spinmatrix:", isp, &
1082 "Percentage CSR non-zero elements:", nze_percentage
1083 WRITE (iw,
'(T2,A,I2,T30,A,T68,I12)')
"ERI_GPW| Spinmatrix:", isp, &
1084 "nrows_total", eri_mat%nrows_total
1085 WRITE (iw,
'(T2,A,I2,T30,A,T68,I12)')
"ERI_GPW| Spinmatrix:", isp, &
1086 "ncols_total", eri_mat%ncols_total
1087 WRITE (iw,
'(T2,A,I2,T30,A,T68,I12)')
"ERI_GPW| Spinmatrix:", isp, &
1088 "nrows_local", eri_mat%nrows_local
1092 CALL para_env%sync()
1095 nspins = active_space_env%nspins
1096 ALLOCATE (active_space_env%p_active(nspins))
1098 mo_set => active_space_env%mos_active(isp)
1099 CALL get_mo_set(mo_set, mo_coeff=mo_coeff, nmo=nmo)
1100 CALL create_subspace_matrix(mo_coeff, active_space_env%p_active(isp), nmo)
1102 SELECT CASE (mselect)
1104 cpabort(
"Unknown orbital selection method")
1107 IF (nspins == 2) focc = 1.0_dp
1109 fmat => active_space_env%p_active(isp)
1111 IF (nspins == 2)
THEN
1113 nel = (active_space_env%nelec_active + active_space_env%multiplicity - 1)/2
1115 nel = (active_space_env%nelec_active - active_space_env%multiplicity + 1)/2
1118 nel = active_space_env%nelec_active
1120 DO i = 1, nmo_active
1121 m = active_space_env%active_orbitals(i, isp)
1122 fel = min(focc, real(nel, kind=
dp))
1124 nel = nel - nint(fel)
1129 cpabort(
"NOT IMPLEMENTED")
1131 cpabort(
"NOT IMPLEMENTED")
1135 CALL calculate_spin_pol_overlap(active_space_env%mos_active, qs_env, active_space_env)
1140 IF (
ASSOCIATED(xc_section))
CALL section_vals_get(xc_section, explicit=explicit)
1145 IF (
ASSOCIATED(qs_env%x_data))
CALL hfx_release(qs_env%x_data)
1149 CALL get_qs_env(qs_env, atomic_kind_set=atomic_kind_set, qs_kind_set=qs_kind_set, &
1150 particle_set=particle_set, cell=cell, ks_env=ks_env)
1151 IF (dft_control%do_admm)
THEN
1152 basis_type =
'AUX_FIT'
1157 CALL hfx_create(qs_env%x_data, para_env, hfx_section, atomic_kind_set, &
1158 qs_kind_set, particle_set, dft_control, cell, orb_basis=basis_type, &
1159 nelectron_total=nelec_total)
1161 qs_env%requires_matrix_vxc = .true.
1164 CALL set_ks_env(ks_env, s_mstruct_changed=.true.)
1166 just_energy=.false., &
1167 ext_xc_section=xc_section)
1169 CALL set_ks_env(ks_env, s_mstruct_changed=.false.)
1174 active_space_env%xc_section => xc_section
1178 CALL calculate_operators(active_space_env%mos_active, qs_env, active_space_env)
1180 active_space_env%energy_ref = energy%total
1182 CALL subspace_fock_matrix(active_space_env, dft_control%roks)
1185 CALL set_qs_env(qs_env, active_space=active_space_env)
1189 SELECT CASE (as_solver)
1192 WRITE (iw,
'(/,T3,A)')
"No active space solver specified, skipping embedding calculation"
1195 CALL para_env%sync()
1197 CALL rsdft_embedding(qs_env, active_space_env, as_input)
1200 CALL local_fci_embedding(qs_env, active_space_env, as_input)
1203 cpabort(
"Unknown active space solver")
1207 IF (active_space_env%fcidump)
THEN
1208 CALL fcidump(active_space_env, as_input, dft_control%roks, &
1214 CALL write_active_space_molden(qs_env, active_space_env, as_input)
1218 IF (active_space_env%qcschema)
THEN
1220 IF (para_env%is_source())
THEN
1227 WRITE (iw,
'(/,T2,A)') &
1228 '!-------------------- End of Active Space Interface --------------------------!'
1231 CALL para_env%sync()
1233 CALL timestop(handle)
1253 SUBROUTINE ensure_canonical_orbitals(qs_env, mo_set, ks_matrix, ispin, manual, do_kpoints, iw)
1257 INTEGER,
INTENT(IN) :: ispin
1258 LOGICAL,
INTENT(IN) :: manual, do_kpoints
1259 INTEGER,
INTENT(IN) :: iw
1261 LOGICAL :: on_the_fly_loc, rotated
1262 REAL(kind=
dp) :: eps_canonical, max_offdiag
1263 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: energies
1272 IF (do_kpoints)
RETURN
1273 NULLIFY (dft_control, input, mo_derivs, mo_deriv, scf_control)
1274 CALL get_qs_env(qs_env, dft_control=dft_control, scf_control=scf_control, input=input, &
1275 mo_derivs=mo_derivs)
1276 IF (dft_control%roks)
RETURN
1279 eps_canonical = max(1.0e-4_dp, 100.0_dp*scf_control%eps_scf)
1280 IF (mo_set%use_mo_coeff_b)
CALL copy_dbcsr_to_fm(mo_set%mo_coeff_b, mo_set%mo_coeff)
1281 ALLOCATE (energies(mo_set%nmo))
1283 DEALLOCATE (energies)
1284 IF (max_offdiag <= eps_canonical)
THEN
1285 IF (iw > 0)
WRITE (iw,
'(/,T3,A,I0,A,ES9.2,A)')
"SCF orbitals of spin ", ispin, &
1286 " are canonical (max |<i|F|j>| = ", max_offdiag,
")"
1290 on_the_fly_loc = .false.
1291 IF (scf_control%use_ot)
CALL section_vals_val_get(input,
"DFT%SCF%OT%ON_THE_FLY_LOC", l_val=on_the_fly_loc)
1292 IF (on_the_fly_loc)
THEN
1293 IF (.NOT. manual)
THEN
1294 CALL cp_abort(__location__, &
1295 "ORBITAL_SELECTION CANONICAL needs canonical orbitals, but the "// &
1296 "SCF orbitals are localized (ON_THE_FLY_LOC). Use ORBITAL_SELECTION MANUAL "// &
1297 "to select localized orbitals, or switch off ON_THE_FLY_LOC.")
1299 IF (iw > 0)
WRITE (iw,
'(/,T3,A,I0,A)')
"SCF orbitals of spin ", ispin, &
1300 " are localized (ON_THE_FLY_LOC): ACTIVE_ORBITAL_INDICES refer to the localized orbitals"
1304 IF (
ASSOCIATED(mo_derivs))
THEN
1305 IF (
SIZE(mo_derivs) >= ispin) mo_deriv => mo_derivs(ispin)%matrix
1309 WRITE (iw,
'(/,T3,A,I0,A,ES9.2,A)')
"SCF orbitals of spin ", ispin, &
1310 " are not canonical (max |<i|F|j>| = ", max_offdiag,
")"
1311 WRITE (iw,
'(T3,A)')
"Rotated into canonical orbitals, separately for occupied and virtual orbitals"
1314 END SUBROUTINE ensure_canonical_orbitals
1327 SUBROUTINE virtual_orbital_preconditioner(preconditioner, mo_set, ks_matrix, s_matrix, nmo_virtual, &
1328 para_env, blacs_env)
1331 TYPE(
dbcsr_type),
POINTER :: ks_matrix, s_matrix
1332 INTEGER,
INTENT(IN) :: nmo_virtual
1337 IF (nmo_virtual <= 0)
RETURN
1342 matrix_s=s_matrix, convert_precond_to_dbcsr=.true., &
1343 mo_set=mo_set, energy_gap=0.2_dp)
1345 END SUBROUTINE virtual_orbital_preconditioner
1354 SUBROUTINE check_active_space_degeneracy(active_space_env, mos)
1356 TYPE(
mo_set_type),
DIMENSION(:),
INTENT(IN) :: mos
1358 REAL(kind=
dp),
PARAMETER :: eps_degenerate = 1.0e-5_dp
1360 CHARACTER(LEN=200) :: message
1361 INTEGER :: first_active, first_other, ispin, mspin, &
1363 REAL(kind=
dp),
DIMENSION(:),
POINTER :: eigenvalues
1365 DO ispin = 1,
SIZE(active_space_env%active_orbitals, 2)
1366 mspin = min(ispin,
SIZE(mos))
1367 CALL get_mo_set(mos(mspin), nmo=nmo, eigenvalues=eigenvalues)
1369 IF (.NOT.
ASSOCIATED(eigenvalues)) cycle
1370 IF (all(abs(eigenvalues(1:nmo)) < epsilon(1.0_dp))) cycle
1372 eps_degenerate, npairs, first_active, first_other)
1373 IF (npairs > 0)
THEN
1374 WRITE (message,
'(A,I0,A,I0,A,I0,A,I0,A)') &
1375 "The active space splits a set of degenerate orbitals: active orbital ", first_active, &
1376 " and inactive/virtual orbital ", first_other,
" (spin ", ispin,
", ", npairs, &
1377 " degenerate pairs in total)."
1378 cpwarn(trim(message))
1382 END SUBROUTINE check_active_space_degeneracy
1392 SUBROUTINE write_active_space_molden(qs_env, active_space_env, as_input)
1397 INTEGER :: i, iorb, ispin, m, nao, nmo_active, &
1398 nmo_inactive, nmo_out, nspins
1399 REAL(kind=
dp) :: maxocc
1402 TYPE(
cp_fm_type),
POINTER :: mo_coeff_active, mo_coeff_inactive
1403 TYPE(
mo_set_type),
ALLOCATABLE,
DIMENSION(:) :: mos_out
1405 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
1408 NULLIFY (cell, fm_struct, mo_coeff_active, mo_coeff_inactive, particle_set, qs_kind_set)
1409 CALL get_qs_env(qs_env, cell=cell, particle_set=particle_set, qs_kind_set=qs_kind_set)
1412 nspins =
SIZE(active_space_env%mos_active)
1413 nmo_active =
SIZE(active_space_env%active_orbitals, 1)
1414 nmo_inactive =
SIZE(active_space_env%inactive_orbitals, 1)
1415 nmo_out = nmo_inactive + nmo_active
1416 ALLOCATE (mos_out(nspins))
1417 DO ispin = 1, nspins
1418 CALL get_mo_set(active_space_env%mos_active(ispin), nao=nao, maxocc=maxocc, &
1419 mo_coeff=mo_coeff_active)
1420 CALL get_mo_set(active_space_env%mos_inactive(ispin), mo_coeff=mo_coeff_inactive)
1421 CALL allocate_mo_set(mos_out(ispin), nao, nmo_out, 0, 0.0_dp, maxocc, 0.0_dp)
1423 template_fmstruct=mo_coeff_active%matrix_struct)
1424 CALL init_mo_set(mos_out(ispin), fm_struct=fm_struct, name=
"active space orbitals")
1427 DO i = 1, nmo_inactive
1428 m = active_space_env%inactive_orbitals(i, ispin)
1429 CALL cp_fm_to_fm(mo_coeff_inactive, mos_out(ispin)%mo_coeff, 1, m, i)
1430 mos_out(ispin)%eigenvalues(i) = active_space_env%mos_inactive(ispin)%eigenvalues(m)
1431 mos_out(ispin)%occupation_numbers(i) = active_space_env%mos_inactive(ispin)%occupation_numbers(m)
1433 DO i = 1, nmo_active
1434 m = active_space_env%active_orbitals(i, ispin)
1435 iorb = nmo_inactive + i
1436 CALL cp_fm_to_fm(mo_coeff_active, mos_out(ispin)%mo_coeff, 1, m, iorb)
1437 mos_out(ispin)%eigenvalues(iorb) = active_space_env%mos_active(ispin)%eigenvalues(m)
1438 mos_out(ispin)%occupation_numbers(iorb) = active_space_env%mos_active(ispin)%occupation_numbers(m)
1442 CALL write_mos_molden(mos_out, qs_kind_set, particle_set, molden_section, cell=cell)
1444 DO ispin = 1, nspins
1447 DEALLOCATE (mos_out)
1449 END SUBROUTINE write_active_space_molden
1459 SUBROUTINE calculate_spin_pol_overlap(mos, qs_env, active_space_env)
1461 TYPE(
mo_set_type),
DIMENSION(:),
INTENT(IN) :: mos
1465 CHARACTER(LEN=*),
PARAMETER :: routinen =
'calculate_spin_pol_overlap'
1467 INTEGER :: handle, nmo, nspins
1468 LOGICAL :: do_kpoints
1469 TYPE(
cp_fm_type),
POINTER :: mo_coeff_a, mo_coeff_b
1471 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: s_matrix_kp
1473 CALL timeset(routinen, handle)
1475 nspins = active_space_env%nspins
1478 IF (nspins > 1)
THEN
1479 CALL get_qs_env(qs_env, do_kpoints=do_kpoints)
1480 IF (do_kpoints)
THEN
1481 CALL get_qs_env(qs_env, matrix_s_kp=s_matrix_kp)
1482 s_matrix => s_matrix_kp(:, 1)
1486 ALLOCATE (active_space_env%sab_sub(1))
1488 CALL get_mo_set(mo_set=mos(1), mo_coeff=mo_coeff_a, nmo=nmo)
1489 CALL get_mo_set(mo_set=mos(2), mo_coeff=mo_coeff_b, nmo=nmo)
1490 CALL subspace_operator(mo_coeff_a, nmo, s_matrix(1)%matrix, active_space_env%sab_sub(1), mo_coeff_b)
1493 CALL timestop(handle)
1495 END SUBROUTINE calculate_spin_pol_overlap
1505 SUBROUTINE calculate_operators(mos, qs_env, active_space_env)
1507 TYPE(
mo_set_type),
DIMENSION(:),
INTENT(IN) :: mos
1511 CHARACTER(LEN=*),
PARAMETER :: routinen =
'calculate_operators'
1513 INTEGER :: handle, ispin, nmo, nspins
1515 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: h_matrix, ks_matrix
1517 CALL timeset(routinen, handle)
1519 nspins = active_space_env%nspins
1523 CALL get_qs_env(qs_env, matrix_ks_kp=ks_matrix)
1524 ALLOCATE (active_space_env%ks_sub(nspins))
1525 DO ispin = 1, nspins
1526 CALL get_mo_set(mo_set=mos(ispin), mo_coeff=mo_coeff, nmo=nmo)
1527 CALL subspace_operator(mo_coeff, nmo, ks_matrix(ispin, 1)%matrix, active_space_env%ks_sub(ispin))
1534 CALL get_qs_env(qs_env=qs_env, matrix_h_kp=h_matrix)
1535 ALLOCATE (active_space_env%h_sub(nspins))
1536 DO ispin = 1, nspins
1537 CALL get_mo_set(mo_set=mos(ispin), mo_coeff=mo_coeff, nmo=nmo)
1538 CALL subspace_operator(mo_coeff, nmo, h_matrix(1, 1)%matrix, active_space_env%h_sub(ispin))
1541 CALL timestop(handle)
1543 END SUBROUTINE calculate_operators
1555 SUBROUTINE subspace_operator(mo_coeff, nmo, op_matrix, op_sub, mo_coeff_b)
1558 INTEGER,
INTENT(IN) :: nmo
1561 TYPE(
cp_fm_type),
INTENT(IN),
OPTIONAL :: mo_coeff_b
1563 CHARACTER(LEN=*),
PARAMETER :: routinen =
'subspace_operator'
1565 INTEGER :: handle, ncol, nrow
1568 CALL timeset(routinen, handle)
1570 CALL cp_fm_get_info(matrix=mo_coeff, ncol_global=ncol, nrow_global=nrow)
1571 cpassert(nmo <= ncol)
1574 CALL cp_fm_create(vectors, mo_coeff%matrix_struct,
"vectors")
1575 CALL create_subspace_matrix(mo_coeff, op_sub, nmo)
1577 IF (
PRESENT(mo_coeff_b))
THEN
1585 CALL parallel_gemm(
'T',
'N', nmo, nmo, nrow, 1.0_dp, mo_coeff, vectors, 0.0_dp, op_sub)
1589 CALL timestop(handle)
1591 END SUBROUTINE subspace_operator
1601 SUBROUTINE create_subspace_matrix(orbitals, op_sub, n)
1605 INTEGER,
INTENT(IN) :: n
1613 para_env=orbitals%matrix_struct%para_env, &
1614 context=orbitals%matrix_struct%context)
1615 CALL cp_fm_create(op_sub, fm_struct, name=
"Subspace operator")
1620 END SUBROUTINE create_subspace_matrix
1633 SUBROUTINE calculate_eri_gpw(mos, orbitals, eri_env, qs_env, iw, restricted)
1635 TYPE(
mo_set_type),
DIMENSION(:),
INTENT(IN) :: mos
1636 INTEGER,
DIMENSION(:, :),
POINTER :: orbitals
1639 INTEGER,
INTENT(IN) :: iw
1640 LOGICAL,
INTENT(IN) :: restricted
1642 CHARACTER(LEN=*),
PARAMETER :: routinen =
'calculate_eri_gpw'
1644 INTEGER :: col_local, color, handle, i1, i2, i3, i4, i_multigrid, icount2, intcount, isp, &
1645 isp1, isp2, ispin, iwa1, iwa12, iwa2, iwb1, iwb12, iwb2, iwbs, iwbt, iwfn, n_multigrid, &
1646 ncol_global, ncol_local, nmm, nmo, nmo1, nmo2, nrow_global, nrow_local, nspins, &
1647 number_of_subgroups, nx, row_local, stored_integrals
1648 INTEGER,
ALLOCATABLE,
DIMENSION(:) :: eri_index
1649 INTEGER,
DIMENSION(:),
POINTER :: col_indices, row_indices
1650 LOGICAL :: print1, print2, &
1651 skip_load_balance_distributed
1652 REAL(kind=
dp) :: dvol, erint, pair_int, &
1653 progression_factor, rc, rsize, t1, t2
1654 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: eri
1659 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_matrix_pq_rnu, fm_matrix_pq_rs, &
1663 TYPE(
dbcsr_type),
ALLOCATABLE,
DIMENSION(:) :: matrix_pq_rnu, mo_coeff_as
1667 POINTER :: sab_orb_sub
1675 DIMENSION(:, :),
TARGET :: wfn_a
1678 TYPE(
qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
1682 CALL timeset(routinen, handle)
1687 SELECT CASE (eri_env%eri_gpw%print_level)
1708 CALL get_qs_env(qs_env, para_env=para_env, blacs_env=blacs_env)
1709 IF (eri_env%eri_gpw%group_size < 1) eri_env%eri_gpw%group_size = para_env%num_pe
1710 IF (mod(para_env%num_pe, eri_env%eri_gpw%group_size) /= 0)
THEN
1711 cpabort(
"Group size must be a divisor of the total number of processes!")
1714 IF (eri_env%eri_gpw%group_size == para_env%num_pe)
THEN
1715 eri_env%para_env_sub => para_env
1716 CALL eri_env%para_env_sub%retain()
1717 blacs_env_sub => blacs_env
1718 CALL blacs_env_sub%retain()
1719 number_of_subgroups = 1
1722 number_of_subgroups = para_env%num_pe/eri_env%eri_gpw%group_size
1723 color = para_env%mepos/eri_env%eri_gpw%group_size
1724 ALLOCATE (eri_env%para_env_sub)
1725 CALL eri_env%para_env_sub%from_split(para_env, color)
1726 NULLIFY (blacs_env_sub)
1729 CALL eri_env%comm_exchange%from_split(para_env, eri_env%para_env_sub%mepos)
1732 CALL get_qs_env(qs_env, dft_control=dft_control)
1733 ALLOCATE (qs_control)
1734 qs_control_old => dft_control%qs_control
1735 qs_control = qs_control_old
1736 dft_control%qs_control => qs_control
1737 progression_factor = qs_control%progression_factor
1738 n_multigrid =
SIZE(qs_control%e_cutoff)
1742 IF (restricted) nspins = 1
1744 ALLOCATE (qs_control%e_cutoff(n_multigrid))
1746 qs_control%cutoff = eri_env%eri_gpw%cutoff*0.5_dp
1747 qs_control%e_cutoff(1) = qs_control%cutoff
1748 DO i_multigrid = 2, n_multigrid
1749 qs_control%e_cutoff(i_multigrid) = qs_control%e_cutoff(i_multigrid - 1) &
1752 qs_control%relative_cutoff = eri_env%eri_gpw%rel_cutoff*0.5_dp
1756 CALL create_mat_munu(mat_munu, qs_env, eri_env%eri_gpw%eps_grid, blacs_env_sub, sab_orb_sub=sab_orb_sub, &
1757 do_alloc_blocks_from_nbl=.true., dbcsr_sym_type=dbcsr_type_symmetric)
1761 NULLIFY (pw_env_sub)
1763 CALL pw_env_rebuild(pw_env_sub, qs_env, external_para_env=eri_env%para_env_sub)
1764 CALL pw_env_get(pw_env_sub, auxbas_pw_pool=auxbas_pw_pool, poisson_env=poisson_env)
1767 IF (eri_env%eri_gpw%redo_poisson)
THEN
1769 IF (sum(eri_env%periodicity) /= 0)
THEN
1774 poisson_env%parameters%periodic = eri_env%periodicity
1783 rc = cell%hmat(1, 1)
1786 rc = min(rc, 0.5_dp*cell%hmat(iwa1, iwa1))
1788 poisson_env%green_fft%radius = rc
1791 CALL pw_eri_green_create(poisson_env%green_fft, eri_env)
1795 IF (sum(cell%perd) /= sum(eri_env%periodicity))
THEN
1796 IF (sum(eri_env%periodicity) /= 0)
THEN
1797 WRITE (unit=iw, fmt=
"(/,T2,A,T51,A30)") &
1798 "ERI_GPW| Switching Poisson solver to",
"PERIODIC"
1800 WRITE (unit=iw, fmt=
"(/,T2,A,T51,A30)") &
1801 "ERI_GPW| Switching Poisson solver to",
"ANALYTIC"
1805 SELECT CASE (poisson_env%green_fft%method)
1807 WRITE (unit=iw, fmt=
"(T2,A,T51,A30)") &
1808 "ERI_GPW| Poisson Greens function",
"PERIODIC"
1810 WRITE (unit=iw, fmt=
"(T2,A,T51,A30)") &
1811 "ERI_GPW| Poisson Greens function",
"ANALYTIC"
1812 WRITE (unit=iw, fmt=
"(T2,A,T71,F10.4)")
"ERI_GPW| Poisson cutoff radius", &
1813 poisson_env%green_fft%radius*
angstrom
1815 cpabort(
"Wrong Greens function setup")
1820 ALLOCATE (mo_coeff_as(nspins), fm_mo_coeff_as(nspins))
1821 DO ispin = 1, nspins
1823 REAL(kind=
dp),
DIMENSION(:, :),
ALLOCATABLE :: c, c_active
1827 CALL get_mo_set(mos(ispin), mo_coeff=mo_coeff, nmo=nmo)
1830 ALLOCATE (c_active(
SIZE(c, 1),
SIZE(orbitals, 1)))
1831 DO i1 = 1,
SIZE(orbitals, 1)
1832 c_active(:, i1) = c(:, orbitals(i1, ispin))
1835 c_active, mat_munu%matrix, gd_array, eri_env%eri_gpw%eps_filter)
1837 DEALLOCATE (c, c_active)
1840 CALL dbcsr_get_info(mo_coeff_as(ispin), nfullrows_total=nrow_global, nfullcols_total=ncol_global)
1843 CALL cp_fm_struct_create(fm_struct, context=blacs_env_sub, para_env=eri_env%para_env_sub, &
1844 nrow_global=nrow_global, ncol_global=ncol_global)
1853 NULLIFY (task_list_sub)
1854 skip_load_balance_distributed = dft_control%qs_control%skip_load_balance_distributed
1857 reorder_rs_grid_ranks=.true., &
1858 skip_load_balance_distributed=skip_load_balance_distributed, &
1859 pw_env_external=pw_env_sub, sab_orb_external=sab_orb_sub)
1864 ALLOCATE (matrix_pq_rnu(nspins), fm_matrix_pq_rnu(nspins), fm_matrix_pq_rs(nspins))
1865 DO ispin = 1, nspins
1866 CALL dbcsr_create(matrix_pq_rnu(ispin), template=mo_coeff_as(ispin))
1867 CALL dbcsr_set(matrix_pq_rnu(ispin), 0.0_dp)
1869 CALL dbcsr_get_info(matrix_pq_rnu(ispin), nfullrows_total=nrow_global, nfullcols_total=ncol_global)
1872 CALL cp_fm_struct_create(fm_struct, context=blacs_env_sub, para_env=eri_env%para_env_sub, &
1873 nrow_global=nrow_global, ncol_global=ncol_global)
1878 CALL cp_fm_struct_create(fm_struct, context=blacs_env_sub, para_env=eri_env%para_env_sub, &
1879 nrow_global=ncol_global, ncol_global=ncol_global)
1887 CALL auxbas_pw_pool%create_pw(wfn_r)
1888 CALL auxbas_pw_pool%create_pw(rho_g)
1889 CALL get_qs_env(qs_env, qs_kind_set=qs_kind_set, cell=cell, &
1890 particle_set=particle_set, atomic_kind_set=atomic_kind_set)
1896 IF (restricted) nspins = 1
1897 IF (eri_env%eri_gpw%store_wfn)
THEN
1901 DO ispin = 1, nspins
1904 rsize = real(
SIZE(wfn_r%array), kind=
dp)*nx
1906 IF (print1 .AND. iw > 0)
THEN
1907 rsize = rsize*8._dp/1000000._dp
1908 WRITE (iw,
"(T2,'ERI_GPW|',' Store active orbitals on real space grid ',T66,F12.3,' MB')") rsize
1910 ALLOCATE (wfn_a(nmo, nspins))
1911 DO ispin = 1, nspins
1912 CALL get_mo_set(mo_set=mos(ispin), mo_coeff=mo_coeff, nmo=nmo)
1913 DO i1 = 1,
SIZE(orbitals, 1)
1914 iwfn = orbitals(i1, ispin)
1915 CALL auxbas_pw_pool%create_pw(wfn_a(iwfn, ispin))
1917 qs_kind_set, cell, dft_control, particle_set, pw_env_sub)
1918 IF (print2 .AND. iw > 0)
THEN
1919 WRITE (iw,
"(T2,'ERI_GPW|',' Orbital stored ',I4,' Spin ',i1)") iwfn, ispin
1925 ALLOCATE (wfn1, wfn2)
1926 CALL auxbas_pw_pool%create_pw(wfn1)
1927 CALL auxbas_pw_pool%create_pw(wfn2)
1929 ALLOCATE (wfn3, wfn4)
1930 CALL auxbas_pw_pool%create_pw(wfn3)
1931 CALL auxbas_pw_pool%create_pw(wfn4)
1936 CALL auxbas_pw_pool%create_pw(rho_r)
1937 CALL auxbas_pw_pool%create_pw(pot_g)
1942 dvol = rho_r%pw_grid%dvol
1948 stored_integrals = 0
1951 nmm = (nmo1*(nmo1 + 1))/2
1952 DO i1 = 1,
SIZE(orbitals, 1)
1953 iwa1 = orbitals(i1, isp1)
1954 IF (eri_env%eri_gpw%store_wfn)
THEN
1955 wfn1 => wfn_a(iwa1, isp1)
1958 qs_kind_set, cell, dft_control, particle_set, pw_env_sub)
1960 DO i2 = i1,
SIZE(orbitals, 1)
1961 iwa2 = orbitals(i2, isp1)
1964 IF (mod(iwa12 - 1, eri_env%comm_exchange%num_pe) /= eri_env%comm_exchange%mepos) cycle
1965 iwa12 = (iwa12 - 1)/eri_env%comm_exchange%num_pe + 1
1966 IF (eri_env%eri_gpw%store_wfn)
THEN
1967 wfn2 => wfn_a(iwa2, isp1)
1970 qs_kind_set, cell, dft_control, particle_set, pw_env_sub)
1979 IF (pair_int < eri_env%eps_integral) cycle
1984 DO isp2 = isp1, nspins
1986 nx = (nmo2*(nmo2 + 1))/2
1987 ALLOCATE (eri(nx), eri_index(nx))
1989 CALL integrate_v_rspace(rho_r, hmat=mat_munu, qs_env=qs_env, &
1990 calculate_forces=.false., compute_tau=.false., gapw=.false., &
1991 pw_env_external=pw_env_sub, task_list_external=task_list_sub)
1993 CALL dbcsr_multiply(
"N",
"N", 1.0_dp, mat_munu%matrix, mo_coeff_as(isp2), &
1994 0.0_dp, matrix_pq_rnu(isp2), filter_eps=eri_env%eri_gpw%eps_filter)
1997 CALL cp_fm_get_info(fm_matrix_pq_rnu(isp2), ncol_global=ncol_global, nrow_global=nrow_global)
1999 CALL parallel_gemm(
"T",
"N", ncol_global, ncol_global, nrow_global, 0.5_dp, &
2000 fm_matrix_pq_rnu(isp2), fm_mo_coeff_as(isp2), &
2001 0.0_dp, fm_matrix_pq_rs(isp2))
2002 CALL parallel_gemm(
"T",
"N", ncol_global, ncol_global, nrow_global, 0.5_dp, &
2003 fm_mo_coeff_as(isp2), fm_matrix_pq_rnu(isp2), &
2004 1.0_dp, fm_matrix_pq_rs(isp2))
2006 CALL cp_fm_get_info(fm_matrix_pq_rs(isp2), ncol_local=ncol_local, nrow_local=nrow_local, &
2007 col_indices=col_indices, row_indices=row_indices)
2010 DO col_local = 1, ncol_local
2011 iwb1 = orbitals(col_indices(col_local), isp2)
2012 IF (isp1 == isp2 .AND. iwb1 < iwa1) cycle
2013 DO row_local = 1, nrow_local
2014 iwb2 = orbitals(row_indices(row_local), isp2)
2015 IF (iwb2 < iwb1) cycle
2016 IF (isp1 == isp2 .AND. iwa1 == iwb1 .AND. iwb2 < iwa2) cycle
2019 erint = fm_matrix_pq_rs(isp2)%local_data(row_local, col_local)
2020 IF (abs(erint) > eri_env%eps_integral)
THEN
2021 icount2 = icount2 + 1
2022 eri(icount2) = erint
2023 eri_index(icount2) = iwb12
2027 stored_integrals = stored_integrals + icount2
2029 isp = (isp1 - 1)*isp2 + (isp2 - isp1 + 1)
2030 CALL update_csr_matrix(eri_env%eri(isp)%csr_mat, icount2, eri, eri_index, iwa12)
2032 DEALLOCATE (eri, eri_index)
2035 DO isp2 = isp1, nspins
2037 nx = (nmo2*(nmo2 + 1))/2
2038 ALLOCATE (eri(nx), eri_index(nx))
2041 IF (isp1 == isp2) iwbs = i1
2042 isp = (isp1 - 1)*isp2 + (isp2 - isp1 + 1)
2043 DO i3 = iwbs,
SIZE(orbitals, 1)
2044 iwb1 = orbitals(i3, isp2)
2045 IF (eri_env%eri_gpw%store_wfn)
THEN
2046 wfn3 => wfn_a(iwb1, isp2)
2049 qs_kind_set, cell, dft_control, particle_set, pw_env_sub)
2054 IF (isp1 == isp2 .AND. i1 == i3) iwbt = i2
2055 DO i4 = iwbt,
SIZE(orbitals, 1)
2056 iwb2 = orbitals(i4, isp2)
2057 IF (eri_env%eri_gpw%store_wfn)
THEN
2058 wfn4 => wfn_a(iwb2, isp2)
2061 qs_kind_set, cell, dft_control, particle_set, pw_env_sub)
2065 icount2 = icount2 + 1
2066 eri(icount2) = erint
2071 CALL eri_env%para_env_sub%sum(eri)
2076 IF (isp1 == isp2) iwbs = i1
2077 isp = (isp1 - 1)*isp2 + (isp2 - isp1 + 1)
2078 DO i3 = iwbs,
SIZE(orbitals, 1)
2079 iwb1 = orbitals(i3, isp2)
2081 IF (isp1 == isp2 .AND. i1 == i3) iwbt = i2
2082 DO i4 = iwbt,
SIZE(orbitals, 1)
2083 iwb2 = orbitals(i4, isp2)
2084 intcount = intcount + 1
2085 erint = eri(intcount)
2086 IF (abs(erint) > eri_env%eps_integral)
THEN
2087 IF (mod(intcount, eri_env%para_env_sub%num_pe) == eri_env%para_env_sub%mepos)
THEN
2088 icount2 = icount2 + 1
2089 eri(icount2) = erint
2090 eri_index(icount2) = eri_index(intcount)
2095 stored_integrals = stored_integrals + icount2
2097 CALL update_csr_matrix(eri_env%eri(isp)%csr_mat, icount2, eri, eri_index, iwa12)
2099 DEALLOCATE (eri, eri_index)
2102 cpabort(
"Unknown option")
2108 IF (print1 .AND. iw > 0)
THEN
2109 WRITE (iw,
"(T2,'ERI_GPW|',' Number of Integrals stored locally',T71,I10)") stored_integrals
2112 IF (eri_env%eri_gpw%store_wfn)
THEN
2113 DO ispin = 1, nspins
2114 DO i1 = 1,
SIZE(orbitals, 1)
2115 iwfn = orbitals(i1, ispin)
2116 CALL wfn_a(iwfn, ispin)%release()
2123 DEALLOCATE (wfn1, wfn2)
2127 DEALLOCATE (wfn3, wfn4)
2130 CALL auxbas_pw_pool%give_back_pw(wfn_r)
2131 CALL auxbas_pw_pool%give_back_pw(rho_g)
2132 CALL auxbas_pw_pool%give_back_pw(rho_r)
2133 CALL auxbas_pw_pool%give_back_pw(pot_g)
2136 DO ispin = 1, nspins
2142 DEALLOCATE (matrix_pq_rnu, fm_matrix_pq_rnu, fm_matrix_pq_rs)
2145 DO ispin = 1, nspins
2149 DEALLOCATE (mo_coeff_as, fm_mo_coeff_as)
2153 DEALLOCATE (mat_munu%matrix)
2156 dft_control%qs_control => qs_control_old
2157 DEALLOCATE (qs_control%e_cutoff)
2158 DEALLOCATE (qs_control)
2163 WRITE (iw,
'(/,T2,A,T66,F14.2)')
"ERI_GPW| ERI calculation took (sec)", t2 - t1
2167 CALL timestop(handle)
2169 END SUBROUTINE calculate_eri_gpw
2179 SUBROUTINE pw_eri_green_create(green, eri_env)
2181 TYPE(greens_fn_type),
INTENT(INOUT) :: green
2182 TYPE(eri_type) :: eri_env
2184 COMPLEX(KIND=dp) :: erf_fac_p, z_p
2186 REAL(kind=dp) :: cossin_fac, ea, erfcos_fac, exp_prefac, &
2187 g, g0, g2, g3d, ga, ginf, omega, &
2191 associate(gf => green%influence_fn, grid => green%influence_fn%pw_grid)
2192 SELECT CASE (green%method)
2195 SELECT CASE (eri_env%operator)
2196 CASE (eri_operator_coulomb)
2197 DO ig = grid%first_gne0, grid%ngpts_cut_local
2199 gf%array(ig) = fourpi/g2
2201 IF (grid%have_g0) gf%array(1) = 0.0_dp
2203 CASE (eri_operator_yukawa)
2204 CALL cp_warn(__location__,
"Yukawa operator has not been tested")
2205 omega2 = eri_env%omega**2
2206 DO ig = grid%first_gne0, grid%ngpts_cut_local
2208 gf%array(ig) = fourpi/(omega2 + g2)
2210 IF (grid%have_g0) gf%array(1) = fourpi/omega2
2212 CASE (eri_operator_erf)
2213 omega2 = eri_env%omega**2
2214 DO ig = grid%first_gne0, grid%ngpts_cut_local
2216 gf%array(ig) = fourpi/g2*exp(-0.25_dp*g2/omega2)
2218 IF (grid%have_g0) gf%array(1) = 0.0_dp
2220 CASE (eri_operator_erfc)
2221 omega2 = eri_env%omega**2
2222 DO ig = grid%first_gne0, grid%ngpts_cut_local
2224 gf%array(ig) = fourpi/g2*(1.0_dp - exp(-0.25_dp*g2/omega2))
2226 IF (grid%have_g0) gf%array(1) = pi/omega2
2228 CASE (eri_operator_trunc)
2229 rc = eri_env%cutoff_radius
2230 DO ig = grid%first_gne0, grid%ngpts_cut_local
2234 IF (g*rc >= 0.005_dp)
THEN
2235 gf%array(ig) = fourpi/g2*(1.0_dp - cos(g*rc))
2237 gf%array(ig) = fourpi/g2*(g*rc)**2/2.0_dp*(1.0_dp - (g*rc)**2/12.0_dp)
2240 IF (grid%have_g0) gf%array(1) = twopi*rc**2
2242 CASE (eri_operator_lr_trunc)
2243 omega = eri_env%omega
2245 rc = eri_env%cutoff_radius
2249 DO ig = grid%first_gne0, grid%ngpts_cut_local
2252 IF (g <= 2.0_dp*g0)
THEN
2253 gf%array(ig) = -pi/omega2*erf(omega*rc) &
2254 + twopi*rc2*erf(omega*rc) &
2255 + 2*rootpi*rc*exp(-omega2*rc2)/omega
2256 ELSE IF (g >= 2.0_dp*ginf*omega)
THEN
2258 exp_prefac = exp(-omega2*rc2)/(rootpi*(omega2*rc2 + 0.25_dp*g2/omega2))
2260 cossin_fac = omega*rc*cos(g*rc) - 0.5_dp*g/omega*sin(g*rc)
2262 erfcos_fac = erf(omega*rc)*cos(g*rc)
2264 gf%array(ig) = fourpi/g2*(-exp_prefac*cossin_fac - erfcos_fac)
2267 exp_prefac = twopi/g2*exp(-0.25_dp*g2/omega2)
2269 z_p = cmplx(omega*rc, 0.5_dp*g/omega, kind=dp)
2271 erf_fac_p = 2.0_dp*real(erfz_fast(z_p))
2273 erfcos_fac = fourpi/g2*erf(omega*rc)*cos(g*rc)
2275 gf%array(ig) = exp_prefac*erf_fac_p - erfcos_fac
2278 IF (grid%have_g0)
THEN
2279 gf%array(1) = -pi/omega2*erf(omega*rc) &
2280 + twopi*rc2*erf(omega*rc) &
2281 + 2*rootpi*rc*exp(-omega2*rc2)/omega
2285 cpabort(
"Please specify a valid operator for the periodic Poisson solver")
2293 SELECT CASE (eri_env%operator)
2297 CASE (eri_operator_coulomb, eri_operator_trunc)
2298 IF (eri_env%operator == eri_operator_coulomb)
THEN
2301 rc = eri_env%cutoff_radius
2303 DO ig = grid%first_gne0, grid%ngpts_cut_local
2307 IF (g*rc >= 0.005_dp)
THEN
2308 gf%array(ig) = fourpi/g2*(1.0_dp - cos(g*rc))
2310 gf%array(ig) = fourpi/g2*(g*rc)**2/2.0_dp*(1.0_dp - (g*rc)**2/12.0_dp)
2313 IF (grid%have_g0) gf%array(1) = twopi*rc**2
2316 CASE (eri_operator_yukawa)
2317 CALL cp_warn(__location__,
"Yukawa operator has not been tested")
2319 omega = eri_env%omega
2321 DO ig = grid%first_gne0, grid%ngpts_cut_local
2324 g3d = fourpi/(omega**2 + g2)
2325 gf%array(ig) = g3d*(1.0_dp - ea*(cos(g*rc) + omega/g*sin(g*rc)))
2327 IF (grid%have_g0) gf%array(1) = fourpi/(omega**2)*(1.0_dp - ea*(1.0_dp + omega*rc))
2331 CASE (eri_operator_erf, eri_operator_lr_trunc)
2332 IF (eri_env%operator == eri_operator_erf)
THEN
2335 rc = eri_env%cutoff_radius
2337 omega2 = eri_env%omega**2
2338 DO ig = grid%first_gne0, grid%ngpts_cut_local
2341 ga = -0.25_dp*g2/omega2
2342 gf%array(ig) = fourpi/g2*exp(ga)*(1.0_dp - cos(g*rc))
2344 IF (grid%have_g0) gf%array(1) = twopi*rc**2
2348 CASE (eri_operator_erfc)
2349 CALL cp_warn(__location__, &
2350 "Short-range Coulomb operator may be incorrect with ANALYTIC0D Poisson solver")
2352 omega2 = eri_env%omega**2
2353 DO ig = grid%first_gne0, grid%ngpts_cut_local
2356 ga = -0.25_dp*g2/omega2
2357 gf%array(ig) = fourpi/g2*(1.0_dp - exp(ga))*(1.0_dp - cos(g*rc))
2359 IF (grid%have_g0) gf%array(1) = pi/omega2
2362 cpabort(
"Unsupported operator")
2366 cpabort(
"Unsupported Poisson solver")
2370 END SUBROUTINE pw_eri_green_create
2382 SUBROUTINE update_csr_matrix(csr_mat, nnz, rdat, rind, irow)
2384 TYPE(dbcsr_csr_type),
INTENT(INOUT) :: csr_mat
2385 INTEGER,
INTENT(IN) :: nnz
2386 REAL(kind=dp),
DIMENSION(:),
INTENT(IN) :: rdat
2387 INTEGER,
DIMENSION(:),
INTENT(IN) :: rind
2388 INTEGER,
INTENT(IN) :: irow
2390 INTEGER :: k, nrow, nze, nze_new
2393 nze = csr_mat%nze_local
2396 CALL reallocate(csr_mat%nzval_local%r_dp, 1, nze_new)
2397 csr_mat%nzval_local%r_dp(nze + 1:nze_new) = rdat(1:nnz)
2399 CALL reallocate(csr_mat%colind_local, 1, nze_new)
2400 csr_mat%colind_local(nze + 1:nze_new) = rind(1:nnz)
2402 nrow = csr_mat%nrows_local
2403 CALL reallocate(csr_mat%rowptr_local, 1, irow + 1)
2404 csr_mat%rowptr_local(nrow + 1:irow) = nze + 1
2405 csr_mat%rowptr_local(irow + 1) = nze_new + 1
2407 CALL reallocate(csr_mat%nzerow_local, 1, irow)
2408 DO k = nrow + 1, irow
2409 csr_mat%nzerow_local(k) = csr_mat%rowptr_local(k + 1) - csr_mat%rowptr_local(k)
2411 csr_mat%nrows_local = irow
2412 csr_mat%nze_local = csr_mat%nze_local + nnz
2414 csr_mat%nze_total = csr_mat%nze_total + nnz
2415 csr_mat%has_indices = .true.
2417 END SUBROUTINE update_csr_matrix
2425 SUBROUTINE print_orbital_cubes(input, qs_env, mos)
2426 TYPE(section_vals_type),
POINTER :: input
2427 TYPE(qs_environment_type),
POINTER :: qs_env
2428 TYPE(mo_set_type),
DIMENSION(:),
INTENT(IN) :: mos
2430 CHARACTER(LEN=default_path_length) :: filebody, filename, title
2431 INTEGER :: i, imo, isp, nmo, str(3), unit_nr
2432 INTEGER,
DIMENSION(:),
POINTER :: alist, blist, istride
2433 LOGICAL :: do_mo, explicit_a, explicit_b
2434 TYPE(atomic_kind_type),
DIMENSION(:),
POINTER :: atomic_kind_set
2435 TYPE(cell_type),
POINTER :: cell
2436 TYPE(cp_fm_type),
POINTER :: mo_coeff
2437 TYPE(dft_control_type),
POINTER :: dft_control
2438 TYPE(mp_para_env_type),
POINTER :: para_env
2439 TYPE(particle_list_type),
POINTER :: particles
2440 TYPE(particle_type),
DIMENSION(:),
POINTER :: particle_set
2441 TYPE(pw_c1d_gs_type) :: wf_g
2442 TYPE(pw_env_type),
POINTER :: pw_env
2443 TYPE(pw_pool_type),
POINTER :: auxbas_pw_pool
2444 TYPE(pw_r3d_rs_type) :: wf_r
2445 TYPE(qs_kind_type),
DIMENSION(:),
POINTER :: qs_kind_set
2446 TYPE(qs_subsys_type),
POINTER :: subsys
2447 TYPE(section_vals_type),
POINTER :: dft_section, scf_input
2449 CALL section_vals_val_get(input,
"FILENAME", c_val=filebody)
2450 CALL section_vals_val_get(input,
"STRIDE", i_vals=istride)
2451 IF (
SIZE(istride) == 1)
THEN
2452 str(1:3) = istride(1)
2453 ELSE IF (
SIZE(istride) == 3)
THEN
2454 str(1:3) = istride(1:3)
2456 cpabort(
"STRIDE arguments inconsistent")
2458 CALL section_vals_val_get(input,
"ALIST", i_vals=alist, explicit=explicit_a)
2459 CALL section_vals_val_get(input,
"BLIST", i_vals=blist, explicit=explicit_b)
2461 CALL get_qs_env(qs_env=qs_env, &
2462 dft_control=dft_control, &
2463 para_env=para_env, &
2465 atomic_kind_set=atomic_kind_set, &
2466 qs_kind_set=qs_kind_set, &
2468 particle_set=particle_set, &
2472 CALL qs_subsys_get(subsys, particles=particles)
2474 CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool)
2475 CALL auxbas_pw_pool%create_pw(wf_r)
2476 CALL auxbas_pw_pool%create_pw(wf_g)
2478 dft_section => section_vals_get_subs_vals(scf_input,
"DFT")
2480 DO isp = 1,
SIZE(mos)
2481 CALL get_mo_set(mo_set=mos(isp), mo_coeff=mo_coeff, nmo=nmo)
2483 IF (
SIZE(mos) > 1)
THEN
2486 CALL write_mo_set_to_output_unit(mos(isp), qs_kind_set, particle_set, &
2487 dft_section, 4, 0, final_mos=.true., spin=
"ALPHA")
2489 CALL write_mo_set_to_output_unit(mos(isp), qs_kind_set, particle_set, &
2490 dft_section, 4, 0, final_mos=.true., spin=
"BETA")
2492 cpabort(
"Invalid spin")
2495 CALL write_mo_set_to_output_unit(mos(isp), qs_kind_set, particle_set, &
2496 dft_section, 4, 0, final_mos=.true.)
2500 IF (isp == 1 .AND. explicit_a)
THEN
2501 IF (alist(1) == -1)
THEN
2505 DO i = 1,
SIZE(alist)
2506 IF (imo == alist(i)) do_mo = .true.
2509 ELSE IF (isp == 2 .AND. explicit_b)
THEN
2510 IF (blist(1) == -1)
THEN
2514 DO i = 1,
SIZE(blist)
2515 IF (imo == blist(i)) do_mo = .true.
2521 IF (.NOT. do_mo) cycle
2522 CALL calculate_wavefunction(mo_coeff, imo, wf_r, wf_g, atomic_kind_set, &
2523 qs_kind_set, cell, dft_control, particle_set, pw_env)
2524 IF (para_env%is_source())
THEN
2525 WRITE (filename,
'(A,A1,I4.4,A1,I1.1,A)') trim(filebody),
"_", imo,
"_", isp,
".cube"
2526 CALL open_file(filename, unit_number=unit_nr, file_status=
"UNKNOWN", file_action=
"WRITE")
2527 WRITE (title, *)
"Active Orbital ", imo,
" spin ", isp
2531 CALL cp_pw_to_cube(wf_r, unit_nr, title, particles=particles, stride=istride)
2532 IF (para_env%is_source())
THEN
2533 CALL close_file(unit_nr)
2538 CALL auxbas_pw_pool%give_back_pw(wf_r)
2539 CALL auxbas_pw_pool%give_back_pw(wf_g)
2541 END SUBROUTINE print_orbital_cubes
2552 SUBROUTINE fcidump(active_space_env, as_input, restricted, check_reference)
2554 TYPE(active_space_type),
POINTER :: active_space_env
2555 TYPE(section_vals_type),
POINTER :: as_input
2556 LOGICAL,
INTENT(IN) :: restricted, check_reference
2558 CHARACTER(LEN=*),
PARAMETER :: roks_warning = &
2559 "ROKS FCIDUMP spin blocks differ. Check the cell size and the consistency of "// &
2560 "the SCF exchange and active-space ERI operators."
2561 REAL(kind=dp),
PARAMETER :: roks_fock_tol = 1.0e-6_dp
2563 INTEGER :: i, i1, i2, i3, i4, isym, iw, m1, m2, &
2564 ms2, nmo, norb, nspins
2565 REAL(kind=dp) :: checksum, esub, spin_difference
2566 REAL(kind=dp),
ALLOCATABLE,
DIMENSION(:, :) :: fmat, fock_diff, pmat
2567 TYPE(cp_logger_type),
POINTER :: logger
2568 TYPE(eri_fcidump_checksum) :: eri_checksum
2569 TYPE(eri_fcidump_print) :: writer
2572 spin_difference = 0.0_dp
2574 logger => cp_get_default_logger()
2575 iw = cp_print_key_unit_nr(logger, as_input,
"FCIDUMP", &
2576 extension=
".fcidump", file_status=
"REPLACE", file_action=
"WRITE", file_form=
"FORMATTED")
2578 nspins = active_space_env%nspins
2579 norb =
SIZE(active_space_env%active_orbitals, 1)
2580 ms2 = active_space_env%multiplicity - 1
2581 IF (nspins == 1 .OR. restricted)
THEN
2583 associate(nelec => active_space_env%nelec_active)
2586 WRITE (iw,
"(A,A,I4,A,I4,A,I2,A)")
"&FCI",
" NORB=", norb,
",NELEC=", nelec,
",MS2=", ms2,
","
2588 WRITE (iw,
"(A,1000(I1,','))")
" ORBSYM=", (isym, i=1, norb)
2590 WRITE (iw,
"(A,I1,A)")
" ISYM=", isym,
","
2591 IF (restricted)
WRITE (iw,
"(A,I1,A)")
" UHF=", 0,
","
2592 WRITE (iw,
"(A)")
" /"
2596 writer = eri_fcidump_print(iw, 1, 1)
2597 IF (check_reference)
THEN
2598 writer%nalpha = (nelec + ms2)/2
2599 writer%nbeta = (nelec - ms2)/2
2601 CALL active_space_env%eri%eri_foreach(1, active_space_env%active_orbitals, &
2603 CALL eri_checksum%set(1, 1)
2604 CALL active_space_env%eri%eri_foreach(1, active_space_env%active_orbitals, eri_checksum, 1, 1)
2608 nmo = active_space_env%eri%norb
2609 ALLOCATE (fmat(nmo, nmo))
2610 CALL replicate_and_symmetrize_matrix(nmo, active_space_env%fock_sub(1), fmat)
2611 esub = active_space_env%energy_inactive
2612 IF (restricted)
THEN
2613 ALLOCATE (fock_diff(nmo, nmo), pmat(nmo, nmo))
2614 CALL replicate_and_symmetrize_matrix(nmo, active_space_env%fock_sub(2), fock_diff)
2615 fock_diff(:, :) = fmat - fock_diff
2616 associate(active => active_space_env%active_orbitals(:, 1))
2617 spin_difference = maxval(abs(fock_diff(active, active)))
2620 fmat(:, :) = fmat - 0.5_dp*fock_diff
2621 CALL replicate_and_symmetrize_matrix(nmo, active_space_env%p_active(1), pmat)
2622 esub = esub + 0.5_dp*sum(fock_diff*pmat)
2623 CALL replicate_and_symmetrize_matrix(nmo, active_space_env%p_active(2), pmat)
2624 esub = esub - 0.5_dp*sum(fock_diff*pmat)
2625 DEALLOCATE (fock_diff, pmat)
2629 DO m1 = 1,
SIZE(active_space_env%active_orbitals, 1)
2630 i1 = active_space_env%active_orbitals(m1, 1)
2631 IF (m1 <= writer%nalpha) writer%determinant_energy = writer%determinant_energy + fmat(i1, i1)
2632 IF (m1 <= writer%nbeta) writer%determinant_energy = writer%determinant_energy + fmat(i1, i1)
2633 DO m2 = m1,
SIZE(active_space_env%active_orbitals, 1)
2634 i2 = active_space_env%active_orbitals(m2, 1)
2635 checksum = checksum + abs(fmat(i1, i2))
2636 WRITE (iw,
"(ES23.16,4I4)") fmat(i1, i2), m1, m2, i3, i4
2642 i1 = 0; i2 = 0; i3 = 0; i4 = 0
2643 checksum = checksum + abs(esub)
2644 IF (iw > 0)
WRITE (iw,
"(ES23.16,4I4)") esub, i1, i2, i3, i4
2648 associate(nelec => active_space_env%nelec_active)
2651 WRITE (iw,
"(A,A,I4,A,I4,A,I2,A)")
"&FCI",
" NORB=", norb,
",NELEC=", nelec,
",MS2=", ms2,
","
2653 WRITE (iw,
"(A,1000(I1,','))")
" ORBSYM=", (isym, i=1, norb)
2655 WRITE (iw,
"(A,I1,A)")
" ISYM=", isym,
","
2656 WRITE (iw,
"(A,I1,A)")
" UHF=", 1,
","
2657 WRITE (iw,
"(A)")
" /"
2662 CALL active_space_env%eri%eri_foreach(1, active_space_env%active_orbitals, &
2663 eri_fcidump_print(iw, 1, 1), 1, 1)
2664 CALL eri_checksum%set(1, 1)
2665 CALL active_space_env%eri%eri_foreach(1, active_space_env%active_orbitals, eri_checksum, 1, 1)
2667 CALL active_space_env%eri%eri_foreach(2, active_space_env%active_orbitals, &
2668 eri_fcidump_print(iw, 1, norb + 1), 1, 2)
2669 CALL eri_checksum%set(1, norb + 1)
2670 CALL active_space_env%eri%eri_foreach(2, active_space_env%active_orbitals, eri_checksum, 1, 2)
2672 CALL active_space_env%eri%eri_foreach(3, active_space_env%active_orbitals, &
2673 eri_fcidump_print(iw, norb + 1, norb + 1), 2, 2)
2674 CALL eri_checksum%set(norb + 1, norb + 1)
2675 CALL active_space_env%eri%eri_foreach(3, active_space_env%active_orbitals, eri_checksum, 2, 2)
2678 nmo = active_space_env%eri%norb
2679 ALLOCATE (fmat(nmo, nmo))
2680 CALL replicate_and_symmetrize_matrix(nmo, active_space_env%fock_sub(1), fmat)
2684 i1 = active_space_env%active_orbitals(m1, 1)
2686 i2 = active_space_env%active_orbitals(m2, 1)
2687 checksum = checksum + abs(fmat(i1, i2))
2688 WRITE (iw,
"(ES23.16,4I4)") fmat(i1, i2), m1, m2, i3, i4
2694 ALLOCATE (fmat(nmo, nmo))
2695 CALL replicate_and_symmetrize_matrix(nmo, active_space_env%fock_sub(2), fmat)
2698 DO m1 = 1,
SIZE(active_space_env%active_orbitals, 1)
2699 i1 = active_space_env%active_orbitals(m1, 2)
2700 DO m2 = m1,
SIZE(active_space_env%active_orbitals, 1)
2701 i2 = active_space_env%active_orbitals(m2, 2)
2702 checksum = checksum + abs(fmat(i1, i2))
2703 WRITE (iw,
"(ES23.16,4I4)") fmat(i1, i2), m1 + norb, m2 + norb, i3, i4
2709 esub = active_space_env%energy_inactive
2710 i1 = 0; i2 = 0; i3 = 0; i4 = 0
2711 checksum = checksum + abs(esub)
2712 IF (iw > 0)
WRITE (iw,
"(ES23.16,4I4)") esub, i1, i2, i3, i4
2716 CALL cp_print_key_finished_output(iw, logger, as_input,
"FCIDUMP")
2719 iw = cp_logger_get_default_io_unit(logger)
2720 IF (iw > 0)
WRITE (iw,
'(T4,A,T66,F12.8)')
"FCIDUMP| Checksum:", eri_checksum%checksum + checksum
2721 IF (restricted)
THEN
2722 IF (check_reference .AND. writer%unit_nr > 0 .AND. iw > 0)
THEN
2723 WRITE (iw,
'(T4,A,1X,ES23.16)')
"FCIDUMP| Reference determinant energy offset [hartree]:", &
2724 writer%determinant_energy + esub - active_space_env%energy_ref
2726 IF (iw > 0)
WRITE (iw,
'(T4,A,1X,ES12.5)') &
2727 "FCIDUMP| Max. ROKS spin-block difference [hartree]:", spin_difference
2728 IF (spin_difference > roks_fock_tol)
THEN
2729 cpwarn(roks_warning)
2734 END SUBROUTINE fcidump
2742 SUBROUTINE replicate_and_symmetrize_matrix(norb, distributed_matrix, replicated_matrix)
2743 INTEGER,
INTENT(IN) :: norb
2744 TYPE(cp_fm_type),
INTENT(IN) :: distributed_matrix
2745 REAL(dp),
DIMENSION(:, :),
INTENT(INOUT) :: replicated_matrix
2750 replicated_matrix(:, :) = 0.0_dp
2753 CALL cp_fm_get_element(distributed_matrix, i1, i2, mval)
2754 replicated_matrix(i1, i2) = mval
2755 replicated_matrix(i2, i1) = mval
2758 END SUBROUTINE replicate_and_symmetrize_matrix
2767 SUBROUTINE subspace_fock_matrix(active_space_env, restricted)
2769 TYPE(active_space_type),
POINTER :: active_space_env
2770 LOGICAL,
INTENT(IN) :: restricted
2772 INTEGER :: i1, i2, is, norb, nspins
2773 REAL(kind=dp) :: eeri, eref, esub, mval
2774 REAL(kind=dp),
ALLOCATABLE,
DIMENSION(:, :) :: ks_a_mat, ks_a_ref, ks_b_mat, ks_b_ref, &
2775 ks_mat, ks_ref, p_a_mat, p_b_mat, p_mat
2776 TYPE(cp_fm_type),
POINTER :: matrix, mo_coef
2777 TYPE(dbcsr_csr_type),
POINTER :: eri, eri_aa, eri_ab, eri_bb
2779 eref = active_space_env%energy_ref
2780 nspins = active_space_env%nspins
2782 IF (nspins == 1)
THEN
2783 CALL get_mo_set(active_space_env%mos_active(1), nmo=norb, mo_coeff=mo_coef)
2788 ALLOCATE (ks_mat(norb, norb), ks_ref(norb, norb), p_mat(norb, norb))
2792 CALL replicate_and_symmetrize_matrix(norb, active_space_env%ks_sub(1), ks_mat)
2793 CALL replicate_and_symmetrize_matrix(norb, active_space_env%p_active(1), p_mat)
2796 eri => active_space_env%eri%eri(1)%csr_mat
2797 CALL build_subspace_fock_matrix(active_space_env%active_orbitals, eri, p_mat, ks_ref, &
2798 active_space_env%eri%comm_exchange)
2802 eeri = 0.5_dp*sum(ks_ref*p_mat)
2808 esub = eref - sum(ks_mat(1:norb, 1:norb)*p_mat(1:norb, 1:norb)) + eeri
2811 ks_mat(1:norb, 1:norb) = ks_mat(1:norb, 1:norb) - ks_ref(1:norb, 1:norb)
2814 active_space_env%energy_inactive = esub
2816 CALL cp_fm_release(active_space_env%fock_sub)
2817 ALLOCATE (active_space_env%fock_sub(nspins))
2819 matrix => active_space_env%ks_sub(is)
2820 CALL cp_fm_create(active_space_env%fock_sub(is), matrix%matrix_struct, &
2821 name=
"Active Fock operator")
2823 matrix => active_space_env%fock_sub(1)
2826 mval = ks_mat(i1, i2)
2827 CALL cp_fm_set_element(matrix, i1, i2, mval)
2832 CALL get_mo_set(active_space_env%mos_active(1), nmo=norb)
2837 ALLOCATE (ks_a_mat(norb, norb), ks_b_mat(norb, norb), &
2838 & ks_a_ref(norb, norb), ks_b_ref(norb, norb), &
2839 & p_a_mat(norb, norb), p_b_mat(norb, norb))
2840 ks_a_ref(:, :) = 0.0_dp; ks_b_ref(:, :) = 0.0_dp
2842 CALL replicate_and_symmetrize_matrix(norb, active_space_env%p_active(1), p_a_mat)
2843 CALL replicate_and_symmetrize_matrix(norb, active_space_env%p_active(2), p_b_mat)
2844 CALL replicate_and_symmetrize_matrix(norb, active_space_env%ks_sub(1), ks_a_mat)
2845 CALL replicate_and_symmetrize_matrix(norb, active_space_env%ks_sub(2), ks_b_mat)
2848 IF (restricted)
THEN
2850 eri_aa => active_space_env%eri%eri(1)%csr_mat
2851 CALL build_subspace_spin_fock_matrix(active_space_env%active_orbitals, eri_aa, eri_aa, p_a_mat, p_b_mat, ks_a_ref, &
2852 tr_mixed_eri=.false., comm_exchange=active_space_env%eri%comm_exchange, &
2853 restricted=restricted)
2854 CALL build_subspace_spin_fock_matrix(active_space_env%active_orbitals, eri_aa, eri_aa, p_b_mat, p_a_mat, ks_b_ref, &
2855 tr_mixed_eri=.true., comm_exchange=active_space_env%eri%comm_exchange, &
2856 restricted=restricted)
2858 eri_aa => active_space_env%eri%eri(1)%csr_mat
2859 eri_ab => active_space_env%eri%eri(2)%csr_mat
2860 eri_bb => active_space_env%eri%eri(3)%csr_mat
2861 CALL build_subspace_spin_fock_matrix(active_space_env%active_orbitals, eri_aa, eri_ab, p_a_mat, p_b_mat, ks_a_ref, &
2862 tr_mixed_eri=.false., comm_exchange=active_space_env%eri%comm_exchange, &
2863 restricted=restricted)
2864 CALL build_subspace_spin_fock_matrix(active_space_env%active_orbitals, eri_bb, eri_ab, p_b_mat, p_a_mat, ks_b_ref, &
2865 tr_mixed_eri=.true., comm_exchange=active_space_env%eri%comm_exchange, &
2866 restricted=restricted)
2871 eeri = 0.5_dp*(sum(ks_a_ref*p_a_mat) + sum(ks_b_ref*p_b_mat))
2872 esub = eref - sum(ks_a_mat*p_a_mat) - sum(ks_b_mat*p_b_mat) + eeri
2873 ks_a_mat(:, :) = ks_a_mat(:, :) - ks_a_ref(:, :)
2874 ks_b_mat(:, :) = ks_b_mat(:, :) - ks_b_ref(:, :)
2876 active_space_env%energy_inactive = esub
2878 CALL cp_fm_release(active_space_env%fock_sub)
2879 ALLOCATE (active_space_env%fock_sub(nspins))
2881 matrix => active_space_env%ks_sub(is)
2882 CALL cp_fm_create(active_space_env%fock_sub(is), matrix%matrix_struct, &
2883 name=
"Active Fock operator")
2886 matrix => active_space_env%fock_sub(1)
2889 mval = ks_a_mat(i1, i2)
2890 CALL cp_fm_set_element(matrix, i1, i2, mval)
2893 matrix => active_space_env%fock_sub(2)
2896 mval = ks_b_mat(i1, i2)
2897 CALL cp_fm_set_element(matrix, i1, i2, mval)
2903 END SUBROUTINE subspace_fock_matrix
2913 SUBROUTINE build_subspace_fock_matrix(active_orbitals, eri, p_mat, ks_ref, comm_exchange)
2914 INTEGER,
DIMENSION(:, :),
INTENT(IN) :: active_orbitals
2915 TYPE(dbcsr_csr_type),
INTENT(IN) :: eri
2916 REAL(dp),
DIMENSION(:, :),
INTENT(IN) :: p_mat
2917 REAL(dp),
DIMENSION(:, :),
INTENT(INOUT) :: ks_ref
2918 TYPE(mp_comm_type),
INTENT(IN) :: comm_exchange
2920 CHARACTER(LEN=*),
PARAMETER :: routinen =
'build_subspace_fock_matrix'
2922 INTEGER :: handle, i1, i12, i12l, i2, i3, i34, &
2923 i34l, i4, irptr, m1, m2, nindex, &
2926 TYPE(mp_comm_type) :: mp_group
2928 CALL timeset(routinen, handle)
2931 norb =
SIZE(active_orbitals, 1)
2932 nmo_total =
SIZE(p_mat, 1)
2933 nindex = (nmo_total*(nmo_total + 1))/2
2934 CALL mp_group%set_handle(eri%mp_group%get_handle())
2936 i1 = active_orbitals(m1, 1)
2938 i2 = active_orbitals(m2, 1)
2939 i12 = csr_idx_to_combined(i1, i2, nmo_total)
2940 IF (mod(i12 - 1, comm_exchange%num_pe) == comm_exchange%mepos)
THEN
2941 i12l = (i12 - 1)/comm_exchange%num_pe + 1
2942 irptr = eri%rowptr_local(i12l) - 1
2943 DO i34l = 1, eri%nzerow_local(i12l)
2944 i34 = eri%colind_local(irptr + i34l)
2945 CALL csr_idx_from_combined(i34, nmo_total, i3, i4)
2946 erint = eri%nzval_local%r_dp(irptr + i34l)
2948 ks_ref(i1, i2) = ks_ref(i1, i2) + erint*p_mat(i3, i4)
2950 ks_ref(i1, i2) = ks_ref(i1, i2) + erint*p_mat(i3, i4)
2952 IF (i12 /= i34)
THEN
2953 ks_ref(i3, i4) = ks_ref(i3, i4) + erint*p_mat(i1, i2)
2955 ks_ref(i3, i4) = ks_ref(i3, i4) + erint*p_mat(i1, i2)
2959 erint = -0.5_dp*erint
2960 ks_ref(i1, i3) = ks_ref(i1, i3) + erint*p_mat(i2, i4)
2962 ks_ref(i2, i3) = ks_ref(i2, i3) + erint*p_mat(i1, i4)
2965 ks_ref(i1, i4) = ks_ref(i1, i4) + erint*p_mat(i2, i3)
2967 IF (i1 /= i2 .AND. i3 /= i4)
THEN
2968 ks_ref(i2, i4) = ks_ref(i2, i4) + erint*p_mat(i1, i3)
2971 IF (i12 /= i34)
THEN
2972 ks_ref(i3, i1) = ks_ref(i3, i1) + erint*p_mat(i4, i2)
2974 ks_ref(i3, i2) = ks_ref(i3, i2) + erint*p_mat(i4, i1)
2977 ks_ref(i4, i1) = ks_ref(i4, i1) + erint*p_mat(i3, i2)
2979 IF (i1 /= i2 .AND. i3 /= i4)
THEN
2980 ks_ref(i4, i2) = ks_ref(i4, i2) + erint*p_mat(i3, i1)
2989 i1 = active_orbitals(m1, 1)
2991 i2 = active_orbitals(m2, 1)
2992 ks_ref(i2, i1) = ks_ref(i1, i2)
2995 CALL mp_group%sum(ks_ref)
2997 CALL timestop(handle)
2999 END SUBROUTINE build_subspace_fock_matrix
3013 SUBROUTINE build_subspace_spin_fock_matrix(active_orbitals, eri_aa, eri_ab, p_a_mat, p_b_mat, ks_a_ref, tr_mixed_eri, &
3014 comm_exchange, restricted)
3015 INTEGER,
DIMENSION(:, :),
INTENT(IN) :: active_orbitals
3016 TYPE(dbcsr_csr_type),
INTENT(IN) :: eri_aa, eri_ab
3017 REAL(dp),
DIMENSION(:, :),
INTENT(IN) :: p_a_mat, p_b_mat
3018 REAL(dp),
DIMENSION(:, :),
INTENT(INOUT) :: ks_a_ref
3019 LOGICAL,
INTENT(IN) :: tr_mixed_eri
3020 TYPE(mp_comm_type),
INTENT(IN) :: comm_exchange
3021 LOGICAL,
INTENT(IN) :: restricted
3023 CHARACTER(LEN=*),
PARAMETER :: routinen =
'build_subspace_spin_fock_matrix'
3025 INTEGER :: handle, i1, i12, i12l, i2, i3, i34, &
3026 i34l, i4, irptr, m1, m2, nindex, &
3027 nmo_total, norb, spin1, spin2
3028 REAL(dp) :: erint, p12, p34
3029 TYPE(mp_comm_type) :: mp_group
3031 CALL timeset(routinen, handle)
3033 norb =
SIZE(active_orbitals, 1)
3034 nmo_total =
SIZE(p_a_mat, 1)
3035 nindex = (nmo_total*(nmo_total + 1))/2
3036 IF (tr_mixed_eri)
THEN
3044 i1 = active_orbitals(m1, spin1)
3046 i2 = active_orbitals(m2, spin1)
3047 i12 = csr_idx_to_combined(i1, i2, nmo_total)
3048 IF (mod(i12 - 1, comm_exchange%num_pe) == comm_exchange%mepos)
THEN
3049 i12l = (i12 - 1)/comm_exchange%num_pe + 1
3050 irptr = eri_aa%rowptr_local(i12l) - 1
3051 DO i34l = 1, eri_aa%nzerow_local(i12l)
3052 i34 = eri_aa%colind_local(irptr + i34l)
3053 CALL csr_idx_from_combined(i34, nmo_total, i3, i4)
3054 erint = eri_aa%nzval_local%r_dp(irptr + i34l)
3056 p12 = p_a_mat(i1, i2)
3057 p34 = p_a_mat(i3, i4)
3058 IF (restricted)
THEN
3059 p12 = p12 + p_b_mat(i1, i2)
3060 p34 = p34 + p_b_mat(i3, i4)
3062 IF (i1 /= i2) p12 = 2.0_dp*p12
3063 IF (i3 /= i4) p34 = 2.0_dp*p34
3065 ks_a_ref(i1, i2) = ks_a_ref(i1, i2) + erint*p34
3066 IF (i12 /= i34)
THEN
3068 ks_a_ref(i3, i4) = ks_a_ref(i3, i4) + erint*p12
3071 erint = -1.0_dp*erint
3073 ks_a_ref(i1, i3) = ks_a_ref(i1, i3) + erint*p_a_mat(i2, i4)
3076 ks_a_ref(i2, i3) = ks_a_ref(i2, i3) + erint*p_a_mat(i1, i4)
3080 ks_a_ref(i1, i4) = ks_a_ref(i1, i4) + erint*p_a_mat(i2, i3)
3082 IF (i1 /= i2 .AND. i3 /= i4)
THEN
3084 ks_a_ref(i2, i4) = ks_a_ref(i2, i4) + erint*p_a_mat(i1, i3)
3086 IF (i12 /= i34)
THEN
3087 ks_a_ref(i3, i1) = ks_a_ref(i3, i1) + erint*p_a_mat(i4, i2)
3089 ks_a_ref(i3, i2) = ks_a_ref(i3, i2) + erint*p_a_mat(i4, i1)
3092 ks_a_ref(i4, i1) = ks_a_ref(i4, i1) + erint*p_a_mat(i3, i2)
3094 IF (i1 /= i2 .AND. i3 /= i4)
THEN
3095 ks_a_ref(i4, i2) = ks_a_ref(i4, i2) + erint*p_a_mat(i3, i1)
3105 IF (.NOT. restricted)
THEN
3107 i1 = active_orbitals(m1, 1)
3109 i2 = active_orbitals(m2, 1)
3110 i12 = csr_idx_to_combined(i1, i2, nmo_total)
3111 IF (mod(i12 - 1, comm_exchange%num_pe) == comm_exchange%mepos)
THEN
3112 i12l = (i12 - 1)/comm_exchange%num_pe + 1
3113 irptr = eri_ab%rowptr_local(i12l) - 1
3114 DO i34l = 1, eri_ab%nzerow_local(i12l)
3115 i34 = eri_ab%colind_local(irptr + i34l)
3116 CALL csr_idx_from_combined(i34, nmo_total, i3, i4)
3117 erint = eri_ab%nzval_local%r_dp(irptr + i34l)
3119 IF (tr_mixed_eri)
THEN
3121 ks_a_ref(i3, i4) = ks_a_ref(i3, i4) + erint*p_b_mat(i1, i2)
3122 IF (i1 /= i2) ks_a_ref(i3, i4) = ks_a_ref(i3, i4) + erint*p_b_mat(i1, i2)
3125 ks_a_ref(i1, i2) = ks_a_ref(i1, i2) + erint*p_b_mat(i3, i4)
3126 IF (i3 /= i4) ks_a_ref(i1, i2) = ks_a_ref(i1, i2) + erint*p_b_mat(i3, i4)
3135 i1 = active_orbitals(m1, spin1)
3137 i2 = active_orbitals(m2, spin1)
3138 ks_a_ref(i2, i1) = ks_a_ref(i1, i2)
3141 CALL mp_group%set_handle(eri_aa%mp_group%get_handle())
3142 CALL mp_group%sum(ks_a_ref)
3144 CALL timestop(handle)
3146 END SUBROUTINE build_subspace_spin_fock_matrix
3158 SUBROUTINE create_pro_basis(pro_basis_set, zval, ishell, nshell, lnam)
3159 TYPE(gto_basis_set_type),
POINTER :: pro_basis_set
3160 INTEGER,
INTENT(IN) :: zval, ishell
3161 INTEGER,
DIMENSION(:),
INTENT(IN) :: nshell
3162 CHARACTER(LEN=*),
DIMENSION(:),
INTENT(IN) :: lnam
3164 CHARACTER(LEN=6),
DIMENSION(:),
POINTER :: sym
3166 INTEGER,
DIMENSION(4, 7) :: ne
3167 INTEGER,
DIMENSION(:),
POINTER :: lq, nq
3168 REAL(kind=dp),
DIMENSION(:),
POINTER :: zet
3169 TYPE(sto_basis_set_type),
POINTER :: sto_basis_set
3171 cpassert(.NOT.
ASSOCIATED(pro_basis_set))
3172 NULLIFY (sto_basis_set)
3179 ne(l, i) = ptable(zval)%e_conv(l - 1) - 2*nj*(i - l)
3180 ne(l, i) = max(ne(l, i), 0)
3181 ne(l, i) = min(ne(l, i), 2*nj)
3184 ALLOCATE (nq(ishell), lq(ishell), zet(ishell), sym(ishell))
3187 SELECT CASE (lnam(i))
3197 cpabort(
"Wrong l QN")
3200 zet(i) = srules(zval, ne, nq(1), lq(1))
3202 CALL allocate_sto_basis_set(sto_basis_set)
3203 CALL set_sto_basis_set(sto_basis_set, nshell=1, nq=nq, lq=lq, zet=zet, symbol=sym)
3204 CALL create_gto_from_sto_basis(sto_basis_set, pro_basis_set, 6)
3205 pro_basis_set%norm_type = 2
3206 CALL init_orb_basis_set(pro_basis_set)
3207 CALL deallocate_sto_basis_set(sto_basis_set)
3209 END SUBROUTINE create_pro_basis
3216 SUBROUTINE update_density_ao(active_space_env, rho_ao)
3217 TYPE(active_space_type),
POINTER :: active_space_env
3218 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: rho_ao
3220 INTEGER :: ispin, nao, nmo, nspins
3221 TYPE(cp_fm_type) :: r, u
3222 TYPE(cp_fm_type),
POINTER :: c_active, p_active_mo
3223 TYPE(dbcsr_type),
POINTER :: p_inactive_ao
3224 TYPE(mo_set_type),
DIMENSION(:),
POINTER :: mos_active
3228 nspins = active_space_env%nspins
3229 mos_active => active_space_env%mos_active
3230 DO ispin = 1, nspins
3232 p_inactive_ao => active_space_env%pmat_inactive(ispin)%matrix
3235 CALL dbcsr_copy(rho_ao(ispin)%matrix, p_inactive_ao)
3238 p_active_mo => active_space_env%p_active(ispin)
3241 CALL cp_fm_create(r, p_active_mo%matrix_struct)
3242 CALL cp_fm_to_fm(p_active_mo, r)
3245 CALL get_mo_set(mos_active(ispin), mo_coeff=c_active, nao=nao, nmo=nmo)
3246 CALL cp_fm_create(u, c_active%matrix_struct)
3247 CALL parallel_gemm(
"N",
"N", nao, nmo, nmo, 1.0_dp, c_active, r, 0.0_dp, u)
3249 CALL cp_dbcsr_plus_fm_fm_t(sparse_matrix=rho_ao(ispin)%matrix, &
3250 matrix_v=u, matrix_g=c_active, ncol=nmo, alpha=1.0_dp)
3252 CALL cp_fm_release(r)
3253 CALL cp_fm_release(u)
3256 END SUBROUTINE update_density_ao
3268 LOGICAL FUNCTION eri_fcidump_print_func(this, i, j, k, l, val)
RESULT(cont)
3269 CLASS(eri_fcidump_print),
INTENT(INOUT) :: this
3270 INTEGER,
INTENT(IN) :: i, j, k, l
3271 REAL(kind=dp),
INTENT(IN) :: val
3274 IF (this%unit_nr > 0)
THEN
3275 WRITE (this%unit_nr,
"(ES23.16,4I4)") val, i + this%bra_start - 1, j + this%bra_start - 1, &
3276 & k + this%ket_start - 1, l + this%ket_start - 1
3278 IF (max(i, j, k, l) <= this%nalpha)
THEN
3279 IF (i == j .AND. k == l)
THEN
3281 IF (i <= this%nbeta) this%determinant_energy = this%determinant_energy + val
3283 this%determinant_energy = this%determinant_energy + &
3284 merge(2, 1, i <= this%nbeta)*merge(2, 1, k <= this%nbeta)*val
3286 ELSE IF (i == k .AND. j == l)
THEN
3287 this%determinant_energy = this%determinant_energy - merge(2, 1, max(i, j) <= this%nbeta)*val
3293 END FUNCTION eri_fcidump_print_func
3305 LOGICAL FUNCTION eri_fcidump_checksum_func(this, i, j, k, l, val)
RESULT(cont)
3306 CLASS(eri_fcidump_checksum),
INTENT(INOUT) :: this
3307 INTEGER,
INTENT(IN) :: i, j, k, l
3308 REAL(kind=dp),
INTENT(IN) :: val
3315 this%checksum = this%checksum + abs(val)
3318 END FUNCTION eri_fcidump_checksum_func
3326 SUBROUTINE print_pmat_noon(active_space_env, iw)
3327 TYPE(active_space_type),
POINTER :: active_space_env
3330 INTEGER :: i1, i2, ii, ispin, jm, m1, m2, &
3332 REAL(kind=dp),
ALLOCATABLE,
DIMENSION(:, :) :: noon, pmat
3333 TYPE(cp_fm_type),
POINTER :: p_active
3335 nspins = active_space_env%nspins
3336 nmo_active = active_space_env%nmo_active
3338 ALLOCATE (noon(nmo_active, nspins))
3339 ALLOCATE (pmat(nmo_active, nmo_active))
3341 DO ispin = 1, nspins
3342 p_active => active_space_env%p_active(ispin)
3343 noon(:, ispin) = 0.0_dp
3346 DO i1 = 1, nmo_active
3347 m1 = active_space_env%active_orbitals(i1, ispin)
3348 DO i2 = 1, nmo_active
3349 m2 = active_space_env%active_orbitals(i2, ispin)
3350 CALL cp_fm_get_element(p_active, m1, m2, pmat(i1, i2))
3355 WRITE (iw,
'(/,T3,A,I2,A)')
"Active space density matrix for spin ", ispin
3356 DO i1 = 1, nmo_active
3357 DO ii = 1, nmo_active, 8
3358 jm = min(7, nmo_active - ii)
3359 WRITE (iw,
'(T3,6(F9.4))') (pmat(i1, ii + i2), i2=0, jm)
3365 CALL diamat_all(pmat, noon(:, ispin))
3368 WRITE (iw,
'(/,T3,A,I2,A)')
"Natural orbitals occupation numbers for spin ", ispin
3369 DO i1 = 1, nmo_active, 8
3370 jm = min(7, nmo_active - i1)
3372 WRITE (iw,
'(T3,6(F9.4))') (noon(nmo_active - i1 - i2 + 1, ispin), i2=0, jm)
3381 END SUBROUTINE print_pmat_noon
3389 SUBROUTINE local_fci_embedding(qs_env, active_space_env, as_input)
3390 TYPE(qs_environment_type),
POINTER :: qs_env
3391 TYPE(active_space_type),
POINTER :: active_space_env
3392 TYPE(section_vals_type),
POINTER :: as_input
3394 CHARACTER(LEN=*),
PARAMETER :: routinen =
'local_fci_embedding'
3396 INTEGER :: handle, iter, iw, max_iter
3397 LOGICAL :: converged, do_scf_embedding
3398 REAL(kind=dp) :: delta_e, energy_corr, energy_new, &
3399 energy_old, energy_scf, eps_iter, t1, &
3401 REAL(kind=dp),
ALLOCATABLE,
DIMENSION(:) :: p_act_mo_a, p_act_mo_b
3402 TYPE(cp_logger_type),
POINTER :: logger
3403 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: rho_ao
3404 TYPE(dft_control_type),
POINTER :: dft_control
3405 TYPE(mo_set_type),
DIMENSION(:),
POINTER :: mos_active
3406 TYPE(mp_para_env_type),
POINTER :: para_env
3407 TYPE(qs_energy_type),
POINTER :: energy
3408 TYPE(qs_ks_env_type),
POINTER :: ks_env
3409 TYPE(qs_rho_type),
POINTER :: rho
3411 CALL timeset(routinen, handle)
3414 logger => cp_get_default_logger()
3415 iw = cp_logger_get_default_io_unit(logger)
3417 CALL get_qs_env(qs_env, para_env=para_env, dft_control=dft_control)
3419 CALL section_vals_val_get(as_input,
"SCF_EMBEDDING", l_val=do_scf_embedding)
3420 active_space_env%do_scf_embedding = do_scf_embedding
3421 CALL section_vals_val_get(as_input,
"MAX_ITER", i_val=max_iter)
3422 IF (max_iter < 0) cpabort(
"Specify a non-negative number of max iterations.")
3423 CALL section_vals_val_get(as_input,
"EPS_ITER", r_val=eps_iter)
3424 IF (eps_iter < 0.0_dp) cpabort(
"Specify a non-negative convergence threshold.")
3426 CALL get_qs_env(qs_env, rho=rho, energy=energy, ks_env=ks_env)
3427 CALL qs_rho_get(rho, rho_ao=rho_ao)
3430 WRITE (unit=iw, fmt=
"(/,T2,A,/)") &
3431 "RANGE-SEPARATED DFT EMBEDDING WITH LIBFCI SOLVER"
3432 WRITE (iw,
'(T3,A,T68,I12)')
"Max. iterations", max_iter
3433 WRITE (iw,
'(T3,A,T68,E12.4)')
"Conv. threshold", eps_iter
3434 WRITE (iw,
'(T3,A,T68,A)')
"Density mixer", trim(active_space_mixing_label(active_space_env))
3435 WRITE (iw,
'(T3,A,T66,F14.2)')
"Mixing alpha", active_space_env%alpha
3436 WRITE (unit=iw, fmt=
"(/,T3,A,T11,A,T21,A,T34,A,T55,A,T75,A,/,T3,A)") &
3437 "Iter",
"Update",
"Time",
"Corr. energy",
"Total energy",
"Change", repeat(
"-", 78)
3442 energy_scf = active_space_env%energy_ref
3443 energy_new = energy_scf
3444 mos_active => active_space_env%mos_active
3446 DO WHILE (iter < max_iter)
3449 IF (active_space_env%nspins == 2)
THEN
3450 CALL solve_active_space_fci(active_space_env, para_env, p_act_mo_a, p_act_mo_b)
3451 active_space_env%energy_total = active_space_env%energy_inactive + active_space_env%energy_active
3452 CALL update_active_density(p_act_mo_a, active_space_env, p_act_mo_b)
3453 DEALLOCATE (p_act_mo_a, p_act_mo_b)
3455 CALL solve_active_space_fci(active_space_env, para_env, p_act_mo_a)
3456 active_space_env%energy_total = active_space_env%energy_inactive + active_space_env%energy_active
3457 CALL update_active_density(p_act_mo_a, active_space_env)
3458 DEALLOCATE (p_act_mo_a)
3461 energy_old = energy_new
3462 energy_new = active_space_env%energy_total
3463 energy_corr = energy_new - energy_scf
3464 delta_e = energy_new - energy_old
3470 fmt=
"(T3,I4,T11,A,T19,F6.1,T28,F18.10,T49,F18.10,T70,ES11.2)") &
3471 iter, trim(active_space_mixing_label(active_space_env)), &
3472 t1 - t2, energy_corr, energy_new, delta_e
3476 CALL update_density_ao(active_space_env, rho_ao)
3477 CALL qs_rho_update_rho(rho, qs_env=qs_env)
3478 CALL qs_ks_did_change(qs_env%ks_env, rho_changed=.true.)
3479 CALL evaluate_core_matrix_traces(qs_env)
3480 CALL qs_ks_build_kohn_sham_matrix(qs_env, calculate_forces=.false., &
3481 just_energy=.false., &
3482 ext_xc_section=active_space_env%xc_section)
3484 active_space_env%energy_ref = energy%total
3485 CALL calculate_operators(mos_active, qs_env, active_space_env)
3486 CALL subspace_fock_matrix(active_space_env, dft_control%roks)
3488 IF (.NOT. active_space_env%do_scf_embedding)
THEN
3490 WRITE (unit=iw, fmt=
"(/,T3,A,I5,A)") &
3491 "*** one-shot embedding correction finished ***"
3495 ELSE IF (abs(delta_e) <= eps_iter)
THEN
3497 WRITE (unit=iw, fmt=
"(/,T3,A,I5,A)") &
3498 "*** rs-DFT embedding run converged in ", iter,
" iteration(s) ***"
3505 IF (.NOT. converged)
THEN
3507 WRITE (unit=iw, fmt=
"(/,T3,A,I5,A)") &
3508 "*** rs-DFT embedding did not converged after ", iter,
" iteration(s) ***"
3512 energy%total = active_space_env%energy_total
3515 WRITE (unit=iw, fmt=
"(/,T3,A)") &
3516 "Final energy contributions:"
3517 WRITE (unit=iw, fmt=
"(T6,A,T56,F20.10)") &
3518 "Inactive energy:", active_space_env%energy_inactive
3519 WRITE (unit=iw, fmt=
"(T6,A,T56,F20.10)") &
3520 "Active energy:", active_space_env%energy_active
3521 WRITE (unit=iw, fmt=
"(T6,A,T56,F20.10)") &
3522 "Correlation energy:", energy_corr
3523 WRITE (unit=iw, fmt=
"(T6,A,T56,F20.10)") &
3524 "Total rs-DFT energy:", active_space_env%energy_total
3527 CALL print_pmat_noon(active_space_env, iw)
3528 CALL para_env%sync()
3529 CALL timestop(handle)
3531 END SUBROUTINE local_fci_embedding
3539 SUBROUTINE rsdft_embedding(qs_env, active_space_env, as_input)
3540 TYPE(qs_environment_type),
POINTER :: qs_env
3541 TYPE(active_space_type),
POINTER :: active_space_env
3542 TYPE(section_vals_type),
POINTER :: as_input
3544 CHARACTER(LEN=*),
PARAMETER :: routinen =
'rsdft_embedding'
3548 CALL timeset(routinen, handle)
3549 cpabort(
"CP2K was compiled with the __NO_SOCKETS option!")
3551 mark_used(active_space_env)
3555 INTEGER :: iw, client_fd, socket_fd, iter, max_iter
3556 LOGICAL :: converged, do_scf_embedding, ionode
3557 REAL(kind=dp) :: delta_e, energy_corr, energy_new, &
3558 energy_old, energy_scf, eps_iter, t1, t2
3559 TYPE(cp_logger_type),
POINTER :: logger
3560 TYPE(dbcsr_p_type),
DIMENSION(:),
POINTER :: rho_ao
3561 TYPE(mo_set_type),
DIMENSION(:),
POINTER :: mos_active
3562 TYPE(mp_para_env_type),
POINTER :: para_env
3563 TYPE(qs_energy_type),
POINTER :: energy
3564 TYPE(qs_ks_env_type),
POINTER :: ks_env
3565 TYPE(qs_rho_type),
POINTER :: rho
3566 TYPE(dft_control_type),
POINTER :: dft_control
3568 CALL timeset(routinen, handle)
3572 logger => cp_get_default_logger()
3573 iw = cp_logger_get_default_io_unit(logger)
3575 CALL get_qs_env(qs_env, para_env=para_env, dft_control=dft_control)
3576 ionode = para_env%is_source()
3579 CALL section_vals_val_get(as_input,
"SCF_EMBEDDING", l_val=do_scf_embedding)
3580 active_space_env%do_scf_embedding = do_scf_embedding
3581 CALL section_vals_val_get(as_input,
"MAX_ITER", i_val=max_iter)
3582 IF (max_iter < 0) cpabort(
"Specify a non-negative number of max iterations.")
3583 CALL section_vals_val_get(as_input,
"EPS_ITER", r_val=eps_iter)
3584 IF (eps_iter < 0.0_dp) cpabort(
"Specify a non-negative convergence threshold.")
3587 CALL initialize_socket(socket_fd, client_fd, as_input, ionode)
3588 CALL para_env%sync()
3591 CALL send_eri_to_client(client_fd, active_space_env, para_env)
3594 CALL get_qs_env(qs_env, rho=rho, energy=energy, ks_env=ks_env)
3595 CALL qs_rho_get(rho, rho_ao=rho_ao)
3598 WRITE (unit=iw, fmt=
"(/,T2,A,/)") &
3599 "RANGE-SEPARATED DFT EMBEDDING SELF-CONSISTENT OPTIMIZATION"
3601 WRITE (iw,
'(T3,A,T68,I12)')
"Max. iterations", max_iter
3602 WRITE (iw,
'(T3,A,T68,E12.4)')
"Conv. threshold", eps_iter
3603 WRITE (iw,
'(T3,A,T68,A)')
"Density mixer", trim(active_space_mixing_label(active_space_env))
3604 WRITE (iw,
'(T3,A,T66,F14.2)')
"Mixing alpha", active_space_env%alpha
3606 WRITE (unit=iw, fmt=
"(/,T3,A,T11,A,T21,A,T34,A,T55,A,T75,A,/,T3,A)") &
3607 "Iter",
"Update",
"Time",
"Corr. energy",
"Total energy",
"Change", repeat(
"-", 78)
3614 energy_scf = active_space_env%energy_ref
3615 energy_new = energy_scf
3616 mos_active => active_space_env%mos_active
3620 DO WHILE (iter < max_iter)
3625 CALL send_fock_to_client(client_fd, active_space_env, para_env)
3628 energy_old = energy_new
3629 energy_new = active_space_env%energy_total
3630 energy_corr = energy_new - energy_scf
3631 delta_e = energy_new - energy_old
3639 fmt=
"(T3,I4,T11,A,T19,F6.1,T28,F18.10,T49,F18.10,T70,ES11.2)") &
3640 iter, trim(active_space_mixing_label(active_space_env)), &
3641 t1 - t2, energy_corr, energy_new, delta_e
3646 CALL update_density_ao(active_space_env, rho_ao)
3649 CALL qs_rho_update_rho(rho, qs_env=qs_env)
3650 CALL qs_ks_did_change(qs_env%ks_env, rho_changed=.true.)
3652 CALL evaluate_core_matrix_traces(qs_env)
3655 CALL qs_ks_build_kohn_sham_matrix(qs_env, calculate_forces=.false., &
3656 just_energy=.false., &
3657 ext_xc_section=active_space_env%xc_section)
3660 active_space_env%energy_ref = energy%total
3663 CALL calculate_operators(mos_active, qs_env, active_space_env)
3666 CALL subspace_fock_matrix(active_space_env, dft_control%roks)
3669 IF (.NOT. active_space_env%do_scf_embedding)
THEN
3671 WRITE (unit=iw, fmt=
"(/,T3,A,I5,A)") &
3672 "*** one-shot embedding correction finished ***"
3677 ELSE IF (abs(delta_e) <= eps_iter)
THEN
3679 WRITE (unit=iw, fmt=
"(/,T3,A,I5,A)") &
3680 "*** rs-DFT embedding run converged in ", iter,
" iteration(s) ***"
3687 IF (.NOT. converged)
THEN
3689 WRITE (unit=iw, fmt=
"(/,T3,A,I5,A)") &
3690 "*** rs-DFT embedding did not converged after ", iter,
" iteration(s) ***"
3695 energy%total = active_space_env%energy_total
3699 WRITE (unit=iw, fmt=
"(/,T3,A)") &
3700 "Final energy contributions:"
3701 WRITE (unit=iw, fmt=
"(T6,A,T56,F20.10)") &
3702 "Inactive energy:", active_space_env%energy_inactive
3703 WRITE (unit=iw, fmt=
"(T6,A,T56,F20.10)") &
3704 "Active energy:", active_space_env%energy_active
3705 WRITE (unit=iw, fmt=
"(T6,A,T56,F20.10)") &
3706 "Correlation energy:", energy_corr
3707 WRITE (unit=iw, fmt=
"(T6,A,T56,F20.10)") &
3708 "Total rs-DFT energy:", active_space_env%energy_total
3712 CALL print_pmat_noon(active_space_env, iw)
3714 CALL finalize_socket(socket_fd, client_fd, as_input, ionode)
3715 CALL para_env%sync()
3718 CALL timestop(handle)
3720 END SUBROUTINE rsdft_embedding
3730 SUBROUTINE initialize_socket(socket_fd, client_fd, as_input, ionode)
3731 INTEGER,
INTENT(OUT) :: socket_fd, client_fd
3732 TYPE(section_vals_type),
INTENT(IN),
POINTER :: as_input
3733 LOGICAL,
INTENT(IN) :: ionode
3735 CHARACTER(LEN=*),
PARAMETER :: routinen =
'initialize_socket'
3736 INTEGER,
PARAMETER :: backlog = 10
3738 CHARACTER(LEN=default_path_length) :: hostname
3739 INTEGER :: handle, iw, port, protocol
3741 TYPE(cp_logger_type),
POINTER :: logger
3743 CALL timeset(routinen, handle)
3745 logger => cp_get_default_logger()
3746 iw = cp_logger_get_default_io_unit(logger)
3749 CALL section_vals_val_get(as_input,
"SOCKET%INET", l_val=inet)
3755 CALL section_vals_val_get(as_input,
"SOCKET%HOST", c_val=hostname)
3756 CALL section_vals_val_get(as_input,
"SOCKET%PORT", i_val=port)
3759 CALL open_bind_socket(socket_fd, protocol, port, trim(hostname)//c_null_char)
3760 WRITE (iw,
'(/,T2,A,A)')
"@SERVER: Created socket with address ", trim(hostname)
3764 WRITE (iw,
'(T2,A)')
"@SERVER: Waiting for requests..."
3766 WRITE (iw,
'(T2,A,I2)')
"@SERVER: Accepted socket with fd ", client_fd
3769 CALL timestop(handle)
3771 END SUBROUTINE initialize_socket
3780 SUBROUTINE finalize_socket(socket_fd, client_fd, as_input, ionode)
3781 INTEGER,
INTENT(IN) :: socket_fd, client_fd
3782 TYPE(section_vals_type),
INTENT(IN),
POINTER :: as_input
3783 LOGICAL,
INTENT(IN) :: ionode
3785 CHARACTER(LEN=*),
PARAMETER :: routinen =
'finalize_socket'
3786 INTEGER,
PARAMETER :: header_len = 12
3788 CHARACTER(LEN=default_path_length) :: hostname
3791 CALL timeset(routinen, handle)
3793 CALL section_vals_val_get(as_input,
"SOCKET%HOST", c_val=hostname)
3803 IF (file_exists(trim(hostname)))
THEN
3808 CALL timestop(handle)
3810 END SUBROUTINE finalize_socket
3818 SUBROUTINE send_eri_to_client(client_fd, active_space_env, para_env)
3819 INTEGER,
INTENT(IN) :: client_fd
3820 TYPE(active_space_type),
INTENT(IN),
POINTER :: active_space_env
3821 TYPE(mp_para_env_type),
INTENT(IN),
POINTER :: para_env
3823 CHARACTER(LEN=*),
PARAMETER :: routinen =
'send_eri_to_client'
3824 INTEGER,
PARAMETER :: header_len = 12
3826 CHARACTER(LEN=default_string_length) ::
header
3827 INTEGER :: handle, iw
3828 LOGICAL :: ionode, restricted_orbitals
3829 REAL(kind=dp),
ALLOCATABLE,
DIMENSION(:) :: eri_aa, eri_ab, eri_bb, s_ab
3830 TYPE(cp_logger_type),
POINTER :: logger
3832 CALL timeset(routinen, handle)
3834 logger => cp_get_default_logger()
3835 iw = cp_logger_get_default_io_unit(logger)
3836 ionode = para_env%is_source()
3837 restricted_orbitals = active_space_env%restricted_orbitals
3839 ALLOCATE (eri_aa(active_space_env%nmo_active**4))
3840 CALL eri_to_array(active_space_env%eri, eri_aa, active_space_env%active_orbitals, 1, 1)
3841 IF (active_space_env%nspins == 2)
THEN
3842 ALLOCATE (eri_ab(active_space_env%nmo_active**4))
3843 ALLOCATE (eri_bb(active_space_env%nmo_active**4))
3844 IF (restricted_orbitals)
THEN
3848 CALL eri_to_array(active_space_env%eri, eri_ab, active_space_env%active_orbitals, 1, 2)
3849 CALL eri_to_array(active_space_env%eri, eri_bb, active_space_env%active_orbitals, 2, 2)
3852 ALLOCATE (s_ab(active_space_env%nmo_active**2))
3853 associate(act_indices_a => active_space_env%active_orbitals(:, 1), &
3854 act_indices_b => active_space_env%active_orbitals(:, 2))
3855 CALL subspace_matrix_to_array(active_space_env%sab_sub(1), s_ab, act_indices_a, act_indices_b)
3860 IF (ionode)
CALL writebuffer(client_fd,
"STATUS ", header_len)
3863 CALL para_env%sync()
3868 CALL para_env%bcast(
header, para_env%source)
3872 IF (trim(
header) ==
"READY")
THEN
3874 CALL para_env%sync()
3876 CALL writebuffer(client_fd,
"TWOBODY ", header_len)
3877 CALL writebuffer(client_fd, active_space_env%nspins)
3878 CALL writebuffer(client_fd, active_space_env%nmo_active)
3879 CALL writebuffer(client_fd, active_space_env%nelec_active)
3880 CALL writebuffer(client_fd, active_space_env%multiplicity)
3884 IF (active_space_env%nspins == 2)
THEN
3890 ELSE IF (trim(
header) ==
"RECEIVED")
THEN
3896 IF (active_space_env%nspins == 2)
THEN
3902 CALL para_env%sync()
3904 CALL timestop(handle)
3906 END SUBROUTINE send_eri_to_client
3914 SUBROUTINE send_fock_to_client(client_fd, active_space_env, para_env)
3915 INTEGER,
INTENT(IN) :: client_fd
3916 TYPE(active_space_type),
INTENT(INOUT),
POINTER :: active_space_env
3917 TYPE(mp_para_env_type),
INTENT(IN),
POINTER :: para_env
3919 CHARACTER(LEN=*),
PARAMETER :: routinen =
'send_fock_to_client'
3920 INTEGER,
PARAMETER :: header_len = 12
3922 CHARACTER(LEN=default_string_length) ::
header
3923 INTEGER :: handle, iw
3924 LOGICAL :: debug, ionode
3925 REAL(kind=dp),
ALLOCATABLE,
DIMENSION(:) :: fock_a, fock_b, p_act_mo_a, p_act_mo_b
3926 TYPE(cp_logger_type),
POINTER :: logger
3928 CALL timeset(routinen, handle)
3933 logger => cp_get_default_logger()
3934 iw = cp_logger_get_default_io_unit(logger)
3935 ionode = para_env%is_source()
3937 ALLOCATE (p_act_mo_a(active_space_env%nmo_active**2))
3938 ALLOCATE (fock_a(active_space_env%nmo_active**2))
3939 IF (active_space_env%nspins == 2)
THEN
3940 ALLOCATE (p_act_mo_b(active_space_env%nmo_active**2))
3941 ALLOCATE (fock_b(active_space_env%nmo_active**2))
3945 associate(act_indices => active_space_env%active_orbitals(:, 1))
3946 CALL subspace_matrix_to_array(active_space_env%fock_sub(1), fock_a, act_indices, act_indices)
3949 IF (active_space_env%nspins == 2)
THEN
3950 associate(act_indices => active_space_env%active_orbitals(:, 2))
3951 CALL subspace_matrix_to_array(active_space_env%fock_sub(2), fock_b, act_indices, act_indices)
3956 IF (ionode)
CALL writebuffer(client_fd,
"STATUS ", header_len)
3960 CALL para_env%sync()
3962 IF (debug .AND. iw > 0)
WRITE (iw, *)
"@SERVER: Waiting for messages..."
3965 CALL para_env%bcast(
header, para_env%source)
3967 IF (debug .AND. iw > 0)
WRITE (iw, *)
"@SERVER: Message from client: ", trim(
header)
3969 IF (trim(
header) ==
"READY")
THEN
3971 CALL para_env%sync()
3973 CALL writebuffer(client_fd,
"ONEBODY ", header_len)
3974 CALL writebuffer(client_fd, active_space_env%energy_inactive)
3978 IF (active_space_env%nspins == 2)
THEN
3983 ELSE IF (trim(
header) ==
"HAVEDATA")
THEN
3985 CALL para_env%sync()
3987 IF (debug .AND. iw > 0)
WRITE (iw, *)
"@SERVER: Qiskit has data to transfer"
3988 CALL writebuffer(client_fd,
"GETDENSITY ", header_len)
3991 CALL readbuffer(client_fd, active_space_env%energy_active)
3992 CALL readbuffer(client_fd, p_act_mo_a,
SIZE(p_act_mo_a))
3993 IF (active_space_env%nspins == 2)
THEN
3994 CALL readbuffer(client_fd, p_act_mo_b,
SIZE(p_act_mo_b))
3999 CALL para_env%bcast(active_space_env%energy_active, para_env%source)
4000 CALL para_env%bcast(p_act_mo_a, para_env%source)
4001 IF (active_space_env%nspins == 2)
THEN
4002 CALL para_env%bcast(p_act_mo_b, para_env%source)
4006 active_space_env%energy_total = active_space_env%energy_inactive + active_space_env%energy_active
4009 IF (active_space_env%nspins == 2)
THEN
4010 CALL update_active_density(p_act_mo_a, active_space_env, p_act_mo_b)
4012 CALL update_active_density(p_act_mo_a, active_space_env)
4021 DEALLOCATE (p_act_mo_a)
4023 IF (active_space_env%nspins == 2)
THEN
4024 DEALLOCATE (p_act_mo_b)
4028 CALL para_env%sync()
4030 CALL timestop(handle)
4032 END SUBROUTINE send_fock_to_client
Types and set/get functions for auxiliary density matrix methods.
subroutine, public get_admm_env(admm_env, mo_derivs_aux_fit, mos_aux_fit, sab_aux_fit, sab_aux_fit_asymm, sab_aux_fit_vs_orb, matrix_s_aux_fit, matrix_s_aux_fit_kp, matrix_s_aux_fit_vs_orb, matrix_s_aux_fit_vs_orb_kp, task_list_aux_fit, matrix_ks_aux_fit, matrix_ks_aux_fit_kp, matrix_ks_aux_fit_im, matrix_ks_aux_fit_dft, matrix_ks_aux_fit_hfx, matrix_ks_aux_fit_dft_kp, matrix_ks_aux_fit_hfx_kp, rho_aux_fit, rho_aux_fit_buffer, admm_dm)
Get routine for the ADMM env.
subroutine, public admm_env_release(admm_env)
releases the ADMM environment, cleans up all types
Define the atomic kind types and their sub types.
subroutine, public create_gto_from_sto_basis(sto_basis_set, gto_basis_set, ngauss, ortho, ngaussflex)
...
pure real(dp) function, public srules(z, ne, n, l)
...
subroutine, public deallocate_sto_basis_set(sto_basis_set)
...
subroutine, public allocate_sto_basis_set(sto_basis_set)
...
subroutine, public set_sto_basis_set(sto_basis_set, name, nshell, symbol, nq, lq, zet)
...
subroutine, public init_orb_basis_set(gto_basis_set)
Initialise a Gaussian-type orbital (GTO) basis set data set.
Handles all functions related to the CELL.
subroutine, public write_cell_low(cell, unit_str, output_unit, label)
Write the cell parameters to the output unit.
subroutine, public set_cell_param(cell, cell_length, cell_angle, periodic, do_init_cell)
Sets the cell using the internal parameters (a,b,c) (alpha,beta,gamma) using the convention: a parall...
subroutine, public init_cell(cell, hmat, periodic)
Initialise/readjust a simulation cell after hmat has been changed.
Handles all functions related to the CELL.
integer, parameter, public use_perd_xyz
integer, parameter, public use_perd_none
methods related to the blacs parallel environment
integer, parameter, public blacs_grid_square
subroutine, public cp_blacs_env_release(blacs_env)
releases the given blacs_env
subroutine, public cp_blacs_env_create(blacs_env, para_env, blacs_grid_layout, blacs_repeatable, row_major, grid_2d)
allocates and initializes a type that represent a blacs context
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
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_iterator_start(iterator, matrix, dynamic, dynamic_byrows)
...
subroutine, public dbcsr_iterator_next_block(iterator, row, column, block, block_number_argument_has_been_removed, row_size, col_size, row_offset, col_offset, transposed)
...
real(kind=dp) function, public dbcsr_get_occupation(matrix)
...
subroutine, public dbcsr_set(matrix, alpha)
...
subroutine, public dbcsr_release(matrix)
...
CSR matrix type, DBCSR-CSR conversions, and CSR file I/O built on cp_dbcsr_api.
DBCSR operations in CP2K.
subroutine, public cp_dbcsr_sm_fm_multiply(matrix, fm_in, fm_out, ncol, alpha, beta)
multiply a dbcsr with a fm matrix
subroutine, public copy_dbcsr_to_fm(matrix, fm, plan, check_plan)
Copy a DBCSR matrix to a BLACS matrix.
subroutine, public cp_dbcsr_plus_fm_fm_t(sparse_matrix, matrix_v, matrix_g, ncol, alpha, keep_sparsity, symmetry_mode)
performs the multiplication sparse_matrix+dense_mat*dens_mat^T if matrix_g is not explicitly given,...
subroutine, public cp_dbcsr_m_by_n_from_template(matrix, template, m, n, sym)
Utility function to create an arbitrary shaped dbcsr matrix with the same processor grid as the templ...
subroutine, public cp_dbcsr_write_sparse_matrix(sparse_matrix, before, after, qs_env, para_env, first_row, last_row, first_col, last_col, scale, output_unit, omit_headers, cartesian_basis)
...
Utility routines to open and close files.
logical function, public file_exists(file_name)
Checks if a file exists, considering also the file discovery mechanism.
subroutine, public open_file(file_name, unit_number, file_status, file_form, file_action, file_position, file_pad, file_access, debug)
Opens a file and returns its logical unit number.
subroutine, public close_file(unit_number, file_status)
Closes an open file given by its logical unit number.
Basic linear algebra operations for full matrices.
subroutine, public cp_fm_column_scale(matrixa, scaling, first_col, source)
Scales columns of the full matrix by corresponding factors.
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_get_info(matrix, name, nrow_global, ncol_global, nrow_block, ncol_block, nrow_local, ncol_local, row_indices, col_indices, local_data, context, nrow_locals, ncol_locals, matrix_struct, para_env)
returns all kind of information about the full matrix
subroutine, public cp_fm_get_element(matrix, irow_global, icol_global, alpha, local)
returns an element of a fm this value is valid on every cpu using this call is expensive
subroutine, public cp_fm_set_all(matrix, alpha, beta)
set all elements of a matrix to the same value, and optionally the diagonal to a different one
subroutine, public cp_fm_create(matrix, matrix_struct, name, nrow, ncol, set_zero)
creates a new full matrix with the given structure
subroutine, public cp_fm_set_element(matrix, irow_global, icol_global, alpha)
sets an element of a matrix
subroutine, public cp_fm_init_random(matrix, ncol, start_col)
fills a matrix with random numbers
subroutine, public cp_fm_write_formatted(fm, unit, header, value_format)
Write out a full matrix in plain text.
various routines to log and control the output. The idea is that decisions about where to log should ...
integer function, public cp_logger_get_default_io_unit(logger)
returns the unit nr for the ionode (-1 on all other processors) skips as well checks if the procs cal...
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
routines to handle the output, The idea is to remove the decision of wheter to output and what to out...
integer, parameter, public debug_print_level
integer, parameter, public low_print_level
integer, parameter, public medium_print_level
subroutine, public cp_print_key_finished_output(unit_nr, logger, basis_section, print_key_path, local, ignore_should_output, on_file, mpi_io)
should be called after you finish working with a unit obtained with cp_print_key_unit_nr,...
integer, parameter, public cp_p_file
integer, parameter, public high_print_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...
integer, parameter, public silent_print_level
integer function, public cp_print_key_unit_nr(logger, basis_section, print_key_path, extension, middle_name, local, log_filename, ignore_should_output, file_form, file_position, file_action, file_status, do_backup, on_file, is_new_file, mpi_io, fout, file_access)
...
A wrapper around pw_to_cube() which accepts particle_list_type.
subroutine, public cp_pw_to_cube(pw, unit_nr, title, particles, zeff, stride, max_file_size_mb, zero_tails, silent, mpi_io)
...
Module to compute the error function of a complex argument.
elemental complex(kind=dp) function, public erfz_fast(z)
Computes the error function of a complex argument using the Poppe and Wijers algorithm.
Types to describe group distributions.
Types and set/get functions for HFX.
subroutine, public hfx_create(x_data, para_env, hfx_section, atomic_kind_set, qs_kind_set, particle_set, dft_control, cell, orb_basis, ri_basis, nelectron_total, nkp_grid)
This routine allocates and initializes all types in hfx_data
subroutine, public hfx_release(x_data)
This routine deallocates all data structures
Defines the basic variable types.
integer, parameter, public int_8
integer, parameter, public dp
integer, parameter, public default_string_length
integer, parameter, public default_path_length
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, rskp_transform)
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
Definition of mathematical constants and functions.
real(kind=dp), parameter, public pi
real(kind=dp), parameter, public rootpi
real(kind=dp), parameter, public fourpi
real(kind=dp), parameter, public twopi
Collection of simple mathematical functions and subroutines.
subroutine, public diamat_all(a, eigval, dac)
Diagonalize the symmetric n by n matrix a using the LAPACK library. Only the upper triangle of matrix...
Utility routines for the memory handling.
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)
Functions handling the MOLDEN format. Split from mode_selective.
subroutine, public write_mos_molden(mos, qs_kind_set, particle_set, print_section, cell, unoccupied_orbs, unoccupied_evals, qs_env, calc_energies)
Write out the MOs in molden format for visualisation.
Calls routines to get RI integrals and calculate total energies.
subroutine, public grep_rows_in_subgroups(para_env, para_env_sub, mo_coeff, gd_array, c)
...
subroutine, public build_dbcsr_from_rows(para_env_sub, mo_coeff_to_build, cread, mat_munu, gd_array, eps_filter)
Encapsulate the building of dbcsr_matrices mo_coeff_(v,o,all).
subroutine, public create_mat_munu(mat_munu, qs_env, eps_grid, blacs_env_sub, do_ri_aux_basis, do_mixed_basis, group_size_prim, do_alloc_blocks_from_nbl, do_kpoints, sab_orb_sub, dbcsr_sym_type, custom_row_blk_sizes)
Encapsulate the building of dbcsr_matrix mat_munu.
integer, parameter, public mt0d
basic linear algebra operations for full matrixes
represent a simple array based list of the given type
Define the data structure for the particle information.
Periodic Table related data definitions.
type(atom), dimension(0:nelem), public ptable
Definition of physical constants:
real(kind=dp), parameter, public angstrom
real(kind=dp), parameter, public bohr
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(preconditioner_env, precon_type, solver_type, matrix_h, matrix_s, matrix_t, mo_set, energy_gap, convert_precond_to_dbcsr, chol_type, full_all_rotation)
...
methods of pw_env that have dependence on qs_env
subroutine, public pw_env_rebuild(pw_env, qs_env, external_para_env)
rebuilds the pw_env data (necessary if cell or cutoffs change)
subroutine, public pw_env_create(pw_env)
creates a pw_env, if qs_env is given calls pw_env_rebuild
container for various plainwaves related things
subroutine, public pw_env_release(pw_env, para_env)
releases the given pw_env (see doc/ReferenceCounting.html)
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
subroutine, public pw_gauss_damp(pw, omega)
Multiply all data points with a Gaussian damping factor Needed for longrange Coulomb potential V(\vec...
subroutine, public pw_compl_gauss_damp(pw, omega)
Multiply all data points with a Gaussian damping factor Needed for longrange Coulomb potential V(\vec...
functions related to the poisson solver on regular grids
integer, parameter, public pw_poisson_periodic
integer, parameter, public periodic3d
integer, parameter, public analytic0d
integer, parameter, public pw_poisson_analytic
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
The module to read/write QCSchema HDF5 files for interfacing CP2K with other programs.
subroutine, public qcschema_env_release(qcschema_env)
Releases the allocated memory of a qcschema environment.
subroutine, public qcschema_env_create(qcschema_env, qs_env)
Create and initialize a qcschema object from a quickstep environment.
subroutine, public qcschema_to_hdf5(qcschema_env, filename)
Writes a qcschema object to an hdf5 file.
Local FCI solver interface for active-space embedding.
subroutine, public solve_active_space_fci(active_space_env, para_env, p_act_mo_a, p_act_mo_b)
Solve the current active-space Hamiltonian with the local FCI kernel.
Determine active space Hamiltonian.
subroutine eri_fcidump_set(this, bra_start, ket_start)
Sets the starting indices of the bra and ket.
subroutine, public active_space_main(qs_env)
Main method for determining the active space Hamiltonian.
Dense density mixing for active-space embedding.
character(len=15) function, public active_space_mixing_label(active_space_env)
Return the current active-space mixer label for iteration output.
subroutine, public update_active_density(p_act_mo_a, active_space_env, p_act_mo_b)
Update active space density matrix from Fortran arrays.
subroutine, public initialize_active_space_mixing(active_space_env, as_input)
Initialize the density mixer used in the self-consistent active-space embedding loop.
The types needed for the calculation of active space Hamiltonians.
subroutine, public csr_idx_from_combined(ij, n, i, j)
extracts indices i and j from combined index ij
integer function, public csr_idx_to_combined(i, j, n)
calculates combined index (ij)
subroutine, public create_active_space_type(active_space_env)
Creates an active space environment type, nullifying all quantities.
Contains utility routines for the active space module.
pure subroutine, public find_degenerate_splits(eigenvalues, active, eps_degenerate, npairs, first_active, first_other)
Finds pairs of degenerate orbitals of which one is active and the other is not, i....
subroutine, public eri_to_array(eri_env, array, active_orbitals, spin1, spin2)
Copy the eri tensor for spins isp1 and isp2 to a standard 1D Fortran array.
subroutine, public subspace_matrix_to_array(source_matrix, target_array, row_index, col_index)
Copy a (square portion) of a cp_fm_type matrix to a standard 1D Fortran array.
Calculate the plane wave density by collocating the primitive Gaussian functions (pgf).
subroutine, public calculate_wavefunction(mo_vectors, ivector, rho, rho_gspace, atomic_kind_set, qs_kind_set, cell, dft_control, particle_set, pw_env, basis_type)
maps a given wavefunction on the grid
collects routines that calculate density matrices
subroutine, public get_qs_env(qs_env, atomic_kind_set, qs_kind_set, cell, super_cell, cell_ref, use_ref_cell, kpoints, dft_control, mos, sab_orb, sab_all, qmmm, qmmm_periodic, mimic, sac_ae, sac_ppl, sac_lri, sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, sab_cneo, particle_set, energy, force, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, matrix_vhxc, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, xcint_weights, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, rhoz_cneo_set, ecoul_1c, rho0_s_rs, rho0_s_gs, rhoz_cneo_s_rs, rhoz_cneo_s_gs, do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, lri_env, lri_density, exstate_env, ec_env, harris_env, dispersion_env, gcp_env, vee, rho_external, external_vxc, mask, mp2_env, bs_env, kg_env, wanniercentres, atprop, ls_scf_env, do_transport, transport_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, mscfg_env, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, eeq, rhs, do_rixs, tb_tblite, matrix_metric, matrix_metric_kp)
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.
Integrate single or product functions over a potential on a RS grid.
Define the quickstep kind type and their sub types.
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_build_kohn_sham_matrix(qs_env, calculate_forces, just_energy, print_active, ext_ks_matrix, ext_xc_section)
routine where the real calculations are made: the KS matrix is calculated
subroutine, public set_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, vppl, xcint_weights, rho_core, rho_nlcc, rho_nlcc_g, vee, neighbor_list_id, kpoints, 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, subsys, dft_control, dbcsr_dist, distribution_2d, pw_env, para_env, blacs_env, uspp, upf_inverse, skala)
...
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...
Definition and initialisation of the mo data type.
subroutine, public write_mo_set_to_output_unit(mo_set, qs_kind_set, particle_set, dft_section, before, kpoint, final_mos, spin, solver_method, rtp, cpart, sim_step, umo_set, qs_env, para_env_inter_kp)
Write MO information to output file (eigenvalues, occupation numbers, coefficients).
collects routines that perform operations directly related to MOs
subroutine, public make_mo_set_canonical(mo_set, ks_matrix, eps_canonical, rotated, max_offdiag, mo_derivs)
Rotates the orbitals of an MO set into canonical orbitals (eigenvectors of the Fock matrix in the spa...
subroutine, public calculate_orbital_fock_elements(orbitals, ks_matrix, orbital_energies, max_offdiag)
Orbital energies <phi_i|F|phi_i> of a set of orbitals and the largest off-diagonal Fock matrix elemen...
Definition and initialisation of the mo data type.
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 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.
Define the neighbor list data types and the corresponding functionality.
subroutine, public release_neighbor_list_sets(nlists)
releases an array of neighbor_list_sets
an eigen-space solver for the generalised symmetric eigenvalue problem for sparse matrices,...
subroutine, public ot_eigensolver(matrix_h, matrix_s, matrix_orthogonal_space_fm, matrix_c_fm, preconditioner, eps_gradient, iter_max, size_ortho_space, silent, ot_settings)
...
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...
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
types that represent a quickstep subsys
subroutine, public qs_subsys_get(subsys, atomic_kinds, atomic_kind_set, particles, particle_set, local_particles, molecules, molecule_set, molecule_kinds, molecule_kind_set, local_molecules, para_env, colvar_p, shell_particles, core_particles, gci, multipoles, natom, nparticle, ncore, nshell, nkind, atprop, virial, results, cell, cell_ref, use_ref_cell, energy, force, qs_kind_set, cp_subsys, nelectron_total, nelectron_spin)
...
parameters that control an scf iteration
Implements UNIX and INET sockets.
generate the tasks lists used by collocate and integrate routines
subroutine, public generate_qs_task_list(ks_env, task_list, basis_type, reorder_rs_grid_ranks, skip_load_balance_distributed, pw_env_external, sab_orb_external, ext_kpoints)
...
subroutine, public deallocate_task_list(task_list)
deallocates the components and the object itself
subroutine, public allocate_task_list(task_list)
allocates and initialised the components of the task_list_type
All kind of helpful little routines.
pure integer function, dimension(2), public get_limit(m, n, me)
divide m entries into n parts, return size of part me
void open_bind_socket(int *psockfd, int *inet, int *port, char *host)
Opens and binds a socket.
void writebuffer(int *psockfd, char *data, int *plen)
Writes to a socket.
void accept_socket(int *psockfd, int *pclientfd)
Listens to a socket.
void close_socket(int *psockfd)
Closes a socket.
void listen_socket(int *psockfd, int *backlog)
Listens to a socket.
void readbuffer(int *psockfd, char *data, int *plen)
Reads from a socket.
void remove_socket_file(char *host)
Removes a socket file.
stores some data used in wavefunction fitting
Provides all information about an atomic kind.
Type defining parameters related to the simulation cell.
represent a blacs multidimensional parallel environment (for the mpi corrispective see cp_paratypes/m...
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 information about kpoints.
stores all the informations relevant to an mpi environment
represent a list of objects
contained for different pw related things
contains all the informations needed by the fft based poisson solvers
environment for the poisson solver
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
The full QCSchema output type. For more information refer to: https://molssi-qc-schema....
Abstract function object for the eri_type_eri_foreach method.
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.