Skip to content

Commit

Permalink
open-shell in periodic GW and local gap printing
Browse files Browse the repository at this point in the history
  • Loading branch information
JWilhelm authored and oschuett committed Feb 28, 2023
1 parent 8334c8f commit 4e8b7c4
Show file tree
Hide file tree
Showing 15 changed files with 917 additions and 364 deletions.
71 changes: 56 additions & 15 deletions src/input_cp2k_mp2.F
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,16 @@ SUBROUTINE create_ri_g0w0(section)
CALL section_add_keyword(section, keyword)
CALL keyword_release(keyword)

CALL keyword_create(keyword, __LOCATION__, name="PRINT_SELF_ENERGY", &
description="If true, print the self-energy for all levels for real energy "// &
"together with the straight line to see the quasiparticle energy as intersection. "// &
"In addition, prints the self-energy for imaginary frequencies together with the Pade fit.", &
usage="SELF_ENERGY", &
default_l_val=.FALSE., &
lone_keyword_l_val=.TRUE.)
CALL section_add_keyword(section, keyword)
CALL keyword_release(keyword)

CALL keyword_create(keyword, __LOCATION__, name="RI_SIGMA_X", &
description="If true, the exchange self-energy is calculated approximatively with RI. "// &
"If false, the Hartree-Fock implementation in CP2K is used.", &
Expand Down Expand Up @@ -927,13 +937,13 @@ SUBROUTINE create_ri_g0w0(section)
CALL section_add_subsection(section, subsection)
CALL section_release(subsection)

! here we generate a subsection for additional printing
CALL create_print_section(subsection)
! here we generate a subsection for calculating the GW band structures
CALL create_kpoint_set_section(subsection)
CALL section_add_subsection(section, subsection)
CALL section_release(subsection)

! here we generate a subsection for calculating the GW band structures
CALL create_kpoint_set_section(subsection)
! here we generate a subsection for additional printing
CALL create_print_section(subsection)
CALL section_add_subsection(section, subsection)
CALL section_release(subsection)

Expand All @@ -947,24 +957,55 @@ SUBROUTINE create_print_section(section)
TYPE(section_type), POINTER :: section

TYPE(keyword_type), POINTER :: keyword
TYPE(section_type), POINTER :: print_key

CPASSERT(.NOT. ASSOCIATED(section))
NULLIFY (print_key, keyword)
CALL section_create(section, __LOCATION__, name="PRINT", &
description="Parameters for GW related output.", &
n_keywords=1, n_subsections=0, repeats=.FALSE.)
description="Section of possible print options specific for the GW code.", &
n_keywords=0, n_subsections=1, repeats=.FALSE.)

CALL cp_print_key_section_create(print_key, __LOCATION__, "LOCAL_BANDGAP", &
description="Prints a local bandgap E_gap(r), derived from the local density of "// &
"states rho(r,E). Details and formulae in the SI of the periodic GW paper (2023).", &
print_level=high_print_level, add_last=add_last_numeric, &
filename="LOCAL_BANDGAP", &
common_iter_levels=3)

CALL keyword_create(keyword, __LOCATION__, name="ENERGY_WINDOW", &
description="Energy window in the LDOS for searching the gap.", &
usage="ENERGY_WINDOW 6.0", &
default_r_val=cp_unit_to_cp2k(value=6.0_dp, unit_str="eV"), &
unit_str="eV")
CALL section_add_keyword(print_key, keyword)
CALL keyword_release(keyword)

NULLIFY (keyword)
CALL keyword_create(keyword, __LOCATION__, name="ENERGY_SPACING", &
description="Energy spacing of the LDOS for searching the gap.", &
usage="ENERGY_SPACING 0.03", &
default_r_val=cp_unit_to_cp2k(value=0.03_dp, unit_str="eV"), &
unit_str="eV")
CALL section_add_keyword(print_key, keyword)
CALL keyword_release(keyword)

CALL keyword_create(keyword, __LOCATION__, name="SELF_ENERGY", &
description="If true, print the self-energy for all levels for real energy "// &
"together with the straight line to see the quasiparticle energy as intersection. "// &
"In addition, prints the self-energy for imaginary frequencies together with the Pade fit.", &
usage="SELF_ENERGY", &
default_l_val=.FALSE., &
lone_keyword_l_val=.TRUE.)
CALL section_add_keyword(section, keyword)
CALL keyword_create(keyword, __LOCATION__, name="LDOS_THRESHOLD_GAP", &
description="Relative LDOS threshold that determines the local bandgap.", &
usage="LDOS_THRESHOLD_GAP 0.1", &
default_r_val=0.1_dp)
CALL section_add_keyword(print_key, keyword)
CALL keyword_release(keyword)

