Skip to content

Commit

Permalink
computing SOC matrices with k-points with symmetry (fix) (cp2k#3513)
Browse files Browse the repository at this point in the history
Co-authored-by: JWilhelm <[email protected]>
  • Loading branch information
JWilhelm and JWilhelm authored Jul 1, 2024
1 parent aaf81e1 commit ce58a42
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 43 deletions.
1 change: 0 additions & 1 deletion src/bse_iterative.F
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,6 @@ SUBROUTINE compute_AZ(AZ, Z_vectors, B_iaQ_bse_local, B_bar_ijQ_bse_local, B_abQ

DO i_Z_vector = 1, num_Z_vectors

! JW TO DO: OMP PARALLELIZATION
DO LLL = 1, local_RI_size

! M_ja^P = sum_b Z_jb*B_ba^P
Expand Down
62 changes: 32 additions & 30 deletions src/post_scf_bandstructure_utils.F
Original file line number Diff line number Diff line change
Expand Up @@ -651,24 +651,24 @@ END SUBROUTINE compute_cfm_mo_coeff_kp_and_eigenval_scf_kp

! **************************************************************************************************
!> \brief ...
!> \param matrix_ks ...
!> \param mat_rs ...
!> \param ispin ...
!> \param xkp ...
!> \param cell_to_index_scf ...
!> \param sab_nl ...
!> \param bs_env ...
!> \param cfm_ks ...
!> \param cfm_kp ...
!> \param imag_rs_mat ...
! **************************************************************************************************
SUBROUTINE rsmat_to_kp(matrix_ks, ispin, xkp, cell_to_index_scf, sab_nl, bs_env, cfm_ks, imag_rs_mat)
TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: matrix_ks
SUBROUTINE rsmat_to_kp(mat_rs, ispin, xkp, cell_to_index_scf, sab_nl, bs_env, cfm_kp, imag_rs_mat)
TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: mat_rs
INTEGER :: ispin
REAL(KIND=dp), DIMENSION(3) :: xkp
INTEGER, DIMENSION(:, :, :), POINTER :: cell_to_index_scf
TYPE(neighbor_list_set_p_type), DIMENSION(:), &
POINTER :: sab_nl
TYPE(post_scf_bandstructure_type), POINTER :: bs_env
TYPE(cp_cfm_type) :: cfm_ks
TYPE(cp_cfm_type) :: cfm_kp
LOGICAL, OPTIONAL :: imag_rs_mat

CHARACTER(LEN=*), PARAMETER :: routineN = 'rsmat_to_kp'
Expand All @@ -685,25 +685,26 @@ SUBROUTINE rsmat_to_kp(matrix_ks, ispin, xkp, cell_to_index_scf, sab_nl, bs_env,
IF (PRESENT(imag_rs_mat)) imag_rs_mat_private = imag_rs_mat

IF (imag_rs_mat_private) THEN
CALL dbcsr_create(rmat, template=matrix_ks(1, 1)%matrix, matrix_type=dbcsr_type_antisymmetric)
CALL dbcsr_create(cmat, template=matrix_ks(1, 1)%matrix, matrix_type=dbcsr_type_symmetric)
CALL dbcsr_create(rmat, template=mat_rs(1, 1)%matrix, matrix_type=dbcsr_type_antisymmetric)
CALL dbcsr_create(cmat, template=mat_rs(1, 1)%matrix, matrix_type=dbcsr_type_symmetric)
ELSE
CALL dbcsr_create(rmat, template=matrix_ks(1, 1)%matrix, matrix_type=dbcsr_type_symmetric)
CALL dbcsr_create(cmat, template=matrix_ks(1, 1)%matrix, matrix_type=dbcsr_type_antisymmetric)
CALL dbcsr_create(rmat, template=mat_rs(1, 1)%matrix, matrix_type=dbcsr_type_symmetric)
CALL dbcsr_create(cmat, template=mat_rs(1, 1)%matrix, matrix_type=dbcsr_type_antisymmetric)
END IF
CALL dbcsr_create(nsmat, template=matrix_ks(1, 1)%matrix, matrix_type=dbcsr_type_no_symmetry)
CALL dbcsr_create(nsmat, template=mat_rs(1, 1)%matrix, matrix_type=dbcsr_type_no_symmetry)
CALL cp_dbcsr_alloc_block_from_nbl(rmat, sab_nl)
CALL cp_dbcsr_alloc_block_from_nbl(cmat, sab_nl)

CALL dbcsr_set(rmat, 0.0_dp)
CALL dbcsr_set(cmat, 0.0_dp)
CALL rskp_transform(rmatrix=rmat, cmatrix=cmat, rsmat=matrix_ks, ispin=ispin, &
CALL rskp_transform(rmatrix=rmat, cmatrix=cmat, rsmat=mat_rs, ispin=ispin, &
xkp=xkp, cell_to_index=cell_to_index_scf, sab_nl=sab_nl)

CALL dbcsr_desymmetrize(rmat, nsmat)
CALL copy_dbcsr_to_fm(nsmat, bs_env%fm_work_mo(1))
CALL dbcsr_desymmetrize(cmat, nsmat)
CALL copy_dbcsr_to_fm(nsmat, bs_env%fm_work_mo(2))
CALL cp_fm_to_cfm(bs_env%fm_work_mo(1), bs_env%fm_work_mo(2), cfm_ks)
CALL cp_fm_to_cfm(bs_env%fm_work_mo(1), bs_env%fm_work_mo(2), cfm_kp)

CALL dbcsr_deallocate_matrix(rmat)
CALL dbcsr_deallocate_matrix(cmat)
Expand Down Expand Up @@ -2737,7 +2738,7 @@ SUBROUTINE H_KS_spinor_kp(qs_env, bs_env)
nkp_bs_and_DOS, s
INTEGER, DIMENSION(:, :, :), POINTER :: cell_to_index_scf
REAL(KIND=dp), DIMENSION(3) :: xkp
TYPE(cp_cfm_type) :: cfm_V_SOC_xyz
TYPE(cp_cfm_type) :: cfm_V_SOC_xyz_ikp
TYPE(cp_fm_struct_type), POINTER :: str
TYPE(kpoint_type), POINTER :: kpoints_scf
TYPE(neighbor_list_set_p_type), DIMENSION(:), &
Expand All @@ -2750,7 +2751,7 @@ SUBROUTINE H_KS_spinor_kp(qs_env, bs_env)
s = bs_env%n_ao + 1
str => bs_env%cfm_ks_kp(1, 1)%matrix_struct

CALL cp_cfm_create(cfm_V_SOC_xyz, bs_env%cfm_work_mo%matrix_struct)
CALL cp_cfm_create(cfm_V_SOC_xyz_ikp, bs_env%cfm_work_mo%matrix_struct)

CALL alloc_cfm_double_array_1d(bs_env%cfm_SOC_spinor_ao, bs_env%cfm_ks_kp(1, 1), nkp_bs_and_DOS)

Expand All @@ -2759,42 +2760,43 @@ SUBROUTINE H_KS_spinor_kp(qs_env, bs_env)
NULLIFY (sab_nl)
CALL get_kpoint_info(kpoints_scf, sab_nl=sab_nl, cell_to_index=cell_to_index_scf)

DO ikp = 1, nkp_bs_and_DOS
DO i_dim = 1, 3

xkp(1:3) = bs_env%kpoints_DOS%xkp(1:3, ikp)
DO ikp = 1, nkp_bs_and_DOS

xkp(1:3) = bs_env%kpoints_DOS%xkp(1:3, ikp)

DO i_dim = 1, 3
CALL cp_cfm_set_all(cfm_V_SOC_xyz_ikp, z_zero)

CALL cp_cfm_set_all(cfm_V_SOC_xyz, z_zero)
CALL rsmat_to_kp(bs_env%mat_V_SOC_xyz, i_dim, xkp, cell_to_index_scf, &
sab_nl, bs_env, cfm_V_SOC_xyz, imag_rs_mat=.TRUE.)
sab_nl, bs_env, cfm_V_SOC_xyz_ikp, imag_rs_mat=.TRUE.)

! multiply V_SOC with i because bs_env%mat_V_SOC_xyz stores imag. part (real part = 0)
CALL cp_cfm_scale(gaussi, cfm_V_SOC_xyz)
CALL cp_cfm_scale(gaussi, cfm_V_SOC_xyz_ikp)

SELECT CASE (i_dim)
CASE (1)
! add V^SOC_x * σ_x for σ_x = ( (0,1) (1,0) )
CALL add_cfm_submat(bs_env%cfm_SOC_spinor_ao(ikp), cfm_V_SOC_xyz, 1, s)
CALL add_cfm_submat(bs_env%cfm_SOC_spinor_ao(ikp), cfm_V_SOC_xyz, s, 1)
CALL add_cfm_submat(bs_env%cfm_SOC_spinor_ao(ikp), cfm_V_SOC_xyz_ikp, 1, s)
CALL add_cfm_submat(bs_env%cfm_SOC_spinor_ao(ikp), cfm_V_SOC_xyz_ikp, s, 1)
CASE (2)
! add V^SOC_y * σ_y for σ_y = ( (0,-i) (i,0) )
CALL cp_cfm_scale(gaussi, cfm_V_SOC_xyz)
CALL add_cfm_submat(bs_env%cfm_SOC_spinor_ao(ikp), cfm_V_SOC_xyz, 1, s)
CALL cp_cfm_scale(-z_one, cfm_V_SOC_xyz)
CALL add_cfm_submat(bs_env%cfm_SOC_spinor_ao(ikp), cfm_V_SOC_xyz, s, 1)
CALL cp_cfm_scale(gaussi, cfm_V_SOC_xyz_ikp)
CALL add_cfm_submat(bs_env%cfm_SOC_spinor_ao(ikp), cfm_V_SOC_xyz_ikp, 1, s)
CALL cp_cfm_scale(-z_one, cfm_V_SOC_xyz_ikp)
CALL add_cfm_submat(bs_env%cfm_SOC_spinor_ao(ikp), cfm_V_SOC_xyz_ikp, s, 1)
CASE (3)
! add V^SOC_z * σ_z for σ_z = ( (1,0) (0,1) )
CALL add_cfm_submat(bs_env%cfm_SOC_spinor_ao(ikp), cfm_V_SOC_xyz, 1, 1)
CALL cp_cfm_scale(-z_one, cfm_V_SOC_xyz)
CALL add_cfm_submat(bs_env%cfm_SOC_spinor_ao(ikp), cfm_V_SOC_xyz, s, s)
CALL add_cfm_submat(bs_env%cfm_SOC_spinor_ao(ikp), cfm_V_SOC_xyz_ikp, 1, 1)
CALL cp_cfm_scale(-z_one, cfm_V_SOC_xyz_ikp)
CALL add_cfm_submat(bs_env%cfm_SOC_spinor_ao(ikp), cfm_V_SOC_xyz_ikp, s, s)
END SELECT

END DO

END DO ! ikp

CALL cp_cfm_release(cfm_V_SOC_xyz)
CALL cp_cfm_release(cfm_V_SOC_xyz_ikp)

CALL timestop(handle)

Expand Down
1 change: 0 additions & 1 deletion src/rpa_gw_sigma_x.F
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,6 @@ SUBROUTINE compute_vec_Sigma_x_minus_vxc_gw(qs_env, mp2_env, mos_mp2, energy_ex,
END IF

IF (do_kpoints_from_Gamma .AND. print_exx == gw_print_exx) THEN
! JW not yet there: open shell
ALLOCATE (mat_exchange_for_kp_from_gamma(1))

DO ispin = 1, 1
Expand Down
29 changes: 23 additions & 6 deletions src/soc_pseudopotential_methods.F
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ MODULE soc_pseudopotential_methods
cp_cfm_type
USE cp_control_types, ONLY: dft_control_type
USE cp_dbcsr_api, ONLY: dbcsr_add,&
dbcsr_copy,&
dbcsr_create,&
dbcsr_desymmetrize,&
dbcsr_p_type,&
Expand Down Expand Up @@ -73,7 +74,7 @@ SUBROUTINE V_SOC_xyz_from_pseudopotential(qs_env, mat_V_SOC_xyz)
INTEGER :: handle, img, nder, nimages, xyz
INTEGER, DIMENSION(:, :, :), POINTER :: cell_to_index
LOGICAL :: calculate_forces, do_symmetric, &
LOGICAL :: calculate_forces, do_kp, do_symmetric, &
use_virial
REAL(KIND=dp) :: eps_ppnl
TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
Expand All @@ -98,6 +99,7 @@ SUBROUTINE V_SOC_xyz_from_pseudopotential(qs_env, mat_V_SOC_xyz)
eps_ppnl = dft_control%qs_control%eps_ppnl
nimages = dft_control%nimages
do_kp = (nimages > 1)
CALL get_neighbor_list_set_p(neighbor_list_sets=sab_orb, symmetric=do_symmetric)
CALL get_kpoint_info(kpoint=kpoints, cell_to_index=cell_to_index)
Expand Down Expand Up @@ -141,9 +143,15 @@ SUBROUTINE V_SOC_xyz_from_pseudopotential(qs_env, mat_V_SOC_xyz)
DO img = 1, nimages
ALLOCATE (mat_l_nosym(xyz, img)%matrix)
CALL dbcsr_create(mat_l_nosym(xyz, img)%matrix, template=matrix_s(1, 1)%matrix, &
matrix_type=dbcsr_type_no_symmetry)
CALL dbcsr_desymmetrize(mat_l(xyz, img)%matrix, mat_l_nosym(xyz, img)%matrix)
IF (do_kp) THEN
CALL dbcsr_create(mat_l_nosym(xyz, img)%matrix, template=matrix_s(1, 1)%matrix, &
matrix_type=dbcsr_type_antisymmetric)
CALL dbcsr_copy(mat_l_nosym(xyz, img)%matrix, mat_l(xyz, img)%matrix)
ELSE
CALL dbcsr_create(mat_l_nosym(xyz, img)%matrix, template=matrix_s(1, 1)%matrix, &
matrix_type=dbcsr_type_no_symmetry)
CALL dbcsr_desymmetrize(mat_l(xyz, img)%matrix, mat_l_nosym(xyz, img)%matrix)
END IF
END DO
END DO
Expand All @@ -153,8 +161,17 @@ SUBROUTINE V_SOC_xyz_from_pseudopotential(qs_env, mat_V_SOC_xyz)
DO xyz = 1, 3
DO img = 1, nimages
ALLOCATE (mat_V_SOC_xyz(xyz, img)%matrix)
CALL dbcsr_create(mat_V_SOC_xyz(xyz, img)%matrix, template=matrix_s(1, 1)%matrix, &
matrix_type=dbcsr_type_no_symmetry)
IF (do_kp) THEN
! mat_V_SOC_xyz^R with neighbor cell R actually has no symmetry
! mat_V_SOC_xyz^R_µν = mat_V_SOC_xyz^R_νµ* (the actual symmetry is
! mat_V_SOC_xyz^R_µν = mat_V_SOC_xyz^-R_νµ* ) but rskp_transform
! for mat_V_SOC_xyz^R -> mat_V_SOC_xyz(k) requires symmetry...
CALL dbcsr_create(mat_V_SOC_xyz(xyz, img)%matrix, template=matrix_s(1, 1)%matrix, &
matrix_type=dbcsr_type_antisymmetric)
ELSE
CALL dbcsr_create(mat_V_SOC_xyz(xyz, img)%matrix, template=matrix_s(1, 1)%matrix, &
matrix_type=dbcsr_type_no_symmetry)
END IF
CALL cp_dbcsr_alloc_block_from_nbl(mat_V_SOC_xyz(xyz, img)%matrix, sab_orb)
! factor 0.5 from ħ/2 prefactor
CALL dbcsr_add(mat_V_SOC_xyz(xyz, img)%matrix, mat_l_nosym(xyz, img)%matrix, &
Expand Down
10 changes: 5 additions & 5 deletions tests/QS/regtest-scalable-gw/TEST_FILES
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
01_G0W0_periodic_H2O.inp 106 1e-03 9.861
02_G0W0_IH_SOC_LDOS.inp 106 1e-03 17.826
02_G0W0_IH_SOC_LDOS.inp 107 1e-03 11.344
03_G0W0_bandstructure_IH_chain.inp 106 1e-03 21.977
03_G0W0_bandstructure_IH_chain.inp 108 2e-03 21.692
03_G0W0_bandstructure_IH_chain.inp 106 5e-04 21.977
03_G0W0_bandstructure_IH_chain.inp 108 5e-04 21.692
04_G0W0_SOC_TeH_chain_open_shell_kp_extrapol.inp 106 1e-03 5.174
05_G0W0_SOC_TeH_chain_open_shell.inp 106 1e-03 5.178
05_G0W0_SOC_TeH_chain_open_shell.inp 107 1e-03 0.306
05_G0W0_SOC_TeH_chain_open_shell.inp 108 1e-03 5.134
05_G0W0_SOC_TeH_chain_open_shell.inp 106 5e-04 5.178
05_G0W0_SOC_TeH_chain_open_shell.inp 107 5e-04 0.306
05_G0W0_SOC_TeH_chain_open_shell.inp 108 5e-04 5.134
#EOF

0 comments on commit ce58a42

Please sign in to comment.