Skip to content

Commit

Permalink
Calculate_wavefunction refactoring, fix dropped commit (cp2k#3643)
Browse files Browse the repository at this point in the history
  • Loading branch information
juerghutter authored Aug 22, 2024
1 parent 44379fe commit b513455
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 102 deletions.
27 changes: 11 additions & 16 deletions src/mp2_eri_gpw.F
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ MODULE mp2_eri_gpw
USE cp_control_types, ONLY: dft_control_type
USE cp_dbcsr_api, ONLY: dbcsr_p_type,&
dbcsr_set
USE cp_fm_types, ONLY: cp_fm_type
USE gaussian_gridlevels, ONLY: gaussian_gridlevel
USE input_constants, ONLY: do_potential_coulomb,&
do_potential_id,&
Expand Down Expand Up @@ -48,7 +47,7 @@ MODULE mp2_eri_gpw
USE pw_types, ONLY: pw_c1d_gs_type,&
pw_r3d_rs_type
USE qs_collocate_density, ONLY: calculate_rho_elec,&
calculate_wavefunction,&
collocate_function,&
collocate_single_gaussian
USE qs_environment_types, ONLY: get_qs_env,&
qs_environment_type
Expand Down Expand Up @@ -86,7 +85,6 @@ MODULE mp2_eri_gpw

! **************************************************************************************************
!> \brief ...
!> \param mo_coeff ...
!> \param psi_L ...
!> \param rho_g ...
!> \param atomic_kind_set ...
Expand All @@ -104,11 +102,11 @@ MODULE mp2_eri_gpw
!> \param qs_env ...
!> \param task_list_sub ...
! **************************************************************************************************
SUBROUTINE mp2_eri_3c_integrate_gpw(mo_coeff, psi_L, rho_g, atomic_kind_set, qs_kind_set, cell, dft_control, particle_set, &
SUBROUTINE mp2_eri_3c_integrate_gpw(psi_L, rho_g, atomic_kind_set, qs_kind_set, &
cell, dft_control, particle_set, &
pw_env_sub, external_vector, poisson_env, rho_r, pot_g, &
potential_parameter, mat_munu, qs_env, task_list_sub)

TYPE(cp_fm_type), INTENT(IN) :: mo_coeff
TYPE(pw_r3d_rs_type), INTENT(INOUT) :: psi_L
TYPE(pw_c1d_gs_type), INTENT(INOUT) :: rho_g
TYPE(atomic_kind_type), DIMENSION(:), INTENT(IN), &
Expand Down Expand Up @@ -136,10 +134,9 @@ SUBROUTINE mp2_eri_3c_integrate_gpw(mo_coeff, psi_L, rho_g, atomic_kind_set, qs_
CALL timeset(routineN, handle)

! pseudo psi_L
CALL calculate_wavefunction(mo_coeff, 1, psi_L, rho_g, atomic_kind_set, &
qs_kind_set, cell, dft_control, particle_set, pw_env_sub, &
basis_type="RI_AUX", &
external_vector=external_vector)
CALL collocate_function(external_vector, psi_L, rho_g, atomic_kind_set, &
qs_kind_set, cell, particle_set, pw_env_sub, &
dft_control%qs_control%eps_rho_rspace, basis_type="RI_AUX")

CALL calc_potential_gpw(rho_r, rho_g, poisson_env, pot_g, potential_parameter)

Expand Down Expand Up @@ -352,7 +349,6 @@ SUBROUTINE mp2_eri_2c_integrate_gpw(qs_env, para_env_sub, my_group_L_start, my_g
!> \brief Integrates the potential of a RI function obtaining the forces and stress tensor
!> \param rho_r ...
!> \param LLL ...
!> \param matrix ...
!> \param rho_g ...
!> \param atomic_kind_set ...
!> \param qs_kind_set ...
Expand All @@ -375,15 +371,14 @@ SUBROUTINE mp2_eri_2c_integrate_gpw(qs_env, para_env_sub, my_group_L_start, my_g
!> \param psi_L ...
!> \param factor ...
! **************************************************************************************************
SUBROUTINE integrate_potential_forces_2c(rho_r, LLL, matrix, rho_g, atomic_kind_set, &
SUBROUTINE integrate_potential_forces_2c(rho_r, LLL, rho_g, atomic_kind_set, &
qs_kind_set, particle_set, cell, pw_env_sub, poisson_env, pot_g, &
potential_parameter, use_virial, rho_g_copy, dvg, &
kind_of, atom_of_kind, G_PQ_local, force, h_stress, para_env_sub, &
dft_control, psi_L, factor)

TYPE(pw_r3d_rs_type), INTENT(INOUT) :: rho_r
INTEGER, INTENT(IN) :: LLL
TYPE(cp_fm_type), INTENT(IN) :: matrix
TYPE(pw_c1d_gs_type), INTENT(INOUT) :: rho_g
TYPE(atomic_kind_type), DIMENSION(:), INTENT(IN), &
POINTER :: atomic_kind_set
Expand Down Expand Up @@ -439,10 +434,10 @@ SUBROUTINE integrate_potential_forces_2c(rho_r, LLL, matrix, rho_g, atomic_kind_
! hartree potential derivatives
CALL pw_zero(psi_L)
CALL pw_zero(rho_g)
CALL calculate_wavefunction(matrix, 1, psi_L, rho_g, atomic_kind_set, &
qs_kind_set, cell, dft_control, particle_set, pw_env_sub, &
basis_type="RI_AUX", &
external_vector=0.5_dp*factor*G_PQ_local)
CALL collocate_function(0.5_dp*factor*G_PQ_local, psi_L, rho_g, atomic_kind_set, &
qs_kind_set, cell, particle_set, pw_env_sub, &
dft_control%qs_control%eps_rho_rspace, &
basis_type="RI_AUX")
! transfer to reciprocal space and calculate potential
CALL calc_potential_gpw(psi_L, rho_g, poisson_env, pot_g, potential_parameter, no_transfer=.TRUE.)
! update virial with volume term (first calculate hartree like energy (diagonal part of the virial))
Expand Down
10 changes: 5 additions & 5 deletions src/mp2_gpw.F
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ SUBROUTINE mp2_gpw_main(qs_env, mp2_env, Emp2, Emp2_Cou, Emp2_EX, Emp2_S, Emp2_T
CALL mp2_ri_gpw_compute_in( &
BIb_C, BIb_C_gw, BIb_C_bse_ij, BIb_C_bse_ab, gd_array, gd_B_virtual, dimen_RI, dimen_RI_red, qs_env, &
para_env, para_env_sub, color_sub, cell, particle_set, &
atomic_kind_set, qs_kind_set, mo_coeff, fm_matrix_PQ, fm_matrix_L_kpoints, fm_matrix_Minv_L_kpoints, &
atomic_kind_set, qs_kind_set, fm_matrix_PQ, fm_matrix_L_kpoints, fm_matrix_Minv_L_kpoints, &
fm_matrix_Minv, fm_matrix_Minv_Vtrunc_Minv, nmo, homo, mat_munu, sab_orb_sub, &
mo_coeff_o, mo_coeff_v, mo_coeff_all, mo_coeff_gw, mo_coeff_o_bse, mo_coeff_v_bse, &
mp2_env%mp2_gpw%eps_filter, unit_nr, &
Expand All @@ -410,7 +410,7 @@ SUBROUTINE mp2_gpw_main(qs_env, mp2_env, Emp2, Emp2_Cou, Emp2_EX, Emp2_S, Emp2_T
CALL mp2_ri_gpw_compute_in(BIb_C, BIb_C_gw, BIb_C_bse_ij, BIb_C_bse_ab, gd_array, gd_B_virtual, &
dimen_RI, dimen_RI_red, qs_env, para_env, para_env_sub, &
color_sub, cell, particle_set, &
atomic_kind_set, qs_kind_set, mo_coeff, fm_matrix_PQ, &
atomic_kind_set, qs_kind_set, fm_matrix_PQ, &
fm_matrix_L_kpoints, fm_matrix_Minv_L_kpoints, &
fm_matrix_Minv, fm_matrix_Minv_Vtrunc_Minv, nmo, homo, &
mat_munu, sab_orb_sub, &
Expand All @@ -436,7 +436,7 @@ SUBROUTINE mp2_gpw_main(qs_env, mp2_env, Emp2, Emp2_Cou, Emp2_EX, Emp2_S, Emp2_T
CALL mp2_gpw_compute( &
Emp2, Emp2_Cou, Emp2_EX, qs_env, para_env, para_env_sub, color_sub, &
cell, particle_set, &
atomic_kind_set, qs_kind_set, mo_coeff(1), Eigenval, nmo, homo, mat_munu, &
atomic_kind_set, qs_kind_set, Eigenval, nmo, homo, mat_munu, &
sab_orb_sub, mo_coeff_o, mo_coeff_v, mp2_env%mp2_gpw%eps_filter, unit_nr, &
mp2_env%mp2_memory, calc_ex, blacs_env_sub, Emp2_AB)
Expand All @@ -445,7 +445,7 @@ SUBROUTINE mp2_gpw_main(qs_env, mp2_env, Emp2, Emp2_Cou, Emp2_EX, Emp2_S, Emp2_T
IF (unit_nr > 0) WRITE (unit_nr, '(T3,A)') 'Beta (ia|'
CALL mp2_gpw_compute( &
Emp2_BB, Emp2_Cou_BB, Emp2_EX_BB, qs_env, para_env, para_env_sub, color_sub, cell, particle_set, &
atomic_kind_set, qs_kind_set, mo_coeff(2), Eigenval(:, 2:2), nmo, homo(2:2), mat_munu, &
atomic_kind_set, qs_kind_set, Eigenval(:, 2:2), nmo, homo(2:2), mat_munu, &
sab_orb_sub, mo_coeff_o(2:2), mo_coeff_v(2:2), mp2_env%mp2_gpw%eps_filter, unit_nr, &
mp2_env%mp2_memory, calc_ex, blacs_env_sub)
Expand All @@ -467,7 +467,7 @@ SUBROUTINE mp2_gpw_main(qs_env, mp2_env, Emp2, Emp2_Cou, Emp2_EX, Emp2_S, Emp2_T
! closed shell case
CALL mp2_gpw_compute( &
Emp2, Emp2_Cou, Emp2_EX, qs_env, para_env, para_env_sub, color_sub, cell, particle_set, &
atomic_kind_set, qs_kind_set, mo_coeff(1), Eigenval(:, 1:1), nmo, homo(1:1), mat_munu, &
atomic_kind_set, qs_kind_set, Eigenval(:, 1:1), nmo, homo(1:1), mat_munu, &
sab_orb_sub, mo_coeff_o(1:1), mo_coeff_v(1:1), mp2_env%mp2_gpw%eps_filter, unit_nr, &
mp2_env%mp2_memory, calc_ex, blacs_env_sub)
END IF
Expand Down
18 changes: 8 additions & 10 deletions src/mp2_gpw_method.F
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ MODULE mp2_gpw_method
USE pw_pool_types, ONLY: pw_pool_type
USE pw_types, ONLY: pw_c1d_gs_type,&
pw_r3d_rs_type
USE qs_collocate_density, ONLY: calculate_wavefunction
USE qs_collocate_density, ONLY: collocate_function
USE qs_environment_types, ONLY: qs_environment_type
USE qs_integrate_potential, ONLY: integrate_v_rspace
USE qs_kind_types, ONLY: qs_kind_type
Expand Down Expand Up @@ -80,7 +80,6 @@ MODULE mp2_gpw_method
!> \param particle_set ...
!> \param atomic_kind_set ...
!> \param qs_kind_set ...
!> \param mo_coeff ...
!> \param Eigenval ...
!> \param nmo ...
!> \param homo ...
Expand All @@ -96,7 +95,7 @@ MODULE mp2_gpw_method
!> \param Emp2_AB ...
! **************************************************************************************************
SUBROUTINE mp2_gpw_compute(Emp2, Emp2_Cou, Emp2_EX, qs_env, para_env, para_env_sub, color_sub, &
cell, particle_set, atomic_kind_set, qs_kind_set, mo_coeff, Eigenval, nmo, homo, &
cell, particle_set, atomic_kind_set, qs_kind_set, Eigenval, nmo, homo, &
mat_munu, sab_orb_sub, mo_coeff_o, mo_coeff_v, eps_filter, unit_nr, &
mp2_memory, calc_ex, blacs_env_sub, Emp2_AB)

Expand All @@ -108,7 +107,6 @@ SUBROUTINE mp2_gpw_compute(Emp2, Emp2_Cou, Emp2_EX, qs_env, para_env, para_env_s
TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
TYPE(cp_fm_type), INTENT(IN) :: mo_coeff
REAL(KIND=dp), DIMENSION(:, :), INTENT(IN) :: Eigenval
INTEGER, INTENT(IN) :: nmo
INTEGER, DIMENSION(:), INTENT(IN) :: homo
Expand Down Expand Up @@ -361,9 +359,9 @@ SUBROUTINE mp2_gpw_compute(Emp2, Emp2_Cou, Emp2_EX, qs_env, para_env, para_env_s
ALLOCATE (psi_i(my_I_occupied_start:my_I_occupied_end))
DO i = my_I_occupied_start, my_I_occupied_end
CALL auxbas_pw_pool%create_pw(psi_i(i))
CALL calculate_wavefunction(mo_coeff, i, psi_i(i), rho_g, atomic_kind_set, &
qs_kind_set, cell, dft_control, particle_set, &
pw_env_sub, external_vector=my_Cocc(:, i - my_I_occupied_start + 1))
CALL collocate_function(my_Cocc(:, i - my_I_occupied_start + 1), &
psi_i(i), rho_g, atomic_kind_set, qs_kind_set, cell, particle_set, &
pw_env_sub, dft_control%qs_control%eps_rho_rspace)
END DO
Emp2 = 0.0_dp
Expand All @@ -380,9 +378,9 @@ SUBROUTINE mp2_gpw_compute(Emp2, Emp2_Cou, Emp2_EX, qs_env, para_env, para_env_s
IF (calc_ex) BIb_C = 0.0_dp
! psi_a
CALL calculate_wavefunction(mo_coeff, a, psi_a, rho_g, atomic_kind_set, &
qs_kind_set, cell, dft_control, particle_set, &
pw_env_sub, external_vector=my_Cvirt(:, a - (homo(1) + my_A_virtual_start) + 1))
CALL collocate_function(my_Cvirt(:, a - (homo(1) + my_A_virtual_start) + 1), &
psi_a, rho_g, atomic_kind_set, qs_kind_set, cell, particle_set, &
pw_env_sub, dft_control%qs_control%eps_rho_rspace)
i_counter = 0
DO i = my_I_occupied_start, my_I_occupied_end
i_counter = i_counter + 1
Expand Down
6 changes: 2 additions & 4 deletions src/mp2_integrals.F
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ MODULE mp2_integrals
!> \param particle_set ...
!> \param atomic_kind_set ...
!> \param qs_kind_set ...
!> \param mo_coeff ...
!> \param fm_matrix_PQ ...
!> \param fm_matrix_L_kpoints ...
!> \param fm_matrix_Minv_L_kpoints ...
Expand Down Expand Up @@ -185,7 +184,7 @@ MODULE mp2_integrals
! **************************************************************************************************
SUBROUTINE mp2_ri_gpw_compute_in(BIb_C, BIb_C_gw, BIb_C_bse_ij, BIb_C_bse_ab, gd_array, gd_B_virtual, &
dimen_RI, dimen_RI_red, qs_env, para_env, para_env_sub, color_sub, &
cell, particle_set, atomic_kind_set, qs_kind_set, mo_coeff, &
cell, particle_set, atomic_kind_set, qs_kind_set, &
fm_matrix_PQ, fm_matrix_L_kpoints, fm_matrix_Minv_L_kpoints, &
fm_matrix_Minv, fm_matrix_Minv_Vtrunc_Minv, &
nmo, homo, mat_munu, &
Expand Down Expand Up @@ -215,7 +214,6 @@ SUBROUTINE mp2_ri_gpw_compute_in(BIb_C, BIb_C_gw, BIb_C_bse_ij, BIb_C_bse_ab, gd
TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
TYPE(cp_fm_type), DIMENSION(:), INTENT(IN) :: mo_coeff
TYPE(cp_fm_type), INTENT(OUT) :: fm_matrix_PQ
TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:, :) :: fm_matrix_L_kpoints, &
fm_matrix_Minv_L_kpoints, &
Expand Down Expand Up @@ -612,7 +610,7 @@ SUBROUTINE mp2_ri_gpw_compute_in(BIb_C, BIb_C_gw, BIb_C_bse_ij, BIb_C_bse_ab, gd

DO i_counter = 1, my_group_L_size

CALL mp2_eri_3c_integrate_gpw(mo_coeff(1), psi_L, rho_g, atomic_kind_set, qs_kind_set, cell, dft_control, &
CALL mp2_eri_3c_integrate_gpw(psi_L, rho_g, atomic_kind_set, qs_kind_set, cell, dft_control, &
particle_set, pw_env_sub, my_Lrows(:, i_counter), poisson_env, rho_r, pot_g, &
ri_metric, mat_munu, qs_env, task_list_sub)

Expand Down
4 changes: 2 additions & 2 deletions src/mp2_ri_grad.F
Original file line number Diff line number Diff line change
Expand Up @@ -361,15 +361,15 @@ SUBROUTINE calc_ri_mp2_nonsep(qs_env, mp2_env, para_env, para_env_sub, cell, par
G_P_ia(:, L_counter), matrix_P_inu, &
mo_coeff_v, mo_coeff_o, eps_filter)

CALL integrate_potential_forces_2c(rho_r, LLL, mo_coeff(1), rho_g, atomic_kind_set, &
CALL integrate_potential_forces_2c(rho_r, LLL, rho_g, atomic_kind_set, &
qs_kind_set, particle_set, cell, pw_env_sub, poisson_env, &
pot_g, mp2_env%potential_parameter, use_virial, &
rho_g_copy, dvg, kind_of, atom_of_kind, G_PQ_local(:, L_counter), &
mp2_force, h_stress, para_env_sub, dft_control, psi_L, factor_2c)

IF (.NOT. compare_potential_types(mp2_env%ri_metric, mp2_env%potential_parameter)) THEN

CALL integrate_potential_forces_2c(rho_r, LLL, mo_coeff(1), rho_g, atomic_kind_set, &
CALL integrate_potential_forces_2c(rho_r, LLL, rho_g, atomic_kind_set, &
qs_kind_set, particle_set, cell, pw_env_sub, poisson_env, &
pot_g, mp2_env%ri_metric, use_virial, &
rho_g_copy, dvg, kind_of, atom_of_kind, G_PQ_local_2(:, L_counter), &
Expand Down
27 changes: 14 additions & 13 deletions src/optimize_embedding_potential.F
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ MODULE optimize_embedding_potential
USE pw_types, ONLY: pw_c1d_gs_type,&
pw_r3d_rs_type
USE qs_collocate_density, ONLY: calculate_rho_resp_all,&
calculate_wavefunction
calculate_wavefunction,&
collocate_function
USE qs_environment_types, ONLY: get_qs_env,&
qs_environment_type,&
set_qs_env
Expand Down Expand Up @@ -1791,10 +1792,10 @@ SUBROUTINE update_embed_pot(embed_pot_coef, dimen_aux, embed_pot, spin_embed_pot
CALL para_env%sum(wf_vector)

! Calculate the variable part of the embedding potential
CALL calculate_wavefunction(mo_coeff, 1, psi_L, rho_g, atomic_kind_set, &
qs_kind_set, cell, dft_control, particle_set, pw_env, &
basis_type="RI_AUX", &
external_vector=wf_vector)
CALL collocate_function(wf_vector, psi_L, rho_g, atomic_kind_set, &
qs_kind_set, cell, particle_set, pw_env, &
dft_control%qs_control%eps_rho_rspace, &
basis_type="RI_AUX")
! Update the full embedding potential
IF (add_const_pot) THEN
CALL pw_copy(const_pot, embed_pot)
Expand All @@ -1818,10 +1819,10 @@ SUBROUTINE update_embed_pot(embed_pot_coef, dimen_aux, embed_pot, spin_embed_pot
CALL para_env%sum(wf_vector)

! Calculate the variable part of the embedding potential
CALL calculate_wavefunction(mo_coeff, 1, psi_L, rho_g, atomic_kind_set, &
qs_kind_set, cell, dft_control, particle_set, pw_env, &
basis_type="RI_AUX", &
external_vector=wf_vector)
CALL collocate_function(wf_vector, psi_L, rho_g, atomic_kind_set, &
qs_kind_set, cell, particle_set, pw_env, &
dft_control%qs_control%eps_rho_rspace, &
basis_type="RI_AUX")
! No constant potential for spin-dependent potential
CALL pw_zero(spin_embed_pot)
CALL pw_axpy(psi_L, spin_embed_pot)
Expand All @@ -1843,10 +1844,10 @@ SUBROUTINE update_embed_pot(embed_pot_coef, dimen_aux, embed_pot, spin_embed_pot
CALL calculate_wavefunction(mo_coeff, 1, psi_L, rho_g, atomic_kind_set, &
qs_kind_set, cell, dft_control, particle_set, pw_env)

CALL calculate_wavefunction(mo_coeff, 1, psi_L, rho_g, atomic_kind_set, &
qs_kind_set, cell, dft_control, particle_set, pw_env, &
basis_type="RI_AUX", &
external_vector=wf_vector)
CALL collocate_function(wf_vector, psi_L, rho_g, atomic_kind_set, &
qs_kind_set, cell, particle_set, pw_env, &
dft_control%qs_control%eps_rho_rspace, &
basis_type="RI_AUX")

! Update the full embedding potential
IF (add_const_pot) THEN
Expand Down
Loading

0 comments on commit b513455

Please sign in to comment.