CALL keyword_create(keyword, __LOCATION__, name="STRIDE", &
description="The stride (X,Y,Z) used to write the cube file "// &
"(larger values result in smaller cube files). You can provide 3 numbers (for X,Y,Z) or"// &
" 1 number valid for all components.", &
usage="STRIDE 2 2 2", n_var=-1, default_i_vals=(/2, 2, 2/), type_of_var=integer_t)
CALL section_add_keyword(print_key, keyword)
CALL keyword_release(keyword)

CALL section_add_subsection(section, print_key)
CALL section_release(print_key)

END SUBROUTINE

! **************************************************************************************************
Expand Down
26 changes: 15 additions & 11 deletions src/mp2_gpw.F
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ SUBROUTINE mp2_gpw_main(qs_env, mp2_env, Emp2, Emp2_Cou, Emp2_EX, Emp2_S, Emp2_T
IF (do_im_time) THEN

IF (mp2_env%ri_metric%potential_type == ri_default) THEN
IF (SUM(periodic) > 0) THEN
IF (SUM(periodic) == 1 .OR. SUM(periodic) == 3) THEN
mp2_env%ri_metric%potential_type = do_potential_id
ELSE
mp2_env%ri_metric%potential_type = do_potential_truncated
Expand Down Expand Up @@ -307,14 +307,16 @@ SUBROUTINE mp2_gpw_main(qs_env, mp2_env, Emp2, Emp2_Cou, Emp2_EX, Emp2_S, Emp2_T
CALL m_flush(unit_nr)
END IF

! a logger
NULLIFY (logger_sub)
CALL cp_logger_create(logger_sub, para_env=para_env_sub, &
default_global_unit_nr=local_unit_nr, close_global_unit_on_dealloc=.FALSE.)
CALL cp_logger_set(logger_sub, local_filename="MP2_localLog")
! set to a custom print level (we could also have a different print level for para_env%source)
logger_sub%iter_info%print_level = mp2_env%mp2_gpw%print_level
CALL cp_add_default_logger(logger_sub)
IF (.NOT. mp2_env%ri_g0w0%print_local_bandgap) THEN
! a logger
NULLIFY (logger_sub)
CALL cp_logger_create(logger_sub, para_env=para_env_sub, &
default_global_unit_nr=local_unit_nr, close_global_unit_on_dealloc=.FALSE.)
CALL cp_logger_set(logger_sub, local_filename="MP2_localLog")
! set to a custom print level (we could also have a different print level for para_env%source)
logger_sub%iter_info%print_level = mp2_env%mp2_gpw%print_level
CALL cp_add_default_logger(logger_sub)
END IF

! a blacs_env (ignore the globenv stored defaults for now)
blacs_grid_layout = BLACS_GRID_SQUARE
Expand Down Expand Up @@ -628,8 +630,10 @@ SUBROUTINE mp2_gpw_main(qs_env, mp2_env, Emp2, Emp2_Cou, Emp2_EX, Emp2_S, Emp2_T

CALL cp_blacs_env_release(blacs_env_sub)

CALL cp_rm_default_logger()
CALL cp_logger_release(logger_sub)
IF (.NOT. mp2_env%ri_g0w0%print_local_bandgap) THEN
CALL cp_rm_default_logger()
CALL cp_logger_release(logger_sub)
END IF

CALL cp_para_env_release(para_env_sub)

Expand Down
21 changes: 16 additions & 5 deletions src/mp2_ri_2c.F
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ MODULE mp2_ri_2c
kpoint_type
USE libint_2c_3c, ONLY: compare_potential_types,&
libint_potential_type
USE machine, ONLY: m_flush
USE machine, ONLY: m_flush,&
m_walltime
USE message_passing, ONLY: mp_request_type
USE mp2_eri, ONLY: mp2_eri_2c_integrate
USE mp2_eri_gpw, ONLY: mp2_eri_2c_integrate_gpw
Expand Down Expand Up @@ -257,8 +258,8 @@ SUBROUTINE get_2c_integrals(qs_env, eri_method, eri_param, para_env, para_env_su
! k-dependent 1/r Coulomb matrix V_PQ(k)
CALL compute_V_by_lattice_sum(qs_env, fm_matrix_L_kpoints, fm_matrix_Minv_L_kpoints, kpoints)

CALL inversion_of_M_and_mult_with_chol_dec_of_V(fm_matrix_Minv_L_kpoints, fm_matrix_L_kpoints, &
dimen_RI, kpoints, qs_env%mp2_env%ri_rpa_im_time%eps_eigval_S)
CALL inversion_of_M_and_mult_with_chol_dec_of_V(fm_matrix_Minv_L_kpoints, fm_matrix_L_kpoints, dimen_RI, &
unit_nr, kpoints, qs_env%mp2_env%ri_rpa_im_time%eps_eigval_S)

CALL setup_trunc_coulomb_potential_for_exchange_self_energy(qs_env, trunc_coulomb)

Expand Down Expand Up @@ -1446,15 +1447,16 @@ END SUBROUTINE cholesky_decomp
!> \param fm_matrix_Minv_L_kpoints ...
!> \param fm_matrix_L_kpoints ...
!> \param dimen_RI ...
!> \param unit_nr ...
!> \param kpoints ...
!> \param eps_eigval_S ...
! **************************************************************************************************
SUBROUTINE inversion_of_M_and_mult_with_chol_dec_of_V(fm_matrix_Minv_L_kpoints, fm_matrix_L_kpoints, &
dimen_RI, kpoints, eps_eigval_S)
dimen_RI, unit_nr, kpoints, eps_eigval_S)

TYPE(cp_fm_type), DIMENSION(:, :), INTENT(IN) :: fm_matrix_Minv_L_kpoints, &
fm_matrix_L_kpoints
INTEGER, INTENT(IN) :: dimen_RI
INTEGER, INTENT(IN) :: dimen_RI, unit_nr
TYPE(kpoint_type), POINTER :: kpoints
REAL(KIND=dp), INTENT(IN) :: eps_eigval_S

Expand All @@ -1463,6 +1465,7 @@ SUBROUTINE inversion_of_M_and_mult_with_chol_dec_of_V(fm_matrix_Minv_L_kpoints,
czero = CMPLX(0.0_dp, 0.0_dp, KIND=dp), ione = CMPLX(0.0_dp, 1.0_dp, KIND=dp)

INTEGER :: handle, ikp, nkp
REAL(KIND=dp) :: t1, t2
TYPE(cp_cfm_type) :: cfm_matrix_K_tmp, cfm_matrix_M_tmp, &
cfm_matrix_V_tmp, cfm_matrix_Vtrunc_tmp
TYPE(cp_fm_struct_type), POINTER :: matrix_struct
Expand All @@ -1480,6 +1483,8 @@ SUBROUTINE inversion_of_M_and_mult_with_chol_dec_of_V(fm_matrix_Minv_L_kpoints,

DO ikp = 1, nkp

t1 = m_walltime()

CALL cp_cfm_scale_and_add_fm(czero, cfm_matrix_M_tmp, cone, fm_matrix_Minv_L_kpoints(ikp, 1))
CALL cp_cfm_scale_and_add_fm(cone, cfm_matrix_M_tmp, ione, fm_matrix_Minv_L_kpoints(ikp, 2))

Expand All @@ -1500,6 +1505,12 @@ SUBROUTINE inversion_of_M_and_mult_with_chol_dec_of_V(fm_matrix_Minv_L_kpoints,
! move
CALL cp_cfm_to_fm(cfm_matrix_K_tmp, fm_matrix_Minv_L_kpoints(ikp, 1), fm_matrix_Minv_L_kpoints(ikp, 2))

t2 = m_walltime()

IF (unit_nr > 0) WRITE (unit_nr, '(T3,A,I4,A,I3, A, F11.1)') &
'INTEGRAL_INFO| Integrals for k-point', ikp, ' / ', nkp, &
', execution time (s):', t2 - t1

END DO

CALL cp_cfm_release(cfm_matrix_M_tmp)
Expand Down
22 changes: 19 additions & 3 deletions src/mp2_setup.F
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ MODULE mp2_setup
USE cp_eri_mme_interface, ONLY: cp_eri_mme_init_read_input
USE cp_log_handling, ONLY: cp_get_default_logger,&
cp_logger_type
USE cp_output_handling, ONLY: cp_print_key_finished_output,&
USE cp_output_handling, ONLY: cp_p_file,&
cp_print_key_finished_output,&
cp_print_key_should_output,&
cp_print_key_unit_nr
USE cp_parser_methods, ONLY: read_float_object
USE input_constants, ONLY: &
Expand Down Expand Up @@ -141,6 +143,8 @@ SUBROUTINE read_mp2_section(input, mp2_env)
r_val=mp2_env%ri_g0w0%eps_iter)
CALL section_vals_val_get(mp2_section, "RI_RPA%GW%PRINT_EXX", &
i_val=mp2_env%ri_g0w0%print_exx)
CALL section_vals_val_get(mp2_section, "RI_RPA%GW%PRINT_SELF_ENERGY", &
l_val=mp2_env%ri_g0w0%print_self_energy)
CALL section_vals_val_get(mp2_section, "RI_RPA%GW%RI_SIGMA_X", &
l_val=mp2_env%ri_g0w0%do_ri_Sigma_x)
NULLIFY (r_vals)
Expand Down Expand Up @@ -222,8 +226,17 @@ SUBROUTINE read_mp2_section(input, mp2_env)
mp2_env%ri_g0w0%kp_grid_Sigma(2)* &
mp2_env%ri_g0w0%kp_grid_Sigma(3) > 0

CALL section_vals_val_get(mp2_section, "RI_RPA%GW%PRINT%SELF_ENERGY", &
l_val=mp2_env%ri_g0w0%print_self_energy)
mp2_env%ri_g0w0%print_local_bandgap = BTEST(cp_print_key_should_output(logger%iter_info, &
mp2_section, "RI_RPA%GW%PRINT%LOCAL_BANDGAP"), &
cp_p_file)
CALL section_vals_val_get(mp2_section, "RI_RPA%GW%PRINT%LOCAL_BANDGAP%ENERGY_WINDOW", &
r_val=mp2_env%ri_g0w0%energy_window_print_loc_bandgap)
CALL section_vals_val_get(mp2_section, "RI_RPA%GW%PRINT%LOCAL_BANDGAP%ENERGY_SPACING", &
r_val=mp2_env%ri_g0w0%energy_spacing_print_loc_bandgap)
CALL section_vals_val_get(mp2_section, "RI_RPA%GW%PRINT%LOCAL_BANDGAP%LDOS_THRESHOLD_GAP", &
r_val=mp2_env%ri_g0w0%ldos_thresh_print_loc_bandgap)
CALL section_vals_val_get(mp2_section, "RI_RPA%GW%PRINT%LOCAL_BANDGAP%STRIDE", &
i_vals=mp2_env%ri_g0w0%stride_loc_bandgap)

NULLIFY (low_scaling_section)
low_scaling_section => section_vals_get_subs_vals(mp2_section, "LOW_SCALING")
Expand All @@ -243,6 +256,9 @@ SUBROUTINE read_mp2_section(input, mp2_env)
CALL section_vals_val_get(low_scaling_section, "KPOINTS", &
i_vals=mp2_env%ri_rpa_im_time%kp_grid)
mp2_env%ri_rpa_im_time%do_kpoints_from_Gamma = SUM(mp2_env%ri_rpa_im_time%kp_grid) > 0
IF (mp2_env%ri_rpa_im_time%do_kpoints_from_Gamma) THEN
CPASSERT(mp2_env%ri_g0w0%do_kpoints_Sigma)
END IF
CALL section_vals_val_get(low_scaling_section, "KPOINT_WEIGHTS_W", &
i_val=mp2_env%ri_rpa_im_time%kpoint_weights_W_method)
CALL section_vals_val_get(low_scaling_section, "EXPONENT_TAILORED_WEIGHTS", &
Expand Down
5 changes: 4 additions & 1 deletion src/mp2_types.F
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,15 @@ MODULE mp2_types
TYPE(one_dim_real_array), DIMENSION(2) :: ic_corr_list
INTEGER :: print_exx
LOGICAL :: do_gamma_only_sigma
LOGICAL :: update_xc_energy, do_kpoints_Sigma
LOGICAL :: update_xc_energy, do_kpoints_Sigma, print_local_bandgap
INTEGER :: n_kp_in_kp_line, n_special_kp, nkp_self_energy, &
nkp_self_energy_special_kp, nkp_self_energy_monkh_pack
REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :) :: xkp_special_kp
TYPE(dbcsr_p_type), DIMENSION(:), ALLOCATABLE :: &
matrix_sigma_x_minus_vxc, matrix_ks
REAL(KIND=dp) :: broadening_print_loc_bandgap, energy_window_print_loc_bandgap, &
ldos_thresh_print_loc_bandgap, energy_spacing_print_loc_bandgap
INTEGER, DIMENSION(:), POINTER :: stride_loc_bandgap
END TYPE

TYPE ri_basis_opt
Expand Down

0 comments on commit 4e8b7c4

Please sign in to comment.